cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject [14/34] git commit: updated refs/heads/master to 6137d32
Date Thu, 11 Apr 2013 20:24:53 GMT
Changes to make affinity group types configurable.


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

Branch: refs/heads/master
Commit: bb9bdf0173f7a225402a6640a0d8752155c9ee3c
Parents: 708157d
Author: Prachi Damle <prachi@cloud.com>
Authored: Mon Mar 25 14:53:19 2013 -0700
Committer: Prachi Damle <prachi@cloud.com>
Committed: Thu Apr 11 13:23:01 2013 -0700

----------------------------------------------------------------------
 .../affinity/AffinityGroupTypeResponse.java        |   48 ++++++++++
 .../affinitygroup/ListAffinityGroupTypesCmd.java   |   67 +++++++++++++++
 client/tomcatconf/componentContext.xml.in          |    9 ++
 .../affinity/AffinityGroupServiceImpl.java         |   64 +++++++++++++-
 4 files changed, 185 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java
new file mode 100644
index 0000000..2d1cd25
--- /dev/null
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupTypeResponse.java
@@ -0,0 +1,48 @@
+// 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.affinity;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+import org.apache.cloudstack.api.response.ControlledEntityResponse;
+import org.apache.cloudstack.api.response.ControlledViewEntityResponse;
+
+import com.cloud.network.security.SecurityGroup;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+@SuppressWarnings("unused")
+@EntityReference(value = AffinityGroup.class)
+public class AffinityGroupTypeResponse extends BaseResponse {
+
+    @SerializedName(ApiConstants.TYPE)
+    @Param(description = "the type of the affinity group")
+    private String type;
+
+
+    public AffinityGroupTypeResponse() {
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java
b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java
new file mode 100644
index 0000000..ce6e89a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/ListAffinityGroupTypesCmd.java
@@ -0,0 +1,67 @@
+// 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.AffinityGroupTypeResponse;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.log4j.Logger;
+
+import com.cloud.user.Account;
+
+@APICommand(name = "listAffinityGroupTypes", description = "Lists affinity group types available",
responseObject = AffinityGroupTypeResponse.class)
+public class ListAffinityGroupTypesCmd extends BaseListCmd {
+    public static final Logger s_logger = Logger.getLogger(ListAffinityGroupTypesCmd.class.getName());
+
+    private static final String s_name = "listaffinitygrouptypesresponse";
+
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public void execute() {
+        List<String> result = _affinityGroupService.listAffinityGroupTypes();
+        ListResponse<AffinityGroupTypeResponse> response = new ListResponse<AffinityGroupTypeResponse>();
+        ArrayList<AffinityGroupTypeResponse> responses = new ArrayList<AffinityGroupTypeResponse>();
+        if (result != null) {
+            for (String type : result) {
+                AffinityGroupTypeResponse affinityTypeResponse = new AffinityGroupTypeResponse();
+                affinityTypeResponse.setType(type);
+                affinityTypeResponse.setObjectName("affinityGroupType");
+                responses.add(affinityTypeResponse);
+            }
+        }
+        response.setResponses(responses);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/client/tomcatconf/componentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in
index 1582e8b..7f3e02d 100644
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@ -247,4 +247,13 @@
       </list>
     </property>
   </bean>
+
+  <!--
+   AffinityGroup Processors
+  -->
+    <bean id="HostAntiAffinityProcessor" class="org.apache.cloudstack.affinity.HostAntiAffinityProcessor">
+    	<property name="name" value="HostAntiAffinityProcessor"/>
+    	<property name="type" value="host anti-affinity"/>
+ 	</bean>
+  
 </beans>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bb9bdf01/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 21052d0..8536022 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -1,7 +1,10 @@
 package org.apache.cloudstack.affinity;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
@@ -10,6 +13,7 @@ import javax.naming.ConfigurationException;
 import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
 import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.log4j.Logger;
+import org.springframework.context.annotation.Primary;
 
 
 import com.cloud.event.ActionEvent;
@@ -22,6 +26,7 @@ import com.cloud.user.AccountManager;
 import com.cloud.user.UserContext;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.Pair;
+import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
@@ -30,6 +35,7 @@ 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.utils.exception.CloudRuntimeException;
 import com.cloud.utils.fsm.StateListener;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachine;
@@ -69,7 +75,30 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
                     + " already exisits.");
         }
 
-        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, affinityGroupType,
description, domainId,
+
+        //validate the affinityGroupType
+        String internalAffinityType = null;
+        Map<String, AffinityGroupProcessor> typeProcessorMap = getAffinityTypeToProcessorMap();
+        if (typeProcessorMap != null && !typeProcessorMap.isEmpty()) {
+            if (!typeProcessorMap.containsKey(affinityGroupType)) {
+                throw new InvalidParameterValueException("Unable to create affinity group,
invalid affinity group type"
+                        + affinityGroupType);
+            } else {
+                AffinityGroupProcessor processor = typeProcessorMap.get(affinityGroupType);
+                internalAffinityType = processor.getType();
+            }
+        } else {
+            throw new InvalidParameterValueException(
+                    "Unable to create affinity group, no Affinity Group Types configured");
+        }
+
+        if (internalAffinityType == null) {
+            throw new InvalidParameterValueException(
+                    "Unable to create affinity group, Affinity Group Processor for type "
+ affinityGroupType
+                            + "is wrongly configured");
+        }
+
+        AffinityGroupVO group = new AffinityGroupVO(affinityGroupName, internalAffinityType,
description, domainId,
                 owner.getId());
         _affinityGroupDao.persist(group);
 
@@ -188,8 +217,37 @@ public class AffinityGroupServiceImpl extends ManagerBase implements
AffinityGro
 
     @Override
     public List<String> listAffinityGroupTypes() {
-        // TODO Auto-generated method stub
-        return null;
+        List<String> types = new ArrayList<String>();
+        Map<String, AffinityGroupProcessor> componentMap = ComponentContext.getComponentsOfType(AffinityGroupProcessor.class);
+
+        if (componentMap.size() > 0) {
+            for (Entry<String, AffinityGroupProcessor> entry : componentMap.entrySet())
{
+                Map<String, Object> params = entry.getValue().getConfigParams();
+                if (params.containsKey("type")) {
+                    types.add((String) params.get("type"));
+                }
+
+            }
+
+        }
+        return types;
+    }
+
+    protected Map<String, AffinityGroupProcessor> getAffinityTypeToProcessorMap() {
+        Map<String, AffinityGroupProcessor> typeProcessorMap = new HashMap<String,
AffinityGroupProcessor>();
+        Map<String, AffinityGroupProcessor> componentMap = ComponentContext.getComponentsOfType(AffinityGroupProcessor.class);
+
+        if (componentMap.size() > 0) {
+            for (Entry<String, AffinityGroupProcessor> entry : componentMap.entrySet())
{
+                Map<String, Object> params = entry.getValue().getConfigParams();
+                if (params.containsKey("type")) {
+                    typeProcessorMap.put((String) params.get("type"), entry.getValue());
+                }
+
+            }
+
+        }
+        return typeProcessorMap;
     }
 
     @Override


Mime
View raw message