stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject stratos git commit: Fixing application undeployment logic in autosclaer service
Date Mon, 22 Dec 2014 12:03:00 GMT
Repository: stratos
Updated Branches:
  refs/heads/master e45f31f1b -> 8f9d4dfbe


Fixing application undeployment logic in autosclaer service


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

Branch: refs/heads/master
Commit: 8f9d4dfbe5f0677459a1a190841f9eb8af1551fe
Parents: e45f31f
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Mon Dec 22 17:32:40 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Mon Dec 22 17:32:54 2014 +0530

----------------------------------------------------------------------
 .../autoscaler/api/AutoScalerServiceImpl.java   | 25 ++++++++++--
 .../applications/topic/ApplicationBuilder.java  | 30 +++++++-------
 .../internal/AutoscalerServerComponent.java     |  2 +-
 .../autoscaler/pojo/policy/PolicyManager.java   | 41 +++++++++++++++-----
 4 files changed, 68 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/8f9d4dfb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
index 4b2aaea..cc6458c 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
@@ -286,11 +286,28 @@ public class AutoScalerServiceImpl implements AutoScalerServiceInterface
{
 
     @Override
     public void undeployApplication(String applicationId) {
-        ApplicationBuilder.handleApplicationUndeployed(applicationId);
+        try {
+            if (log.isInfoEnabled()) {
+                log.info("Starting to undeploy application: [application-id] " + applicationId);
+            }
 
-        ApplicationContext applicationContext = AutoscalerContext.getInstance().getApplicationContext(applicationId);
-        applicationContext.setStatus(ApplicationContext.STATUS_CREATED);
-        AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
+            ApplicationBuilder.handleApplicationUndeployed(applicationId);
+
+            ApplicationContext applicationContext = AutoscalerContext.getInstance().getApplicationContext(applicationId);
+            applicationContext.setStatus(ApplicationContext.STATUS_CREATED);
+            AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
+
+            DeploymentPolicy deploymentPolicy = PolicyManager.getInstance().getDeploymentPolicy(applicationId);
+            PolicyManager.getInstance().removeDeploymentPolicy(deploymentPolicy);
+
+            if (log.isInfoEnabled()) {
+                log.info("Application undeployed successfully: [application-id] " + applicationId);
+            }
+        } catch (Exception e) {
+            String message = "Could not undeploy application: [application-id] " + applicationId;
+            log.error(message, e);
+            throw new RuntimeException(message, e);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/stratos/blob/8f9d4dfb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
index a2cc84b..74f63f8 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/topic/ApplicationBuilder.java
@@ -299,37 +299,37 @@ public class ApplicationBuilder {
         }
     }
 
-    public static boolean handleApplicationUndeployed(String appId) {
+    public static boolean handleApplicationUndeployed(String applicationId) {
         if (log.isDebugEnabled()) {
-            log.debug("Handling application terminating event: [application-id] " + appId);
+            log.debug("Handling application terminating event: [application-id] " + applicationId);
         }
         Set<ClusterDataHolder> clusterData;
         ApplicationHolder.acquireWriteLock();
         try {
             Applications applications = ApplicationHolder.getApplications();
-            Application application = applications.getApplication(appId);
+            Application application = applications.getApplication(applicationId);
             //update the status of the Group
             if (application == null) {
-                log.warn(String.format("Application does not exist: [application-id] %s",
-                        appId));
+                log.warn(String.format("Application does not exist: [application-id] %s",
applicationId));
                 return false;
             }
             clusterData = application.getClusterDataRecursively();
-            Collection<ApplicationInstance> context = application.
+            Collection<ApplicationInstance> applicationInstances = application.
                     getInstanceIdToInstanceContextMap().values();
             ApplicationStatus status = ApplicationStatus.Terminating;
-            for (ApplicationInstance context1 : context) {
-                if (context1.isStateTransitionValid(status)) {
+            for (ApplicationInstance applicationInstance : applicationInstances) {
+                if (applicationInstance.isStateTransitionValid(status)) {
                     //setting the status, persist and publish
-                    application.setStatus(status, context1.getInstanceId());
-                    updateApplicationMonitor(appId, status, context1.getNetworkPartitionId(),
-                                            context1.getInstanceId());
+                    application.setStatus(status, applicationInstance.getInstanceId());
+                    updateApplicationMonitor(applicationId, status, applicationInstance.getNetworkPartitionId(),
+                                            applicationInstance.getInstanceId());
                     ApplicationHolder.persistApplication(application);
-                    ApplicationsEventPublisher.sendApplicationInstanceTerminatingEvent(appId,
context1.getInstanceId());
+                    ApplicationsEventPublisher.sendApplicationInstanceTerminatingEvent(applicationId,
+                            applicationInstance.getInstanceId());
                 } else {
                     log.warn(String.format("Application Instance state transition is not
valid: [application-id] %s " +
-                                    " [instance-id] %s [current-status] %s [status-requested]
%s", appId,
-                            context1.getInstanceId() + context1.getStatus(), status));
+                                    " [instance-id] %s [current-status] %s [status-requested]
%s", applicationId,
+                            applicationInstance.getInstanceId() + applicationInstance.getStatus(),
status));
                 }
             }
         } finally {
@@ -348,7 +348,7 @@ public class ApplicationBuilder {
                         Cluster cluster = service.getCluster(aClusterData.getClusterId());
                         if (cluster != null) {
                             for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values())
{
-                                ClusterStatusEventPublisher.sendClusterTerminatingEvent(appId,
+                                ClusterStatusEventPublisher.sendClusterTerminatingEvent(applicationId,
                                         aClusterData.getServiceType(),
                                         aClusterData.getClusterId(),
                                         instance.getInstanceId());

http://git-wip-us.apache.org/repos/asf/stratos/blob/8f9d4dfb/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
index a5b73e5..74a43f9 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
@@ -122,7 +122,7 @@ public class AutoscalerServerComponent {
 			Iterator<DeploymentPolicy> depPolicyIterator = depPolicies.iterator();
 			while (depPolicyIterator.hasNext()) {
 				DeploymentPolicy depPolicy = depPolicyIterator.next();
-				PolicyManager.getInstance().addDeploymentPolicyToInformationModel(depPolicy);
+				PolicyManager.getInstance().addDeploymentPolicy(depPolicy);
 			}
 
 			//starting the processor chain

http://git-wip-us.apache.org/repos/asf/stratos/blob/8f9d4dfb/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 5126b8d..a5765c8 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
@@ -21,19 +21,16 @@ package org.apache.stratos.autoscaler.pojo.policy;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.UUID;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.autoscaler.pojo.policy.deployment.DeploymentPolicy;
 import org.apache.stratos.autoscaler.exception.AutoScalerException;
-import org.apache.stratos.autoscaler.exception.partition.InvalidPartitionException;
 import org.apache.stratos.autoscaler.exception.policy.InvalidPolicyException;
 //import org.apache.stratos.autoscaler.pojo.policy.deployment.partition.PartitionManager;
 import org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy;
 import org.apache.stratos.autoscaler.registry.RegistryManager;
-import org.apache.stratos.cloud.controller.stub.domain.Partition;
 
 /**
  * Manager class for the purpose of managing Autoscale/Deployment policy definitions.
@@ -90,9 +87,13 @@ public class PolicyManager {
         return true;
     }
 
-    // Add the deployment policy to information model and persist.
+    /**
+     * Add deployment policy to in memory map and persist.
+     * @param policy
+     * @throws InvalidPolicyException
+     */
     public void addDeploymentPolicy(DeploymentPolicy policy) throws InvalidPolicyException
{
-        addDeploymentPolicyToInformationModel(policy);
+        addDeploymentPolicyToPolicyListMap(policy);
         RegistryManager.getInstance().persistDeploymentPolicy(policy);
 
         if (log.isInfoEnabled()) {
@@ -101,6 +102,21 @@ public class PolicyManager {
         }
     }
 
+    /**
+     * Remove deployment policy from in memory map and registry.
+     * @param policy
+     * @throws InvalidPolicyException
+     */
+    public void removeDeploymentPolicy(DeploymentPolicy policy) {
+        removeDeploymentPolicyFromMap(policy.getApplicationId());
+        RegistryManager.getInstance().removeDeploymentPolicy(policy);
+
+        if (log.isInfoEnabled()) {
+            log.info(String.format("Deployment policy is removed successfully: [application-id]
%s",
+                    policy.getApplicationId()));
+        }
+    }
+
     public void addASPolicyToInformationModel(AutoscalePolicy asPolicy) throws InvalidPolicyException
{
         if (!autoscalePolicyListMap.containsKey(asPolicy.getId())) {
             if (log.isDebugEnabled()) {
@@ -160,23 +176,28 @@ public class PolicyManager {
         return autoscalePolicyListMap.get(id);
     }
 
-    // Add the deployment policy to As in memmory information model. Does not persist.
-    public void addDeploymentPolicyToInformationModel(DeploymentPolicy policy) throws InvalidPolicyException
{
+    private void addDeploymentPolicyToPolicyListMap(DeploymentPolicy policy) throws InvalidPolicyException
{
         if (StringUtils.isEmpty(policy.getApplicationId())) {
-            throw new RuntimeException("Application id is not defined in deployment policy");
+            throw new RuntimeException("Application id is not found in the deployment policy");
         }
         if (!deploymentPolicyListMap.containsKey(policy.getApplicationId())) {
             if (log.isDebugEnabled()) {
-                log.debug("Adding deployment policy: " + policy.getApplicationId());
+                log.debug("Adding deployment policy: [application-id] " + policy.getApplicationId());
             }
             deploymentPolicyListMap.put(policy.getApplicationId(), policy);
         } else {
-        	String errMsg = "Specified deployment policy [" + policy.getApplicationId()+ "]
already exists";
+        	String errMsg = "Deployment policy already exists: [application-id] " + policy.getApplicationId();
         	log.error(errMsg);
             throw new InvalidPolicyException(errMsg);
         }
     }
 
+    private void removeDeploymentPolicyFromMap(String applicationId) {
+        if(deploymentPolicyListMap.containsKey(applicationId)) {
+            deploymentPolicyListMap.remove(applicationId);
+        }
+    }
+
     public void updateDeploymentPolicyToInformationModel(DeploymentPolicy policy) throws
InvalidPolicyException {
         if (log.isDebugEnabled()) {
             log.debug("Updating deployment policy: " + policy.getApplicationId());


Mime
View raw message