cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [2/2] git commit: updated refs/heads/object_store to 8a95620
Date Wed, 22 May 2013 21:35:39 GMT
CLOUDSTACK-2584: set Format value in CopyCommand.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/03909846
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/03909846
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/03909846

Branch: refs/heads/object_store
Commit: 039098469a445cefb7d45177872f8d886cb6c1ef
Parents: eb0a748
Author: Min Chen <min.chen@citrix.com>
Authored: Wed May 22 14:31:53 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Wed May 22 14:33:40 2013 -0700

----------------------------------------------------------------------
 .../storage/image/store/TemplateObject.java        |    4 ++
 .../datastore/ObjectInDataStoreManagerImpl.java    |    9 +++-
 .../com/cloud/template/TemplateManagerImpl.java    |    4 +-
 .../resource/NfsSecondaryStorageResource.java      |   41 ++++++++++++---
 .../storage/template/DownloadManagerImpl.java      |    3 -
 5 files changed, 49 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03909846/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
index feff54e..b17fc3d 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/store/TemplateObject.java
@@ -256,6 +256,10 @@ public class TemplateObject implements TemplateInfo {
         } catch (NoTransitionException e) {
             s_logger.debug("failed to update state", e);
             throw new CloudRuntimeException("Failed to update state" + e.toString());
+        } catch (Exception ex){
+            s_logger.debug("failed to process event and answer", ex);
+            objectInStoreMgr.delete(this);
+            throw new CloudRuntimeException("Failed to process event", ex);
         } finally{
             // in case of OperationFailed, expunge the entry
             if ( event == ObjectInDataStoreStateMachine.Event.OperationFailed){

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03909846/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
index f2ec961..daeaf7c 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
@@ -25,6 +25,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateState;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
@@ -43,6 +44,7 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import com.cloud.agent.api.to.DataObjectType;
+import com.cloud.agent.api.to.S3TO;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.VMTemplateStoragePoolVO;
 import com.cloud.storage.dao.SnapshotDao;
@@ -136,7 +138,12 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager
{
                 ts.setTemplateId(obj.getId());
                 ts.setDataStoreId(dataStore.getId());
                 ts.setDataStoreRole(dataStore.getRole());
-                ts.setInstallPath(TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR
 + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId());
+                String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR
 + templateDao.findById(obj.getId()).getAccountId() + "/" + obj.getId();
+                if ( dataStore.getTO() instanceof S3TO ){
+                    TemplateInfo tmpl = (TemplateInfo)obj;
+                    installPath +=  "/" + tmpl.getUniqueName(); // for S3, we append template
name in the path for template sync since we don't have template.properties there
+                }
+                ts.setInstallPath(installPath);
                 ts.setState(ObjectInDataStoreStateMachine.State.Allocated);
                 ts = templateDataStoreDao.persist(ts);
                 break;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03909846/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index 21615c9..c5e80b0 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -1456,7 +1456,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
             if (privateTemplate == null) {
                 Transaction txn = Transaction.currentTxn();
                 txn.start();
-                // template_store_ref entries should have been removed using our DataObject.processEvent
command in case of failure.
+                // template_store_ref entries should have been removed using our DataObject.processEvent
command in case of failure, but clean it up here to avoid
+                // some leftovers which will cause removing template from vm_template table
fail.
+                this._tmplStoreDao.deletePrimaryRecordsForTemplate(templateId);
                 // Remove the template_zone_ref record
                 this._tmpltZoneDao.deletePrimaryRecordsForTemplate(templateId);
                 // Remove the template record

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03909846/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index eee7e27..a7c409d 100755
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -426,11 +426,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
         }
         return new CopyCmdAnswer("");
     }
-    
+
     protected Answer copyFromNfsToImage(CopyCommand cmd) {
            DataTO destData = cmd.getDestTO();
            DataStoreTO destDataStore = destData.getDataStore();
-           
+
            if (destDataStore instanceof S3TO) {
         	   return copyFromNfsToS3(cmd);
            } else {
@@ -453,7 +453,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
             NfsTO destImageStore = (NfsTO)destDataStore;
             return this.copyFromS3ToNfs(cmd, srcData, s3, destData, destImageStore);
         }
-        
+
         if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole()
== DataStoreRole.Image) {
         	return copyFromNfsToImage(cmd);
         }
@@ -625,15 +625,40 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
         }
     }
 
+    private ImageFormat getTemplateFormat(String filePath){
+        String ext = null;
+        int extensionPos = filePath.lastIndexOf('.');
+        int lastSeparator = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\'));
+        int i =  lastSeparator > extensionPos ? -1 : extensionPos;
+        if (i > 0 ) {
+            ext = filePath.substring(i+1);
+        }
+        if ( ext != null){
+            if ( ext.equalsIgnoreCase("vhd"))
+                return ImageFormat.VHD;
+            else if (ext.equalsIgnoreCase("qcow2"))
+                return ImageFormat.QCOW2;
+            else if (ext.equalsIgnoreCase("ova"))
+                return ImageFormat.OVA;
+            else if (ext.equalsIgnoreCase("tar"))
+                return ImageFormat.TAR;
+            else if (ext.equalsIgnoreCase("img"))
+                return ImageFormat.RAW;
+        }
+
+        return null;
+
+    }
+
     protected Answer copyFromNfsToS3(CopyCommand cmd) {
     	 final DataTO srcData = cmd.getSrcTO();
          final DataTO destData = cmd.getDestTO();
          DataStoreTO srcDataStore = srcData.getDataStore();
          NfsTO srcStore = (NfsTO)srcDataStore;
          DataStoreTO destDataStore = destData.getDataStore();
-         
+
          final S3TO s3 = (S3TO)destDataStore;
-    
+
         try {
             final String templatePath = determineStorageTemplatePath(
             		srcStore.getUrl(), srcData.getPath());
@@ -645,14 +670,16 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
 
             final String bucket = s3.getBucketName();
             final File srcFile = _storage.getFile(templatePath);
+            ImageFormat format = this.getTemplateFormat(templatePath);
             String key = destData.getPath() + S3Utils.SEPARATOR + srcFile.getName();
             putFile(s3, srcFile, bucket, key);
-                  
+
             DataTO retObj = null;
             if (destData.getObjectType() == DataObjectType.TEMPLATE) {
             	TemplateObjectTO newTemplate = new TemplateObjectTO();
             	newTemplate.setPath(key);
             	newTemplate.setSize(srcFile.length());
+            	newTemplate.setFormat(format);
             	retObj = newTemplate;
             } else if (destData.getObjectType() == DataObjectType.VOLUME) {
             	VolumeObjectTO newVol = new VolumeObjectTO();
@@ -660,7 +687,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
             	newVol.setSize(srcFile.length());
             	retObj = newVol;
             }
-            
+
             return new CopyCmdAnswer(retObj);
         } catch (Exception e) {
             s_logger.error("failed to upload" + srcData.getPath(), e);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03909846/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
b/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
index dc08ba6..509364b 100755
--- a/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
+++ b/services/secondary-storage/src/org/apache/cloudstack/storage/template/DownloadManagerImpl.java
@@ -697,9 +697,6 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
             } else {
                 installPathPrefix = resource.getRootDir(cmd) + File.separator + installPathPrefix;
             }
-        } else if (dstore instanceof S3TO) {
-            // S3 key has template name inside to help template sync
-            installPathPrefix = installPathPrefix + File.separator + cmd.getName();
         }
         String user = null;
         String password = null;


Mime
View raw message