Program: 116651
Project: 116651
Buggy source:
static SubscriptionInfo subscribe(CartridgeInfoBean cartridgeInfoBean,ConfigurationContext configurationContext,String tenantUsername,String tenantDomain) throws ADCException, PolicyException, UnregisteredCartridgeException, InvalidCartridgeAliasException, DuplicateCartridgeAliasException, RepositoryRequiredException, AlreadySubscribedException, RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
  CartridgeSubscriptionUtils.validateCartridgeAlias(ApplicationManagementUtil.getTenantId(configurationContext),cartridgeInfoBean.getCartridgeType(),cartridgeInfoBean.getAlias());
  AutoscalerServiceClient autoscalerServiceClient=getAutoscalerServiceClient();
  CloudControllerServiceClient cloudControllerServiceClient=getCloudControllerServiceClient();
  CartridgeInfo cartridgeInfo;
  try {
    cartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(cartridgeInfoBean.getCartridgeType());
  }
 catch (  Exception e) {
    String msg="String_Node_Str" + cartridgeInfoBean.getCartridgeType();
    log.error(msg,e);
    throw new ADCException(msg,e);
  }
  String cartridgeType=cartridgeInfoBean.getCartridgeType();
  String deploymentPolicy=cartridgeInfoBean.getDeploymentPolicy();
  String autoscalingPolicy=cartridgeInfoBean.getAutoscalePolicy();
  String dataCartridgeAlias=cartridgeInfoBean.getDataCartridgeAlias();
  SubscriptionData subscriptionData=new SubscriptionData();
  subscriptionData.setCartridgeType(cartridgeType);
  subscriptionData.setCartridgeAlias(cartridgeInfoBean.getAlias().trim());
  subscriptionData.setDataCartridgeAlias(dataCartridgeAlias);
  subscriptionData.setAutoscalingPolicyName(autoscalingPolicy);
  subscriptionData.setDeploymentPolicyName(deploymentPolicy);
  subscriptionData.setTenantDomain(tenantDomain);
  subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
  subscriptionData.setTenantAdminUsername(tenantUsername);
  subscriptionData.setRepositoryType("String_Node_Str");
  subscriptionData.setRepositoryURL(cartridgeInfoBean.getRepoURL());
  subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoURL());
  subscriptionData.setRepositoryPassword(cartridgeInfoBean.getRepoPassword());
  Properties properties=new Properties();
  if (cartridgeInfoBean.isPersistanceRequired()) {
    Property persistanceRequiredProperty=new Property();
    persistanceRequiredProperty.setName(IS_VOLUME_REQUIRED);
    persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isPersistanceRequired()));
    Property sizeProperty=new Property();
    persistanceRequiredProperty.setName(VOLUME_SIZE);
    persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.getSize()));
    Property deviceProperty=new Property();
    persistanceRequiredProperty.setName(DEVICE_NAME);
    persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.getDevice()));
    Property deleteOnTerminationProperty=new Property();
    persistanceRequiredProperty.setName(SHOULD_DELETE_VOLUME);
    persistanceRequiredProperty.setValue(String.valueOf(cartridgeInfoBean.isRemoveOnTermination()));
    Properties props=new Properties();
    props.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty,deviceProperty,deleteOnTerminationProperty});
  }
  if (cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
    log.info("String_Node_Str");
    subscriptionData.setPrivateRepository(false);
    subscriptionData.setLbClusterId(null);
    subscriptionData.setProperties(null);
    CartridgeSubscription cartridgeSubscription=cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
    log.info("String_Node_Str");
    return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription,properties);
  }
  List<Property> lbRefProp=new ArrayList<Property>();
  LoadbalancerConfig lbConfig=cartridgeInfo.getLbConfig();
  String lbClusterId=null;
  if (lbConfig == null || lbConfig.getProperties() == null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + "String_Node_Str" + 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();
      if (Constants.NO_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType);
          }
          property.setValue(name);
          lbRefProp.add(property);
          break;
        }
      }
 else       if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
        String clusterIdsVal=value;
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType + "String_Node_Str"+ clusterIdsVal);
        }
        String[] clusterIds=clusterIdsVal.split("String_Node_Str");
        for (        String clusterId : clusterIds) {
          if (autoscalerServiceClient != null) {
            try {
              autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,deploymentPolicy);
            }
 catch (            Exception ex) {
              log.error(ex.getMessage(),ex);
            }
          }
        }
        property.setValue(name);
        lbRefProp.add(property);
        break;
      }
 else       if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          CartridgeInfo lbCartridgeInfo=null;
          String lbCartridgeType=lbConfig.getType();
          try {
            if (lbCartridgeType != null) {
              lbCartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
            }
          }
 catch (          Exception e) {
            String msg="String_Node_Str" + cartridgeType;
            log.error(msg,e);
            throw new ADCException(msg,e);
          }
          property.setValue(name);
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType);
          }
          if (autoscalerServiceClient != null) {
            try {
              DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
              for (              DeploymentPolicy policy : lbCartridgeDepPolicies) {
                if (deploymentPolicy.equals(policy.getId())) {
                  if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
                    String lbAlias="String_Node_Str" + 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="String_Node_Str" + cartridgeType + "String_Node_Str"+ Constants.DEFAULT_LOAD_BALANCER;
                      log.error(msg);
                      throw new ADCException(msg);
                    }
                  }
                }
              }
            }
 catch (            Exception ex) {
              log.error(ex.getMessage(),ex);
            }
          }
          lbRefProp.add(property);
          break;
        }
      }
 else       if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          CartridgeInfo lbCartridgeInfo=null;
          String lbCartridgeType=lbConfig.getType();
          try {
            if (lbCartridgeType != null) {
              lbCartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
            }
          }
 catch (          Exception e) {
            String msg="String_Node_Str" + cartridgeType;
            log.error(msg,e);
            throw new ADCException(msg,e);
          }
          Property loadBalancedServiceTypeProperty=new Property();
          loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
          property.setValue(name);
          loadBalancedServiceTypeProperty.setValue(cartridgeType);
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType);
          }
          if (autoscalerServiceClient != null) {
            try {
              DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
              for (              DeploymentPolicy policy : lbCartridgeDepPolicies) {
                if (deploymentPolicy.equals(policy.getId())) {
                  if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,deploymentPolicy)) {
                    String lbAlias="String_Node_Str" + 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="String_Node_Str" + cartridgeType + "String_Node_Str"+ Constants.SERVICE_AWARE_LOAD_BALANCER;
                      log.error(msg);
                      throw new ADCException(msg);
                    }
                  }
                }
              }
            }
 catch (            Exception ex) {
              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()) {
  }
  for (  Property lbRefProperty : lbRefProp) {
    properties.addProperties(lbRefProperty);
  }
  SubscriptionInfo registerCartridgeSubscription=cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription,properties);
  return registerCartridgeSubscription;
}

