cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject git commit: updated refs/heads/master to 3160a0c
Date Thu, 27 Jun 2013 21:34:10 GMT
Updated Branches:
  refs/heads/master c8692f2e4 -> 3160a0c2d


Add template zone related information into TemplateZoneResponse.


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

Branch: refs/heads/master
Commit: 3160a0c2da8036d861594d2286f6a595a41da270
Parents: c8692f2
Author: Min Chen <min.chen@citrix.com>
Authored: Thu Jun 27 14:02:25 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Thu Jun 27 14:34:00 2013 -0700

----------------------------------------------------------------------
 .../api/response/TemplateZoneResponse.java      | 53 ++++++++++--
 .../api/query/dao/TemplateJoinDaoImpl.java      | 84 +++++++++++++-------
 2 files changed, 104 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3160a0c2/api/src/org/apache/cloudstack/api/response/TemplateZoneResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/TemplateZoneResponse.java b/api/src/org/apache/cloudstack/api/response/TemplateZoneResponse.java
index 9d26ad9..3af9a2f 100644
--- a/api/src/org/apache/cloudstack/api/response/TemplateZoneResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/TemplateZoneResponse.java
@@ -16,6 +16,8 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
+import java.util.Date;
+
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
 
@@ -29,6 +31,15 @@ public class TemplateZoneResponse extends BaseResponse {
     @SerializedName(ApiConstants.ZONE_NAME) @Param(description="the name of the zone for
the template")
     private String zoneName;
 
+    @SerializedName(ApiConstants.STATUS) @Param(description="the status of the template")
+    private String status;
+
+    @SerializedName(ApiConstants.IS_READY) // propName="ready"  (FIXME:  this used to be
part of Param annotation, do we need it?)
+    @Param(description="true if the template is ready to be deployed from, false otherwise.")
+    private boolean isReady;
+
+    @SerializedName(ApiConstants.CREATED) @Param(description="the date this template was
created")
+    private Date created;
 
     public TemplateZoneResponse(){
         super();
@@ -58,6 +69,31 @@ public class TemplateZoneResponse extends BaseResponse {
         this.zoneName = zoneName;
     }
 
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public boolean isReady() {
+        return isReady;
+    }
+
+    public void setReady(boolean isReady) {
+        this.isReady = isReady;
+    }
+
+    public Date getCreated() {
+        return created;
+    }
+
+    public void setCreated(Date created) {
+        this.created = created;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -69,21 +105,26 @@ public class TemplateZoneResponse extends BaseResponse {
 
     @Override
     public boolean equals(Object obj) {
-        if (this == obj)
+        if (this == obj) {
             return true;
-        if (obj == null)
+        }
+        if (obj == null) {
             return false;
-        if (getClass() != obj.getClass())
+        }
+        if (getClass() != obj.getClass()) {
             return false;
+        }
         TemplateZoneResponse other = (TemplateZoneResponse) obj;
         String oid = this.getZoneId();
         if (oid == null) {
-            if (other.getZoneId() != null)
+            if (other.getZoneId() != null) {
                 return false;
-        } else if (!oid.equals(other.getZoneId()))
+            }
+        } else if (!oid.equals(other.getZoneId())) {
             return false;
-        else if ( this.getZoneName().equals(other.getZoneName()))
+        } else if ( this.getZoneName().equals(other.getZoneName())) {
             return false;
+        }
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3160a0c2/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
index d4c9560..a31a036 100644
--- a/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/TemplateJoinDaoImpl.java
@@ -38,8 +38,8 @@ import com.cloud.api.query.vo.ResourceTagJoinVO;
 import com.cloud.api.query.vo.TemplateJoinVO;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.storage.Storage;
-import com.cloud.storage.VMTemplateHostVO;
 import com.cloud.storage.Storage.TemplateType;
+import com.cloud.storage.VMTemplateHostVO;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
 import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.Account;
@@ -96,6 +96,36 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO,
Long> im
 
 
 
+    private String getTemplateStatus(TemplateJoinVO template){
+        boolean isAdmin = false;
+        Account caller = UserContext.current().getCaller();
+        if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
+            isAdmin = true;
+        }
+
+        // If the user is an Admin, add the template download status
+        String templateStatus = null;
+        if (isAdmin || caller.getId() == template.getAccountId()) {
+            // add download status
+            if (template.getDownloadState() != Status.DOWNLOADED) {
+                templateStatus = "Processing";
+                if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS)
{
+                    if (template.getDownloadPercent() == 100) {
+                        templateStatus = "Installing Template";
+                    } else {
+                        templateStatus = template.getDownloadPercent() + "% Downloaded";
+                    }
+                } else {
+                    templateStatus = template.getErrorString();
+                }
+            } else if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED)
{
+                templateStatus = "Download Complete";
+            } else {
+                templateStatus = "Successfully Installed";
+            }
+        }
+        return templateStatus;
+    }
 
     @Override
     public TemplateResponse newTemplateResponse(TemplateJoinVO template) {
@@ -136,33 +166,10 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO,
Long> im
         templateResponse.setDomainName(template.getDomainName());
 
 
-
-        boolean isAdmin = false;
-        Account caller = UserContext.current().getCaller();
-        if ((caller == null) || BaseCmd.isAdmin(caller.getType())) {
-            isAdmin = true;
-        }
-
         // If the user is an Admin, add the template download status
-        if (isAdmin || caller.getId() == template.getAccountId()) {
-            // add download status
-            if (template.getDownloadState() != Status.DOWNLOADED) {
-                String templateStatus = "Processing";
-                if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS)
{
-                    if (template.getDownloadPercent() == 100) {
-                        templateStatus = "Installing Template";
-                    } else {
-                        templateStatus = template.getDownloadPercent() + "% Downloaded";
-                    }
-                } else {
-                    templateStatus = template.getErrorString();
-                }
-                templateResponse.setStatus(templateStatus);
-            } else if (template.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED)
{
-                templateResponse.setStatus("Download Complete");
-            } else {
-                templateResponse.setStatus("Successfully Installed");
-            }
+        String templateStatus = getTemplateStatus(template);
+        if ( templateStatus != null ){
+            templateResponse.setStatus(templateStatus);
         }
 
         Long templateSize = template.getSize();
@@ -179,6 +186,17 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO,
Long> im
         // set template zone information
         if (template.getDataCenterId() > 0 ){
             TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(template.getDataCenterUuid(),
template.getDataCenterName());
+            tmplZoneResp.setCreated(template.getCreatedOnStore());
+            if ( template.getFormat() == Storage.ImageFormat.BAREMETAL ){
+                // for baremetal template, we didn't download, but is ready to use.
+                tmplZoneResp.setReady(true);
+            }
+            else{
+                tmplZoneResp.setReady(template.getState() == ObjectInDataStoreStateMachine.State.Ready);
+            }
+            if ( templateStatus != null ){
+                tmplZoneResp.setStatus(templateStatus);
+            }
             templateResponse.addZone(tmplZoneResp);
             // set the first found associated zone directly in TemplateResponse
             templateResponse.setZoneId(template.getDataCenterUuid());
@@ -259,6 +277,18 @@ public class TemplateJoinDaoImpl extends GenericDaoBase<TemplateJoinVO,
Long> im
         // update template zone information
         if (template.getDataCenterId() > 0 ){
             TemplateZoneResponse tmplZoneResp = new TemplateZoneResponse(template.getDataCenterUuid(),
template.getDataCenterName());
+            tmplZoneResp.setCreated(template.getCreatedOnStore());
+            if ( template.getFormat() == Storage.ImageFormat.BAREMETAL ){
+                // for baremetal template, we didn't download, but is ready to use.
+                tmplZoneResp.setReady(true);
+            }
+            else{
+                tmplZoneResp.setReady(template.getState() == ObjectInDataStoreStateMachine.State.Ready);
+            }
+            String templateStatus = getTemplateStatus(template);
+            if ( templateStatus != null ){
+                tmplZoneResp.setStatus(templateStatus);
+            }
             templateResponse.addZone(tmplZoneResp);
             if (templateResponse.getZoneId() == null) {
                 // set the first found associated zone directly in


Mime
View raw message