cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [1/2] git commit: updated refs/heads/object_store to ac7be21
Date Wed, 08 May 2013 03:18:51 GMT
Updated Branches:
  refs/heads/object_store ac1b75dc9 -> ac7be218d


creat template from volume/snapshot, and then create vm from template works now


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

Branch: refs/heads/object_store
Commit: ac7be218d55778e3e22d608b33dec4e0eea457c6
Parents: 5aeca64
Author: Edison Su <sudison@gmail.com>
Authored: Tue May 7 20:15:35 2013 -0700
Committer: Edison Su <sudison@gmail.com>
Committed: Tue May 7 20:18:19 2013 -0700

----------------------------------------------------------------------
 .../resource/NfsSecondaryStorageResource.java      |    8 ++-
 .../storage/image/TemplateServiceImpl.java         |    4 +-
 .../storage/image/store/TemplateObject.java        |   35 +++++++++++++++
 .../xen/resource/XenServerStorageResource.java     |    1 +
 .../com/cloud/template/TemplateManagerImpl.java    |   19 +++++++-
 5 files changed, 59 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac7be218/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
index e9ec839..384a41a 100755
--- a/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
+++ b/core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java
@@ -107,6 +107,7 @@ import com.cloud.host.Host.Type;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.resource.ServerResourceBase;
 import com.cloud.storage.DataStoreRole;
+import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.StorageLayer;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
 import com.cloud.storage.template.DownloadManager;
@@ -298,9 +299,9 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
             snapshotName = snapshotName + ".vhd";
         }
         snapshotPath = snapshotPath.substring(0, index);
-        snapshotPath = srcMountPoint + snapshotPath;
+        snapshotPath = srcMountPoint + File.separator + snapshotPath;
         String destMountPoint = this.getRootDir(destDataStore.getUrl());
