fixing confilcts and merging

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

Branch: refs/heads/master
Commit: bc336fa979dbf6769f34119305a153dc64dc4e13
Parents: 09d0bef 5bd3ffe
Author: Isuru <[email protected]>
Authored: Sun Mar 2 11:52:38 2014 +0530
Committer: Isuru <[email protected]>
Committed: Sun Mar 2 11:52:38 2014 +0530

----------------------------------------------------------------------
 .../cloud/controller/CloudControllerClient.java |  69 +-
 .../exception/InvalidPartitionException.java    |   8 +
 .../exception/InvalidPolicyException.java       |   8 +-
 .../exception/NonExistingLBException.java       |  13 +-
 .../exception/PartitionValidationException.java |  18 +-
 .../exception/PolicyValidationException.java    |  14 +-
 .../autoscaler/exception/SpawningException.java |  13 +-
 .../exception/TerminationException.java         |  12 +-
 .../autoscaler/partition/PartitionManager.java  |   8 +-
 .../stratos/cli/RestCommandLineService.java     |  44 +-
 .../InvalidCartridgeDefinitionException.java    |  13 +-
 .../InvalidCartridgeTypeException.java          |  13 +-
 .../exception/InvalidClusterException.java      |  13 +-
 .../exception/InvalidHostException.java         |  13 +-
 .../exception/InvalidIaasProviderException.java |  13 +-
 .../exception/InvalidMemberException.java       |  13 +-
 .../exception/InvalidPartitionException.java    |  11 +-
 .../exception/InvalidRegionException.java       |  11 +
 .../exception/InvalidXMLException.java          |  11 +
 .../exception/InvalidZoneException.java         |  11 +
 .../MalformedConfigurationFileException.java    |  10 +
 .../exception/NoInstanceFoundException.java     |  11 +
 .../exception/SerializationException.java       |  11 +
 .../UnregisteredCartridgeException.java         |  11 +
 .../exception/UnregisteredClusterException.java |  10 +
 .../cloud/controller/iaases/AWSEC2Iaas.java     |  10 +-
 .../impl/CloudControllerServiceImpl.java        | 233 +------
 .../interfaces/CloudControllerService.java      |  21 +-
 .../util/CloudControllerConstants.java          |   1 +
 .../validate/AWSEC2PartitionValidator.java      |   2 +-
 .../OpenstackNovaPartitionValidator.java        |   2 +-
 .../manager/client/AutoscalerServiceClient.java | 268 +++-----
 .../client/CloudControllerServiceClient.java    |  61 +-
 .../service/ServiceDeploymentManager.java       |   5 +-
 .../UnregisteredCartridgeException.java         |   6 +
 .../manager/CartridgeSubscriptionManager.java   |  10 +-
 .../utils/CartridgeSubscriptionUtils.java       |  10 -
 .../rest/endpoint/services/ServiceUtils.java    | 440 ++++++++----
 .../src/main/resources/AutoScalerService.wsdl   | 678 ++++++++++---------
 .../pom.xml                                     |   2 +-
 .../main/resources/CloudControllerService.wsdl  |  96 ++-
 41 files changed, 1224 insertions(+), 1003 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
----------------------------------------------------------------------
diff --cc 
components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
index a80aea0,11e57a1..3ea0fc6
--- 
a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
+++ 
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/deploy/service/ServiceDeploymentManager.java
@@@ -25,6 -26,8 +25,7 @@@ import org.apache.stratos.cloud.control
  import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
  import org.apache.stratos.cloud.controller.pojo.Properties;
  import org.apache.stratos.cloud.controller.pojo.Property;
+ import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregisteredCartridgeExceptionException;
 -import org.apache.stratos.manager.client.AutoscalerServiceClient;
  import org.apache.stratos.manager.client.CloudControllerServiceClient;
  import 
org.apache.stratos.manager.deploy.service.multitenant.MultiTenantService;
  import 
org.apache.stratos.manager.deploy.service.multitenant.lb.MultiTenantLBService;

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
----------------------------------------------------------------------
diff --cc 
components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
index 6f2880d,cb27159..5cb9721
--- 
a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
+++ 
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/manager/CartridgeSubscriptionManager.java
@@@ -22,9 -22,9 +22,10 @@@ package org.apache.stratos.manager.mana
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
 +import org.apache.stratos.cloud.controller.pojo.LoadbalancerConfig;
  import org.apache.stratos.cloud.controller.pojo.Properties;
  import org.apache.stratos.cloud.controller.pojo.Property;
