adding dupliate cartridge type, subgroup check, getServiceGroup-Dependencies, 
SubGroups, Cartridges APIs to CC


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

Branch: refs/heads/4.0.0-grouping
Commit: 1d474ae4530ca22df1e748820c1b83804bbb526a
Parents: 6f5dc14
Author: Martin Eppel <[email protected]>
Authored: Tue Sep 16 18:06:36 2014 -0700
Committer: Martin Eppel <[email protected]>
Committed: Tue Sep 16 18:06:36 2014 -0700

----------------------------------------------------------------------
 .../impl/CloudControllerServiceImpl.java        |  38 +-
 .../interfaces/CloudControllerService.java      |   4 +-
 .../client/CloudControllerServiceClient.java    |  12 +
 .../deployer/DefaultServiceGroupDeployer.java   |  54 +-
 .../main/resources/CloudControllerService.wsdl  | 640 +++++++++----------
 5 files changed, 419 insertions(+), 329 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/1d474ae4/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
index 34664b0..4d20c82 100644
--- 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
@@ -288,6 +288,14 @@ public class CloudControllerServiceImpl implements 
CloudControllerService {
             log.debug("CloudControllerServiceImpl:deployServiceGroup:" + 
servicegroup.getName());
         }
        
+       String [] subGroups = servicegroup.getCartridges();
+       
+
+       if(log.isDebugEnabled()) {
+            
log.debug("CloudControllerServiceImpl:deployServiceGroup:subGroups" + 
subGroups.length);
+        }
+       
+       
        Dependencies dependencies = servicegroup.getDependencies();
        
        if(log.isDebugEnabled()) {
@@ -353,16 +361,34 @@ public class CloudControllerServiceImpl implements 
CloudControllerService {
        return serviceGroup;
     }
     
-    public String []getServiceGroupSubGroups (String name) throws 
InvalidServiceGroupException {
-       return null;
+    public String [] getServiceGroupSubGroups (String name) throws 
InvalidServiceGroupException {
+       ServiceGroup serviceGroup = this.getServiceGroup(name);
+       if (serviceGroup == null) {
+               throw new InvalidServiceGroupException("Invalid ServiceGroup " 
+ serviceGroup);
+       }
+       
+       return serviceGroup.getSubGroups();
     }
     
-    public Dependencies getServiceGroupCartridges (String name) throws 
InvalidServiceGroupException {
-       return null;
+    /**
+     * 
+     */
+    public String [] getServiceGroupCartridges (String name) throws 
InvalidServiceGroupException {
+       ServiceGroup serviceGroup = this.getServiceGroup(name);
+       if (serviceGroup == null) {
+               throw new InvalidServiceGroupException("Invalid ServiceGroup " 
+ serviceGroup);
+       }
+       String [] cs = serviceGroup.getCartridges();
+       return cs;
+       
     }
     
-    public Dependencies getServiceGroupDepenencies (String name) throws 
InvalidServiceGroupException {
-       return null;
+    public Dependencies getServiceGroupDependencies (String name) throws 
InvalidServiceGroupException {
+       ServiceGroup serviceGroup = this.getServiceGroup(name);
+       if (serviceGroup == null) {
+               throw new InvalidServiceGroupException("Invalid ServiceGroup " 
+ serviceGroup);
+       }
+       return serviceGroup.getDependencies();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/stratos/blob/1d474ae4/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
index 53821dd..ff36c83 100644
--- 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
@@ -55,9 +55,9 @@ public interface CloudControllerService {
     
     public String []getServiceGroupSubGroups (String name) throws 
InvalidServiceGroupException;
     
-    public Dependencies getServiceGroupCartridges (String name) throws 
InvalidServiceGroupException;
+    public String [] getServiceGroupCartridges (String name) throws 
InvalidServiceGroupException;
     
-    public Dependencies getServiceGroupDepenencies (String name) throws 
InvalidServiceGroupException;
+    public Dependencies getServiceGroupDependencies (String name) throws 
InvalidServiceGroupException;
 
     /**
      * Validate a given {@link Partition} for basic property existence.

http://git-wip-us.apache.org/repos/asf/stratos/blob/1d474ae4/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/CloudControllerServiceClient.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/CloudControllerServiceClient.java
 
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/CloudControllerServiceClient.java
index 92b9da7..fb8075d 100644
--- 
a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/CloudControllerServiceClient.java
+++ 
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/client/CloudControllerServiceClient.java
@@ -95,6 +95,18 @@ public class CloudControllerServiceClient {
        stub.undeployServiceGroup(name);
     }
     
+    public String [] getServiceGroupSubGroups(String name) throws 
RemoteException, CloudControllerServiceInvalidServiceGroupExceptionException {
+       return stub.getServiceGroupSubGroups(name);
+    }
+    
+    public String [] getServiceGroupCartridges(String name) throws 
RemoteException, CloudControllerServiceInvalidServiceGroupExceptionException {
+       return stub.getServiceGroupCartridges(name);
+    }
+    
+    public Dependencies getServiceGroupDependencies (String name)throws 
RemoteException, CloudControllerServiceInvalidServiceGroupExceptionException {
+       return stub.getServiceGroupDependencies(name);
+    }
+     
     public ServiceGroup getServiceGroup(String name) throws RemoteException, 
CloudControllerServiceInvalidServiceGroupExceptionException {
        return stub.getServiceGroup(name);
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/1d474ae4/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java
 
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java
index 8735ab3..f944288 100644
--- 
a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java
+++ 
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/grouping/deployer/DefaultServiceGroupDeployer.java
@@ -38,7 +38,9 @@ import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregister
 import java.rmi.RemoteException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 public class DefaultServiceGroupDeployer implements ServiceGroupDeployer {
 
@@ -83,6 +85,20 @@ public class DefaultServiceGroupDeployer implements 
ServiceGroupDeployer {
             }
                
             List<String> cartridgeTypes = 
serviceGroupDefinition.getCartridges();
+            
+            Set<String> duplicates = this.findDuplicates(cartridgeTypes);
+            
+            if (duplicates.size() > 0) {
+               
+               StringBuffer buf = new StringBuffer();
+               for (String dup : duplicates) {
+                       buf. append(dup).append(" ");
+               }
+               if (log.isDebugEnabled()) {
+                       log.debug("duplicate cartridges defined: " + 
buf.toString());
+                }
+               throw new InvalidServiceGroupException("Invalid Service Group 
definition, duplicate cartridges defined:" + buf.toString());
+            }
 
             CloudControllerServiceClient ccServiceClient = null;
 
@@ -116,6 +132,20 @@ public class DefaultServiceGroupDeployer implements 
ServiceGroupDeployer {
             }
                
             List<String> subGroupNames = serviceGroupDefinition.getSubGroups();
+            
+               Set<String> duplicates = this.findDuplicates(subGroupNames);
+            
+            if (duplicates.size() > 0) {
+               
+               StringBuffer buf = new StringBuffer();
+               for (String dup : duplicates) {
+                       buf. append(dup).append(" ");
+               }
+               if (log.isDebugEnabled()) {
+                       log.debug("duplicate subGroups defined: " + 
buf.toString());
+                }
+               throw new InvalidServiceGroupException("Invalid Service Group 
definition, duplicate subGroups defined:" + buf.toString());
+            }
 
             for (String subGroupName : subGroupNames) {
                 if (getServiceGroupDefinition(subGroupName) == null) {
@@ -165,6 +195,7 @@ public class DefaultServiceGroupDeployer implements 
ServiceGroupDeployer {
             
             ServiceGroup serviceGroup = 
ccServiceClient.getServiceGroup(serviceGroupDefinitionName);
             ServiceGroupDefinition serviceGroupDef = 
populateServiceGroupDefinitionPojo(serviceGroup);
+            
             return serviceGroupDef;
 
         } catch (AxisFault axisFault) {
@@ -287,4 +318,25 @@ public class DefaultServiceGroupDeployer implements 
ServiceGroupDeployer {
    
        return servicegroupDef;
     }
-}
+    
+    
+    /**
+     * returns any duplicates in a List
+     * @param checkedList
+     * @return
+     */
+    private Set<String> findDuplicates(List<String> checkedList)
+    { 
+      final Set<String> retVals = new HashSet<String>(); 
+      final Set<String> set1 = new HashSet<String>();
+
+      for (String val : checkedList) {
+         
+         if (!set1.add(val)) {
+               retVals.add(val);
+         }
+      }
+      return retVals;
+    }
+    
+ }

Reply via email to