cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [1/3] git commit: updated refs/heads/master to e384f2d
Date Wed, 19 Aug 2015 10:30:27 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 48bed3f34 -> e384f2d14


CLOUDSTACK-8687: Update prepare template api to seed/prepare a template
only on a given primary storage. Currently, the prepare template api
will seed/prepare a given template on all the primary storage pools in
a zone. If however, a user wishes to prepare a template only a
particular storage pool, it isn't possible. Updated the api to take
storage pool id as an optional parameter. If the pool id is provided
then the template is prepared only on the given primary storage pool


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

Branch: refs/heads/master
Commit: adf6b588ddb2d61bc4aa8ed4c02edaf292fa825e
Parents: 3006b16
Author: Devdeep Singh <devdeep@gmail.com>
Authored: Tue Jul 28 12:05:35 2015 +0530
Committer: Devdeep Singh <devdeep@gmail.com>
Committed: Wed Aug 19 10:04:05 2015 +0530

----------------------------------------------------------------------
 .../com/cloud/template/TemplateApiService.java  |  2 +-
 .../admin/template/PrepareTemplateCmd.java      | 16 +++++-
 .../com/cloud/template/TemplateManagerImpl.java | 56 +++++++++++++-------
 3 files changed, 52 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adf6b588/api/src/com/cloud/template/TemplateApiService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/template/TemplateApiService.java b/api/src/com/cloud/template/TemplateApiService.java
index 43177fc..7348547 100644
--- a/api/src/com/cloud/template/TemplateApiService.java
+++ b/api/src/com/cloud/template/TemplateApiService.java
@@ -51,7 +51,7 @@ public interface TemplateApiService {
 
     VirtualMachineTemplate copyTemplate(CopyTemplateCmd cmd) throws StorageUnavailableException,
ResourceAllocationException;
 
-    VirtualMachineTemplate prepareTemplate(long templateId, long zoneId);
+    VirtualMachineTemplate prepareTemplate(long templateId, long zoneId, Long storageId);
 
     boolean detachIso(long vmId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adf6b588/api/src/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java
b/api/src/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java
index d4c2696..0537c01 100644
--- a/api/src/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/admin/template/PrepareTemplateCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.BaseCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ResponseObject.ResponseView;
 import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.StoragePoolResponse;
 import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
 
@@ -60,6 +61,15 @@ public class PrepareTemplateCmd extends BaseCmd {
                description = "template ID of the template to be prepared in primary storage(s).")
     private Long templateId;
 
+    @ACL(accessType = AccessType.OperateEntry)
+    @Parameter(name = ApiConstants.STORAGE_ID,
+            type = CommandType.UUID,
+            entityType = StoragePoolResponse.class,
+            required = false,
+            description = "storage pool ID of the primary storage pool to which the template
should be prepared. If it is not provided the template" +
+                    " is prepared on all the available primary storage pools.")
+    private Long storageId;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -72,6 +82,10 @@ public class PrepareTemplateCmd extends BaseCmd {
         return templateId;
     }
 
+    public Long getStorageId() {
+        return storageId;
+    }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////
@@ -90,7 +104,7 @@ public class PrepareTemplateCmd extends BaseCmd {
     public void execute() {
         ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
 
-        VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId,
zoneId);
+        VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId,
zoneId, storageId);
         List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(ResponseView.Full,
vmTemplate, zoneId, true);
         response.setResponses(templateResponses);
         response.setResponseName(getCommandName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/adf6b588/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 6e9af8a..0eeab57 100644
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -436,7 +436,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
     }
 
     @Override
-    public VirtualMachineTemplate prepareTemplate(long templateId, long zoneId) {
+    public VirtualMachineTemplate prepareTemplate(long templateId, long zoneId, Long storageId)
{
 
         VMTemplateVO vmTemplate = _tmpltDao.findById(templateId);
         if (vmTemplate == null) {
@@ -445,7 +445,19 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
 
         _accountMgr.checkAccess(CallContext.current().getCallingAccount(), AccessType.OperateEntry,
true, vmTemplate);
 
-        prepareTemplateInAllStoragePools(vmTemplate, zoneId);
+        if (storageId != null) {
+            StoragePoolVO pool = _poolDao.findById(storageId);
+            if (pool != null) {
+                if (pool.getStatus() == StoragePoolStatus.Up && pool.getDataCenterId()
== zoneId) {
+                    prepareTemplateInOneStoragePool(vmTemplate, pool);
+                } else {
+                    s_logger.warn("Skip loading template " + vmTemplate.getId() + " into
primary storage " + pool.getId() + " as either the pool zone "
+                            + pool.getDataCenterId() + " is different from the requested
zone " + zoneId + " or the pool is currently not available.");
+                }
+            }
+        } else {
+            prepareTemplateInAllStoragePools(vmTemplate, zoneId);
+        }
         return vmTemplate;
     }
 
@@ -556,28 +568,32 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
         }
     }
 
+    private void prepareTemplateInOneStoragePool(final VMTemplateVO template, final StoragePoolVO
pool) {
+        s_logger.info("Schedule to preload template " + template.getId() + " into primary
storage " + pool.getId());
+        _preloadExecutor.execute(new ManagedContextRunnable() {
+            @Override
+            protected void runInContext() {
+                try {
+                    reallyRun();
+                } catch (Throwable e) {
+                    s_logger.warn("Unexpected exception ", e);
+                }
+            }
+
+            private void reallyRun() {
+                s_logger.info("Start to preload template " + template.getId() + " into primary
storage " + pool.getId());
+                StoragePool pol = (StoragePool)_dataStoreMgr.getPrimaryDataStore(pool.getId());
+                prepareTemplateForCreate(template, pol);
+                s_logger.info("End of preloading template " + template.getId() + " into primary
storage " + pool.getId());
+            }
+        });
+    }
+
     public void prepareTemplateInAllStoragePools(final VMTemplateVO template, long zoneId)
{
         List<StoragePoolVO> pools = _poolDao.listByStatus(StoragePoolStatus.Up);
         for (final StoragePoolVO pool : pools) {
             if (pool.getDataCenterId() == zoneId) {
-                s_logger.info("Schedule to preload template " + template.getId() + " into
primary storage " + pool.getId());
-                _preloadExecutor.execute(new ManagedContextRunnable() {
-                    @Override
-                    protected void runInContext() {
-                        try {
-                            reallyRun();
-                        } catch (Throwable e) {
-                            s_logger.warn("Unexpected exception ", e);
-                        }
-                    }
-
-                    private void reallyRun() {
-                        s_logger.info("Start to preload template " + template.getId() + "
into primary storage " + pool.getId());
-                        StoragePool pol = (StoragePool)_dataStoreMgr.getPrimaryDataStore(pool.getId());
-                        prepareTemplateForCreate(template, pol);
-                        s_logger.info("End of preloading template " + template.getId() +
" into primary storage " + pool.getId());
-                    }
-                });
+                prepareTemplateInOneStoragePool(template, pool);
             } else {
                 s_logger.info("Skip loading template " + template.getId() + " into primary
storage " + pool.getId() + " as pool zone " + pool.getDataCenterId() +
                         " is different from the requested zone " + zoneId);


Mime
View raw message