+ import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregisteredCartridgeExceptionException;
  import org.apache.stratos.manager.client.CloudControllerServiceClient;
  import org.apache.stratos.manager.dao.CartridgeSubscriptionInfo;
  import org.apache.stratos.manager.dto.SubscriptionInfo;
@@@ -74,16 -85,33 +75,15 @@@ public class CartridgeSubscriptionManag
  
          CartridgeInfo cartridgeInfo;
          try {
 -            cartridgeInfo =
 -                            
CloudControllerServiceClient.getServiceClient().getCartridgeInfo(cartridgeType);
 -            /*
 -            if (props != null) {
 -                // TODO: temp fix, need to do a proper fix
 -                Property[] cartridgeInfoProperties = 
cartridgeInfo.getProperties();
 -                if(cartridgeInfoProperties != null) {
 -                     int length = cartridgeInfoProperties.length + 
props.length;
 -                    Property[] combined = new Property[length];
 -                    System.arraycopy(cartridgeInfoProperties, 0, combined, 0, 
cartridgeInfoProperties.length);
 -                    System.arraycopy(props, 0, combined, 
cartridgeInfoProperties.length, props.length);
 -                    cartridgeInfo.setProperties(combined);
 -                } else {
 -                    cartridgeInfo.setProperties(props);
 -                }
 +            cartridgeInfo = 
CloudControllerServiceClient.getServiceClient().getCartridgeInfo(subscriptionData.getCartridgeType());
  
-         } catch (UnregisteredCartridgeException e) {
-             String message =
-                     subscriptionData.getCartridgeType() + " is not a valid 
cartridgeSubscription type. Please try again with a valid cartridgeSubscription 
type.";
 -            }
 -            */
+         } catch 
(CloudControllerServiceUnregisteredCartridgeExceptionException e) {
 -            String message =
 -                             cartridgeType +
 -                                     " is not a valid cartridgeSubscription 
type. Please try again with a valid cartridgeSubscription type.";
++            String message = subscriptionData.getCartridgeType() + " is not a 
valid cartridgeSubscription type. Please try again with a valid 
cartridgeSubscription type.";
              log.error(message);
-             throw e;
+             throw new ADCException(message, e);
  
          } catch (Exception e) {
 -            String message = "Error getting info for " + cartridgeType;
 +            String message = "Error getting info for " + 
subscriptionData.getCartridgeType();
              log.error(message, e);
              throw new ADCException(message, e);
          }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
