DaanHoogland commented on a change in pull request #3154: Copy template to 
target KVM host if needed when migrating local <> local storage
URL: https://github.com/apache/cloudstack/pull/3154#discussion_r251755714
 
 

 ##########
 File path: 
engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageDataMotionStrategy.java
 ##########
 @@ -140,4 +160,56 @@ protected void setVolumePath(VolumeVO volume) {
     protected boolean shouldMigrateVolume(StoragePoolVO sourceStoragePool, 
Host destHost, StoragePoolVO destStoragePool) {
         return sourceStoragePool.getPoolType() == StoragePoolType.Filesystem;
     }
+
+    /**
+     * If the template is not on the target primary storage then it migrates 
the template.
+     * Otherwise the execution flow fails during migration and creates a null 
file created on the target storage pool.
+     */
+    @Override
+    protected void migrateTemplateToTargetFilesystemStorageIfNeeded(VolumeInfo 
srcVolumeInfo, DataStore destDataStore, StoragePool destStoragePool,
+            Host destHost) {
+        VMTemplateStoragePoolVO vmTemplateStoragePoolVO = 
vmTemplatePoolDao.findByPoolTemplate(destStoragePool.getId(), 
srcVolumeInfo.getTemplateId());
+        if (vmTemplateStoragePoolVO == null && destStoragePool.getPoolType() 
== StoragePoolType.Filesystem) {
+            DataStore sourceTemplateDataStore = 
dataStoreManagerImpl.getImageStore(srcVolumeInfo.getDataCenterId());
+            TemplateInfo sourceTemplateInfo = 
templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), 
sourceTemplateDataStore);
+            TemplateObjectTO sourceTemplate = new 
TemplateObjectTO(sourceTemplateInfo);
+
+            LOGGER.debug(String.format("Could not find template [id=%s, 
name=%s] on the storage pool [id=%s]; copying the template to the target 
storage pool.",
+                    srcVolumeInfo.getTemplateId(), 
sourceTemplateInfo.getName(), destDataStore.getId()));
+
+            TemplateInfo destTemplateInfo = 
templateDataFactory.getTemplate(srcVolumeInfo.getTemplateId(), destDataStore);
+            final TemplateObjectTO destTemplate = new 
TemplateObjectTO(destTemplateInfo);
+
+            sendCopyCommand(destHost, sourceTemplate, destTemplate, 
destDataStore);
+        }
+    }
+
+    /**
+     * Sends the CopyCommand to migrate the template to the dest host.
+     */
+    protected void sendCopyCommand(Host destHost, TemplateObjectTO 
sourceTemplate, TemplateObjectTO destTemplate, DataStore destDataStore) {
+        boolean executeInSequence = 
virtualMachineManager.getExecuteInSequence(HypervisorType.KVM);
+        CopyCommand copyCommand = new CopyCommand(sourceTemplate, 
destTemplate, StorageManager.PRIMARY_STORAGE_DOWNLOAD_WAIT.value(), 
executeInSequence);
+        try {
+            Answer copyCommandAnswer = agentManager.send(destHost.getId(), 
copyCommand);
+            logInCaseOfTemplateCopyFailure(copyCommandAnswer, sourceTemplate, 
destDataStore);
+        } catch (AgentUnavailableException | OperationTimedoutException e) {
+            throw new CloudRuntimeException(String.format("Failed to copy 
template [id=%s, name=%s] to the primary storage pool [id=%s].", 
sourceTemplate.getId(),
+                    sourceTemplate.getName(), destDataStore.getId()), e);
+        }
+    }
+
+    /**
+     * Logs in debug mode the copy command failure if the CopyCommand Answer 
has result as false.
+     */
+    protected void logInCaseOfTemplateCopyFailure(Answer copyCommandAnswer, 
TemplateObjectTO sourceTemplate, DataStore destDataStore) {
+        if (copyCommandAnswer != null && !copyCommandAnswer.getResult()) {
+            String failureDetails = StringUtils.EMPTY;
+            if (copyCommandAnswer.getDetails() != null) {
+                failureDetails = "; details: " + 
copyCommandAnswer.getDetails();
+            }
+            LOGGER.debug(String.format("Failed to copy template [id=%s, 
name=%s] to the primary storage pool [id=%s]%s", sourceTemplate.getId(), 
sourceTemplate.getName(),
 
 Review comment:
   seems like an 'ERROR' to me

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to