cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [13/47] git commit: updated refs/heads/internallb to 3795048
Date Thu, 11 Apr 2013 21:22:36 GMT
ListAffinityGroups API changes


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

Branch: refs/heads/internallb
Commit: 1aed5bf9c2c75843c1d89973f467ec7c9128242d
Parents: 50f53c8
Author: Prachi Damle <prachi@cloud.com>
Authored: Thu Feb 28 17:16:54 2013 -0800
Committer: Prachi Damle <prachi@cloud.com>
Committed: Thu Apr 11 13:22:38 2013 -0700

----------------------------------------------------------------------
 api/src/com/cloud/async/AsyncJob.java              |    3 +-
 .../cloudstack/affinity/AffinityGroupService.java  |   15 ++-
 .../user/affinitygroup/CreateAffinityGroupCmd.java |   49 ++++++-
 .../user/affinitygroup/DeleteAffinityGroupCmd.java |   21 +++-
 .../user/affinitygroup/ListAffinityGroupsCmd.java  |  107 +++++++++++++++
 .../affinity/AffinityGroupServiceImpl.java         |   76 ++++++++++-
 6 files changed, 254 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/com/cloud/async/AsyncJob.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/async/AsyncJob.java b/api/src/com/cloud/async/AsyncJob.java
index 8e4aec0..866429b 100644
--- a/api/src/com/cloud/async/AsyncJob.java
+++ b/api/src/com/cloud/async/AsyncJob.java
@@ -49,7 +49,8 @@ public interface AsyncJob extends Identity, InternalIdentity {
         AutoScalePolicy,
         AutoScaleVmProfile,
         AutoScaleVmGroup,
-        GlobalLoadBalancerRule
+        GlobalLoadBalancerRule,
+        AffinityGroup
     }
 
     long getUserId();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
index 501280d..368abe2 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
@@ -3,6 +3,7 @@ package org.apache.cloudstack.affinity;
 import java.util.List;
 
 import com.cloud.exception.ResourceInUseException;