-        String destPath = destMountPoint + destData.getPath();
+        String destPath = destMountPoint + File.separator + destData.getPath();
 
         String errMsg = null;
         try {
@@ -329,7 +330,8 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements
S
             loc.save();
 
             TemplateObjectTO newTemplate = new TemplateObjectTO();
-            newTemplate.setPath(destData.getPath() + File.separator + templateUuid); 
+            newTemplate.setPath(destData.getPath() + File.separator + templateName); 
+            newTemplate.setFormat(ImageFormat.VHD);
             return new CopyCmdAnswer(newTemplate);
         } catch (ConfigurationException e) {
             s_logger.debug("Failed to create template from snapshot: " + e.toString());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac7be218/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
index b19fc65..95c6b39 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
@@ -396,7 +396,7 @@ public class TemplateServiceImpl implements TemplateService {
             if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
                 //TODO: we cannot directly call deleteTemplateSync here to reuse delete logic
since in this case, our db does not have this template at all.
                 VMTemplateVO template = _templateDao.findById(tInfo.getId());
-                DeleteTemplateCommand dtCommand = new DeleteTemplateCommand(store.getTO(),
tInfo.getInstallPath(), template.getId(), template.getAccountId());
+                DeleteTemplateCommand dtCommand = new DeleteTemplateCommand(store.getTO(),
tInfo.getInstallPath(), null, null);
                 EndPoint ep = _epSelector.select(store);
                 Answer answer = ep.sendMessage(dtCommand);
                 if (answer == null || !answer.getResult()) {
@@ -574,7 +574,7 @@ public class TemplateServiceImpl implements TemplateService {
                 // remove entry from template_store_ref
                 destTemplate.getDataStore().delete(destTemplate);
             } else {
-                destTemplate.processEvent(Event.OperationSuccessed);
+                destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
             }
             future.complete(res);
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac7be218/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 7ff0cc3..37317b0 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
@@ -163,6 +163,7 @@ public class TemplateObject implements TemplateInfo {
     }
 
     public boolean stateTransit(TemplateEvent e) throws NoTransitionException {
+        this.imageVO = imageDao.findById(this.imageVO.getId());
         boolean result= imageMgr.getStateMachine().transitTo(this.imageVO, e, null,
                 imageDao);
         this.imageVO = imageDao.findById(this.imageVO.getId());
@@ -172,6 +173,22 @@ public class TemplateObject implements TemplateInfo {
     @Override
     public void processEvent(Event event) {
         try {
+            if (this.getDataStore().getRole() == DataStoreRole.Image ||
+                    this.getDataStore().getRole() == DataStoreRole.ImageCache) {
+                TemplateEvent templEvent = null;
+                if (event == ObjectInDataStoreStateMachine.Event.CreateOnlyRequested) {
+                    templEvent = TemplateEvent.CreateRequested;
+                } else if (event == ObjectInDataStoreStateMachine.Event.OperationSuccessed)
{
+                    templEvent = TemplateEvent.OperationSucceeded;
+                } else if (event == ObjectInDataStoreStateMachine.Event.OperationFailed)
{
+                    templEvent = TemplateEvent.OperationFailed;
+                }
+                
+                if (templEvent != null) {
+                    this.stateTransit(templEvent);
+                }
+            }
+                
             ojbectInStoreMgr.update(this, event);
         } catch (NoTransitionException e) {
             s_logger.debug("failed to update state", e);
@@ -201,7 +218,25 @@ public class TemplateObject implements TemplateInfo {
         			TemplateDataStoreVO templateStoreRef = this.templateStoreDao.findByStoreTemplate(this.getDataStore().getId(),
         					this.getId());
         			templateStoreRef.setInstallPath(newTemplate.getPath());
+        			templateStoreRef.setDownloadPercent(100);
+        			templateStoreRef.setDownloadState(Status.DOWNLOADED);
         			templateStoreDao.update(templateStoreRef.getId(), templateStoreRef);
+        			VMTemplateVO templateVO = this.imageDao.findById(this.getId());
+        			templateVO.setFormat(newTemplate.getFormat());
+        			this.imageDao.update(templateVO.getId(), templateVO);
+        		}
+        		
+        		TemplateEvent templEvent = null;
+        		if (event == ObjectInDataStoreStateMachine.Event.CreateOnlyRequested) {
+        		    templEvent = TemplateEvent.CreateRequested;
+        		} else if (event == ObjectInDataStoreStateMachine.Event.OperationSuccessed) {
+        		    templEvent = TemplateEvent.OperationSucceeded;
+        		} else if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
+        		    templEvent = TemplateEvent.OperationFailed;
+        		}
+        		
+        		if (templEvent != null) {
+        		    this.stateTransit(templEvent);
         		}
         	}
             ojbectInStoreMgr.update(this, event);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac7be218/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageResource.java
b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageResource.java
index fc3a0dd..8b27efe 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageResource.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServerStorageResource.java
@@ -1275,6 +1275,7 @@ public class XenServerStorageResource {
             tmpltSR = null;
             TemplateObjectTO newTemplate = new TemplateObjectTO();
             newTemplate.setPath(installPath);
+            newTemplate.setFormat(ImageFormat.VHD);
             CopyCmdAnswer answer = new CopyCmdAnswer(newTemplate);
             return answer;
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ac7be218/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 09cce63..46c4c0a 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -22,6 +22,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
@@ -127,6 +128,7 @@ import com.cloud.storage.StoragePoolStatus;
 import com.cloud.storage.TemplateProfile;
 import com.cloud.storage.Upload;
 import com.cloud.storage.Upload.Type;
+import com.cloud.storage.VMTemplateZoneVO;
 
 import com.cloud.storage.UploadVO;
 import com.cloud.storage.VMTemplateHostVO;
@@ -1347,8 +1349,16 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
 
         try {
             TemplateInfo tmplInfo = this._tmplFactory.getTemplate(templateId);
-            snapshot = _snapshotDao.findById(snapshotId);
-            ZoneScope scope = new ZoneScope(snapshot.getDataCenterId());
+            Long zoneId = null;
+            if (snapshotId != null) {
+                snapshot = _snapshotDao.findById(snapshotId);
+                zoneId = snapshot.getDataCenterId();
+
+            } else if (volumeId != null) {
+                volume = _volumeDao.findById(volumeId);
+                zoneId = volume.getDataCenterId();
+            }
+            ZoneScope scope = new ZoneScope(zoneId);
             List<DataStore> store = this._dataStoreMgr.getImageStoresByScope(scope);
             if (store.size() > 1) {
                 throw new CloudRuntimeException("muliple image data store, don't know which
one to use");
@@ -1374,12 +1384,15 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
                     s_logger.debug("Failed to create template" + result.getResult());
                     throw new CloudRuntimeException("Failed to create template" + result.getResult());
                 }
+                
+                VMTemplateZoneVO templateZone = new VMTemplateZoneVO(zoneId, templateId,
new Date());
+                this._tmpltZoneDao.persist(templateZone);
 
                 privateTemplate = this._tmpltDao.findById(templateId);
                 UsageEventVO usageEvent = new UsageEventVO(
                         EventTypes.EVENT_TEMPLATE_CREATE,
                         privateTemplate.getAccountId(),
-                        snapshot.getDataCenterId(),
+                        zoneId,
                         privateTemplate.getId(), privateTemplate.getName(),
                         null, privateTemplate.getSourceTemplateId(),
                         privateTemplate.getSize());


Mime
View raw message