You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2015/08/20 10:31:12 UTC

[3/4] stratos git commit: fixing the application deployment unnecessary wait time

fixing the application deployment unnecessary wait time


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

Branch: refs/heads/master
Commit: 0c794b098e1f28414cc9330eb68fe6aa12231ead
Parents: 2f6a191
Author: reka <rt...@gmail.com>
Authored: Thu Aug 20 13:47:19 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Thu Aug 20 14:00:29 2015 +0530

----------------------------------------------------------------------
 .../AutoscalerTopologyEventReceiver.java        | 69 +++++++++-----------
 .../services/impl/AutoscalerServiceImpl.java    | 12 ++--
 2 files changed, 37 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/0c794b09/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
index 3a8c457..2573991 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/event/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -132,47 +132,38 @@ public class AutoscalerTopologyEventReceiver {
                     ApplicationClustersCreatedEvent applicationClustersCreatedEvent =
                             (ApplicationClustersCreatedEvent) event;
                     String appId = applicationClustersCreatedEvent.getAppId();
-                    boolean appMonitorCreationTriggered = false;
-                    int retries = 30;
-                    while (!appMonitorCreationTriggered && retries > 0) {
-                        try {
-                            //acquire read lock
-                            ApplicationHolder.acquireReadLock();
-                            //start the application monitor
-                            ApplicationContext applicationContext = AutoscalerContext.getInstance().
-                                    getApplicationContext(appId);
-                            if (applicationContext != null &&
-                                    applicationContext.getStatus().
-                                            equals(ApplicationContext.STATUS_DEPLOYED)) {
-                                if (!AutoscalerContext.getInstance().
-                                        containsApplicationPendingMonitor(appId)) {
-                                    appMonitorCreationTriggered = true;
-                                    AutoscalerUtil.getInstance().startApplicationMonitor(appId);
-                                    break;
-                                }
+                    try {
+                        //acquire read lock
+                        ApplicationHolder.acquireReadLock();
+                        //start the application monitor
+                        ApplicationContext applicationContext = AutoscalerContext.getInstance().
+                                getApplicationContext(appId);
+                        if (applicationContext != null &&
+                                applicationContext.getStatus().
+                                        equals(ApplicationContext.STATUS_DEPLOYED)) {
+                            if (!AutoscalerContext.getInstance().
+                                    containsApplicationPendingMonitor(appId)) {
+                                AutoscalerUtil.getInstance().startApplicationMonitor(appId);
                             }
-                        } catch (Exception e) {
-                            String msg = "Error processing event " + e.getLocalizedMessage();
-                            log.error(msg, e);
-                        } finally {
-                            //release read lock
-                            ApplicationHolder.releaseReadLock();
-                        }
-
-                        try {
-                            retries--;
-                            Thread.sleep(1000);
-                        } catch (InterruptedException e) {
+                        } else {
+                            String status;
+                            if(applicationContext == null) {
+                                status = null;
+                            } else {
+                                status = applicationContext.getStatus();
+                            }
+                            log.error("Error while creating the application monitor due to " +
+                                    "in-consistent persistence of [application] " +
+                                    applicationClustersCreatedEvent.getAppId() + ", " +
+                                    "the [application-context] " + applicationContext +
+                            " status of [application-context] " + status);
                         }
-                    }
-
-                    // Reason is to re-try 5 time is because application status might not become "deployed" yet, refer deployApplication API for more information.
-                    // Reason why not throwing error after 5 times is because this not the only place we trigger app-monitor creation.
-                    if (!appMonitorCreationTriggered) {
-                        String msg = String.format("Application monitor creation is not triggered on application "
-                                + "clusters created event even after 5 retries [application-id] %s. "
-                                + "Possible cause is either application context is null or application status didn't become %s yet.", appId, ApplicationContext.STATUS_DEPLOYED);
-                        log.warn(msg);
+                    } catch (Exception e) {
+                        String msg = "Error processing event " + e.getLocalizedMessage();
+                        log.error(msg, e);
+                    } finally {
+                        //release read lock
+                        ApplicationHolder.releaseReadLock();
                     }
                 } catch (ClassCastException e) {
                     String msg = "Error while casting the event " + e.getLocalizedMessage();

http://git-wip-us.apache.org/repos/asf/stratos/blob/0c794b09/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
index f75fbc5..f0e797f 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
@@ -245,10 +245,6 @@ public class AutoscalerServiceImpl implements AutoscalerService {
             // validating application policy against the application
             AutoscalerUtil.validateApplicationPolicyAgainstApplication(applicationId, applicationPolicyId);
 
-            // Create application clusters in cloud controller and send application created event
-            ApplicationBuilder.handleApplicationDeployment(application,
-                    applicationContext.getComponents().getApplicationClusterContexts());
-
             // Setting application policy id in application object
             try {
                 ApplicationHolder.acquireWriteLock();
@@ -272,7 +268,13 @@ public class AutoscalerServiceImpl implements AutoscalerService {
             applicationContext.setStatus(ApplicationContext.STATUS_DEPLOYED);
             AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
 
-            log.info("Waiting for application clusters to be created: [application-id] " + applicationId);
+            // Create application clusters in cloud controller and send application created event
+            ApplicationBuilder.handleApplicationDeployment(application,
+                    applicationContext.getComponents().getApplicationClusterContexts());
+
+            log.info("Waiting for application clusters to be created: [application-id] " +
+                    applicationId);
+
             return true;
         } catch (Exception e) {
             ApplicationContext applicationContext = RegistryManager.getInstance().