Fixed version (ground truth):
static SubscriptionInfo subscribe(CartridgeInfoBean cartridgeInfoBean,ConfigurationContext configurationContext,String tenantUsername,String tenantDomain) throws ADCException, PolicyException, UnregisteredCartridgeException, InvalidCartridgeAliasException, DuplicateCartridgeAliasException, RepositoryRequiredException, AlreadySubscribedException, RepositoryCredentialsRequiredException, InvalidRepositoryException, RepositoryTransportException {
  CartridgeSubscriptionUtils.validateCartridgeAlias(ApplicationManagementUtil.getTenantId(configurationContext),cartridgeInfoBean.getCartridgeType(),cartridgeInfoBean.getAlias());
  AutoscalerServiceClient autoscalerServiceClient=getAutoscalerServiceClient();
  CloudControllerServiceClient cloudControllerServiceClient=getCloudControllerServiceClient();
  CartridgeInfo cartridgeInfo;
  try {
    cartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(cartridgeInfoBean.getCartridgeType());
  }
 catch (  Exception e) {
    String msg="String_Node_Str" + cartridgeInfoBean.getCartridgeType();
    log.error(msg,e);
    throw new ADCException(msg,e);
  }
  String cartridgeType=cartridgeInfoBean.getCartridgeType();
  String deploymentPolicy=cartridgeInfoBean.getDeploymentPolicy();
  String autoscalingPolicy=cartridgeInfoBean.getAutoscalePolicy();
  String dataCartridgeAlias=cartridgeInfoBean.getDataCartridgeAlias();
  SubscriptionData subscriptionData=new SubscriptionData();
  subscriptionData.setCartridgeType(cartridgeType);
  subscriptionData.setCartridgeAlias(cartridgeInfoBean.getAlias().trim());
  subscriptionData.setDataCartridgeAlias(dataCartridgeAlias);
  subscriptionData.setAutoscalingPolicyName(autoscalingPolicy);
  subscriptionData.setDeploymentPolicyName(deploymentPolicy);
  subscriptionData.setTenantDomain(tenantDomain);
  subscriptionData.setTenantId(ApplicationManagementUtil.getTenantId(configurationContext));
  subscriptionData.setTenantAdminUsername(tenantUsername);
  subscriptionData.setRepositoryType("String_Node_Str");
  subscriptionData.setRepositoryURL(cartridgeInfoBean.getRepoURL());
  subscriptionData.setRepositoryUsername(cartridgeInfoBean.getRepoURL());
  subscriptionData.setRepositoryPassword(cartridgeInfoBean.getRepoPassword());
  Properties properties=new Properties();
  if (cartridgeInfoBean.isPersistanceRequired()) {
    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(String.valueOf(cartridgeInfoBean.getSize()));
    Property deviceProperty=new Property();
    deviceProperty.setName(DEVICE_NAME);
    deviceProperty.setValue(String.valueOf(cartridgeInfoBean.getDevice()));
    Property deleteOnTerminationProperty=new Property();
    deleteOnTerminationProperty.setName(SHOULD_DELETE_VOLUME);
    deleteOnTerminationProperty.setValue(String.valueOf(cartridgeInfoBean.isRemoveOnTermination()));
    properties.setProperties(new Property[]{persistanceRequiredProperty,sizeProperty,deviceProperty,deleteOnTerminationProperty});
  }
  if (cartridgeInfo != null && cartridgeInfo.getMultiTenant()) {
    log.info("String_Node_Str");
    subscriptionData.setPrivateRepository(false);
    subscriptionData.setLbClusterId(null);
    subscriptionData.setProperties(null);
    CartridgeSubscription cartridgeSubscription=cartridgeSubsciptionManager.subscribeToCartridgeWithProperties(subscriptionData);
    log.info("String_Node_Str");
    return cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription,properties);
  }
  List<Property> lbRefProp=new ArrayList<Property>();
  LoadbalancerConfig lbConfig=cartridgeInfo.getLbConfig();
  String lbClusterId=null;
  if (lbConfig == null || lbConfig.getProperties() == null) {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + "String_Node_Str" + 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();
      if (Constants.NO_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType);
          }
          property.setValue(name);
          lbRefProp.add(property);
          break;
        }
      }
 else       if (Constants.EXISTING_LOAD_BALANCERS.equals(name)) {
        String clusterIdsVal=value;
        if (log.isDebugEnabled()) {
          log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType + "String_Node_Str"+ clusterIdsVal);
        }
        String[] clusterIds=clusterIdsVal.split("String_Node_Str");
        for (        String clusterId : clusterIds) {
          if (autoscalerServiceClient != null) {
            try {
              autoscalerServiceClient.checkLBExistenceAgainstPolicy(clusterId,deploymentPolicy);
            }
 catch (            Exception ex) {
              log.error(ex.getMessage(),ex);
            }
          }
        }
        property.setValue(name);
        lbRefProp.add(property);
        break;
      }
 else       if (Constants.DEFAULT_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          CartridgeInfo lbCartridgeInfo=null;
          String lbCartridgeType=lbConfig.getType();
          try {
            if (lbCartridgeType != null) {
              lbCartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
            }
          }
 catch (          Exception e) {
            String msg="String_Node_Str" + cartridgeType;
            log.error(msg,e);
            throw new ADCException(msg,e);
          }
          property.setValue(name);
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType);
          }
          if (autoscalerServiceClient != null) {
            try {
              DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
              for (              DeploymentPolicy policy : lbCartridgeDepPolicies) {
                if (deploymentPolicy.equals(policy.getId())) {
                  if (!autoscalerServiceClient.checkDefaultLBExistenceAgainstPolicy(deploymentPolicy)) {
                    String lbAlias="String_Node_Str" + 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="String_Node_Str" + cartridgeType + "String_Node_Str"+ Constants.DEFAULT_LOAD_BALANCER;
                      log.error(msg);
                      throw new ADCException(msg);
                    }
                  }
                }
              }
            }
 catch (            Exception ex) {
              log.error(ex.getMessage(),ex);
            }
          }
          lbRefProp.add(property);
          break;
        }
      }
 else       if (Constants.SERVICE_AWARE_LOAD_BALANCER.equals(name)) {
        if ("String_Node_Str".equals(value)) {
          CartridgeInfo lbCartridgeInfo=null;
          String lbCartridgeType=lbConfig.getType();
          try {
            if (lbCartridgeType != null) {
              lbCartridgeInfo=cloudControllerServiceClient.getCartridgeInfo(lbCartridgeType);
            }
          }
 catch (          Exception e) {
            String msg="String_Node_Str" + cartridgeType;
            log.error(msg,e);
            throw new ADCException(msg,e);
          }
          Property loadBalancedServiceTypeProperty=new Property();
          loadBalancedServiceTypeProperty.setName(Constants.LOAD_BALANCED_SERVICE_TYPE);
          property.setValue(name);
          loadBalancedServiceTypeProperty.setValue(cartridgeType);
          if (log.isDebugEnabled()) {
            log.debug("String_Node_Str" + "String_Node_Str" + cartridgeType);
          }
          if (autoscalerServiceClient != null) {
            try {
              DeploymentPolicy[] lbCartridgeDepPolicies=autoscalerServiceClient.getDeploymentPolicies(lbCartridgeType);
              for (              DeploymentPolicy policy : lbCartridgeDepPolicies) {
                if (deploymentPolicy.equals(policy.getId())) {
                  if (!autoscalerServiceClient.checkServiceLBExistenceAgainstPolicy(cartridgeType,deploymentPolicy)) {
                    String lbAlias="String_Node_Str" + 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="String_Node_Str" + cartridgeType + "String_Node_Str"+ Constants.SERVICE_AWARE_LOAD_BALANCER;
                      log.error(msg);
                      throw new ADCException(msg);
                    }
                  }
                }
              }
            }
 catch (            Exception ex) {
              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()) {
  }
  for (  Property lbRefProperty : lbRefProp) {
    properties.addProperties(lbRefProperty);
  }
  SubscriptionInfo registerCartridgeSubscription=cartridgeSubsciptionManager.registerCartridgeSubscription(cartridgeSubscription,properties);
  return registerCartridgeSubscription;
}