----------------------------------------------------------------------
diff --cc 
components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
index d318224,ee145f5..5fa3717
--- 
a/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
+++ 
b/components/org.apache.stratos.manager/src/main/java/org/apache/stratos/manager/subscription/utils/CartridgeSubscriptionUtils.java
@@@ -221,242 -178,4 +221,232 @@@ public class CartridgeSubscriptionUtil
  
          return source.substring(0, length);
      }
 +
 +    public static LBDataContext getLoadBalancerDataContext (int tenantId, 
String serviceType, String deploymentPolicyName, LoadbalancerConfig lbConfig) 
throws UnregisteredCartridgeException, ADCException {
 +
 +        String lbCartridgeType = lbConfig.getType();
 +
 +        LBDataContext lbDataCtxt = new LBDataContext();
 +        // set tenant Id
 +        lbDataCtxt.setTenantId(tenantId);
 +
 +        Properties lbReferenceProperties = lbConfig.getProperties();
 +
 +        Property lbRefProperty = new Property();
 +        
lbRefProperty.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
 +
 +        for (org.apache.stratos.cloud.controller.pojo.Property prop : 
lbReferenceProperties.getProperties()) {
 +
 +            String name = prop.getName();
 +            String value = prop.getValue();
 +
 +            // TODO make following a chain of responsibility pattern
 +            if (Constants.NO_LOAD_BALANCER.equals(name)) {
 +
 +                if ("true".equals(value)) {
 +                    if (log.isDebugEnabled()) {
 +                        log.debug("This cartridge does not require a load 
balancer. " + "[Type] " + serviceType);
 +                    }
 +                    lbRefProperty.setValue(name);
 +                    lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
 +                    break;
 +                }
 +            } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
 +
 +                String clusterIdsVal = value;
 +                if (log.isDebugEnabled()) {
 +                    log.debug("This cartridge refers to existing load 
balancers. " + "[Type] " + serviceType + "[Referenced Cluster Ids] " + 
clusterIdsVal);
 +                }
 +
 +                String[] clusterIds = clusterIdsVal.split(",");
 +
 +                for (String clusterId : clusterIds) {
 +                    try {
 +                        
AutoscalerServiceClient.getServiceClient().checkLBExistenceAgainstPolicy(clusterId,
 deploymentPolicyName);
 +                    } catch (Exception ex) {
 +                        // we don't need to throw the error here.
 +                        log.error(ex.getMessage(), ex);
 +                    }
 +                }
 +
 +                lbRefProperty.setValue(name);
 +                lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
 +                break;
 +
 +            } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
 +
 +                if ("true".equals(value)) {
 +
 +                    lbRefProperty.setValue(name);
 +
 +                    CartridgeInfo lbCartridgeInfo;
 +
 +                    try {
 +                        lbCartridgeInfo = 
CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
 +
-                     } catch (UnregisteredCartridgeException e) {
-                         String message = lbCartridgeType + " is not a valid 
cartridgeSubscription type";
-                         log.error(message);
-                         throw e;
- 
 +                    } catch (Exception e) {
 +                        String message = "Error getting info for " + 
lbCartridgeType;
 +                        log.error(message, e);
 +                        throw new ADCException(message, e);
 +                    }
 +
 +                    if (lbCartridgeInfo == null) {
 +                        String msg = "Please specify a LB cartridge type for 
the cartridge: " + serviceType + " as category: " +
 +                            Constants.DEFAULT_LOAD_BALANCER;
 +                        log.error(msg);
 +                        throw new ADCException(msg);
 +                    }
 +
 +                    lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
 +
 +                    if (log.isDebugEnabled()) {
 +                        log.debug("This cartridge uses default load balancer. 
" + "[Type] " + serviceType);
 +                    }
 +
 +                    try {
 +                        // get the valid policies for lb cartridge
 +                        DeploymentPolicy[] lbCartridgeDepPolicies =
 +                                
getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
 +                        // traverse deployment policies of lb cartridge
 +                        for (DeploymentPolicy policy : 
lbCartridgeDepPolicies) {
 +
 +                            // check existence of the subscribed policy
 +                            if (deploymentPolicyName.equals(policy.getId())) {
 +
 +                                if 
(!getAutoscalerServiceClient().checkDefaultLBExistenceAgainstPolicy(deploymentPolicyName))
 {
 +
 +                                    Properties lbProperties = new 
Properties();
 +
 +                                    // if LB cartridge definition has 
properties as well, combine
 +                                    if (lbCartridgeInfo.getProperties() != 
null && lbCartridgeInfo.getProperties().length > 0) {
 +                                        
lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new 
Property[]{lbRefProperty}));
 +
 +                                    } else {
 +                                        lbProperties.setProperties(new 
Property[]{lbRefProperty});
 +                                    }
 +
 +                                    lbDataCtxt.addLBProperties(lbProperties);
 +                                }
 +                            }
 +                        }
 +
 +                    } catch (Exception ex) {
 +                        // we don't need to throw the error here.
 +                        log.error(ex.getMessage(), ex);
 +                    }
 +
 +                    // set deployment and autoscaling policies
 +                    lbDataCtxt.setDeploymentPolicy(deploymentPolicyName);
 +                    
lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
 +
 +                    lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
 +                    break;
 +                }
 +
 +            } else if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
 +
 +                if ("true".equals(value)) {
 +
 +                    lbRefProperty.setValue(name);
 +
 +                    CartridgeInfo lbCartridgeInfo;
 +
 +                    try {
 +                        lbCartridgeInfo = 
CloudControllerServiceClient.getServiceClient().getCartridgeInfo(lbCartridgeType);
 +
-                     } catch (UnregisteredCartridgeException e) {
-                         String message = lbCartridgeType + " is not a valid 
cartridgeSubscription type";
-                         log.error(message);
-                         throw e;
- 
 +                    } catch (Exception e) {
 +                        String message = "Error getting info for " + 
lbCartridgeType;
 +                        log.error(message, e);
 +                        throw new ADCException(message, e);
 +                    }
 +
 +                    if (lbCartridgeInfo == null) {
 +                        String msg = "Please specify a LB cartridge type for 
the cartridge: " + serviceType + " as category: " +
 +                                Constants.SERVICE_AWARE_LOAD_BALANCER;
 +                        log.error(msg);
 +                        throw new ADCException(msg);
 +                    }
 +
 +                    lbDataCtxt.setLbCartridgeInfo(lbCartridgeInfo);
 +
 +                    // add a property for the service type
 +                    Property loadBalancedServiceTypeProperty = new Property();
 +                    
loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
 +                    // set the load balanced service type
 +                    loadBalancedServiceTypeProperty.setValue(serviceType);
 +
 +                    if (log.isDebugEnabled()) {
 +                        log.debug("This cartridge uses a service aware load 
balancer. [Type] " + serviceType);
 +                    }
 +
 +                    try {
 +
 +                        // get the valid policies for lb cartridge
 +                        DeploymentPolicy[] lbCartridgeDepPolicies = 
getAutoscalerServiceClient().getDeploymentPolicies(lbCartridgeType);
 +                        // traverse deployment policies of lb cartridge
 +                        for (DeploymentPolicy policy : 
lbCartridgeDepPolicies) {
 +                            // check existence of the subscribed policy
 +                            if (deploymentPolicyName.equals(policy.getId())) {
 +
 +                                if 
(!getAutoscalerServiceClient().checkServiceLBExistenceAgainstPolicy(serviceType,
 deploymentPolicyName)) {
 +
 +                                    Properties lbProperties = new 
Properties();
 +
 +                                    // if LB cartridge definition has 
properties as well, combine
 +                                    if (lbCartridgeInfo.getProperties() != 
null && lbCartridgeInfo.getProperties().length > 0) {
 +                                        
lbProperties.setProperties(combine(lbCartridgeInfo.getProperties(), new 
Property[]{lbRefProperty, loadBalancedServiceTypeProperty}));
 +
 +                                    } else {
 +                                        lbProperties.setProperties(new 
Property[]{lbRefProperty, loadBalancedServiceTypeProperty});
 +                                    }
 +
 +                                    // set a payload property for load 
balanced service type
 +                                    Property payloadProperty = new Property();
 +                                    
payloadProperty.setName("LOAD_BALANCED_SERVICE_TYPE");  //TODO: refactor 
hardcoded name
 +                                    payloadProperty.setValue(serviceType);
 +
 +                                    lbDataCtxt.addLBProperties(lbProperties);
 +                                }
 +                            }
 +                        }
 +
 +                    } catch (Exception ex) {
 +                        // we don't need to throw the error here.
 +                        log.error(ex.getMessage(), ex);
 +                    }
 +
 +                    // set deployment and autoscaling policies
 +                    lbDataCtxt.setDeploymentPolicy(deploymentPolicyName);
 +                    
lbDataCtxt.setAutoscalePolicy(lbCartridgeInfo.getDefaultAutoscalingPolicy());
 +
 +                    lbDataCtxt.addLoadBalancedServiceProperty(lbRefProperty);
 +                    break;
 +                }
 +            }
 +        }
 +
 +        return lbDataCtxt;
 +    }
 +
 +    private static AutoscalerServiceClient getAutoscalerServiceClient () 
