Updated Branches: refs/heads/master e98006b15 -> 533665ae3
Adding Undeploy deployment policy and autoscaler policy Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/08d597d7 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/08d597d7 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/08d597d7 Branch: refs/heads/master Commit: 08d597d72270063ebee7ccb7044c5961598ef00a Parents: 8bac94f Author: Udara Liyanage <[email protected]> Authored: Mon Dec 16 15:59:31 2013 -0500 Committer: Udara Liyanage <[email protected]> Committed: Mon Dec 16 15:59:31 2013 -0500 ---------------------------------------------------------------------- .../autoscaler/partition/PartitionManager.java | 24 +++++++++- .../autoscaler/policy/PolicyManager.java | 9 +++- .../autoscaler/registry/RegistryManager.java | 48 ++++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/08d597d7/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java index 55205a9..5b9c3ab 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java @@ -132,7 +132,29 @@ private static final Log log = LogFactory.getLog(PartitionManager.class); } } - public void addNetworkPartitionContext(NetworkPartitionContext ctxt) { + public void undeployNetworkPartitions(DeploymentPolicy depPolicy) { + for(PartitionGroup partitionGroup: depPolicy.getPartitionGroups()){ + String id = partitionGroup.getId(); + if (networkPartitionContexts.containsKey(id)) { + NetworkPartitionContext netPartCtx = this.getNetworkPartition(id); + // remove from information model + this.removeNetworkPartitionContext(netPartCtx); + //remove from the registry + RegistryManager.getInstance().removeNetworkPartition(this.getNetworkPartition(id).getId()); + }else{ + String errMsg = "Network partition context not found for policy " + depPolicy; + log.error(errMsg); + throw new AutoScalerException(errMsg); + } + + } + } + + private void removeNetworkPartitionContext(NetworkPartitionContext netPartCtx) { + networkPartitionContexts.remove(netPartCtx.getId()); + } + + public void addNetworkPartitionContext(NetworkPartitionContext ctxt) { networkPartitionContexts.put(ctxt.getId(), ctxt); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/08d597d7/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java index 0c19d60..619f4bf 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java @@ -147,6 +147,7 @@ public class PolicyManager { log.debug("Removing policy :" + policy); } autoscalePolicyListMap.remove(policy); + RegistryManager.getInstance().removeAutoscalerPolicy(this.getAutoscalePolicy(policy)); } else { throw new InvalidPolicyException("No such policy [" + policy + "] exists"); } @@ -194,8 +195,14 @@ public class PolicyManager { public void removeDeploymentPolicy(String policy) throws InvalidPolicyException { if (deploymentPolicyListMap.containsKey(policy)) { if (log.isDebugEnabled()) { - log.debug("Removing policy :" + policy); + log.debug("Removing deployment policy :" + policy); } + DeploymentPolicy depPolicy = this.getDeploymentPolicy(policy); + // undeploy network partitions this deployment policy. + PartitionManager.getInstance().undeployNetworkPartitions(depPolicy); + // undeploy the deployment policy. + RegistryManager.getInstance().removeDeploymentPolicy(depPolicy); + // remove from the infromation model. deploymentPolicyListMap.remove(policy); } else { throw new InvalidPolicyException("No such policy [" + policy + "] exists"); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/08d597d7/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 7b05a4f..9a40c83 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 @@ -264,4 +264,52 @@ public class RegistryManager { } return depPolicyList; } + + public void removeAutoscalerPolicy(AutoscalePolicy autoscalePolicy) { + String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.AS_POLICY_RESOURCE + "/" + autoscalePolicy.getId(); + this.delete(resourcePath); + if(log.isDebugEnabled()) { + log.debug(String.format("Autoscaler policy deleted from registry: [id] %s [name] %s [description] %s", + autoscalePolicy.getId(), autoscalePolicy.getDisplayName(), autoscalePolicy.getDescription())); + } + + } + + public void removeDeploymentPolicy(DeploymentPolicy depPolicy){ + String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.DEPLOYMENT_POLICY_RESOURCE; + this.delete(resourcePath); + if(log.isDebugEnabled()) { + log.debug(String.format("Deployment policy deleted from registry: [id] %s" , + depPolicy.getId())); + } + } + + public void removeNetworkPartition(String networkPartition){ + String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.NETWORK_PARTITION_RESOURCE; + this.delete(resourcePath); + if(log.isDebugEnabled()) { + log.debug(String.format("Network partition deleted from registry: [id] %s" , + networkPartition)); + } + } + + + private void delete(String resourcePath) { + try { + registryService.beginTransaction(); + registryService.delete(resourcePath); + registryService.commitTransaction(); + } catch (RegistryException e) { + try { + registryService.rollbackTransaction(); + } catch (RegistryException e1) { + if(log.isErrorEnabled()) { + log.error("Could not rollback transaction", e); + } + } + log.error("Could not delete resource at "+ resourcePath); + throw new AutoScalerException("Could not delete data in registry at " + resourcePath, e); + } + + } }
