cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wid...@apache.org
Subject [2/2] git commit: updated refs/heads/master to aa7f8e5
Date Thu, 13 Aug 2015 11:47:50 GMT
CLOUDSTACK-8133 Added Virtualmachine count and ID's to listSecurityGroups response.

See issue CLOUDSTACK-8133 for more information.

Added null check by comment of Koushik Das.

Added brackets by comment of Wido den Hollander.

Removed a call to findById() by comment of Koushik Das.

Signed-off-by: Wido den Hollander <wido@widodh.nl>


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

Branch: refs/heads/master
Commit: 03f48872d602c64bd74c40a2cd93f17acc746236
Parents: 792c27c
Author: Boris Schrijver <boris@pcextreme.nl>
Authored: Tue Aug 11 19:01:38 2015 +0200
Committer: Wido den Hollander <wido@widodh.nl>
Committed: Thu Aug 13 13:47:38 2015 +0200

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |  1 +
 .../api/response/SecurityGroupResponse.java     | 24 +++++++++++++++--
 .../api/query/dao/SecurityGroupJoinDaoImpl.java | 27 ++++++++++++++++----
 3 files changed, 45 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03f48872/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 0e7ff88..e86e2d4 100644
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -271,6 +271,7 @@ public class ApiConstants {
     public static final String VIRTUAL_MACHINE_ID = "virtualmachineid";
     public static final String VIRTUAL_MACHINE_IDS = "virtualmachineids";
     public static final String VIRTUAL_MACHINE_ID_IP = "vmidipmap";
+    public static final String VIRTUAL_MACHINE_COUNT = "virtualmachinecount";
     public static final String USAGE_ID = "usageid";
 
     public static final String VLAN = "vlan";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03f48872/api/src/org/apache/cloudstack/api/response/SecurityGroupResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/SecurityGroupResponse.java b/api/src/org/apache/cloudstack/api/response/SecurityGroupResponse.java
index 0be2ee1..c96421b 100644
--- a/api/src/org/apache/cloudstack/api/response/SecurityGroupResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/SecurityGroupResponse.java
@@ -19,14 +19,13 @@ package org.apache.cloudstack.api.response;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
-import com.google.gson.annotations.SerializedName;
-
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseResponse;
 import org.apache.cloudstack.api.EntityReference;
 
 import com.cloud.network.security.SecurityGroup;
 import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
 
 @SuppressWarnings("unused")
 @EntityReference(value = SecurityGroup.class)
@@ -76,7 +75,16 @@ public class SecurityGroupResponse extends BaseResponse implements ControlledVie
     @Param(description = "the list of resource tags associated with the rule", responseObject
= ResourceTagResponse.class)
     private Set<ResourceTagResponse> tags;
 
+    @SerializedName(ApiConstants.VIRTUAL_MACHINE_COUNT)
+    @Param(description = "the number of virtualmachines associated with this securitygroup",
since = "4.6.0")
+    private Integer virtualMachineCount;
+
+    @SerializedName(ApiConstants.VIRTUAL_MACHINE_IDS)
+    @Param(description = "the list of virtualmachine ids associated with this securitygroup",
since = "4.6.0")
+    private Set<String> virtualMachineIds;
+
     public SecurityGroupResponse() {
+        this.virtualMachineIds = new LinkedHashSet<String>();
         this.ingressRules = new LinkedHashSet<SecurityGroupRuleResponse>();
         this.egressRules = new LinkedHashSet<SecurityGroupRuleResponse>();
         this.tags = new LinkedHashSet<ResourceTagResponse>();
@@ -176,4 +184,16 @@ public class SecurityGroupResponse extends BaseResponse implements ControlledVie
     public void addTag(ResourceTagResponse tag) {
         this.tags.add(tag);
     }
+
+    public void setVirtualMachineCount(Integer virtualMachineCount) {
+        this.virtualMachineCount = virtualMachineCount;
+    }
+
+    public void setVirtualMachineIds(Set<String> virtualMachineIds) {
+        this.virtualMachineIds = virtualMachineIds;
+    }
+
+    public void addVirtualMachineId(String virtualMachineId) {
+        this.virtualMachineIds.add(virtualMachineId);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03f48872/server/src/com/cloud/api/query/dao/SecurityGroupJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/SecurityGroupJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/SecurityGroupJoinDaoImpl.java
index bb4df1d..1c54427 100644
--- a/server/src/com/cloud/api/query/dao/SecurityGroupJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/SecurityGroupJoinDaoImpl.java
@@ -24,25 +24,28 @@ import java.util.Set;
 import javax.ejb.Local;
 import javax.inject.Inject;
 
-import com.cloud.server.ResourceTag;
 import org.apache.cloudstack.api.response.ResourceTagResponse;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.response.SecurityGroupResponse;
 import org.apache.cloudstack.api.response.SecurityGroupRuleResponse;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+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.ResourceTagJoinVO;
 import com.cloud.api.query.vo.SecurityGroupJoinVO;
 import com.cloud.network.security.SecurityGroup;
+import com.cloud.network.security.SecurityGroupVMMapVO;
 import com.cloud.network.security.SecurityRule.SecurityRuleType;
+import com.cloud.network.security.dao.SecurityGroupVMMapDao;
+import com.cloud.server.ResourceTag;
 import com.cloud.user.Account;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.dao.UserVmDao;
 
 @Component
 @Local(value = {SecurityGroupJoinDao.class})
@@ -51,9 +54,12 @@ public class SecurityGroupJoinDaoImpl extends GenericDaoBase<SecurityGroupJoinVO
 
     @Inject
     private ConfigurationDao _configDao;
-
     @Inject
     private ResourceTagJoinDao _resourceTagJoinDao;
+    @Inject
+    private SecurityGroupVMMapDao _securityGroupVMMapDao;
+    @Inject
+    private UserVmDao _userVmDao;
 
     private final SearchBuilder<SecurityGroupJoinVO> sgSearch;
 
@@ -125,6 +131,17 @@ public class SecurityGroupJoinDaoImpl extends GenericDaoBase<SecurityGroupJoinVO
             }
         }
 
+        List<SecurityGroupVMMapVO> securityGroupVmMap = _securityGroupVMMapDao.listBySecurityGroup(vsg.getId());
+        s_logger.debug("newSecurityGroupResponse() -> virtualmachine count: " + securityGroupVmMap.size());
+        sgResponse.setVirtualMachineCount(securityGroupVmMap.size());
+
+        for(SecurityGroupVMMapVO securityGroupVMMapVO : securityGroupVmMap) {
+            final UserVmVO userVmVO = _userVmDao.findById(securityGroupVMMapVO.getInstanceId());
+            if (userVmVO != null) {
+                sgResponse.addVirtualMachineId(userVmVO.getUuid());
+            }
+        }
+
         // update tag information
         Long tag_id = vsg.getTagId();
         if (tag_id != null && tag_id.longValue() > 0) {


Mime
View raw message