throws ADCException {
 +
 +        try {
 +            return AutoscalerServiceClient.getServiceClient();
 +
 +        } catch (AxisFault axisFault) {
 +            String errorMsg = "Error in getting AutoscalerServiceClient 
instance";
 +            log.error(errorMsg, axisFault);
 +            throw new ADCException (errorMsg, axisFault);
 +        }
 +    }
 +
 +    private static Property[] combine (Property[] propertyArray1, Property[] 
propertyArray2) {
 +
 +        int length = propertyArray1.length + propertyArray2.length;
 +        Property[] combinedProperties = new Property[length];
 +        System.arraycopy(propertyArray1, 0, combinedProperties, 0, 
propertyArray1.length);
 +        System.arraycopy(propertyArray2, 0, combinedProperties, 
propertyArray1.length, propertyArray2.length);
 +
 +        return combinedProperties;
 +    }
  }

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/bc336fa9/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
----------------------------------------------------------------------
diff --cc 
components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
index e243ed8,f95d935..ff52750
--- 
a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
+++ 
b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/services/ServiceUtils.java
@@@ -23,9 -23,15 +23,15 @@@ import org.apache.axis2.context.Configu
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
 +import org.apache.stratos.cloud.controller.pojo.CartridgeConfig;
 +import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
 +import org.apache.stratos.cloud.controller.pojo.Property;
