You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/04/20 02:10:52 UTC

[4/5] git commit: updated refs/heads/object_store to 09ba551

Refactor listTemplatesCmd and listIsoCmd to use db view.

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

Branch: refs/heads/object_store
Commit: 539824797c01a992d3f7868f5ad18848e066dbca
Parents: 7ba1a8f
Author: Min Chen <mi...@citrix.com>
Authored: Fri Apr 19 16:10:09 2013 -0700
Committer: Min Chen <mi...@citrix.com>
Committed: Fri Apr 19 16:10:09 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/server/ManagementService.java    |   22 -
 .../apache/cloudstack/api/ResponseGenerator.java   |   14 +-
 .../command/admin/template/PrepareTemplateCmd.java |    2 +-
 .../api/command/user/iso/ListIsosCmd.java          |   11 +-
 .../api/command/user/iso/RegisterIsoCmd.java       |    6 +-
 .../api/command/user/iso/UpdateIsoCmd.java         |    2 +-
 .../api/command/user/template/CopyTemplateCmd.java |    2 +-
 .../command/user/template/ListTemplatesCmd.java    |   16 +-
 .../command/user/template/RegisterTemplateCmd.java |    2 +-
 .../command/user/template/UpdateTemplateCmd.java   |    2 +-
 .../cloudstack/api/response/TemplateResponse.java  |   35 +-
 .../api/response/TemplateZoneResponse.java         |   90 ++
 .../org/apache/cloudstack/query/QueryService.java  |    7 +
 server/src/com/cloud/api/ApiDBUtils.java           |   36 +
 server/src/com/cloud/api/ApiResponseHelper.java    |  838 +++++--------
 .../src/com/cloud/api/query/QueryManagerImpl.java  |  321 +++++
 .../com/cloud/api/query/ViewResponseHelper.java    |   53 +
 .../com/cloud/api/query/dao/TemplateJoinDao.java   |   42 +
 .../cloud/api/query/dao/TemplateJoinDaoImpl.java   |  441 +++++++
 .../src/com/cloud/api/query/vo/TemplateJoinVO.java | 1006 +++++++++++++++
 .../src/com/cloud/server/ManagementServerImpl.java |   66 +-
 .../src/com/cloud/storage/dao/VMTemplateDao.java   |   17 +-
 .../com/cloud/storage/dao/VMTemplateDaoImpl.java   |   36 +-
 .../com/cloud/template/TemplateManagerImpl.java    |    1 +
 setup/db/db/schema-410to420.sql                    |   95 ++
 25 files changed, 2472 insertions(+), 691 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/com/cloud/server/ManagementService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/server/ManagementService.java b/api/src/com/cloud/server/ManagementService.java
