cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/master to aa57078
Date Thu, 17 Oct 2013 22:26:08 GMT
Updated Branches:
  refs/heads/master 12189074b -> aa570783e


Added resource tag support for Zone


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

Branch: refs/heads/master
Commit: aa570783e8ea108f49af664bd9982bcae2aa86d5
Parents: 1218907
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Thu Oct 17 14:56:55 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Thu Oct 17 15:26:28 2013 -0700

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |  2 +-
 .../user/offering/ListServiceOfferingsCmd.java  |  4 +--
 .../api/command/user/zone/ListZonesByCmd.java   | 32 +++++++++++++++++---
 .../api/response/ServiceOfferingResponse.java   |  2 +-
 .../cloudstack/api/response/ZoneResponse.java   | 15 +++++++++
 .../com/cloud/api/query/QueryManagerImpl.java   | 28 +++++++++++++++--
 .../api/query/dao/DataCenterJoinDaoImpl.java    | 20 ++++++++----
 .../query/dao/ServiceOfferingJoinDaoImpl.java   |  3 +-
 8 files changed, 87 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 62eed09..e2f225d 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -518,7 +518,7 @@ public class ApiConstants {
     public static final String ROUTING = "isrouting";
     public static final String MAX_CONNECTIONS = "maxconnections";
     public static final String SERVICE_STATE = "servicestate";
-    public static final String RESOURCE_TAG = "resourcetag";
+    public static final String RESOURCE_TAGS = "resourcetags";
     public enum HostDetails {
         all, capacity, events, stats, min;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
b/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
index 06aad9d..2869d62 100644
--- a/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/offering/ListServiceOfferingsCmd.java
@@ -25,12 +25,10 @@ import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.BaseCmd.CommandType;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.ServiceOfferingResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
-
 import org.apache.log4j.Logger;
 
 import com.cloud.exception.InvalidParameterValueException;
@@ -66,7 +64,7 @@ public class ListServiceOfferingsCmd extends BaseListCmd {
     @Parameter(name=ApiConstants.SYSTEM_VM_TYPE, type=CommandType.STRING, description="the
system VM type. Possible types are \"consoleproxy\", \"secondarystoragevm\" or \"domainrouter\".")
     private String systemVmType;
     
-    @Parameter(name = ApiConstants.RESOURCE_TAG, type = CommandType.MAP, description = "List
service offerings by resource tags (key/value pairs)", since="4.3")
+    @Parameter(name = ApiConstants.RESOURCE_TAGS, type = CommandType.MAP, description = "List
service offerings by resource tags (key/value pairs)", since="4.3")
     private Map resourceTag;
 
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java b/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java
index 4cf3b58..2a98cfb 100644
--- a/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/zone/ListZonesByCmd.java
@@ -16,21 +16,21 @@
 // under the License.
 package org.apache.cloudstack.api.command.user.zone;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListCmd;
 import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.BaseCmd.CommandType;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.ListResponse;
-import org.apache.cloudstack.api.response.ServiceOfferingResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
 import org.apache.log4j.Logger;
 
-import com.cloud.dc.DataCenter;
+import com.cloud.exception.InvalidParameterValueException;
 
 @APICommand(name = "listZones", description="Lists zones", responseObject=ZoneResponse.class)
 public class ListZonesByCmd extends BaseListCmd {
@@ -62,6 +62,9 @@ public class ListZonesByCmd extends BaseListCmd {
     
     @Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag
to display the capacity of the zones")
     private Boolean showCapacities;
+    
+    @Parameter(name = ApiConstants.TAGS, type = CommandType.MAP, description = "List zones
by resource tags (key/value pairs)", since="4.3")
+    private Map tags;
 
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
@@ -90,6 +93,25 @@ public class ListZonesByCmd extends BaseListCmd {
     public Boolean getShowCapacities() {
         return showCapacities;
     }
+    
+    public Map<String, String> getTags() {
+        Map<String, String> tagsMap = null;
+        if (tags != null && !tags.isEmpty()) {
+            tagsMap = new HashMap<String, String>();
+            Collection<?> servicesCollection = tags.values();
+            Iterator<?> iter = servicesCollection.iterator();
+            while (iter.hasNext()) {
+                HashMap<String, String> services = (HashMap<String, String>)
iter.next();
+                String key = services.get("key");
+                String value = services.get("value");
+                if (value == null) {
+                    throw new InvalidParameterValueException("No value is passed in for key
" + key);
+                }
+                tagsMap.put(key, value);
+            }
+        }
+        return tagsMap;
+    }
 
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/api/src/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/ServiceOfferingResponse.java b/api/src/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
index d683840..204de3b 100644
--- a/api/src/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/ServiceOfferingResponse.java
@@ -107,7 +107,7 @@ public class ServiceOfferingResponse extends BaseResponse {
     @Param(description = "additional key/value details tied with this service offering",
since = "4.2.0")
     private Map<String, String> details;
     
-    @SerializedName(ApiConstants.RESOURCE_TAG)  @Param(description="the list of resource
tags associated with service offering." +
+    @SerializedName(ApiConstants.RESOURCE_TAGS)  @Param(description="the list of resource
tags associated with service offering." +
     		" The resource tags are not used for Volume/VM placement on the specific host.",
             responseObject = ResourceTagResponse.class, since="4.3")
     private Set<ResourceTagResponse> resourceTags;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/api/src/org/apache/cloudstack/api/response/ZoneResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/ZoneResponse.java b/api/src/org/apache/cloudstack/api/response/ZoneResponse.java
index 2ebb15a..85f9ecf 100644
--- a/api/src/org/apache/cloudstack/api/response/ZoneResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/ZoneResponse.java
@@ -16,7 +16,9 @@
 // under the License.
 package org.apache.cloudstack.api.response;
 
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
@@ -98,6 +100,15 @@ public class ZoneResponse extends BaseResponse {
 
     @SerializedName(ApiConstants.LOCAL_STORAGE_ENABLED) @Param(description="true if local
storage offering enabled, false otherwise")
     private boolean localStorageEnabled;
+    
+    @SerializedName(ApiConstants.TAGS)  @Param(description="the list of resource tags associated
with zone.",
+            responseObject = ResourceTagResponse.class, since="4.3")
+    private Set<ResourceTagResponse> tags;
+    
+    
+    public ZoneResponse(){
+        tags = new LinkedHashSet<ResourceTagResponse>();
+    }
 
     public void setId(String id) {
         this.id = id;
@@ -198,4 +209,8 @@ public class ZoneResponse extends BaseResponse {
 	public void setIp6Dns2(String ip6Dns2) {
 		this.ip6Dns2 = ip6Dns2;
 	}
+	
+    public void addTag(ResourceTagResponse tag){
+        this.tags.add(tag);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index b464e9e..8edc2eb 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -2536,9 +2536,23 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
         String keyword = cmd.getKeyword();
         String name = cmd.getName();
         String networkType = cmd.getNetworkType();
-
+        Map<String, String> resourceTags = cmd.getTags();
+        
+        SearchBuilder<DataCenterJoinVO> sb = _dcJoinDao.createSearchBuilder();
+        if (resourceTags != null && !resourceTags.isEmpty()) {
+            SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
+            for (int count=0; count < resourceTags.size(); count++) {
+                tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(),
SearchCriteria.Op.EQ);
+                tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(),
SearchCriteria.Op.EQ);
+                tagSearch.cp();
+            }
+            tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
+            sb.groupBy(sb.entity().getId());
+            sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(),
JoinBuilder.JoinType.INNER);
+        }
+        
         Filter searchFilter = new Filter(DataCenterJoinVO.class, null, false, cmd.getStartIndex(),
cmd.getPageSizeVal());
-        SearchCriteria<DataCenterJoinVO> sc = _dcJoinDao.createSearchCriteria();
+        SearchCriteria<DataCenterJoinVO> sc = sb.create();
 
         if (networkType != null) {
             sc.addAnd("networkType", SearchCriteria.Op.EQ, networkType);
@@ -2687,6 +2701,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
                 }
             }
         }
+        
+        if (resourceTags != null && !resourceTags.isEmpty()) {
+            int count = 0;
+            sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.Zone.toString());
+            for (String key : resourceTags.keySet()) {
+                sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
+                sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), resourceTags.get(key));
+                count++;
+            }
+        }
 
         return _dcJoinDao.searchAndCount(sc, searchFilter);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java
index edceb26..097824c 100644
--- a/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/DataCenterJoinDaoImpl.java
@@ -20,23 +20,23 @@ import java.util.List;
 
 import javax.ejb.Local;
 
+import org.apache.cloudstack.api.response.ResourceTagResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.cloudstack.context.CallContext;
 import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
 
 import com.cloud.api.ApiDBUtils;
 import com.cloud.api.ApiResponseHelper;
 import com.cloud.api.query.vo.DataCenterJoinVO;
+import com.cloud.api.query.vo.ResourceTagJoinVO;
 import com.cloud.dc.DataCenter;
-
-import org.apache.cloudstack.api.response.ZoneResponse;
-import org.apache.cloudstack.context.CallContext;
-
+import com.cloud.server.ResourceTag.TaggedResourceType;
 import com.cloud.user.Account;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 
-import org.springframework.stereotype.Component;
-
 @Component
 @Local(value={DataCenterJoinDao.class})
 public class DataCenterJoinDaoImpl extends GenericDaoBase<DataCenterJoinVO, Long> implements
DataCenterJoinDao {
@@ -97,6 +97,14 @@ public class DataCenterJoinDaoImpl extends GenericDaoBase<DataCenterJoinVO,
Long
         zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
         zoneResponse.setZoneToken(dataCenter.getZoneToken());
         zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
+        
+        // update tag information
+        List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(dataCenter.getUuid(),
TaggedResourceType.Zone);
+        for (ResourceTagJoinVO resourceTag : resourceTags) {            
+            ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag,
false);
+            zoneResponse.addTag(tagResponse);
+        }
+        
         zoneResponse.setObjectName("zone");
         return zoneResponse;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/aa570783/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java
index 8c32be3..52c2e27 100644
--- a/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/ServiceOfferingJoinDaoImpl.java
@@ -89,7 +89,8 @@ public class ServiceOfferingJoinDaoImpl extends GenericDaoBase<ServiceOfferingJo
         List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(offering.getUuid(),
TaggedResourceType.ServiceOffering);
         for (ResourceTagJoinVO resourceTag : resourceTags) {            
             ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag,
false);
-            offeringResponse.addTag(tagResponse);        }
+            offeringResponse.addTag(tagResponse);
+        }
 
         return offeringResponse;
     }


Mime
View raw message