+ import 
org.apache.stratos.autoscaler.stub.AutoScalerServiceInvalidPartitionExceptionException;
+ import 
org.apache.stratos.autoscaler.stub.AutoScalerServiceInvalidPolicyExceptionException;
 -import org.apache.stratos.cloud.controller.pojo.*;
 -import org.apache.stratos.cloud.controller.pojo.Properties;
+ import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceIllegalArgumentExceptionException;
+ import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidCartridgeDefinitionExceptionException;
+ import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidCartridgeTypeExceptionException;
+ import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidIaasProviderExceptionException;
 -import 
org.apache.stratos.cloud.controller.stub.CloudControllerServiceUnregisteredCartridgeExceptionException;
  import org.apache.stratos.manager.client.AutoscalerServiceClient;
  import org.apache.stratos.manager.client.CloudControllerServiceClient;
  import org.apache.stratos.manager.deploy.service.Service;
@@@ -875,19 -1024,302 +996,16 @@@ public class ServiceUtils 
          
subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoURL());
          
subscriptionData.setRepositoryPassword(cartridgeInfoBean.getRepoPassword());
  
 -        Properties properties = new Properties();
 -        if(cartridgeInfoBean.isPersistanceRequired()){
 -            /*
 -            PersistanceMapping persistanceMapping = new PersistanceMapping();
 -            
persistanceMapping.setPersistanceRequired(persistanceMappingBean.persistanceRequired);
 -            persistanceMapping.setSize(persistanceMappingBean.size);
 -            persistanceMapping.setDevice(persistanceMappingBean.device);
 -            
persistanceMapping.setRemoveOntermination(persistanceMappingBean.removeOnTermination);
 -            subscriptionData.setPersistanceMapping(persistanceMapping);
 -            */
 -
 -            // Add persistance mapping properties to the subscription.
 -            Property persistanceRequiredProperty = new Property();
 -            persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
 -            
persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
 -
 -            Property sizeProperty = new Property();
 -            sizeProperty.setName(VOLUME_SIZE);
 -            sizeProperty.setValue(cartridgeInfoBean.getSize());
 -
 -            Property deleteOnTerminationProperty = new Property();
 -            deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
 -            deleteOnTerminationProperty.setValue(String.valueOf(    
cartridgeInfoBean.isRemoveOnTermination()));
 -
 -            properties.setProperties(new 
Property[]{persistanceRequiredProperty,sizeProperty, 
deleteOnTerminationProperty});
 -        }
 -
 -
 -        // If multitenant, return for now. TODO -- fix properly
 -        if(cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
 -               log.info(" ******* MT cartridge ******* ");
 -
 -            subscriptionData.setPrivateRepository(false);
 -            subscriptionData.setLbClusterId(null);
 -            subscriptionData.setProperties(null);
 -
 -            CartridgeSubscription cartridgeSubscription =
 -                                        
cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
 -               log.info(" --- ** -- ");
 -              return 
cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription,
 properties);
 -                       
 +        if (cartridgeInfoBean.isPersistanceRequired()) {
 +            // Add persistence related properties to PersistenceContext
 +            PersistenceContext persistenceContext = new PersistenceContext();
 +            
persistenceContext.setPersistanceRequiredProperty(IS_VOLUME_REQUIRED, 
String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
 +            persistenceContext.setSizeProperty(VOLUME_SIZE, 
cartridgeInfoBean.getSize());
 +            
persistenceContext.setDeleteOnTerminationProperty(SHOULD_DELETE_VOLUME, 
String.valueOf(cartridgeInfoBean.isRemoveOnTermination()));
- 
-             // set the PersistenceContext to to SubscriptionData
-             subscriptionData.setPersistanceCtxt(persistenceContext);
          }
 -        
 -        List<Property> lbRefProp = new ArrayList<Property>();
 -
 -        // get lb config reference
 -        LoadbalancerConfig lbConfig = cartridgeInfo.getLbConfig();
 -        String lbClusterId = null;
 -
 -        if (lbConfig == null || lbConfig.getProperties() == null) {
 -            if (log.isDebugEnabled()) {
 -                log.debug("This Service does not require a load balancer. " + 
"[Service Name] " +
 -                          cartridgeType);
 -            }
 -        } else {
 -
 -            Properties lbReferenceProperties = lbConfig.getProperties();
 -
 -            Property property = new Property();
 -            
property.setName(org.apache.stratos.messaging.util.Constants.LOAD_BALANCER_REF);
  
 -
 -            for (org.apache.stratos.cloud.controller.pojo.Property prop : 
lbReferenceProperties.getProperties()) {
 -
 -                String name = prop.getName();
 -                String value = prop.getValue();
 -
 -                // TODO make following a chain of responsibility pattern
 -                if (Constants.NO_LOAD_BALANCER.equals(name)) {
 -                    if ("true".equals(value)) {
 -                        if (log.isDebugEnabled()) {
 -                            log.debug("This cartridge does not require a load 
balancer. " +
 -                                      "[Type] " + cartridgeType);
 -                        }
 -                        property.setValue(name);
 -                        lbRefProp.add(property);
 -                        break;
 -                    }
 -                } else if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
 -                    String clusterIdsVal = value;
 -                    if (log.isDebugEnabled()) {
 -                        log.debug("This cartridge refers to existing load 
balancers. " + "[Type] " +
 -                                  cartridgeType + "[Referenced Cluster Ids] " 
+ clusterIdsVal);
 -                    }
 -
 -                    String[] clusterIds = clusterIdsVal.split(",");
 -
 -                    for (String clusterId : clusterIds) {
 -                        if (autoscalerServiceClient != null) {
 -                            try {
 -                                
autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,
 -                                                                              
        deploymentPolicy);
 -                            } catch (Exception ex) {
 -                                // we don't need to throw the error here.
 -                                log.error(ex.getMessage(), ex);
 -                            }
 -                        }
 -                    }
 -
 -                    property.setValue(name);
 -                    lbRefProp.add(property);
 -                    break;
 -
 -                } else if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
 -
 -                    if ("true".equals(value)) {
 -
 -                        CartridgeInfo lbCartridgeInfo = null;
 -                        String lbCartridgeType = lbConfig.getType();
 -                        try {
 -                            // retrieve lb Cartridge info
 -                            if(lbCartridgeType != null) {
 -                                lbCartridgeInfo = 
cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
 -                            }
 -                        } catch (Exception e) {
 -                            String msg = "Cannot get cartridge info: " + 
cartridgeType;
 -                            log.error(msg, e);
 -                            throw new ADCException(msg, e);
 -                        }
 -
 -                        property.setValue(name);
 -                        if (log.isDebugEnabled()) {
 -                            log.debug("This cartridge uses default load 
balancer. " + "[Type] " +
 -                                      cartridgeType);
 -                        }
 -                        if (autoscalerServiceClient != null) {
 -                            try {
 -                                // get the valid policies for lb cartridge
 -                                DeploymentPolicy[] lbCartridgeDepPolicies =
 -                                                                            
autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
 -                                // traverse deployment policies of lb 
cartridge
 -                                for (DeploymentPolicy policy : 
lbCartridgeDepPolicies) {
 -                                    // check existence of the subscribed 
policy
 -                                    if 
(deploymentPolicy.equals(policy.getId())) {
 -
 -                                        if 
(!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy))
 {
 -
 -                                            // if lb cluster doesn't exist
 -                                            String lbAlias = "lb" + new 
Random().nextInt();
 -                                            if(lbCartridgeInfo != null) {
 -                                               
lbCartridgeInfo.addProperties(property);
 -                                            lbClusterId = 
subscribeToLb(lbCartridgeType, cartridgeType,
 -                                                          lbAlias,
 -                                                          
lbCartridgeInfo.getDefaultAutoscalingPolicy(),
 -                                                          deploymentPolicy, 
configurationContext,
 -                                                    tenantUsername, 
tenantDomain,
 -                                                          
lbCartridgeInfo.getProperties());
 -                                            } else {
 -                                                String msg = "Please specify 
a LB cartridge type for the cartridge: "
 -                                                                + 
cartridgeType + " as category: " +
 -                                                                
Constants.DEFAULT_LOAD_BALANCER;
 -                                                log.error(msg);
 -                                                throw new ADCException(msg);
 -                                            }
 -                                        }
 -                                    }
 -                                }
 -
 -                            } catch (Exception ex) {
 -                                // we don't need to throw the error here.
 -                                log.error(ex.getMessage(), ex);
 -                            }
 -                        }
 -
 -                        lbRefProp.add(property);
 -                        break;
 -                    }
 -
 -                } else if 
(Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
 -
 -                    if ("true".equals(value)) {
 -
 -                        CartridgeInfo lbCartridgeInfo = null;
 -                        String lbCartridgeType = lbConfig.getType();
 -                        try {
 -                            // retrieve lb Cartridge info
 -                            if(lbCartridgeType != null) {
 -                                lbCartridgeInfo = 
cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
 -                            }
 -                        } catch (Exception e) {
 -                            String msg = "Cannot get cartridge info: " + 
cartridgeType+". Cause: "+e.getMessage();
 -                            log.error(msg, e);
 -                            throw new ADCException(msg, e);
 -                        }
 -
 -                        // add a property for the service type
 -                        Property loadBalancedServiceTypeProperty = new 
Property();
 -                        
loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
 -
 -                        property.setValue(name);
 -                        // set the load balanced service type
 -                        
loadBalancedServiceTypeProperty.setValue(cartridgeType);
 -                        if (log.isDebugEnabled()) {
 -                            log.debug("This cartridge uses a service aware 
load balancer. " +
 -                                    "[Type] " + cartridgeType);
 -                        }
 -                        if (autoscalerServiceClient != null) {
 -                            try {
 -
 -                                // get the valid policies for lb cartridge
 -                                DeploymentPolicy[] lbCartridgeDepPolicies =
 -                                        
autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
 -                                // traverse deployment policies of lb 
cartridge
 -                                for (DeploymentPolicy policy : 
lbCartridgeDepPolicies) {
 -                                    // check existence of the subscribed 
policy
 -                                    if 
(deploymentPolicy.equals(policy.getId())) {
 -
 -                                        if 
(!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,
 -                                                deploymentPolicy)) {
 -
 -                                            // if lb cluster doesn't exist
 -                                            String lbAlias =
 -                                                    "lb" + cartridgeType +
 -                                                            new 
Random().nextInt();
 -
 -                                            if(lbCartridgeInfo != null) {
 -                                                
lbCartridgeInfo.addProperties(property);
 -                                                
lbCartridgeInfo.addProperties(loadBalancedServiceTypeProperty);
 -
 -                                                lbClusterId = 
subscribeToLb(lbCartridgeType, cartridgeType,
 -                                                    lbAlias,
 -                                                    
lbCartridgeInfo.getDefaultAutoscalingPolicy(),
 -                                                    deploymentPolicy,
 -                                                    configurationContext, 
tenantUsername,
 -                                                    tenantDomain,
 -                                                    
lbCartridgeInfo.getProperties());
 -                                            } else {
 -                                                String msg = "Please specify 
a LB cartridge type for the cartridge: "
 -                                                                + 
cartridgeType + " as category: " +
 -                                                                
Constants.SERVICE_AWARE_LOAD_BALANCER;
 -                                                log.error(msg);
 -                                                throw new ADCException(msg);
 -                                            }
 -                                        }
 -                                    }
 -                                }
 -
 -                            } catch (Exception ex) {
 -                                // we don't need to throw the error here.
 -                                log.error(ex.getMessage(), ex);
 -                            }
 -                        }
 -
 -                        lbRefProp.add(property);
 -                        break;
 -                    }
 -                }
 -            }
 -        }
 -
 -        