index d58ea3e..674f67c 100755
--- a/api/src/com/cloud/server/ManagementService.java
+++ b/api/src/com/cloud/server/ManagementService.java
@@ -219,28 +219,6 @@ public interface ManagementService {
      */
     List<? extends Capacity> listCapacities(ListCapacityCmd cmd);
 
-    /**
-     * List ISOs that match the specified criteria.
-     *
-     * @param cmd
-     *            The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account,
-     *            and zoneId
-     *            parameters.
-     * @return list of ISOs
-     */
-    Set<Pair<Long, Long>> listIsos(ListIsosCmd cmd);
-
-    /**
-     * List templates that match the specified criteria.
-     *
-     * @param cmd
-     *            The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account,
-     *            and zoneId
-     *            parameters.
-     * @return list of ISOs
-     */
-    Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd);
-
 
     /**
      * List system VMs by the given search criteria

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index 3d381b0..77d3bea 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -241,7 +241,7 @@ public interface ResponseGenerator {
 
     Host findHostById(Long hostId);
 
-    List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
+    //List<TemplateResponse> createTemplateResponses(long templateId, long zoneId, boolean readyOnly);
 
     VpnUsersResponse createVpnUserResponse(VpnUser user);
 
@@ -267,7 +267,9 @@ public interface ResponseGenerator {
 
     //List<EventResponse> createEventResponse(EventJoinVO... events);
 
-    TemplateResponse createIsoResponse(VirtualMachineTemplate result);
+    TemplateResponse createTemplateUpdateResponse(VirtualMachineTemplate result);
+
+    List<TemplateResponse> createTemplateResponses(VirtualMachineTemplate result, Long zoneId, boolean readyOnly);
 
     List<CapacityResponse> createCapacityResponse(List<? extends Capacity> result, DecimalFormat format);
 
@@ -287,12 +289,12 @@ public interface ResponseGenerator {
 
     Long getSecurityGroupId(String groupName, long accountId);
 
-    List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
-
-    ProjectResponse createProjectResponse(Project project);
+    List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, Long zoneId, boolean readyOnly);
 
+   // List<TemplateResponse> createIsoResponses(long isoId, Long zoneId, boolean readyOnly);
+    //List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
 
-    List<TemplateResponse> createIsoResponses(VirtualMachineTemplate iso, long zoneId, boolean readyOnly);
+    ProjectResponse createProjectResponse(Project project);
 
     List<TemplateResponse> createTemplateResponses(long templateId, Long vmId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/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 7d41d10..aee35ad 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
@@ -80,7 +80,7 @@ public class PrepareTemplateCmd extends BaseCmd {
         ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
 
         VirtualMachineTemplate vmTemplate = _templateService.prepareTemplate(templateId, zoneId);
-        List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(vmTemplate.getId(), zoneId, true);
+        List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(vmTemplate, zoneId, true);
         response.setResponses(templateResponses);
         response.setResponseName(getCommandName());
         this.setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
index 3219601..b490ca9 100644
--- a/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/iso/ListIsosCmd.java
@@ -148,16 +148,7 @@ public class ListIsosCmd extends BaseListTaggedResourcesCmd {
 
     @Override
     public void execute(){
-        Set<Pair<Long, Long>> isoZonePairSet = _mgr.listIsos(this);
-        ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-        List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
-
-        for (Pair<Long, Long> iso : isoZonePairSet) {
-            List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
-            responses = _responseGenerator.createIsoResponses(iso.first(), iso.second(), listInReadyState());
-            templateResponses.addAll(responses);
-        }
-        response.setResponses(templateResponses);
+        ListResponse<TemplateResponse> response = _queryService.listIsos(this);
         response.setResponseName(getCommandName());
         this.setResponseObject(response);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java
index 284d553..0fa47eb 100644
--- a/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/iso/RegisterIsoCmd.java
@@ -88,7 +88,7 @@ public class RegisterIsoCmd extends BaseCmd {
     @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
             description="Register iso for the project")
     private Long projectId;
-    
+
     @Parameter(name=ApiConstants.IMAGE_STORE_UUID, type=CommandType.STRING,
             description="Image store uuid")
     private String imageStoreUuid;
@@ -144,7 +144,7 @@ public class RegisterIsoCmd extends BaseCmd {
     public String getChecksum() {
         return checksum;
     }
-    
+
     public String getImageStoreUuid() {
         return this.imageStoreUuid;
     }
@@ -173,7 +173,7 @@ public class RegisterIsoCmd extends BaseCmd {
         VirtualMachineTemplate template = _templateService.registerIso(this);
         if (template != null) {
             ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-            List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template.getId(), zoneId, false);
+            List<TemplateResponse> templateResponses = _responseGenerator.createIsoResponses(template, zoneId, false);
             response.setResponses(templateResponses);
             response.setResponseName(getCommandName());
             this.setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java b/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java
index 1384fa8..1d84847 100644
--- a/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/iso/UpdateIsoCmd.java
@@ -68,7 +68,7 @@ public class UpdateIsoCmd extends BaseUpdateTemplateOrIsoCmd {
     public void execute(){
         VirtualMachineTemplate result = _templateService.updateTemplate(this);
         if (result != null) {
-            TemplateResponse response = _responseGenerator.createIsoResponse(result);
+            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(result);
             response.setResponseName(getCommandName());
             this.setResponseObject(response);
         } else {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java
index a4f0582..34ee4bd 100644
--- a/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/template/CopyTemplateCmd.java
@@ -124,7 +124,7 @@ public class CopyTemplateCmd extends BaseAsyncCmd {
             VirtualMachineTemplate template = _templateService.copyTemplate(this);
 
             if (template != null){
-                List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template.getId(), getDestinationZoneId(), false);
+                List<TemplateResponse> listResponse = _responseGenerator.createTemplateResponses(template, getDestinationZoneId(), false);
                 TemplateResponse response = new TemplateResponse();
                 if (listResponse != null && !listResponse.isEmpty()) {
                     response = listResponse.get(0);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
index aeb76f5..0b937be 100644
--- a/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/template/ListTemplatesCmd.java
@@ -26,6 +26,7 @@ import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.TemplateResponse;
+import org.apache.cloudstack.api.response.VolumeResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
 import org.apache.log4j.Logger;
 
@@ -55,7 +56,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
     @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the template name")
     private String templateName;
 
-    @Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"selfexecutable\",\"sharedexecutable\",\"executable\", and \"community\". " + 
+    @Parameter(name=ApiConstants.TEMPLATE_FILTER, type=CommandType.STRING, required=true, description="possible values are \"featured\", \"self\", \"selfexecutable\",\"sharedexecutable\",\"executable\", and \"community\". " +
                                                                                         "* featured : templates that have been marked as featured and public. " +
                                                                                         "* self : templates that have been registered or created by the calling user. " +
                                                                                         "* selfexecutable : same as self, but only returns templates that can be used to deploy a new VM. " +
@@ -119,18 +120,7 @@ public class ListTemplatesCmd extends BaseListTaggedResourcesCmd {
 
     @Override
     public void execute(){
-        Set<Pair<Long, Long>> templateZonePairSet = _mgr.listTemplates(this);
-
-        ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-        List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
-
-        for (Pair<Long, Long> template : templateZonePairSet) {
-            List<TemplateResponse> responses = new ArrayList<TemplateResponse>();
-            responses = _responseGenerator.createTemplateResponses(template.first().longValue(), template.second(), listInReadyState());
-            templateResponses.addAll(responses);
-        }
-
-        response.setResponses(templateResponses);
+        ListResponse<TemplateResponse> response = _queryService.listTemplates(this);
         response.setResponseName(getCommandName());
         this.setResponseObject(response);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
index f93c9f4..974edb3 100644
--- a/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/template/RegisterTemplateCmd.java
@@ -230,7 +230,7 @@ public class RegisterTemplateCmd extends BaseCmd {
             VirtualMachineTemplate template = _templateService.registerTemplate(this);
             if (template != null){
                 ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
-                List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template.getId(), zoneId, false);
+                List<TemplateResponse> templateResponses = _responseGenerator.createTemplateResponses(template, zoneId, false);
                 response.setResponses(templateResponses);
                 response.setResponseName(getCommandName());
                 this.setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
index e342fb1..9f55f9d 100644
--- a/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/template/UpdateTemplateCmd.java
@@ -68,7 +68,7 @@ public class UpdateTemplateCmd extends BaseUpdateTemplateOrIsoCmd {
     public void execute(){
         VirtualMachineTemplate result = _templateService.updateTemplate(this);
         if (result != null) {
-            TemplateResponse response = _responseGenerator.createIsoResponse(result);
+            TemplateResponse response = _responseGenerator.createTemplateUpdateResponse(result);
             response.setObjectName("template");
             response.setResponseName(getCommandName());
             this.setResponseObject(response);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/TemplateResponse.java b/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
index ed933ff..225edd5 100644
--- a/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/TemplateResponse.java
@@ -17,8 +17,10 @@
 package org.apache.cloudstack.api.response;
 
 import java.util.Date;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
@@ -31,7 +33,7 @@ import com.google.gson.annotations.SerializedName;
 
 @EntityReference(value=VirtualMachineTemplate.class)
 @SuppressWarnings("unused")
-public class TemplateResponse extends BaseResponse implements ControlledEntityResponse {
+public class TemplateResponse extends BaseResponse implements ControlledViewEntityResponse {
     @SerializedName(ApiConstants.ID) @Param(description="the template ID")
     private String id;
 
@@ -82,6 +84,8 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
     @SerializedName(ApiConstants.ACCOUNT) @Param(description="the account name to which the template belongs")
     private String account;
 
+    //TODO: since a template can be associated to more than one zones, this model is not accurate. For backward-compatibility, keep these fields
+    // here, but add a zones field to capture multiple zones.
     @SerializedName(ApiConstants.ZONE_ID) @Param(description="the ID of the zone for this template")
     private String zoneId;
 
@@ -133,12 +137,20 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
     @SerializedName(ApiConstants.DETAILS) @Param(description="additional key/value details tied with template")
     private Map details;
 
+    @SerializedName("zones")  @Param(description="list of zones associated with tempate", responseObject = TemplateZoneResponse.class)
+    private Set<TemplateZoneResponse> zones;
+
     @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated with tempate", responseObject = ResourceTagResponse.class)
-    private List<ResourceTagResponse> tags;
+    private Set<ResourceTagResponse> tags;
 
     @SerializedName(ApiConstants.SSHKEY_ENABLED) @Param(description="true if template is sshkey enabled, false otherwise")
     private Boolean sshKeyEnabled;
 
+    public TemplateResponse(){
+        zones = new LinkedHashSet<TemplateZoneResponse>();
+        tags = new LinkedHashSet<ResourceTagResponse>();
+    }
+
     @Override
     public String getObjectId() {
         return this.getId();
@@ -288,12 +300,29 @@ public class TemplateResponse extends BaseResponse implements ControlledEntityRe
         this.details = details;
     }
 
-    public void setTags(List<ResourceTagResponse> tags) {
+    public void setTags(Set<ResourceTagResponse> tags) {
         this.tags = tags;
     }
 
+    public void addTag(ResourceTagResponse tag){
+        this.tags.add(tag);
+    }
+
+    public void setZones(Set<TemplateZoneResponse> zones){
+        this.zones = zones;
+    }
+
+    public void addZone(TemplateZoneResponse zone){
+        this.zones.add(zone);
+    }
+
     public void setSshKeyEnabled(boolean sshKeyEnabled) {
         this.sshKeyEnabled = sshKeyEnabled;
     }
 
+    public String getZoneId() {
+        return zoneId;
+    }
+
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/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
new file mode 100644
index 0000000..9d26ad9
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/response/TemplateZoneResponse.java
@@ -0,0 +1,90 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.response;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class TemplateZoneResponse extends BaseResponse {
+    @SerializedName(ApiConstants.ZONE_ID) @Param(description="the ID of the zone for the template")
+    private String zoneId;
+
+    @SerializedName(ApiConstants.ZONE_NAME) @Param(description="the name of the zone for the template")
+    private String zoneName;
+
+
+    public TemplateZoneResponse(){
+        super();
+    }
+
+    public TemplateZoneResponse(String zoneId, String zoneName){
+        super();
+        this.zoneId = zoneId;
+        this.zoneName = zoneName;
+    }
+
+
+
+    public String getZoneId() {
+        return zoneId;
+    }
+
+    public void setZoneId(String zoneId) {
+        this.zoneId = zoneId;
+    }
+
+    public String getZoneName() {
+        return zoneName;
+    }
+
+    public void setZoneName(String zoneName) {
+        this.zoneName = zoneName;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        String oid = this.getZoneId();
+        result = prime * result + ((oid== null) ? 0 : oid.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        TemplateZoneResponse other = (TemplateZoneResponse) obj;
+        String oid = this.getZoneId();
+        if (oid == null) {
+            if (other.getZoneId() != null)
+                return false;
+        } else if (!oid.equals(other.getZoneId()))
+            return false;
+        else if ( this.getZoneName().equals(other.getZoneName()))
+            return false;
+        return true;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/api/src/org/apache/cloudstack/query/QueryService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/query/QueryService.java b/api/src/org/apache/cloudstack/query/QueryService.java
index 66f6399..4efbd1c 100644
--- a/api/src/org/apache/cloudstack/query/QueryService.java
+++ b/api/src/org/apache/cloudstack/query/QueryService.java
@@ -24,6 +24,7 @@ import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
 import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
 import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
 import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
+import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
 import org.apache.cloudstack.api.command.user.job.ListAsyncJobsCmd;
 import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
 import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
@@ -31,6 +32,7 @@ import org.apache.cloudstack.api.command.user.project.ListProjectInvitationsCmd;
 import org.apache.cloudstack.api.command.user.project.ListProjectsCmd;
 import org.apache.cloudstack.api.command.user.securitygroup.ListSecurityGroupsCmd;
 import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
+import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
 import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
 import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
 import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
@@ -51,6 +53,7 @@ import org.apache.cloudstack.api.response.ResourceTagResponse;
 import org.apache.cloudstack.api.response.SecurityGroupResponse;
 import org.apache.cloudstack.api.response.ServiceOfferingResponse;
 import org.apache.cloudstack.api.response.StoragePoolResponse;
+import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.UserResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
@@ -101,4 +104,8 @@ public interface QueryService {
     public ListResponse<ServiceOfferingResponse>  searchForServiceOfferings(ListServiceOfferingsCmd cmd);
 
     public ListResponse<ZoneResponse>  listDataCenters(ListZonesByCmd cmd);
+
+    public ListResponse<TemplateResponse> listTemplates(ListTemplatesCmd cmd);
+
+    public ListResponse<TemplateResponse> listIsos(ListIsosCmd cmd);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53982479/server/src/com/cloud/api/ApiDBUtils.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java
index 6b8607f..00358d7 100755
--- a/server/src/com/cloud/api/ApiDBUtils.java
+++ b/server/src/com/cloud/api/ApiDBUtils.java
@@ -42,6 +42,7 @@ import org.apache.cloudstack.api.response.ResourceTagResponse;
 import org.apache.cloudstack.api.response.SecurityGroupResponse;
 import org.apache.cloudstack.api.response.ServiceOfferingResponse;
 import org.apache.cloudstack.api.response.StoragePoolResponse;
+import org.apache.cloudstack.api.response.TemplateResponse;
 import org.apache.cloudstack.api.response.UserResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.VolumeResponse;
@@ -65,6 +66,7 @@ import com.cloud.api.query.dao.ResourceTagJoinDao;
 import com.cloud.api.query.dao.SecurityGroupJoinDao;
 import com.cloud.api.query.dao.ServiceOfferingJoinDao;
 import com.cloud.api.query.dao.StoragePoolJoinDao;
+import com.cloud.api.query.dao.TemplateJoinDao;
 import com.cloud.api.query.dao.UserAccountJoinDao;
 import com.cloud.api.query.dao.UserVmJoinDao;
 import com.cloud.api.query.dao.VolumeJoinDao;
@@ -84,6 +86,7 @@ import com.cloud.api.query.vo.ResourceTagJoinVO;
 import com.cloud.api.query.vo.SecurityGroupJoinVO;
 import com.cloud.api.query.vo.ServiceOfferingJoinVO;
 import com.cloud.api.query.vo.StoragePoolJoinVO;
+import com.cloud.api.query.vo.TemplateJoinVO;
 import com.cloud.api.query.vo.UserAccountJoinVO;
 import com.cloud.api.query.vo.UserVmJoinVO;
 import com.cloud.api.query.vo.VolumeJoinVO;
@@ -240,6 +243,7 @@ import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.dao.VolumeHostDao;
 import com.cloud.storage.snapshot.SnapshotPolicy;
 import com.cloud.template.TemplateManager;
+import com.cloud.template.VirtualMachineTemplate;
 import com.cloud.user.Account;
 import com.cloud.user.AccountDetailsDao;
 import com.cloud.user.AccountVO;
@@ -369,6 +373,7 @@ public class ApiDBUtils {
     static ImageStoreJoinDao _imageStoreJoinDao;
     static AccountJoinDao _accountJoinDao;
     static AsyncJobJoinDao _jobJoinDao;
+    static TemplateJoinDao _templateJoinDao;
 
     static PhysicalNetworkTrafficTypeDao _physicalNetworkTrafficTypeDao;
     static PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
@@ -474,6 +479,7 @@ public class ApiDBUtils {
     @Inject private ImageStoreJoinDao imageStoreJoinDao;
     @Inject private AccountJoinDao accountJoinDao;
     @Inject private AsyncJobJoinDao jobJoinDao;
+    @Inject private TemplateJoinDao templateJoinDao;
 
     @Inject private PhysicalNetworkTrafficTypeDao physicalNetworkTrafficTypeDao;
     @Inject private PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao;
@@ -575,6 +581,7 @@ public class ApiDBUtils {
         _imageStoreJoinDao = imageStoreJoinDao;
         _accountJoinDao = accountJoinDao;
         _jobJoinDao = jobJoinDao;
+        _templateJoinDao = templateJoinDao;
 
         _physicalNetworkTrafficTypeDao = physicalNetworkTrafficTypeDao;
         _physicalNetworkServiceProviderDao = physicalNetworkServiceProviderDao;
@@ -1606,4 +1613,33 @@ public class ApiDBUtils {
    public static List<NicSecondaryIpVO> findNicSecondaryIps(long nicId) {
        return _nicSecondaryIpDao.listByNicId(nicId);
    }
+
+
+   public static TemplateResponse newTemplateUpdateResponse(TemplateJoinVO vr) {
+       return _templateJoinDao.newUpdateResponse(vr);
+   }
+
+
+   public static TemplateResponse newTemplateResponse(TemplateJoinVO vr) {
+       return _templateJoinDao.newTemplateResponse(vr);
+   }
+
+
+   public static TemplateResponse newIsoResponse(TemplateJoinVO vr) {
+       return _templateJoinDao.newIsoResponse(vr);
+  }
+
+   public static TemplateResponse fillTemplateDetails(TemplateResponse vrData, TemplateJoinVO vr){
+       return _templateJoinDao.setTemplateResponse(vrData, vr);
+   }
+
+   public static List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate vr){
+       return _templateJoinDao.newTemplateView(vr);
+   }
+
+
+   public static List<TemplateJoinVO> newTemplateView(VirtualMachineTemplate vr, long zoneId, boolean readyOnly){
+       return _templateJoinDao.newTemplateView(vr, zoneId, readyOnly);
+   }
+
 }