+import com.cloud.utils.Pair;
 
 public interface AffinityGroupService {
 
@@ -22,7 +23,7 @@ public interface AffinityGroupService {
 
     /**
      * Creates an affinity/anti-affinity group.
-     * 
+     *
      * @param affinityGroupId
      * @param account
      * @param domainId
@@ -32,19 +33,19 @@ public interface AffinityGroupService {
     boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String
affinityGroupName)
             throws ResourceInUseException;
 
-    /**
-     * Lists Affinity Groups
-     *
+    /** Lists Affinity Groups in your account
      * @param account
      * @param domainId
      * @param affinityGroupId
      * @param affinityGroupName
      * @param affinityGroupType
      * @param vmId
+     * @param startIndex
+     * @param pageSize
      * @return
      */
-    List<AffinityGroup> listAffinityGroups(String account, Long domainId, Long affinityGroupId,
-            String affinityGroupName, String affinityGroupType, Long vmId);
+    Pair<List<? extends AffinityGroup>, Integer> listAffinityGroups(Long affinityGroupId,
String affinityGroupName,
+            String affinityGroupType, Long vmId, Long startIndex, Long pageSize);
 
 
     /**
@@ -54,4 +55,6 @@ public interface AffinityGroupService {
      */
     List<String> listAffinityGroupTypes();
 
+    AffinityGroup getAffinityGroup(Long groupId);
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
index c38bcff..b465214 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/CreateAffinityGroupCmd.java
@@ -21,17 +21,20 @@ import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.log4j.Logger;
 
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 
 @APICommand(name = "createAffinityGroup", responseObject = AffinityGroupResponse.class, description
= "Creates an affinity/anti-affinity group")
-public class CreateAffinityGroupCmd extends BaseCmd {
+public class CreateAffinityGroupCmd extends BaseAsyncCreateCmd {
     public static final Logger s_logger = Logger.getLogger(CreateAffinityGroupCmd.class.getName());
 
     private static final String s_name = "createaffinitygroupresponse";
@@ -112,8 +115,7 @@ public class CreateAffinityGroupCmd extends BaseCmd {
 
     @Override
     public void execute() {
-        AffinityGroup group = _affinityGroupService.createAffinityGroup(accountName, domainId,
affinityGroupName,
-                affinityGroupType, description);
+        AffinityGroup group = _affinityGroupService.getAffinityGroup(getEntityId());
         if (group != null) {
             AffinityGroupResponse response = _responseGenerator.createAffinityGroupResponse(group);
             response.setResponseName(getCommandName());
@@ -123,4 +125,43 @@ public class CreateAffinityGroupCmd extends BaseCmd {
                     + affinityGroupName);
         }
     }
+
+    @Override
+    public void create() throws ResourceAllocationException {
+        AffinityGroup result = _affinityGroupService.createAffinityGroup(accountName, domainId,
affinityGroupName,
+                affinityGroupType, description);
+        if (result != null) {
+            setEntityId(result.getId());
+            setEntityUuid(result.getUuid());
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create affinity
group entity" + affinityGroupName);
+        }
+
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_AFFINITY_GROUP_CREATE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "creating Affinity Group";
+    }
+
+    @Override
+    public String getCreateEventType() {
+        return EventTypes.EVENT_AFFINITY_GROUP_CREATE;
+    }
+
+    @Override
+    public String getCreateEventDescription() {
+        return "creating Affinity Group";
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.AffinityGroup;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
index 8ace2e5..4ceba29 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
@@ -20,20 +20,22 @@ import org.apache.cloudstack.affinity.AffinityGroupResponse;
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.ApiErrorCode;
-import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
 import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.api.response.DomainResponse;
 import org.apache.cloudstack.api.response.SuccessResponse;
 import org.apache.log4j.Logger;
 
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 
 @APICommand(name = "deleteAffinityGroup", description = "Deletes affinity group", responseObject
= SuccessResponse.class)
-public class DeleteAffinityGroupCmd extends BaseCmd {
+public class DeleteAffinityGroupCmd extends BaseAsyncCmd {
     public static final Logger s_logger = Logger.getLogger(DeleteAffinityGroupCmd.class.getName());
     private static final String s_name = "deleteaffinitygroupresponse";
 
@@ -134,4 +136,19 @@ public class DeleteAffinityGroupCmd extends BaseCmd {
             throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage());
         }
     }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_AFFINITY_GROUP_DELETE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "Deleting Affinity Group";
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.AffinityGroup;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
new file mode 100644
index 0000000..09d1f8f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupsCmd.java
@@ -0,0 +1,107 @@
+// 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.command.user.affinitygroup;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.affinity.AffinityGroup;
+import org.apache.cloudstack.affinity.AffinityGroupResponse;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.async.AsyncJob;
+import com.cloud.utils.Pair;
+
+@APICommand(name = "listAffinityGroups", description = "Lists affinity groups", responseObject
= AffinityGroupResponse.class)
+public class ListAffinityGroupsCmd extends BaseListCmd {
+    public static final Logger s_logger = Logger.getLogger(ListAffinityGroupsCmd.class.getName());
+
+    private static final String s_name = "listaffinitygroupsresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "lists
affinity groups by name")
+    private String affinityGroupName;
+
+    @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, description
= "lists affinity groups by virtual machine id", entityType = UserVmResponse.class)
+    private Long virtualMachineId;
+
+    @Parameter(name = ApiConstants.ID, type = CommandType.UUID, description = "list the affinity
group by the id provided", entityType = AffinityGroupResponse.class)
+    private Long id;
+
+    @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "lists
affinity groups by type")
+    private String affinityGroupType;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    public String getAffinityGroupName() {
+        return affinityGroupName;
+    }
+
+    public Long getVirtualMachineId() {
+        return virtualMachineId;
+    }
+
+    public Long getId(){
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute(){
+
+        Pair<List<AffinityGroup>, Integer> result = _affinityGroupService.listAffinityGroups(id,
affinityGroupName,
+                affinityGroupType, virtualMachineId, this.getStartIndex(), this.getPageSizeVal());
+        if (result != null) {
+            ListResponse<AffinityGroupResponse> response = new ListResponse<AffinityGroupResponse>();
+            List<AffinityGroupResponse> groupResponses = new ArrayList<AffinityGroupResponse>();
+            for (AffinityGroup group : result.first()) {
+                AffinityGroupResponse groupResponse = _responseGenerator.createAffinityGroupResponse(group);
+                groupResponses.add(groupResponse);
+            }
+            response.setResponses(groupResponses, result.second());
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to search for
affinity groups");
+        }
+    }
+
+    @Override
+    public AsyncJob.Type getInstanceType() {
+        return AsyncJob.Type.AffinityGroup;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1aed5bf9/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index f3b166f..994f225 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -1,5 +1,6 @@
 package org.apache.cloudstack.affinity;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -12,10 +13,13 @@ import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.log4j.Logger;
 
 
+import com.cloud.api.query.vo.SecurityGroupJoinVO;
 import com.cloud.event.ActionEvent;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.ResourceInUseException;
+import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.network.security.SecurityGroupManager;
 import com.cloud.network.security.SecurityGroupRuleVO;
 import com.cloud.network.security.SecurityGroupVMMapVO;
@@ -23,10 +27,19 @@ import com.cloud.network.security.SecurityGroupVO;
 import com.cloud.user.Account;
 import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
+import com.cloud.utils.Pair;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.db.Filter;
+import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.JoinBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.Transaction;
+import com.cloud.vm.UserVmVO;
+import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.dao.UserVmDao;
 
 @Local(value = { AffinityGroupService.class })
 public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService,
Manager {
@@ -43,6 +56,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
     @Inject
     AffinityGroupVMMapDao _affinityGroupVMMapDao;
 
+    @Inject
+    private UserVmDao _userVmDao;
+
     @Override
     public AffinityGroup createAffinityGroup(String account, Long domainId, String affinityGroupName,
             String affinityGroupType, String description) {
@@ -120,12 +136,59 @@ public class AffinityGroupServiceImpl extends ManagerBase implements
AffinityGro
     }
 
     @Override
-    public List<AffinityGroup> listAffinityGroups(String account, Long domainId, Long
affinityGroupId,
-            String affinityGroupName, String affinityGroupType, Long vmId) {
-        // TODO Auto-generated method stub
-        return null;
+    public Pair<List<? extends AffinityGroup>, Integer> listAffinityGroups(Long
affinityGroupId, String affinityGroupName, String affinityGroupType, Long vmId, Long startIndex,
Long pageSize) {
+        Filter searchFilter = new Filter(AffinityGroupVO.class, "id", Boolean.TRUE, startIndex,
pageSize);
+
+        Account caller = UserContext.current().getCaller();
+
+        Long accountId = caller.getAccountId();
+        Long domainId = caller.getDomainId();
+
+        SearchBuilder<AffinityGroupVMMapVO> vmInstanceSearch = _affinityGroupVMMapDao.createSearchBuilder();
+        vmInstanceSearch.and("instanceId", vmInstanceSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
+
+        SearchBuilder<AffinityGroupVO> groupSearch = _affinityGroupDao.createSearchBuilder();
+        groupSearch.join("vmInstanceSearch", vmInstanceSearch, groupSearch.entity().getId(),
vmInstanceSearch.entity()
+                .getAffinityGroupId(), JoinBuilder.JoinType.INNER);
+
+        SearchCriteria<AffinityGroupVO> sc = groupSearch.create();
+
+        if (accountId != null) {
+            sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
+        }
+
+        if (domainId != null) {
+            sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
+        }
+
+        if (affinityGroupId != null) {
+            sc.addAnd("id", SearchCriteria.Op.EQ, affinityGroupId);
+        }
+
+        if (affinityGroupName != null) {
+            sc.addAnd("name", SearchCriteria.Op.EQ, affinityGroupName);
+        }
+
+        if (affinityGroupType != null) {
+            sc.addAnd("type", SearchCriteria.Op.EQ, affinityGroupType);
+        }
+
+        if (vmId != null) {
+            UserVmVO userVM = _userVmDao.findById(vmId);
+            if (userVM == null) {
+                throw new InvalidParameterValueException("Unable to list affinity groups
for virtual machine instance "
+                        + vmId + "; instance not found.");
+            }
+            _accountMgr.checkAccess(caller, null, true, userVM);
+            // add join to affinity_groups_vm_map
+            sc.setJoinParameters("vmInstanceSearch", "instanceId", vmId);
+        }
+
+        Pair<List<AffinityGroupVO>, Integer> result =  _affinityGroupDao.searchAndCount(sc,
searchFilter);
+        return new Pair<List<? extends AffinityGroup>, Integer>(result.first(),
result.second());
     }
 
+
     @Override
     public List<String> listAffinityGroupTypes() {
         // TODO Auto-generated method stub
@@ -153,4 +216,9 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
         return _name;
     }
 
+    @Override
+    public AffinityGroup getAffinityGroup(Long groupId) {
+        return _affinityGroupDao.findById(groupId);
+    }
+
 }


Mime
View raw message