subscriptionData.setPrivateRepository(cartridgeInfoBean.isPrivateRepo());
 -        subscriptionData.setLbClusterId(lbClusterId);
 -        subscriptionData.setProperties(lbRefProp.toArray(new Property[0]));
 -        CartridgeSubscription cartridgeSubscription =
 -                                                      
cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
 -
 -
 -        if (dataCartridgeAlias != null && 
!dataCartridgeAlias.trim().isEmpty()) {
 -
 -            /*dataCartridgeAlias = dataCartridgeAlias.trim();
 -
 -            CartridgeSubscription connectingCartridgeSubscription = null;
 -            try {
 -                connectingCartridgeSubscription =
 -                                                  
cartridgeSubsciptionManager.getCartridgeSubscription(tenantDomain,
 -                                                                              
                         dataCartridgeAlias);
 -
 -            } catch (NotSubscribedException e) {
 -                log.error(e.getMessage(), e);
 -            }
 -            if (connectingCartridgeSubscription != null) {
 -                try {
 -                    
cartridgeSubsciptionManager.connectCartridges(tenantDomain,
 -                                                                  
cartridgeSubscription,
 -                                                                  
connectingCartridgeSubscription.getAlias());
 -
 -                } catch (NotSubscribedException e) {
 -                    log.error(e.getMessage(), e);
 -
 -                } catch (AxisFault axisFault) {
 -                    log.error(axisFault.getMessage(), axisFault);
 -                }
 -            } else {
 -                log.error("Failed to connect. No cartridge subscription found 
for tenant " +
 -                          
ApplicationManagementUtil.getTenantId(configurationContext) +
 -                          " with alias " + alias);
 -            }*/
 -        }
 -
 -        for (Property lbRefProperty : lbRefProp) {
 -            properties.addProperties(lbRefProperty);
 -        }
 -
 -        SubscriptionInfo registerCartridgeSubscription = 
cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription,
 properties);
 -        
 -        return registerCartridgeSubscription;
 +        //subscribe
 +        return 
cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
  
      }
  
@@@ -932,8 -1364,57 +1050,55 @@@
                  new 
org.apache.stratos.rest.endpoint.bean.topology.Cluster[clusters.size()];
          arrCluster = clusters.toArray(arrCluster);
          return arrCluster;
+ 
 -
 -
      }
  
+     // return the cluster id for the lb. This is a temp fix.
 -    private static String subscribeToLb(String cartridgeType, String 
loadBalancedCartridgeType, String lbAlias,
++    /*private static String subscribeToLb(String cartridgeType, String 
loadBalancedCartridgeType, String lbAlias,
+         String defaultAutoscalingPolicy, String deploymentPolicy,
+         ConfigurationContext configurationContext, String userName, String 
tenantDomain, Property[] props) throws ADCException {
+ 
+         CartridgeSubscription cartridgeSubscription;
+ 
+         try {
+             if(log.isDebugEnabled()) {
+                 log.debug("Subscribing to a load balancer [cartridge] 
"+cartridgeType+" [alias] "+lbAlias);
+             }
+ 
+             SubscriptionData subscriptionData = new SubscriptionData();
+             subscriptionData.setCartridgeType(cartridgeType);
+             subscriptionData.setCartridgeAlias(lbAlias.trim());
+             
subscriptionData.setAutoscalingPolicyName(defaultAutoscalingPolicy);
+             subscriptionData.setDeploymentPolicyName(deploymentPolicy);
+             subscriptionData.setTenantDomain(tenantDomain);
+             
subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
+             subscriptionData.setTenantAdminUsername(userName);
+             subscriptionData.setRepositoryType("git");
+             //subscriptionData.setProperties(props);
+             subscriptionData.setPrivateRepository(false);
+ 
+             cartridgeSubscription =
+                     
cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
+ 
+             //set a payload parameter to indicate the load balanced cartridge 
type
+             
cartridgeSubscription.getPayloadData().add("LOAD_BALANCED_SERVICE_TYPE", 
loadBalancedCartridgeType);
+ 
+             Properties lbProperties = new Properties();
+             lbProperties.setProperties(props);
+             
cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription,
 lbProperties);
+             
+             if(log.isDebugEnabled()) {
+                 log.debug("Successfully subscribed to a load balancer 
[cartridge] "+cartridgeType+" [alias] "+lbAlias);
+             }
+         } catch (Exception e) {
+             String msg = "Error while subscribing to load balancer cartridge 
[type] "+cartridgeType+". Cause: "+e.getMessage();
+             log.error(msg, e);
+             throw new ADCException(msg, e);
+         }
+ 
+         return cartridgeSubscription.getClusterDomain();
 -    }
++    } */
+ 
      static StratosAdminResponse unsubscribe(String alias, String 
tenantDomain) throws RestAPIException {
  
          try {

Reply via email to