http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java index ffa9552..bc3052a 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/GroupMonitor.java @@ -164,7 +164,7 @@ public class GroupMonitor extends ParentComponentMonitor { Collection<Instance> parentInstances = parent.getInstances(); for (Instance parentInstance : parentInstances) { - if (parentInstance.getNetworkPartitionUuid().equals(networkPartitionContext.getId())) { + if (parentInstance.getNetworkPartitionId().equals(networkPartitionContext.getId())) { int nonTerminatedInstancesCount = networkPartitionContext. getNonTerminatedInstancesCount(parentInstance.getInstanceId()); int minInstances = networkPartitionContext. @@ -234,7 +234,7 @@ public class GroupMonitor extends ParentComponentMonitor { * @param instanceContext the instance which reaches its max * @param networkPartitionContext the network-partition used for the instances */ - private void handleScalingUpBeyondMax(InstanceContext instanceContext, + private void handleScalingUpBeyondMax(ParentInstanceContext instanceContext, NetworkPartitionContext networkPartitionContext) { if (!hasScalingDependents) { //handling the group scaling and if pending instances found, @@ -513,7 +513,7 @@ public class GroupMonitor extends ParentComponentMonitor { getAppMonitor(appId); //In case if the group instance is not in terminating while application is // terminating, changing the status to terminating - if(applicationMonitor.isTerminating() && instance.getStatus().getCode() < 3) { + if (applicationMonitor.isTerminating() && instance.getStatus().getCode() < 3) { //Sending group instance terminating event ApplicationBuilder.handleGroupTerminatingEvent(appId, id, instanceId); } @@ -686,7 +686,7 @@ public class GroupMonitor extends ParentComponentMonitor { String deploymentPolicyId = AutoscalerUtil.getDeploymentPolicyIdByAlias(appId, groupAlias); DeploymentPolicy deploymentPolicy = PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId); - String networkPartitionId = parentInstanceContext.getNetworkPartitionUuid(); + String networkPartitionId = parentInstanceContext.getNetworkPartitionId(); if (this.getNetworkPartitionContextsMap().containsKey(networkPartitionId)) { parentLevelNetworkPartitionContext = this.getNetworkPartitionContextsMap(). get(networkPartitionId); @@ -695,7 +695,7 @@ public class GroupMonitor extends ParentComponentMonitor { NetworkPartitionRef[] networkPartitions = deploymentPolicy.getNetworkPartitionRefs(); NetworkPartitionRef networkPartition = null; for (NetworkPartitionRef networkPartition1 : networkPartitions) { - if (networkPartition1.getUuid().equals(networkPartitionId)) { + if (networkPartition1.getId().equals(networkPartitionId)) { networkPartition = networkPartition1; } } @@ -733,7 +733,7 @@ public class GroupMonitor extends ParentComponentMonitor { private void addPartitionContext(Instance parentInstanceContext, NetworkPartitionContext networkPartitionContext, String groupAlias) { - String networkPartitionId = parentInstanceContext.getNetworkPartitionUuid(); + String networkPartitionId = parentInstanceContext.getNetworkPartitionId(); String deploymentPolicyId = AutoscalerUtil.getDeploymentPolicyIdByAlias(appId, groupAlias); DeploymentPolicy deploymentPolicy = PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId); @@ -755,7 +755,7 @@ public class GroupMonitor extends ParentComponentMonitor { NetworkPartitionRef networkPartitionRef = null; if (networkPartitions != null && networkPartitions.length != 0) { for (NetworkPartitionRef i : networkPartitions) { - if (i.getUuid().equals(networkPartitionId)) { + if (i.getId().equals(networkPartitionId)) { networkPartitionRef = i; } } @@ -767,14 +767,14 @@ public class GroupMonitor extends ParentComponentMonitor { if (partitions != null && partitions.length != 0) { for (PartitionRef partition : partitions) { - if (networkPartitionContext.getPartitionCtxt(partition.getUuid()) == null) { + if (networkPartitionContext.getPartitionCtxt(partition.getId()) == null) { ParentLevelPartitionContext parentLevelPartitionContext = new ParentLevelPartitionContext( - partition.getUuid(), networkPartitionId, deploymentPolicyId); + partition.getId(), networkPartitionId, deploymentPolicyId); networkPartitionContext.addPartitionContext(parentLevelPartitionContext); if (log.isInfoEnabled()) { log.info(String.format("[Partition] %s has been added for the [Group] %s", - partition.getUuid(), this.id)); + partition.getId(), this.id)); } } } @@ -788,7 +788,7 @@ public class GroupMonitor extends ParentComponentMonitor { * Creates the group instance and adds the required context objects * * @param group the group - * @param partitionContext the parent instance context + * @param parentInstance the parent instance context * @param partitionContext partition-context used to create the group instance * @param parentLevelNetworkPartitionContext the group level network partition context */ @@ -804,7 +804,7 @@ public class GroupMonitor extends ParentComponentMonitor { partitionId = partitionContext.getPartitionId(); } - groupInstance = createGroupInstance(group, parentInstance.getNetworkPartitionUuid(), + groupInstance = createGroupInstance(group, parentInstance.getNetworkPartitionId(), parentInstance.getInstanceId(), partitionId); }
http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java index 0f7bb5b..98e97cf 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/component/ParentComponentMonitor.java @@ -660,7 +660,7 @@ public abstract class ParentComponentMonitor extends Monitor { int noOfInstancesOfRequiredStatus = 0; for (String childInstanceId : groupInstances) { GroupInstance childGroupInstance = (GroupInstance) monitor.getInstance(childInstanceId); - networkPartitionId = childGroupInstance.getNetworkPartitionUuid(); + networkPartitionId = childGroupInstance.getNetworkPartitionId(); if (childGroupInstance.getStatus() == requiredStatus) { noOfInstancesOfRequiredStatus++; } http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/ServiceGroup.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/ServiceGroup.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/ServiceGroup.java index e2d8ae8..65a9c61 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/ServiceGroup.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/ServiceGroup.java @@ -25,9 +25,7 @@ public class ServiceGroup implements Serializable { private static final long serialVersionUID = -7413745300105885793L; - private String uuid; - - private String name; + private String name; private ServiceGroup[] groups; @@ -35,12 +33,12 @@ public class ServiceGroup implements Serializable { private Dependencies dependencies; - public String getUuid() { - return uuid; + public String getName() { + return name; } - public void setUuid(String uuid) { - this.uuid = uuid; + public void setName(String name) { + this.name = name; } public String[] getCartridges() { @@ -66,22 +64,4 @@ public class ServiceGroup implements Serializable { public void setGroups(ServiceGroup[] groups) { this.groups = groups; } - - private int tenantId; - - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java index 3854544..3336776 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java @@ -55,8 +55,12 @@ public class PolicyManager { private static Map<String, ApplicationPolicy> applicationPolicyListMap; - public Collection<DeploymentPolicy> getDeploymentPolicies() { - return deploymentPolicyListMap.values(); + private PolicyManager() { + // Initialize distributed object provider + DistributedObjectProvider distributedObjectProvider = ServiceReferenceHolder.getInstance().getDistributedObjectProvider(); + autoscalePolicyListMap = distributedObjectProvider.getMap(AS_POLICY_ID_TO_AUTOSCALE_POLICY_MAP); + deploymentPolicyListMap = distributedObjectProvider.getMap(DEPLOYMENT_POLICY_ID_TO_DEPLOYMENT_POLICY_MAP); + applicationPolicyListMap = distributedObjectProvider.getMap(APPLICATION_ID_TO_APPLICATION_POLICY_MAP); } /* An instance of a PolicyManager is created when the class is loaded. @@ -64,68 +68,54 @@ public class PolicyManager { * PolicyManager is created only once. Hence it is singleton. */ - private static class InstanceHolder { - private static final PolicyManager INSTANCE = new PolicyManager(); - } - public static PolicyManager getInstance() { return InstanceHolder.INSTANCE; } - private PolicyManager() { - // Initialize distributed object provider - DistributedObjectProvider distributedObjectProvider = ServiceReferenceHolder.getInstance().getDistributedObjectProvider(); - autoscalePolicyListMap = distributedObjectProvider.getMap(AS_POLICY_ID_TO_AUTOSCALE_POLICY_MAP); - deploymentPolicyListMap = distributedObjectProvider.getMap(DEPLOYMENT_POLICY_ID_TO_DEPLOYMENT_POLICY_MAP); - applicationPolicyListMap = distributedObjectProvider.getMap(APPLICATION_ID_TO_APPLICATION_POLICY_MAP); + public Collection<DeploymentPolicy> getDeploymentPolicies() { + return deploymentPolicyListMap.values(); } // Add the policy to information model and persist. public boolean addAutoscalePolicy(AutoscalePolicy policy) throws AutoScalingPolicyAlreadyExistException { if (log.isInfoEnabled()) { - log.info(String.format("Adding autoscaling policy: [tenant-id] %d [autoscaling policy-uuid] %s " + - "[autoscaling policy-id] " + - "%s", policy.getTenantId(), policy.getUuid(), policy.getId())); + log.info(String.format("Adding autoscaling policy: [id] %s", policy.getId())); } - if (StringUtils.isEmpty(policy.getUuid())) { + if (StringUtils.isEmpty(policy.getId())) { throw new AutoScalerException("Autoscaling policy id cannot be empty"); } this.addASPolicyToInformationModel(policy); RegistryManager.getInstance().persistAutoscalerPolicy(policy); if (log.isInfoEnabled()) { - log.info(String.format("Autoscaling policy: [tenant-id] %d [autoscaling-policy-uuid] %s " + - "[autoscaling-policy-id] %s added successfully", policy.getTenantId(), policy.getUuid(), - policy.getId())); + log.info(String.format("Autoscaling policy is added successfully: [id] %s", policy.getId())); } return true; } public boolean updateAutoscalePolicy(AutoscalePolicy policy) throws InvalidPolicyException { - if (StringUtils.isEmpty(policy.getUuid())) { + if (StringUtils.isEmpty(policy.getId())) { throw new AutoScalerException("Autoscaling policy id cannot be empty"); } this.updateASPolicyInInformationModel(policy); RegistryManager.getInstance().persistAutoscalerPolicy(policy); if (log.isInfoEnabled()) { - log.info(String.format("Autoscaling policy updated successfully: [tenant-id] %d [autoscaling policy-uuid]" + - " %s [autoscaling policy-id] %s", policy.getTenantId(), policy.getUuid(), policy.getId())); + log.info(String.format("Autoscaling policy is updated successfully: [id] %s", policy.getId())); } return true; } - public boolean removeAutoscalePolicy(String policyId) { - if (StringUtils.isEmpty(policyId)) { + public boolean removeAutoscalePolicy(String policyID) { + if (StringUtils.isEmpty(policyID)) { throw new AutoScalerException("Autoscaling policy id cannot be empty"); } - this.removeASPolicyInInformationModel(policyId); - RegistryManager.getInstance().removeAutoscalerPolicy(policyId); + this.removeASPolicyInInformationModel(policyID); + RegistryManager.getInstance().removeAutoscalerPolicy(policyID); if (log.isInfoEnabled()) { - log.info(String.format("Autoscaling policy removed successfully: [autoscaling-policy-id] %s", policyId)); + log.info(String.format("Autoscaling policy is removed successfully: [id] %s", policyID)); } return true; } - /** * Add deployment policy to in memory map and persist. * @@ -137,45 +127,40 @@ public class PolicyManager { RegistryManager.getInstance().persistDeploymentPolicy(policy); if (log.isInfoEnabled()) { - log.info(String.format("Deployment policy added successfully: [tenant-id] %d [deployment-policy-uuid] %s " + - "[deployment-policy-id] %s", policy.getTenantId(), policy.getUuid(), policy.getId())); + log.info(String.format("Deployment policy is added successfully: [deployment-policy-id] %s", + policy.getDeploymentPolicyID())); } } /** - * Retrieve deployment policies from registry and add it to in memory model + * Retrieve deployment policies from registy and add it to in memory model * * @param deploymentPolicy * @throws InvalidDeploymentPolicyException */ public void addDeploymentPolicyToInformationModel(DeploymentPolicy deploymentPolicy) throws InvalidDeploymentPolicyException { - if (!deploymentPolicyListMap.containsKey(deploymentPolicy.getUuid())) { + if (!deploymentPolicyListMap.containsKey(deploymentPolicy.getDeploymentPolicyID())) { if (log.isDebugEnabled()) { - log.debug(String.format("Adding deployment policy [tenant-id] %d [deployment-policy-uuid] %s " + - "deployment-policy-id] %s: ", deploymentPolicy.getTenantId(), - deploymentPolicy.getUuid(), deploymentPolicy.getId())); + log.debug("Adding deployment policy: " + deploymentPolicy.getDeploymentPolicyID()); } - deploymentPolicyListMap.put(deploymentPolicy.getUuid(), deploymentPolicy); + deploymentPolicyListMap.put(deploymentPolicy.getDeploymentPolicyID(), deploymentPolicy); } else { - String errMsg = String.format("Deployment policy already exists: [tenant-id] %d [deployment-policy-uuid] " + - "%s [deployment-policy-id] %s", deploymentPolicy.getTenantId(), - deploymentPolicy.getUuid(), deploymentPolicy.getId()); + String errMsg = "Specified deployment policy [" + + deploymentPolicy.getDeploymentPolicyID() + "] already exists"; log.error(errMsg); throw new InvalidDeploymentPolicyException(errMsg); } } public boolean updateDeploymentPolicy(DeploymentPolicy policy) throws InvalidPolicyException { - if (StringUtils.isEmpty(policy.getUuid())) { + if (StringUtils.isEmpty(policy.getDeploymentPolicyID())) { throw new AutoScalerException("Deployment policy id cannot be empty"); } this.updateDeploymentPolicyInInformationModel(policy); RegistryManager.getInstance().persistDeploymentPolicy(policy); if (log.isInfoEnabled()) { - log.info(String.format("Deployment policy updated successfully: [tenant-id] %d [deployment-policy-uuid] " + - "%s [deployment-policy-id] %s", policy.getTenantId(), - policy.getUuid(), policy.getId())); + log.info(String.format("Deployment policy is updated successfully: [id] %s", policy.getDeploymentPolicyID())); } return true; } @@ -183,66 +168,58 @@ public class PolicyManager { /** * Remove deployment policy from in memory map and registry. * - * @param deploymentPolicyId Deployment policy Id + * @param deploymentPolicyID * @throws InvalidPolicyException */ - public void removeDeploymentPolicy(String deploymentPolicyId) { - removeDeploymentPolicyFromMap(deploymentPolicyId); - RegistryManager.getInstance().removeDeploymentPolicy(deploymentPolicyId); + public void removeDeploymentPolicy(String deploymentPolicyID) { + removeDeploymentPolicyFromMap(deploymentPolicyID); + RegistryManager.getInstance().removeDeploymentPolicy(deploymentPolicyID); if (log.isInfoEnabled()) { - log.info(String.format("Deployment policy removed successfully: [deployment-policy-id] %s", - deploymentPolicyId)); + log.info(String.format("Deployment policy is removed successfully: [deployment-policy-id] %s", + deploymentPolicyID)); } } public void addASPolicyToInformationModel(AutoscalePolicy asPolicy) throws AutoScalingPolicyAlreadyExistException { - if (!autoscalePolicyListMap.containsKey(asPolicy.getUuid())) { + if (!autoscalePolicyListMap.containsKey(asPolicy.getId())) { if (log.isDebugEnabled()) { - log.debug(String.format("Adding autoscaling policy: [tenant-id] %d [autoscaling-policy-uuid] " + - "%s " + - "[autoscaling-policy-id] %s", asPolicy.getTenantId(), asPolicy.getUuid(), asPolicy.getId())); + log.debug("Adding autoscaling policy: " + asPolicy.getId()); } - autoscalePolicyListMap.put(asPolicy.getUuid(), asPolicy); + autoscalePolicyListMap.put(asPolicy.getId(), asPolicy); } else { - String errMsg = String.format("Specified autoscaling policy already exists: [tenant-id] %d " + - "[autoscaling-policy-uuid] %s [autoscaling-policy-id] %s", asPolicy.getTenantId(), - asPolicy.getUuid(), asPolicy.getId()); + String errMsg = "Specified autoscaling policy [" + asPolicy.getId() + "] already exists"; log.error(errMsg); throw new AutoScalingPolicyAlreadyExistException(errMsg); } } public void updateASPolicyInInformationModel(AutoscalePolicy asPolicy) throws InvalidPolicyException { - if (autoscalePolicyListMap.containsKey(asPolicy.getUuid())) { + if (autoscalePolicyListMap.containsKey(asPolicy.getId())) { if (log.isDebugEnabled()) { - log.debug(String.format("Updating autoscaling policy: [tenant-id] %d [autoscaling-policy-uuid] %s " + - "[autoscaling-policy-id] %s", asPolicy.getTenantId(), asPolicy.getUuid(), - asPolicy.getId())); + log.debug("Updating autoscaling policy: " + asPolicy.getId()); } - autoscalePolicyListMap.put(asPolicy.getUuid(), asPolicy); + autoscalePolicyListMap.put(asPolicy.getId(), asPolicy); } } public void updateDeploymentPolicyInInformationModel(DeploymentPolicy deploymentPolicy) throws InvalidPolicyException { - if (deploymentPolicyListMap.containsKey(deploymentPolicy.getUuid())) { + if (deploymentPolicyListMap.containsKey(deploymentPolicy.getDeploymentPolicyID())) { if (log.isDebugEnabled()) { - log.debug(String.format("Updating deployment policy: [tenant-id] %d [deployment-policy-uuid] " + - "%s [deployment-policy-id] %s", deploymentPolicy.getTenantId(), - deploymentPolicy.getUuid(), deploymentPolicy.getId())); + log.debug("Updating deployment policy: " + deploymentPolicy.getDeploymentPolicyID()); } - deploymentPolicyListMap.put(deploymentPolicy.getUuid(), deploymentPolicy); + deploymentPolicyListMap.put(deploymentPolicy.getDeploymentPolicyID(), deploymentPolicy); } } - public void removeASPolicyInInformationModel(String policyId) throws PolicyDoesNotExistException { - if (autoscalePolicyListMap.containsKey(policyId)) { + public void removeASPolicyInInformationModel(String policyID) throws PolicyDoesNotExistException { + if (autoscalePolicyListMap.containsKey(policyID)) { if (log.isDebugEnabled()) { - log.debug("Removing autoscaling policy: [autoscaling-policy-id] " + policyId); + log.debug("Updating autoscaling policy: " + policyID); } - autoscalePolicyListMap.remove(policyId); + autoscalePolicyListMap.remove(policyID); } else { - throw new PolicyDoesNotExistException("No such policy exists: [autoscaling-policy-id] " + policyId); + throw new PolicyDoesNotExistException("No such policy ID [" + policyID + "] exists"); } } @@ -253,8 +230,7 @@ public class PolicyManager { } applicationPolicyListMap.remove(applicationPolicyId); } else { - throw new InvalidPolicyException(String.format("Application policy not found: [application-policy-id] " + - "%s", applicationPolicyId)); + throw new InvalidPolicyException(String.format("Application policy not found: [application-policy-id] %s", applicationPolicyId)); } } @@ -288,43 +264,24 @@ public class PolicyManager { /** * Returns the autoscale policy to which the specified id is mapped or null * - * @param uuid Autoscale policy UUID + * @param id * @return */ - public AutoscalePolicy getAutoscalePolicy(String uuid) { - return autoscalePolicyListMap.get(uuid); + public AutoscalePolicy getAutoscalePolicy(String id) { + return autoscalePolicyListMap.get(id); } - /** - * Returns the autoscale policy to which the specified id is mapped or null - * - * @param id Autoscle policy Id - * @return - */ - public AutoscalePolicy getAutoscalePolicyById(String id) { - AutoscalePolicy autoscalePolicy = null; - for (AutoscalePolicy autoscalePolicy1 : getAutoscalePolicyList()) { - if (autoscalePolicy1.getId().equals(id)) { - autoscalePolicy = autoscalePolicy1; - } - } - return autoscalePolicy; - } - - private void addDeploymentPolicyToPolicyListMap(DeploymentPolicy policy) { - if (StringUtils.isEmpty(policy.getUuid())) { + if (StringUtils.isEmpty(policy.getDeploymentPolicyID())) { throw new RuntimeException("Application id is not found in the deployment policy"); } - if (!deploymentPolicyListMap.containsKey(policy.getUuid())) { + if (!deploymentPolicyListMap.containsKey(policy.getDeploymentPolicyID())) { if (log.isDebugEnabled()) { - log.debug(String.format("Adding deployment policy: [tenant-id] %d [deployment-policy-uuid] %s " + - "[deployment-policy-id] %s ", policy.getTenantId(), policy.getUuid(), policy.getId())); + log.debug("Adding deployment policy: [deployment-policy-id] " + policy.getDeploymentPolicyID()); } - deploymentPolicyListMap.put(policy.getUuid(), policy); + deploymentPolicyListMap.put(policy.getDeploymentPolicyID(), policy); } else { - String errMsg = String.format("Deployment policy already exists: [tenant-id] %d [deployment-policy-uuid] " + - "%s [deployment-policy-id] %s ", policy.getTenantId(), policy.getUuid(), policy.getId()); + String errMsg = "Deployment policy already exists: [deployment-policy-id] " + policy.getDeploymentPolicyID(); log.error(errMsg); } } @@ -337,9 +294,9 @@ public class PolicyManager { public void updateDeploymentPolicyToInformationModel(DeploymentPolicy policy) throws InvalidPolicyException { if (log.isDebugEnabled()) { - log.debug("Updating deployment policy: " + policy.getUuid()); + log.debug("Updating deployment policy: " + policy.getDeploymentPolicyID()); } - deploymentPolicyListMap.put(policy.getUuid(), policy); + deploymentPolicyListMap.put(policy.getDeploymentPolicyID(), policy); } /** @@ -377,43 +334,25 @@ public class PolicyManager { /** * Returns the deployment policy to which the specified id is mapped or null * - * @param uuid UUID of the deployment policy + * @param id * @return */ - public DeploymentPolicy getDeploymentPolicy(String uuid) { - return deploymentPolicyListMap.get(uuid); - } - - /** - * Returns the deployment policy to which the specified id is mapped or null - * - * @param id Id of the deployment policy - * @return - */ - public DeploymentPolicy getDeploymentPolicyById(String id) { - DeploymentPolicy deploymentPolicy = null; - for (DeploymentPolicy deploymentPolicy1 : getDeploymentPolicies()) { - if (deploymentPolicy1.getId().equals(id)) { - deploymentPolicy = deploymentPolicy1; - } - } - return deploymentPolicy; + public DeploymentPolicy getDeploymentPolicy(String id) { + return deploymentPolicyListMap.get(id); } public void addApplicationPolicy(ApplicationPolicy applicationPolicy) throws InvalidApplicationPolicyException { - String applicationPolicyUuid = applicationPolicy.getUuid(); + String applicationPolicyId = applicationPolicy.getId(); if (log.isInfoEnabled()) { - log.info(String.format("Adding application policy : [tenant-id] %d [application-policy-uuid] %s " + - "[application-policy-id] %s", applicationPolicy.getTenantId(), applicationPolicyUuid, - applicationPolicy.getId())); + log.info(String.format("Adding application policy : [application-policy-id] %s", applicationPolicyId)); } this.addApplicationPolicyToInformationModel(applicationPolicy); RegistryManager.getInstance().persistApplicationPolicy(applicationPolicy); if (log.isInfoEnabled()) { - log.info(String.format("Application policy added successfully: [tenant-id] %d [application-policy-uuid] %s " + - "[application-policy-id] %s", applicationPolicy.getTenantId(), applicationPolicyUuid, - applicationPolicy.getId())); + log.info(String + .format("Application policy is added successfully: [application-policy-id] %s", + applicationPolicyId)); } } @@ -425,26 +364,21 @@ public class PolicyManager { this.removeApplicationPolicyInInformationModel(applicationPolicyId); RegistryManager.getInstance().removeApplicationPolicy(applicationPolicyId); if (log.isInfoEnabled()) { - log.info(String.format("Application policy removed successfully: [application-policy-id] %s", - applicationPolicyId)); + log.info(String.format("Application policy is removed successfully: [id] %s", applicationPolicyId)); } return true; } public void addApplicationPolicyToInformationModel(ApplicationPolicy applicationPolicy) throws InvalidApplicationPolicyException { - String applicationPolicyUuid = applicationPolicy.getUuid(); - if (!applicationPolicyListMap.containsKey(applicationPolicyUuid)) { + String applicationPolicyId = applicationPolicy.getId(); + if (!applicationPolicyListMap.containsKey(applicationPolicyId)) { if (log.isDebugEnabled()) { - log.debug(String.format("Adding application policy: [tenant-id] %d [application-policy-uuid] %s " + - "[application-policy-id] %s", applicationPolicy.getTenantId(), applicationPolicyUuid, - applicationPolicy.getId())); + log.debug("Adding application policy : " + applicationPolicyId); } - applicationPolicyListMap.put(applicationPolicyUuid, applicationPolicy); + applicationPolicyListMap.put(applicationPolicyId, applicationPolicy); } else { - String errMsg = String.format("Application policy already exists : [tenant-id] %d " + - "[application-policy-uuid] %s [application-policy-id] %s", - applicationPolicy.getTenantId(), applicationPolicyUuid, applicationPolicy.getId()); + String errMsg = "Application policy already exists : " + applicationPolicyId; log.error(errMsg); throw new InvalidApplicationPolicyException(errMsg); } @@ -454,75 +388,39 @@ public class PolicyManager { /** * Retruns an ApplicationPolicy of a given application * - * @param applicationPolicyId Application policy Id + * @param applicationPolicyId * @return */ public ApplicationPolicy getApplicationPolicy(String applicationPolicyId) { return applicationPolicyListMap.get(applicationPolicyId); } - /** - * Returns the application policy to which the specified id is mapped or null - * - * @param uuid Id of the deployment policy - * @return - */ - public ApplicationPolicy getApplicationPolicyByUuid(String uuid) { - ApplicationPolicy applicationPolicy = null; - for (ApplicationPolicy applicationPolicy1 : getApplicationPolicies()) { - if (applicationPolicy1.getUuid().equals(uuid)) { - applicationPolicy = applicationPolicy1; - } - } - return applicationPolicy; - } - public void updateApplicationPolicyInInformationModel(ApplicationPolicy applicationPolicy) { - if (applicationPolicyListMap.containsKey(applicationPolicy.getUuid())) { + if (applicationPolicyListMap.containsKey(applicationPolicy.getId())) { if (log.isDebugEnabled()) { - log.debug(String.format("Updating application policy: [tenant-id] %d [application-policy-uuid] %s " + - "[application-policy-id] %s", applicationPolicy.getTenantId(), applicationPolicy.getUuid(), - applicationPolicy.getId())); + log.debug("Updating application policy: " + applicationPolicy.getId()); } - applicationPolicyListMap.put(applicationPolicy.getUuid(), applicationPolicy); + applicationPolicyListMap.put(applicationPolicy.getId(), applicationPolicy); } } public boolean updateApplicationPolicy(ApplicationPolicy applicationPolicy) { - if (StringUtils.isEmpty(applicationPolicy.getUuid())) { + if (StringUtils.isEmpty(applicationPolicy.getId())) { throw new AutoScalerException("Application policy id cannot be empty"); } this.updateApplicationPolicyInInformationModel(applicationPolicy); RegistryManager.getInstance().persistApplicationPolicy(applicationPolicy); if (log.isInfoEnabled()) { - log.info(String.format("Application policyupdated successfully: [id] %s", applicationPolicy.getUuid())); + log.info(String.format("Application policy is updated successfully: [id] %s", applicationPolicy.getId())); } return true; } - /** - * Returns the application policy to which the specified id is mapped or null - * - * @return List of all application policies - */ public ApplicationPolicy[] getApplicationPolicies() { return applicationPolicyListMap.values().toArray(new ApplicationPolicy[0]); } - /** - * Checks whether application policy exists in the tenant - * @param applicationPolicyId application policy id - * @param tenantId tenant id - * @return boolean value - */ - public Boolean checkApplicationPolicyInTenant(String applicationPolicyId, int tenantId) { - ApplicationPolicy[] applicationPolicies = getApplicationPolicies(); - for (ApplicationPolicy applicationPolicy1 : applicationPolicies) { - if (applicationPolicy1.getId().equals(applicationPolicyId) && applicationPolicy1.getTenantId() == - tenantId) { - return true; - } - } - return false; + private static class InstanceHolder { + private static final PolicyManager INSTANCE = new PolicyManager(); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/AutoscalePolicy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/AutoscalePolicy.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/AutoscalePolicy.java index 852d873..8eee898 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/AutoscalePolicy.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/autoscale/AutoscalePolicy.java @@ -28,7 +28,6 @@ public class AutoscalePolicy implements Serializable { private static final long serialVersionUID = 1754373171598089271L; private LoadThresholds loadThresholds; - private String uuid; private String id; private String displayName; private String description; @@ -36,15 +35,6 @@ public class AutoscalePolicy implements Serializable { private int tenantId; private float instanceRoundingFactor; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - /** * Gets the value of the loadThresholds property. * @@ -66,23 +56,23 @@ public class AutoscalePolicy implements Serializable { } /** - * Gets the value of the uuid property. + * Gets the value of the id property. * * @return possible object is * {@link String } */ - public String getUuid() { - return uuid; + public String getId() { + return id; } /** - * Sets the value of the uuid property. + * Sets the value of the id property. * * @param value allowed object is * {@link String } */ - public void setUuid(String value) { - this.uuid = value; + public void setId(String value) { + this.id = value; } /** @@ -159,7 +149,7 @@ public class AutoscalePolicy implements Serializable { @Override public String toString() { - return "ASPolicy [uuid=" + uuid + ", displayName=" + displayName + return "ASPolicy [id=" + id + ", displayName=" + displayName + ", description=" + description + ", isPublic=" + isPublic + "]"; } http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/ApplicationPolicy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/ApplicationPolicy.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/ApplicationPolicy.java index f961e1c..856f90f 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/ApplicationPolicy.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/ApplicationPolicy.java @@ -25,12 +25,9 @@ import java.io.Serializable; public class ApplicationPolicy implements Serializable { private static final long serialVersionUID = -2851334419121310395L; - private String uuid; private String id; - private int tenantId; private String algorithm; private String[] networkPartitions; - private String[] networkPartitionsUuid; private Properties properties; // if networkPartitionGroups property is set, we are populating following variable. private String[] networkPartitionGroups; @@ -43,22 +40,6 @@ public class ApplicationPolicy implements Serializable { this.id = id; } - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - public String getAlgorithm() { return algorithm; } @@ -90,12 +71,4 @@ public class ApplicationPolicy implements Serializable { public void setNetworkPartitionGroups(String[] networkPartitionGroups) { this.networkPartitionGroups = networkPartitionGroups; } - - public String[] getNetworkPartitionsUuid() { - return networkPartitionsUuid; - } - - public void setNetworkPartitionsUuid(String[] networkPartitionsUuid) { - this.networkPartitionsUuid = networkPartitionsUuid; - } } http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java index 7d3bae8..56d1f15 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/deployment/DeploymentPolicy.java @@ -32,34 +32,15 @@ import java.util.Arrays; public class DeploymentPolicy implements Serializable { private static final long serialVersionUID = 5675507196284400099L; - private String uuid; - private int tenantId; - private String id; + private String deploymentPolicyID; private NetworkPartitionRef[] networkPartitionRefs; - public String getUuid() { - return uuid; + public String getDeploymentPolicyID() { + return deploymentPolicyID; } - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; + public void setDeploymentPolicyID(String deploymentPolicyID) { + this.deploymentPolicyID = deploymentPolicyID; } public NetworkPartitionRef[] getNetworkPartitionRefs() { @@ -79,7 +60,7 @@ public class DeploymentPolicy implements Serializable { public NetworkPartitionRef getNetworkPartitionByNetworkPartitionId(String networkPartitionId) { if (networkPartitionRefs != null) { for (NetworkPartitionRef networkPartition : networkPartitionRefs) { - if (networkPartition.getUuid().equals(networkPartitionId)) { + if (networkPartition.getId().equals(networkPartitionId)) { return networkPartition; } } @@ -96,7 +77,7 @@ public class DeploymentPolicy implements Serializable { public PartitionRef[] getPartitionsByNetworkPartitionId(String networkPartitionId) { if (networkPartitionRefs != null) { for (NetworkPartitionRef networkPartitionRef : networkPartitionRefs) { - if (networkPartitionRef.getUuid().equals(networkPartitionId)) { + if (networkPartitionRef.getId().equals(networkPartitionId)) { return networkPartitionRef.getPartitionRefs(); } } @@ -105,7 +86,7 @@ public class DeploymentPolicy implements Serializable { } public String toString() { - return String.format("{ deployment-policy-id : %s, network-partitions : %s", uuid, + return String.format("{ deployment-policy-id : %s, network-partitions : %s", deploymentPolicyID, Arrays.toString(networkPartitionRefs)); } http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java index b7e659e..e16d3f5 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java @@ -162,7 +162,7 @@ public class RegistryManager { } public void persistDeploymentPolicy(DeploymentPolicy deploymentPolicy) { - String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.DEPLOYMENT_POLICY_RESOURCE + "/" + deploymentPolicy.getUuid(); + String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.DEPLOYMENT_POLICY_RESOURCE + "/" + deploymentPolicy.getDeploymentPolicyID(); persist(deploymentPolicy, resourcePath); if (log.isDebugEnabled()) { log.debug(String.format("Deployment policy written to registry: %s", deploymentPolicy.toString())); @@ -173,14 +173,14 @@ public class RegistryManager { try { startTenantFlow(); String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + - AutoscalerConstants.AS_POLICY_RESOURCE + "/" + autoscalePolicy.getUuid(); + AutoscalerConstants.AS_POLICY_RESOURCE + "/" + autoscalePolicy.getId(); persist(autoscalePolicy, resourcePath); if (log.isDebugEnabled()) { log.debug(String.format("Autoscaler policy written to registry: [id] %s [name] %s [description] %s", - autoscalePolicy.getUuid(), autoscalePolicy.getDisplayName(), autoscalePolicy.getDescription())); + autoscalePolicy.getId(), autoscalePolicy.getDisplayName(), autoscalePolicy.getDescription())); } } catch (AutoScalerException e) { - String message = "Unable to persist autoscaler policy [autoscaler-policy-id] " + autoscalePolicy.getUuid(); + String message = "Unable to persist autoscaler policy [autoscaler-policy-id] " + autoscalePolicy.getId(); log.error(message, e); throw e; } finally { @@ -264,10 +264,10 @@ public class RegistryManager { try { startTenantFlow(); String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + - AutoscalerConstants.APPLICATION_CONTEXTS_RESOURCE + "/" + applicationContext.getApplicationUuid(); + AutoscalerConstants.APPLICATION_CONTEXTS_RESOURCE + "/" + applicationContext.getApplicationId(); persist(applicationContext, resourcePath); if (log.isDebugEnabled()) { - log.debug("Application context [" + applicationContext.getApplicationUuid() + "] " + + log.debug("Application context [" + applicationContext.getApplicationId() + "] " + "persisted successfully in the autoscaler registry"); } } finally { @@ -336,13 +336,13 @@ public class RegistryManager { public void persistServiceGroup(ServiceGroup servicegroup) { try { startTenantFlow(); - if (servicegroup == null || StringUtils.isEmpty(servicegroup.getUuid())) { + if (servicegroup == null || StringUtils.isEmpty(servicegroup.getName())) { throw new IllegalArgumentException("Cartridge group or group name can not be null"); } - String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.SERVICE_GROUP + "/" + servicegroup.getUuid(); + String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.SERVICE_GROUP + "/" + servicegroup.getName(); persist(servicegroup, resourcePath); if (log.isDebugEnabled()) { - log.debug(String.format("Persisted cartridge group %s at path %s", servicegroup.getUuid(), resourcePath)); + log.debug(String.format("Persisted cartridge group %s at path %s", servicegroup.getName(), resourcePath)); } } finally { endTenantFlow(); @@ -352,29 +352,29 @@ public class RegistryManager { public void updateServiceGroup(ServiceGroup serviceGroup) throws InvalidServiceGroupException, RegistryException { try { - if (serviceGroup == null || StringUtils.isEmpty(serviceGroup.getUuid())) { + if (serviceGroup == null || StringUtils.isEmpty(serviceGroup.getName())) { throw new IllegalArgumentException("Cartridge group or group name cannot be null"); } - if (getServiceGroup(serviceGroup.getUuid()) == null) { + if (getServiceGroup(serviceGroup.getName()) == null) { throw new InvalidServiceGroupException(String.format("Cartridge group does not exist: " + - "[cartridge-group] %s", serviceGroup.getUuid())); + "[cartridge-group] %s", serviceGroup.getName())); } persistServiceGroup(serviceGroup); if (log.isDebugEnabled()) { - log.debug(String.format("Updated cartridge group: [group-name] %s", serviceGroup.getUuid())); + log.debug(String.format("Updated cartridge group: [group-name] %s", serviceGroup.getName())); } } catch (Exception e) { String message = (String.format("Unable to update cartridge group [group-name] %s", - serviceGroup.getUuid())); + serviceGroup.getName())); log.error(message, e); throw new RegistryException(message, e); } } - public boolean serviceGroupExist(String serviceGroupUuid) { - String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.SERVICE_GROUP + "/" + serviceGroupUuid; + public boolean serviceGroupExist(String serviceGroupName) { + String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.SERVICE_GROUP + "/" + serviceGroupName; return resourceExist(resourcePath); } @@ -400,7 +400,7 @@ public class RegistryManager { asPolicy = (AutoscalePolicy) dataObj; if (log.isDebugEnabled()) { log.debug(String.format("Autoscaler policy read from registry: [id] %s [name] %s [description] %s", - asPolicy.getUuid(), asPolicy.getDisplayName(), asPolicy.getDescription())); + asPolicy.getId(), asPolicy.getDisplayName(), asPolicy.getDescription())); } asPolicyList.add(asPolicy); } else { @@ -537,10 +537,10 @@ public class RegistryManager { } } - public ServiceGroup getServiceGroup(String uuid) throws Exception { + public ServiceGroup getServiceGroup(String name) throws Exception { try { startTenantFlow(); - String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.SERVICE_GROUP + "/" + uuid; + String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.SERVICE_GROUP + "/" + name; Object serializedObj = instance.retrieve(resourcePath); ServiceGroup group = null; if (serializedObj != null) { @@ -561,18 +561,6 @@ public class RegistryManager { } } - public ServiceGroup getServiceGroup(String name, int tenantId) throws Exception { - ServiceGroup[] serviceGroups = getServiceGroups(); - if (serviceGroups != null) { - for (ServiceGroup serviceGroup : serviceGroups) { - if (serviceGroup.getName().equals(name) && (serviceGroup.getTenantId() == tenantId)) { - return serviceGroup; - } - } - } - return null; - } - public ServiceGroup[] getServiceGroups() { try { startTenantFlow(); @@ -645,20 +633,20 @@ public class RegistryManager { policyID; delete(resourcePath); if (log.isDebugEnabled()) { - log.debug(String.format("Autoscaler policy deleted from registry: %s [id]", policyID)); + log.debug(String.format("Autoscaler policy deleted from registry: [id]", policyID)); } } finally { endTenantFlow(); } } - public void removeDeploymentPolicy(String deploymentPolicyId) { + public void removeDeploymentPolicy(String deploymentPolicyID) { String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + AutoscalerConstants.DEPLOYMENT_POLICY_RESOURCE + "/" + - deploymentPolicyId; + deploymentPolicyID; this.delete(resourcePath); if (log.isDebugEnabled()) { log.debug(String.format("Deployment policy deleted from registry: [id] %s", - deploymentPolicyId)); + deploymentPolicyID)); } } @@ -694,10 +682,10 @@ public class RegistryManager { try { startTenantFlow(); String resourcePath = AutoscalerConstants.AUTOSCALER_RESOURCE + - AutoscalerConstants.APPLICATION_POLICY_RESOURCE + "/" + applicationPolicy.getUuid(); + AutoscalerConstants.APPLICATION_POLICY_RESOURCE + "/" + applicationPolicy.getId(); persist(applicationPolicy, resourcePath); if (log.isDebugEnabled()) { - log.debug(String.format("Application policy written to registry : %s", applicationPolicy.getUuid())); + log.debug(String.format("Application policy written to registry : %s", applicationPolicy.getId())); } } finally { endTenantFlow(); http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java index d221286..1a8bfc9 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/RuleTasksDelegator.java @@ -36,8 +36,6 @@ import org.apache.stratos.autoscaler.context.partition.network.NetworkPartitionC import org.apache.stratos.autoscaler.event.publisher.InstanceNotificationPublisher; import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor; import org.apache.stratos.cloud.controller.stub.domain.MemberContext; -import org.apache.stratos.cloud.controller.stub.domain.NetworkPartition; -import org.apache.stratos.common.client.CloudControllerServiceClient; import org.apache.stratos.common.constants.StratosConstants; /** @@ -45,12 +43,10 @@ import org.apache.stratos.common.constants.StratosConstants; */ public class RuleTasksDelegator { - private static boolean arspiIsSet = false; - private static final Log log = LogFactory.getLog(RuleTasksDelegator.class); + private static boolean arspiIsSet = false; - public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative, - int timeInterval) { + public double getPredictedValueForNextMinute(float average, float gradient, float secondDerivative, int timeInterval) { double predictedValue; // s = u * t + 0.5 * a * t * t if (log.isDebugEnabled()) { @@ -65,8 +61,7 @@ public class RuleTasksDelegator { public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue, float rifThreshold) { - if (rifThreshold != 0) { - + if (rifThreshold > 0) { float requiredNumberOfInstances = rifPredictedValue / rifThreshold; return (int) Math.ceil(requiredNumberOfInstances); } else { @@ -176,22 +171,12 @@ public class RuleTasksDelegator { * @param clusterMonitorPartitionContext Cluster monitor partition context * @param clusterId Cluster id * @param clusterInstanceId Instance id - * @param isPrimary Is a primary member - * @param autoscalingReason scaling reason for member - * @param scalingTime scaling time */ public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext, String clusterId, - String clusterInstanceId, boolean isPrimary, String autoscalingReason, long scalingTime) { + String clusterInstanceId) { try { String nwPartitionId = clusterMonitorPartitionContext.getNetworkPartitionId(); - String nwPartitionUuid = null; - NetworkPartition[] networkPartitionList = CloudControllerServiceClient.getInstance().getNetworkPartitions(); - for (int i = 0; i < networkPartitionList.length; i++) { - if (networkPartitionList[i].getUuid().equals(nwPartitionId)) { - nwPartitionUuid = networkPartitionList[i].getUuid(); - } - } // Calculate accumulation of minimum counts of all the partition of current network partition int minimumCountOfNetworkPartition; @@ -209,16 +194,14 @@ public class RuleTasksDelegator { .startInstance(clusterMonitorPartitionContext.getPartition(), clusterId, clusterInstanceId, clusterMonitorPartitionContext.getNetworkPartitionId(), - isPrimary, - minimumCountOfNetworkPartition, autoscalingReason, scalingTime); + minimumCountOfNetworkPartition); if (memberContext != null) { ClusterLevelPartitionContext partitionContext = clusterInstanceContext. getPartitionCtxt(clusterMonitorPartitionContext.getPartitionId()); partitionContext.addPendingMember(memberContext); partitionContext.addMemberStatsContext(new MemberStatsContext(memberContext.getMemberId())); if (log.isDebugEnabled()) { - log.debug(String.format("Pending member added, [member] %s [partition] %s", - memberContext.getMemberId(), + log.debug(String.format("Pending member added, [member] %s [partition] %s", memberContext.getMemberId(), memberContext.getPartition().getId())); } @@ -257,8 +240,7 @@ public class RuleTasksDelegator { clusterMonitor.sendScalingOverMaxEvent(networkPartitionId, instanceId); } - public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId, - String instanceId) { + public void delegateScalingDownBeyondMinNotification(String clusterId, String networkPartitionId, String instanceId) { if (log.isDebugEnabled()) { log.debug("Scaling down lower min notification is going to the [parentInstance] " + instanceId); } @@ -281,8 +263,8 @@ public class RuleTasksDelegator { clusterMonitorPartitionContext.removeMemberStatsContext(memberId); } else if (clusterMonitorPartitionContext.pendingMemberAvailable(memberId)) { - log.info(String.format("[scale-down] Moving pending member to termination pending list " + - "[member id] %s " + "[partition] %s [network partition] %s", memberId, + log.info(String.format("[scale-down] Moving pending member to termination pending list [member id] %s " + + "[partition] %s [network partition] %s", memberId, clusterMonitorPartitionContext.getPartitionId(), clusterMonitorPartitionContext.getNetworkPartitionId())); clusterMonitorPartitionContext.movePendingMemberToObsoleteMembers(memberId); @@ -293,8 +275,7 @@ public class RuleTasksDelegator { } } - public void delegateTerminateDependency(ClusterLevelPartitionContext clusterMonitorPartitionContext, - String memberId) { + public void delegateTerminateDependency(ClusterLevelPartitionContext clusterMonitorPartitionContext, String memberId) { try { //calling SM to send the instance notification event. if (log.isDebugEnabled()) { @@ -379,8 +360,7 @@ public class RuleTasksDelegator { float memberMemoryConsumptionAverage = memberStatsContext.getMemoryConsumption().getAverage(); float memberMemoryConsumptionGredient = memberStatsContext.getMemoryConsumption().getGradient(); - float memberMemoryConsumptionSecondDerivative = - memberStatsContext.getMemoryConsumption().getSecondDerivative(); + float memberMemoryConsumptionSecondDerivative = memberStatsContext.getMemoryConsumption().getSecondDerivative(); double memberPredictedMemoryConsumption = getPredictedValueForNextMinute(memberMemoryConsumptionAverage, memberMemoryConsumptionGredient, memberMemoryConsumptionSecondDerivative, 1); @@ -402,4 +382,4 @@ public class RuleTasksDelegator { return 0; } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/stratos/blob/4b864473/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java index d8fa9e5..d984d64 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/AutoscalerService.java @@ -27,7 +27,6 @@ import org.apache.stratos.autoscaler.exception.application.ApplicationDefinition import org.apache.stratos.autoscaler.exception.application.InvalidApplicationPolicyException; import org.apache.stratos.autoscaler.exception.application.InvalidServiceGroupException; import org.apache.stratos.autoscaler.exception.CartridgeNotFoundException; -import org.apache.stratos.autoscaler.exception.partition.PartitionValidationException; import org.apache.stratos.autoscaler.exception.policy.*; import org.apache.stratos.autoscaler.pojo.ServiceGroup; import org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy; @@ -51,18 +50,10 @@ public interface AutoscalerService { /** * Get an autoscaling policy * - * @param autoscalingPolicyUuid + * @param autoscalingPolicyId * @return */ - public AutoscalePolicy getAutoscalingPolicy(String autoscalingPolicyUuid); - - /** - * Get an autoscaling policy - * - * @param autoscalingPolicyId - * @return - */ - public AutoscalePolicy getAutoscalingPolicyForTenant(String autoscalingPolicyId,int tenantId); + public AutoscalePolicy getAutoscalingPolicy(String autoscalingPolicyId); /** * Get autoscaling policies @@ -117,20 +108,12 @@ public interface AutoscalerService { public ApplicationContext getApplication(String applicationId); /** - * Get an application - * - * @param applicationId - * @param tenantId - */ - public ApplicationContext getApplicationByTenant(String applicationId, int tenantId); - - /** * Check if the application exists * * @param applicationId * @return whether application exists or not */ - boolean existApplication(String applicationId,int tenantId); + boolean existApplication(String applicationId); /** * Get all applications @@ -178,29 +161,9 @@ public interface AutoscalerService { * Get application policy by application id * * @param applicationPolicyId the application policy id - * @param tenantId tenant id - * @return {@link ApplicationPolicy} used by the given application - */ - public ApplicationPolicy getApplicationPolicy(String applicationPolicyId, int tenantId); - - /** - * Get application policy by application uuid - * - * @param applicationPolicyUuid the application policy uuid * @return {@link ApplicationPolicy} used by the given application */ - public ApplicationPolicy getApplicationPolicyByUuid(String applicationPolicyUuid); - - /** - * - * Get application policy by application id and tenant id - * - * @param applicationPolicyId - * @param tenantId - * @return - */ - - public ApplicationPolicy getApplicationPolicyByTenant(String applicationPolicyId, int tenantId); + public ApplicationPolicy getApplicationPolicy(String applicationPolicyId); /** * Remove application policy @@ -268,14 +231,6 @@ public interface AutoscalerService { */ public ServiceGroup getServiceGroup(String name); - /** - * Get cartridge group by tenant - * @param name - * @param tenantId - * @return - */ - public ServiceGroup getServiceGroupByTenant(String name, int tenantId); - /** * Find cluster id of an application by subscription alias. * @@ -318,19 +273,10 @@ public interface AutoscalerService { /** * Get deployment policy definition * - * @param deploymentPolicyUuid + * @param deploymentPolicyID * @return */ - public DeploymentPolicy getDeploymentPolicy(String deploymentPolicyUuid); - - /** - * Get deployment policy definition - * - * @param deploymentPolicyID - * @param tenantId - * @return - */ - public DeploymentPolicy getDeploymentPolicyForTenant(String deploymentPolicyID,int tenantId); + public DeploymentPolicy getDeploymentPolicy(String deploymentPolicyID); /** * Get deployment policies @@ -339,45 +285,4 @@ public interface AutoscalerService { */ public DeploymentPolicy[] getDeploymentPolicies(); - /** - * Get applications by tenant - * - * @return array of {@link DeploymentPolicy} - */ - public ApplicationContext[] getApplicationsByTenant(int tenantId); - - /** - * Get deployment policy definition by tenant - * - * @param tenantId tenant id - * @return Deployment policy - */ - public DeploymentPolicy[] getDeploymentPoliciesByTenant(int tenantId); - - /** - * Get autoscaling policy definition by tenant - * - * @param tenantId tenant id - * @return Array of autoscaling policies for tenant - */ - public AutoscalePolicy[] getAutoScalingPoliciesByTenant(int tenantId); - - /** - * Returns the application policy to which the specified id is mapped or null - * - * @param tenantId Id of the deployment policy - * @return Array of application policies for a tenant - */ - public ApplicationPolicy[] getApplicationPoliciesByTenant(int tenantId); - - /** - * Validate the network partition with the application - * @param networkPartitionId Network partition id - * @param tenantId tenant id - * @return - */ - public boolean validateNetworkPartitionWithApplication(String networkPartitionId,int tenantId) - throws PartitionValidationException; - - }
