You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2015/11/29 20:25:32 UTC

[01/28] stratos git commit: Formatting Application message processors and improving logs

Repository: stratos
Updated Branches:
  refs/heads/stratos-4.1.x 4e868f24f -> e9bef7da5


Formatting Application message processors and improving logs


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

Branch: refs/heads/stratos-4.1.x
Commit: 6b4be642d76b815906663156e8717f2f13d995d2
Parents: 5344c39
Author: Akila Perera <ra...@gmail.com>
Authored: Sun Nov 29 23:54:19 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:45 2015 +0530

----------------------------------------------------------------------
 .../ApplicationCreatedMessageProcessor.java     | 25 ++++++------
 .../ApplicationDeletedMessageProcessor.java     | 12 +++---
 ...cationInstanceActivatedMessageProcessor.java | 42 ++++++++++----------
 ...licationInstanceCreatedMessageProcessor.java | 25 ++++++------
 ...tionInstanceInactivatedMessageProcessor.java | 40 ++++++++++---------
 ...ationInstanceTerminatedMessageProcessor.java | 25 ++++++------
 ...tionInstanceTerminatingMessageProcessor.java | 41 ++++++++++---------
 7 files changed, 109 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6b4be642/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationCreatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationCreatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationCreatedMessageProcessor.java
index 83622ee..2bbd1f5 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationCreatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationCreatedMessageProcessor.java
@@ -39,15 +39,13 @@ public class ApplicationCreatedMessageProcessor extends MessageProcessor {
 
     @Override
     public boolean process(String type, String message, Object object) {
-
         Applications applications = (Applications) object;
-
         if (ApplicationCreatedEvent.class.getName().equals(type)) {
             if (!applications.isInitialized()) {
                 return false;
             }
-
-            ApplicationCreatedEvent event = (ApplicationCreatedEvent) MessagingUtil.jsonToObject(message, ApplicationCreatedEvent.class);
+            ApplicationCreatedEvent event = (ApplicationCreatedEvent) MessagingUtil
+                    .jsonToObject(message, ApplicationCreatedEvent.class);
             if (event == null) {
                 log.error("Unable to convert the JSON message to ApplicationCreatedEvent");
                 return false;
@@ -60,19 +58,19 @@ public class ApplicationCreatedMessageProcessor extends MessageProcessor {
             } finally {
                 ApplicationsUpdater.releaseWriteLockForApplications();
             }
-
         } else {
             if (nextProcessor != null) {
                 // ask the next processor to take care of the message.
                 return nextProcessor.process(type, message, applications);
             } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process message using available message processors: [type] %s, [body] %s", type,
+                        message));
             }
         }
     }
 
     private boolean doProcess(ApplicationCreatedEvent event, Applications applications) {
-
         // check if required properties are available
         if (event.getApplication() == null) {
             String errorMsg = "Application object of application created event is invalid";
@@ -80,8 +78,10 @@ public class ApplicationCreatedMessageProcessor extends MessageProcessor {
             throw new RuntimeException(errorMsg);
         }
 
-        if (event.getApplication().getUniqueIdentifier() == null || event.getApplication().getUniqueIdentifier().isEmpty()) {
-            String errorMsg = "App id of application created event is invalid: [ " + event.getApplication().getUniqueIdentifier() + " ]";
+        if (event.getApplication().getUniqueIdentifier() == null || event.getApplication().getUniqueIdentifier()
+                .isEmpty()) {
+            String errorMsg = String.format("App id of application created event is invalid: [%s]",
+                    event.getApplication().getUniqueIdentifier());
             log.error(errorMsg);
             throw new RuntimeException(errorMsg);
         }
@@ -89,16 +89,17 @@ public class ApplicationCreatedMessageProcessor extends MessageProcessor {
         // check if an Application with same name exists in applications
         if (applications.applicationExists(event.getApplication().getUniqueIdentifier())) {
             if (log.isDebugEnabled()) {
-                log.debug("Application with id [ " + event.getApplication().getUniqueIdentifier() + " ] already exists");
+                log.debug(String.format("App id of application created event already exists: [%s]",
+                        event.getApplication().getUniqueIdentifier()));
             }
         } else {
             // add application and the clusters to Topology
             applications.addApplication(event.getApplication());
             if (log.isInfoEnabled()) {
-                log.info("Application with id [ " + event.getApplication().getUniqueIdentifier() + " ] created");
+                log.info(String.format("Application created with id: [%s]",
+                        event.getApplication().getUniqueIdentifier()));
             }
         }
-
         notifyEventListeners(event);
         return true;
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6b4be642/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationDeletedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationDeletedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationDeletedMessageProcessor.java
index f1dc19c..61c4d39 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationDeletedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationDeletedMessageProcessor.java
@@ -39,15 +39,14 @@ public class ApplicationDeletedMessageProcessor extends MessageProcessor {
 
     @Override
     public boolean process(String type, String message, Object object) {
-
         Applications applications = (Applications) object;
-
         if (ApplicationDeletedEvent.class.getName().equals(type)) {
             if (!applications.isInitialized()) {
                 return false;
             }
 
-            ApplicationDeletedEvent event = (ApplicationDeletedEvent) MessagingUtil.jsonToObject(message, ApplicationDeletedEvent.class);
+            ApplicationDeletedEvent event = (ApplicationDeletedEvent) MessagingUtil
+                    .jsonToObject(message, ApplicationDeletedEvent.class);
             if (event == null) {
                 log.error("Unable to convert the JSON message to ApplicationDeletedEvent");
                 return false;
@@ -66,13 +65,14 @@ public class ApplicationDeletedMessageProcessor extends MessageProcessor {
                 // ask the next processor to take care of the message.
                 return nextProcessor.process(type, message, applications);
             } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process message using available message processors: [type] %s [body] %s", type,
+                        message));
             }
         }
     }
 
     private boolean doProcess(ApplicationDeletedEvent event, Applications applications) {
-
         // check if required properties are available
         if (event.getAppId() == null || event.getAppId().isEmpty()) {
             String errorMsg = "App id of application deleted event is invalid: [ " + event.getAppId() + " ]";
@@ -82,13 +82,11 @@ public class ApplicationDeletedMessageProcessor extends MessageProcessor {
 
         // Remove application and clusters from topology
         applications.removeApplication(event.getAppId());
-
         notifyEventListeners(event);
 
         if (log.isInfoEnabled()) {
             log.info("[Application] " + event.getAppId() + " has been successfully removed");
         }
-
         return true;
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6b4be642/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceActivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceActivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceActivatedMessageProcessor.java
index 862ad8e..1acd9f6 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceActivatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceActivatedMessageProcessor.java
@@ -33,10 +33,7 @@ import org.apache.stratos.messaging.util.MessagingUtil;
  * This processor responsible to process the application activation even and update the Topology.
  */
 public class ApplicationInstanceActivatedMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationInstanceActivatedMessageProcessor.class);
-
-
+    private static final Log log = LogFactory.getLog(ApplicationInstanceActivatedMessageProcessor.class);
     private MessageProcessor nextProcessor;
 
     @Override
@@ -44,15 +41,15 @@ public class ApplicationInstanceActivatedMessageProcessor extends MessageProcess
         this.nextProcessor = nextProcessor;
     }
 
-
     @Override
     public boolean process(String type, String message, Object object) {
         Applications applications = (Applications) object;
 
         if (ApplicationInstanceActivatedEvent.class.getName().equals(type)) {
             // Return if applications has not been initialized
-            if (!applications.isInitialized())
+            if (!applications.isInitialized()) {
                 return false;
+            }
 
             // Parse complete message and build event
             ApplicationInstanceActivatedEvent event = (ApplicationInstanceActivatedEvent) MessagingUtil.
@@ -61,7 +58,6 @@ public class ApplicationInstanceActivatedMessageProcessor extends MessageProcess
             try {
                 ApplicationsUpdater.acquireWriteLockForApplication(event.getAppId());
                 return doProcess(event, applications);
-
             } finally {
                 ApplicationsUpdater.releaseWriteLockForApplication(event.getAppId());
             }
@@ -71,37 +67,43 @@ public class ApplicationInstanceActivatedMessageProcessor extends MessageProcess
                 // ask the next processor to take care of the message.
                 return nextProcessor.process(type, message, applications);
             } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process message using available message processors: [type] %s [body] %s", type,
+                        message));
             }
         }
     }
 
     private boolean doProcess(ApplicationInstanceActivatedEvent event, Applications applications) {
-
         // Validate event against the existing applications
         Application application = applications.getApplication(event.getAppId());
         if (application == null) {
             if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
+                log.warn(String.format("Application does not exist: [application-id] %s", event.getAppId()));
             }
             return false;
         } else {
             // Apply changes to the applications
-            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
-            if (context == null) {
+            ApplicationInstance applicationInstance = application.getInstanceContexts(event.getInstanceId());
+            if (applicationInstance == null) {
                 if (log.isWarnEnabled()) {
-                    log.warn(String.format("Application instance not exists in group: [AppId] %s" +
-                            "[instanceId] %s", event.getAppId(), event.getInstanceId()));
+                    log.warn(String.format(
+                            "Application instance not exists in group: [application-id] %s [instance-id] %s",
+                            event.getAppId(), event.getInstanceId()));
                 }
-
                 return false;
             }
-            ApplicationStatus status = ApplicationStatus.Active;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid application state transfer from [" + context.getStatus() + "] to [" + status + "]");
+            ApplicationStatus currentStatus = applicationInstance.getStatus();
+            if (!applicationInstance.isStateTransitionValid(ApplicationStatus.Active)) {
+                log.error(String.format("Invalid application state transfer [from] %s [to] %s", currentStatus,
+                        ApplicationStatus.Active));
+                return false;
+            }
+            applicationInstance.setStatus(ApplicationStatus.Active);
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Application instance status updated [from] %s [to] %s for [instance-id] %s",
+                        currentStatus, ApplicationStatus.Active, applicationInstance.getInstanceId()));
             }
-            context.setStatus(status);
         }
 
         // Notify event listeners

http://git-wip-us.apache.org/repos/asf/stratos/blob/6b4be642/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceCreatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceCreatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceCreatedMessageProcessor.java
index e56d7bf..5e79f85 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceCreatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceCreatedMessageProcessor.java
@@ -45,9 +45,8 @@ public class ApplicationInstanceCreatedMessageProcessor extends MessageProcessor
             if (!applications.isInitialized()) {
                 return false;
             }
-            ApplicationInstanceCreatedEvent event =
-                    (ApplicationInstanceCreatedEvent) MessagingUtil.jsonToObject(message,
-                            ApplicationInstanceCreatedEvent.class);
+            ApplicationInstanceCreatedEvent event = (ApplicationInstanceCreatedEvent) MessagingUtil
+                    .jsonToObject(message, ApplicationInstanceCreatedEvent.class);
             if (event == null) {
                 log.error("Unable to convert the JSON message to ApplicationInstanceCreatedEvent");
                 return false;
@@ -56,8 +55,7 @@ public class ApplicationInstanceCreatedMessageProcessor extends MessageProcessor
             ApplicationsUpdater.acquireWriteLockForApplications();
             try {
                 return doProcess(event, applications);
-            }
-            finally {
+            } finally {
                 ApplicationsUpdater.releaseWriteLockForApplications();
             }
         } else {
@@ -73,12 +71,12 @@ public class ApplicationInstanceCreatedMessageProcessor extends MessageProcessor
     }
 
     private boolean doProcess(ApplicationInstanceCreatedEvent event, Applications applications) {
-
         // check if required properties are available
         if (event.getApplicationInstance() == null || event.getApplicationId() == null) {
-            String errorMsg = "Application instance object of ApplicationInstanceCreatedEvent is invalid. " +
-                    "[ApplicationId] " + event.getApplicationId() + ", [ApplicationInstance] " +
-                    event.getApplicationInstance();
+            String errorMsg = String
+                    .format("Application instance object of ApplicationInstanceCreatedEvent is invalid: "
+                                    + "[application-id] %s, [app-instance-id] %s", event.getApplicationId(),
+                            event.getApplicationInstance().getInstanceId());
             log.error(errorMsg);
             throw new RuntimeException(errorMsg);
         }
@@ -90,8 +88,8 @@ public class ApplicationInstanceCreatedMessageProcessor extends MessageProcessor
         ApplicationInstance applicationInstance = event.getApplicationInstance();
 
         if (applicationInstance.getInstanceId() == null || applicationInstance.getInstanceId().isEmpty()) {
-            String errorMsg = "App instance id of application instance created event is invalid: [ "
-                    + applicationInstance.getInstanceId() + " ]";
+            String errorMsg = String.format("Application instance created event is invalid: [app-instance-id] %s",
+                    applicationInstance.getInstanceId());
             log.error(errorMsg);
             throw new RuntimeException(errorMsg);
         }
@@ -99,7 +97,8 @@ public class ApplicationInstanceCreatedMessageProcessor extends MessageProcessor
         // check if an Application instance with same name exists in applications instance
         if (null != applications.getApplication(event.getApplicationId()).
                 getInstanceByNetworkPartitionId(applicationInstance.getNetworkPartitionId())) {
-            log.warn("Application instance [AppInstanceId] " + applicationInstance.getInstanceId() + " already exists");
+            log.warn(String.format("Application instance [app-instance-id] %s already exists",
+                    applicationInstance.getInstanceId()));
         } else {
             // add application instance to Application Topology
             applications.getApplication(event.getApplicationId())
@@ -108,4 +107,4 @@ public class ApplicationInstanceCreatedMessageProcessor extends MessageProcessor
         notifyEventListeners(event);
         return true;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/6b4be642/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceInactivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceInactivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceInactivatedMessageProcessor.java
index 3f1b56c..daa2290 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceInactivatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceInactivatedMessageProcessor.java
@@ -33,9 +33,7 @@ import org.apache.stratos.messaging.util.MessagingUtil;
  * This processor responsible to process the application Inactivation even and update the Topology.
  */
 public class ApplicationInstanceInactivatedMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationInstanceInactivatedMessageProcessor.class);
-
+    private static final Log log = LogFactory.getLog(ApplicationInstanceInactivatedMessageProcessor.class);
 
     private MessageProcessor nextProcessor;
 
@@ -44,15 +42,15 @@ public class ApplicationInstanceInactivatedMessageProcessor extends MessageProce
         this.nextProcessor = nextProcessor;
     }
 
-
     @Override
     public boolean process(String type, String message, Object object) {
         Applications applications = (Applications) object;
 
         if (ApplicationInstanceInactivatedEvent.class.getName().equals(type)) {
             // Return if applications has not been initialized
-            if (!applications.isInitialized())
+            if (!applications.isInitialized()) {
                 return false;
+            }
 
             // Parse complete message and build event
             ApplicationInstanceInactivatedEvent event = (ApplicationInstanceInactivatedEvent) MessagingUtil.
@@ -72,38 +70,44 @@ public class ApplicationInstanceInactivatedMessageProcessor extends MessageProce
                 // ask the next processor to take care of the message.
                 return nextProcessor.process(type, message, applications);
             } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process message using available message processors: [type] %s [body] %s", type,
+                        message));
             }
         }
     }
 
     private boolean doProcess(ApplicationInstanceInactivatedEvent event, Applications applications) {
-
         // Validate event against the existing applications
         Application application = applications.getApplication(event.getAppId());
         if (application == null) {
             if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
+                log.warn(String.format("Application does not exist: [service] %s", event.getAppId()));
             }
             return false;
         } else {
             // Apply changes to the applications
-            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
-            if (context == null) {
+            ApplicationInstance applicationInstance = application.getInstanceContexts(event.getInstanceId());
+            if (applicationInstance == null) {
                 if (log.isWarnEnabled()) {
-                    log.warn(String.format("Application instance not exists in group: [application-id] %s" +
-                            "[instance-id] %s", event.getAppId(), event.getInstanceId()));
+                    log.warn(String.format(
+                            "Application instance not exists in group: [application-id] %s, [instance-id] %s",
+                            event.getAppId(), event.getInstanceId()));
                 }
 
                 return false;
             }
-            ApplicationStatus status = ApplicationStatus.Inactive;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid state transfer from [ " + context.getStatus() +
-                        " ] to [ " + status + " ]");
+            ApplicationStatus currentStatus = applicationInstance.getStatus();
+            if (!applicationInstance.isStateTransitionValid(ApplicationStatus.Inactive)) {
+                log.error(String.format("Invalid application state transfer [from] %s [to] %s", currentStatus,
+                        ApplicationStatus.Inactive));
+                return false;
+            }
+            applicationInstance.setStatus(ApplicationStatus.Inactive);
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Application instance status updated [from] %s [to] %s for [instance-id] %s",
+                        currentStatus, ApplicationStatus.Inactive, applicationInstance.getInstanceId()));
             }
-            context.setStatus(status);
         }
 
         // Notify event listeners

http://git-wip-us.apache.org/repos/asf/stratos/blob/6b4be642/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatedMessageProcessor.java
index 0753969..68e4557 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatedMessageProcessor.java
@@ -32,9 +32,7 @@ import org.apache.stratos.messaging.util.MessagingUtil;
  * This processor responsible to process the application Inactivation even and update the Topology.
  */
 public class ApplicationInstanceTerminatedMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationInstanceTerminatedMessageProcessor.class);
-
+    private static final Log log = LogFactory.getLog(ApplicationInstanceTerminatedMessageProcessor.class);
 
     private MessageProcessor nextProcessor;
 
@@ -43,15 +41,15 @@ public class ApplicationInstanceTerminatedMessageProcessor extends MessageProces
         this.nextProcessor = nextProcessor;
     }
 
-
     @Override
     public boolean process(String type, String message, Object object) {
         Applications applications = (Applications) object;
 
         if (ApplicationInstanceTerminatedEvent.class.getName().equals(type)) {
             // Return if applications has not been initialized
-            if (!applications.isInitialized())
+            if (!applications.isInitialized()) {
                 return false;
+            }
 
             // Parse complete message and build event
             ApplicationInstanceTerminatedEvent event = (ApplicationInstanceTerminatedEvent) MessagingUtil.
@@ -71,16 +69,18 @@ public class ApplicationInstanceTerminatedMessageProcessor extends MessageProces
                 // ask the next processor to take care of the message.
                 return nextProcessor.process(type, message, applications);
             } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process message using available message processors: [type] %s [body] %s", type,
+                        message));
             }
         }
     }
 
     private boolean doProcess(ApplicationInstanceTerminatedEvent event, Applications applications) {
-
         // check if required properties are available
         if (event.getAppId() == null) {
-            String errorMsg = "Application Id of application removed event is invalid";
+            String errorMsg = "Application Id of application to be removed event is null. Failed to process "
+                    + "ApplicationInstanceTerminatedEvent";
             log.error(errorMsg);
             throw new RuntimeException(errorMsg);
         }
@@ -89,12 +89,15 @@ public class ApplicationInstanceTerminatedMessageProcessor extends MessageProces
         String appId = event.getAppId();
         String instanceId = event.getInstanceId();
         if (applications.applicationExists(appId)) {
-            log.warn("Application with id [ " + appId + " ] still exists in Applications, removing it");
+            log.warn(String.format(
+                    "Application [application-id] %s still exists. Removing application instance [instance-id] %s",
+                    appId, instanceId));
             ApplicationInstance instance = applications.getApplication(appId).
                     getInstanceContexts(instanceId);
             if (instance == null) {
                 if (log.isDebugEnabled()) {
-                    log.debug("Application [Instance] " + instanceId + " has already been removed");
+                    log.debug(String.format("Application instance [instance-id] %s has already been removed",
+                            instanceId));
                 }
             } else {
                 instance.setStatus(ApplicationStatus.Terminated);
@@ -102,9 +105,7 @@ public class ApplicationInstanceTerminatedMessageProcessor extends MessageProces
             }
 
         }
-
         notifyEventListeners(event);
         return true;
-
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/6b4be642/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatingMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatingMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatingMessageProcessor.java
index bd184a1..a96b45c 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatingMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationInstanceTerminatingMessageProcessor.java
@@ -33,9 +33,7 @@ import org.apache.stratos.messaging.util.MessagingUtil;
  * This processor responsible to process the application Inactivation even and update the Topology.
  */
 public class ApplicationInstanceTerminatingMessageProcessor extends MessageProcessor {
-    private static final Log log =
-            LogFactory.getLog(ApplicationInstanceTerminatingMessageProcessor.class);
-
+    private static final Log log = LogFactory.getLog(ApplicationInstanceTerminatingMessageProcessor.class);
 
     private MessageProcessor nextProcessor;
 
@@ -44,15 +42,15 @@ public class ApplicationInstanceTerminatingMessageProcessor extends MessageProce
         this.nextProcessor = nextProcessor;
     }
 
-
     @Override
     public boolean process(String type, String message, Object object) {
         Applications applications = (Applications) object;
 
         if (ApplicationInstanceTerminatingEvent.class.getName().equals(type)) {
             // Return if applications has not been initialized
-            if (!applications.isInitialized())
+            if (!applications.isInitialized()) {
                 return false;
+            }
 
             // Parse complete message and build event
             ApplicationInstanceTerminatingEvent event = (ApplicationInstanceTerminatingEvent) MessagingUtil.
@@ -72,43 +70,48 @@ public class ApplicationInstanceTerminatingMessageProcessor extends MessageProce
                 // ask the next processor to take care of the message.
                 return nextProcessor.process(type, message, applications);
             } else {
-                throw new RuntimeException(String.format("Failed to process message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process message using available message processors: [type] %s [body] %s", type,
+                        message));
             }
         }
     }
 
     private boolean doProcess(ApplicationInstanceTerminatingEvent event, Applications applications) {
-
         // Validate event against the existing applications
         Application application = applications.getApplication(event.getAppId());
         if (application == null) {
             if (log.isWarnEnabled()) {
-                log.warn(String.format("Application does not exist: [service] %s",
-                        event.getAppId()));
+                log.warn(String.format("Application does not exist: [application-id] %s", event.getAppId()));
             }
             return false;
         } else {
             // Apply changes to the applications
-            ApplicationInstance context = application.getInstanceContexts(event.getInstanceId());
-            if (context == null) {
+            ApplicationInstance applicationInstance = application.getInstanceContexts(event.getInstanceId());
+            if (applicationInstance == null) {
                 if (log.isWarnEnabled()) {
-                    log.warn(String.format("Application Instance not exists in Group: [AppId] %s" +
-                            "[instanceId] %s", event.getAppId(), event.getInstanceId()));
+                    log.warn(String.format(
+                            "Application instance does not exist in group: [application-id] %s, [instance-id] %s",
+                            event.getAppId(), event.getInstanceId()));
                 }
 
                 return false;
             }
-            ApplicationStatus status = ApplicationStatus.Terminating;
-            if (!context.isStateTransitionValid(status)) {
-                log.error("Invalid State transfer from [ " + context.getStatus() +
-                        " ] to [ " + status + " ]");
+            ApplicationStatus currentStatus = applicationInstance.getStatus();
+            if (!applicationInstance.isStateTransitionValid(ApplicationStatus.Terminating)) {
+                log.error(String.format("Invalid application state transfer [from] %s [to] %s", currentStatus,
+                        ApplicationStatus.Terminating));
+                return false;
+            }
+            applicationInstance.setStatus(ApplicationStatus.Terminating);
+            if (log.isDebugEnabled()) {
+                log.debug(String.format("Application instance status updated [from] %s [to] %s for [instance-id] %s",
+                        currentStatus, ApplicationStatus.Terminating, applicationInstance.getInstanceId()));
             }
-            context.setStatus(status);
         }
 
         // Notify event listeners
         notifyEventListeners(event);
         return true;
-
     }
 }


[28/28] stratos git commit: Assert monitors are re-created after restarting Stratos in StratosServerRestartTestCase

Posted by ra...@apache.org.
Assert monitors are re-created after restarting Stratos in StratosServerRestartTestCase


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

Branch: refs/heads/stratos-4.1.x
Commit: 314020b3a00457c34acc16cc87ff7caaad195936
Parents: 35eb6c2
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:27:33 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:48 2015 +0530

----------------------------------------------------------------------
 .../server/StratosServerRestartTestCase.java    | 90 ++++++++++----------
 1 file changed, 45 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/314020b3/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/server/StratosServerRestartTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/server/StratosServerRestartTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/server/StratosServerRestartTestCase.java
index 569152a..66c67e7 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/server/StratosServerRestartTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/server/StratosServerRestartTestCase.java
@@ -27,7 +27,6 @@ import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.common.extensions.StratosServerExtension;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.topology.Member;
 import org.testng.Assert;
 import org.testng.annotations.Test;
@@ -43,6 +42,9 @@ import static org.testng.AssertJUnit.assertTrue;
  * Deploy a sample application on mock IaaS and assert whether application instance, cluster instance, member instances
  * are getting activated. Restart the Stratos and check all again.
  */
+@Test(groups = { "server" },
+      dependsOnGroups = { "adc", "application", "cartridge", "iaas", "policies", "users" },
+      alwaysRun = true)
 public class StratosServerRestartTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(StratosServerRestartTestCase.class);
     private static final String RESOURCES_PATH = "/stratos-server-restart-test";
@@ -52,30 +54,27 @@ public class StratosServerRestartTestCase extends StratosIntegrationTest {
     private static final String deploymentPolicyId = "deployment-policy-stratos-server-restart-test";
     private static final String applicationId = "stratos-server-restart-test";
     private static final String applicationPolicyId = "application-policy-stratos-server-restart-test";
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT,
-            groups = { "stratos.server.restart"},
-            dependsOnGroups = { "stratos.application.deployment","stratos.cartridge.iaas", "stratos.policy.management","adc","all","smoke","metadata"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void stratosServerRestartTest() throws Exception {
+        log.info("Running StratosServerRestartTestCase.stratosServerRestartTest test method...");
+        long startTime = System.currentTimeMillis();
 
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
-
-        log.info("Adding autoscaling policy [autoscale policy id] " + autoscalingPolicyId);
         boolean addedScalingPolicy = restClient.addEntity(
                 RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(addedScalingPolicy);
 
         log.info(String.format("Adding cartridge [cartridge type] %s", cartridgeId));
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC1);
 
         log.info(String.format("Adding network partition [network partition id] %s", networkPartitionId));
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId + ".json", RestConstants.NETWORK_PARTITIONS,
-                RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         log.info(String.format("Adding deployment policy [deployment policy id] %s", deploymentPolicyId));
@@ -101,18 +100,19 @@ public class StratosServerRestartTestCase extends StratosIntegrationTest {
         assertTrue(addAppPolicy);
 
         ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient
-                .getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
-                        ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME);
+                .getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, ApplicationPolicyBean.class,
+                        RestConstants.APPLICATION_POLICIES_NAME);
         assertEquals(policyBean.getId(), applicationPolicyId);
 
-        log.info(String.format("Deploying application [application id] %s using [application policy id] %s", applicationId, applicationPolicyId));
+        log.info(String.format("Deploying application [application id] %s using [application policy id] %s",
+                applicationId, applicationPolicyId));
         String resourcePath = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId;
         boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
         assertTrue(deployed);
 
         log.info("Waiting for application status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(applicationId, ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(applicationId);
 
         log.info("Waiting for cluster status to become ACTIVE...");
         topologyHandler.assertClusterActivation(applicationId);
@@ -121,6 +121,15 @@ public class StratosServerRestartTestCase extends StratosIntegrationTest {
         Assert.assertTrue(memberList.size() == 1,
                 String.format("Active member list for application %s is empty", applicationId));
 
+        /*
+        * Restarting Stratos server
+        */
+        StratosServerExtension.restartStratosServer();
+
+        /*
+        * Assert whether cluster monitors were re-created by terminating mock instances. Application status should
+        * become inactive
+        */
         log.info("Terminating members in [cluster id] c1-stratos-server-restart-test in mock IaaS directly to "
                 + "simulate faulty members...");
         Map<String, Member> memberMap = TopologyHandler.getInstance()
@@ -132,30 +141,21 @@ public class StratosServerRestartTestCase extends StratosIntegrationTest {
         }
         // application status should be marked as inactive since some members are faulty
         log.info("Waiting for application status to become INACTIVE");
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Inactive);
-
-        // application should recover itself and become active after spinning more instances
-        log.info("Waiting for application status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationInActiveStatus(bean.getApplicationId());
 
         log.info("Waiting for cluster status to become ACTIVE...");
         topologyHandler.assertClusterActivation(bean.getApplicationId());
 
-        // restart stratos server
-        StratosServerExtension.restartStratosServer();
-
+        // application should recover itself and become active after spinning more instances
         log.info("Waiting for application status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Active);
-
-        log.info("Waiting for cluster status to become ACTIVE...");
-        topologyHandler.assertClusterActivation(bean.getApplicationId());
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         memberList = topologyHandler.getMembersForApplication(bean.getApplicationId());
         Assert.assertTrue(memberList.size() == 1,
                 String.format("Active member list for application %s is empty", bean.getApplicationId()));
 
         log.info(String.format("Un-deploying the application [application id] %s", applicationId));
-        String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId+
+        String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
         boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
@@ -165,17 +165,17 @@ public class StratosServerRestartTestCase extends StratosIntegrationTest {
         if (!undeploy) {
             //Need to forcefully undeploy the application
             log.info(String.format("Force undeployment is going to start for the [application] %s", applicationId));
-            restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId+
+            restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId +
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = topologyHandler.assertApplicationUndeploy(applicationId);
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    applicationId), forceUndeployed);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId),
+                    forceUndeployed);
         }
 
         log.info(String.format("Removing the application [application id] %s", applicationId));
-        boolean removedApp = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removedApp = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId, RestConstants.APPLICATIONS_NAME);
         assertTrue(removedApp);
 
         ApplicationBean beanRemoved = (ApplicationBean) restClient
@@ -184,14 +184,13 @@ public class StratosServerRestartTestCase extends StratosIntegrationTest {
         assertNull(beanRemoved);
 
         log.info(String.format("Removing the application policy [application policy id] %s", applicationPolicyId));
-        boolean removeAppPolicy = restClient
-                .removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
-                        RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removeAppPolicy);
 
         log.info(String.format("Removing the cartridge [cartridge type] %s", cartridgeId));
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC1);
 
         log.info(String.format("Removing the autoscaling policy [autoscaling policy id] %s", autoscalingPolicyId));
@@ -200,15 +199,16 @@ public class StratosServerRestartTestCase extends StratosIntegrationTest {
         assertTrue(removedAuto);
 
         log.info(String.format("Removing the deployment policy [deployment policy id] %s", deploymentPolicyId));
-        boolean removedDep = restClient
-                .removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
-                        RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
 
         log.info(String.format("Removing the network partition [network partition id] %s", networkPartitionId));
-        boolean removedNet = restClient
-                .removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
-                        RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedNet);
+
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("StratosServerRestartTestCase completed in [duration] %s ms", duration));
     }
 }


[05/28] stratos git commit: Add synchronize blocks to InstanceNotifierEventReceiver to avoid concurrency issues

Posted by ra...@apache.org.
Add synchronize blocks to InstanceNotifierEventReceiver to avoid concurrency issues


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

Branch: refs/heads/stratos-4.1.x
Commit: eb93f701bd1f1e1cd6e9181f8dd702b391fbc500
Parents: 2b6f972
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:06:41 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../notifier/InstanceNotifierEventReceiver.java | 62 +++++++++++---------
 1 file changed, 33 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/eb93f701/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/instance/notifier/InstanceNotifierEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/instance/notifier/InstanceNotifierEventReceiver.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/instance/notifier/InstanceNotifierEventReceiver.java
index 7476d18..4ad6572 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/instance/notifier/InstanceNotifierEventReceiver.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/instance/notifier/InstanceNotifierEventReceiver.java
@@ -19,7 +19,6 @@
 
 package org.apache.stratos.messaging.message.receiver.instance.notifier;
 
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.messaging.broker.subscribe.EventSubscriber;
@@ -32,50 +31,54 @@ import org.apache.stratos.messaging.util.MessagingUtil;
 public class InstanceNotifierEventReceiver {
     private static final Log log = LogFactory.getLog(InstanceNotifierEventReceiver.class);
     private final InstanceNotifierEventMessageDelegator messageDelegator;
-    private final InstanceNotifierEventMessageListener messageListener;
     private EventSubscriber eventSubscriber;
     private boolean terminated;
 
     public InstanceNotifierEventReceiver() {
         InstanceNotifierEventMessageQueue messageQueue = new InstanceNotifierEventMessageQueue();
         this.messageDelegator = new InstanceNotifierEventMessageDelegator(messageQueue);
-        this.messageListener = new InstanceNotifierEventMessageListener(messageQueue);
+        InstanceNotifierEventMessageListener messageListener = new InstanceNotifierEventMessageListener(messageQueue);
+        // Start topic subscriber thread
+        eventSubscriber = new EventSubscriber(MessagingUtil.Topics.INSTANCE_NOTIFIER_TOPIC.getTopicName(),
+                messageListener);
     }
 
     public void addEventListener(EventListener eventListener) {
         messageDelegator.addEventListener(eventListener);
     }
 
-
     public void execute() {
-        try {
-            // Start topic subscriber thread
-            eventSubscriber = new EventSubscriber(MessagingUtil.Topics.INSTANCE_NOTIFIER_TOPIC.getTopicName(), messageListener);
-//			subscriber.setMessageListener(messageListener);
-            Thread subscriberThread = new Thread(eventSubscriber);
-
-            subscriberThread.start();
-            if (log.isDebugEnabled()) {
-                log.debug("InstanceNotifier event message receiver thread started");
-            }
-
-            // Start instance notifier event message delegator thread
-            Thread receiverThread = new Thread(messageDelegator);
-            receiverThread.start();
-            if (log.isDebugEnabled()) {
-                log.debug("InstanceNotifier event message delegator thread started");
+        synchronized (this) {
+            if (terminated) {
+                log.info("InstanceNotifierEventReceiver has been terminated. Event subscriber will not be created.");
+                return;
             }
+            try {
+                Thread subscriberThread = new Thread(eventSubscriber);
+                subscriberThread.start();
+                if (log.isDebugEnabled()) {
+                    log.debug("InstanceNotifier event message receiver thread started");
+                }
 
-            // Keep the thread live until terminated
-            while (!terminated) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException ignore) {
+                // Start instance notifier event message delegator thread
+                Thread receiverThread = new Thread(messageDelegator);
+                receiverThread.start();
+                if (log.isDebugEnabled()) {
+                    log.debug("InstanceNotifier event message delegator thread started");
+                }
+            } catch (Exception e) {
+                if (log.isErrorEnabled()) {
+                    log.error("InstanceNotifier receiver failed", e);
                 }
             }
-        } catch (Exception e) {
-            if (log.isErrorEnabled()) {
-                log.error("InstanceNotifier receiver failed", e);
+        }
+        log.info("InstanceNotifierEventReceiver started");
+
+        // Keep the thread live until terminated
+        while (!terminated) {
+            try {
+                Thread.sleep(2000);
+            } catch (InterruptedException ignore) {
             }
         }
     }
@@ -84,9 +87,10 @@ public class InstanceNotifierEventReceiver {
         return ((eventSubscriber != null) && (eventSubscriber.isSubscribed()));
     }
 
-    public void terminate() {
+    public synchronized void terminate() {
         eventSubscriber.terminate();
         messageDelegator.terminate();
         terminated = true;
+        log.info("InstanceNotifierEventReceiver terminated");
     }
 }


[25/28] stratos git commit: Rename default timeout consts

Posted by ra...@apache.org.
Rename default timeout consts


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

Branch: refs/heads/stratos-4.1.x
Commit: 1284c55b2bf33b14f184b66005e47477269fe07e
Parents: 314020b
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:28:05 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:48 2015 +0530

----------------------------------------------------------------------
 .../stratos/integration/tests/StratosIntegrationTest.java       | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/1284c55b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
index fca858e..7de8020 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/StratosIntegrationTest.java
@@ -34,9 +34,8 @@ public class StratosIntegrationTest {
     protected String stratosSecuredBackendURL;
     protected RestClient restClient;
     protected MockIaasApiClient mockIaasApiClient;
-    public static final int GLOBAL_TEST_TIMEOUT = 5 * 60 * 1000; // 5 mins
-	public static final int IAAS_PROVIDER_TEST_TIMEOUT = 10 * 60 * 1000; // 10 mins
-    public static final int APPLICATION_TEST_TIMEOUT = 25 * 60 * 1000; // 25 mins
+    public static final int DEFAULT_TEST_TIMEOUT = 5 * 60 * 1000; // 5 mins
+    public static final int DEFAULT_APPLICATION_TEST_TIMEOUT = 25 * 60 * 1000; // 25 mins
 
     public StratosIntegrationTest() {
         try {


[22/28] stratos git commit: Increase executor thread pool size to 20 to compensate for event receivers

Posted by ra...@apache.org.
Increase executor thread pool size to 20 to compensate for event receivers


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

Branch: refs/heads/stratos-4.1.x
Commit: 179120ddc4a46a95bc08fcb3399c895919d6a509
Parents: 87b4471
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:19:25 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../cloud/controller/internal/CloudControllerServiceComponent.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/179120dd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
index 808ac5c..3a0b1e3 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/internal/CloudControllerServiceComponent.java
@@ -75,7 +75,7 @@ public class CloudControllerServiceComponent {
     private static final String CLOUD_CONTROLLER_COORDINATOR_LOCK = "cloud.controller.coordinator.lock";
     private static final String THREAD_POOL_ID = "cloud.controller.thread.pool";
     private static final String SCHEDULER_THREAD_POOL_ID = "cloud.controller.scheduler.thread.pool";
-    private static final int THREAD_POOL_SIZE = 10;
+    private static final int THREAD_POOL_SIZE = 20;
     private static final int SCHEDULER_THREAD_POOL_SIZE = 5;
 
     private ClusterStatusTopicReceiver clusterStatusTopicReceiver;


[26/28] stratos git commit: Update log4j.properties file used in integration test with necessary DEBUG logs to help troubleshoot test failures

Posted by ra...@apache.org.
Update log4j.properties file used in integration test with necessary DEBUG logs to help troubleshoot test failures


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

Branch: refs/heads/stratos-4.1.x
Commit: 9700dec9db36b41cdd243f2ab5861e319d054515
Parents: 1284c55
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:29:05 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:48 2015 +0530

----------------------------------------------------------------------
 .../src/test/resources/common/log4j.properties        | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/9700dec9/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties b/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties
index 2d49c47..f948315 100644
--- a/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/common/log4j.properties
@@ -52,17 +52,23 @@ log4j.logger.me.prettyprint.cassandra.hector.TimingLogger=ERROR
 log4j.logger.org.wso2=INFO
 
 # Apache Stratos logging configuration
-log4j.logger.org.apache.stratos.manager=INFO
+log4j.logger.org.apache.stratos.manager=DEBUG
 log4j.logger.org.apache.stratos.autoscaler=DEBUG
 log4j.logger.org.apache.stratos.messaging=INFO
 log4j.logger.org.apache.stratos.cloud.controller=DEBUG
 log4j.logger.org.wso2.andes.client=ERROR
 # Autoscaler rule logs
-log4j.logger.org.apache.stratos.autoscaler.rule.RuleLog=DEBUG
+log4j.logger.org.apache.stratos.autoscaler.rule.RuleLog=INFO
+
 log4j.logger.org.apache.stratos.cloud.controller.messaging.topology.TopologyHolder=INFO
-log4j.logger.org.apache.stratos.mock.iaas.client=DEBUG
-log4j.logger.org.apache.stratos.mock.iaas.services=DEBUG
+log4j.logger.org.apache.stratos.mock.iaas=DEBUG
+log4j.logger.org.apache.stratos.mock.iaas.client=INFO
+log4j.logger.org.apache.stratos.mock.iaas.statistics.publisher=INFO
 log4j.logger.org.apache.stratos.metadata.service=DEBUG
+log4j.logger.org.apache.stratos.messaging.message.processor.application=DEBUG
+log4j.logger.org.apache.stratos.messaging.message.processor.cluster=DEBUG
+log4j.logger.org.apache.stratos.messaging.domain.application=DEBUG
+log4j.logger.org.apache.stratos.autoscaler.applications.ApplicationHolder=INFO
 
 # Apache jclouds
 #log4j.logger.jclouds.wire=DEBUG


[14/28] stratos git commit: Fixed formatting and log messages

Posted by ra...@apache.org.
Fixed formatting and log messages


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

Branch: refs/heads/stratos-4.1.x
Commit: c39d46fdb642bc072bc2f4e40343d6fec051ba78
Parents: da9b0b3
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:15:10 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../services/impl/AutoscalerServiceImpl.java    | 38 ++++++++++----------
 1 file changed, 19 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/c39d46fd/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 6f84b75..0943de0 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
@@ -34,7 +34,6 @@ import org.apache.stratos.autoscaler.context.InstanceContext;
 import org.apache.stratos.autoscaler.context.cluster.ClusterInstanceContext;
 import org.apache.stratos.autoscaler.context.partition.ClusterLevelPartitionContext;
 import org.apache.stratos.autoscaler.context.partition.network.NetworkPartitionContext;
-import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
 import org.apache.stratos.autoscaler.exception.*;
 import org.apache.stratos.autoscaler.exception.application.ApplicationDefinitionException;
 import org.apache.stratos.autoscaler.exception.application.InvalidApplicationPolicyException;
@@ -44,7 +43,6 @@ import org.apache.stratos.autoscaler.exception.policy.*;
 import org.apache.stratos.autoscaler.monitor.Monitor;
 import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
 import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
-import org.apache.stratos.autoscaler.monitor.component.GroupMonitor;
 import org.apache.stratos.autoscaler.pojo.Dependencies;
 import org.apache.stratos.autoscaler.pojo.ServiceGroup;
 import org.apache.stratos.autoscaler.pojo.policy.PolicyManager;
@@ -465,7 +463,7 @@ public class AutoscalerServiceImpl implements AutoscalerService {
         ApplicationMonitor appMonitor = asCtx.getAppMonitor(applicationId);
 
         if (appMonitor == null) {
-            log.info(String.format("Could not find application monitor for the application %s, " + "hence returning",
+            log.info(String.format("Could not find application monitor for [application-id] %s, hence returning false",
                     applicationId));
             return false;
         }
@@ -505,7 +503,7 @@ public class AutoscalerServiceImpl implements AutoscalerService {
                         return false;
                     } else {
                         log.info(String.format("Previous graceful un-deployment is in progress for "
-                                        + "[application-id] %s , thus  terminating instances directly", applicationId));
+                                + "[application-id] %s , thus  terminating instances directly", applicationId));
                         appMonitor.setForce(true);
                         terminateAllMembersAndClustersForcefully(applicationId);
                     }
@@ -996,8 +994,8 @@ public class AutoscalerServiceImpl implements AutoscalerService {
                                         .terminateInstanceForcefully(memberIdToTerminate);
                             } catch (Exception e) {
                                 log.error(String.format(
-                                                "Forceful termination of member %s has failed, but continuing forceful "
-                                                        + "deletion of other members", memberIdToTerminate));
+                                        "Forceful termination of member %s has failed, but continuing forceful "
+                                                + "deletion of other members", memberIdToTerminate));
                             }
                         }
                     }
@@ -1114,9 +1112,9 @@ public class AutoscalerServiceImpl implements AutoscalerService {
                     }
                 }
                 if (isPartitionFound == false) {
-                    String msg = String.format("Partition Id is not found: [deployment-policy-id] %s "
-                                    + "[network-partition-id] %s [partition-id] %s", deploymentPolicyId,
-                            networkPartitionId, partitionId);
+                    String msg = String
+                            .format("Partition Id is not found: [deployment-policy-id] %s [network-partition-id] %s "
+                                    + "[partition-id] %s", deploymentPolicyId, networkPartitionId, partitionId);
                     log.error(msg);
                     throw new InvalidDeploymentPolicyException(msg);
                 }
@@ -1125,9 +1123,10 @@ public class AutoscalerServiceImpl implements AutoscalerService {
             // partition algorithm can't be null or empty
             String partitionAlgorithm = networkPartitionRef.getPartitionAlgo();
             if (StringUtils.isBlank(partitionAlgorithm)) {
-                String msg = String.format("Partition algorithm is blank: [deployment-policy-id] %s "
-                                + "[network-partition-id] %s [partition-algorithm] %s", deploymentPolicyId,
-                        networkPartitionId, partitionAlgorithm);
+                String msg = String
+                        .format("Partition algorithm is blank: [deployment-policy-id] %s [network-partition-id] %s "
+                                        + "[partition-algorithm] %s", deploymentPolicyId, networkPartitionId,
+                                partitionAlgorithm);
                 log.error(msg);
                 throw new InvalidDeploymentPolicyException(msg);
             }
@@ -1135,10 +1134,11 @@ public class AutoscalerServiceImpl implements AutoscalerService {
             // partition algorithm should be either one-after-another or round-robin
             if ((!StratosConstants.PARTITION_ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm))
                     && (!StratosConstants.PARTITION_ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm))) {
-                String msg = String.format("Partition algorithm is not valid: [deployment-policy-id] %s " +
-                                "[network-partition-id] %s [partition-algorithm] %s. : " +
-                                "Partition algorithm should be either one-after-another or round-robin ",
-                        deploymentPolicyId, networkPartitionId, partitionAlgorithm);
+                String msg = String
+                        .format("Partition algorithm is not valid: [deployment-policy-id] %s [network-partition-id] "
+                                        + "%s [partition-algorithm] %s. Partition algorithm should be either "
+                                        + "one-after-another or round-robin ", deploymentPolicyId, networkPartitionId,
+                                partitionAlgorithm);
                 log.error(msg);
                 throw new InvalidDeploymentPolicyException(msg);
             }
@@ -1146,9 +1146,9 @@ public class AutoscalerServiceImpl implements AutoscalerService {
             // a network partition reference should contain at least one partition reference
             PartitionRef[] partitions = networkPartitionRef.getPartitionRefs();
             if (null == partitions || partitions.length == 0) {
-                String msg = String.format("Network partition does not have any partition references: "
-                                + "[deployment-policy-id] %s [network-partition-id] %s", deploymentPolicyId,
-                        networkPartitionId);
+                String msg = String
+                        .format("Network partition does not have any partition references [deployment-policy-id] %s "
+                                + "[network-partition-id] %s", deploymentPolicyId, networkPartitionId);
                 log.error(msg);
                 throw new InvalidDeploymentPolicyException(msg);
             }


[20/28] stratos git commit: Add debug log to print status of each group instance in GroupStatusActiveProcessor

Posted by ra...@apache.org.
Add debug log to print status of each group instance in GroupStatusActiveProcessor


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

Branch: refs/heads/stratos-4.1.x
Commit: 34f80ec91182ba1ccfa27147ec42b146f0545b73
Parents: 138bd5e
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:17:33 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../group/GroupStatusActiveProcessor.java       | 84 +++++++++++++++-----
 1 file changed, 63 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/34f80ec9/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
index b6b0a97..260c78e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusActiveProcessor.java
@@ -24,8 +24,14 @@ import org.apache.stratos.autoscaler.applications.ApplicationHolder;
 import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
 import org.apache.stratos.autoscaler.status.processor.StatusProcessor;
 import org.apache.stratos.messaging.domain.application.*;
+import org.apache.stratos.messaging.domain.instance.ClusterInstance;
+import org.apache.stratos.messaging.domain.instance.GroupInstance;
+import org.apache.stratos.messaging.domain.topology.Cluster;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 
+import java.util.Collection;
 import java.util.Map;
 
 /**
@@ -41,8 +47,7 @@ public class GroupStatusActiveProcessor extends GroupStatusProcessor {
     }
 
     @Override
-    public boolean process(String idOfComponent, String appId,
-                           String instanceId) {
+    public boolean process(String idOfComponent, String appId, String instanceId) {
         boolean statusChanged;
         statusChanged = doProcess(idOfComponent, appId, instanceId);
         if (statusChanged) {
@@ -54,8 +59,8 @@ public class GroupStatusActiveProcessor extends GroupStatusProcessor {
             return nextProcessor.process(idOfComponent, appId, instanceId);
         } else {
 
-            log.warn(String.format("No possible state change found for [component] %s [instance] %s",
-                    idOfComponent, instanceId));
+            log.warn(String.format("No possible state change found for [component] %s, [instance] %s", idOfComponent,
+                    instanceId));
         }
         return false;
     }
@@ -67,8 +72,9 @@ public class GroupStatusActiveProcessor extends GroupStatusProcessor {
         Map<String, ClusterDataHolder> clusterData;
 
         if (log.isDebugEnabled()) {
-            log.debug("StatusChecker calculating the active status for the group " +
-                    "[ " + idOfComponent + " ] " + " for the instance " + " [ " + instanceId + " ]");
+            log.debug(String.format(
+                    "GroupStatusActiveProcessor is checking the status of [application-id] %s, [group-id] %s, "
+                            + "[group-instance-id] %s", appId, idOfComponent, instanceId));
         }
         try {
             ApplicationHolder.acquireWriteLock();
@@ -84,35 +90,71 @@ public class GroupStatusActiveProcessor extends GroupStatusProcessor {
             groups = component.getAliasToGroupMap();
             clusterData = component.getClusterDataMap();
 
-            if (groups.isEmpty() &&
-                    getAllClusterInSameState(clusterData, ClusterStatus.Active, instanceId) ||
-                    clusterData.isEmpty() &&
-                            getAllGroupInSameState(groups, GroupStatus.Active, instanceId) ||
-                    getAllClusterInSameState(clusterData, ClusterStatus.Active, instanceId) &&
-                            getAllGroupInSameState(groups, GroupStatus.Active, instanceId)) {
+            if (groups.isEmpty() && getAllClusterInSameState(clusterData, ClusterStatus.Active, instanceId) ||
+                    clusterData.isEmpty() && getAllGroupInSameState(groups, GroupStatus.Active, instanceId) ||
+                    getAllClusterInSameState(clusterData, ClusterStatus.Active, instanceId) && getAllGroupInSameState(
+                            groups, GroupStatus.Active, instanceId)) {
 
                 if (component instanceof Application) {
                     //send application activated event
-                    log.info("Sending application instance active for [application] " + appId +
-                            " [instance] " + instanceId);
+                    log.info(String.format(
+                            "Sending application instance active event for [application-id] %s, [instance-id] %s",
+                            appId, instanceId));
                     ApplicationBuilder.handleApplicationInstanceActivatedEvent(appId, instanceId);
                     return true;
                 } else {
                     //send activation to the parent
-                    log.info("Sending group instance active for [group] " +
-                            component.getUniqueIdentifier() + " [instance] " + instanceId);
-                    ApplicationBuilder.handleGroupInstanceActivatedEvent(appId,
-                            component.getUniqueIdentifier(), instanceId);
+                    log.info(String.format(
+                            "Sending group instance active event for [application-id] %s, [group-id] %s, "
+                                    + "[instance-id] %s", appId, component.getUniqueIdentifier(), instanceId));
+                    ApplicationBuilder
+                            .handleGroupInstanceActivatedEvent(appId, component.getUniqueIdentifier(), instanceId);
                     return true;
                 }
-
+            } else {
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format(
+                            "GroupStatusActiveProcessor did not detect any status change for [application-id] %s, "
+                                    + "[group-id] %s, [instance-id] %s", appId, idOfComponent, instanceId));
+                    for (Map.Entry<String, Group> entry : groups.entrySet()) {
+                        Collection<Group> groupCollection = entry.getValue().getGroups();
+                        for (Group group : groupCollection) {
+                            for (GroupInstance groupInstance : group.getInstanceIdToInstanceContextMap().values()) {
+                                log.debug(String.format("Groups: [group-id] %s, [group-instance-id] %s, [status] %s",
+                                        group.getUniqueIdentifier(), groupInstance.getInstanceId(), entry.getKey(),
+                                        groupInstance.getStatus()));
+                            }
+
+                        }
+
+                    }
+                    for (Map.Entry<String, ClusterDataHolder> entry : clusterData.entrySet()) {
+                        String serviceName = entry.getValue().getServiceType();
+                        String clusterId = entry.getValue().getClusterId();
+                        TopologyManager.acquireReadLockForCluster(serviceName, clusterId);
+                        try {
+                            Service service = TopologyManager.getTopology().getService(serviceName);
+                            Cluster cluster = service.getCluster(clusterId);
+                            ClusterInstance context = cluster.getInstanceContexts(instanceId);
+                            if (context != null) {
+                                log.debug(String.format(
+                                        "ClusterData: [cluster-id] %s, [cluster-instance-id] %s, [status] %s",
+                                        entry.getKey(), instanceId, context.getStatus()));
+                            } else {
+                                log.debug(String.format(
+                                        "ClusterData: cluster instance context is null: [cluster-instance-id] %s",
+                                        instanceId));
+                            }
+                        } finally {
+                            TopologyManager.releaseReadLockForCluster(serviceName, clusterId);
+                        }
+                    }
+                }
             }
         } finally {
             ApplicationHolder.releaseWriteLock();
-
         }
         return false;
     }
 
-
 }


[13/28] stratos git commit: Throw MetadataException on failures in MetadataApiRegistry (instead of RegistryException coming from Carbon)

Posted by ra...@apache.org.
Throw MetadataException on failures in MetadataApiRegistry (instead of RegistryException coming from Carbon)


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

Branch: refs/heads/stratos-4.1.x
Commit: 3b83cef816450660abfda9a078e87c7717bfb2cf
Parents: 272210b
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:22:40 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../metadata/service/registry/DataStore.java    | 21 ++++++-----
 .../service/registry/MetadataApiRegistry.java   | 37 ++++++++++----------
 2 files changed, 31 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/3b83cef8/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
index a71c745..20ae1ac 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/DataStore.java
@@ -18,8 +18,8 @@
  */
 package org.apache.stratos.metadata.service.registry;
 
-
 import org.apache.stratos.metadata.service.definition.Property;
+import org.apache.stratos.metadata.service.exception.MetadataException;
 import org.wso2.carbon.registry.api.RegistryException;
 
 import java.util.List;
@@ -29,18 +29,21 @@ import java.util.List;
  */
 public interface DataStore {
 
-    public void addPropertyToApplication(String applicationId, Property property) throws RegistryException;
+    public void addPropertyToApplication(String applicationId, Property property)
+            throws RegistryException, MetadataException;
 
-    public List<Property> getApplicationProperties(String applicationId) throws RegistryException;
+    public List<Property> getApplicationProperties(String applicationId) throws MetadataException;
 
-    public List<Property> getClusterProperties(String applicationId, String clusterId)
-            throws RegistryException;
+    public List<Property> getClusterProperties(String applicationId, String clusterId) throws MetadataException;
 
-    public void addPropertyToCluster(String applicationId, String clusterId, Property property) throws RegistryException;
+    public void addPropertyToCluster(String applicationId, String clusterId, Property property)
+            throws RegistryException, MetadataException;
 
-    public boolean deleteApplicationProperties(String applicationId) throws RegistryException;
+    public boolean deleteApplicationProperties(String applicationId) throws RegistryException, MetadataException;
 
-    public boolean removePropertyFromApplication(String applicationId, String propertyName) throws RegistryException;
+    public boolean removePropertyFromApplication(String applicationId, String propertyName)
+            throws RegistryException, MetadataException;
 
-    public boolean removePropertyValueFromApplication(String applicationId, String propertyName, String valueToRemove) throws RegistryException;
+    public boolean removePropertyValueFromApplication(String applicationId, String propertyName, String valueToRemove)
+            throws RegistryException, MetadataException;
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/3b83cef8/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java
index 11d1468..75ddbc7 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/registry/MetadataApiRegistry.java
@@ -67,9 +67,9 @@ public class MetadataApiRegistry implements DataStore {
      *
      * @param applicationId Application ID under which properties should be retrieved
      * @return List of properties
-     * @throws RegistryException
+     * @throws MetadataException
      */
-    public List<Property> getApplicationProperties(String applicationId) throws RegistryException {
+    public List<Property> getApplicationProperties(String applicationId) throws MetadataException {
         String resourcePath = mainResource + applicationId;
         try {
             acquireReadLock(applicationId);
@@ -79,7 +79,7 @@ public class MetadataApiRegistry implements DataStore {
                     .format("Failed to get properties from registry [resource-path] %s for " + "[application-id] %s",
                             resourcePath, applicationId);
             log.error(msg, e);
-            throw new RegistryException(msg, e);
+            throw new MetadataException(msg, e);
         } finally {
             try {
                 releaseReadLock(applicationId);
@@ -94,9 +94,9 @@ public class MetadataApiRegistry implements DataStore {
      * @param applicationId Application ID under which properties should be retrieved
      * @param clusterId     Cluster ID under which properties should be retrieved
      * @return List of properties
-     * @throws RegistryException
+     * @throws MetadataException
      */
-    public List<Property> getClusterProperties(String applicationId, String clusterId) throws RegistryException {
+    public List<Property> getClusterProperties(String applicationId, String clusterId) throws MetadataException {
         String resourcePath = mainResource + applicationId + "/" + clusterId;
         try {
             acquireReadLock(applicationId);
@@ -105,7 +105,7 @@ public class MetadataApiRegistry implements DataStore {
             String msg = String.format("Failed to get properties from registry [resource-path] %s for [application-id] "
                     + "%s, [cluster-id] %s", resourcePath, applicationId, clusterId);
             log.error(msg, e);
-            throw new RegistryException(msg, e);
+            throw new MetadataException(msg, e);
         } finally {
             try {
                 releaseReadLock(applicationId);
@@ -143,7 +143,8 @@ public class MetadataApiRegistry implements DataStore {
         return newProperties;
     }
 
-    public void addPropertyToApplication(String applicationId, Property property) throws RegistryException {
+    public void addPropertyToApplication(String applicationId, Property property)
+            throws RegistryException, MetadataException {
         Registry registry = getRegistry();
         String resourcePath = mainResource + applicationId;
 
@@ -192,7 +193,7 @@ public class MetadataApiRegistry implements DataStore {
                     .format("Failed to persist properties in registry: [resource-path] %s, [key] %s, [values] %s",
                             resourcePath, property.getKey(), Arrays.asList(property.getValues()));
             log.error(msg, e);
-            throw new RegistryException(msg, e);
+            throw new MetadataException(msg, e);
         } finally {
             try {
                 releaseWriteLock(applicationId);
@@ -208,7 +209,7 @@ public class MetadataApiRegistry implements DataStore {
     }
 
     public boolean removePropertyValueFromApplication(String applicationId, String propertyKey, String valueToRemove)
-            throws RegistryException {
+            throws RegistryException, MetadataException {
         Registry registry = getRegistry();
         String resourcePath = mainResource + applicationId;
 
@@ -233,7 +234,7 @@ public class MetadataApiRegistry implements DataStore {
                             propertyKey, valueToRemove));
             return true;
         } catch (Exception e) {
-            throw new RegistryException(
+            throw new MetadataException(
                     String.format("Could not remove registry resource: [resource-path] %s, [key] %s, [value] %s",
                             resourcePath, propertyKey, valueToRemove), e);
         } finally {
@@ -250,10 +251,10 @@ public class MetadataApiRegistry implements DataStore {
      * @param applicationId Application ID against which added property will be stored
      * @param clusterId     Cluster ID against which added property will be stored
      * @param property      Property to be stored in the registry
-     * @throws RegistryException
+     * @throws RegistryException, MetadataException
      */
     public void addPropertyToCluster(String applicationId, String clusterId, Property property)
-            throws RegistryException {
+            throws RegistryException, MetadataException {
         Registry registry = getRegistry();
         String resourcePath = mainResource + applicationId + "/" + clusterId;
 
@@ -278,7 +279,7 @@ public class MetadataApiRegistry implements DataStore {
                     "Registry property persisted: [resource-path] %s [Property Name] %s [Property Values] %s",
                     resourcePath, property.getKey(), Arrays.asList(property.getValues())));
         } catch (Exception e) {
-            throw new RegistryException(
+            throw new MetadataException(
                     String.format("Could not add registry resource: [resource-path] %s, [key] %s, [value] %s",
                             resourcePath, property.getKey(), Arrays.asList(property.getValues())), e);
 
@@ -299,9 +300,9 @@ public class MetadataApiRegistry implements DataStore {
      *
      * @param applicationId ID of the application.
      * @return True if resource exist and able to delete, else false.
-     * @throws RegistryException
+     * @throws RegistryException, MetadataException
      */
-    public boolean deleteApplicationProperties(String applicationId) throws RegistryException {
+    public boolean deleteApplicationProperties(String applicationId) throws RegistryException, MetadataException {
         if (StringUtils.isBlank(applicationId)) {
             throw new IllegalArgumentException("Application ID can not be null");
         }
@@ -320,7 +321,7 @@ public class MetadataApiRegistry implements DataStore {
             }
             return true;
         } catch (Exception e) {
-            throw new RegistryException(
+            throw new MetadataException(
                     String.format("Could not remove registry resource: [resource-path] %s", resourcePath), e);
         } finally {
             try {
@@ -331,7 +332,7 @@ public class MetadataApiRegistry implements DataStore {
     }
 
     public boolean removePropertyFromApplication(String applicationId, String propertyKey)
-            throws org.wso2.carbon.registry.api.RegistryException {
+            throws RegistryException, MetadataException {
         Registry registry = getRegistry();
         String resourcePath = mainResource + applicationId;
         Resource nodeResource;
@@ -361,7 +362,7 @@ public class MetadataApiRegistry implements DataStore {
                     propertyKey));
             return true;
         } catch (Exception e) {
-            throw new RegistryException(
+            throw new MetadataException(
                     String.format("Could not remove registry resource: [resource-path] %s, [key] %s", resourcePath,
                             propertyKey), e);
         } finally {


[19/28] stratos git commit: Cleaning up test cases. Remove duplicate assertions. Fix formatting.

Posted by ra...@apache.org.
Cleaning up test cases. Remove duplicate assertions. Fix formatting.


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

Branch: refs/heads/stratos-4.1.x
Commit: 35eb6c22d3611d63e2ecbfb2fbfdb49727d23971
Parents: 76199f0
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:26:16 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 pom.xml                                         |   2 +-
 .../ApplicationBurstingTestCase.java            | 145 +++----
 .../ApplicationStartupOrderTestCase.java        | 165 ++++----
 .../application/ApplicationUpdateTestCase.java  | 131 +++---
 .../application/GroupStartupOrderTestCase.java  | 229 +++++------
 .../GroupTerminationBehaviorTestCase.java       | 196 ++++-----
 .../application/MetadataServiceTestCase.java    |  32 +-
 ...PartitionOneAfterAnotherClusterTestCase.java | 148 ++++---
 .../PartitionRoundRobinClusterTestCase.java     | 129 +++---
 .../SampleApplicationStartupTestCase.java       |  46 ++-
 .../application/SampleApplicationsTestCase.java | 401 ++++++++++---------
 .../SingleClusterScalingTestCase.java           | 131 +++---
 .../tests/cartridge/CartridgeGroupTestCase.java | 241 +++++++++++
 .../tests/cartridge/CartridgeTestCase.java      | 183 +++++++++
 .../tests/group/CartridgeGroupTestCase.java     | 251 ------------
 .../tests/group/CartridgeTestCase.java          | 183 ---------
 .../tests/iaas/IaaSProviderTestCase.java        |  28 +-
 .../iaas/IaasProviderAttributeTestCase.java     |  61 +--
 .../policies/ApplicationPolicyTestCase.java     | 111 ++---
 .../policies/AutoscalingPolicyTestCase.java     |   5 +-
 .../policies/DeploymentPolicyTestCase.java      |   7 +-
 .../policies/NetworkPartitionTestCase.java      |   7 +-
 .../integration/tests/users/TenantTestCase.java |   8 +-
 .../integration/tests/users/UserTestCase.java   |   5 +-
 24 files changed, 1364 insertions(+), 1481 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 6b3cfc3..8125401 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1795,7 +1795,7 @@
         <maven.compiler.plugin.version>2.3.1</maven.compiler.plugin.version>
         <maven.wagon.ssh.extension.version>2.1</maven.wagon.ssh.extension.version>
         <maven.project.info.reports.plugin.version>2.4</maven.project.info.reports.plugin.version>
-        <maven.surefire.plugin.version>2.18</maven.surefire.plugin.version>
+        <maven.surefire.plugin.version>2.19</maven.surefire.plugin.version>
         <maven.resources.plugin.verison>2.7</maven.resources.plugin.verison>
         <maven.dependency.plugin.version>2.10</maven.dependency.plugin.version>
         <maven.incremental.build.plugin.version>1.3</maven.incremental.build.plugin.version>

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java
index ce1e0c4..b63525c 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationBurstingTestCase.java
@@ -22,24 +22,23 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.application.ApplicationBean;
 import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
-import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
-import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
 /**
  * This will handle the application bursting test cases
  */
+@Test(groups = { "application", "app-burst" })
 public class ApplicationBurstingTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(ApplicationBurstingTestCase.class);
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
     private static final String RESOURCES_PATH = "/application-bursting-test";
     private static final String autoscalingPolicyId = "autoscaling-policy-application-bursting-test";
     private static final String cartridgeId1 = "esb-application-bursting-test";
@@ -52,62 +51,60 @@ public class ApplicationBurstingTestCase extends StratosIntegrationTest {
     private static final String applicationId = "application-bursting-test";
     private static final String applicationPolicyId = "application-policy-application-bursting-test";
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testApplicationBusting() throws Exception {
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
+        log.info("Running ApplicationBurstingTestCase.testApplicationBusting test method...");
+        long startTime = System.currentTimeMillis();
 
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(addedScalingPolicy);
 
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId1 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId1 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC1);
 
-        boolean addedC2 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId2 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC2 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId2 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC2);
 
-        boolean addedC3 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId3 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC3 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId3 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC3);
 
         boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + cartridgeGroupId + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                "/" + cartridgeGroupId + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(addedG1);
 
         CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId,
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
+                getEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId, CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
         assertEquals(beanG1.getName(), cartridgeGroupId);
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartition1 + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartition1 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartition2 + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartition2 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN2);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(addedDep);
 
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        applicationId + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+                applicationId + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         assertTrue(added);
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), applicationId);
 
         boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
@@ -118,13 +115,11 @@ public class ApplicationBurstingTestCase extends StratosIntegrationTest {
         //deploy the application
         String resourcePath = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId;
-        boolean deployed = restClient.deployEntity(resourcePath,
-                RestConstants.APPLICATIONS_NAME);
+        boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
         assertTrue(deployed);
 
         //Application active handling
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(applicationId);
 
         //Group active handling
         topologyHandler.assertGroupActivation(bean.getApplicationId());
@@ -132,29 +127,11 @@ public class ApplicationBurstingTestCase extends StratosIntegrationTest {
         //Cluster active handling
         topologyHandler.assertClusterActivation(bean.getApplicationId());
 
-        boolean removedGroup =
-                restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId,
-                        RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(removedGroup);
-
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertFalse(removedAuto);
-
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartition1, RestConstants.NETWORK_PARTITIONS_NAME);
-        assertFalse(removedNet);
-
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
-        assertFalse(removedDep);
-
         //Un-deploying the application
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
-                RestConstants.APPLICATIONS_NAME);
+        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
         assertTrue(unDeployed);
 
         boolean undeploy = topologyHandler.assertApplicationUndeploy(applicationId);
@@ -166,62 +143,56 @@ public class ApplicationBurstingTestCase extends StratosIntegrationTest {
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = topologyHandler.assertApplicationUndeploy(applicationId);
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    applicationId), forceUndeployed);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId),
+                    forceUndeployed);
 
         }
 
-        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removed = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId, RestConstants.APPLICATIONS_NAME);
         assertTrue(removed);
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertNull(beanRemoved);
 
-        removedGroup =
-                restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId,
-                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        boolean removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(removedGroup);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId1,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId1, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC1);
 
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId2,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId2, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC2);
 
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId3,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId3, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC3);
 
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(removedAuto);
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartition1, RestConstants.NETWORK_PARTITIONS_NAME);
-        assertFalse(removedNet);
-
-        boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartition2, RestConstants.NETWORK_PARTITIONS_NAME);
-        assertFalse(removedN2);
-
-        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removeAppPolicy);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartition1, RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartition1,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         Assert.assertTrue(removedNet);
 
-        removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartition2, RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartition2,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         Assert.assertTrue(removedN2);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("ApplicationBurstingTestCase completed in [duration] %s ms", duration));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationStartupOrderTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationStartupOrderTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationStartupOrderTestCase.java
index bde6b04..cbb222b 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationStartupOrderTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationStartupOrderTestCase.java
@@ -18,21 +18,25 @@
  */
 package org.apache.stratos.integration.tests.application;
 
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.junit.matchers.JUnitMatchers.containsString;
-import static org.testng.AssertJUnit.assertTrue;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
 import org.junit.Rule;
 import org.junit.rules.ExpectedException;
 import org.testng.annotations.Test;
 
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+import static org.testng.AssertJUnit.assertTrue;
+
 /**
  * Handling the startup order of the application
  */
+@Test(groups = { "application" })
 public class ApplicationStartupOrderTestCase extends StratosIntegrationTest {
+    private static final Log log = LogFactory.getLog(ApplicationStartupOrderTestCase.class);
     private static final String RESOURCES_PATH = "/application-startup-order-test";
     private static final String autoscalingPolicyId = "autoscaling-policy-application-startup-order-test";
     private static final String cartridgeId1 = "esb-application-startup-order-test";
@@ -51,133 +55,130 @@ public class ApplicationStartupOrderTestCase extends StratosIntegrationTest {
     @Rule
     public ExpectedException thrown = ExpectedException.none();
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testApplicationStartupOrder() throws Exception {
-    	
-    	thrown.expect(RuntimeException.class);
-    	thrown.expectMessage(
-    			"{\"status\":\"error\",\"message\":\"The startup-order defined in the [application] application-startup-order-test is not correct. [startup-order-alias] group.my-dbgroup3333 is not there in the application.\"}");
+        log.info("Running ApplicationStartupOrderTestCase.testApplicationStartupOrder test method...");
+        long startTime = System.currentTimeMillis();
+
+        thrown.expect(RuntimeException.class);
+        thrown.expectMessage("{\"status\":\"error\",\"message\":\"The startup-order defined in the [application] "
+                + "application-startup-order-test is not correct. [startup-order-alias] group.my-dbgroup3333 "
+                + "is not there in the application.\"}");
 
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(addedScalingPolicy);
 
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId1 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId1 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC1);
 
-        boolean addedC2 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId2 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC2 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId2 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC2);
 
-        boolean addedC3 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId3 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC3 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId3 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC3);
 
-        boolean addedC4 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId4 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC4 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId4 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC4);
 
-        boolean addedC5 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId5 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC5 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId5 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC5);
 
         boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + cartridgeGroupId1 + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                "/" + cartridgeGroupId1 + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(addedG1);
 
         boolean addedG2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + cartridgeGroupId2 + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                "/" + cartridgeGroupId2 + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(addedG2);
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId1 + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId1 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId2 + ".json",
-        RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId2 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN2);
 
         boolean addedDep1 = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId1 + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId1 + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(addedDep1);
 
         boolean addedDep2 = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId2 + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId2 + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(addedDep2);
-            	     			
-    	try {
+
+        try {
             restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                            applicationId + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
-        	fail("Should throw an exception if the aliases mentioned in dependency order section are not defined");
-    	} catch (Exception e) {
-    		assertThat(
-    				e.getMessage(),containsString("The startup-order defined in the [application] application-startup-order-test is not correct. [startup-order-alias] group.my-dbgroup3333 is not there in the application."));
-    	}
-    	// Clean up        
-        boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                cartridgeGroupId1,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                    applicationId + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
+            fail("Should throw an exception if the aliases mentioned in dependency order section are not defined");
+        } catch (Exception e) {
+            assertThat(e.getMessage(), containsString(
+                    "The startup-order defined in the [application] application-startup-order-test is not correct. "
+                            + "[startup-order-alias] group.my-dbgroup3333 is not there in the application."));
+        }
+        // Clean up
+        boolean removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId1, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(removedGroup);
 
-        removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                cartridgeGroupId2,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+        removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId2, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(removedGroup);
 
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertTrue(removedAuto);   
-                
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId1, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
+        assertTrue(removedAuto);
+
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId1,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
-        
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId2, RestConstants.DEPLOYMENT_POLICIES_NAME);
+
+        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId2,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
-        
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1,
+
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1,
                 RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedNet);
-        
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId2,
+
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId2,
                 RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedNet);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId1,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId1, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC1);
-        
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId2,
-                RestConstants.CARTRIDGES_NAME);
+
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId2, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC2);
 
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId3,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId3, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC3);
 
-        boolean removedC4 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId4,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC4 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId4, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC4);
 
-        boolean removedC5 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId5,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC5 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId5, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC5);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("ApplicationStartupOrderTestCase completed in [duration] %s ms", duration));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java
index 0d2c5f7..fcf2573 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/ApplicationUpdateTestCase.java
@@ -23,12 +23,10 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.application.ApplicationBean;
 import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
-import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
 import org.apache.stratos.messaging.domain.application.Application;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
 import org.apache.stratos.messaging.domain.application.Group;
 import org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
@@ -40,7 +38,9 @@ import static junit.framework.Assert.assertTrue;
 /**
  * Sample application tests with application add, .
  */
+@Test(groups = { "application", "app-update" })
 public class ApplicationUpdateTestCase extends StratosIntegrationTest {
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
     private static final Log log = LogFactory.getLog(ApplicationUpdateTestCase.class);
     private static final String RESOURCES_PATH = "/application-update-test";
     private static final String autoscalingPolicyId = "autoscaling-policy-application-update-test";
@@ -55,12 +55,13 @@ public class ApplicationUpdateTestCase extends StratosIntegrationTest {
     private static final String applicationPolicyId = "application-policy-application-update-test";
     private static final String applicationId2 = "g-sc-G123-1-application-update-test-v1";
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testDeployApplication() throws Exception {
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
+        log.info("Running ApplicationUpdateTestCase.testDeployApplication test method...");
+        long startTime = System.currentTimeMillis();
 
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertEquals(addedScalingPolicy, true);
 
@@ -80,37 +81,34 @@ public class ApplicationUpdateTestCase extends StratosIntegrationTest {
         assertEquals(addedC3, true);
 
         boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + cartridgeGroupId + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                "/" + cartridgeGroupId + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertEquals(addedG1, true);
 
         CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId,
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
+                getEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId, CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
         assertEquals(beanG1.getName(), cartridgeGroupId);
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId1 + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId1 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(addedN1, true);
 
         boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId2 + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId2 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(addedN2, true);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertEquals(addedDep, true);
 
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        applicationId1 + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+                applicationId1 + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         assertEquals(added, true);
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId1, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId1, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), applicationId1);
 
         boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
@@ -121,12 +119,11 @@ public class ApplicationUpdateTestCase extends StratosIntegrationTest {
         //deploy the application
         String resourcePath = RestConstants.APPLICATIONS + "/" + applicationId1 +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId;
-        boolean deployed = restClient.deployEntity(resourcePath,
-                RestConstants.APPLICATIONS_NAME);
+        boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
         assertEquals(deployed, true);
 
         //Application active handling
-        topologyHandler.assertApplicationStatus(applicationId1, ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(applicationId1);
 
         //Group active handling
         topologyHandler.assertGroupActivation(applicationId1);
@@ -136,12 +133,12 @@ public class ApplicationUpdateTestCase extends StratosIntegrationTest {
 
         //Updating application
         boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        applicationId2 + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+                applicationId2 + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         assertEquals(updated, true);
 
-        ApplicationBean updatedBean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId1, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean updatedBean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId1, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(updatedBean.getApplicationId(), applicationId1);
 
         //Need to validate whether the updated taken into the applications Topology
@@ -165,29 +162,27 @@ public class ApplicationUpdateTestCase extends StratosIntegrationTest {
 
         topologyHandler.assertClusterMinMemberCount(bean.getApplicationId(), 2);
 
-        boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+        boolean removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertEquals(removedGroup, false);
 
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertEquals(removedAuto, false);
 
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1,
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1,
                 RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(removedNet, false);
 
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertEquals(removedDep, false);
 
         //Un-deploying the application
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId1 +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
-                RestConstants.APPLICATIONS_NAME);
+        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
         assertEquals(unDeployed, true);
 
         boolean undeploy = topologyHandler.assertApplicationUndeploy(applicationId1);
@@ -198,63 +193,65 @@ public class ApplicationUpdateTestCase extends StratosIntegrationTest {
             restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId1 +
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
-            boolean forceUndeployed =
-                    topologyHandler.assertApplicationUndeploy(applicationId1);
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    applicationId1), forceUndeployed);
+            boolean forceUndeployed = topologyHandler.assertApplicationUndeploy(applicationId1);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId1),
+                    forceUndeployed);
 
         }
 
-        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId1,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removed = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId1, RestConstants.APPLICATIONS_NAME);
         assertEquals(removed, true);
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId1, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId1, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(beanRemoved, null);
 
-        removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+        removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertEquals(removedGroup, true);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId1,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId1, RestConstants.CARTRIDGES_NAME);
         assertEquals(removedC1, true);
 
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId2,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId2, RestConstants.CARTRIDGES_NAME);
         assertEquals(removedC2, true);
 
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId3,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId3, RestConstants.CARTRIDGES_NAME);
         assertEquals(removedC3, true);
 
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertEquals(removedAuto, true);
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertEquals(removedDep, true);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1, RestConstants.NETWORK_PARTITIONS_NAME);
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(removedNet, false);
 
-        boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId2, RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId2,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(removedN2, false);
 
-        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertEquals(removeAppPolicy, true);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1, RestConstants.NETWORK_PARTITIONS_NAME);
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(removedNet, true);
 
-        removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId2, RestConstants.NETWORK_PARTITIONS_NAME);
+        removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId2,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(removedN2, true);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("ApplicationBurstingTestCase completed in [duration] %s ms", duration));
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTestCase.java
index 4c7384c..5425339 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupStartupOrderTestCase.java
@@ -24,21 +24,21 @@ import org.apache.stratos.common.beans.application.ApplicationBean;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.testng.annotations.Test;
 
 import java.util.Map;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
-import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
 /**
  * Handling the startup order of the group
  */
+@Test(groups = { "application" })
 public class GroupStartupOrderTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(GroupStartupOrderTestCase.class);
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
     private static final String RESOURCES_PATH = "/group-startup-order-test";
     private static final String autoscalingPolicyId = "autoscaling-policy-group-startup-order-test";
     private static final String esbCartridgeId = "esb-group-startup-order-test";
@@ -54,81 +54,78 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
     private static final String deploymentPolicyId = "deployment-policy-group-startup-order-test";
     private static final String applicationPolicyId = "application-policy-group-startup-order-test";
     private static final String applicationId = "group-startup-order-test";
-    private static final int GROUP_ACTIVE_TIMEOUT = 300000;
-    private static final int NODES_START_PARALLEL_TIMEOUT = 30000;
+    private static final int GROUP_ACTIVE_TIMEOUT = 500000;
+    private static final int NODES_START_PARALLEL_TIMEOUT = 500000;
 
-
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testTerminationBehavior() throws Exception {
+        log.info("Running GroupStartupOrderTestCase.testTerminationBehavior test method...");
+        long startTime = System.currentTimeMillis();
 
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(addedScalingPolicy);
 
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + esbCartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + esbCartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC1);
 
-        boolean addedC2 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + phpCartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC2 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + phpCartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC2);
 
-        boolean addedC3 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + stratosLbCartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC3 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + stratosLbCartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC3);
 
-        boolean addedC5 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcat1CartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC5 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcat1CartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC5);
 
-        boolean addedC6 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcat2CartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC6 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcat2CartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC6);
 
-        boolean addedC7 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcat3CartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC7 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcat3CartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC7);
 
-        boolean addedC8 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcatCartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC8 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + tomcatCartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC8);
 
         boolean addedG2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + cartridgeGroupId1 + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                "/" + cartridgeGroupId1 + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(addedG2);
 
         boolean addedG3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + cartridgeGroupId2 + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                "/" + cartridgeGroupId2 + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(addedG3);
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId1 + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId1 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(addedDep);
 
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        applicationId + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+                applicationId + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         assertTrue(added);
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), applicationId);
 
         boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
@@ -139,23 +136,20 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
         //deploy the application
         String resourcePath = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId;
-        boolean deployed = restClient.deployEntity(resourcePath,
-                RestConstants.APPLICATIONS_NAME);
+        boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
         assertTrue(deployed);
 
-        String group6 = topologyHandler.generateId(bean.getApplicationId(),
-                "my-group6-group-startup-order-test", bean.getApplicationId() + "-1");
+        String group6 = topologyHandler.generateId(bean.getApplicationId(), "my-group6-group-startup-order-test",
+                bean.getApplicationId() + "-1");
 
-        String group8 = topologyHandler.generateId(bean.getApplicationId(),
-                "my-group8-group-startup-order-test", bean.getApplicationId() + "-1");
+        String group8 = topologyHandler.generateId(bean.getApplicationId(), "my-group8-group-startup-order-test",
+                bean.getApplicationId() + "-1");
 
         String lb = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-stratos-lb-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-stratos-lb-group-startup-order-test");
 
         String tomcat = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-tomcat-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-tomcat-group-startup-order-test");
 
         assertCreationOfNodes(lb, tomcat);
 
@@ -165,47 +159,41 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
 
         assertCreationOfNodes(tomcat, group8);
 
-        String group7 = topologyHandler.generateId(bean.getApplicationId(),
-                "my-group7-group-startup-order-test", bean.getApplicationId() + "-1");
+        String group7 = topologyHandler.generateId(bean.getApplicationId(), "my-group7-group-startup-order-test",
+                bean.getApplicationId() + "-1");
 
-        String groupTom2 = topologyHandler.generateId(bean.getApplicationId(),
-                "my-group6-group-tom2-group-startup-order-test", bean.getApplicationId() + "-1");
+        String groupTom2 = topologyHandler
+                .generateId(bean.getApplicationId(), "my-group6-group-tom2-group-startup-order-test",
+                        bean.getApplicationId() + "-1");
 
         assertCreationOfNodesInParallel(group7, groupTom2);
 
         String group7Tomcat = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-group7-tomcat-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-group7-tomcat-group-startup-order-test");
 
         String group7Tomcat1 = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-group7-tomcat1-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-group7-tomcat1-group-startup-order-test");
 
         assertCreationOfNodes(group7Tomcat, group7Tomcat1);
 
         String groupTom2Tomcat2 = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-group-tom2-tomcat2-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-group-tom2-tomcat2-group-startup-order-test");
 
         String groupTom2Tomcat3 = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-group-tom2-tomcat3-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-group-tom2-tomcat3-group-startup-order-test");
 
         assertCreationOfNodes(groupTom2Tomcat2, groupTom2Tomcat3);
 
         String group8Tomcat2 = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-tomcat2-group8-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-tomcat2-group8-group-startup-order-test");
 
         String group8Tomcat = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "my-tomcat-group8-group-startup-order-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "my-tomcat-group8-group-startup-order-test");
 
         assertCreationOfNodesInParallel(group8Tomcat2, group8Tomcat);
 
         //Application active handling
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         //Group active handling
         topologyHandler.assertGroupActivation(bean.getApplicationId());
@@ -213,36 +201,11 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
         //Cluster active handling
         topologyHandler.assertClusterActivation(bean.getApplicationId());
 
-        boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                cartridgeGroupId1,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(removedGroup);
-
-        removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                cartridgeGroupId2,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(removedGroup);
-
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertFalse(removedAuto);
-
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1,
-                RestConstants.NETWORK_PARTITIONS_NAME);
-        //Trying to remove the used network partition
-        assertFalse(removedNet);
-
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
-        assertFalse(removedDep);
-
         //Un-deploying the application
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
-                RestConstants.APPLICATIONS_NAME);
+        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
         assertTrue(unDeployed);
 
         boolean undeploy = topologyHandler.assertApplicationUndeploy(applicationId);
@@ -254,66 +217,65 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = topologyHandler.assertApplicationUndeploy(applicationId);
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    applicationId), forceUndeployed);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId),
+                    forceUndeployed);
 
         }
 
-        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removed = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId, RestConstants.APPLICATIONS_NAME);
         assertTrue(removed);
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertNull(beanRemoved);
 
-        removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                cartridgeGroupId1, RestConstants.CARTRIDGE_GROUPS_NAME);
+        boolean removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId1, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(removedGroup);
 
-        removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                cartridgeGroupId2, RestConstants.CARTRIDGE_GROUPS_NAME);
+        removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, cartridgeGroupId2, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(removedGroup);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, stratosLbCartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, stratosLbCartridgeId, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC1);
 
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES,tomcatCartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, tomcatCartridgeId, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC2);
 
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, tomcat1CartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, tomcat1CartridgeId, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC3);
 
-        boolean removedC4 = restClient.removeEntity(RestConstants.CARTRIDGES, tomcat2CartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC4 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, tomcat2CartridgeId, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC4);
 
-        boolean removedC5 = restClient.removeEntity(RestConstants.CARTRIDGES, tomcat3CartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC5 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, tomcat3CartridgeId, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC5);
 
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(removedAuto);
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1, RestConstants.NETWORK_PARTITIONS_NAME);
-        assertFalse(removedNet);
-
-        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removeAppPolicy);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1, RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedNet);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("GroupStartupOrderTestCase completed in [duration] %s ms", duration));
     }
 
     private void assertCreationOfNodes(String firstNodeId, String secondNodeId) {
@@ -325,8 +287,7 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
         while (!activeMembers.containsKey(firstNodeId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignored) {
+            } catch (InterruptedException ignored) {
             }
             activeMembers = TopologyHandler.getInstance().getActivateddMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_ACTIVE_TIMEOUT) {
@@ -338,8 +299,7 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
         while (!createdMembers.containsKey(secondNodeId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             createdMembers = TopologyHandler.getInstance().getCreatedMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_ACTIVE_TIMEOUT) {
@@ -361,8 +321,7 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
         while (!(createdMembers.containsKey(firstNodeId) && createdMembers.containsKey(firstNodeId))) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignored) {
+            } catch (InterruptedException ignored) {
             }
             createdMembers = TopologyHandler.getInstance().getCreatedMembers();
             if ((System.currentTimeMillis() - startTime) > NODES_START_PARALLEL_TIMEOUT) {
@@ -372,4 +331,4 @@ public class GroupStartupOrderTestCase extends StratosIntegrationTest {
         assertTrue(createdMembers.containsKey(firstNodeId));
         assertTrue(createdMembers.containsKey(firstNodeId));
     }
-}
\ No newline at end of file
+}


[24/28] stratos git commit: Fix formatting. Move acquireRad/WriteLock out of try block.

Posted by ra...@apache.org.
Fix formatting. Move acquireRad/WriteLock out of try block.


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

Branch: refs/heads/stratos-4.1.x
Commit: a9ed3c55f3483142485ae35cb515933d656d5900
Parents: 179120d
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:20:29 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../messaging/topology/TopologyBuilder.java     | 66 +++++++++-----------
 1 file changed, 29 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/a9ed3c55/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
index d0a21d1..109cf30 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java
@@ -69,8 +69,8 @@ public class TopologyBuilder {
         if (cartridgeList == null) {
             throw new RuntimeException("Cartridge list is empty");
         }
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
             for (Cartridge cartridge : cartridgeList) {
                 if (!topology.serviceExists(cartridge.getType())) {
                     ServiceType serviceType = cartridge.isMultiTenant() ?
@@ -126,8 +126,8 @@ public class TopologyBuilder {
                 throw new RuntimeException(String.format("Service %s does not exist", cartridge.getType()));
             }
             if (service.getClusters().size() == 0) {
+                TopologyHolder.acquireWriteLock();
                 try {
-                    TopologyHolder.acquireWriteLock();
                     topology.removeService(cartridge.getType());
                     TopologyHolder.updateTopology(topology);
                 } finally {
@@ -149,8 +149,8 @@ public class TopologyBuilder {
             for (Cluster cluster : appClusters) {
                 Service service = topology.getService(cluster.getServiceName());
                 if (service == null) {
-                    throw new RuntimeException("Service " + cluster.getServiceName()
-                            + " not found in topology, unable to create cluster");
+                    throw new RuntimeException(
+                            "Service " + cluster.getServiceName() + " not found in topology, unable to create cluster");
                 }
                 service.addCluster(cluster);
                 log.info("Cluster created: [cluster] " + cluster.getClusterId());
@@ -312,8 +312,8 @@ public class TopologyBuilder {
             throw new RuntimeException(String.format("Cluster %s does not exist for service %s", ctxt.getClusterId(),
                     ctxt.getCartridgeType()));
         }
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
             Cluster cluster = service.removeCluster(ctxt.getClusterId());
             deploymentPolicy = cluster.getDeploymentPolicyName();
             TopologyHolder.updateTopology(topology);
@@ -344,8 +344,8 @@ public class TopologyBuilder {
         if (cluster.memberExists(memberId)) {
             throw new RuntimeException(String.format("Member %s already exists", memberId));
         }
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
             Member member = new Member(service.getServiceName(), clusterId, memberId, clusterInstanceId,
                     networkPartitionId, partitionId, memberContext.getLoadBalancingIPType(), initTime);
             member.setStatus(MemberStatus.Created);
@@ -396,9 +396,8 @@ public class TopologyBuilder {
         if (member == null) {
             throw new RuntimeException(String.format("Member %s does not exist", memberContext.getMemberId()));
         }
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
-
             // Set instance id returned by the IaaS
             member.setInstanceId(memberContext.getInstanceId());
             // Set ip addresses
@@ -493,9 +492,8 @@ public class TopologyBuilder {
                 throw new RuntimeException(
                         String.format("Member %s does not exist", instanceStartedEvent.getMemberId()));
             }
-
+            TopologyHolder.acquireWriteLock();
             try {
-                TopologyHolder.acquireWriteLock();
                 // try update lifecycle state
                 if (!member.isStateTransitionValid(MemberStatus.Starting)) {
                     log.error("Invalid State Transition from " + member.getStatus() + " to " +
@@ -564,8 +562,8 @@ public class TopologyBuilder {
         // grouping - set grouid
         //TODO
         memberActivatedEvent.setApplicationId(null);
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
             // try update lifecycle state
             if (!member.isStateTransitionValid(MemberStatus.Active)) {
                 log.error("Invalid state transition from [" + member.getStatus() + "] to [" +
@@ -665,9 +663,8 @@ public class TopologyBuilder {
                 instanceReadyToShutdownEvent.getNetworkPartitionId(), instanceReadyToShutdownEvent.getPartitionId());
         //member ReadyToShutDown state change time
         Long timestamp = null;
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
-
             if (!member.isStateTransitionValid(MemberStatus.ReadyToShutDown)) {
                 throw new RuntimeException("Invalid State Transition from " + member.getStatus() + " to " +
                         MemberStatus.ReadyToShutDown);
@@ -723,8 +720,8 @@ public class TopologyBuilder {
                 instanceMaintenanceModeEvent.getServiceName(), instanceMaintenanceModeEvent.getClusterId(),
                 instanceMaintenanceModeEvent.getClusterInstanceId(), instanceMaintenanceModeEvent.getMemberId(),
                 instanceMaintenanceModeEvent.getNetworkPartitionId(), instanceMaintenanceModeEvent.getPartitionId());
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
             // try update lifecycle state
             if (!member.isStateTransitionValid(MemberStatus.In_Maintenance)) {
                 throw new RuntimeException(
@@ -769,15 +766,15 @@ public class TopologyBuilder {
         String clusterAlias = CloudControllerUtil.getAliasFromClusterId(clusterId);
         Member member = cluster.getMember(memberId);
         if (member == null) {
-            throw new RuntimeException((String.format("Member %s does not exist", memberId)));
+            throw new RuntimeException((String.format("Member [member-id] %s does not exist", memberId)));
         }
 
         String clusterInstanceId = member.getClusterInstanceId();
 
         //member terminated time
         Long timestamp = null;
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
             properties = member.getProperties();
             cluster.removeMember(member);
             TopologyHolder.updateTopology(topology);
@@ -804,7 +801,6 @@ public class TopologyBuilder {
 
     public static void handleClusterActivatedEvent(
             ClusterStatusClusterActivatedEvent clusterStatusClusterActivatedEvent) throws RegistryException {
-
         Topology topology = TopologyHolder.getTopology();
         Service service = topology.getService(clusterStatusClusterActivatedEvent.getServiceName());
         //update the status of the cluster
@@ -830,12 +826,10 @@ public class TopologyBuilder {
         ClusterInstanceActivatedEvent clusterInstanceActivatedEvent = new ClusterInstanceActivatedEvent(
                 clusterStatusClusterActivatedEvent.getAppId(), clusterStatusClusterActivatedEvent.getServiceName(),
                 clusterStatusClusterActivatedEvent.getClusterId(), clusterStatusClusterActivatedEvent.getInstanceId());
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
-
             Collection<KubernetesService> kubernetesServices = clusterContext
                     .getKubernetesServices(clusterStatusClusterActivatedEvent.getInstanceId());
-
             if ((kubernetesServices != null) && (kubernetesServices.size() > 0)) {
                 try {
                     // Generate access URLs for kubernetes services
@@ -850,28 +844,28 @@ public class TopologyBuilder {
                                 // Using type URI since only http, https, ftp, file, jar protocols are
                                 // supported in URL
                                 int port = kubernetesService.getPort();
-                                if(cluster.getLoadBalancerIps().size() > 0) {
+                                if (cluster.getLoadBalancerIps().size() > 0) {
                                     // Load balancer ips have been provided, need to use proxy port
                                     port = findProxyPort(applicationId, clusterId, kubernetesService.getPortName());
                                 }
-                                URI accessURL = new URI(kubernetesService.getProtocol(), null, hostname,
-                                        port, null, null, null);
+                                URI accessURL = new URI(kubernetesService.getProtocol(), null, hostname, port, null,
+                                        null, null);
                                 cluster.addAccessUrl(clusterStatusClusterActivatedEvent.getInstanceId(),
                                         accessURL.toString());
                                 clusterInstanceActivatedEvent.addAccessUrl(accessURL.toString());
                             }
                         }
                     }
-                    if(cluster.getLoadBalancerIps().size() == 0) {
+                    if (cluster.getLoadBalancerIps().size() == 0) {
                         // Load balancer ips not given, use node public ips as load balancer ips
                         List<String> nodePublicIpsList = new ArrayList<>();
                         nodePublicIpsList.addAll(nodePublicIps);
                         cluster.setLoadBalancerIps(nodePublicIpsList);
                         clusterInstanceActivatedEvent.setLoadBalancerIps(nodePublicIpsList);
                     }
-                    log.info(String.format("Access URLs generated for kubernetes services: [application] %s " +
-                                    "[cluster] %s [access-urls] %s",
-                            applicationId, clusterId, clusterInstanceActivatedEvent.getAccessUrls()));
+                    log.info(String.format("Access URLs generated for kubernetes services: [application] %s "
+                                    + "[cluster] %s [access-urls] %s", applicationId, clusterId,
+                            clusterInstanceActivatedEvent.getAccessUrls()));
                 } catch (URISyntaxException e) {
                     log.error("Could not generate access URLs for Kubernetes services", e);
                 }
@@ -881,8 +875,8 @@ public class TopologyBuilder {
                             getClusterPortMappings(applicationId, clusterId);
                     for (ClusterPortMapping portMapping : portMappings) {
                         for (String hostname : cluster.getHostNames()) {
-                            URI accessURL = new URI(portMapping.getProtocol(), null, hostname,
-                                    portMapping.getPort(), null, null, null);
+                            URI accessURL = new URI(portMapping.getProtocol(), null, hostname, portMapping.getPort(),
+                                    null, null, null);
                             cluster.addAccessUrl(clusterStatusClusterActivatedEvent.getInstanceId(),
                                     accessURL.toString());
                             clusterInstanceActivatedEvent.addAccessUrl(accessURL.toString());
@@ -924,13 +918,14 @@ public class TopologyBuilder {
     private static int findProxyPort(String applicationId, String clusterId, String portName) {
         List<ClusterPortMapping> portMappings = CloudControllerContext.getInstance().
                 getClusterPortMappings(applicationId, clusterId);
-        for(ClusterPortMapping portMapping : portMappings) {
-            if(portMapping.getName().equals(portName)) {
+        for (ClusterPortMapping portMapping : portMappings) {
+            if (portMapping.getName().equals(portName)) {
                 return portMapping.getProxyPort();
             }
         }
-        throw new RuntimeException(String.format("Port mapping not found: [application] %s [cluster] %s " +
-                        "[port-name] %s", applicationId, clusterId, portName));
+        throw new RuntimeException(
+                String.format("Port mapping not found: [application] %s [cluster] %s " + "[port-name] %s",
+                        applicationId, clusterId, portName));
     }
 
     public static void handleClusterInactivateEvent(ClusterStatusClusterInactivateEvent clusterInactivateEvent)
@@ -953,8 +948,8 @@ public class TopologyBuilder {
         ClusterInstanceInactivateEvent clusterInactivatedEvent1 = new ClusterInstanceInactivateEvent(
                 clusterInactivateEvent.getAppId(), clusterInactivateEvent.getServiceName(),
                 clusterInactivateEvent.getClusterId(), clusterInactivateEvent.getInstanceId());
+        TopologyHolder.acquireWriteLock();
         try {
-            TopologyHolder.acquireWriteLock();
             ClusterInstance context = cluster.getInstanceContexts(clusterInactivateEvent.getInstanceId());
             if (context == null) {
                 throw new RuntimeException("Cluster Instance Context is not found for [cluster] " +
@@ -1024,14 +1019,11 @@ public class TopologyBuilder {
         } finally {
             TopologyHolder.releaseWriteLock();
         }
-
     }
 
     public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event)
             throws RegistryException {
-
         TopologyHolder.acquireWriteLock();
-
         try {
             Topology topology = TopologyHolder.getTopology();
             Cluster cluster = topology.getService(event.getServiceName()).


[07/28] stratos git commit: Formatting cluster status message processors and improving logs

Posted by ra...@apache.org.
Formatting cluster status message processors and improving logs


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

Branch: refs/heads/stratos-4.1.x
Commit: 2b82b91faf9e0a5b7488ed5e68fc9cf62183b8bc
Parents: 6b4be64
Author: Akila Perera <ra...@gmail.com>
Authored: Sun Nov 29 23:55:03 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../ClusterStatusClusterActivatedMessageProcessor.java    | 10 +++++++---
 .../ClusterStatusClusterInactivateMessageProcessor.java   | 10 +++++++---
 ...usterStatusClusterInstanceCreatedMessageProcessor.java | 10 +++++-----
 .../status/ClusterStatusClusterResetMessageProcessor.java | 10 +++++++---
 .../ClusterStatusClusterTerminatedMessageProcessor.java   | 10 +++++++---
 .../ClusterStatusClusterTerminatingMessageProcessor.java  | 10 +++++++---
 6 files changed, 40 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2b82b91f/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterActivatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterActivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterActivatedMessageProcessor.java
index 2815cb5..9b50982 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterActivatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterActivatedMessageProcessor.java
@@ -24,7 +24,6 @@ import org.apache.stratos.messaging.event.cluster.status.ClusterStatusClusterAct
 import org.apache.stratos.messaging.message.processor.MessageProcessor;
 import org.apache.stratos.messaging.util.MessagingUtil;
 
-
 public class ClusterStatusClusterActivatedMessageProcessor extends MessageProcessor {
     private static final Log log = LogFactory.getLog(ClusterStatusClusterActivatedMessageProcessor.class);
     private MessageProcessor nextProcessor;
@@ -42,7 +41,10 @@ public class ClusterStatusClusterActivatedMessageProcessor extends MessageProces
                     jsonToObject(message, ClusterStatusClusterActivatedEvent.class);
 
             if (log.isDebugEnabled()) {
-                log.debug("Received ClusterStatusClusterActivatedEvent: " + event.toString());
+                log.debug(String.format(
+                        "Received ClusterStatusClusterActivatedEvent: [application-id] %s, [cluster-id] %s, "
+                                + "[cluster-instance-id] %s", event.getAppId(), event.getClusterId(),
+                        event.getInstanceId()));
             }
             // Notify event listeners
             notifyEventListeners(event);
@@ -51,7 +53,9 @@ public class ClusterStatusClusterActivatedMessageProcessor extends MessageProces
             if (nextProcessor != null) {
                 return nextProcessor.process(type, message, object);
             } else {
-                throw new RuntimeException(String.format("Failed to process cluster activated message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process cluster activated message using available message processors: [type] %s "
+                                + "[body] %s", type, message));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2b82b91f/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInactivateMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInactivateMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInactivateMessageProcessor.java
index 34f6dfc..b1b1642 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInactivateMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInactivateMessageProcessor.java
@@ -24,7 +24,6 @@ import org.apache.stratos.messaging.event.cluster.status.ClusterStatusClusterIna
 import org.apache.stratos.messaging.message.processor.MessageProcessor;
 import org.apache.stratos.messaging.util.MessagingUtil;
 
-
 public class ClusterStatusClusterInactivateMessageProcessor extends MessageProcessor {
     private static final Log log = LogFactory.getLog(ClusterStatusClusterInactivateMessageProcessor.class);
     private MessageProcessor nextProcessor;
@@ -42,7 +41,10 @@ public class ClusterStatusClusterInactivateMessageProcessor extends MessageProce
                     jsonToObject(message, ClusterStatusClusterInactivateEvent.class);
 
             if (log.isDebugEnabled()) {
-                log.debug("Received ClusterStatusClusterInactivateEvent: " + event.toString());
+                log.debug(String.format(
+                        "Received ClusterStatusClusterInactivateEvent: [application-id] %s, [cluster-id] %s, "
+                                + "[cluster-instance-id] %s", event.getAppId(), event.getClusterId(),
+                        event.getInstanceId()));
             }
             // Notify event listeners
             notifyEventListeners(event);
@@ -51,7 +53,9 @@ public class ClusterStatusClusterInactivateMessageProcessor extends MessageProce
             if (nextProcessor != null) {
                 return nextProcessor.process(type, message, object);
             } else {
-                throw new RuntimeException(String.format("Failed to process cluster activated message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process cluster activated message using available message processors: [type] %s "
+                                + "[body] %s", type, message));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2b82b91f/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInstanceCreatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInstanceCreatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInstanceCreatedMessageProcessor.java
index f9b5705..3eb8ba0 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInstanceCreatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterInstanceCreatedMessageProcessor.java
@@ -24,7 +24,6 @@ import org.apache.stratos.messaging.event.cluster.status.ClusterStatusClusterIns
 import org.apache.stratos.messaging.message.processor.MessageProcessor;
 import org.apache.stratos.messaging.util.MessagingUtil;
 
-
 public class ClusterStatusClusterInstanceCreatedMessageProcessor extends MessageProcessor {
     private static final Log log = LogFactory.getLog(ClusterStatusClusterInstanceCreatedMessageProcessor.class);
     private MessageProcessor nextProcessor;
@@ -41,9 +40,8 @@ public class ClusterStatusClusterInstanceCreatedMessageProcessor extends Message
             ClusterStatusClusterInstanceCreatedEvent event = (ClusterStatusClusterInstanceCreatedEvent) MessagingUtil.
                     jsonToObject(message, ClusterStatusClusterInstanceCreatedEvent.class);
 
-            if (log.isDebugEnabled()) {
-                log.debug("Received ClusterStatusClusterInstanceCreatedEvent: " + event.toString());
-            }
+            log.debug(String.format("Received ClusterStatusClusterInstanceCreatedEvent: [service] %s, [cluster-id] %s, "
+                    + "[cluster-instance-id] %s", event.getServiceName(), event.getClusterId(), event.getInstanceId()));
             // Notify event listeners
             notifyEventListeners(event);
             return true;
@@ -51,7 +49,9 @@ public class ClusterStatusClusterInstanceCreatedMessageProcessor extends Message
             if (nextProcessor != null) {
                 return nextProcessor.process(type, message, object);
             } else {
-                throw new RuntimeException(String.format("Failed to process cluster created message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process cluster created message using available message processors: [type] %s "
+                                + "[body] %s", type, message));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2b82b91f/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterResetMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterResetMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterResetMessageProcessor.java
index de1f7c3..d6044cd 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterResetMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterResetMessageProcessor.java
@@ -24,7 +24,6 @@ import org.apache.stratos.messaging.event.cluster.status.ClusterStatusClusterRes
 import org.apache.stratos.messaging.message.processor.MessageProcessor;
 import org.apache.stratos.messaging.util.MessagingUtil;
 
-
 public class ClusterStatusClusterResetMessageProcessor extends MessageProcessor {
     private static final Log log = LogFactory.getLog(ClusterStatusClusterResetMessageProcessor.class);
     private MessageProcessor nextProcessor;
@@ -42,7 +41,10 @@ public class ClusterStatusClusterResetMessageProcessor extends MessageProcessor
                     jsonToObject(message, ClusterStatusClusterResetEvent.class);
 
             if (log.isDebugEnabled()) {
-                log.debug("Received ClusterStatusClusterResettedEvent: " + event.toString());
+                log.debug(String.format(
+                        "Received ClusterStatusClusterResetEvent: [application-id] %s, [cluster-id] %s, "
+                                + "[cluster-instance-id] %s", event.getAppId(), event.getClusterId(),
+                        event.getInstanceId()));
             }
             // Notify event listeners
             notifyEventListeners(event);
@@ -51,7 +53,9 @@ public class ClusterStatusClusterResetMessageProcessor extends MessageProcessor
             if (nextProcessor != null) {
                 return nextProcessor.process(type, message, object);
             } else {
-                throw new RuntimeException(String.format("Failed to process cluster created message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process cluster created message using available message processors: [type] %s "
+                                + "[body] %s", type, message));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2b82b91f/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatedMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatedMessageProcessor.java
index fca96f2..c027031 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatedMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatedMessageProcessor.java
@@ -25,7 +25,6 @@ import org.apache.stratos.messaging.message.processor.MessageProcessor;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 import org.apache.stratos.messaging.util.MessagingUtil;
 
-
 public class ClusterStatusClusterTerminatedMessageProcessor extends MessageProcessor {
     private static final Log log = LogFactory.getLog(ClusterStatusClusterTerminatedMessageProcessor.class);
     private MessageProcessor nextProcessor;
@@ -43,7 +42,10 @@ public class ClusterStatusClusterTerminatedMessageProcessor extends MessageProce
                     jsonToObject(message, ClusterStatusClusterTerminatedEvent.class);
 
             if (log.isDebugEnabled()) {
-                log.debug("Received ClusterStatusClusterTerminatedEvent: " + event.toString());
+                log.debug(String.format(
+                        "Received ClusterStatusClusterTerminatedEvent: [application-id] %s, [cluster-id] %s, "
+                                + "[cluster-instance-id] %s", event.getAppId(), event.getClusterId(),
+                        event.getInstanceId()));
             }
 
             TopologyManager.getTopology().removeFromClusterMap(event.getClusterId());
@@ -54,7 +56,9 @@ public class ClusterStatusClusterTerminatedMessageProcessor extends MessageProce
             if (nextProcessor != null) {
                 return nextProcessor.process(type, message, object);
             } else {
-                throw new RuntimeException(String.format("Failed to process cluster activated message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process cluster activated message using available message processors: [type] %s "
+                                + "[body] %s", type, message));
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/2b82b91f/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatingMessageProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatingMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatingMessageProcessor.java
index 37cc77f..0ff8417 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatingMessageProcessor.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusClusterTerminatingMessageProcessor.java
@@ -24,7 +24,6 @@ import org.apache.stratos.messaging.event.cluster.status.ClusterStatusClusterTer
 import org.apache.stratos.messaging.message.processor.MessageProcessor;
 import org.apache.stratos.messaging.util.MessagingUtil;
 
-
 public class ClusterStatusClusterTerminatingMessageProcessor extends MessageProcessor {
     private static final Log log = LogFactory.getLog(ClusterStatusClusterTerminatingMessageProcessor.class);
     private MessageProcessor nextProcessor;
@@ -42,7 +41,10 @@ public class ClusterStatusClusterTerminatingMessageProcessor extends MessageProc
                     jsonToObject(message, ClusterStatusClusterTerminatingEvent.class);
 
             if (log.isDebugEnabled()) {
-                log.debug("Received ClusterStatusClusterTerminatingEvent: " + event.toString());
+                log.debug(String.format(
+                        "Received ClusterStatusClusterTerminatingEvent: [application-id] %s, [cluster-id] %s, "
+                                + "[cluster-instance-id] %s", event.getAppId(), event.getClusterId(),
+                        event.getInstanceId()));
             }
             // Notify event listeners
             notifyEventListeners(event);
@@ -51,7 +53,9 @@ public class ClusterStatusClusterTerminatingMessageProcessor extends MessageProc
             if (nextProcessor != null) {
                 return nextProcessor.process(type, message, object);
             } else {
-                throw new RuntimeException(String.format("Failed to process cluster activated message using available message processors: [type] %s [body] %s", type, message));
+                throw new RuntimeException(String.format(
+                        "Failed to process cluster terminating message using available message processors: [type] %s "
+                                + "[body] %s", type, message));
             }
         }
     }


[09/28] stratos git commit: Introduced assertApplicationActiveStatus and assertApplicationInActiveStatus methods which use thread synchronization with topology receivers to assert application status. Added log messages for each method to help troubleshoo

Posted by ra...@apache.org.
Introduced assertApplicationActiveStatus and assertApplicationInActiveStatus methods which use thread synchronization with topology receivers to assert application status. Added log messages for each method to help troubleshoot test failures.


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

Branch: refs/heads/stratos-4.1.x
Commit: d58701195805ce319002e4f6b9a47d289999a959
Parents: 6b5b847
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:10:47 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../integration/common/TopologyHandler.java     | 511 +++++++++++++------
 1 file changed, 355 insertions(+), 156 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/d5870119/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java
index 209ad13..a0cc928 100644
--- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/TopologyHandler.java
@@ -30,13 +30,16 @@ import org.apache.stratos.messaging.domain.topology.MemberStatus;
 import org.apache.stratos.messaging.domain.topology.Service;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.application.*;
+import org.apache.stratos.messaging.event.health.stat.MemberFaultEvent;
 import org.apache.stratos.messaging.event.topology.*;
 import org.apache.stratos.messaging.listener.application.*;
+import org.apache.stratos.messaging.listener.health.stat.MemberFaultEventListener;
 import org.apache.stratos.messaging.listener.topology.*;
 import org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
 import org.apache.stratos.messaging.message.receiver.application.ApplicationsEventReceiver;
 import org.apache.stratos.messaging.message.receiver.application.signup.ApplicationSignUpEventReceiver;
 import org.apache.stratos.messaging.message.receiver.application.signup.ApplicationSignUpManager;
+import org.apache.stratos.messaging.message.receiver.health.stat.HealthStatEventReceiver;
 import org.apache.stratos.messaging.message.receiver.tenant.TenantEventReceiver;
 import org.apache.stratos.messaging.message.receiver.tenant.TenantManager;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
@@ -47,6 +50,7 @@ import java.rmi.RemoteException;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
 
 import static org.testng.AssertJUnit.*;
 
@@ -54,30 +58,32 @@ import static org.testng.AssertJUnit.*;
  * To start the Topology receivers
  */
 public class TopologyHandler {
-    private static final Log log = LogFactory.getLog(TopologyHandler.class);
-
-    public static final int APPLICATION_ACTIVATION_TIMEOUT = 500000;
-    public static final int APPLICATION_UNDEPLOYMENT_TIMEOUT = 500000;
-    public static final int MEMBER_TERMINATION_TIMEOUT = 500000;
-    public static final int APPLICATION_INIT_TIMEOUT = 20000;
+    public static final int APPLICATION_ACTIVATION_TIMEOUT = 300000;
+    public static final int APPLICATION_INACTIVATION_TIMEOUT = 120000;
+    public static final int APPLICATION_UNDEPLOYMENT_TIMEOUT = 30000;
+    public static final int MEMBER_TERMINATION_TIMEOUT = 120000;
+    public static final int APPLICATION_TOPOLOGY_INIT_TIMEOUT = 20000;
     public static final int TENANT_INIT_TIMEOUT = 20000;
     public static final int APPLICATION_SIGNUP_INIT_TIMEOUT = 20000;
     public static final int TOPOLOGY_INIT_TIMEOUT = 20000;
     public static final String APPLICATION_STATUS_CREATED = "Created";
     public static final String APPLICATION_STATUS_UNDEPLOYING = "Undeploying";
+    private static final Log log = LogFactory.getLog(TopologyHandler.class);
+    public static TopologyHandler topologyHandler;
+    private HealthStatEventReceiver healthStatEventReceiver;
     private ApplicationsEventReceiver applicationsEventReceiver;
     private TopologyEventReceiver topologyEventReceiver;
     private TenantEventReceiver tenantEventReceiver;
     private ApplicationSignUpEventReceiver applicationSignUpEventReceiver;
-    public static TopologyHandler topologyHandler;
-    private ExecutorService executorService = StratosThreadPool.getExecutorService("stratos.integration.test.pool", 10);
-    private Map<String, Long> terminatedMembers = new ConcurrentHashMap<String, Long>();
-    private Map<String, Long> terminatingMembers = new ConcurrentHashMap<String, Long>();
+    private ExecutorService executorService = StratosThreadPool.getExecutorService("stratos.integration.test.pool", 30);
+    private Map<String, Long> terminatedMembers = new ConcurrentHashMap<>();
+    private Map<String, Long> terminatingMembers = new ConcurrentHashMap<>();
     private Map<String, Long> createdMembers = new ConcurrentHashMap<String, Long>();
     private Map<String, Long> inActiveMembers = new ConcurrentHashMap<String, Long>();
     private Map<String, Long> activateddMembers = new ConcurrentHashMap<String, Long>();
 
     private TopologyHandler() {
+        initializeHealthStatsEventReceiver();
         initializeApplicationEventReceiver();
         initializeTopologyEventReceiver();
         initializeTenantEventReceiver();
@@ -90,6 +96,17 @@ public class TopologyHandler {
         addApplicationEventListeners();
     }
 
+    public static TopologyHandler getInstance() {
+        if (topologyHandler == null) {
+            synchronized (TopologyHandler.class) {
+                if (topologyHandler == null) {
+                    topologyHandler = new TopologyHandler();
+                }
+            }
+        }
+        return topologyHandler;
+    }
+
     private void initializeApplicationSignUpEventReceiver() {
         applicationSignUpEventReceiver = new ApplicationSignUpEventReceiver();
         applicationSignUpEventReceiver.setExecutorService(executorService);
@@ -102,15 +119,21 @@ public class TopologyHandler {
         tenantEventReceiver.execute();
     }
 
-    public static TopologyHandler getInstance() {
-        if (topologyHandler == null) {
-            synchronized (TopologyHandler.class) {
-                if (topologyHandler == null) {
-                    topologyHandler = new TopologyHandler();
-                }
+    /**
+     * Initialize application event receiver
+     */
+    private void initializeHealthStatsEventReceiver() {
+        healthStatEventReceiver = new HealthStatEventReceiver();
+        healthStatEventReceiver.setExecutorService(executorService);
+        healthStatEventReceiver.addEventListener(new MemberFaultEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                MemberFaultEvent memberFaultEvent = (MemberFaultEvent) event;
+                log.info(String.format("MemberFaultEvent received for member [member-id] %s",
+                        memberFaultEvent.getMemberId()));
             }
-        }
-        return topologyHandler;
+        });
+        healthStatEventReceiver.execute();
     }
 
     /**
@@ -119,6 +142,28 @@ public class TopologyHandler {
     private void initializeApplicationEventReceiver() {
         applicationsEventReceiver = new ApplicationsEventReceiver();
         applicationsEventReceiver.setExecutorService(executorService);
+        applicationsEventReceiver.addEventListener(new ApplicationInstanceActivatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                ApplicationInstanceActivatedEvent appInstanceActivatedEvent = (ApplicationInstanceActivatedEvent) event;
+                log.info(String.format(
+                        "ApplicationInstanceActivatedEvent received for application [application-id] %s [instance-id]"
+                                + " %s", appInstanceActivatedEvent.getAppId(),
+                        appInstanceActivatedEvent.getInstanceId()));
+            }
+        });
+
+        applicationsEventReceiver.addEventListener(new ApplicationInstanceInactivatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                ApplicationInstanceInactivatedEvent appInstanceInactivatedEvent
+                        = (ApplicationInstanceInactivatedEvent) event;
+                log.info(String.format(
+                        "ApplicationInstanceInactivatedEvent received for application [application-id] %s "
+                                + "[instance-id] %s", appInstanceInactivatedEvent.getAppId(),
+                        appInstanceInactivatedEvent.getInstanceId()));
+            }
+        });
         applicationsEventReceiver.execute();
     }
 
@@ -128,6 +173,39 @@ public class TopologyHandler {
     private void initializeTopologyEventReceiver() {
         topologyEventReceiver = new TopologyEventReceiver();
         topologyEventReceiver.setExecutorService(executorService);
+        topologyEventReceiver.addEventListener(new MemberActivatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                MemberActivatedEvent memberActivatedEvent = (MemberActivatedEvent) event;
+                log.info(String.format("MemberActivatedEvent received for member [member-id] %s",
+                        memberActivatedEvent.getMemberId()));
+            }
+        });
+
+        topologyEventReceiver.addEventListener(new MemberTerminatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                MemberTerminatedEvent memberTerminatedEvent = (MemberTerminatedEvent) event;
+                log.info(String.format("MemberTerminatedEvent received for member [member-id] %s",
+                        memberTerminatedEvent.getMemberId()));
+            }
+        });
+        topologyEventReceiver.addEventListener(new ClusterInstanceActivatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                ClusterInstanceActivatedEvent clusterInstanceActivatedEvent = (ClusterInstanceActivatedEvent) event;
+                log.info(String.format("ClusterInstanceActivatedEvent received for cluster [cluster-id] %s",
+                        clusterInstanceActivatedEvent.getClusterId()));
+            }
+        });
+        topologyEventReceiver.addEventListener(new ClusterInstanceInactivateEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                ClusterInstanceInactivateEvent clusterInstanceInactivateEvent = (ClusterInstanceInactivateEvent) event;
+                log.info(String.format("MemberTerminatedEvent received for cluster [cluster-id] %s",
+                        clusterInstanceInactivateEvent.getClusterId()));
+            }
+        });
         topologyEventReceiver.execute();
     }
 
@@ -135,26 +213,22 @@ public class TopologyHandler {
      * Assert application Topology initialization
      */
     private void assertApplicationTopologyInitialized() {
-        log.info(String.format("Asserting application topology initialization within %d ms", APPLICATION_INIT_TIMEOUT));
+        log.info(String.format("Asserting application topology initialization within %d ms",
+                APPLICATION_TOPOLOGY_INIT_TIMEOUT));
         long startTime = System.currentTimeMillis();
-        boolean applicationTopologyInitialized = ApplicationManager.getApplications().isInitialized();
-        while (!applicationTopologyInitialized) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            applicationTopologyInitialized = ApplicationManager.getApplications().isInitialized();
-            if ((System.currentTimeMillis() - startTime) > APPLICATION_INIT_TIMEOUT) {
+        while (!ApplicationManager.getApplications().isInitialized()) {
+            log.info("Waiting for application topology to be initialized...");
+            sleep(1000);
+            if ((System.currentTimeMillis() - startTime) > APPLICATION_TOPOLOGY_INIT_TIMEOUT) {
                 break;
             }
         }
-        if (applicationTopologyInitialized) {
+        if (ApplicationManager.getApplications().isInitialized()) {
             log.info(String.format("Application topology initialized under %d ms",
                     (System.currentTimeMillis() - startTime)));
         }
-        assertEquals(
-                String.format("Application topology didn't get initialized within %d ms", APPLICATION_INIT_TIMEOUT),
-                applicationTopologyInitialized, true);
+        assertTrue(String.format("Application topology didn't get initialized within %d ms",
+                APPLICATION_TOPOLOGY_INIT_TIMEOUT), ApplicationManager.getApplications().isInitialized());
     }
 
     /**
@@ -163,102 +237,208 @@ public class TopologyHandler {
     private void assertTopologyInitialized() {
         log.info(String.format("Asserting topology initialization within %d ms", TOPOLOGY_INIT_TIMEOUT));
         long startTime = System.currentTimeMillis();
-        boolean topologyInitialized = TopologyManager.getTopology().isInitialized();
-        while (!topologyInitialized) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            topologyInitialized = TopologyManager.getTopology().isInitialized();
+        while (!TopologyManager.getTopology().isInitialized()) {
+            log.info("Waiting for topology to be initialized...");
+            sleep(1000);
             if ((System.currentTimeMillis() - startTime) > TOPOLOGY_INIT_TIMEOUT) {
                 break;
             }
         }
-        if (topologyInitialized) {
+        if (TopologyManager.getTopology().isInitialized()) {
             log.info(String.format("Topology initialized under %d ms", (System.currentTimeMillis() - startTime)));
         }
-        assertEquals(String.format("Topology didn't get initialized within %d ms", TOPOLOGY_INIT_TIMEOUT),
-                topologyInitialized, true);
+        assertTrue(String.format("Topology didn't get initialized within %d ms", TOPOLOGY_INIT_TIMEOUT),
+                TopologyManager.getTopology().isInitialized());
     }
 
     private void assertTenantInitialized() {
         log.info(String.format("Asserting tenant model initialization within %d ms", TENANT_INIT_TIMEOUT));
         long startTime = System.currentTimeMillis();
-        boolean tenantInitialized = TenantManager.getInstance().isInitialized();
-        while (!tenantInitialized) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            tenantInitialized = TenantManager.getInstance().isInitialized();
+        while (!TenantManager.getInstance().isInitialized()) {
+            log.info("Waiting for tenant model to be initialized...");
+            sleep(1000);
             if ((System.currentTimeMillis() - startTime) > TENANT_INIT_TIMEOUT) {
                 break;
             }
         }
-        if (tenantInitialized) {
+        if (TenantManager.getInstance().isInitialized()) {
             log.info(String.format("Tenant model initialized under %d ms", (System.currentTimeMillis() - startTime)));
         }
-        assertEquals(String.format("Tenant model didn't get initialized within %d ms", TENANT_INIT_TIMEOUT),
-                tenantInitialized, true);
+        assertTrue(String.format("Tenant model didn't get initialized within %d ms", TENANT_INIT_TIMEOUT),
+                TenantManager.getInstance().isInitialized());
     }
 
     private void assertApplicationSignUpInitialized() {
         log.info(String.format("Asserting application signup initialization within %d ms",
                 APPLICATION_SIGNUP_INIT_TIMEOUT));
         long startTime = System.currentTimeMillis();
-        boolean applicationSignUpInitialized = ApplicationSignUpManager.getInstance().isInitialized();
-        while (!applicationSignUpInitialized) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            applicationSignUpInitialized = ApplicationSignUpManager.getInstance().isInitialized();
+        while (!ApplicationSignUpManager.getInstance().isInitialized()) {
+            log.info("Waiting for application signup model to be initialized...");
+            sleep(1000);
             if ((System.currentTimeMillis() - startTime) > APPLICATION_SIGNUP_INIT_TIMEOUT) {
                 break;
             }
         }
-        if (applicationSignUpInitialized) {
+        if (ApplicationSignUpManager.getInstance().isInitialized()) {
             log.info(String.format("Application signup initialized under %d ms",
                     (System.currentTimeMillis() - startTime)));
         }
-        assertEquals(String.format("Application signup didn't get initialized within %d ms",
-                APPLICATION_SIGNUP_INIT_TIMEOUT), applicationSignUpInitialized, true);
+        assertTrue(String.format("Application signup didn't get initialized within %d ms",
+                APPLICATION_SIGNUP_INIT_TIMEOUT), ApplicationSignUpManager.getInstance().isInitialized());
     }
 
     /**
-     * Assert application activation
+     * Assert application Active status
      *
-     * @param applicationName
+     * @param applicationId
      */
-    public void assertApplicationStatus(String applicationName, ApplicationStatus status) {
-        long startTime = System.currentTimeMillis();
-        Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        while (!((application != null) && (application.getStatus() == status))) {
-            try {
-                log.info(String.format("Waiting for [application] %s to become [status] %s...", applicationName,
-                        status));
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
-            }
-            application = ApplicationManager.getApplications().getApplication(applicationName);
-            if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
-                log.error("Application did not activate within timeout period");
-                break;
+    public void assertApplicationActiveStatus(final String applicationId) throws InterruptedException {
+        log.info(String.format("Asserting application status ACTIVE for [application-id] %s...", applicationId));
+        final long startTime = System.currentTimeMillis();
+        final Object synObject = new Object();
+        ApplicationInstanceActivatedEventListener activatedEventListener
+                = new ApplicationInstanceActivatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                ApplicationInstanceActivatedEvent activatedEvent = (ApplicationInstanceActivatedEvent) event;
+                Application application = ApplicationManager.getApplications().getApplication(applicationId);
+                if (application == null) {
+                    log.warn(String.format("Application is null: [application-id] %s, [instance-id] %s", applicationId,
+                            activatedEvent.getInstanceId()));
+                }
+                if (application != null && application.getStatus() == ApplicationStatus.Active) {
+                    synchronized (synObject) {
+                        synObject.notify();
+                    }
+                }
             }
+        };
+        applicationsEventReceiver.addEventListener(activatedEventListener);
+
+        Future future = executorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                Application application = ApplicationManager.getApplications().getApplication(applicationId);
+                while (!((application != null) && (application.getStatus() == ApplicationStatus.Active))) {
+                    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
+                        log.error(String.format("Application [application-id] %s did not activate within [timeout] %d",
+                                applicationId, APPLICATION_ACTIVATION_TIMEOUT));
+                        break;
+                    }
+                    ApplicationStatus currentStatus = (application != null) ? application.getStatus() : null;
+                    log.info(String.format(
+                            "Waiting for [application-id] %s [current-status] %s to become [status] %s...",
+                            applicationId, currentStatus, ApplicationStatus.Active));
+                    sleep(10000);
+                    application = ApplicationManager.getApplications().getApplication(applicationId);
+                }
+                synchronized (synObject) {
+                    synObject.notify();
+                }
+            }
+        });
+
+        synchronized (synObject) {
+            synObject.wait();
+            future.cancel(true);
+            applicationsEventReceiver.removeEventListener(activatedEventListener);
         }
-        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
-        assertEquals(String.format("Application status did not change to %s: [application-id] %s", status.toString(),
-                applicationName), status, application.getStatus());
+
+        Application application = ApplicationManager.getApplications().getApplication(applicationId);
+        ApplicationStatus currentStatus = (application != null) ? application.getStatus() : null;
+        log.info(
+                String.format("Assert application active status for [application-id] %s [current-status] %s took %d ms",
+                        applicationId, currentStatus, System.currentTimeMillis() - startTime));
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationId), application);
+        assertEquals(
+                String.format("Application status did not change to %s: [application-id] %s", ApplicationStatus.Active,
+                        applicationId), ApplicationStatus.Active, application.getStatus());
+    }
+
+    /**
+     * Assert application Inactive status within default timeout
+     *
+     * @param applicationId
+     */
+    public void assertApplicationInActiveStatus(final String applicationId) throws InterruptedException {
+        assertApplicationInActiveStatus(applicationId, APPLICATION_INACTIVATION_TIMEOUT);
+    }
+
+    /**
+     * Assert application Inactive status
+     *
+     * @param applicationId
+     * @param timeout
+     */
+    public void assertApplicationInActiveStatus(final String applicationId, final int timeout)
+            throws InterruptedException {
+        log.info(
+                String.format("Asserting application status INACTIVE for [application-id] %s within [timeout] %d ms...",
+                        applicationId, timeout));
+        final long startTime = System.currentTimeMillis();
+        final Object synObject = new Object();
+        ApplicationInstanceInactivatedEventListener inactivatedEventListener
+                = new ApplicationInstanceInactivatedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                Application application = ApplicationManager.getApplications().getApplication(applicationId);
+                if (application == null || application.getStatus() == ApplicationStatus.Inactive) {
+                    synchronized (synObject) {
+                        synObject.notify();
+                    }
+                }
+            }
+        };
+        applicationsEventReceiver.addEventListener(inactivatedEventListener);
+
+        Future future = executorService.submit(new Runnable() {
+            @Override
+            public void run() {
+                Application application = ApplicationManager.getApplications().getApplication(applicationId);
+                while (!((application != null) && (application.getStatus() == ApplicationStatus.Inactive))) {
+                    if ((System.currentTimeMillis() - startTime) > timeout) {
+                        log.error(String.format(
+                                "Application [application-id] %s did not become inactive within [timeout] %d",
+                                applicationId, timeout));
+                        break;
+                    }
+                    ApplicationStatus currentStatus = (application != null) ? application.getStatus() : null;
+                    log.info(String.format(
+                            "Waiting for [application-id] %s [current-status] %s to become [status] %s...",
+                            applicationId, currentStatus, ApplicationStatus.Inactive));
+                    sleep(10000);
+                    application = ApplicationManager.getApplications().getApplication(applicationId);
+                }
+                synchronized (synObject) {
+                    synObject.notify();
+                }
+            }
+        });
+
+        synchronized (synObject) {
+            synObject.wait();
+            future.cancel(true);
+            applicationsEventReceiver.removeEventListener(inactivatedEventListener);
+        }
+        Application application = ApplicationManager.getApplications().getApplication(applicationId);
+        ApplicationStatus currentStatus = (application != null) ? application.getStatus() : null;
+        log.info(String.format(
+                "Assert application inactive status for [application-id] %s [current-status] %s took %d ms",
+                applicationId, currentStatus, System.currentTimeMillis() - startTime));
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationId), application);
+        assertEquals(String.format("Application status did not change to %s: [application-id] %s",
+                ApplicationStatus.Inactive, applicationId), ApplicationStatus.Inactive, application.getStatus());
     }
 
     /**
      * Assert application activation
      *
-     * @param applicationName
+     * @param applicationId
      */
-    public void assertGroupActivation(String applicationName) {
-        Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
+    public void assertGroupActivation(String applicationId) {
+        log.info(String.format("Asserting group status ACTIVE for [application-id] %s...", applicationId));
+        Application application = ApplicationManager.getApplications().getApplication(applicationId);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationId), application);
 
         Collection<Group> groups = application.getAllGroupsRecursively();
         for (Group group : groups) {
@@ -269,23 +449,25 @@ public class TopologyHandler {
     /**
      * Assert application activation
      *
-     * @param applicationName
+     * @param applicationId
      */
-    public void assertClusterActivation(String applicationName) {
-        Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
+    public void assertClusterActivation(String applicationId) {
+        log.info(String.format("Asserting cluster status ACTIVE for [application-id] %s...", applicationId));
+        Application application = ApplicationManager.getApplications().getApplication(applicationId);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationId), application);
 
         Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
         for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
             String serviceName = clusterDataHolder.getServiceType();
             String clusterId = clusterDataHolder.getClusterId();
             Service service = TopologyManager.getTopology().getService(serviceName);
-            assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName,
-                    serviceName), service);
+            assertNotNull(
+                    String.format("Service is not found: [application-id] %s [service] %s", applicationId, serviceName),
+                    service);
 
             Cluster cluster = service.getCluster(clusterId);
             assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
-                    applicationName, serviceName, clusterId), cluster);
+                    applicationId, serviceName, clusterId), cluster);
             for (Member member : cluster.getMembers()) {
                 log.info(String.format("Member [member-id] %s found in cluster instance [cluster-instance] %s of "
                                 + "cluster [cluster-id] %s", member.getMemberId(), member.getClusterInstanceId(),
@@ -351,17 +533,22 @@ public class TopologyHandler {
      * @param mockIaasApiClient
      */
     public void terminateMemberInMockIaas(String memberId, MockIaasApiClient mockIaasApiClient) {
-        boolean memberTerminated = false;
-        memberTerminated = mockIaasApiClient.terminateInstance(memberId);
+        boolean memberTerminated = mockIaasApiClient.terminateInstance(memberId);
+        log.info(String.format("Terminating mock instance via Mock API client: [member-id] %s", memberId));
         assertTrue(String.format("Member [member-id] %s couldn't be terminated from the mock IaaS", memberId),
                 memberTerminated);
     }
 
     public void assertMemberTermination(String memberId) {
+        log.info(String.format("Asserting member termination for [member-id] %s", memberId));
         long startTime = System.currentTimeMillis();
-        assertNotNull(String.format("Member id is not found: [member-id] %s", memberId));
+        assertNotNull("Member id cannot be null", memberId);
         boolean hasMemberRemoved = false;
         while (!hasMemberRemoved) {
+            if (System.currentTimeMillis() - startTime > MEMBER_TERMINATION_TIMEOUT) {
+                log.error("Member did not get removed from the topology within timeout period");
+                break;
+            }
             // Wait until the member gets removed by MemberTerminatedEvent topology receiver
             if (getTerminatingMembers().get(memberId) == null &&
                     getInActiveMembers().get(memberId) == null &&
@@ -369,39 +556,34 @@ public class TopologyHandler {
                     getCreatedMembers().get(memberId) == null) {
                 getTerminatedMembers().remove(memberId);
                 hasMemberRemoved = true;
-            } else {
-                if (getTerminatedMembers().get(memberId) - startTime > MEMBER_TERMINATION_TIMEOUT) {
-                    log.error("Member did not get removed from the topology within timeout period");
-                    break;
-                }
-            }
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException e) {
-                log.error("Could not sleep", e);
             }
+            log.info(String.format("Waiting for [member-id] %s to be terminated...", memberId));
+            sleep(2000);
         }
+        log.info(String.format("Assert member termination for [member-id] %s took %d ms", memberId,
+                System.currentTimeMillis() - startTime));
         assertTrue(String.format("Member [member-id] %s did not get removed from the topology", memberId),
                 hasMemberRemoved);
     }
 
-    public void assertClusterMinMemberCount(String applicationName, int minMembers) {
+    public void assertClusterMinMemberCount(String applicationId, int minMembers) {
+        log.info(String.format("Asserting cluster min member count for [application-id] %s...", applicationId));
         long startTime = System.currentTimeMillis();
-
-        Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
+        Application application = ApplicationManager.getApplications().getApplication(applicationId);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationId), application);
 
         Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
         for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
             String serviceName = clusterDataHolder.getServiceType();
             String clusterId = clusterDataHolder.getClusterId();
             Service service = TopologyManager.getTopology().getService(serviceName);
-            assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName,
-                    serviceName), service);
+            assertNotNull(
+                    String.format("Service is not found: [application-id] %s [service] %s", applicationId, serviceName),
+                    service);
 
             Cluster cluster = service.getCluster(clusterId);
             assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
-                    applicationName, serviceName, clusterId), cluster);
+                    applicationId, serviceName, clusterId), cluster);
             boolean clusterActive = false;
 
             for (ClusterInstance instance : cluster.getInstanceIdToInstanceContextMap().values()) {
@@ -416,14 +598,15 @@ public class TopologyHandler {
                 clusterActive = activeInstances >= minMembers;
 
                 while (!clusterActive) {
-                    try {
-                        Thread.sleep(1000);
-                    } catch (InterruptedException ignore) {
+                    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
+                        log.error("Cluster did not activate within timeout period");
+                        break;
                     }
+                    log.info(String.format("Waiting for [application-id] %s to be terminated...", applicationId));
+                    sleep(2000);
                     service = TopologyManager.getTopology().getService(serviceName);
-                    assertNotNull(
-                            String.format("Service is not found: [application-id] %s [service] %s", applicationName,
-                                    serviceName), service);
+                    assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationId,
+                            serviceName), service);
 
                     cluster = service.getCluster(clusterId);
                     activeInstances = 0;
@@ -437,14 +620,11 @@ public class TopologyHandler {
                     clusterActive = activeInstances >= minMembers;
                     assertNotNull(
                             String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
-                                    applicationName, serviceName, clusterId), cluster);
-
-                    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
-                        log.error("Cluster did not activate within timeout period");
-                        break;
-                    }
+                                    applicationId, serviceName, clusterId), cluster);
                 }
             }
+            log.info(String.format("Assert cluster min member count [cluster-id] %s took %d ms", clusterId,
+                    System.currentTimeMillis() - startTime));
             assertEquals(String.format("Cluster status did not change to active: [cluster-id] %s", clusterId),
                     clusterActive, true);
         }
@@ -454,46 +634,52 @@ public class TopologyHandler {
     /**
      * Assert application activation
      *
-     * @param applicationName
+     * @param applicationId
      */
-    public boolean assertApplicationUndeploy(String applicationName) {
+    public boolean assertApplicationUndeploy(String applicationId) {
+        log.info(String.format("Asserting application undeploy for [application-id] %s...", applicationId));
         long startTime = System.currentTimeMillis();
-        Application application = ApplicationManager.getApplications().getApplication(applicationName);
+        Application application = ApplicationManager.getApplications().getApplication(applicationId);
         ApplicationContext applicationContext = null;
         try {
-            applicationContext = AutoscalerServiceClient.getInstance().getApplication(applicationName);
+            applicationContext = AutoscalerServiceClient.getInstance().getApplication(applicationId);
         } catch (RemoteException e) {
-            log.error("Error while getting the application context for [application] " + applicationName);
+            log.error(
+                    String.format("Error while getting the application context for [application-id] %s", applicationId),
+                    e);
         }
         while (((application != null) && application.getInstanceContextCount() > 0) || (applicationContext == null
                 || applicationContext.getStatus().equals(APPLICATION_STATUS_UNDEPLOYING))) {
-            try {
-                Thread.sleep(1000);
-            } catch (InterruptedException ignore) {
+            if ((System.currentTimeMillis() - startTime) > APPLICATION_UNDEPLOYMENT_TIMEOUT) {
+                log.error(String.format("Application [application-id] %s did not undeploy within timeout period",
+                        applicationId));
+                break;
             }
-            application = ApplicationManager.getApplications().getApplication(applicationName);
+            String currentStatus = (applicationContext != null) ? applicationContext.getStatus() : null;
+            log.info(String.format("Waiting for [application-id] %s [current-status] %s to be undeployed...",
+                    applicationId, currentStatus));
+            sleep(2000);
+            application = ApplicationManager.getApplications().getApplication(applicationId);
             try {
-                applicationContext = AutoscalerServiceClient.getInstance().getApplication(applicationName);
+                applicationContext = AutoscalerServiceClient.getInstance().getApplication(applicationId);
             } catch (RemoteException e) {
-                log.error("Error while getting the application context for [application] " + applicationName);
-            }
-            if ((System.currentTimeMillis() - startTime) > APPLICATION_UNDEPLOYMENT_TIMEOUT) {
-                log.error("Application did not undeploy within timeout period");
-                break;
+                log.error(String.format("Error while getting the application context for [application-id] %s",
+                        applicationId), e);
             }
         }
+        log.info(String.format("Assert application undeploy for [application-id] %s took %d ms", applicationId,
+                System.currentTimeMillis() - startTime));
 
-        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
-        assertNotNull(String.format("Application Context is not found: [application-id] %s", applicationName),
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationId), application);
+        assertNotNull(String.format("Application Context is not found: [application-id] %s", applicationId),
                 applicationContext);
 
-        //Force undeployment after the graceful deployment
+        // Trigger a forced undeployment if graceful deployment fails
         if (application.getInstanceContextCount() > 0 || applicationContext.getStatus()
                 .equals(APPLICATION_STATUS_UNDEPLOYING)) {
             return false;
         }
-        assertEquals(
-                String.format("Application status did not change to Created: [application-id] %s", applicationName),
+        assertEquals(String.format("Application status did not change to Created: [application-id] %s", applicationId),
                 APPLICATION_STATUS_CREATED, applicationContext.getStatus());
         return true;
     }
@@ -501,40 +687,46 @@ public class TopologyHandler {
     /**
      * Assert application activation
      *
-     * @param applicationName
+     * @param applicationId
      */
-    public void assertGroupInstanceCount(String applicationName, String groupAlias, int count) {
+    public void assertGroupInstanceCount(String applicationId, String groupAlias, int count) {
+        log.info(String.format("Asserting group instance count for [application-id] %s, [group-alias] %s...",
+                applicationId, groupAlias));
         long startTime = System.currentTimeMillis();
-        Application application = ApplicationManager.getApplications().getApplication(applicationName);
+        Application application = ApplicationManager.getApplications().getApplication(applicationId);
         if (application != null) {
             Group group = application.getGroupRecursively(groupAlias);
             while (group.getInstanceContextCount() != count) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException ignore) {
-                }
                 if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
                     log.error("Group instance min count check failed within timeout period");
                     break;
                 }
+                log.info(String.format(
+                        "Waiting until [application-id] %s [group-alias] %s instance count to be [count] %d...",
+                        applicationId, groupAlias, count));
+                sleep(2000);
             }
+            log.info(String.format("Assert group instance min count for [group-alias] %s took %d ms", groupAlias,
+                    System.currentTimeMillis() - startTime));
+
             for (GroupInstance instance : group.getInstanceIdToInstanceContextMap().values()) {
                 while (!instance.getStatus().equals(GroupStatus.Active)) {
-                    try {
-                        Thread.sleep(1000);
-                    } catch (InterruptedException ignore) {
-                    }
                     if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
                         log.error("Application did not activate within timeout period");
                         break;
                     }
+                    log.info(String.format("Waiting for group [alias] %s, [group-instance-id] %s to be active...",
+                            instance.getAlias(), instance.getInstanceId()));
+                    sleep(2000);
                 }
             }
+            log.info(String.format("Assert group instance active for [group-alias] %s took %d ms", groupAlias,
+                    System.currentTimeMillis() - startTime));
             assertEquals(
-                    String.format("Application status did not change to active: [application-id] %s", applicationName),
+                    String.format("Application status did not change to active: [application-id] %s", applicationId),
                     group.getInstanceContextCount(), count);
         }
-        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationId), application);
 
     }
 
@@ -760,4 +952,11 @@ public class TopologyHandler {
         }
         return memberList;
     }
+
+    private void sleep(long time) {
+        try {
+            Thread.sleep(time);
+        } catch (Exception ignored) {
+        }
+    }
 }


[06/28] stratos git commit: Introducing removeEventListener method to unregister an event listener

Posted by ra...@apache.org.
Introducing removeEventListener method to unregister an event listener


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

Branch: refs/heads/stratos-4.1.x
Commit: bd5e2f8dd0645233f38a3b995dddd598e3022244
Parents: 2b82b91
Author: Akila Perera <ra...@gmail.com>
Authored: Sun Nov 29 23:57:07 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../processor/MessageProcessorChain.java        |  2 +
 .../ApplicationsMessageProcessorChain.java      | 38 +++++++++++++++-
 .../ApplicationSignUpMessageProcessorChain.java | 13 ++++++
 .../ClusterStatusMessageProcessorChain.java     | 18 ++++++++
 .../DomainMappingMessageProcessorChain.java     | 11 +++++
 .../stat/HealthStatMessageProcessorChain.java   | 41 ++++++++++++++++-
 .../InitializerMessageProcessorChain.java       | 15 ++++++
 .../InstanceNotifierMessageProcessorChain.java  | 12 +++++
 .../InstanceStatusMessageProcessorChain.java    | 14 ++++++
 .../tenant/TenantMessageProcessorChain.java     | 14 ++++++
 .../topology/TopologyMessageProcessorChain.java | 48 ++++++++++++++++++++
 .../ApplicationsEventMessageDelegator.java      |  4 ++
 .../application/ApplicationsEventReceiver.java  |  4 ++
 13 files changed, 231 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/MessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/MessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/MessageProcessorChain.java
index 0814830..fb49a97 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/MessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/MessageProcessorChain.java
@@ -39,6 +39,8 @@ public abstract class MessageProcessorChain {
 
     public abstract void addEventListener(EventListener eventListener);
 
+    public abstract void removeEventListener(EventListener eventListener);
+
     public void add(MessageProcessor messageProcessor) {
         if (list.size() > 0) {
             list.getLast().setNext(messageProcessor);

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationsMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationsMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationsMessageProcessorChain.java
index bed9b0d..71a968e 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationsMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/ApplicationsMessageProcessorChain.java
@@ -101,7 +101,6 @@ public class ApplicationsMessageProcessorChain extends MessageProcessorChain {
     }
 
     public void addEventListener(EventListener eventListener) {
-
         if (eventListener instanceof GroupInstanceCreatedEventListener) {
             groupCreatedMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof GroupInstanceInactivateEventListener) {
@@ -136,4 +135,41 @@ public class ApplicationsMessageProcessorChain extends MessageProcessorChain {
             throw new RuntimeException("Unknown event listener " + eventListener.toString());
         }
     }
+
+
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof GroupInstanceCreatedEventListener) {
+            groupCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GroupInstanceInactivateEventListener) {
+            groupInactivateMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GroupInstanceActivatedEventListener) {
+            groupActivatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GroupInstanceTerminatingEventListener) {
+            groupTerminatingProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GroupInstanceTerminatedEventListener) {
+            groupTerminatedProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationInstanceCreatedEventListener) {
+            applicationInstanceCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationCreatedEventListener) {
+            applicationCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationUndeployedEventListener) {
+            applicationUpdatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationDeletedEventListener) {
+            applicationDeletedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationInstanceActivatedEventListener) {
+            applicationActivatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationInstanceInactivatedEventListener) {
+            applicationInactivatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationInstanceTerminatingEventListener) {
+            applicationTerminatingMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationInstanceTerminatedEventListener) {
+            applicationTerminatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof CompleteApplicationsEventListener) {
+            completeApplicationsMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GroupMaintenanceModeEventListener){
+            groupMaintenanceModeProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener " + eventListener.toString());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/signup/ApplicationSignUpMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/signup/ApplicationSignUpMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/signup/ApplicationSignUpMessageProcessorChain.java
index c1a63f7..fea4092 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/signup/ApplicationSignUpMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/application/signup/ApplicationSignUpMessageProcessorChain.java
@@ -62,4 +62,17 @@ public class ApplicationSignUpMessageProcessorChain extends MessageProcessorChai
             throw new RuntimeException("Unknown event listener");
         }
     }
+
+    @Override
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof CompleteApplicationSignUpsEventListener) {
+            completeApplicationSignUpsMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationSignUpAddedEventListener) {
+            applicationSignUpAddedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationSignUpRemovedEventListener) {
+            applicationSignUpRemovedMessageProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusMessageProcessorChain.java
index 090a586..87ceb73 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/cluster/status/ClusterStatusMessageProcessorChain.java
@@ -79,6 +79,24 @@ public class ClusterStatusMessageProcessorChain extends MessageProcessorChain {
         } else {
             throw new RuntimeException("Unknown event listener " + eventListener.toString());
         }
+    }
 
+    @Override
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof ClusterStatusClusterResetEventListener) {
+            clusterResetMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterStatusClusterInactivateEventListener) {
+            clusterInactivateMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterStatusClusterActivatedEventListener) {
+            clusterActivatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterStatusClusterTerminatingEventListener) {
+            clusterTerminatingMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterStatusClusterTerminatedEventListener) {
+            clusterTerminatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterStatusClusterInstanceCreatedEventListener) {
+            clusterInstanceCreatedMessageProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener " + eventListener.toString());
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/domain/mapping/DomainMappingMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/domain/mapping/DomainMappingMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/domain/mapping/DomainMappingMessageProcessorChain.java
index ab4452b..9f494f8 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/domain/mapping/DomainMappingMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/domain/mapping/DomainMappingMessageProcessorChain.java
@@ -55,4 +55,15 @@ public class DomainMappingMessageProcessorChain extends MessageProcessorChain {
             throw new RuntimeException("Unknown event listener");
         }
     }
+
+    @Override
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof DomainMappingAddedEventListener) {
+            domainNameAddedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof DomainMappingRemovedEventListener) {
+            domainNameRemovedMessageProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/health/stat/HealthStatMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/health/stat/HealthStatMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/health/stat/HealthStatMessageProcessorChain.java
index 70bde39..2066a0a 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/health/stat/HealthStatMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/health/stat/HealthStatMessageProcessorChain.java
@@ -93,7 +93,6 @@ public class HealthStatMessageProcessorChain extends MessageProcessorChain {
     }
 
     public void addEventListener(EventListener eventListener) {
-
         if (eventListener instanceof AverageLoadAverageEventListener) {
             averageLoadAverageMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof AverageMemoryConsumptionEventListener) {
@@ -126,10 +125,48 @@ public class HealthStatMessageProcessorChain extends MessageProcessorChain {
             secondDerivativeOfLoadAverageMessageProcessor.addEventListener(eventListener);
         } else if (eventListener instanceof SecondDerivativeOfMemoryConsumptionEventListener) {
             secondDerivativeOfMemoryConsumptionMessageProcessor.addEventListener(eventListener);
-
         } else if (eventListener instanceof SecondDerivativeOfRequestsInFlightEventListener) {
             secondDerivativeOfRequestsInFlightMessageProcessor.addEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof AverageLoadAverageEventListener) {
+            averageLoadAverageMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof AverageMemoryConsumptionEventListener) {
+            averageMemoryConsumptionMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof AverageRequestsInFlightEventListener) {
+            averageRequestsInFlightMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof AverageRequestsServingCapabilityEventListener) {
+            averageRequestsServingCapabilityMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GradientOfLoadAverageEventListener) {
+            gradientOfLoadAverageMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GradientOfMemoryConsumptionEventListener) {
+            gradientOfMemoryConsumptionMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof GradientOfRequestsInFlightEventListener) {
+            gradientOfRequestsInFlightMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberAverageLoadAverageEventListener) {
+            memberAverageLoadAverageMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberAverageMemoryConsumptionEventListener) {
+            memberAverageMemoryConsumptionMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberFaultEventListener) {
+            memberFaultMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberGradientOfLoadAverageEventListener) {
+            memberGradientOfLoadAverageMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberGradientOfMemoryConsumptionEventListener) {
+            memberGradientOfMemoryConsumptionMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberSecondDerivativeOfLoadAverageEventListener) {
+            memberSecondDerivativeOfLoadAverageMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberSecondDerivativeOfMemoryConsumptionEventListener) {
+            memberSecondDerivativeOfMemoryConsumptionMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof SecondDerivativeOfLoadAverageEventListener) {
+            secondDerivativeOfLoadAverageMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof SecondDerivativeOfMemoryConsumptionEventListener) {
+            secondDerivativeOfMemoryConsumptionMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof SecondDerivativeOfRequestsInFlightEventListener) {
+            secondDerivativeOfRequestsInFlightMessageProcessor.removeEventListener(eventListener);
         } else {
             throw new RuntimeException("Unknown event listener");
         }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/initializer/InitializerMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/initializer/InitializerMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/initializer/InitializerMessageProcessorChain.java
index f3e292f..44398b7 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/initializer/InitializerMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/initializer/InitializerMessageProcessorChain.java
@@ -67,4 +67,19 @@ public class InitializerMessageProcessorChain extends MessageProcessorChain {
             throw new RuntimeException("Unknown event listener");
         }
     }
+
+    @Override
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof CompleteTopologyRequestEventListener) {
+            completeTopologyRequestMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof CompleteApplicationsRequestEventListener) {
+            completeApplicationsRequestMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof CompleteTenantRequestEventListener) {
+            completeTenantRequestMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof CompleteApplicationSignUpsRequestEventListener) {
+            completeApplicationSignUpsRequestMessageProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java
index 013a030..a8db9d8 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/notifier/InstanceNotifierMessageProcessorChain.java
@@ -63,4 +63,16 @@ public class InstanceNotifierMessageProcessorChain extends MessageProcessorChain
             throw new RuntimeException("Unknown event listener");
         }
     }
+
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof ArtifactUpdateEventListener) {
+            artifactUpdateMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof InstanceCleanupMemberEventListener) {
+            instanceCleanupMemberNotifierMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof InstanceCleanupClusterEventListener) {
+            instanceCleanupClusterNotifierMessageProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/status/InstanceStatusMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/status/InstanceStatusMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/status/InstanceStatusMessageProcessorChain.java
index 8e6a7de..4b5daed 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/status/InstanceStatusMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/instance/status/InstanceStatusMessageProcessorChain.java
@@ -73,4 +73,18 @@ public class InstanceStatusMessageProcessorChain extends MessageProcessorChain {
             throw new RuntimeException("Unknown event listener");
         }
     }
+
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof InstanceStartedEventListener) {
+            instanceStatusMemberStartedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof InstanceReadyToShutdownEventListener) {
+            instanceStatusMemberReadyToShutdownMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof InstanceMaintenanceListener) {
+            instanceStatusMemberMaintenanceMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof InstanceActivatedEventListener) {
+            instanceStatusMemberActivatedMessageProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
index 53c6085..bfb23ba 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/tenant/TenantMessageProcessorChain.java
@@ -71,4 +71,18 @@ public class TenantMessageProcessorChain extends MessageProcessorChain {
             throw new RuntimeException("Unknown event listener");
         }
     }
+
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof CompleteTenantEventListener) {
+            completeTenantMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof TenantCreatedEventListener) {
+            tenantCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof TenantUpdatedEventListener) {
+            tenantUpdatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof TenantRemovedEventListener) {
+            tenantRemovedMessageProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
index a026a50..4dadcb7 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/TopologyMessageProcessorChain.java
@@ -171,4 +171,52 @@ public class TopologyMessageProcessorChain extends MessageProcessorChain {
             throw new RuntimeException("Unknown event listener");
         }
     }
+
+    public void removeEventListener(EventListener eventListener) {
+        if (eventListener instanceof CompleteTopologyEventListener) {
+            completeTopologyMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterCreatedEventListener) {
+            clusterCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationClustersCreatedEventListener) {
+            appClustersCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ApplicationClustersRemovedEventListener) {
+            appClustersRemovedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterInstanceActivatedEventListener) {
+            clusterActivatedProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterInstanceInactivateEventListener) {
+            clusterInactivateProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterRemovedEventListener) {
+            clusterRemovedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterInstanceCreatedEventListener) {
+            clusterInstanceCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterInstanceTerminatedEventListener) {
+            clusterTerminatedProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterResetEventListener) {
+            clusterResetMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ClusterInstanceTerminatingEventListener) {
+            clusterTerminatingProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberCreatedEventListener) {
+            memberCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberInitializedEventListener) {
+            memberInitializedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberActivatedEventListener) {
+            memberActivatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberStartedEventListener) {
+            memberStartedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberReadyToShutdownEventListener) {
+            memberReadyToShutdownProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberSuspendedEventListener) {
+            memberSuspendedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberTerminatedEventListener) {
+            memberTerminatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ServiceCreatedEventListener) {
+            serviceCreatedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof ServiceRemovedEventListener) {
+            serviceRemovedMessageProcessor.removeEventListener(eventListener);
+        } else if (eventListener instanceof MemberMaintenanceListener) {
+            memberMaintenanceModeProcessor.removeEventListener(eventListener);
+        } else {
+            throw new RuntimeException("Unknown event listener");
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventMessageDelegator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventMessageDelegator.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventMessageDelegator.java
index 29e57cc..59ef5ca 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventMessageDelegator.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventMessageDelegator.java
@@ -41,6 +41,10 @@ public class ApplicationsEventMessageDelegator implements Runnable {
         processorChain.addEventListener(eventListener);
     }
 
+    public void removeEventListener(EventListener eventListener){
+        processorChain.removeEventListener(eventListener);
+    }
+
     @Override
     public void run() {
         try {

http://git-wip-us.apache.org/repos/asf/stratos/blob/bd5e2f8d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventReceiver.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventReceiver.java
index d7e7196..9306ad2 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventReceiver.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/receiver/application/ApplicationsEventReceiver.java
@@ -47,6 +47,10 @@ public class ApplicationsEventReceiver {
         messageDelegator.addEventListener(eventListener);
     }
 
+    public void removeEventListener(EventListener eventListener) {
+        messageDelegator.removeEventListener(eventListener);
+    }
+
     public void execute() {
         try {
             // Start topic subscriber thread


[12/28] stratos git commit: Refactor GitHookTestCase: Use restClient deployEntity. Make artifactUpdateEventCount AtomicInteger. Terminate event receiver and shutdown executor service at the end of test case.

Posted by ra...@apache.org.
Refactor GitHookTestCase: Use restClient deployEntity. Make artifactUpdateEventCount AtomicInteger. Terminate event receiver and shutdown executor service at the end of test case.


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

Branch: refs/heads/stratos-4.1.x
Commit: 76199f0a1897e1cab39f8dc2452346f71d5530fa
Parents: 3b83cef
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:24:46 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../integration/tests/adc/GitHookTestCase.java  | 108 +++++++++----------
 1 file changed, 49 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/76199f0a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java
index 5e3ff70..3f708db 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/adc/GitHookTestCase.java
@@ -26,14 +26,14 @@ import org.apache.stratos.common.threading.StratosThreadPool;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.listener.instance.notifier.ArtifactUpdateEventListener;
 import org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventReceiver;
 import org.testng.annotations.Test;
 
-import java.net.URI;
+import java.io.File;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
@@ -42,24 +42,26 @@ import static org.testng.AssertJUnit.assertTrue;
 /**
  * Test case to test the /repo/notify endpoint
  */
+@Test(groups = { "adc" })
 public class GitHookTestCase extends StratosIntegrationTest {
 
     private static Log log = LogFactory.getLog(GitHookTestCase.class);
-    private static final String RESOURCES_PATH = "/git-hook-test";
-    private int artifactUpdateEvents = 0;
+    private static final String RESOURCES_PATH = File.separator + "git-hook-test";
+    private AtomicInteger artifactUpdateEventCount = new AtomicInteger(0);
     private static final String autoscalePolicyId = "autoscaling-policy-git-hook-test";
     private static final String cartridgeId = "c1-git-hook-test";
     private static final String networkPartitionId = "network-partition-git-hook-test";
     private static final String depPolicyId = "deployment-policy-git-hook-test";
     private static final String applicationId = "git-hook-test";
     private static final String appPolicyId = "application-policy-git-hook-test";
+    private static final String GIT_HOOK_ARTIFACT_FILENAME = "hook-req.json";
+    private static final int ARTIFACT_UPDATED_EXPECTED_COUNT = 2;
+    private ExecutorService eventListenerExecutorService = StratosThreadPool
+            .getExecutorService("stratos.integration.test.git.thread.pool", 5);
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"adc", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void sendRepoNotify() throws Exception {
         deployArtifacts();
-        ExecutorService eventListenerExecutorService = StratosThreadPool.getExecutorService(
-                                                                            "stratos.integration.test.git.thread.pool",
-                                                                            5);
         final InstanceNotifierEventReceiver instanceNotifierEventReceiver = new InstanceNotifierEventReceiver();
         eventListenerExecutorService.submit(new Runnable() {
             @Override
@@ -71,57 +73,48 @@ public class GitHookTestCase extends StratosIntegrationTest {
         ArtifactUpdateEventListener artifactUpdateEventListener = new ArtifactUpdateEventListener() {
             @Override
             protected void onEvent(Event event) {
-                artifactUpdateEvents++;
+                artifactUpdateEventCount.addAndGet(1);
             }
         };
 
         instanceNotifierEventReceiver.addEventListener(artifactUpdateEventListener);
+        restClient.addEntity(RESOURCES_PATH + File.separator + GIT_HOOK_ARTIFACT_FILENAME, RestConstants.REPO_NOTIFY,
+                RestConstants.REPO_NOTIFY_NAME);
 
-        String gitHookFile = "hook-req.json";
-        restClient.doPost(
-                new URI(stratosBackendURL + RestConstants.REPO_NOTIFY),
-                restClient.getJsonStringFromFile(RESOURCES_PATH + "/" + gitHookFile));
-
-        while (artifactUpdateEvents < 2) {
-            log.info("Waiting till artifact updated comes in... ");
+        while (artifactUpdateEventCount.get() < ARTIFACT_UPDATED_EXPECTED_COUNT) {
+            log.info("Waiting until artifact updated event is received...");
             Thread.sleep(1000);
         }
-
-        log.info("Waiting for application status to become ACTIVE...");
-        TopologyHandler.getInstance().assertApplicationStatus(applicationId, ApplicationStatus.Active);
-
+        TopologyHandler.getInstance().assertApplicationActiveStatus(applicationId);
+        instanceNotifierEventReceiver.terminate();
+        eventListenerExecutorService.shutdownNow();
         undeployArtifacts();
     }
 
     private void deployArtifacts() throws Exception {
-        boolean autoscalePolicyAdded = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalePolicyId + ".json",
-                RestConstants.AUTOSCALING_POLICIES,
-                RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean autoscalePolicyAdded = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalePolicyId + ".json",
+                        RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(autoscalePolicyAdded);
 
-        boolean cartridgeAdded = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
-                RestConstants.CARTRIDGES,
-                RestConstants.CARTRIDGES_NAME);
+        boolean cartridgeAdded = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(cartridgeAdded);
 
-        boolean networkPartitionAdded = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + networkPartitionId + ".json",
-                RestConstants.NETWORK_PARTITIONS,
-                RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean networkPartitionAdded = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" + networkPartitionId + ".json",
+                        RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(networkPartitionAdded);
 
-        boolean deploymentPolicyAdded = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + depPolicyId + ".json",
-                RestConstants.DEPLOYMENT_POLICIES,
-                RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean deploymentPolicyAdded = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" + depPolicyId + ".json",
+                        RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(deploymentPolicyAdded);
 
-        boolean applicationAdded = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + applicationId + ".json",
-                RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+        boolean applicationAdded = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" + applicationId + ".json",
+                        RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         assertTrue(applicationAdded);
 
         ApplicationBean bean = (ApplicationBean) restClient
@@ -129,19 +122,18 @@ public class GitHookTestCase extends StratosIntegrationTest {
                         RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), applicationId);
 
-        boolean appPolicyAdded = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + appPolicyId + ".json",
-                RestConstants.APPLICATION_POLICIES,
-                RestConstants.APPLICATION_POLICIES_NAME);
+        boolean appPolicyAdded = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" + appPolicyId + ".json",
+                        RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(appPolicyAdded);
 
         boolean appDeployed = restClient.deployEntity(
-                RestConstants.APPLICATIONS + "/" + applicationId + RestConstants.APPLICATIONS_DEPLOY + "/" + appPolicyId,
-                RestConstants.APPLICATIONS_NAME);
+                RestConstants.APPLICATIONS + "/" + applicationId + RestConstants.APPLICATIONS_DEPLOY + "/"
+                        + appPolicyId, RestConstants.APPLICATIONS_NAME);
         assertTrue(appDeployed);
     }
 
-    private void undeployArtifacts() throws Exception{
+    private void undeployArtifacts() throws Exception {
         log.info(String.format("Un-deploying the application [application id] %s", applicationId));
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_UNDEPLOY;
@@ -158,12 +150,13 @@ public class GitHookTestCase extends StratosIntegrationTest {
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = TopologyHandler.getInstance().assertApplicationUndeploy(applicationId);
-            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId), forceUndeployed);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId),
+                    forceUndeployed);
         }
 
         log.info("Removing the application [application id] sample-application-startup-test");
-        boolean removedApp = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removedApp = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId, RestConstants.APPLICATIONS_NAME);
         assertTrue(removedApp);
 
         ApplicationBean beanRemoved = (ApplicationBean) restClient
@@ -173,13 +166,12 @@ public class GitHookTestCase extends StratosIntegrationTest {
 
         log.info(String.format("Removing the application policy [application policy id] %s", appPolicyId));
         boolean removeAppPolicy = restClient
-                .removeEntity(RestConstants.APPLICATION_POLICIES, appPolicyId,
-                        RestConstants.APPLICATION_POLICIES_NAME);
+                .removeEntity(RestConstants.APPLICATION_POLICIES, appPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removeAppPolicy);
 
         log.info(String.format("Removing the cartridge [cartridge type] %s", cartridgeId));
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC1);
 
         log.info(String.format("Removing the autoscaling policy [autoscaling policy id] %s", autoscalePolicyId));
@@ -189,14 +181,12 @@ public class GitHookTestCase extends StratosIntegrationTest {
 
         log.info(String.format("Removing the deployment policy [deployment policy id] %s", depPolicyId));
         boolean removedDep = restClient
-                .removeEntity(RestConstants.DEPLOYMENT_POLICIES, depPolicyId,
-                        RestConstants.DEPLOYMENT_POLICIES_NAME);
+                .removeEntity(RestConstants.DEPLOYMENT_POLICIES, depPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
 
         log.info(String.format("Removing the network partition [network partition id] %s", networkPartitionId));
-        boolean removedNet = restClient
-                .removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
-                        RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedNet);
     }
 }


[27/28] stratos git commit: Set parallel false at suite level in testng configuration file

Posted by ra...@apache.org.
Set parallel false at suite level in testng configuration file


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

Branch: refs/heads/stratos-4.1.x
Commit: e9bef7da5fcd7cf8cde2335904b3b5188bf05f6c
Parents: 9700dec
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:29:47 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:48 2015 +0530

----------------------------------------------------------------------
 .../test-integration/src/test/resources/test-suite-all.xml       | 4 ++--
 .../test-integration/src/test/resources/test-suite-smoke.xml     | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/e9bef7da/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-all.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-all.xml b/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-all.xml
index be687f2..5a73f7c 100644
--- a/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-all.xml
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-all.xml
@@ -20,7 +20,7 @@
 
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 
-<suite name="StratosIntegrationSuite">
+<suite name="StratosIntegrationSuite" parallel="false">
     <listeners>
         <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestExecutionListener"/>
         <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestSuiteListener"/>
@@ -41,4 +41,4 @@
             <package name="org.apache.stratos.integration.tests.*"/>
         </packages>
     </test>
-</suite>
\ No newline at end of file
+</suite>

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9bef7da/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-smoke.xml
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-smoke.xml b/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-smoke.xml
index 0f388d7..0e2fbf0 100644
--- a/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-smoke.xml
+++ b/products/stratos/modules/integration/test-integration/src/test/resources/test-suite-smoke.xml
@@ -20,7 +20,7 @@
 
 <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 
-<suite name="StratosIntegrationSuite">
+<suite name="StratosIntegrationSuite" parallel="false">
     <listeners>
         <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestExecutionListener"/>
         <listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestSuiteListener"/>


[03/28] stratos git commit: Set timeout value to 600000 ms in waitForPort method to avoid build failures in slow builder machines. Fixed formatting.

Posted by ra...@apache.org.
Set timeout value to 600000 ms in waitForPort method to avoid build failures in slow builder machines. Fixed formatting.


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

Branch: refs/heads/stratos-4.1.x
Commit: da9b0b367321fb5516d1f12053e3f4bf5d533bd8
Parents: d0f0f81
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:13:58 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../common/StratosTestServerManager.java        | 102 ++++++++-----------
 1 file changed, 42 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/da9b0b36/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java
index d2db900..cda20c6 100644
--- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/StratosTestServerManager.java
@@ -137,8 +137,7 @@ public class StratosTestServerManager extends TestServerManager {
 
             // set truststores and jndi.properties path
             setSystemproperties();
-        }
-        catch (IOException e) {
+        } catch (IOException e) {
             throw new AutomationFrameworkException("Could not configure Stratos server", e);
         }
     }
@@ -157,15 +156,13 @@ public class StratosTestServerManager extends TestServerManager {
         copyConfigFile(commonResourcesPath, CARTRIDGE_CONFIG_PROPERTIES_FILENAME, Util.CARBON_CONF_PATH);
         copyConfigFile(commonResourcesPath, IDENTITY_FILENAME, Util.CARBON_CONF_PATH);
         copyConfigFile(commonResourcesPath, THRIFT_CLIENT_CONFIG_FILENAME, Util.CARBON_CONF_PATH);
-        copyConfigFile(commonResourcesPath, SCALING_DROOL_FILENAME,
-                Util.CARBON_CONF_PATH + PATH_SEP + "drools");
+        copyConfigFile(commonResourcesPath, SCALING_DROOL_FILENAME, Util.CARBON_CONF_PATH + PATH_SEP + "drools");
         copyConfigFile(commonResourcesPath, JMS_OUTPUT_ADAPTER_FILENAME,
                 "repository" + PATH_SEP + "deployment" + PATH_SEP + "server" + PATH_SEP + "outputeventadaptors");
 
     }
 
-    private void copyConfigFile(String filePath, String fileName, String destinationFolder)
-            throws IOException {
+    private void copyConfigFile(String filePath, String fileName, String destinationFolder) throws IOException {
         assertNotNull(carbonHome, "CARBON_HOME is null");
         String fileAbsPath = filePath + PATH_SEP + fileName;
         log.info("Copying file: " + fileAbsPath);
@@ -178,19 +175,18 @@ public class StratosTestServerManager extends TestServerManager {
         // replace placeholders with dynamic values
         String content = IOUtils.toString(new FileInputStream(destFile), StandardCharsets.UTF_8.displayName());
         content = content.replaceAll(Util.ACTIVEMQ_DYNAMIC_PORT_PLACEHOLDER, String.valueOf(activeMQDynamicPort));
-        content = content.replaceAll(Util.STRATOS_SECURE_DYNAMIC_PORT_PLACEHOLDER,
-                String.valueOf(stratosSecureDynamicPort));
-        content = content.replaceAll(Util.STRATOS_DYNAMIC_PORT_PLACEHOLDER,
-                String.valueOf(stratosDynamicPort));
-        content = content.replaceAll(Util.THRIFT_SECURE_DYNAMIC_PORT_PLACEHOLDER,
-                String.valueOf(thriftSecureDynamicPort));
+        content = content
+                .replaceAll(Util.STRATOS_SECURE_DYNAMIC_PORT_PLACEHOLDER, String.valueOf(stratosSecureDynamicPort));
+        content = content.replaceAll(Util.STRATOS_DYNAMIC_PORT_PLACEHOLDER, String.valueOf(stratosDynamicPort));
+        content = content
+                .replaceAll(Util.THRIFT_SECURE_DYNAMIC_PORT_PLACEHOLDER, String.valueOf(thriftSecureDynamicPort));
         content = content.replaceAll(Util.THRIFT_DYNAMIC_PORT_PLACEHOLDER, String.valueOf(thriftDynamicPort));
         IOUtils.write(content, new FileOutputStream(destFile), StandardCharsets.UTF_8.displayName());
     }
 
     public void setSystemproperties() throws AutomationFrameworkException {
-        URL resourceUrl = getClass().getResource(File.separator + "keystores" + File.separator
-                + "products" + File.separator + "wso2carbon.jks");
+        URL resourceUrl = getClass().getResource(
+                File.separator + "keystores" + File.separator + "products" + File.separator + "wso2carbon.jks");
         System.setProperty("javax.net.ssl.trustStore", resourceUrl.getPath());
         System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
         System.setProperty("javax.net.ssl.trustStoreType", "JKS");
@@ -202,8 +198,7 @@ public class StratosTestServerManager extends TestServerManager {
             String autoscalerServiceURL = webAppURLHttps + "/services/AutoscalerService";
             System.setProperty(StratosConstants.AUTOSCALER_SERVICE_URL, autoscalerServiceURL);
             log.info("Autoscaler service URL set to " + autoscalerServiceURL);
-        }
-        catch (Exception e) {
+        } catch (Exception e) {
             throw new AutomationFrameworkException("Could not set autoscaler service URL system property", e);
         }
     }
@@ -282,6 +277,7 @@ class StratosServerManager extends CarbonServerManager {
     private static final String CMD_ARG = "cmdArg";
     private static int defaultHttpPort = Integer.parseInt("9763");
     private static int defaultHttpsPort = Integer.parseInt("9443");
+    private static final long RESTART_TIMEOUT = 600000;
 
     public StratosServerManager(AutomationContext context) {
         super(context);
@@ -306,11 +302,11 @@ class StratosServerManager extends CarbonServerManager {
                 String[] cmdArray;
                 if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                     e = new File(carbonHome + File.separator + "bin");
-                    cmdArray = new String[]{"cmd.exe", "/c", scriptName + ".bat"};
+                    cmdArray = new String[] { "cmd.exe", "/c", scriptName + ".bat" };
                     cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
                     tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, e);
                 } else {
-                    cmdArray = new String[]{"sh", "bin/" + scriptName + ".sh"};
+                    cmdArray = new String[] { "sh", "bin/" + scriptName + ".sh" };
                     cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
                     tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, e);
                 }
@@ -323,8 +319,7 @@ class StratosServerManager extends CarbonServerManager {
                     public void run() {
                         try {
                             StratosServerManager.this.serverShutdown(StratosServerManager.this.portOffset);
-                        }
-                        catch (Exception var2) {
+                        } catch (Exception var2) {
                             log.error("Error while server shutdown ..", var2);
                         }
 
@@ -335,8 +330,8 @@ class StratosServerManager extends CarbonServerManager {
                 long time = System.currentTimeMillis() + 60000L;
 
                 while (true) {
-                    if (this.inputStreamHandler.getOutput().contains("Mgt Console URL") ||
-                            System.currentTimeMillis() >= time) {
+                    if (this.inputStreamHandler.getOutput().contains("Mgt Console URL")
+                            || System.currentTimeMillis() >= time) {
                         int httpsPort = defaultHttpsPort + this.portOffset;
                         String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl()
                                 .replaceAll("(:\\d+)", ":" + httpsPort);
@@ -346,8 +341,7 @@ class StratosServerManager extends CarbonServerManager {
                         break;
                     }
                 }
-            }
-            catch (XPathExpressionException | IOException var13) {
+            } catch (XPathExpressionException | IOException var13) {
                 throw new IllegalStateException("Unable to start server", var13);
             }
 
@@ -399,17 +393,14 @@ class StratosServerManager extends CarbonServerManager {
                 String baseDir = System.getProperty("basedir", ".") + File.separator + "target";
                 log.info("Extracting carbon zip file.. ");
                 (new ArchiveExtractor()).extractFile(carbonServerZipFile, baseDir + File.separator + extractDir);
-                this.carbonHome =
-                        (new File(baseDir)).getAbsolutePath() + File.separator + extractDir + File.separator +
-                                extractedCarbonDir;
+                this.carbonHome = (new File(baseDir)).getAbsolutePath() + File.separator + extractDir + File.separator +
+                        extractedCarbonDir;
 
                 try {
-                    this.isCoverageEnable =
-                            Boolean.parseBoolean(this.automationContext.getConfigurationValue("//coverage"));
-                }
-                catch (XPathExpressionException var8) {
-                    throw new AutomationFrameworkException("Coverage configuration not found in automation.xml",
-                            var8);
+                    this.isCoverageEnable = Boolean
+                            .parseBoolean(this.automationContext.getConfigurationValue("//coverage"));
+                } catch (XPathExpressionException var8) {
+                    throw new AutomationFrameworkException("Coverage configuration not found in automation.xml", var8);
                 }
                 // Fix startup script issue by copying stratos.sh as stratos-server.sh
                 // TODO: remove this class after automation engine provides a way to pass startup script name
@@ -435,8 +426,7 @@ class StratosServerManager extends CarbonServerManager {
 
                 try {
                     url = this.automationContext.getContextUrls().getBackEndUrl();
-                }
-                catch (XPathExpressionException var10) {
+                } catch (XPathExpressionException var10) {
                     throw new AutomationFrameworkException("Get context failed", var10);
                 }
 
@@ -446,18 +436,16 @@ class StratosServerManager extends CarbonServerManager {
                     ClientConnectionUtil.sendForcefulShutDownRequest(backendURL,
                             this.automationContext.getSuperTenant().getContextUser().getUserName(),
                             this.automationContext.getSuperTenant().getContextUser().getPassword());
-                }
-                catch (AutomationFrameworkException var8) {
+                } catch (AutomationFrameworkException var8) {
                     throw new AutomationFrameworkException("Get context failed", var8);
-                }
-                catch (XPathExpressionException var9) {
+                } catch (XPathExpressionException var9) {
                     throw new AutomationFrameworkException("Get context failed", var9);
                 }
 
                 long time = System.currentTimeMillis() + 300000L;
 
-                while (!this.inputStreamHandler.getOutput().contains("Halting JVM") &&
-                        System.currentTimeMillis() < time) {
+                while (!this.inputStreamHandler.getOutput().contains("Halting JVM")
+                        && System.currentTimeMillis() < time) {
                     ;
                 }
 
@@ -471,11 +459,10 @@ class StratosServerManager extends CarbonServerManager {
             if (this.isCoverageEnable) {
                 try {
                     log.info("Generating Jacoco code coverage...");
-                    this.generateCoverageReport(new File(
-                            this.carbonHome + File.separator + "repository" + File.separator + "components" +
+                    this.generateCoverageReport(
+                            new File(this.carbonHome + File.separator + "repository" + File.separator + "components" +
                                     File.separator + "plugins" + File.separator));
-                }
-                catch (IOException var7) {
+                } catch (IOException var7) {
                     log.error("Failed to generate code coverage ", var7);
                     throw new AutomationFrameworkException("Failed to generate code coverage ", var7);
                 }
@@ -490,11 +477,9 @@ class StratosServerManager extends CarbonServerManager {
 
     private void generateCoverageReport(File classesDir) throws IOException, AutomationFrameworkException {
         CodeCoverageUtils
-                .executeMerge(FrameworkPathUtil.getJacocoCoverageHome(),
-                        FrameworkPathUtil.getCoverageMergeFilePath());
-        ReportGenerator reportGenerator =
-                new ReportGenerator(new File(FrameworkPathUtil.getCoverageMergeFilePath()), classesDir,
-                        new File(CodeCoverageUtils.getJacocoReportDirectory()), (File) null);
+                .executeMerge(FrameworkPathUtil.getJacocoCoverageHome(), FrameworkPathUtil.getCoverageMergeFilePath());
+        ReportGenerator reportGenerator = new ReportGenerator(new File(FrameworkPathUtil.getCoverageMergeFilePath()),
+                classesDir, new File(CodeCoverageUtils.getJacocoReportDirectory()), (File) null);
         reportGenerator.create();
         log.info("Jacoco coverage dump file path : " + FrameworkPathUtil.getCoverageDumpFilePath());
         log.info("Jacoco class file path : " + classesDir);
@@ -505,12 +490,11 @@ class StratosServerManager extends CarbonServerManager {
     public synchronized void restartGracefully() throws AutomationFrameworkException {
         try {
             int time = defaultHttpsPort + this.portOffset;
-            String backendURL =
-                    this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + time);
+            String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl()
+                    .replaceAll("(:\\d+)", ":" + time);
             User e = this.automationContext.getSuperTenant().getTenantAdmin();
             ClientConnectionUtil.sendGraceFullRestartRequest(backendURL, e.getUserName(), e.getPassword());
-        }
-        catch (XPathExpressionException var5) {
+        } catch (XPathExpressionException var5) {
             throw new AutomationFrameworkException("restart failed", var5);
         }
 
@@ -529,10 +513,9 @@ class StratosServerManager extends CarbonServerManager {
         try {
             ClientConnectionUtil.waitForPort(
                     Integer.parseInt((String) this.automationContext.getInstance().getPorts().get("https")),
-                    (String) this.automationContext.getInstance().getHosts().get("default"));
+                    RESTART_TIMEOUT, true, (String) this.automationContext.getInstance().getHosts().get("default"));
             ClientConnectionUtil.waitForLogin(this.automationContext);
-        }
-        catch (XPathExpressionException var4) {
+        } catch (XPathExpressionException var4) {
             throw new AutomationFrameworkException("Connection attempt to carbon server failed", var4);
         }
     }
@@ -578,8 +561,7 @@ class StratosServerManager extends CarbonServerManager {
     }
 
     private int getPortOffsetFromCommandMap(Map<String, String> commandMap) {
-        return commandMap.containsKey("-DportOffset") ? Integer.parseInt((String) commandMap.get("-DportOffset")) :
-                0;
+        return commandMap.containsKey("-DportOffset") ? Integer.parseInt((String) commandMap.get("-DportOffset")) : 0;
     }
 
     private String[] mergerArrays(String[] array1, String[] array2) {
@@ -620,4 +602,4 @@ class StratosServerManager extends CarbonServerManager {
         }
 
     }
-}
\ No newline at end of file
+}


[08/28] stratos git commit: Add debug log message for getStatus method to print status of each application instance

Posted by ra...@apache.org.
Add debug log message for getStatus method to print status of each application instance


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

Branch: refs/heads/stratos-4.1.x
Commit: 2b6f9727460f1a19222d1d96520e07dda6d5e61f
Parents: bd5e2f8
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:04:54 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../messaging/domain/application/Application.java        | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2b6f9727/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/Application.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/Application.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/Application.java
index 0a0cb67..5dcea72 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/Application.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/Application.java
@@ -20,6 +20,8 @@
 package org.apache.stratos.messaging.domain.application;
 
 import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.messaging.domain.instance.ApplicationInstance;
 import org.apache.stratos.messaging.domain.instance.Instance;
 
@@ -33,7 +35,7 @@ import java.util.Stack;
 public class Application extends ParentComponent<ApplicationInstance> {
 
     private static final long serialVersionUID = -5092959597171649688L;
-
+    private static final Log log = LogFactory.getLog(Application.class);
     // Unique id for the Application, defined in Application Definition
     private String id;
     private String name;
@@ -57,8 +59,6 @@ public class Application extends ParentComponent<ApplicationInstance> {
         this.id = id;
         this.key = RandomStringUtils.randomAlphanumeric(16);
         this.setInstanceIdToInstanceContextMap(new HashMap<String, ApplicationInstance>());
-        //this.applicationStateManager =
-        //new LifeCycleStateManager<ApplicationStatus>(ApplicationStatus.Created, id);
     }
 
     public String getUniqueIdentifier() {
@@ -105,6 +105,11 @@ public class Application extends ParentComponent<ApplicationInstance> {
         if ((getInstanceIdToInstanceContextMap() != null) && (getInstanceIdToInstanceContextMap().size() > 0)) {
             boolean applicationActive = true;
             for (ApplicationInstance applicationInstance : getInstanceIdToInstanceContextMap().values()) {
+                if (log.isDebugEnabled()) {
+                    log.debug(String.format(
+                            "Checking status of [application-id] %s. ApplicationInstance: [instance-id] %s, [status] "
+                                    + "%s", id, applicationInstance.getInstanceId(), applicationInstance.getStatus()));
+                }
                 if (applicationInstance.getStatus() != ApplicationStatus.Active) {
                     applicationActive = false;
                 }


[21/28] stratos git commit: Fix logs formatting

Posted by ra...@apache.org.
Fix logs formatting


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

Branch: refs/heads/stratos-4.1.x
Commit: 87b4471e13666b874ef95afa3c941ae32b1f1351
Parents: 34f80ec
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:18:19 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../processor/group/GroupStatusProcessor.java   | 10 ++---
 .../group/GroupStatusTerminatedProcessor.java   | 42 +++++++++-----------
 2 files changed, 22 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/87b4471e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
index e4ae474..77b98c7 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusProcessor.java
@@ -41,7 +41,6 @@ import java.util.Map;
 public abstract class GroupStatusProcessor extends StatusProcessor {
     private static final Log log = LogFactory.getLog(GroupStatusProcessor.class);
 
-
     /**
      * Message processing and delegating logic.
      *
@@ -95,8 +94,8 @@ public abstract class GroupStatusProcessor extends StatusProcessor {
      * @param status      the status to check of the group
      * @return whether all groups in the same state or not
      */
-    protected boolean getAllClusterInSameState(Map<String, ClusterDataHolder> clusterData,
-                                               ClusterStatus status, String instanceId) {
+    protected boolean getAllClusterInSameState(Map<String, ClusterDataHolder> clusterData, ClusterStatus status,
+            String instanceId) {
         boolean clusterStat = false;
         for (Map.Entry<String, ClusterDataHolder> clusterDataHolderEntry : clusterData.entrySet()) {
             String serviceName = clusterDataHolderEntry.getValue().getServiceType();
@@ -108,8 +107,8 @@ public abstract class GroupStatusProcessor extends StatusProcessor {
                 ClusterInstance context = cluster.getInstanceContexts(instanceId);
                 if (context != null) {
                     if (log.isDebugEnabled()) {
-                        log.debug("Checking the status of cluster " + clusterId + " instance status is: " +
-                                context.getStatus().toString());
+                        log.debug(String.format("Cluster instance: [cluster-id] %s, [instance-id] %s, [status] %s",
+                                clusterId, instanceId, context.getStatus().toString()));
                     }
                     if (context.getStatus() == status) {
                         clusterStat = true;
@@ -131,5 +130,4 @@ public abstract class GroupStatusProcessor extends StatusProcessor {
         }
         return clusterStat;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/87b4471e/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
index fc1a736..4382d8b 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/group/GroupStatusTerminatedProcessor.java
@@ -42,8 +42,7 @@ public class GroupStatusTerminatedProcessor extends GroupStatusProcessor {
     }
 
     @Override
-    public boolean process(String idOfComponent, String appId,
-                           String instanceId) {
+    public boolean process(String idOfComponent, String appId, String instanceId) {
         boolean statusChanged;
         statusChanged = doProcess(idOfComponent, appId, instanceId);
         if (statusChanged) {
@@ -55,8 +54,8 @@ public class GroupStatusTerminatedProcessor extends GroupStatusProcessor {
             return nextProcessor.process(idOfComponent, appId, instanceId);
         } else {
 
-            log.warn(String.format("No possible state change found for [component] %s [instance] %s",
-                    idOfComponent, instanceId));
+            log.warn(String.format("No possible state change found for [component] %s [instance] %s", idOfComponent,
+                    instanceId));
         }
         return false;
     }
@@ -68,13 +67,12 @@ public class GroupStatusTerminatedProcessor extends GroupStatusProcessor {
         Map<String, ClusterDataHolder> clusterData;
 
         if (log.isDebugEnabled()) {
-            log.debug("StatusChecker calculating the terminated status for the group " +
-                    "[ " + idOfComponent + " ] " + " for the instance " + " [ " + instanceId + " ]");
+            log.debug(String.format(
+                    "GroupStatusTerminatedProcessor is calculating the terminated status for [group-id] %s "
+                            + "[instance-id] %s", idOfComponent, instanceId));
         }
-
+        ApplicationHolder.acquireWriteLock();
         try {
-            ApplicationHolder.acquireWriteLock();
-
             Application application = ApplicationHolder.getApplications().
                     getApplication(appId);
             component = application;
@@ -88,32 +86,28 @@ public class GroupStatusTerminatedProcessor extends GroupStatusProcessor {
             groups = component.getAliasToGroupMap();
             clusterData = component.getClusterDataMap();
 
-            if (groups.isEmpty() &&
-                    getAllClusterInSameState(clusterData, ClusterStatus.Terminated, instanceId) ||
-                    clusterData.isEmpty() &&
-                            getAllGroupInSameState(groups, GroupStatus.Terminated, instanceId) ||
-                    getAllClusterInSameState(clusterData, ClusterStatus.Terminated, instanceId) &&
-                            getAllGroupInSameState(groups, GroupStatus.Terminated, instanceId)) {
+            if (groups.isEmpty() && getAllClusterInSameState(clusterData, ClusterStatus.Terminated, instanceId) ||
+                    clusterData.isEmpty() && getAllGroupInSameState(groups, GroupStatus.Terminated, instanceId) ||
+                    getAllClusterInSameState(clusterData, ClusterStatus.Terminated, instanceId)
+                            && getAllGroupInSameState(groups, GroupStatus.Terminated, instanceId)) {
                 //send the terminated event
                 if (component instanceof Application) {
-                    log.info("Sending application instance terminated for [application] " + appId
-                            + " [instance] " + instanceId);
+                    log.info(String.format(
+                            "Sending application instance terminated for [application-id] %s, [instance-id] %s", appId,
+                            instanceId));
                     ApplicationBuilder.handleApplicationInstanceTerminatedEvent(appId, instanceId);
                     return true;
                 } else {
-                    log.info("Sending group instance terminated for [group] " +
-                            component.getUniqueIdentifier() + " [instance] " + instanceId);
-                    ApplicationBuilder.handleGroupInstanceTerminatedEvent(appId,
-                            component.getUniqueIdentifier(), instanceId);
+                    log.info(String.format("Sending group instance terminated for [group-id] %s, [instance-id] %s",
+                            component.getUniqueIdentifier(), instanceId));
+                    ApplicationBuilder
+                            .handleGroupInstanceTerminatedEvent(appId, component.getUniqueIdentifier(), instanceId);
                     return true;
                 }
             }
         } finally {
             ApplicationHolder.releaseWriteLock();
-
         }
         return false;
     }
-
-
 }


[10/28] stratos git commit: Add const for REPO_NOTIFY_NAME entity

Posted by ra...@apache.org.
Add const for REPO_NOTIFY_NAME entity


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

Branch: refs/heads/stratos-4.1.x
Commit: 6b5b847f55d8b011347935f7b22ab2e6acdaaf2a
Parents: 6adcd8c
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:08:30 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../java/org/apache/stratos/integration/common/RestConstants.java   | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6b5b847f/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
index aa2a220..7467e5d 100644
--- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/RestConstants.java
@@ -35,6 +35,7 @@ public class RestConstants {
     public static final String APPLICATIONS_DEPLOY = "/deploy";
     public static final String APPLICATIONS_UNDEPLOY = "/undeploy";
     public static final String REPO_NOTIFY = "/" + API + "/repo/notify";
+    public static final String REPO_NOTIFY_NAME = "GitHook";
 
     public static final String AUTOSCALING_POLICIES_PATH = "/autoscaling-policies/";
     public static final String AUTOSCALING_POLICIES_NAME = "autoscalingPolicy";


[23/28] stratos git commit: Catch a generic Exception in MetadataApi

Posted by ra...@apache.org.
Catch a generic Exception in MetadataApi


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

Branch: refs/heads/stratos-4.1.x
Commit: 272210bbb9c4df3f2b566b583a0702ff4f728d02
Parents: a9ed3c5
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:21:10 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../stratos/metadata/service/api/MetadataApi.java | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/272210bb/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
index 53174e0..053e030 100644
--- a/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
+++ b/components/org.apache.stratos.metadata.service/src/main/java/org/apache/stratos/metadata/service/api/MetadataApi.java
@@ -68,7 +68,7 @@ public class MetadataApi {
                 propertiesArr = new Property[properties.size()];
                 propertiesArr = properties.toArray(propertiesArr);
             }
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = "Error occurred while getting properties ";
             log.error(msg, e);
             throw new RestAPIException(msg, e);
@@ -98,7 +98,7 @@ public class MetadataApi {
                 propertiesArr = new Property[properties.size()];
                 propertiesArr = properties.toArray(propertiesArr);
             }
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = "Error occurred while getting properties ";
             log.error(msg, e);
             throw new RestAPIException(msg, e);
@@ -133,7 +133,7 @@ public class MetadataApi {
                     break;
                 }
             }
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = "Error occurred while getting property";
             log.error(msg, e);
             throw new RestAPIException(msg, e);
@@ -169,7 +169,7 @@ public class MetadataApi {
                     break;
                 }
             }
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = "Error occurred while getting property";
             log.error(msg, e);
             throw new RestAPIException(msg, e);
@@ -194,7 +194,7 @@ public class MetadataApi {
 
         try {
             registry.addPropertyToApplication(applicationId, property);
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = "Error occurred while adding properties ";
             log.error(msg, e);
             throw new RestAPIException(msg, e);
@@ -212,7 +212,7 @@ public class MetadataApi {
 
         try {
             registry.addPropertyToCluster(applicationId, clusterId, property);
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = "Error occurred while adding properties ";
             log.error(msg, e);
             throw new RestAPIException(msg, e);
@@ -232,7 +232,7 @@ public class MetadataApi {
             if (!deleted) {
                 log.warn(String.format("No metadata is associated with given appId %s", applicationId));
             }
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = "Resource attached with appId could not be deleted [application-id] " + applicationId;
             log.error(msg, e);
             throw new RestAPIException(msg, e);
@@ -252,7 +252,7 @@ public class MetadataApi {
             if (!deleted) {
                 log.warn(String.format("No metadata is associated with given appId %s", applicationId));
             }
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = String
                     .format("[application-id] %s [property-name] %s deletion failed ", applicationId, propertyName);
             log.error(msg, e);
@@ -274,7 +274,7 @@ public class MetadataApi {
             if (!deleted) {
                 log.warn(String.format("No metadata is associated with given [application-id] %s", applicationId));
             }
-        } catch (RegistryException e) {
+        } catch (Exception e) {
             String msg = String
                     .format("[application-id] %s [property-name] %s [value] %s deletion failed" + applicationId,
                             propertyName, propertyValue);


[17/28] stratos git commit: Cleaning up test cases. Remove duplicate assertions. Fix formatting.

Posted by ra...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
index 581115a..29566f6 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationsTestCase.java
@@ -41,32 +41,37 @@ import static org.testng.AssertJUnit.assertTrue;
 /**
  * Sample application tests with application add, .
  */
+@Test(groups = { "application" })
 public class SampleApplicationsTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(SampleApplicationsTestCase.class);
     private static final String RESOURCES_PATH = "/sample-applications-test";
+    long startTime;
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT,
+          priority = 1)
     public void testApplication() throws Exception {
-        String autoscalingPolicyId = "autoscaling-policy-sample-applications-test";
+        startTime = System.currentTimeMillis();
+        log.info("Running SampleApplicationsTestCase.testApplication test method...");
 
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        String autoscalingPolicyId = "autoscaling-policy-sample-applications-test";
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertEquals(addedScalingPolicy, true);
 
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertEquals(addedC1, true);
 
-        boolean addedC2 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC2 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertEquals(addedC2, true);
 
-        boolean addedC3 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC3 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertEquals(addedC3, true);
 
         boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
@@ -75,23 +80,23 @@ public class SampleApplicationsTestCase extends StratosIntegrationTest {
         assertEquals(addedG1, true);
 
         CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
+                getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test", CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
         assertEquals(beanG1.getName(), "G1-sample-applications-test");
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        "network-partition-sample-applications-test-1.json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                        "network-partition-sample-applications-test-1.json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(addedN1, true);
 
         boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        "network-partition-sample-applications-test-2.json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                        "network-partition-sample-applications-test-2.json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(addedN2, true);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        "deployment-policy-sample-applications-test.json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        "deployment-policy-sample-applications-test.json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertEquals(addedDep, true);
 
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
@@ -99,8 +104,9 @@ public class SampleApplicationsTestCase extends StratosIntegrationTest {
                 RestConstants.APPLICATIONS_NAME);
         assertEquals(added, true);
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                "g-sc-G123-1-sample-applications-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-sample-applications-test", ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), "g-sc-G123-1-sample-applications-test");
 
         CartridgeGroupReferenceBean group1 = bean.getComponents().getGroups().get(0);
@@ -138,12 +144,13 @@ public class SampleApplicationsTestCase extends StratosIntegrationTest {
         assertEquals(c3.getCartridgeMax(), 2);
 
         boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH +
-                        "/g-sc-G123-1-sample-applications-test-v1.json",
-                RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
+                        "/g-sc-G123-1-sample-applications-test-v1.json", RestConstants.APPLICATIONS,
+                RestConstants.APPLICATIONS_NAME);
         assertEquals(updated, true);
 
-        ApplicationBean updatedBean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                "g-sc-G123-1-sample-applications-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean updatedBean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-sample-applications-test", ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
 
         assertEquals(bean.getApplicationId(), "g-sc-G123-1-sample-applications-test");
 
@@ -181,224 +188,226 @@ public class SampleApplicationsTestCase extends StratosIntegrationTest {
         assertEquals(c3.getCartridgeMin(), 2);
         assertEquals(c3.getCartridgeMax(), 3);
 
-
-        boolean removedGroup =
-                restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
-                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
+                RestConstants.CARTRIDGE_GROUPS_NAME);
         assertFalse(removedGroup);
 
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertFalse(removedAuto);
 
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-sample-applications-test-1",
-                RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-applications-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         //Trying to remove the used network partition
         assertFalse(removedNet);
 
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                "deployment-policy-sample-applications-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient
+                .removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-sample-applications-test",
+                        RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertFalse(removedDep);
 
-        boolean removed =
-                restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-sample-applications-test",
-                        RestConstants.APPLICATIONS_NAME);
+        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-sample-applications-test",
+                RestConstants.APPLICATIONS_NAME);
         assertTrue(removed);
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                "g-sc-G123-1-sample-applications-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, "g-sc-G123-1-sample-applications-test", ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertNull(beanRemoved);
 
         removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
                 RestConstants.CARTRIDGE_GROUPS_NAME);
         assertEquals(removedGroup, true);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-sample-applications-test",
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c1-sample-applications-test", RestConstants.CARTRIDGES_NAME);
         assertEquals(removedC1, true);
 
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2-sample-applications-test",
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c2-sample-applications-test", RestConstants.CARTRIDGES_NAME);
         assertEquals(removedC2, true);
 
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3-sample-applications-test",
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c3-sample-applications-test", RestConstants.CARTRIDGES_NAME);
         assertEquals(removedC3, true);
 
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertEquals(removedAuto, true);
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                "deployment-policy-sample-applications-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
+        removedDep = restClient
+                .removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-sample-applications-test",
+                        RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertEquals(removedDep, true);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-sample-applications-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+        removedNet = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-applications-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         assertEquals(removedNet, true);
 
-        boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-sample-applications-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
-        assertEquals(removedN2, true, String.format(
-                "[Network partition] network-partition-sample-applications-test-2 could not be removed for " +
-                        "[application] g-sc-G123-1-sample-applications-test"));
+        boolean removedN2 = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-applications-test-2",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
+        assertEquals(removedN2, true,
+                "[Network partition] network-partition-sample-applications-test-2 could not be removed for "
+                        + "[application] g-sc-G123-1-sample-applications-test");
     }
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT,
+          priority = 2)
     public void testApplicationList() throws Exception {
-            String autoscalingPolicyId = "autoscaling-policy-sample-applications-test";
-
-            boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                            + "/" + autoscalingPolicyId + ".json",
-                    RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
-            assertEquals(addedScalingPolicy, true);
-
-            boolean addedC1 = restClient.addEntity(
-                    RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json",
-                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-            assertEquals(addedC1, true);
-
-            boolean addedC2 = restClient.addEntity(
-                    RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json",
-                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-            assertEquals(addedC2, true);
-
-            boolean addedC3 = restClient.addEntity(
-                    RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json",
-                    RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-            assertEquals(addedC3, true);
-
-            boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                            "/" + "cartridge-nested-sample-applications-test.json", RestConstants.CARTRIDGE_GROUPS,
-                    RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(addedG1, true);
-
-            CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
-                    getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
-                            CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(beanG1.getName(), "G1-sample-applications-test");
-
-            boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                            "network-partition-sample-applications-test-1.json",
-                    RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
-            assertEquals(addedN1, true);
-
-            boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                            "network-partition-sample-applications-test-2.json",
-                    RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
-            assertEquals(addedN2, true);
-
-            boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                            "deployment-policy-sample-applications-test.json",
-                    RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
-            assertEquals(addedDep, true);
-
-            String app1 = "sample-applications-test-1";
-            String app2 = "sample-applications-test-2";
-            boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                            app1 + ".json", RestConstants.APPLICATIONS,
-                    RestConstants.APPLICATIONS_NAME);
-            assertEquals(added, true);
-
-            added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                            app2 + ".json", RestConstants.APPLICATIONS,
-                    RestConstants.APPLICATIONS_NAME);
-            assertEquals(added, true);
-
-            Type listType = new TypeToken<ArrayList<ApplicationBean>>() {
-            }.getType();
-
-            List<ApplicationBean> applicationList = (List<ApplicationBean>) restClient.
-                    listEntity(RestConstants.APPLICATIONS,
-                            listType, RestConstants.APPLICATIONS_NAME);
-            assertTrue(applicationList.size() >= 2);
-
-
-            ApplicationBean bean1 = null;
-            for (ApplicationBean applicationBean : applicationList) {
-                if (applicationBean.getApplicationId().equals(app1)) {
-                    bean1 = applicationBean;
-                }
-            }
-            assertNotNull(bean1);
+        log.info("Running SampleApplicationsTestCase.testApplicationList test method...");
 
-            ApplicationBean bean2 = null;
-            for (ApplicationBean applicationBean : applicationList) {
-                if (applicationBean.getApplicationId().equals(app2)) {
-                    bean2 = applicationBean;
-                }
+        String autoscalingPolicyId = "autoscaling-policy-sample-applications-test";
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
+                RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
+        assertEquals(addedScalingPolicy, true);
+
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c1-sample-applications-test.json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertEquals(addedC1, true);
+
+        boolean addedC2 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c2-sample-applications-test.json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertEquals(addedC2, true);
+
+        boolean addedC3 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c3-sample-applications-test.json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertEquals(addedC3, true);
+
+        boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+                        "/" + "cartridge-nested-sample-applications-test.json", RestConstants.CARTRIDGE_GROUPS,
+                RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertEquals(addedG1, true);
+
+        CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
+                getEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test", CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertEquals(beanG1.getName(), "G1-sample-applications-test");
+
+        boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                        "network-partition-sample-applications-test-1.json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
+        assertEquals(addedN1, true);
+
+        boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
+                        "network-partition-sample-applications-test-2.json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
+        assertEquals(addedN2, true);
+
+        boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
+                        "deployment-policy-sample-applications-test.json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
+        assertEquals(addedDep, true);
+
+        String app1 = "sample-applications-test-1";
+        String app2 = "sample-applications-test-2";
+        boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
+                app1 + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
+        assertEquals(added, true);
+
+        added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
+                app2 + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
+        assertEquals(added, true);
+
+        Type listType = new TypeToken<ArrayList<ApplicationBean>>() {
+        }.getType();
+
+        List<ApplicationBean> applicationList = (List<ApplicationBean>) restClient.
+                listEntity(RestConstants.APPLICATIONS, listType, RestConstants.APPLICATIONS_NAME);
+        assertTrue(applicationList.size() >= 2);
+
+        ApplicationBean bean1 = null;
+        for (ApplicationBean applicationBean : applicationList) {
+            if (applicationBean.getApplicationId().equals(app1)) {
+                bean1 = applicationBean;
             }
-            assertNotNull(bean2);
+        }
+        assertNotNull(bean1);
 
+        ApplicationBean bean2 = null;
+        for (ApplicationBean applicationBean : applicationList) {
+            if (applicationBean.getApplicationId().equals(app2)) {
+                bean2 = applicationBean;
+            }
+        }
+        assertNotNull(bean2);
 
-            boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, app1,
-                    RestConstants.APPLICATIONS_NAME);
-            assertTrue(removed);
+        boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
+                RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertFalse(removedGroup);
 
-            ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                    app1, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
-            assertNull(beanRemoved);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
+        assertFalse(removedAuto);
 
-            boolean removedGroup =
-                    restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
-                            RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertFalse(removedGroup);
+        boolean removedNet = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-applications-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
+        //Trying to remove the used network partition
+        assertFalse(removedNet);
 
-            boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                    autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-            assertFalse(removedAuto);
+        boolean removedDep = restClient
+                .removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-sample-applications-test",
+                        RestConstants.DEPLOYMENT_POLICIES_NAME);
+        assertFalse(removedDep);
 
-            boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                    "network-partition-sample-applications-test-1",
-                    RestConstants.NETWORK_PARTITIONS_NAME);
-            //Trying to remove the used network partition
-            assertFalse(removedNet);
+        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, app1, RestConstants.APPLICATIONS_NAME);
+        assertTrue(removed);
 
-            boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                    "deployment-policy-sample-applications-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
-            assertFalse(removedDep);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, app1, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        assertNull(beanRemoved);
 
-            removed = restClient.removeEntity(RestConstants.APPLICATIONS, app2,
-                    RestConstants.APPLICATIONS_NAME);
-            assertTrue(removed);
+        removed = restClient.removeEntity(RestConstants.APPLICATIONS, app2, RestConstants.APPLICATIONS_NAME);
+        assertTrue(removed);
 
-            beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                    app2, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
-            assertNull(beanRemoved);
+        beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, app2, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        assertNull(beanRemoved);
 
-            removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
-                    RestConstants.CARTRIDGE_GROUPS_NAME);
-            assertEquals(removedGroup, true);
+        removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G1-sample-applications-test",
+                RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertEquals(removedGroup, true);
 
-            boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-sample-applications-test",
-                    RestConstants.CARTRIDGES_NAME);
-            assertEquals(removedC1, true);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c1-sample-applications-test", RestConstants.CARTRIDGES_NAME);
+        assertEquals(removedC1, true);
 
-            boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c2-sample-applications-test",
-                    RestConstants.CARTRIDGES_NAME);
-            assertEquals(removedC2, true);
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c2-sample-applications-test", RestConstants.CARTRIDGES_NAME);
+        assertEquals(removedC2, true);
 
-            boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c3-sample-applications-test",
-                    RestConstants.CARTRIDGES_NAME);
-            assertEquals(removedC3, true);
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c3-sample-applications-test", RestConstants.CARTRIDGES_NAME);
+        assertEquals(removedC3, true);
 
-            removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                    autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-            assertEquals(removedAuto, true);
+        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
+        assertEquals(removedAuto, true);
 
-            removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                    "deployment-policy-sample-applications-test", RestConstants.DEPLOYMENT_POLICIES_NAME);
-            assertEquals(removedDep, true);
+        removedDep = restClient
+                .removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-sample-applications-test",
+                        RestConstants.DEPLOYMENT_POLICIES_NAME);
+        assertEquals(removedDep, true);
 
-            removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                    "network-partition-sample-applications-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
-            assertEquals(removedNet, true);
+        removedNet = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-applications-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
+        assertEquals(removedNet, true);
 
-            boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                    "network-partition-sample-applications-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
-            assertEquals(removedN2, true, String.format(
-                    "[Network partition] network-partition-sample-applications-test-2 could not be removed for " +
-                            "[application] g-sc-G123-1-sample-applications-test"));
+        boolean removedN2 = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-applications-test-2",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
+        assertEquals(removedN2, true,
+                "[Network partition] network-partition-sample-applications-test-2 could not be removed for "
+                        + "[application] g-sc-G123-1-sample-applications-test");
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("SampleApplicationsTestCase completed in [duration] %s ms", duration));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
index 3ea53e7..7e0ac78 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SingleClusterScalingTestCase.java
@@ -21,12 +21,10 @@ package org.apache.stratos.integration.tests.application;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.application.ApplicationBean;
-import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
 import org.apache.stratos.messaging.domain.application.Application;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
 import org.apache.stratos.messaging.domain.instance.ClusterInstance;
 import org.apache.stratos.messaging.domain.topology.Cluster;
@@ -40,15 +38,14 @@ import org.testng.annotations.Test;
 
 import java.util.Set;
 
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNull;
+import static org.testng.Assert.*;
 import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertTrue;
 
 /**
  * This will handle the scale-up and scale-down of a particular cluster bursting test cases
  */
+@Test(groups = { "application", "scale" })
 public class SingleClusterScalingTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(SingleClusterScalingTestCase.class);
     private static final String RESOURCES_PATH = "/single-cluster-scaling-test";
@@ -61,38 +58,39 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
     private static final int CLUSTER_SCALE_UP_TIMEOUT = 180000;
     private static final int CLUSTER_SCALE_DOWN_TIMEOUT = 360000;
     private int activeInstancesAfterScaleup = 0;
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testDeployApplication() throws Exception {
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
+        log.info("Running SingleClusterScalingTestCase.testDeployApplication test method...");
+        long startTime = System.currentTimeMillis();
 
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         Assert.assertTrue(addedScalingPolicy);
 
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         Assert.assertTrue(addedC1);
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         Assert.assertTrue(addedN1);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         Assert.assertTrue(addedDep);
 
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        applicationId + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+                applicationId + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(added);
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), applicationId);
 
         boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
@@ -103,13 +101,11 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
         //deploy the application
         String resourcePath = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId;
-        boolean deployed = restClient.deployEntity(resourcePath,
-                RestConstants.APPLICATIONS_NAME);
+        boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(deployed);
 
         //Application active handling
-        topologyHandler.assertApplicationStatus(bean.getApplicationId()
-                , ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         //Cluster active handling
         topologyHandler.assertClusterActivation(bean.getApplicationId());
@@ -123,26 +119,24 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
         //Check whether cluster could scale-down upto the minimum
         assertClusterScaleDownToMinimumCount(bean.getApplicationId());
 
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertFalse(removedAuto);
 
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId,
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
                 RestConstants.NETWORK_PARTITIONS_NAME);
         //Trying to remove the used network partition
         assertFalse(removedNet);
 
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertFalse(removedDep);
 
         //Un-deploying the application
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
-                RestConstants.APPLICATIONS_NAME);
+        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(unDeployed);
 
         boolean undeploy = topologyHandler.assertApplicationUndeploy(applicationId);
@@ -150,45 +144,48 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
             //Need to forcefully undeploy the application
             log.info(String.format("Force undeployment is going to start for the [application] %s", applicationId));
 
-            restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId+
+            restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId +
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = topologyHandler.assertApplicationUndeploy(applicationId);
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    applicationId), forceUndeployed);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId),
+                    forceUndeployed);
         }
 
-        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removed = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(removed);
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertNull(beanRemoved);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId, RestConstants.CARTRIDGES_NAME);
         Assert.assertTrue(removedC1);
 
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         Assert.assertTrue(removedAuto);
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         Assert.assertTrue(removedDep);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME);
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertFalse(removedNet);
 
-        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         Assert.assertTrue(removeAppPolicy);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME);
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         Assert.assertTrue(removedNet);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("SingleClusterScalingTestCase completed in [duration] %s ms", duration));
     }
 
     /**
@@ -198,24 +195,22 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
      */
     private void assertClusterWithScalingup(String applicationName) {
         Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s",
-                applicationName), application);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
         boolean clusterScaleup = false;
         String clusterId = null;
         long startTime = System.currentTimeMillis();
         while (!clusterScaleup) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
             for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
                 String serviceName = clusterDataHolder.getServiceType();
                 clusterId = clusterDataHolder.getClusterId();
                 Service service = TopologyManager.getTopology().getService(serviceName);
-                assertNotNull(String.format("Service is not found: [application-id] %s [service] %s",
-                        applicationName, serviceName), service);
+                assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName,
+                        serviceName), service);
 
                 Cluster cluster = service.getCluster(clusterId);
                 assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
@@ -252,24 +247,22 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
      */
     private void assertClusterWithScaleDown(String applicationName) {
         Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s",
-                applicationName), application);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
         boolean clusterScaleDown = false;
         String clusterId = null;
         long startTime = System.currentTimeMillis();
         while (!clusterScaleDown) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
             for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
                 String serviceName = clusterDataHolder.getServiceType();
                 clusterId = clusterDataHolder.getClusterId();
                 Service service = TopologyManager.getTopology().getService(serviceName);
-                assertNotNull(String.format("Service is not found: [application-id] %s [service] %s",
-                        applicationName, serviceName), service);
+                assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName,
+                        serviceName), service);
 
                 Cluster cluster = service.getCluster(clusterId);
                 assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
@@ -312,24 +305,22 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
      */
     private void assertClusterScaleDownToMinimumCount(String applicationName) {
         Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s",
-                applicationName), application);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
         boolean clusterScaleDown = false;
         String clusterId = null;
         long startTime = System.currentTimeMillis();
         while (!clusterScaleDown) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
             for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
                 String serviceName = clusterDataHolder.getServiceType();
                 clusterId = clusterDataHolder.getClusterId();
                 Service service = TopologyManager.getTopology().getService(serviceName);
-                assertNotNull(String.format("Service is not found: [application-id] %s [service] %s",
-                        applicationName, serviceName), service);
+                assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName,
+                        serviceName), service);
 
                 Cluster cluster = service.getCluster(clusterId);
                 assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
@@ -357,4 +348,4 @@ public class SingleClusterScalingTestCase extends StratosIntegrationTest {
         assertEquals(clusterScaleDown, true,
                 String.format("Cluster did not get scaled up: [cluster-id] %s", clusterId));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeGroupTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeGroupTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeGroupTestCase.java
new file mode 100644
index 0000000..7cbf603
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeGroupTestCase.java
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.integration.tests.cartridge;
+
+import com.google.gson.reflect.TypeToken;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
+import org.apache.stratos.integration.common.RestConstants;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.testng.annotations.Test;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.AssertJUnit.*;
+
+/**
+ * Test to handle Cartridge group CRUD operations
+ */
+@Test(groups = { "cartridge" })
+public class CartridgeGroupTestCase extends StratosIntegrationTest {
+    private static final Log log = LogFactory.getLog(CartridgeGroupTestCase.class);
+    private static final String RESOURCES_PATH = "/cartridge-group-test";
+    private long startTime;
+
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT,
+          priority = 1)
+    public void testCartridgeGroup() throws Exception {
+        log.info("Running CartridgeGroupTestCase.testCartridgeGroup test method...");
+        startTime = System.currentTimeMillis();
+
+        boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+                "/" + "c4-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", "c4-cartridge-group-test"), addedC1);
+
+        boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+                "/" + "c5-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", "c5-cartridge-group-test"), addedC2);
+
+        boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+                "/" + "c6-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", "c6-cartridge-group-test"), addedC3);
+
+        boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+                        "/" + "g4-g5-g6-cartridge-group-test.json", RestConstants.CARTRIDGE_GROUPS,
+                RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
+                "g4-g5-g6-cartridge-group-test"), added);
+
+        CartridgeGroupBean bean = (CartridgeGroupBean) restClient.
+                getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertEquals(bean.getName(), "G4-cartridge-group-test",
+                String.format("Cartridge Group name did not match: [cartridge-group-name] %s",
+                        "g4-g5-g6-cartridge-group-test.json"));
+
+        boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+                        "/" + "g4-g5-g6-cartridge-group-test-v1.json", RestConstants.CARTRIDGE_GROUPS,
+                RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge Group did not updated: [cartridge-group-name] %s",
+                "g4-g5-g6-cartridge-group-test"), updated);
+
+        CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClient.
+                getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertEquals(updatedBean.getName(), "G4-cartridge-group-test",
+                String.format("Updated Cartridge Group didn't match: [cartridge-group-name] %s",
+                        "g4-g5-g6-cartridge-group-test"));
+
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertFalse(
+                String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s",
+                        "c4-cartridge-group-test"), removedC1);
+
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertFalse(
+                String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s",
+                        "c5-cartridge-group-test"), removedC2);
+
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertFalse(
+                String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s",
+                        "c6-cartridge-group-test"), removedC3);
+
+        boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
+                RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
+                "g4-g5-g6-cartridge-group-test"), removed);
+
+        CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
+                getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test", CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertEquals(beanRemoved, null,
+                String.format("Cartridge Group did not removed completely: [cartridge-group-name] %s",
+                        "g4-g5-g6-cartridge-group-test"));
+
+        removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", "c4-cartridge-group-test"),
+                removedC1);
+
+        removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", "c5-cartridge-group-test"),
+                removedC2);
+
+        removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", "c6-cartridge-group-test"),
+                removedC3);
+    }
+
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT,
+          priority = 2)
+    public void testCartridgeGroupList() throws Exception {
+        log.info("Running CartridgeGroupTestCase.testCartridgeGroupList test method...");
+        boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+                "/" + "c4-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", "c4-cartridge-group-test"), addedC1);
+
+        boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+                "/" + "c5-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", "c5-cartridge-group-test"), addedC2);
+
+        boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
+                "/" + "c6-cartridge-group-test.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s", "c6-cartridge-group-test"), addedC3);
+
+        String group1 = "group-1-cartridge-group-test";
+        String group2 = "group-2-cartridge-group-test";
+
+        boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+                "/" + group1 + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s", group1), added);
+
+        added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
+                "/" + group2 + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s", group1), added);
+
+        Type listType = new TypeToken<ArrayList<CartridgeGroupBean>>() {
+        }.getType();
+
+        List<CartridgeGroupBean> cartridgeGroupList = (List<CartridgeGroupBean>) restClient.
+                listEntity(RestConstants.CARTRIDGE_GROUPS, listType, RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(cartridgeGroupList.size() >= 2);
+
+        CartridgeGroupBean bean1 = null;
+        for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
+            if (cartridgeGroupBean.getName().equals(group1)) {
+                bean1 = cartridgeGroupBean;
+            }
+        }
+        assertNotNull(bean1);
+
+        CartridgeGroupBean bean2 = null;
+        for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
+            if (cartridgeGroupBean.getName().equals(group2)) {
+                bean2 = cartridgeGroupBean;
+            }
+        }
+        assertNotNull(bean2);
+
+        boolean removed = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, group1, RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", group1), removed);
+
+        CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
+                getEntity(RestConstants.CARTRIDGE_GROUPS, group1, CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertNull(String.format("Cartridge Group did not removed completely: " + "[cartridge-group-name] %s", group1),
+                beanRemoved);
+
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertFalse(
+                String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s",
+                        "c4-cartridge-group-test"), removedC1);
+
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertFalse(
+                String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s",
+                        "c5-cartridge-group-test"), removedC2);
+
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertFalse(
+                String.format("Cartridge can be removed while it is used in " + "cartridge group: [cartridge-name] %s",
+                        "c6-cartridge-group-test"), removedC3);
+
+        removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group2, RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s", group2), removed);
+
+        beanRemoved = (CartridgeGroupBean) restClient.
+                getEntity(RestConstants.CARTRIDGE_GROUPS, group2, CartridgeGroupBean.class,
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertNull(String.format("Cartridge Group did not removed completely: " + "[cartridge-group-name] %s", group2),
+                beanRemoved);
+
+        removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", "c4-cartridge-group-test"),
+                removedC1);
+
+        removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", "c5-cartridge-group-test"),
+                removedC2);
+
+        removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test", RestConstants.CARTRIDGE_GROUPS_NAME);
+        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s", "c6-cartridge-group-test"),
+                removedC3);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("ApplicationBurstingTestCase completed in [duration] %s ms", duration));
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeTestCase.java
new file mode 100644
index 0000000..3672373
--- /dev/null
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/cartridge/CartridgeTestCase.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.stratos.integration.tests.cartridge;
+
+import com.google.gson.reflect.TypeToken;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.beans.PropertyBean;
+import org.apache.stratos.common.beans.cartridge.CartridgeBean;
+import org.apache.stratos.integration.common.RestConstants;
+import org.apache.stratos.integration.tests.StratosIntegrationTest;
+import org.testng.annotations.Test;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
+/**
+ * Test to handle Cartridge CRUD operations
+ */
+@Test(groups = { "cartridge" })
+public class CartridgeTestCase extends StratosIntegrationTest {
+    private static final Log log = LogFactory.getLog(CartridgeTestCase.class);
+    private static final String RESOURCES_PATH = "/cartridge-test";
+    private long startTime;
+
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT,
+          priority = 1)
+    public void testCartridge() throws Exception {
+        log.info("Running CartridgeTestCase.testCartridge test method...");
+        startTime = System.currentTimeMillis();
+
+        String cartridgeType = "c0-cartridge-test";
+        boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
+                cartridgeType + ".json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(added);
+        CartridgeBean bean = (CartridgeBean) restClient.
+                getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
+        assertEquals(bean.getCategory(), "Application");
+        assertEquals(bean.getHost(), "qmog.cisco.com");
+        for (PropertyBean property : bean.getProperty()) {
+            if (property.getName().equals("payload_parameter.CEP_IP")) {
+                assertEquals(property.getValue(), "octl.qmog.cisco.com");
+            } else if (property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) {
+                assertEquals(property.getValue(), "admin");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) {
+                assertEquals(property.getValue(), "octl.qmog.cisco.com");
+            } else if (property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) {
+                assertEquals(property.getValue(), "1");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) {
+                assertEquals(property.getValue(), "admin");
+            } else if (property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) {
+                assertEquals(property.getValue(), "test");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) {
+                assertEquals(property.getValue(), "7711");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) {
+                assertEquals(property.getValue(), "7611");
+            } else if (property.getName().equals("payload_parameter.CEP_PORT")) {
+                assertEquals(property.getValue(), "7611");
+            } else if (property.getName().equals("payload_parameter.MB_PORT")) {
+                assertEquals(property.getValue(), "61616");
+            }
+        }
+
+        boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
+                cartridgeType + "-v1.json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(updated);
+        CartridgeBean updatedBean = (CartridgeBean) restClient.
+                getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
+        assertEquals(updatedBean.getType(), "c0-cartridge-test");
+        assertEquals(updatedBean.getCategory(), "Data");
+        assertEquals(updatedBean.getHost(), "qmog.cisco.com12");
+        for (PropertyBean property : updatedBean.getProperty()) {
+            if (property.getName().equals("payload_parameter.CEP_IP")) {
+                assertEquals(property.getValue(), "octl.qmog.cisco.com123");
+            } else if (property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) {
+                assertEquals(property.getValue(), "admin123");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) {
+                assertEquals(property.getValue(), "octl.qmog.cisco.com123");
+            } else if (property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) {
+                assertEquals(property.getValue(), "3");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) {
+                assertEquals(property.getValue(), "admin123");
+            } else if (property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) {
+                assertEquals(property.getValue(), "test123");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) {
+                assertEquals(property.getValue(), "7712");
+            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) {
+                assertEquals(property.getValue(), "7612");
+            } else if (property.getName().equals("payload_parameter.CEP_PORT")) {
+                assertEquals(property.getValue(), "7612");
+            } else if (property.getName().equals("payload_parameter.MB_PORT")) {
+                assertEquals(property.getValue(), "61617");
+            }
+        }
+
+        boolean removed = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeType, RestConstants.CARTRIDGES_NAME);
+        assertTrue(removed);
+
+        CartridgeBean beanRemoved = (CartridgeBean) restClient.
+                getEntity(RestConstants.CARTRIDGES, cartridgeType, CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
+        assertNull(beanRemoved);
+    }
+
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT,
+          priority = 2)
+    public void testCartridgeList() throws Exception {
+        log.info("Running CartridgeTestCase.testCartridgeList test method...");
+
+        String cartridgeType1 = "c1-cartridge-test";
+        String cartridgeType2 = "c2-cartridge-test";
+        boolean added1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
+                cartridgeType1 + ".json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(added1);
+
+        boolean added2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
+                cartridgeType2 + ".json", RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        assertTrue(added2);
+
+        Type listType = new TypeToken<ArrayList<CartridgeBean>>() {
+        }.getType();
+
+        List<CartridgeBean> cartridgeList = (List<CartridgeBean>) restClient
+                .listEntity(RestConstants.CARTRIDGES, listType, RestConstants.CARTRIDGES_NAME);
+        assertTrue(cartridgeList.size() >= 2);
+
+        CartridgeBean bean1 = null;
+        for (CartridgeBean cartridgeBean : cartridgeList) {
+            if (cartridgeBean.getType().equals(cartridgeType1)) {
+                bean1 = cartridgeBean;
+            }
+        }
+        assertNotNull(bean1);
+
+        CartridgeBean bean2 = null;
+        for (CartridgeBean cartridgeBean : cartridgeList) {
+            if (cartridgeBean.getType().equals(cartridgeType1)) {
+                bean2 = cartridgeBean;
+            }
+        }
+        assertNotNull(bean2);
+
+        boolean removed = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeType1, RestConstants.CARTRIDGES_NAME);
+        assertTrue(removed);
+
+        CartridgeBean beanRemoved = (CartridgeBean) restClient.
+                getEntity(RestConstants.CARTRIDGES, cartridgeType1, CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
+        assertEquals(beanRemoved, null);
+
+        removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType2, RestConstants.CARTRIDGES_NAME);
+        assertTrue(removed);
+
+        beanRemoved = (CartridgeBean) restClient.
+                getEntity(RestConstants.CARTRIDGES, cartridgeType2, CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
+        assertNull(beanRemoved);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("CartridgeTestCase completed in [duration] %s ms", duration));
+    }
+}


[18/28] stratos git commit: Cleaning up test cases. Remove duplicate assertions. Fix formatting.

Posted by ra...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTestCase.java
index 7ef911f..d7b400a 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/GroupTerminationBehaviorTestCase.java
@@ -22,11 +22,9 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.application.ApplicationBean;
 import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
-import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.topology.Member;
 import org.testng.annotations.Test;
 
@@ -36,14 +34,15 @@ import java.util.Map;
 
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
-import static org.testng.AssertJUnit.assertFalse;
 import static org.testng.AssertJUnit.assertTrue;
 
 /**
  * Handling the termination behavior of the group
  */
+@Test(groups = { "application", "failed" })
 public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(GroupTerminationBehaviorTestCase.class);
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
     private static final String RESOURCES_PATH = "/group-termination-behavior-test";
     private static final String autoscalingPolicyId = "autoscaling-policy-group-termination-behavior-test";
     private static final String cartridgeId1 = "c1-group-termination-behavior-test";
@@ -55,40 +54,38 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
     private static final String deploymentPolicyId = "deployment-policy-group-termination-behavior-test";
     private static final int GROUP_INACTIVE_TIMEOUT = 180000;
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment", "failed"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testTerminationBehavior() throws Exception {
+        log.info("Running GroupTerminationBehaviorTestCase.testTerminationBehavior test method...");
+        long startTime = System.currentTimeMillis();
 
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
-
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(addedScalingPolicy);
 
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId1 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId1 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC1);
 
-        boolean addedC2 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId2 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC2 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId2 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC2);
 
-        boolean addedC3 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId3 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC3 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId3 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC3);
 
-        boolean addedC4 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId4 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC4 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId4 + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         assertTrue(addedC4);
 
         boolean addedG1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + cartridgeGroupId + ".json",
-                RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+                "/" + cartridgeGroupId + ".json", RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(addedG1);
 
         CartridgeGroupBean beanG1 = (CartridgeGroupBean) restClient.
@@ -97,61 +94,54 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         assertEquals(beanG1.getName(), "g-sc-G4-group-termination-behavior-test");
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId1 + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId1 + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(addedDep);
 
         final String applicationId = "group-termination-behavior-test";
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        applicationId + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+                applicationId + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         assertTrue(added);
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), "group-termination-behavior-test");
 
         final String applicationPolicyId = "application-policy-group-termination-behavior-test";
         boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
-                        applicationPolicyId + ".json",
-                RestConstants.APPLICATION_POLICIES,
+                        applicationPolicyId + ".json", RestConstants.APPLICATION_POLICIES,
                 RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(addAppPolicy);
 
         //deploy the application
         String resourcePath = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId;
-        boolean deployed = restClient.deployEntity(resourcePath,
-                RestConstants.APPLICATIONS_NAME);
+        boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
         assertTrue(deployed);
 
-        String groupId = topologyHandler.generateId(bean.getApplicationId(),
-                "g-G1-1x0-group-termination-behavior-test", bean.getApplicationId() + "-1");
+        String groupId = topologyHandler.generateId(bean.getApplicationId(), "g-G1-1x0-group-termination-behavior-test",
+                bean.getApplicationId() + "-1");
 
         String clusterIdC3 = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "c3-1x0-group-termination-behavior-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "c3-1x0-group-termination-behavior-test");
 
         String clusterIdC4 = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "c4-1x0-group-termination-behavior-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "c4-1x0-group-termination-behavior-test");
 
         String clusterIdC2 = topologyHandler.
-                getClusterIdFromAlias(bean.getApplicationId(),
-                        "c2-1x0-group-termination-behavior-test");
+                getClusterIdFromAlias(bean.getApplicationId(), "c2-1x0-group-termination-behavior-test");
 
         assertCreationOfNodes(groupId, clusterIdC2);
 
         assertCreationOfNodes(clusterIdC3, clusterIdC4);
 
         //Application active handling
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         //Group active handling
         topologyHandler.assertGroupActivation(bean.getApplicationId());
@@ -159,8 +149,8 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         //Cluster active handling
         topologyHandler.assertClusterActivation(bean.getApplicationId());
 
-        Map<String, Member> memberMap = TopologyHandler.getInstance().getMembersForCluster
-                ("c3-group-termination-behavior-test", bean.getApplicationId());
+        Map<String, Member> memberMap = TopologyHandler.getInstance()
+                .getMembersForCluster("c3-group-termination-behavior-test", bean.getApplicationId());
 
         //Terminate members in the cluster
         for (Map.Entry<String, Member> entry : memberMap.entrySet()) {
@@ -185,8 +175,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         assertCreationOfNodes(clusterIdC3, clusterIdC4);
 
         //Application active handling
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         //Group active handling
         topologyHandler.assertGroupActivation(bean.getApplicationId());
@@ -194,31 +183,11 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         //Cluster active handling
         topologyHandler.assertClusterActivation(bean.getApplicationId());
 
-        boolean removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                "g-sc-G4-group-termination-behavior-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(removedGroup);
-
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertFalse(removedAuto);
-
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1,
-                RestConstants.NETWORK_PARTITIONS_NAME);
-        //Trying to remove the used network partition
-        assertFalse(removedNet);
-
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
-        assertFalse(removedDep);
-
         //Un-deploying the application
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
-                RestConstants.APPLICATIONS_NAME);
+        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
         assertTrue(unDeployed);
 
         boolean undeploy = topologyHandler.assertApplicationUndeploy(applicationId);
@@ -230,55 +199,59 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = topologyHandler.assertApplicationUndeploy(applicationId);
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    applicationId), forceUndeployed);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId),
+                    forceUndeployed);
 
         }
 
-        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removed = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId, RestConstants.APPLICATIONS_NAME);
         assertTrue(removed);
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertNull(beanRemoved);
 
-        removedGroup = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS,
-                "g-sc-G4-group-termination-behavior-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
+        boolean removedGroup = restClient
+                .removeEntity(RestConstants.CARTRIDGE_GROUPS, "g-sc-G4-group-termination-behavior-test",
+                        RestConstants.CARTRIDGE_GROUPS_NAME);
         assertTrue(removedGroup);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId1,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId1, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC1);
 
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId2,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC2 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId2, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC2);
 
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId3,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC3 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId3, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC3);
 
-        boolean removedC4 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId4,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC4 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId4, RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC4);
 
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(removedAuto);
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId1, RestConstants.NETWORK_PARTITIONS_NAME);
-        assertFalse(removedNet);
-
-        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removeAppPolicy);
+
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId1,
+                RestConstants.NETWORK_PARTITIONS_NAME);
+        assertTrue(removedNet);
+
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("GroupTerminationBehaviorTestCase completed in [duration] %s ms", duration));
     }
 
     private void assertGroupInactive(String groupId, String clusterId) {
@@ -288,8 +261,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         while (!inActiveMap.containsKey(clusterId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             inActiveMap = TopologyHandler.getInstance().getInActiveMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -301,8 +273,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         while (!inActiveMap.containsKey(groupId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             inActiveMap = TopologyHandler.getInstance().getInActiveMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -320,8 +291,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
             while (!terminatingMembers.containsKey(clusterId)) {
                 try {
                     Thread.sleep(1000);
-                }
-                catch (InterruptedException ignore) {
+                } catch (InterruptedException ignore) {
                 }
                 terminatingMembers = TopologyHandler.getInstance().getTerminatingMembers();
                 if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -334,8 +304,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         while (!terminatingMembers.containsKey(groupId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             terminatingMembers = TopologyHandler.getInstance().getTerminatingMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -354,8 +323,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
             while (!terminatedMembers.containsKey(clusterId)) {
                 try {
                     Thread.sleep(1000);
-                }
-                catch (InterruptedException ignore) {
+                } catch (InterruptedException ignore) {
                 }
                 terminatedMembers = TopologyHandler.getInstance().getTerminatedMembers();
                 if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -368,8 +336,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         while (!terminatedMembers.containsKey(groupId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignore) {
+            } catch (InterruptedException ignore) {
             }
             terminatedMembers = TopologyHandler.getInstance().getTerminatedMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -389,8 +356,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         while (!activeMembers.containsKey(firstNodeId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignored) {
+            } catch (InterruptedException ignored) {
             }
             activeMembers = TopologyHandler.getInstance().getActivateddMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -402,8 +368,7 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         while (!createdMembers.containsKey(secondNodeId)) {
             try {
                 Thread.sleep(1000);
-            }
-            catch (InterruptedException ignored) {
+            } catch (InterruptedException ignored) {
             }
             createdMembers = TopologyHandler.getInstance().getCreatedMembers();
             if ((System.currentTimeMillis() - startTime) > GROUP_INACTIVE_TIMEOUT) {
@@ -412,5 +377,8 @@ public class GroupTerminationBehaviorTestCase extends StratosIntegrationTest {
         }
         assertTrue(createdMembers.containsKey(secondNodeId));
         assertTrue(createdMembers.get(secondNodeId) > activeMembers.get(firstNodeId));
+
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("GroupTerminationBehaviorTestCase completed in [duration] %s ms", duration));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
index f33ecad..5ba3634 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/MetadataServiceTestCase.java
@@ -28,14 +28,11 @@ import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.metadata.client.beans.PropertyBean;
 import org.apache.stratos.mock.iaas.domain.MockInstanceMetadata;
 import org.testng.Assert;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
+import org.testng.annotations.*;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -52,7 +49,7 @@ import static org.testng.AssertJUnit.assertTrue;
  * Deploy a sample application on mock IaaS and load test metadata service with high load of concurrent read/write
  * operations from multiple clients
  */
-@Test(groups = { "stratos.application.deployment", "metadata" })
+@Test(groups = { "application", "metadata" })
 public class MetadataServiceTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(MetadataServiceTestCase.class);
     private static final String RESOURCES_PATH = "/metadata-service-test";
@@ -77,10 +74,10 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
     public static final String APPLICATION_POLICY_ID = "application-policy-metadata-service-test";
     public static final String DEPLOYMENT_POLICY_ID = "deployment-policy-metadata-service-test";
 
-    @BeforeTest(timeOut = APPLICATION_TEST_TIMEOUT)
+    @BeforeClass(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void deployApplications() throws Exception {
+        log.info("Running MetadataServiceTestCase.deployApplications method...");
         startTime = System.currentTimeMillis();
-        log.info("Adding autoscaling policy [autoscale policy id] " + AUTOSCALE_POLICY_ID);
         boolean addedScalingPolicy = restClient.addEntity(
                 RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + AUTOSCALE_POLICY_ID + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
@@ -154,13 +151,13 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
         assertTrue(deployed);
 
         log.info("Waiting for application-1 status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(bean1.getApplicationId(), ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean1.getApplicationId());
 
         log.info("Waiting for cluster status of application-1 to become ACTIVE...");
         topologyHandler.assertClusterActivation(bean1.getApplicationId());
 
         log.info("Waiting for application-2 status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(bean2.getApplicationId(), ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean2.getApplicationId());
 
         log.info("Waiting for cluster status of application-2 to become ACTIVE...");
         topologyHandler.assertClusterActivation(bean2.getApplicationId());
@@ -200,10 +197,11 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
         return payloadProperties;
     }
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT,
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service basic test",
           priority = 1)
     public void testBasicOperations() throws Exception {
+        log.info("Running MetadataServiceTestCase.testBasicOperations test method...");
         String key = "mykey";
         String val1 = "myval1";
         String val2 = "myval2";
@@ -266,10 +264,11 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
         log.info("Metadata service basic test completed successfully");
     }
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT,
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service concurrency test",
           priority = 2)
     public void metadataConcurrencyTest() throws Exception {
+        log.info("Running MetadataServiceTestCase.metadataConcurrencyTest test method...");
         log.info("Starting multiple clients to add properties");
         ExecutorService taskExecutor = Executors.newFixedThreadPool(5);
         List<Callable<Void>> tasks = new ArrayList<>();
@@ -289,10 +288,11 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
         log.info("Metadata service concurrency test completed successfully");
     }
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT,
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service security test",
           priority = 3)
     public void metadataSecurityTest() throws Exception {
+        log.info("Running MetadataServiceTestCase.metadataSecurityTest test method...");
         String key = "mykey";
         String val1 = "myval1";
 
@@ -321,10 +321,11 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
         log.info("Metadata service security test completed successfully");
     }
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT,
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT,
           description = "Application startup, activation and metadata service concurrency test",
           priority = 10)
     public void cleanupAfterUndeployingAppTest() throws Exception {
+        log.info("Running MetadataServiceTestCase.cleanupAfterUndeployingAppTest test method...");
         // undeploy the app and check whether metadata entries are cleared
         log.info("Un-deploying the application [application id] " + APPLICATION_1_ID);
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + APPLICATION_1_ID +
@@ -367,8 +368,9 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
         };
     }
 
-    @AfterTest(timeOut = APPLICATION_TEST_TIMEOUT)
+    @AfterClass(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void cleanup() throws Exception {
+        log.info("Running MetadataServiceTestCase.cleanup method...");
         // remove app-1
         log.info("Removing the application [application id] " + APPLICATION_1_ID);
         boolean removedApp = restClient
@@ -436,6 +438,6 @@ public class MetadataServiceTestCase extends StratosIntegrationTest {
                 RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedNet);
         long duration = System.currentTimeMillis() - startTime;
-        log.info("Metadata test completed in " + duration + " ms");
+        log.info(String.format("MetadataServiceTestCase completed in [duration] %s ms", duration));
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTestCase.java
index 301cd53..6cbcef1 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionOneAfterAnotherClusterTestCase.java
@@ -26,7 +26,6 @@ import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
 import org.apache.stratos.messaging.domain.application.Application;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
 import org.apache.stratos.messaging.domain.instance.ClusterInstance;
 import org.apache.stratos.messaging.domain.topology.Cluster;
@@ -34,6 +33,7 @@ import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.messaging.domain.topology.Service;
 import org.apache.stratos.messaging.message.receiver.application.ApplicationManager;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import java.util.*;
@@ -45,63 +45,62 @@ import static org.testng.AssertJUnit.assertTrue;
 /**
  * This will handle the scale-up and scale-down of a particular cluster bursting test cases
  */
+@Test(groups = { "application", "failed" })
 public class PartitionOneAfterAnotherClusterTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(PartitionOneAfterAnotherClusterTestCase.class);
     private static final String RESOURCES_PATH = "/partition-round-robin-cluster-test";
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment", "failed"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testDeployApplication() throws Exception {
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
-        String autoscalingPolicyId = "autoscaling-policy-3";
+        log.info("Running PartitionOneAfterAnotherClusterTestCase.testDeployApplication test method...");
+        long startTime = System.currentTimeMillis();
 
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        String autoscalingPolicyId = "autoscaling-policy-3";
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertEquals(addedScalingPolicy, true);
+        Assert.assertTrue(addedScalingPolicy, "Could not add autoscaling policy");
 
-        boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c7.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertEquals(addedC1, true);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + "c7.json", RestConstants.CARTRIDGES,
+                        RestConstants.CARTRIDGES_NAME);
+        Assert.assertTrue(addedC1, "Could not add cartridge");
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        "network-partition-11.json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
-        assertEquals(addedN1, true);
+                "network-partition-11.json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+        Assert.assertTrue(addedN1, "Could not add network partition");
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        "deployment-policy-5.json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
-        assertEquals(addedDep, true);
+                "deployment-policy-5.json", RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        Assert.assertTrue(addedDep, "Could not add deployment policy");
 
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        "single-cluster-scaling-test.json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
-        assertEquals(added, true);
+                "single-cluster-scaling-test.json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
+        Assert.assertTrue(added, "Could not add application");
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                "single-cluster-scaling-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, "single-cluster-scaling-test", ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), "single-cluster-scaling-test");
 
         boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
                         "application-policy-4.json", RestConstants.APPLICATION_POLICIES,
                 RestConstants.APPLICATION_POLICIES_NAME);
-        assertEquals(addAppPolicy, true);
+        Assert.assertTrue(addAppPolicy, "Could not add application policy");
 
-        ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient.getEntity(
-                RestConstants.APPLICATION_POLICIES,
-                "application-policy-4", ApplicationPolicyBean.class,
-                RestConstants.APPLICATION_POLICIES_NAME);
+        ApplicationPolicyBean policyBean = (ApplicationPolicyBean) restClient
+                .getEntity(RestConstants.APPLICATION_POLICIES, "application-policy-4", ApplicationPolicyBean.class,
+                        RestConstants.APPLICATION_POLICIES_NAME);
 
         //deploy the application
         String resourcePath = RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + "application-policy-4";
-        boolean deployed = restClient.deployEntity(resourcePath,
-                RestConstants.APPLICATIONS_NAME);
-        assertEquals(deployed, true);
+        boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
+        Assert.assertTrue(deployed, "Could not deploy app");
 
         //Application active handling
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         //Cluster active handling
         topologyHandler.assertClusterActivation(bean.getApplicationId());
@@ -111,28 +110,25 @@ public class PartitionOneAfterAnotherClusterTestCase extends StratosIntegrationT
 
         //Removing one member from cluster and check for auto healing
 
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
+        Assert.assertTrue(removedAuto, "Could not remove autoscaling policy");
 
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertEquals(removedAuto, false);
-
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-11",
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-11",
                 RestConstants.NETWORK_PARTITIONS_NAME);
         //Trying to remove the used network partition
-        assertEquals(removedNet, false);
+        Assert.assertTrue(removedNet, "Could not remove network partition");
 
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                "deployment-policy-5", RestConstants.DEPLOYMENT_POLICIES_NAME);
-        assertEquals(removedDep, false);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-5",
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
+        Assert.assertTrue(removedDep, "Could not remove deployment policy");
 
         //Un-deploying the application
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + "single-cluster-scaling-test" +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
-                RestConstants.APPLICATIONS_NAME);
-        assertEquals(unDeployed, true);
+        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
+        Assert.assertTrue(unDeployed, "Could not undeploy app");
 
         boolean undeploy = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
         if (!undeploy) {
@@ -143,44 +139,45 @@ public class PartitionOneAfterAnotherClusterTestCase extends StratosIntegrationT
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("single-cluster-scaling-test");
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    "single-cluster-scaling-test"), forceUndeployed);
+            assertTrue(
+                    String.format("Forceful undeployment failed for the application %s", "single-cluster-scaling-test"),
+                    forceUndeployed);
 
         }
 
         boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, "single-cluster-scaling-test",
                 RestConstants.APPLICATIONS_NAME);
-        assertEquals(removed, true);
+        Assert.assertTrue(removed, "Could not remomve application");
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                "single-cluster-scaling-test", ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, "single-cluster-scaling-test", ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(beanRemoved, null);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c7",
-                RestConstants.CARTRIDGES_NAME);
-        assertEquals(removedC1, true);
-
-
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertEquals(removedAuto, true);
+        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c7", RestConstants.CARTRIDGES_NAME);
+        Assert.assertTrue(removedC1, "Could not remove cartridge");
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                "deployment-policy-5", RestConstants.DEPLOYMENT_POLICIES_NAME);
-        assertEquals(removedDep, true);
+        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
+        Assert.assertTrue(removedAuto, "Could not remove autoscaling policy");
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-11", RestConstants.NETWORK_PARTITIONS_NAME);
-        assertEquals(removedNet, false);
+        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-5",
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
+        Assert.assertTrue(removedDep, "Could not remomve deployment policy");
 
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-11",
+                RestConstants.NETWORK_PARTITIONS_NAME);
+        Assert.assertTrue(removedNet, "Could not remove network partition");
 
-        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                "application-policy-4", RestConstants.APPLICATION_POLICIES_NAME);
-        assertEquals(removeAppPolicy, true);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, "application-policy-4",
+                RestConstants.APPLICATION_POLICIES_NAME);
+        Assert.assertTrue(removeAppPolicy, "Could not remove application policy");
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-11", RestConstants.NETWORK_PARTITIONS_NAME);
-        assertEquals(removedNet, true);
+        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-11",
+                RestConstants.NETWORK_PARTITIONS_NAME);
+        Assert.assertTrue(removedNet, "Could not remove network partition");
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("PartitionOneAfterAnotherClusterTestCase completed in [duration] %s ms", duration));
     }
 
     /**
@@ -190,16 +187,15 @@ public class PartitionOneAfterAnotherClusterTestCase extends StratosIntegrationT
      */
     private void assertClusterWithRoundRobinAlgorithm(String applicationName) {
         Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s",
-                applicationName), application);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
 
         Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
         for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
             String serviceName = clusterDataHolder.getServiceType();
             String clusterId = clusterDataHolder.getClusterId();
             Service service = TopologyManager.getTopology().getService(serviceName);
-            assertNotNull(String.format("Service is not found: [application-id] %s [service] %s",
-                    applicationName, serviceName), service);
+            assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName,
+                    serviceName), service);
 
             Cluster cluster = service.getCluster(clusterId);
             assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
@@ -262,8 +258,8 @@ public class PartitionOneAfterAnotherClusterTestCase extends StratosIntegrationT
                     } else {
                         p1Index++;
                         previousPartition = p1;
-                        assertEquals(allInitTime.get(i), p1InitTime.get(p1Index), "Partition-1 doesn't not contain " +
-                                "correct values in current iteration");
+                        assertEquals(allInitTime.get(i), p1InitTime.get(p1Index),
+                                "Partition-1 doesn't not contain " + "correct values in current iteration");
                         if (p2Index >= 0) {
                             assertEquals(allInitTime.get(i - 1), p2InitTime.get(p2Index),
                                     "Partition-2 doesn't not contain correct values in the previous iteration");
@@ -277,4 +273,4 @@ public class PartitionOneAfterAnotherClusterTestCase extends StratosIntegrationT
             }
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTestCase.java
index b8d119c..4fa50b9 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/PartitionRoundRobinClusterTestCase.java
@@ -25,7 +25,6 @@ import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
 import org.apache.stratos.messaging.domain.application.Application;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.application.ClusterDataHolder;
 import org.apache.stratos.messaging.domain.instance.ClusterInstance;
 import org.apache.stratos.messaging.domain.topology.Cluster;
@@ -39,7 +38,6 @@ import org.testng.annotations.Test;
 import java.util.*;
 
 import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNull;
 import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertTrue;
@@ -47,6 +45,7 @@ import static org.testng.AssertJUnit.assertTrue;
 /**
  * This will handle the scale-up and scale-down of a particular cluster bursting test cases
  */
+@Test(groups = { "application", "round-robin" })
 public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(PartitionRoundRobinClusterTestCase.class);
     private static final String RESOURCES_PATH = "/partition-round-robin-cluster-test";
@@ -56,40 +55,39 @@ public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
     private static final String deploymentPolicyId = "deployment-policy-partition-round-robin-test";
     private static final String applicationId = "partition-round-robin-test";
     private static final String applicationPolicyId = "application-policy-partition-round-robin-test";
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.application.deployment"})
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testDeployApplication() throws Exception {
+        log.info("Running PartitionRoundRobinClusterTestCase.testDeployApplication test method...");
+        long startTime = System.currentTimeMillis();
 
-
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
-
-        boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH
-                        + "/" + autoscalingPolicyId + ".json",
+        boolean addedScalingPolicy = restClient.addEntity(
+                RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
                 RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
         Assert.assertTrue(addedScalingPolicy);
 
-        boolean addedC1 = restClient.addEntity(
-                RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean addedC1 = restClient
+                .addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" + cartridgeId + ".json",
+                        RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
         Assert.assertTrue(addedC1);
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        networkPartitionId + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                networkPartitionId + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         Assert.assertTrue(addedN1);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        deploymentPolicyId + ".json",
-                RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
+                        deploymentPolicyId + ".json", RestConstants.DEPLOYMENT_POLICIES,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         Assert.assertTrue(addedDep);
 
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
-                        applicationId + ".json", RestConstants.APPLICATIONS,
-                RestConstants.APPLICATIONS_NAME);
+                applicationId + ".json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(added);
 
-        ApplicationBean bean = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean bean = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertEquals(bean.getApplicationId(), applicationId);
 
         boolean addAppPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
@@ -100,14 +98,11 @@ public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
         //deploy the application
         String resourcePath = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_DEPLOY + "/" + applicationPolicyId;
-        boolean deployed = restClient.deployEntity(resourcePath,
-                RestConstants.APPLICATIONS_NAME);
+        boolean deployed = restClient.deployEntity(resourcePath, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(deployed);
 
-
         //Application active handling
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         //Cluster active handling
         topologyHandler.assertClusterActivation(bean.getApplicationId());
@@ -115,86 +110,57 @@ public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
         //Verifying whether members got created using round robin algorithm
         assertClusterWithRoundRobinAlgorithm(bean.getApplicationId());
 
-        //Application in-active handling
-        log.info("Waiting for the faulty member detection from " +
-                "CEP as the statistics are stopped...");
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Inactive);
-
-        //Application active handling after application becomes active again
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(),
-                ApplicationStatus.Active);
-
-        //Cluster active handling
-        topologyHandler.assertClusterActivation(bean.getApplicationId());
-
-        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
-        assertFalse(removedAuto);
-
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId,
-                RestConstants.NETWORK_PARTITIONS_NAME);
-        //Trying to remove the used network partition
-        assertFalse(removedNet);
-
-        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
-        assertFalse(removedDep);
-
         //Un-deploying the application
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/" + applicationId +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy,
-                RestConstants.APPLICATIONS_NAME);
+        boolean unDeployed = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(unDeployed);
 
         boolean undeploy = topologyHandler.assertApplicationUndeploy(applicationId);
         if (!undeploy) {
             //Need to forcefully undeploy the application
-            log.info(String.format("Force undeployment is going to start for the [application] %s", applicationId));
+            log.info(String.format("Force undeployment is going to start for [application-id] %s", applicationId));
 
             restClient.undeployEntity(RestConstants.APPLICATIONS + "/" + applicationId +
                     RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
             boolean forceUndeployed = topologyHandler.assertApplicationUndeploy(applicationId);
-            assertTrue(String.format("Forceful undeployment failed for the application %s",
-                    applicationId), forceUndeployed);
+            assertTrue(String.format("Forceful undeployment failed for the application %s", applicationId),
+                    forceUndeployed);
 
         }
 
-        boolean removed = restClient.removeEntity(RestConstants.APPLICATIONS, applicationId,
-                RestConstants.APPLICATIONS_NAME);
+        boolean removed = restClient
+                .removeEntity(RestConstants.APPLICATIONS, applicationId, RestConstants.APPLICATIONS_NAME);
         Assert.assertTrue(removed);
 
-        ApplicationBean beanRemoved = (ApplicationBean) restClient.getEntity(RestConstants.APPLICATIONS,
-                applicationId, ApplicationBean.class, RestConstants.APPLICATIONS_NAME);
+        ApplicationBean beanRemoved = (ApplicationBean) restClient
+                .getEntity(RestConstants.APPLICATIONS, applicationId, ApplicationBean.class,
+                        RestConstants.APPLICATIONS_NAME);
         assertNull(beanRemoved);
 
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeId,
-                RestConstants.CARTRIDGES_NAME);
+        boolean removedC1 = restClient
+                .removeEntity(RestConstants.CARTRIDGES, cartridgeId, RestConstants.CARTRIDGES_NAME);
         Assert.assertTrue(removedC1);
 
-        removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES,
-                autoscalingPolicyId, RestConstants.AUTOSCALING_POLICIES_NAME);
+        boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         Assert.assertTrue(removedAuto);
 
-        removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES,
-                deploymentPolicyId, RestConstants.DEPLOYMENT_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.DEPLOYMENT_POLICIES, deploymentPolicyId,
+                RestConstants.DEPLOYMENT_POLICIES_NAME);
         Assert.assertTrue(removedDep);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME);
-        assertFalse(removedNet);
-
-        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removeAppPolicy = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         Assert.assertTrue(removeAppPolicy);
 
-        removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                networkPartitionId, RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS, networkPartitionId,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         Assert.assertTrue(removedNet);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("PartitionRoundRobinClusterTestCase completed in [duration] %s ms", duration));
     }
 
     /**
@@ -204,16 +170,15 @@ public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
      */
     private void assertClusterWithRoundRobinAlgorithm(String applicationName) {
         Application application = ApplicationManager.getApplications().getApplication(applicationName);
-        assertNotNull(String.format("Application is not found: [application-id] %s",
-                applicationName), application);
+        assertNotNull(String.format("Application is not found: [application-id] %s", applicationName), application);
 
         Set<ClusterDataHolder> clusterDataHolderSet = application.getClusterDataRecursively();
         for (ClusterDataHolder clusterDataHolder : clusterDataHolderSet) {
             String serviceName = clusterDataHolder.getServiceType();
             String clusterId = clusterDataHolder.getClusterId();
             Service service = TopologyManager.getTopology().getService(serviceName);
-            assertNotNull(String.format("Service is not found: [application-id] %s [service] %s",
-                    applicationName, serviceName), service);
+            assertNotNull(String.format("Service is not found: [application-id] %s [service] %s", applicationName,
+                    serviceName), service);
 
             Cluster cluster = service.getCluster(clusterId);
             assertNotNull(String.format("Cluster is not found: [application-id] %s [service] %s [cluster-id] %s",
@@ -243,7 +208,7 @@ public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
                 List<Long> p2InitTime = partitionIdToMembersMap.get(p2);
                 Collections.sort(p2InitTime);
 
-                List<Long> allInitTime = new ArrayList<Long>();
+                List<Long> allInitTime = new ArrayList<>();
                 allInitTime.addAll(p1InitTime);
                 allInitTime.addAll(p2InitTime);
                 Collections.sort(allInitTime);
@@ -253,10 +218,10 @@ public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
                 String previousPartition = null;
                 for (int i = 0; i < allInitTime.size(); i++) {
                     if (previousPartition == null) {
-                        if (p1InitTime.get(0) == allInitTime.get(i)) {
+                        if (Objects.equals(p1InitTime.get(0), allInitTime.get(i))) {
                             previousPartition = p1;
                             p1Index++;
-                        } else if (p2InitTime.get(0) == allInitTime.get(i)) {
+                        } else if (Objects.equals(p2InitTime.get(0), allInitTime.get(i))) {
                             previousPartition = p2;
                             p2Index++;
 
@@ -292,4 +257,4 @@ public class PartitionRoundRobinClusterTestCase extends StratosIntegrationTest {
             }
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationStartupTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationStartupTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationStartupTestCase.java
index e0c9a23..306a5e0 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationStartupTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/application/SampleApplicationStartupTestCase.java
@@ -28,7 +28,6 @@ import org.apache.stratos.common.beans.policy.deployment.ApplicationPolicyBean;
 import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.apache.stratos.messaging.domain.topology.Member;
 import org.apache.stratos.metadata.client.beans.PropertyBean;
 import org.apache.stratos.mock.iaas.domain.MockInstanceMetadata;
@@ -45,9 +44,11 @@ import static org.testng.AssertJUnit.assertTrue;
  * Deploy a sample application on mock IaaS and assert whether application instance, cluster instance, member instances
  * are getting activated. Kill the mock instance and check whether
  */
+@Test(groups = { "application", "smoke" })
 public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(SampleApplicationStartupTestCase.class);
     private static final String RESOURCES_PATH = "/sample-application-startup-test";
+    private TopologyHandler topologyHandler = TopologyHandler.getInstance();
     private static final String PAYLOAD_PARAMETER_SEPARATOR = ",";
     private static final String PAYLOAD_PARAMETER_NAME_VALUE_SEPARATOR = "=";
     private static final String PAYLOAD_PARAMETER_TOKEN_KEY = "TOKEN";
@@ -55,13 +56,13 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
     private GsonBuilder gsonBuilder = new GsonBuilder();
     private Gson gson = gsonBuilder.create();
 
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT,
-          description = "Application startup, activation and faulty member " + "detection",
-          groups = { "stratos.application.startup", "smoke" })
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT,
+          description = "Application startup, activation and faulty member detection")
     public void testApplication() throws Exception {
-        String autoscalingPolicyId = "autoscaling-policy-sample-application-startup-test";
-        TopologyHandler topologyHandler = TopologyHandler.getInstance();
+        log.info("Running SampleApplicationStartupTestCase.testApplication test method...");
+        long startTime = System.currentTimeMillis();
 
+        String autoscalingPolicyId = "autoscaling-policy-sample-application-startup-test";
         log.info("Adding autoscaling policy [autoscale policy id] " + autoscalingPolicyId);
         boolean addedScalingPolicy = restClient.addEntity(
                 RESOURCES_PATH + RestConstants.AUTOSCALING_POLICIES_PATH + "/" + autoscalingPolicyId + ".json",
@@ -89,7 +90,7 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
         log.info("Adding application [application id] sample-application-startup-test");
         boolean addedApp = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATIONS_PATH + "/" +
                 "sample-application-startup-test.json", RestConstants.APPLICATIONS, RestConstants.APPLICATIONS_NAME);
-        assertEquals(addedApp, true);
+        Assert.assertTrue(addedApp);
 
         ApplicationBean bean = (ApplicationBean) restClient
                 .getEntity(RestConstants.APPLICATIONS, "sample-application-startup-test", ApplicationBean.class,
@@ -109,18 +110,18 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
         assertEquals(policyBean.getId(), "application-policy-sample-application-startup-test");
 
         // Used policies/cartridges should not removed...asserting validations when removing policies
-        log.info("Trying to remove the used autoscaling policy...");
+        log.info("Trying to remove used autoscaling policy...");
         boolean removedUsedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
                 RestConstants.AUTOSCALING_POLICIES_NAME);
         assertFalse(removedUsedAuto);
 
-        log.info("Trying to remove the used network partition...");
+        log.info("Trying to remove used network partition...");
         boolean removedUsedNet = restClient
                 .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-application-startup-test",
                         RestConstants.NETWORK_PARTITIONS_NAME);
         assertFalse(removedUsedNet);
 
-        log.info("Trying to remove the used deployment policy...");
+        log.info("Trying to remove used deployment policy...");
         boolean removedUsedDep = restClient
                 .removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-sample-application-startup-test",
                         RestConstants.DEPLOYMENT_POLICIES_NAME);
@@ -145,7 +146,8 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
         assertFalse(removed);
 
         log.info("Waiting for application status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Active);
+        //topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         log.info("Waiting for cluster status to become ACTIVE...");
         topologyHandler.assertClusterActivation(bean.getApplicationId());
@@ -187,9 +189,7 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
         Assert.assertTrue(propertyBean != null && propertyBean.getValues().size() > 0, "Empty property list");
         List<String> addedValues = new ArrayList<>(Arrays.asList(val1, val2));
         boolean hasPropertiesAdded = propertyBean.getValues().containsAll(addedValues);
-
         Assert.assertTrue(hasPropertiesAdded, "Metadata properties retrieved are not correct");
-        log.info("Metadata test completed successfully");
 
         log.info("Terminating members in [cluster id] c1-sample-application-startup-test in mock IaaS directly to "
                 + "simulate faulty members...");
@@ -202,11 +202,12 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
         }
         // application status should be marked as inactive since some members are faulty
         log.info("Waiting for application status to become INACTIVE");
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Inactive);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         // application should recover itself and become active after spinning more instances
         log.info("Waiting for application status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Active);
+        //topologyHandler.assertApplicationStatus(bean.getApplicationId(), ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(bean.getApplicationId());
 
         log.info("Waiting for cluster status to become ACTIVE...");
         topologyHandler.assertClusterActivation(bean.getApplicationId());
@@ -231,7 +232,7 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
                     "sample-application-startup-test"), forceUndeployed);
         }
 
-        log.info("Removing the application [application id] sample-application-startup-test");
+        log.info("Removing application [application id] sample-application-startup-test");
         boolean removedApp = restClient.removeEntity(RestConstants.APPLICATIONS, "sample-application-startup-test",
                 RestConstants.APPLICATIONS_NAME);
         assertTrue(removedApp);
@@ -241,35 +242,36 @@ public class SampleApplicationStartupTestCase extends StratosIntegrationTest {
                         RestConstants.APPLICATIONS_NAME);
         assertNull(beanRemoved);
 
-        log.info("Removing the application policy [application policy id] "
+        log.info("Removing application policy [application policy id] "
                 + "application-policy-sample-application-startup-test");
         boolean removeAppPolicy = restClient
                 .removeEntity(RestConstants.APPLICATION_POLICIES, "application-policy-sample-application-startup-test",
                         RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removeAppPolicy);
 
-        log.info("Removing the cartridge [cartridge type] c1-sample-application-startup-test");
+        log.info("Removing cartridge [cartridge type] c1-sample-application-startup-test");
         boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c1-sample-application-startup-test",
                 RestConstants.CARTRIDGES_NAME);
         assertTrue(removedC1);
 
-        log.info("Removing the autoscaling policy [autoscaling policy id] " + autoscalingPolicyId);
+        log.info("Removing autoscaling policy [autoscaling policy id] " + autoscalingPolicyId);
         boolean removedAuto = restClient.removeEntity(RestConstants.AUTOSCALING_POLICIES, autoscalingPolicyId,
                 RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(removedAuto);
 
-        log.info("Removing the deployment policy [deployment policy id] "
+        log.info("Removing deployment policy [deployment policy id] "
                 + "deployment-policy-sample-application-startup-test");
         boolean removedDep = restClient
                 .removeEntity(RestConstants.DEPLOYMENT_POLICIES, "deployment-policy-sample-application-startup-test",
                         RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(removedDep);
 
-        log.info("Removing the network partition [network partition id] "
-                + "network-partition-sample-application-startup-test");
+        log.info("Removing network partition [network partition id] network-partition-sample-application-startup-test");
         boolean removedNet = restClient
                 .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-sample-application-startup-test",
                         RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedNet);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("SampleApplicationStartupTestCase completed in [duration] %s ms", duration));
     }
 }


[11/28] stratos git commit: Add logs for integration common RestClient to help troubleshoot integration test failures

Posted by ra...@apache.org.
Add logs for integration common RestClient to help troubleshoot integration test failures


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

Branch: refs/heads/stratos-4.1.x
Commit: 6adcd8c37165a82fd03ea78bd767eb83fa79f91d
Parents: eb93f70
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:07:43 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../integration/common/rest/RestClient.java     | 61 ++++++++++++++------
 1 file changed, 42 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/6adcd8c3/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
index cb1cb18..e818fe5 100644
--- a/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
+++ b/products/stratos/modules/integration/test-common/src/main/java/org/apache/stratos/integration/common/rest/RestClient.java
@@ -163,9 +163,10 @@ public class RestClient {
     }
 
     public boolean addEntity(String filePath, String resourcePath, String entityName) throws Exception {
+        log.info(String.format("Adding [entity] %s, [resource-path] %s, [file-path] %s", entityName, resourcePath,
+                filePath));
         String content = getJsonStringFromFile(filePath);
         URI uri = new URIBuilder(this.endPoint + resourcePath).build();
-
         HttpResponse response = doPost(uri, content);
         if (response != null) {
             if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
@@ -178,8 +179,8 @@ public class RestClient {
     }
 
     public boolean deployEntity(String resourcePath, String entityName) throws Exception {
+        log.info(String.format("Deploying [entity] %s, [resource-path] %s", entityName, resourcePath));
         URI uri = new URIBuilder(this.endPoint + resourcePath).build();
-
         HttpResponse response = doPost(uri, "");
         if (response != null) {
             if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
@@ -192,8 +193,8 @@ public class RestClient {
     }
 
     public boolean undeployEntity(String resourcePath, String entityName) throws Exception {
+        log.info(String.format("Undeploying [entity] %s, [resource-path] %s", entityName, resourcePath));
         URI uri = new URIBuilder(this.endPoint + resourcePath).build();
-
         HttpResponse response = doPost(uri, "");
         if (response != null) {
             if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
@@ -207,6 +208,8 @@ public class RestClient {
 
     public Object getEntity(String resourcePath, String identifier, Class responseJsonClass, String entityName)
             throws Exception {
+        log.info(String.format("Retrieving [entity] %s, [resource-path] %s, [identifier] %s, [response-class] %s",
+                entityName, resourcePath, identifier, responseJsonClass.getSimpleName()));
         URI uri = new URIBuilder(this.endPoint + resourcePath + "/" + identifier).build();
         HttpResponse response = doGet(uri);
         if (response != null) {
@@ -222,6 +225,7 @@ public class RestClient {
     }
 
     public Object listEntity(String resourcePath, Type type, String entityName) throws Exception {
+        log.info(String.format("Listing [entity] %s, [resource-path] %s, [type] %s", entityName, resourcePath, type));
         URI uri = new URIBuilder(this.endPoint + resourcePath).build();
         HttpResponse response = doGet(uri);
         if (response != null) {
@@ -237,6 +241,8 @@ public class RestClient {
     }
 
     public boolean removeEntity(String resourcePath, String identifier, String entityName) throws Exception {
+        log.info(String.format("Removing [entity] %s, [resource-path] %s, [identifier] %s", entityName, resourcePath,
+                identifier));
         URI uri = new URIBuilder(this.endPoint + "/" + resourcePath + "/" + identifier).build();
         HttpResponse response = doDelete(uri);
         if (response != null) {
@@ -244,9 +250,9 @@ public class RestClient {
                 return true;
             } else {
                 ErrorResponse errorResponse = gson.fromJson(response.getContent(), ErrorResponse.class);
-                log.error("Error response while removing entity [identifier] " + identifier + ", [entity name] " +
-                        entityName + ", [error] " + errorResponse.getErrorMessage() + ", [error code] " + errorResponse
-                        .getErrorCode());
+                log.error(String.format(
+                        "Error response while removing entity [identifier] %s, [entity name] %s, [error] %s, [code] %s",
+                        identifier, entityName, errorResponse.getErrorMessage(), errorResponse.getErrorCode()));
                 return false;
             }
         }
@@ -254,9 +260,10 @@ public class RestClient {
     }
 
     public boolean updateEntity(String filePath, String resourcePath, String entityName) throws Exception {
+        log.info(String.format("Updating [entity] %s, [resource-path] %s, [file-path] %s", entityName, resourcePath,
+                filePath));
         String content = getJsonStringFromFile(filePath);
         URI uri = new URIBuilder(this.endPoint + resourcePath).build();
-
         HttpResponse response = doPut(uri, content);
         if (response != null) {
             if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
@@ -273,6 +280,8 @@ public class RestClient {
 
     public boolean addPropertyToApplication(String appId, String propertyKey, String propertyValue, String accessToken)
             throws Exception {
+        log.info(String.format("Adding property to application [application-id] %s, [key] %s, [value] %s, [token] %s",
+                appId, propertyKey, propertyValue, accessToken));
         URI uri = new URIBuilder(
                 this.securedEndpoint + RestConstants.METADATA_API + "/applications/" + appId + "/properties").build();
         PropertyBean property = new PropertyBean(propertyKey, propertyValue);
@@ -290,7 +299,6 @@ public class RestClient {
         } finally {
             releaseConnection(postRequest);
         }
-
         if (response != null) {
             if ((response.getStatusCode() >= 200) && (response.getStatusCode() < 300)) {
                 return true;
@@ -303,6 +311,9 @@ public class RestClient {
 
     public boolean addPropertyToCluster(String appId, String clusterId, String propertyKey, String propertyValue,
             String accessToken) throws Exception {
+        log.info(String.format(
+                "Adding property to cluster [application-id] %s, [cluster-id] %s, [key] %s, [value] %s, [token] %s",
+                appId, clusterId, propertyKey, propertyValue, accessToken));
         URI uri = new URIBuilder(
                 this.securedEndpoint + RestConstants.METADATA_API + "/applications/" + appId + "/clusters/" + clusterId
                         + "/properties").build();
@@ -332,11 +343,13 @@ public class RestClient {
         throw new Exception("Null response received. Could not add property to cluster: " + clusterId);
     }
 
-    public PropertyBean getClusterProperty(String appId, String clusterId, String propertyName, String accessToken)
+    public PropertyBean getClusterProperty(String appId, String clusterId, String propertyKey, String accessToken)
             throws Exception {
+        log.info(String.format("Retrieving cluster property [application-id] %s, [cluster-id] %s, [key] %s, [token] %s",
+                appId, clusterId, propertyKey, accessToken));
         URI uri = new URIBuilder(
                 this.securedEndpoint + RestConstants.METADATA_API + "/applications/" + appId + "/cluster/" + clusterId
-                        + "/properties/" + propertyName).build();
+                        + "/properties/" + propertyKey).build();
         HttpResponse response;
         HttpGet getRequest = null;
         try {
@@ -353,10 +366,12 @@ public class RestClient {
         }.getType());
     }
 
-    public PropertyBean getApplicationProperty(String appId, String propertyName, String accessToken) throws Exception {
+    public PropertyBean getApplicationProperty(String appId, String propertyKey, String accessToken) throws Exception {
+        log.info(String.format("Retrieving application property [application-id] %s, [key] %s, [token] %s", appId,
+                propertyKey, accessToken));
         URI uri = new URIBuilder(
                 this.securedEndpoint + RestConstants.METADATA_API + "/applications/" + appId + "/properties/"
-                        + propertyName).build();
+                        + propertyKey).build();
         HttpResponse response;
         HttpGet getRequest = null;
         try {
@@ -376,6 +391,8 @@ public class RestClient {
     }
 
     public boolean deleteApplicationProperties(String appId, String accessToken) throws Exception {
+        log.info(String.format("Deleting application properties in [application-id] %s, [token] %s", appId,
+                accessToken));
         URI uri = new URIBuilder(
                 this.securedEndpoint + RestConstants.METADATA_API + "/applications/" + appId + "/properties").build();
         HttpResponse response;
@@ -401,10 +418,12 @@ public class RestClient {
                 String.format("Null response received. Could not delete properties for [application] %s", appId));
     }
 
-    public boolean deleteApplicationProperty(String appId, String propertyName, String accessToken) throws Exception {
+    public boolean deleteApplicationProperty(String appId, String propertyKey, String accessToken) throws Exception {
+        log.info(String.format("Deleting application property in [application-id] %s, [key] %s, [token] %s", appId,
+                propertyKey, accessToken));
         URI uri = new URIBuilder(
                 this.securedEndpoint + RestConstants.METADATA_API + "/applications/" + appId + "/properties/"
-                        + propertyName).build();
+                        + propertyKey).build();
         HttpResponse response;
         HttpDelete httpDelete = null;
         try {
@@ -424,15 +443,19 @@ public class RestClient {
                 throw new RuntimeException(response.getContent());
             }
         }
-        throw new Exception(String.format("Null response received. Could not delete [property] %s in [application] %s",
-                propertyName, appId));
+        throw new Exception(
+                String.format("Null response received. Could not delete [property] %s in [application] %s", propertyKey,
+                        appId));
     }
 
-    public boolean deleteApplicationPropertyValue(String appId, String propertyName, String value, String accessToken)
+    public boolean deleteApplicationPropertyValue(String appId, String propertyKey, String value, String accessToken)
             throws Exception {
+        log.info(String.format(
+                "Deleting application property value in [application-id] %s, [key] %s, [value] %s, [token] %s", appId,
+                propertyKey, value, accessToken));
         URI uri = new URIBuilder(
                 this.securedEndpoint + RestConstants.METADATA_API + "/applications/" + appId + "/properties/"
-                        + propertyName + "/value/" + value).build();
+                        + propertyKey + "/value/" + value).build();
         HttpResponse response;
         HttpDelete httpDelete = null;
         try {
@@ -454,7 +477,7 @@ public class RestClient {
         }
         throw new Exception(
                 String.format("Null response received. Could not delete [value] %s, [property] %s in [application] %s",
-                        value, propertyName, appId));
+                        value, propertyKey, appId));
     }
 
     /**


[16/28] stratos git commit: Cleaning up test cases. Remove duplicate assertions. Fix formatting.

Posted by ra...@apache.org.
http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTestCase.java
deleted file mode 100644
index 38e440f..0000000
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeGroupTestCase.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.stratos.integration.tests.group;
-
-import com.google.gson.reflect.TypeToken;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.beans.cartridge.CartridgeGroupBean;
-import org.apache.stratos.integration.common.RestConstants;
-import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.testng.annotations.Test;
-
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.AssertJUnit.*;
-
-/**
- * Test to handle Cartridge group CRUD operations
- */
-public class CartridgeGroupTestCase extends StratosIntegrationTest {
-    private static final Log log = LogFactory.getLog(CartridgeGroupTestCase.class);
-    private static final String RESOURCES_PATH = "/cartridge-group-test";
-
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.cartridge.deployment", "smoke"})
-    public void testCartridgeGroup() throws Exception {
-        boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
-                        "/" + "c4-cartridge-group-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
-                "c4-cartridge-group-test"), addedC1);
-
-        boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
-                        "/" + "c5-cartridge-group-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
-                "c5-cartridge-group-test"), addedC2);
-
-        boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
-                        "/" + "c6-cartridge-group-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
-                "c6-cartridge-group-test"), addedC3);
-
-        boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + "g4-g5-g6-cartridge-group-test.json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
-                "g4-g5-g6-cartridge-group-test"), added);
-
-        CartridgeGroupBean bean = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertEquals(bean.getName(), "G4-cartridge-group-test",
-                String.format("Cartridge Group name did not match: [cartridge-group-name] %s",
-                        "g4-g5-g6-cartridge-group-test.json"));
-
-        boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + "g4-g5-g6-cartridge-group-test-v1.json",
-                RestConstants.CARTRIDGE_GROUPS, RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge Group did not updated: [cartridge-group-name] %s",
-                "g4-g5-g6-cartridge-group-test"), updated);
-
-        CartridgeGroupBean updatedBean = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertEquals(updatedBean.getName(), "G4-cartridge-group-test",
-                String.format("Updated Cartridge Group didn't match: [cartridge-group-name] %s",
-                        "g4-g5-g6-cartridge-group-test"));
-
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(String.format("Cartridge can be removed while it is used in " +
-                "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1);
-
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(String.format("Cartridge can be removed while it is used in " +
-                        "cartridge group: [cartridge-name] %s",
-                "c5-cartridge-group-test"), removedC2);
-
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(String.format("Cartridge can be removed while it is used in " +
-                        "cartridge group: [cartridge-name] %s",
-                "c6-cartridge-group-test"), removedC3);
-
-        boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
-                "g4-g5-g6-cartridge-group-test"), removed);
-
-        CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, "G4-cartridge-group-test",
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertEquals(beanRemoved, null,
-                String.format("Cartridge Group did not removed completely: [cartridge-group-name] %s",
-                        "g4-g5-g6-cartridge-group-test"));
-
-        removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
-                "c4-cartridge-group-test"), removedC1);
-
-        removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
-                "c5-cartridge-group-test"), removedC2);
-
-        removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
-                "c6-cartridge-group-test"), removedC3);
-    }
-
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.cartridge.deployment", "smoke"})
-    public void testCartridgeGroupList() throws Exception {
-        boolean addedC1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
-                        "/" + "c4-cartridge-group-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
-                "c4-cartridge-group-test"), addedC1);
-
-        boolean addedC2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
-                        "/" + "c5-cartridge-group-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
-                "c5-cartridge-group-test"), addedC2);
-
-        boolean addedC3 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH +
-                        "/" + "c6-cartridge-group-test.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(String.format("Cartridge did not added: [cartridge-name] %s",
-                "c6-cartridge-group-test"), addedC3);
-
-        String group1 = "group-1-cartridge-group-test";
-        String group2 = "group-2-cartridge-group-test";
-
-        boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + group1 + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
-                group1), added);
-
-        added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGE_GROUPS_PATH +
-                        "/" + group2 + ".json", RestConstants.CARTRIDGE_GROUPS,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge Group did not added: [cartridge-group-name] %s",
-                group1), added);
-
-        Type listType = new TypeToken<ArrayList<CartridgeGroupBean>>() {
-        }.getType();
-
-        List<CartridgeGroupBean> cartridgeGroupList = (List<CartridgeGroupBean>) restClient.
-                listEntity(RestConstants.CARTRIDGE_GROUPS,
-                        listType, RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(cartridgeGroupList.size() >= 2);
-
-        CartridgeGroupBean bean1 = null;
-        for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
-            if (cartridgeGroupBean.getName().equals(group1)) {
-                bean1 = cartridgeGroupBean;
-            }
-        }
-        assertNotNull(bean1);
-
-        CartridgeGroupBean bean2 = null;
-        for (CartridgeGroupBean cartridgeGroupBean : cartridgeGroupList) {
-            if (cartridgeGroupBean.getName().equals(group2)) {
-                bean2 = cartridgeGroupBean;
-            }
-        }
-        assertNotNull(bean2);
-
-        boolean removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group1,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
-                group1), removed);
-
-        CartridgeGroupBean beanRemoved = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, group1,
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertNull(String.format("Cartridge Group did not removed completely: " +
-                        "[cartridge-group-name] %s",
-                group1), beanRemoved);
-
-        boolean removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(String.format("Cartridge can be removed while it is used in " +
-                "cartridge group: [cartridge-name] %s", "c4-cartridge-group-test"), removedC1);
-
-        boolean removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(String.format("Cartridge can be removed while it is used in " +
-                        "cartridge group: [cartridge-name] %s",
-                "c5-cartridge-group-test"), removedC2);
-
-        boolean removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertFalse(String.format("Cartridge can be removed while it is used in " +
-                        "cartridge group: [cartridge-name] %s",
-                "c6-cartridge-group-test"), removedC3);
-
-        removed = restClient.removeEntity(RestConstants.CARTRIDGE_GROUPS, group2,
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge Group did not removed: [cartridge-group-name] %s",
-                group2), removed);
-
-        beanRemoved = (CartridgeGroupBean) restClient.
-                getEntity(RestConstants.CARTRIDGE_GROUPS, group2,
-                        CartridgeGroupBean.class, RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertNull(String.format("Cartridge Group did not removed completely: " +
-                        "[cartridge-group-name] %s",
-                group2), beanRemoved);
-
-        removedC1 = restClient.removeEntity(RestConstants.CARTRIDGES, "c4-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
-                "c4-cartridge-group-test"), removedC1);
-
-        removedC2 = restClient.removeEntity(RestConstants.CARTRIDGES, "c5-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
-                "c5-cartridge-group-test"), removedC2);
-
-        removedC3 = restClient.removeEntity(RestConstants.CARTRIDGES, "c6-cartridge-group-test",
-                RestConstants.CARTRIDGE_GROUPS_NAME);
-        assertTrue(String.format("Cartridge can not be removed : [cartridge-name] %s",
-                "c6-cartridge-group-test"), removedC3);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTestCase.java
deleted file mode 100644
index 4e9484a..0000000
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/group/CartridgeTestCase.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.stratos.integration.tests.group;
-
-import com.google.gson.reflect.TypeToken;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.beans.PropertyBean;
-import org.apache.stratos.common.beans.cartridge.CartridgeBean;
-import org.apache.stratos.integration.common.RestConstants;
-import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.testng.annotations.Test;
-
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-import static org.testng.AssertJUnit.assertNotNull;
-import static org.testng.AssertJUnit.assertTrue;
-
-/**
- * Test to handle Cartridge CRUD operations
- */
-public class CartridgeTestCase extends StratosIntegrationTest {
-    private static final Log log = LogFactory.getLog(CartridgeTestCase.class);
-    private static final String RESOURCES_PATH = "/cartridge-test";
-
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.cartridge.deployment", "smoke"})
-    public void testCartridge() throws Exception {
-        String cartridgeType = "c0-cartridge-test";
-        boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
-                        cartridgeType + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(added);
-        CartridgeBean bean = (CartridgeBean) restClient.
-                getEntity(RestConstants.CARTRIDGES, cartridgeType,
-                        CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
-        assertEquals(bean.getCategory(), "Application");
-        assertEquals(bean.getHost(), "qmog.cisco.com");
-        for (PropertyBean property : bean.getProperty()) {
-            if (property.getName().equals("payload_parameter.CEP_IP")) {
-                assertEquals(property.getValue(), "octl.qmog.cisco.com");
-            } else if (property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) {
-                assertEquals(property.getValue(), "admin");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) {
-                assertEquals(property.getValue(), "octl.qmog.cisco.com");
-            } else if (property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) {
-                assertEquals(property.getValue(), "1");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) {
-                assertEquals(property.getValue(), "admin");
-            } else if (property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) {
-                assertEquals(property.getValue(), "test");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) {
-                assertEquals(property.getValue(), "7711");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) {
-                assertEquals(property.getValue(), "7611");
-            } else if (property.getName().equals("payload_parameter.CEP_PORT")) {
-                assertEquals(property.getValue(), "7611");
-            } else if (property.getName().equals("payload_parameter.MB_PORT")) {
-                assertEquals(property.getValue(), "61616");
-            }
-        }
-
-
-        boolean updated = restClient.updateEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
-                        cartridgeType + "-v1.json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(updated);
-        CartridgeBean updatedBean = (CartridgeBean) restClient.
-                getEntity(RestConstants.CARTRIDGES, cartridgeType,
-                        CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
-        assertEquals(updatedBean.getType(), "c0-cartridge-test");
-        assertEquals(updatedBean.getCategory(), "Data");
-        assertEquals(updatedBean.getHost(), "qmog.cisco.com12");
-        for (PropertyBean property : updatedBean.getProperty()) {
-            if (property.getName().equals("payload_parameter.CEP_IP")) {
-                assertEquals(property.getValue(), "octl.qmog.cisco.com123");
-            } else if (property.getName().equals("payload_parameter.CEP_ADMIN_PASSWORD")) {
-                assertEquals(property.getValue(), "admin123");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_IP")) {
-                assertEquals(property.getValue(), "octl.qmog.cisco.com123");
-            } else if (property.getName().equals("payload_parameter.QTCM_NETWORK_COUNT")) {
-                assertEquals(property.getValue(), "3");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_ADMIN_PASSWORD")) {
-                assertEquals(property.getValue(), "admin123");
-            } else if (property.getName().equals("payload_parameter.QTCM_DNS_SEGMENT")) {
-                assertEquals(property.getValue(), "test123");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_SECURE_PORT")) {
-                assertEquals(property.getValue(), "7712");
-            } else if (property.getName().equals("payload_parameter.MONITORING_SERVER_PORT")) {
-                assertEquals(property.getValue(), "7612");
-            } else if (property.getName().equals("payload_parameter.CEP_PORT")) {
-                assertEquals(property.getValue(), "7612");
-            } else if (property.getName().equals("payload_parameter.MB_PORT")) {
-                assertEquals(property.getValue(), "61617");
-            }
-        }
-
-        boolean removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType,
-                RestConstants.CARTRIDGES_NAME);
-        assertTrue(removed);
-
-        CartridgeBean beanRemoved = (CartridgeBean) restClient.
-                getEntity(RestConstants.CARTRIDGES, cartridgeType,
-                        CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
-        assertNull(beanRemoved);
-    }
-
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.cartridge.deployment", "smoke"})
-    public void testCartridgeList() throws Exception {
-        String cartridgeType1 = "c1-cartridge-test";
-        String cartridgeType2 = "c2-cartridge-test";
-        boolean added1 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
-                        cartridgeType1 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(added1);
-
-        boolean added2 = restClient.addEntity(RESOURCES_PATH + RestConstants.CARTRIDGES_PATH + "/" +
-                        cartridgeType2 + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
-        assertTrue(added2);
-
-        Type listType = new TypeToken<ArrayList<CartridgeBean>>() {
-        }.getType();
-
-        List<CartridgeBean> cartridgeList = (List<CartridgeBean>) restClient.listEntity(RestConstants.CARTRIDGES,
-                listType, RestConstants.CARTRIDGES_NAME);
-        assertTrue(cartridgeList.size() >= 2);
-
-        CartridgeBean bean1 = null;
-        for (CartridgeBean cartridgeBean : cartridgeList) {
-            if (cartridgeBean.getType().equals(cartridgeType1)) {
-                bean1 = cartridgeBean;
-            }
-        }
-        assertNotNull(bean1);
-
-        CartridgeBean bean2 = null;
-        for (CartridgeBean cartridgeBean : cartridgeList) {
-            if (cartridgeBean.getType().equals(cartridgeType1)) {
-                bean2 = cartridgeBean;
-            }
-        }
-        assertNotNull(bean2);
-
-        boolean removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType1,
-                RestConstants.CARTRIDGES_NAME);
-        assertTrue(removed);
-
-        CartridgeBean beanRemoved = (CartridgeBean) restClient.
-                getEntity(RestConstants.CARTRIDGES, cartridgeType1,
-                        CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
-        assertEquals(beanRemoved, null);
-
-        removed = restClient.removeEntity(RestConstants.CARTRIDGES, cartridgeType2,
-                RestConstants.CARTRIDGES_NAME);
-        assertTrue(removed);
-
-        beanRemoved = (CartridgeBean) restClient.
-                getEntity(RestConstants.CARTRIDGES, cartridgeType2,
-                        CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
-        assertNull(beanRemoved);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaaSProviderTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaaSProviderTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaaSProviderTestCase.java
index ba4a3f6..093ecc8 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaaSProviderTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaaSProviderTestCase.java
@@ -19,6 +19,8 @@
 
 package org.apache.stratos.integration.tests.iaas;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.common.beans.IaasProviderInfoBean;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
 import org.testng.annotations.Test;
@@ -34,22 +36,28 @@ import static org.testng.AssertJUnit.assertTrue;
 /**
  * IaaS provider related test cases
  */
+
+@Test(groups = { "iaas" })
 public class IaaSProviderTestCase extends StratosIntegrationTest {
+    private static final Log log = LogFactory.getLog(IaaSProviderTestCase.class);
+
     private static final String RESOURCES_PATH = "/api";
     private static final String IDENTIFIER = "/iaasProviders";
-    
-    @Test(timeOut = APPLICATION_TEST_TIMEOUT, groups = {"stratos.cartridge.iaas"})
+
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
     public void testListIaaSProviders() throws Exception {
-        assertTrue(true);  
-        
-        IaasProviderInfoBean iaasProviderInfo = (IaasProviderInfoBean) restClient.getEntity(RESOURCES_PATH,
-                IDENTIFIER, IaasProviderInfoBean.class, "IaaSProvider");
+        log.info("Running IaaSProviderTestCase.testListIaaSProviders test method...");
+        long startTime = System.currentTimeMillis();
+        assertTrue(true);
+
+        IaasProviderInfoBean iaasProviderInfo = (IaasProviderInfoBean) restClient
+                .getEntity(RESOURCES_PATH, IDENTIFIER, IaasProviderInfoBean.class, "IaaSProvider");
         assertNotNull(iaasProviderInfo);
         List<String> iaasList = iaasProviderInfo.getIaasProviders();
         for (String iaas : iaasList) {
-        	assertThat(iaas, either(containsString("kubernetes")).or(containsString("mock")) );
-		}
+            assertThat(iaas, either(containsString("kubernetes")).or(containsString("mock")));
+        }
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("IaaSProviderTestCase completed in [duration] %s ms", duration));
     }
-
-    
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaasProviderAttributeTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaasProviderAttributeTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaasProviderAttributeTestCase.java
index b6c4553..d90014e 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaasProviderAttributeTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/iaas/IaasProviderAttributeTestCase.java
@@ -28,7 +28,6 @@ import org.apache.stratos.integration.common.RestConstants;
 import org.apache.stratos.integration.common.ServerLogClient;
 import org.apache.stratos.integration.common.TopologyHandler;
 import org.apache.stratos.integration.tests.StratosIntegrationTest;
-import org.apache.stratos.messaging.domain.application.ApplicationStatus;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
@@ -39,6 +38,7 @@ import java.util.List;
 import static org.testng.Assert.*;
 import static org.testng.AssertJUnit.assertTrue;
 
+@Test(groups = { "iaas" })
 public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
 
     private static final Log log = LogFactory.getLog(IaasProviderAttributeTestCase.class);
@@ -51,34 +51,36 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
     private static final String UPDATED_CARTRIDGE = "cartridge-iaasprovider-attribute-test-updated";
     private static final String APPLICATION = "app-iaasprovider-attribute-test";
     private ServerLogClient serverLogClient;
+    private long startTime;
 
     @BeforeClass
-    public void setup () throws Exception {
+    public void setup() throws Exception {
         serverLogClient = new ServerLogClient(stratosSecuredBackendURL + "/services/", adminUsername, adminPassword);
     }
 
-    @Test(timeOut = IAAS_PROVIDER_TEST_TIMEOUT, groups = {"stratos.cartridge.iaas", "all"})
-    public void testIaasProviderAttributes () throws Exception {
+    @Test(timeOut = DEFAULT_APPLICATION_TEST_TIMEOUT)
+    public void testIaasProviderAttributes() throws Exception {
+        log.info("Running IaasProviderAttributeTestCase.testIaasProviderAttributes test method...");
+        startTime = System.currentTimeMillis();
 
         // add autoscaling policy
         log.info("Adding autoscaling policy [autoscale policy id] " + AUTOSCALING_POLICY);
         boolean addedScalingPolicy = restClient.addEntity(RESOURCES_PATH + RestConstants.
-                        AUTOSCALING_POLICIES_PATH + "/" + AUTOSCALING_POLICY + ".json",
-                RestConstants.AUTOSCALING_POLICIES, RestConstants.AUTOSCALING_POLICIES_NAME);
+                        AUTOSCALING_POLICIES_PATH + "/" + AUTOSCALING_POLICY + ".json", RestConstants
+                .AUTOSCALING_POLICIES,
+                RestConstants.AUTOSCALING_POLICIES_NAME);
         assertTrue(addedScalingPolicy);
 
         // add network partition
         log.info("Adding network partition [network partition id] " + NETWORK_PARTITION);
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + "/network-partitions" + "/" +
-                        NETWORK_PARTITION + ".json", RestConstants.NETWORK_PARTITIONS,
-                RestConstants.NETWORK_PARTITIONS_NAME);
+                NETWORK_PARTITION + ".json", RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         // add deployment policy
         log.info("Adding deployment policy [deployment policy id] " + DEPLOYMENT_POLICY);
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.DEPLOYMENT_POLICIES_PATH + "/" +
-                        DEPLOYMENT_POLICY + ".json", RestConstants.DEPLOYMENT_POLICIES,
-                RestConstants.DEPLOYMENT_POLICIES_NAME);
+                DEPLOYMENT_POLICY + ".json", RestConstants.DEPLOYMENT_POLICIES, RestConstants.DEPLOYMENT_POLICIES_NAME);
         assertTrue(addedDep);
 
         // add application policy
@@ -89,8 +91,9 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
         assertTrue(addAppPolicy);
 
         // deploy a default cartridge
-        boolean defaultCartridgeAdded = restClient.addEntity(RESOURCES_PATH + "/cartridges/" + CARTRIDGE + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean defaultCartridgeAdded = restClient
+                .addEntity(RESOURCES_PATH + "/cartridges/" + CARTRIDGE + ".json", RestConstants.CARTRIDGES,
+                        RestConstants.CARTRIDGES_NAME);
         assertTrue("Default cartridge not deployed properly", defaultCartridgeAdded);
 
         // deploy application
@@ -100,16 +103,16 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
         assertEquals(addedApp, true);
 
         // Test Iaas Provider attributes
-        CartridgeBean defaultCartridgeBean = (CartridgeBean) restClient.getEntity(RestConstants.CARTRIDGES, CARTRIDGE, CartridgeBean.class,
-                RestConstants.CARTRIDGES_NAME);
+        CartridgeBean defaultCartridgeBean = (CartridgeBean) restClient
+                .getEntity(RestConstants.CARTRIDGES, CARTRIDGE, CartridgeBean.class, RestConstants.CARTRIDGES_NAME);
 
         assertEquals(CARTRIDGE, defaultCartridgeBean.getType());
         List<IaasProviderBean> iaasProviders = defaultCartridgeBean.getIaasProvider();
         assertNotNull(iaasProviders, "No Iaas Providers found in default cartridge definition");
         IaasProviderBean mockIaasProvider = getMockIaasProvider(iaasProviders);
         assertNotNull(mockIaasProvider, "Mock Iaas Provider not found in default cartridge definition");
-        assertNotNull(mockIaasProvider.getProperty(), "No properties found in Iaas Provider " +
-                "config of default cartridge definition");
+        assertNotNull(mockIaasProvider.getProperty(),
+                "No properties found in Iaas Provider " + "config of default cartridge definition");
 
         ///applications/{applicationId}/deploy/{applicationPolicyId}
         log.info("Deploying application [application id] app-iaasprovider-attribute-test using [application policy id] "
@@ -127,14 +130,15 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
         TopologyHandler topologyHandler = TopologyHandler.getInstance();
 
         log.info("Waiting for application status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(applicationBean.getApplicationId(), ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(applicationBean.getApplicationId());
 
         // create a ServerLogClientInstance and get logs
         boolean found = false;
         LogEvent[] logEvents = serverLogClient.getAllLogLines();
         if (logEvents.length > 0) {
             for (LogEvent log : logEvents) {
-                if (!log.getMessage().contains("cartridge_property_value_1") && log.getMessage().contains("cc_property_value_1")) {
+                if (!log.getMessage().contains("cartridge_property_value_1") && log.getMessage()
+                        .contains("cc_property_value_1")) {
                     found = true;
                     break;
                 }
@@ -148,8 +152,7 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
         String resourcePathUndeploy = RestConstants.APPLICATIONS + "/app-iaasprovider-attribute-test" +
                 RestConstants.APPLICATIONS_UNDEPLOY;
 
-        boolean undeployedApp = restClient.undeployEntity(resourcePathUndeploy, RestConstants
-                .APPLICATIONS_NAME);
+        boolean undeployedApp = restClient.undeployEntity(resourcePathUndeploy, RestConstants.APPLICATIONS_NAME);
         assertTrue(undeployedApp);
         log.info("Undeployed application 'app-iaasprovider-attribute-test'");
 
@@ -159,12 +162,14 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
                 RestConstants.APPLICATIONS_UNDEPLOY + "?force=true", RestConstants.APPLICATIONS);
 
         boolean forceUndeployed = topologyHandler.assertApplicationUndeploy("app-iaasprovider-attribute-test");
-        assertTrue(String.format("Forceful undeployment failed for the application %s",
-                "app-iaasprovider-attribute-test"), forceUndeployed);
+        assertTrue(
+                String.format("Forceful undeployment failed for the application %s", "app-iaasprovider-attribute-test"),
+                forceUndeployed);
 
         // update cartridge
-        boolean updated = restClient.updateEntity(RESOURCES_PATH + "/cartridges/" + UPDATED_CARTRIDGE + ".json",
-                RestConstants.CARTRIDGES, RestConstants.CARTRIDGES_NAME);
+        boolean updated = restClient
+                .updateEntity(RESOURCES_PATH + "/cartridges/" + UPDATED_CARTRIDGE + ".json", RestConstants.CARTRIDGES,
+                        RestConstants.CARTRIDGES_NAME);
         assertTrue(updated);
         log.info("Updated cartridge 'cartridge-iaasprovider-attribute-test'");
 
@@ -176,7 +181,7 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
         log.info("Re-deployed application 'app-iaasprovider-attribute-test'");
 
         log.info("Waiting for application status to become ACTIVE...");
-        topologyHandler.assertApplicationStatus(applicationBean.getApplicationId(), ApplicationStatus.Active);
+        TopologyHandler.getInstance().assertApplicationActiveStatus(applicationBean.getApplicationId());
 
         logEvents = serverLogClient.getAllLogLines();
         found = false;
@@ -193,8 +198,10 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
     }
 
     @AfterClass
-    public void tearDown () throws Exception {
+    public void tearDown() throws Exception {
         terminateAndRemoveAllArtifacts();
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("IaasProviderAttributeTestCase completed in [duration] %s ms", duration));
     }
 
     private IaasProviderBean getMockIaasProvider(List<IaasProviderBean> iaasProviders) {
@@ -206,7 +213,7 @@ public class IaasProviderAttributeTestCase extends StratosIntegrationTest {
         return null;
     }
 
-    private void terminateAndRemoveAllArtifacts () throws Exception {
+    private void terminateAndRemoveAllArtifacts() throws Exception {
 
         TopologyHandler topologyHandler = TopologyHandler.getInstance();
 

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTestCase.java
index 2ae3207..8862301 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/ApplicationPolicyTestCase.java
@@ -40,31 +40,37 @@ import static org.testng.AssertJUnit.assertTrue;
 /**
  * Test to handle Network partition CRUD operations
  */
+@Test(groups = { "policies" })
 public class ApplicationPolicyTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(ApplicationPolicyTestCase.class);
     private static final String RESOURCES_PATH = "/application-policy-test";
+    private long startTime;
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT,
+          priority = 1)
     public void testApplicationPolicy() throws Exception {
+        log.info("Running ApplicationPolicyTestCase.testApplicationPolicy test method...");
+        startTime = System.currentTimeMillis();
+
         String applicationPolicyId = "application-policy-application-policy-test";
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        "network-partition-application-policy-test-1" + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                        "network-partition-application-policy-test-1" + ".json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        "network-partition-application-policy-test-2" + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                        "network-partition-application-policy-test-2" + ".json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN2);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
-                        applicationPolicyId + ".json",
-                RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME);
+                        applicationPolicyId + ".json", RestConstants.APPLICATION_POLICIES,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(addedDep);
 
         ApplicationPolicyBean bean = (ApplicationPolicyBean) restClient.
-                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
-                        ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME);
+                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, ApplicationPolicyBean.class,
+                        RestConstants.APPLICATION_POLICIES_NAME);
         assertEquals(bean.getId(), applicationPolicyId);
         assertEquals(bean.getAlgorithm(), "one-after-another",
                 String.format("The expected algorithm %s is not found in %s", "one-after-another",
@@ -85,33 +91,34 @@ public class ApplicationPolicyTestCase extends StratosIntegrationTest {
                 assertEquals(propertyBean.getValue(),
                         "network-partition-application-policy-test-1,network-partition-application-policy-test-2",
                         String.format("The networkPartitionGroups algorithm %s is not found in %s",
-                                "network-partition-application-policy-test-1, network-partition-application-policy-test-2",
-                                applicationPolicyId));
+                                "network-partition-application-policy-test-1, "
+                                        + "network-partition-application-policy-test-2", applicationPolicyId));
                 algoFound = true;
 
             }
         }
         if (!algoFound) {
-            assertNull(String.format("The networkPartitionGroups property is not found in %s",
-                    applicationPolicyId));
+            assertNull(String.format("The networkPartitionGroups property is not found in %s", applicationPolicyId));
         }
 
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         //Trying to remove the used network partition
         assertFalse(removedNet);
 
-        boolean removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removedDep);
 
         ApplicationPolicyBean beanRemovedDep = (ApplicationPolicyBean) restClient.
-                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId,
-                        ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME);
+                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId, ApplicationPolicyBean.class,
+                        RestConstants.APPLICATION_POLICIES_NAME);
         assertNull(beanRemovedDep);
 
-        boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedN1 = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedN1);
 
         NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient.
@@ -119,8 +126,9 @@ public class ApplicationPolicyTestCase extends StratosIntegrationTest {
                         NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME);
         assertNull(beanRemovedN1);
 
-        boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-application-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedN2 = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedN2);
 
         NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient.
@@ -129,37 +137,37 @@ public class ApplicationPolicyTestCase extends StratosIntegrationTest {
         assertNull(beanRemovedN2);
     }
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT,
+          priority = 2)
     public void testApplicationPolicyList() throws Exception {
         String applicationPolicyId1 = "application-policy-application-policy-test-1";
         String applicationPolicyId2 = "application-policy-application-policy-test-2";
 
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        "network-partition-application-policy-test-1" + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                        "network-partition-application-policy-test-1" + ".json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN1);
 
         boolean addedN2 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
-                        "network-partition-application-policy-test-2" + ".json",
-                RestConstants.NETWORK_PARTITIONS, RestConstants.NETWORK_PARTITIONS_NAME);
+                        "network-partition-application-policy-test-2" + ".json", RestConstants.NETWORK_PARTITIONS,
+                RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(addedN2);
 
         boolean addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
-                        applicationPolicyId1 + ".json",
-                RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME);
+                        applicationPolicyId1 + ".json", RestConstants.APPLICATION_POLICIES,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(addedDep);
 
         addedDep = restClient.addEntity(RESOURCES_PATH + RestConstants.APPLICATION_POLICIES_PATH + "/" +
-                        applicationPolicyId2 + ".json",
-                RestConstants.APPLICATION_POLICIES, RestConstants.APPLICATION_POLICIES_NAME);
+                        applicationPolicyId2 + ".json", RestConstants.APPLICATION_POLICIES,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(addedDep);
 
         Type listType = new TypeToken<ArrayList<ApplicationPolicyBean>>() {
         }.getType();
 
         List<ApplicationPolicyBean> applicationPolicyList = (List<ApplicationPolicyBean>) restClient.
-                listEntity(RestConstants.APPLICATION_POLICIES,
-                        listType, RestConstants.APPLICATION_POLICIES_NAME);
+                listEntity(RestConstants.APPLICATION_POLICIES, listType, RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(applicationPolicyList.size() >= 2);
 
         ApplicationPolicyBean bean1 = null;
@@ -178,31 +186,33 @@ public class ApplicationPolicyTestCase extends StratosIntegrationTest {
         }
         assertNotNull(bean2);
 
-        boolean removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId1, RestConstants.APPLICATION_POLICIES_NAME);
+        boolean removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId1,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removedDep);
 
         ApplicationPolicyBean beanRemovedDep = (ApplicationPolicyBean) restClient.
-                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId1,
-                        ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME);
+                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId1, ApplicationPolicyBean.class,
+                        RestConstants.APPLICATION_POLICIES_NAME);
         assertNull(beanRemovedDep);
 
-        boolean removedNet = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedNet = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         //Trying to remove the used network partition
         assertFalse(removedNet);
 
-        removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES,
-                applicationPolicyId2, RestConstants.APPLICATION_POLICIES_NAME);
+        removedDep = restClient.removeEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId2,
+                RestConstants.APPLICATION_POLICIES_NAME);
         assertTrue(removedDep);
 
         beanRemovedDep = (ApplicationPolicyBean) restClient.
-                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId2,
-                        ApplicationPolicyBean.class, RestConstants.APPLICATION_POLICIES_NAME);
+                getEntity(RestConstants.APPLICATION_POLICIES, applicationPolicyId2, ApplicationPolicyBean.class,
+                        RestConstants.APPLICATION_POLICIES_NAME);
         assertNull(beanRemovedDep);
 
-        boolean removedN1 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-application-policy-test-1", RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedN1 = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-1",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedN1);
 
         NetworkPartitionBean beanRemovedN1 = (NetworkPartitionBean) restClient.
@@ -210,13 +220,16 @@ public class ApplicationPolicyTestCase extends StratosIntegrationTest {
                         NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME);
         assertNull(beanRemovedN1);
 
-        boolean removedN2 = restClient.removeEntity(RestConstants.NETWORK_PARTITIONS,
-                "network-partition-application-policy-test-2", RestConstants.NETWORK_PARTITIONS_NAME);
+        boolean removedN2 = restClient
+                .removeEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2",
+                        RestConstants.NETWORK_PARTITIONS_NAME);
         assertTrue(removedN2);
 
         NetworkPartitionBean beanRemovedN2 = (NetworkPartitionBean) restClient.
                 getEntity(RestConstants.NETWORK_PARTITIONS, "network-partition-application-policy-test-2",
                         NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME);
         assertNull(beanRemovedN2);
+        long duration = System.currentTimeMillis() - startTime;
+        log.info(String.format("IaaSProviderTestCase completed in [duration] %s ms", duration));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java
index 24da49f..a6fc43b 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/AutoscalingPolicyTestCase.java
@@ -35,11 +35,12 @@ import static org.testng.AssertJUnit.*;
 /**
  * Test to handle autoscaling policy CRUD operations
  */
+@Test(groups = { "policies" })
 public class AutoscalingPolicyTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(AutoscalingPolicyTestCase.class);
     private static final String RESOURCES_PATH = "/autoscaling-policy-test";
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void testAutoscalingPolicy() throws Exception {
         String policyId = "autoscaling-policy-autoscaling-policy-test";
         boolean added = restClient
@@ -87,7 +88,7 @@ public class AutoscalingPolicyTestCase extends StratosIntegrationTest {
                 policyId), beanRemoved);
     }
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void testAutoscalingPolicyList() throws Exception {
         String policyId1 = "autoscaling-policy-autoscaling-policy-test-1";
         String policyId2 = "autoscaling-policy-autoscaling-policy-test-2";

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java
index 866132a..854c84d 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/DeploymentPolicyTestCase.java
@@ -40,11 +40,12 @@ import static org.testng.AssertJUnit.*;
 /**
  * Test to handle Deployment policy CRUD operations
  */
+@Test(groups = { "policies" })
 public class DeploymentPolicyTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(DeploymentPolicyTestCase.class);
     private static final String RESOURCES_PATH = "/deployment-policy-test";
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void testDeploymentPolicy() throws Exception {
         String deploymentPolicyId = "deployment-policy-deployment-policy-test";
         boolean addedN1 = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
@@ -166,7 +167,7 @@ public class DeploymentPolicyTestCase extends StratosIntegrationTest {
         assertNull(beanRemovedN2);
     }
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void testDeploymentPolicyList() throws Exception {
         String deploymentPolicyId1 = "deployment-policy-deployment-policy-test-1";
         String deploymentPolicyId2 = "deployment-policy-deployment-policy-test-2";
@@ -258,4 +259,4 @@ public class DeploymentPolicyTestCase extends StratosIntegrationTest {
                         DeploymentPolicyBean.class, RestConstants.NETWORK_PARTITIONS_NAME);
         assertNull(beanRemovedN2);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java
index ce8e4f5..9ddbafc 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/policies/NetworkPartitionTestCase.java
@@ -38,11 +38,12 @@ import static org.testng.AssertJUnit.*;
 /**
  * Test to handle Network partition CRUD operations
  */
+@Test(groups = { "policies" })
 public class NetworkPartitionTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(NetworkPartitionTestCase.class);
     private static final String RESOURCES_PATH = "/network-partition-test";
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void testNetworkPartition() throws Exception {
         String networkPartitionId = "network-partition-network-partition-test";
         boolean added = restClient.addEntity(RESOURCES_PATH + RestConstants.NETWORK_PARTITIONS_PATH + "/" +
@@ -89,7 +90,7 @@ public class NetworkPartitionTestCase extends StratosIntegrationTest {
         assertNull(beanRemoved);
     }
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"stratos.policy.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void testNetworkPartitionList() throws Exception {
         String networkPartitionId1 = "network-partition-network-partition-test-1";
         String networkPartitionId2 = "network-partition-network-partition-test-2";
@@ -144,4 +145,4 @@ public class NetworkPartitionTestCase extends StratosIntegrationTest {
                         NetworkPartitionBean.class, RestConstants.NETWORK_PARTITIONS_NAME);
         assertNull(beanRemoved);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java
index e64926f..e9696e1 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/TenantTestCase.java
@@ -28,15 +28,15 @@ import static junit.framework.Assert.assertTrue;
 /**
  * Handling users
  */
+@Test(groups = { "users", "disabled" })
 public class TenantTestCase extends StratosIntegrationTest {
     private static final String RESOURCES_PATH = "/user-test";
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"user.management", "smoke", "disabled"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void addUser() throws Exception {
         String tenantId = "tenant-1";
         boolean addedUser1 = restClient.addEntity(RESOURCES_PATH + "/" +
-                        tenantId + ".json",
-                RestConstants.USERS, RestConstants.USERS_NAME);
+                tenantId + ".json", RestConstants.USERS, RestConstants.USERS_NAME);
         assertTrue(addedUser1);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/35eb6c22/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java
----------------------------------------------------------------------
diff --git a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java
index 24d8a5b..4ee721f 100644
--- a/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java
+++ b/products/stratos/modules/integration/test-integration/src/test/java/org/apache/stratos/integration/tests/users/UserTestCase.java
@@ -35,11 +35,12 @@ import static org.testng.AssertJUnit.*;
 /**
  * Handling users
  */
+@Test(groups = { "users" })
 public class UserTestCase extends StratosIntegrationTest {
     private static final Log log = LogFactory.getLog(UserTestCase.class);
     private static final String RESOURCES_PATH = "/user-test";
 
-    @Test(timeOut = GLOBAL_TEST_TIMEOUT, groups = {"user.management", "smoke"})
+    @Test(timeOut = DEFAULT_TEST_TIMEOUT)
     public void addUser() throws Exception {
         String userId = "user-1";
         boolean addedUser1 = restClient.addEntity(RESOURCES_PATH + "/" +
@@ -101,4 +102,4 @@ public class UserTestCase extends StratosIntegrationTest {
         }
         assertNull(bean1);
     }
-}
\ No newline at end of file
+}


[04/28] stratos git commit: Added null check for appMonitor object in ClusterInstanceTerminatedEventListener. Fixed formatting and log messages.

Posted by ra...@apache.org.
Added null check for appMonitor object in ClusterInstanceTerminatedEventListener. Fixed formatting and log messages.


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

Branch: refs/heads/stratos-4.1.x
Commit: d0f0f81bd8a6a142eb4eeda36276d3dac9ff44c5
Parents: d587011
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:12:43 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:46 2015 +0530

----------------------------------------------------------------------
 .../AutoscalerTopologyEventReceiver.java        | 277 +++++++++----------
 1 file changed, 130 insertions(+), 147 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/d0f0f81b/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 500b95a..8336f86 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
@@ -35,8 +35,6 @@ import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
 import org.apache.stratos.autoscaler.monitor.events.ClusterStatusEvent;
 import org.apache.stratos.autoscaler.util.AutoscalerUtil;
 import org.apache.stratos.autoscaler.util.ServiceReferenceHolder;
-import org.apache.stratos.messaging.broker.publish.EventPublisher;
-import org.apache.stratos.messaging.broker.publish.EventPublisherPool;
 import org.apache.stratos.messaging.domain.application.Application;
 import org.apache.stratos.messaging.domain.application.Applications;
 import org.apache.stratos.messaging.domain.instance.ClusterInstance;
@@ -44,12 +42,10 @@ import org.apache.stratos.messaging.domain.topology.Cluster;
 import org.apache.stratos.messaging.domain.topology.ClusterStatus;
 import org.apache.stratos.messaging.domain.topology.Service;
 import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.event.initializer.CompleteTopologyRequestEvent;
 import org.apache.stratos.messaging.event.topology.*;
 import org.apache.stratos.messaging.listener.topology.*;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
 import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-import org.apache.stratos.messaging.util.MessagingUtil;
 
 import java.util.concurrent.ExecutorService;
 
@@ -57,9 +53,7 @@ import java.util.concurrent.ExecutorService;
  * Autoscaler topology receiver.
  */
 public class AutoscalerTopologyEventReceiver {
-
     private static final Log log = LogFactory.getLog(AutoscalerTopologyEventReceiver.class);
-
     private TopologyEventReceiver topologyEventReceiver;
     private boolean terminated;
     private boolean topologyInitialized;
@@ -72,10 +66,8 @@ public class AutoscalerTopologyEventReceiver {
 
     public void execute() {
         //FIXME this activated before autoscaler deployer activated.
-
         topologyEventReceiver.setExecutorService(getExecutorService());
         topologyEventReceiver.execute();
-
         if (log.isInfoEnabled()) {
             log.info("Autoscaler topology receiver thread started");
         }
@@ -87,29 +79,27 @@ public class AutoscalerTopologyEventReceiver {
             @Override
             protected void onEvent(Event event) {
                 if (!topologyInitialized) {
-                    log.info("[CompleteTopologyEvent] Received: " + event.getClass());
+                    log.info("[CompleteTopologyEvent] received: " + event.getClass());
                     try {
                         ApplicationHolder.acquireReadLock();
                         Applications applications = ApplicationHolder.getApplications();
                         if (applications != null) {
                             for (Application application : applications.
                                     getApplications().values()) {
-                                ApplicationContext applicationContext =
-                                        AutoscalerContext.getInstance().
-                                                getApplicationContext(application.getUniqueIdentifier());
+                                ApplicationContext applicationContext = AutoscalerContext.getInstance().
+                                        getApplicationContext(application.getUniqueIdentifier());
                                 if (applicationContext != null && applicationContext.getStatus().
                                         equals(ApplicationContext.STATUS_DEPLOYED)) {
                                     if (AutoscalerUtil.allClustersInitialized(application)) {
-                                        AutoscalerUtil.getInstance().startApplicationMonitor(
-                                                application.getUniqueIdentifier());
+                                        AutoscalerUtil.getInstance()
+                                                .startApplicationMonitor(application.getUniqueIdentifier());
                                     } else {
-                                        log.error("Complete Topology is not consistent with " +
-                                                "the applications which got persisted");
+                                        log.error("Complete Topology is not consistent with the applications which got "
+                                                + "persisted");
                                     }
                                 } else {
-                                    log.info("The application is not yet " +
-                                            "deployed for this [application] " +
-                                            application.getUniqueIdentifier());
+                                    log.info("The application is not yet deployed for this [application] " + application
+                                            .getUniqueIdentifier());
                                 }
 
                             }
@@ -126,14 +116,13 @@ public class AutoscalerTopologyEventReceiver {
             }
         });
 
-
         topologyEventReceiver.addEventListener(new ApplicationClustersCreatedEventListener() {
             @Override
             protected void onEvent(Event event) {
                 try {
-                    log.info("[ApplicationClustersCreatedEvent] Received: " + event.getClass());
-                    ApplicationClustersCreatedEvent applicationClustersCreatedEvent =
-                            (ApplicationClustersCreatedEvent) event;
+                    log.info("[ApplicationClustersCreatedEvent] received: " + event.getClass());
+                    ApplicationClustersCreatedEvent applicationClustersCreatedEvent
+                            = (ApplicationClustersCreatedEvent) event;
                     String appId = applicationClustersCreatedEvent.getAppId();
                     try {
                         //acquire read lock
@@ -141,28 +130,26 @@ public class AutoscalerTopologyEventReceiver {
                         //start the application monitor
                         ApplicationContext applicationContext = AutoscalerContext.getInstance().
                                 getApplicationContext(appId);
-                        if (applicationContext != null &&
-                                applicationContext.getStatus().
-                                        equals(ApplicationContext.STATUS_DEPLOYED)) {
+                        if (applicationContext != null && applicationContext.getStatus().
+                                equals(ApplicationContext.STATUS_DEPLOYED)) {
                             if (!AutoscalerContext.getInstance().
                                     containsApplicationPendingMonitor(appId)) {
                                 AutoscalerUtil.getInstance().startApplicationMonitor(appId);
                             }
                         } else {
                             String status;
-                            if(applicationContext == null) {
+                            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);
+                            log.error(String.format(
+                                    "Error while creating the application monitor due to inconsistent persistence of "
+                                            + "[application] %s, [application-context] %s, [status] %s",
+                                    applicationClustersCreatedEvent.getAppId(), applicationContext, status));
                         }
                     } catch (Exception e) {
-                        String msg = "Error processing event " + e.getLocalizedMessage();
+                        String msg = "Error processing ApplicationClustersCreatedEvent: " + e.getLocalizedMessage();
                         log.error(msg, e);
                     } finally {
                         //release read lock
@@ -179,7 +166,7 @@ public class AutoscalerTopologyEventReceiver {
         topologyEventReceiver.addEventListener(new ClusterInstanceActivatedEventListener() {
             @Override
             protected void onEvent(Event event) {
-                log.info("[ClusterActivatedEvent] Received: " + event.getClass());
+                log.info("[ClusterActivatedEvent] received: " + event.getClass());
                 ClusterInstanceActivatedEvent clusterActivatedEvent = (ClusterInstanceActivatedEvent) event;
                 String clusterId = clusterActivatedEvent.getClusterId();
                 String instanceId = clusterActivatedEvent.getInstanceId();
@@ -188,8 +175,8 @@ public class AutoscalerTopologyEventReceiver {
                 monitor = asCtx.getClusterMonitor(clusterId);
                 if (null == monitor) {
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                + "[cluster] %s", clusterId));
+                        log.debug(String.format("Cluster monitor is not found in autoscaler context [cluster-id] %s",
+                                clusterId));
                     }
                     return;
                 }
@@ -202,7 +189,7 @@ public class AutoscalerTopologyEventReceiver {
         topologyEventReceiver.addEventListener(new ClusterResetEventListener() {
             @Override
             protected void onEvent(Event event) {
-                log.info("[ClusterCreatedEvent] Received: " + event.getClass());
+                log.info("[ClusterCreatedEvent] received: " + event.getClass());
                 ClusterResetEvent clusterResetEvent = (ClusterResetEvent) event;
                 String clusterId = clusterResetEvent.getClusterId();
                 String instanceId = clusterResetEvent.getInstanceId();
@@ -211,8 +198,8 @@ public class AutoscalerTopologyEventReceiver {
                 monitor = asCtx.getClusterMonitor(clusterId);
                 if (null == monitor) {
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                + "[cluster] %s", clusterId));
+                        log.debug(String.format("Cluster monitor is not found in autoscaler context [cluster-id] %s",
+                                clusterId));
                     }
                     return;
                 }
@@ -226,14 +213,14 @@ public class AutoscalerTopologyEventReceiver {
         topologyEventReceiver.addEventListener(new ClusterCreatedEventListener() {
             @Override
             protected void onEvent(Event event) {
-                log.info("[ClusterCreatedEvent] Received: " + event.getClass());
+                log.info("[ClusterCreatedEvent] received: " + event.getClass());
             }
         });
 
         topologyEventReceiver.addEventListener(new ClusterInstanceInactivateEventListener() {
             @Override
             protected void onEvent(Event event) {
-                log.info("[ClusterInactivateEvent] Received: " + event.getClass());
+                log.info("[ClusterInactivateEvent] received: " + event.getClass());
                 ClusterInstanceInactivateEvent clusterInactivateEvent = (ClusterInstanceInactivateEvent) event;
                 String clusterId = clusterInactivateEvent.getClusterId();
                 String instanceId = clusterInactivateEvent.getInstanceId();
@@ -242,8 +229,8 @@ public class AutoscalerTopologyEventReceiver {
                 monitor = asCtx.getClusterMonitor(clusterId);
                 if (null == monitor) {
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                + "[cluster] %s", clusterId));
+                        log.debug(String.format("Cluster monitor is not found in autoscaler context " + "[cluster] %s",
+                                clusterId));
                     }
                     return;
                 }
@@ -255,7 +242,7 @@ public class AutoscalerTopologyEventReceiver {
         topologyEventReceiver.addEventListener(new ClusterInstanceTerminatingEventListener() {
             @Override
             protected void onEvent(Event event) {
-                log.info("[ClusterTerminatingEvent] Received: " + event.getClass());
+                log.info("[ClusterTerminatingEvent] received: " + event.getClass());
                 ClusterInstanceTerminatingEvent clusterTerminatingEvent = (ClusterInstanceTerminatingEvent) event;
                 String clusterId = clusterTerminatingEvent.getClusterId();
                 String clusterInstanceId = clusterTerminatingEvent.getInstanceId();
@@ -264,8 +251,8 @@ public class AutoscalerTopologyEventReceiver {
                 monitor = asCtx.getClusterMonitor(clusterId);
                 if (null == monitor) {
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                + "[cluster] %s", clusterId));
+                        log.debug(String.format("Cluster monitor is not found in autoscaler context " + "[cluster] %s",
+                                clusterId));
                     }
                     // if monitor does not exist, send cluster terminated event
                     ClusterStatusEventPublisher.sendClusterTerminatedEvent(clusterTerminatingEvent.getAppId(),
@@ -280,11 +267,9 @@ public class AutoscalerTopologyEventReceiver {
                     InstanceNotificationPublisher.getInstance().
                             sendInstanceCleanupEventForCluster(clusterId, clusterInstanceId);
                     //Terminating the pending members
-                    monitor.terminatePendingMembers(clusterInstanceId,
-                            clusterInstance.getNetworkPartitionId());
+                    monitor.terminatePendingMembers(clusterInstanceId, clusterInstance.getNetworkPartitionId());
                     //Move all members to terminating pending list
-                    monitor.moveMembersToTerminatingPending(clusterInstanceId,
-                            clusterInstance.getNetworkPartitionId());
+                    monitor.moveMembersToTerminatingPending(clusterInstanceId, clusterInstance.getNetworkPartitionId());
                 } else {
                     monitor.notifyParentMonitor(ClusterStatus.Terminating, clusterInstanceId);
                     monitor.terminateAllMembers(clusterInstanceId, clusterInstance.getNetworkPartitionId());
@@ -297,7 +282,7 @@ public class AutoscalerTopologyEventReceiver {
         topologyEventReceiver.addEventListener(new ClusterInstanceTerminatedEventListener() {
             @Override
             protected void onEvent(Event event) {
-                log.info("[ClusterTerminatedEvent] Received: " + event.getClass());
+                log.info("[ClusterTerminatedEvent] received: " + event.getClass());
                 ClusterInstanceTerminatedEvent clusterTerminatedEvent = (ClusterInstanceTerminatedEvent) event;
                 String clusterId = clusterTerminatedEvent.getClusterId();
                 String instanceId = clusterTerminatedEvent.getInstanceId();
@@ -309,16 +294,15 @@ public class AutoscalerTopologyEventReceiver {
                         getAppMonitor(clusterTerminatedEvent.getAppId());
                 if (null == monitor) {
                     if (log.isDebugEnabled()) {
-                        log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                + "[cluster] %s", clusterId));
+                        log.debug(String.format("Cluster monitor is not found in autoscaler context [cluster] %s",
+                                clusterId));
                     }
-                    // if the cluster monitor is null, assume that its termianted
+                    // if the cluster monitor is null, assume that it is terminated
                     appMonitor = AutoscalerContext.getInstance().
                             getAppMonitor(clusterTerminatedEvent.getAppId());
                     if (appMonitor != null && !appMonitor.isForce()) {
                         appMonitor.onChildStatusEvent(
-                                new ClusterStatusEvent(ClusterStatus.Terminated,
-                                        clusterId, instanceId));
+                                new ClusterStatusEvent(ClusterStatus.Terminated, clusterId, instanceId));
                     }
                     return;
                 }
@@ -330,7 +314,7 @@ public class AutoscalerTopologyEventReceiver {
                         getNetworkPartitionCtxt(instance.getNetworkPartitionId()).
                         removeInstanceContext(instanceId);
                 monitor.removeInstance(instanceId);
-                if (!monitor.hasInstance() && appMonitor.isTerminating()) {
+                if (!monitor.hasInstance() && (appMonitor != null && appMonitor.isTerminating())) {
                     //Destroying and Removing the Cluster monitor
                     monitor.destroy();
                     AutoscalerContext.getInstance().removeClusterMonitor(clusterId);
@@ -343,7 +327,7 @@ public class AutoscalerTopologyEventReceiver {
             @Override
             protected void onEvent(Event event) {
                 try {
-                    log.info("[MemberReadyToShutdownEvent] Received: " + event.getClass());
+                    log.info("[MemberReadyToShutdownEvent] received: " + event.getClass());
                     MemberReadyToShutdownEvent memberReadyToShutdownEvent = (MemberReadyToShutdownEvent) event;
                     String clusterId = memberReadyToShutdownEvent.getClusterId();
                     AutoscalerContext asCtx = AutoscalerContext.getInstance();
@@ -351,20 +335,19 @@ public class AutoscalerTopologyEventReceiver {
                     monitor = asCtx.getClusterMonitor(clusterId);
                     if (null == monitor) {
                         if (log.isDebugEnabled()) {
-                            log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                    + "[cluster] %s", clusterId));
+                            log.debug(String.format(
+                                    "Cluster monitor is not found in autoscaler context " + "[cluster] %s", clusterId));
                         }
                         return;
                     }
                     monitor.handleMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
                 } catch (Exception e) {
-                    String msg = "Error processing event " + e.getLocalizedMessage();
+                    String msg = "Error processing MemberReadyToShutdownEvent: " + e.getLocalizedMessage();
                     log.error(msg, e);
                 }
             }
         });
 
-
         topologyEventReceiver.addEventListener(new MemberStartedEventListener() {
             @Override
             protected void onEvent(Event event) {
@@ -383,14 +366,14 @@ public class AutoscalerTopologyEventReceiver {
                     monitor = asCtx.getClusterMonitor(clusterId);
                     if (null == monitor) {
                         if (log.isDebugEnabled()) {
-                            log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                    + "[cluster] %s", clusterId));
+                            log.debug(String.format(
+                                    "Cluster monitor is not found in autoscaler context " + "[cluster] %s", clusterId));
                         }
                         return;
                     }
                     monitor.handleMemberTerminatedEvent(memberTerminatedEvent);
                 } catch (Exception e) {
-                    String msg = "Error processing event " + e.getLocalizedMessage();
+                    String msg = "Error processing MemberTerminatedEvent: " + e.getLocalizedMessage();
                     log.error(msg, e);
                 }
             }
@@ -408,14 +391,14 @@ public class AutoscalerTopologyEventReceiver {
                     monitor = asCtx.getClusterMonitor(clusterId);
                     if (null == monitor) {
                         if (log.isDebugEnabled()) {
-                            log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                    + "[cluster] %s", clusterId));
+                            log.debug(String.format(
+                                    "Cluster monitor is not found in autoscaler context " + "[cluster] %s", clusterId));
                         }
                         return;
                     }
                     monitor.handleMemberActivatedEvent(memberActivatedEvent);
                 } catch (Exception e) {
-                    String msg = "Error processing event " + e.getLocalizedMessage();
+                    String msg = "Error processing MemberActivatedEvent: " + e.getLocalizedMessage();
                     log.error(msg, e);
                 }
             }
@@ -432,101 +415,101 @@ public class AutoscalerTopologyEventReceiver {
                     monitor = asCtx.getClusterMonitor(clusterId);
                     if (null == monitor) {
                         if (log.isDebugEnabled()) {
-                            log.debug(String.format("A cluster monitor is not found in autoscaler context "
-                                    + "[cluster] %s", clusterId));
+                            log.debug(String.format("Cluster monitor is not found in autoscaler context [cluster] %s",
+                                    clusterId));
                         }
                         return;
                     }
                     monitor.handleMemberMaintenanceModeEvent(maintenanceModeEvent);
                 } catch (Exception e) {
-                    String msg = "Error processing event " + e.getLocalizedMessage();
+                    String msg = "Error processing MemberMaintenanceModeEvent: " + e.getLocalizedMessage();
                     log.error(msg, e);
                 }
             }
         });
 
         topologyEventReceiver.addEventListener(new ClusterInstanceCreatedEventListener() {
-                                                   @Override
-                                                   protected void onEvent(Event event) {
-
-                                                       ClusterInstanceCreatedEvent clusterInstanceCreatedEvent =
-                                                               (ClusterInstanceCreatedEvent) event;
-                                                       ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().
-                                                               getClusterMonitor(clusterInstanceCreatedEvent.getClusterId());
-                                                       ClusterInstance clusterInstance = ((ClusterInstanceCreatedEvent) event).
-                                                               getClusterInstance();
-                                                       String instanceId = clusterInstance.getInstanceId();
-                                                       //FIXME to take lock when clusterMonitor is running
-                                                       if (clusterMonitor != null) {
-                                                           TopologyManager.acquireReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
-                                                                   clusterInstanceCreatedEvent.getClusterId());
-
-                                                           try {
-                                                               Service service = TopologyManager.getTopology().
-                                                                       getService(clusterInstanceCreatedEvent.getServiceName());
-
-                                                               if (service != null) {
-                                                                   Cluster cluster = service.getCluster(clusterInstanceCreatedEvent.getClusterId());
-                                                                   if (cluster != null) {
-                                                                       try {
-                                                                           ClusterContext clusterContext =
-                                                                                   (ClusterContext) clusterMonitor.getClusterContext();
-                                                                           if (clusterContext == null) {
-                                                                               clusterContext = ClusterContextFactory.getVMClusterContext(instanceId, cluster,
-                                                                                       clusterMonitor.hasScalingDependents(), clusterMonitor.getDeploymentPolicyId());
-                                                                               clusterMonitor.setClusterContext(clusterContext);
-
-                                                                           }
-                                                                           log.info(" Cluster monitor has scaling dependents"
-                                                                                   + "  [" + clusterMonitor.hasScalingDependents() + "] "); // TODO -- remove this log..
-                                                                           clusterContext.addInstanceContext(instanceId, cluster,
-                                                                                   clusterMonitor.hasScalingDependents(), clusterMonitor.groupScalingEnabledSubtree());
-                                                                           if (clusterMonitor.getInstance(instanceId) == null) {
-                                                                               // adding the same instance in topology to monitor as a reference
-                                                                               ClusterInstance clusterInstance1 = cluster.getInstanceContexts(instanceId);
-                                                                               clusterMonitor.addInstance(clusterInstance1);
-                                                                           }
-
-                                                                           if (clusterMonitor.hasMonitoringStarted().compareAndSet(false, true)) {
-                                                                               clusterMonitor.startScheduler();
-                                                                               log.info("Monitoring task for Cluster Monitor with cluster id "
-                                                                                       + clusterInstanceCreatedEvent.getClusterId() + " started successfully");
-                                                                           } else {
-                                                                               //monitor already started. Invoking it directly to speed up the process
-                                                                               ((ClusterMonitor) clusterMonitor).monitor();
-                                                                           }
-                                                                       } catch (PolicyValidationException e) {
-                                                                           log.error(e.getMessage(), e);
-                                                                       } catch (PartitionValidationException e) {
-                                                                           log.error(e.getMessage(), e);
-                                                                       }
-                                                                   }
-
-                                                               } else {
-                                                                   log.error("Service " + clusterInstanceCreatedEvent.getServiceName() +
-                                                                           " not found, no cluster instance added to ClusterMonitor " +
-                                                                           clusterInstanceCreatedEvent.getClusterId());
-                                                               }
-
-                                                           } finally {
-                                                               TopologyManager.releaseReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
-                                                                       clusterInstanceCreatedEvent.getClusterId());
-                                                           }
-
-                                                       } else {
-                                                           log.error("No Cluster Monitor found for cluster id " +
-                                                                   clusterInstanceCreatedEvent.getClusterId());
-                                                       }
-                                                   }
-                                               }
-
-        );
+            @Override
+            protected void onEvent(Event event) {
+
+                ClusterInstanceCreatedEvent clusterInstanceCreatedEvent = (ClusterInstanceCreatedEvent) event;
+                ClusterMonitor clusterMonitor = AutoscalerContext.getInstance().
+                        getClusterMonitor(clusterInstanceCreatedEvent.getClusterId());
+                ClusterInstance clusterInstance = ((ClusterInstanceCreatedEvent) event).
+                        getClusterInstance();
+                String instanceId = clusterInstance.getInstanceId();
+                //FIXME to take lock when clusterMonitor is running
+                if (clusterMonitor != null) {
+                    TopologyManager.acquireReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
+                            clusterInstanceCreatedEvent.getClusterId());
+
+                    try {
+                        Service service = TopologyManager.getTopology().
+                                getService(clusterInstanceCreatedEvent.getServiceName());
+
+                        if (service != null) {
+                            Cluster cluster = service.getCluster(clusterInstanceCreatedEvent.getClusterId());
+                            if (cluster != null) {
+                                try {
+                                    ClusterContext clusterContext = (ClusterContext) clusterMonitor.getClusterContext();
+                                    if (clusterContext == null) {
+                                        clusterContext = ClusterContextFactory.getVMClusterContext(instanceId, cluster,
+                                                clusterMonitor.hasScalingDependents(),
+                                                clusterMonitor.getDeploymentPolicyId());
+                                        clusterMonitor.setClusterContext(clusterContext);
+
+                                    }
+                                    log.info(String.format("Cluster monitor has scaling dependents: [%s]",
+                                            Boolean.toString(clusterMonitor.hasScalingDependents())));
+                                    // TODO -- remove this log..
+                                    clusterContext.addInstanceContext(instanceId, cluster,
+                                            clusterMonitor.hasScalingDependents(),
+                                            clusterMonitor.groupScalingEnabledSubtree());
+                                    if (clusterMonitor.getInstance(instanceId) == null) {
+                                        // adding the same instance in
+                                        // topology to monitor as a reference
+                                        ClusterInstance clusterInstance1 = cluster.getInstanceContexts(instanceId);
+                                        clusterMonitor.addInstance(clusterInstance1);
+                                    }
+
+                                    if (clusterMonitor.hasMonitoringStarted().compareAndSet(false, true)) {
+                                        clusterMonitor.startScheduler();
+                                        log.info(String.format(
+                                                "Monitoring task for Cluster Monitor with [cluster-id] %s started "
+                                                        + "successfully", clusterInstanceCreatedEvent.getClusterId()));
+                                    } else {
+                                        //monitor already started. Invoking it
+                                        // directly to speed up the process
+                                        ((ClusterMonitor) clusterMonitor).monitor();
+                                    }
+                                } catch (PolicyValidationException e) {
+                                    log.error(e.getMessage(), e);
+                                } catch (PartitionValidationException e) {
+                                    log.error(e.getMessage(), e);
+                                }
+                            }
+
+                        } else {
+                            log.error(String.format("Service %s not found, no cluster instance added to ClusterMonitor",
+                                    clusterInstanceCreatedEvent.getServiceName()));
+                        }
+
+                    } finally {
+                        TopologyManager.releaseReadLockForCluster(clusterInstanceCreatedEvent.getServiceName(),
+                                clusterInstanceCreatedEvent.getClusterId());
+                    }
+
+                } else {
+                    log.error(String.format("No Cluster Monitor found for [cluster-id] %s",
+                            clusterInstanceCreatedEvent.getClusterId()));
+                }
+            }
+        });
     }
 
     /**
      * Terminate load balancer topology receiver thread.
      */
-
     public void terminate() {
         topologyEventReceiver.terminate();
         terminated = true;


[15/28] stratos git commit: Add instance id to log messages in autoscaler ClusterStatusActiveProcessor

Posted by ra...@apache.org.
Add instance id to log messages in autoscaler ClusterStatusActiveProcessor


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

Branch: refs/heads/stratos-4.1.x
Commit: 138bd5e0548b74072a561af5ca12f82884e439c7
Parents: c39d46f
Author: Akila Perera <ra...@gmail.com>
Authored: Mon Nov 30 00:16:32 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:47 2015 +0530

----------------------------------------------------------------------
 .../cluster/ClusterStatusActiveProcessor.java   | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/138bd5e0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
index a8521d5..8dd9a8e 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/processor/cluster/ClusterStatusActiveProcessor.java
@@ -53,8 +53,9 @@ public class ClusterStatusActiveProcessor extends ClusterStatusProcessor {
                 // ask the next processor to take care of the message.
                 return nextProcessor.process(type, clusterId, instanceId);
             } else {
-                log.warn(String.format("No possible state change found for [type] %s [cluster] %s " +
-                        "[instance] %s", type, clusterId, instanceId));
+                log.warn(
+                        String.format("No possible state change found for [type] %s, [cluster] %s, [instance] %s", type,
+                                clusterId, instanceId));
             }
         }
         return false;
@@ -64,12 +65,10 @@ public class ClusterStatusActiveProcessor extends ClusterStatusProcessor {
         ClusterMonitor monitor = AutoscalerContext.getInstance().
                 getClusterMonitor(clusterId);
         boolean clusterActive = false;
-        for (NetworkPartitionContext clusterLevelNetworkPartitionContext :
-                monitor.getNetworkPartitionCtxts()) {
+        for (NetworkPartitionContext clusterLevelNetworkPartitionContext : monitor.getNetworkPartitionCtxts()) {
             //minimum check per partition
-            ClusterInstanceContext instanceContext =
-                    (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
-                            getInstanceContext(instanceId);
+            ClusterInstanceContext instanceContext = (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
+                    getInstanceContext(instanceId);
             if (instanceContext != null) {
                 if (instanceContext.getActiveMembers() >= instanceContext.getMinInstanceCount()) {
                     clusterActive = true;
@@ -79,12 +78,13 @@ public class ClusterStatusActiveProcessor extends ClusterStatusProcessor {
         }
         if (clusterActive) {
             if (log.isInfoEnabled()) {
-                log.info("Publishing cluster activated event for [application]: "
-                        + monitor.getAppId() + " [cluster]: " + clusterId);
+                log.info(String.format("Publishing cluster activated event for [application-id] %s, [cluster-id] %s, "
+                        + "[cluster-instance-id] %s", monitor.getAppId(), clusterId, instanceId));
             }
             //TODO service call
-            ClusterStatusEventPublisher.sendClusterActivatedEvent(monitor.getAppId(),
-                    monitor.getServiceId(), monitor.getClusterId(), instanceId);
+            ClusterStatusEventPublisher
+                    .sendClusterActivatedEvent(monitor.getAppId(), monitor.getServiceId(), monitor.getClusterId(),
+                            instanceId);
         }
         return clusterActive;
     }


[02/28] stratos git commit: Closing STRATOS-1633: Refactoring Mock IaaS

Posted by ra...@apache.org.
Closing STRATOS-1633: Refactoring Mock IaaS


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

Branch: refs/heads/stratos-4.1.x
Commit: 5344c394c45886857ef4ae08063f573d3471ad6a
Parents: 4e868f2
Author: Akila Perera <ra...@gmail.com>
Authored: Sun Nov 29 23:52:17 2015 +0530
Committer: Akila Perera <ra...@gmail.com>
Committed: Mon Nov 30 00:33:45 2015 +0530

----------------------------------------------------------------------
 .../iaas/internal/MockIaasServiceComponent.java |   6 -
 .../iaas/services/impl/MockIaasServiceImpl.java |  65 +++----
 .../iaas/services/impl/MockIaasServiceUtil.java |  23 ---
 .../mock/iaas/services/impl/MockInstance.java   | 187 +++++++++++++------
 .../publisher/MockHealthStatisticsNotifier.java |  56 +++---
 .../mock/iaas/test/MockIaasServiceTest.java     | 149 +++++++++------
 .../src/test/resources/jndi.properties          |  22 +++
 .../src/test/resources/thrift-client-config.xml |  50 +++++
 8 files changed, 336 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/internal/MockIaasServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/internal/MockIaasServiceComponent.java b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/internal/MockIaasServiceComponent.java
index bc384c6..07cf540 100644
--- a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/internal/MockIaasServiceComponent.java
+++ b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/internal/MockIaasServiceComponent.java
@@ -65,12 +65,6 @@ public class MockIaasServiceComponent {
                     // Wait for stratos manager to be activated
                     componentStartUpSynchronizer.waitForComponentActivation(Component.MockIaaS,
                             Component.StratosManager);
-
-                    PersistenceManager persistenceManager =
-                            PersistenceManagerFactory.getPersistenceManager(PersistenceManagerType.Registry);
-                    MockIaasServiceUtil mockIaasServiceUtil = new MockIaasServiceUtil(persistenceManager);
-                    mockIaasServiceUtil.startInstancesPersisted();
-
                     MockIaasService mockIaasService = new MockIaasServiceImpl();
                     context.getBundleContext().registerService(MockIaasService.class.getName(), mockIaasService, null);
                     log.info("Mock IaaS service registered");

http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceImpl.java b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceImpl.java
index 2090199..106ece7 100644
--- a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceImpl.java
+++ b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceImpl.java
@@ -21,7 +21,6 @@ package org.apache.stratos.mock.iaas.services.impl;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.threading.StratosThreadPool;
 import org.apache.stratos.mock.iaas.domain.MockInstanceContext;
 import org.apache.stratos.mock.iaas.domain.MockInstanceMetadata;
 import org.apache.stratos.mock.iaas.exceptions.MockIaasException;
@@ -32,12 +31,8 @@ import org.apache.stratos.mock.iaas.services.MockIaasService;
 import org.apache.stratos.mock.iaas.statistics.generator.MockHealthStatisticsGenerator;
 import org.wso2.carbon.registry.core.exceptions.RegistryException;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
 
 /**
  * Mock IaaS service implementation. This is a singleton class that simulates a standard Infrastructure as a Service
@@ -52,14 +47,9 @@ import java.util.concurrent.ExecutorService;
 public class MockIaasServiceImpl implements MockIaasService {
 
     private static final Log log = LogFactory.getLog(MockIaasServiceImpl.class);
-
-    private static final ExecutorService mockMemberExecutorService = StratosThreadPool
-            .getExecutorService(MockConstants.MOCK_MEMBER_THREAD_POOL, MockConstants.MOCK_MEMBER_THREAD_POOL_SIZE);
-    private static volatile MockIaasServiceImpl instance;
-
     private PersistenceManager persistenceManager;
     private MockIaasServiceUtil mockIaasServiceUtil;
-    private Map<String, MockInstance> instanceIdToMockInstanceMap; // Map<InstanceId,MockInstance>
+    private Map<String, MockInstance> instanceIdToMockInstanceMap;
 
     /**
      * Default public constructor
@@ -71,8 +61,8 @@ public class MockIaasServiceImpl implements MockIaasService {
             PersistenceManagerType persistenceManagerType = PersistenceManagerType.valueOf(persistenceManagerTypeStr);
             persistenceManager = PersistenceManagerFactory.getPersistenceManager(persistenceManagerType);
             mockIaasServiceUtil = new MockIaasServiceUtil(persistenceManager);
-
             instanceIdToMockInstanceMap = mockIaasServiceUtil.readFromRegistry();
+            startPersistedMockInstances();
         } catch (RegistryException e) {
             String message = "Could not read service name -> mock member map from registry";
             log.error(message, e);
@@ -84,6 +74,23 @@ public class MockIaasServiceImpl implements MockIaasService {
         }
     }
 
+    private void startPersistedMockInstances() throws RegistryException {
+        if (instanceIdToMockInstanceMap != null) {
+            log.info("Starting mock instances persisted...");
+            Set<String> serviceNameSet = new HashSet<String>();
+            for (MockInstance mockInstance : instanceIdToMockInstanceMap.values()) {
+                mockInstance.initialize();
+
+                // Schedule statistics updater tasks for service
+                String serviceName = mockInstance.getMockInstanceContext().getServiceName();
+                if (!serviceNameSet.contains(serviceName)) {
+                    MockHealthStatisticsGenerator.getInstance().scheduleStatisticsUpdaterTasks(serviceName);
+                    serviceNameSet.add(serviceName);
+                }
+            }
+        }
+    }
+
     /**
      * Start mock instance.
      *
@@ -104,40 +111,24 @@ public class MockIaasServiceImpl implements MockIaasService {
 
                 MockInstance mockInstance = new MockInstance(mockInstanceContext);
                 instanceIdToMockInstanceMap.put(instanceId, mockInstance);
-                mockMemberExecutorService.submit(mockInstance);
+                mockInstance.initialize();
 
                 // Persist changes
                 mockIaasServiceUtil
                         .persistInRegistry((ConcurrentHashMap<String, MockInstance>) instanceIdToMockInstanceMap);
-
                 String serviceName = mockInstanceContext.getServiceName();
                 MockHealthStatisticsGenerator.getInstance().scheduleStatisticsUpdaterTasks(serviceName);
-
-                // Simulate instance creation time
-                sleep(2000);
-
                 return new MockInstanceMetadata(mockInstanceContext);
             }
         } catch (Exception e) {
-            String msg = "Could not start mock instance: " + mockInstanceContext.getMemberId();
+            String msg = String
+                    .format("Could not start mock instance: [member-id] %s", mockInstanceContext.getMemberId());
             log.error(msg, e);
             throw new MockIaasException(msg, e);
         }
     }
 
     /**
-     * Sleep the current thread for a given period of time
-     *
-     * @param time time in milliseconds
-     */
-    private void sleep(int time) {
-        try {
-            Thread.sleep(time);
-        } catch (InterruptedException ignore) {
-        }
-    }
-
-    /**
      * Get mock instances.
      *
      * @return a list of mock instance metadata objects
@@ -199,12 +190,10 @@ public class MockIaasServiceImpl implements MockIaasService {
     public void terminateInstance(String instanceId) {
         try {
             synchronized (MockIaasServiceImpl.class) {
-                log.info(String.format("Terminating instance: [instance-id] %s", instanceId));
-
+                log.info(String.format("Terminating mock instance: [instance-id] %s", instanceId));
                 MockInstance mockInstance = instanceIdToMockInstanceMap.get(instanceId);
                 if (mockInstance != null) {
                     String serviceName = mockInstance.getMockInstanceContext().getServiceName();
-
                     mockInstance.terminate();
                     instanceIdToMockInstanceMap.remove(instanceId);
                     mockIaasServiceUtil
@@ -214,13 +203,13 @@ public class MockIaasServiceImpl implements MockIaasService {
                         MockHealthStatisticsGenerator.getInstance().stopStatisticsUpdaterTasks(serviceName);
                     }
 
-                    log.info(String.format("Instance terminated successfully: [instance-id] %s", instanceId));
+                    log.info(String.format("Mock instance terminated successfully: [instance-id] %s", instanceId));
                 } else {
-                    log.warn(String.format("Instance not found: [instance-id] %s", instanceId));
+                    log.warn(String.format("Mock instance not found: [instance-id] %s", instanceId));
                 }
             }
         } catch (Exception e) {
-            String msg = "Could not terminate mock instance: " + instanceId;
+            String msg = String.format("Could not terminate mock instance: [instance-id] %s", instanceId);
             log.error(msg, e);
         }
     }

http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceUtil.java b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceUtil.java
index cbdc090..c950528 100644
--- a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceUtil.java
+++ b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockIaasServiceUtil.java
@@ -57,27 +57,4 @@ public class MockIaasServiceUtil {
     public ConcurrentHashMap<String, MockInstance> readFromRegistry() throws RegistryException {
         return (ConcurrentHashMap<String, MockInstance>) persistenceManager.read(MOCK_IAAS_MEMBERS);
     }
-
-    public void startInstancesPersisted() throws RegistryException {
-        Map<String, MockInstance> instanceIdToMockMemberMap = readFromRegistry();
-        ExecutorService mockMemberExecutorService =
-                StratosThreadPool.getExecutorService(MockConstants.MOCK_MEMBER_THREAD_POOL,
-                        MockConstants.MOCK_MEMBER_THREAD_POOL_SIZE);
-
-        if (instanceIdToMockMemberMap != null) {
-            log.info("Starting mock instances persisted...");
-
-            Set<String> serviceNameSet = new HashSet<String>();
-            for (MockInstance mockInstance : instanceIdToMockMemberMap.values()) {
-                mockMemberExecutorService.submit(mockInstance);
-
-                // Schedule statistics updater tasks for service
-                String serviceName = mockInstance.getMockInstanceContext().getServiceName();
-                if (!serviceNameSet.contains(serviceName)) {
-                    MockHealthStatisticsGenerator.getInstance().scheduleStatisticsUpdaterTasks(serviceName);
-                    serviceNameSet.add(serviceName);
-                }
-            }
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java
index a8f3bcc..7b31861 100644
--- a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java
+++ b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/services/impl/MockInstance.java
@@ -21,20 +21,26 @@ package org.apache.stratos.mock.iaas.services.impl;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.common.domain.NameValuePair;
 import org.apache.stratos.common.threading.StratosThreadPool;
+import org.apache.stratos.messaging.domain.topology.MemberStatus;
 import org.apache.stratos.messaging.event.Event;
 import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupClusterEvent;
 import org.apache.stratos.messaging.event.instance.notifier.InstanceCleanupMemberEvent;
+import org.apache.stratos.messaging.event.topology.MemberInitializedEvent;
+import org.apache.stratos.messaging.event.topology.MemberMaintenanceModeEvent;
+import org.apache.stratos.messaging.event.topology.MemberStartedEvent;
 import org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupClusterEventListener;
 import org.apache.stratos.messaging.listener.instance.notifier.InstanceCleanupMemberEventListener;
+import org.apache.stratos.messaging.listener.topology.MemberInitializedEventListener;
+import org.apache.stratos.messaging.listener.topology.MemberMaintenanceListener;
+import org.apache.stratos.messaging.listener.topology.MemberStartedEventListener;
 import org.apache.stratos.messaging.message.receiver.instance.notifier.InstanceNotifierEventReceiver;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyEventReceiver;
 import org.apache.stratos.mock.iaas.domain.MockInstanceContext;
 import org.apache.stratos.mock.iaas.event.publisher.MockMemberEventPublisher;
 import org.apache.stratos.mock.iaas.statistics.publisher.MockHealthStatisticsNotifier;
 
 import java.io.Serializable;
-import java.util.Properties;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
@@ -44,41 +50,117 @@ import java.util.concurrent.atomic.AtomicBoolean;
 /**
  * Mock member instance definition.
  */
-public class MockInstance implements Runnable, Serializable {
+public class MockInstance implements Serializable {
     private static final Log log = LogFactory.getLog(MockInstance.class);
     private static final int HEALTH_STAT_INTERVAL = 15; // 15 seconds
-    private final MockInstanceContext mockInstanceContext;
+
     private transient ScheduledFuture<?> healthStatNotifierScheduledFuture;
     private transient InstanceNotifierEventReceiver instanceNotifierEventReceiver;
+    private transient TopologyEventReceiver topologyEventReceiver;
+    private transient MockHealthStatisticsNotifier mockHealthStatisticsNotifier;
+
+    // this is the mock iaas instance runtime status, do not persist this state
+    private transient MemberStatus memberStatus = MemberStatus.Created;
+
+    private final MockInstanceContext mockInstanceContext;
+    private final AtomicBoolean hasGracefullyShutdown = new AtomicBoolean(false);
+
     private static final ExecutorService eventListenerExecutorService = StratosThreadPool
-            .getExecutorService("mock.iaas.event.listener.thread.pool", 20);
+            .getExecutorService("mock.iaas.event.listener.thread.pool", 100);
     private static final ScheduledExecutorService healthStatNotifierExecutorService = StratosThreadPool
-            .getScheduledExecutorService("mock.iaas.health.statistics.notifier.thread.pool", 20);
-    AtomicBoolean hasGracefullyShutdown = new AtomicBoolean(false);
+            .getScheduledExecutorService("mock.iaas.health.statistics.notifier.thread.pool", 100);
 
     public MockInstance(MockInstanceContext mockInstanceContext) {
         this.mockInstanceContext = mockInstanceContext;
     }
 
-    @Override
-    public void run() {
-        if (log.isInfoEnabled()) {
-            log.info(String.format("Mock member started: [member-id] %s", mockInstanceContext.getMemberId()));
+    public synchronized void initialize() {
+        if (MemberStatus.Created.equals(memberStatus) || memberStatus == null) {
+            startTopologyEventReceiver();
+            startInstanceNotifierEventReceiver();
+            startHealthStatisticsPublisher();
+            memberStatus = MemberStatus.Initialized;
+            if (log.isInfoEnabled()) {
+                log.info(String.format("Mock instance initialized: [member-id] %s", mockInstanceContext.getMemberId()));
+            }
+        } else {
+            if (log.isInfoEnabled()) {
+                log.info(String.format(
+                        "Mock instance cannot be initialized since it is not in created state: [member-id] %s [status] "
+                                + "%s", mockInstanceContext.getMemberId(), memberStatus));
+            }
         }
-        sleep(5000);
-        MockMemberEventPublisher.publishInstanceStartedEvent(mockInstanceContext);
-        sleep(5000);
-        MockMemberEventPublisher.publishInstanceActivatedEvent(mockInstanceContext);
-        startInstanceNotifierReceiver();
-        startHealthStatisticsPublisher();
     }
 
-    private void startInstanceNotifierReceiver() {
+    private void startHealthStatisticsPublisher() {
+        mockHealthStatisticsNotifier = new MockHealthStatisticsNotifier(mockInstanceContext);
+        if (log.isDebugEnabled()) {
+            log.debug(String.format("Starting health statistics notifier: [member-id] %s",
+                    mockInstanceContext.getMemberId()));
+        }
+        healthStatNotifierScheduledFuture = healthStatNotifierExecutorService
+                .scheduleAtFixedRate(mockHealthStatisticsNotifier, 0, HEALTH_STAT_INTERVAL, TimeUnit.SECONDS);
+
         if (log.isDebugEnabled()) {
-            log.debug("Starting instance notifier event message receiver for mock member [member-id] "
-                            + mockInstanceContext.getMemberId());
+            log.debug(String.format("Health statistics notifier started: [member-id] %s",
+                    mockInstanceContext.getMemberId()));
         }
+    }
 
+    private void startTopologyEventReceiver() {
+        topologyEventReceiver = new TopologyEventReceiver();
+        topologyEventReceiver.addEventListener(new MemberInitializedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                MemberInitializedEvent memberInitializedEvent = (MemberInitializedEvent) event;
+                if (memberInitializedEvent.getMemberId().equals(mockInstanceContext.getMemberId())) {
+                    MockMemberEventPublisher.publishInstanceStartedEvent(mockInstanceContext);
+
+                    if (log.isInfoEnabled()) {
+                        log.info(String.format("Mock member started event published for [member-id] %s",
+                                mockInstanceContext.getMemberId()));
+                    }
+                }
+            }
+        });
+        topologyEventReceiver.addEventListener(new MemberStartedEventListener() {
+            @Override
+            protected void onEvent(Event event) {
+                MemberStartedEvent memberStartedEvent = (MemberStartedEvent) event;
+                if (memberStartedEvent.getMemberId().equals(mockInstanceContext.getMemberId())) {
+                    MockMemberEventPublisher.publishInstanceActivatedEvent(mockInstanceContext);
+
+                    if (log.isInfoEnabled()) {
+                        log.info(String.format("Mock member activated event published for [member-id] %s",
+                                mockInstanceContext.getMemberId()));
+                    }
+                }
+            }
+        });
+        topologyEventReceiver.addEventListener(new MemberMaintenanceListener() {
+            @Override
+            protected void onEvent(Event event) {
+                MemberMaintenanceModeEvent memberMaintenanceModeEvent = (MemberMaintenanceModeEvent) event;
+                if (memberMaintenanceModeEvent.getMemberId().equals(mockInstanceContext.getMemberId())) {
+                    MockMemberEventPublisher.publishInstanceReadyToShutdownEvent(mockInstanceContext);
+                    hasGracefullyShutdown.set(true);
+                    if (log.isInfoEnabled()) {
+                        log.info(String.format("Mock member ready to shutdown event published for [member-id] %s",
+                                mockInstanceContext.getMemberId()));
+                    }
+                }
+            }
+        });
+        topologyEventReceiver.setExecutorService(eventListenerExecutorService);
+        topologyEventReceiver.execute();
+        if (log.isDebugEnabled()) {
+            log.debug(String.format(
+                    "Mock instance topology event message receiver started for mock member [member-id] %s",
+                    mockInstanceContext.getMemberId()));
+        }
+    }
+
+    private void startInstanceNotifierEventReceiver() {
         instanceNotifierEventReceiver = new InstanceNotifierEventReceiver();
         instanceNotifierEventReceiver.addEventListener(new InstanceCleanupClusterEventListener() {
             @Override
@@ -101,25 +183,24 @@ public class MockInstance implements Runnable, Serializable {
                 }
             }
         });
-
+        // TODO: Fix InstanceNotifierEventReceiver to use executor service
+        // do not remove this since execute() is a blocking call
         eventListenerExecutorService.submit(new Runnable() {
             @Override
             public void run() {
                 instanceNotifierEventReceiver.execute();
             }
         });
-
         if (log.isDebugEnabled()) {
-            log.debug("Instance notifier event message receiver started");
+            log.debug(String.format(
+                    "Mock instance instance notifier event message receiver started for mock member [member-id] %s",
+                    mockInstanceContext.getMemberId()));
         }
     }
 
     private void handleMemberTermination() {
         if (!hasGracefullyShutdown.get()) {
             MockMemberEventPublisher.publishMaintenanceModeEvent(mockInstanceContext);
-            sleep(5000);
-            MockMemberEventPublisher.publishInstanceReadyToShutdownEvent(mockInstanceContext);
-            hasGracefullyShutdown.set(true);
         } else {
             if (log.isDebugEnabled()) {
                 log.debug(String.format("Mock instance is already gracefully shutdown [member-id] %s",
@@ -128,50 +209,36 @@ public class MockInstance implements Runnable, Serializable {
         }
     }
 
-    private void startHealthStatisticsPublisher() {
-        if (log.isDebugEnabled()) {
-            log.debug(String.format("Starting health statistics notifier: [member-id] %s",
-                    mockInstanceContext.getMemberId()));
-        }
-
-        healthStatNotifierScheduledFuture = healthStatNotifierExecutorService
-                .scheduleAtFixedRate(new MockHealthStatisticsNotifier(mockInstanceContext), 0, HEALTH_STAT_INTERVAL,
-                        TimeUnit.SECONDS);
-
-        if (log.isDebugEnabled()) {
-            log.debug(String.format("Health statistics notifier started: [member-id] %s",
-                    mockInstanceContext.getMemberId()));
-        }
-    }
-
     private void stopHealthStatisticsPublisher() {
-        if (healthStatNotifierScheduledFuture != null) {
-            healthStatNotifierScheduledFuture.cancel(true);
-        }
+        healthStatNotifierScheduledFuture.cancel(true);
     }
 
     private void stopInstanceNotifierReceiver() {
-        if (instanceNotifierEventReceiver != null) {
-            instanceNotifierEventReceiver.terminate();
-        }
-    }
-
-    private void sleep(long time) {
-        try {
-            Thread.sleep(time);
-        } catch (InterruptedException ignore) {
-        }
+        instanceNotifierEventReceiver.terminate();
     }
 
     public MockInstanceContext getMockInstanceContext() {
         return mockInstanceContext;
     }
 
-    public void terminate() {
-        stopInstanceNotifierReceiver();
-        stopHealthStatisticsPublisher();
-        if (log.isInfoEnabled()) {
-            log.info(String.format("Mock member terminated: [member-id] %s", mockInstanceContext.getMemberId()));
+    public synchronized void terminate() {
+        if (MemberStatus.Initialized.equals(memberStatus)) {
+            stopInstanceNotifierReceiver();
+            stopHealthStatisticsPublisher();
+            memberStatus = MemberStatus.Terminated;
+            if (log.isInfoEnabled()) {
+                log.info(String.format("Mock instance stopped: [member-id] %s", mockInstanceContext.getMemberId()));
+            }
+        } else {
+            if (log.isInfoEnabled()) {
+                log.info(String.format(
+                        "Mock instance cannot be terminated since it is not in initialized state: [member-id] %s ",
+                        mockInstanceContext.getMemberId()));
+            }
         }
     }
+
+    public MockHealthStatisticsNotifier getMockHealthStatisticsNotifier() {
+        return mockHealthStatisticsNotifier;
+    }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/publisher/MockHealthStatisticsNotifier.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/publisher/MockHealthStatisticsNotifier.java b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/publisher/MockHealthStatisticsNotifier.java
index c2d1c6c..4f3de51 100644
--- a/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/publisher/MockHealthStatisticsNotifier.java
+++ b/components/org.apache.stratos.mock.iaas/src/main/java/org/apache/stratos/mock/iaas/statistics/publisher/MockHealthStatisticsNotifier.java
@@ -42,12 +42,12 @@ public class MockHealthStatisticsNotifier implements Runnable {
 
     public MockHealthStatisticsNotifier(MockInstanceContext mockMemberContext) {
         this.mockMemberContext = mockMemberContext;
-        this.healthStatisticsPublisher = HealthStatisticsPublisherFactory.createHealthStatisticsPublisher(
-                StatisticsPublisherType.WSO2CEP);
+        this.healthStatisticsPublisher = HealthStatisticsPublisherFactory
+                .createHealthStatisticsPublisher(StatisticsPublisherType.WSO2CEP);
         this.healthStatisticsPublisher.setEnabled(true);
 
-        this.inFlightRequestPublisher = InFlightRequestPublisherFactory.createInFlightRequestPublisher(
-                StatisticsPublisherType.WSO2CEP);
+        this.inFlightRequestPublisher = InFlightRequestPublisherFactory
+                .createInFlightRequestPublisher(StatisticsPublisherType.WSO2CEP);
         this.inFlightRequestPublisher.setEnabled(true);
     }
 
@@ -61,22 +61,17 @@ public class MockHealthStatisticsNotifier implements Runnable {
         }
 
         try {
-            double memoryConsumption = MockHealthStatistics.getInstance().getStatistics(
-                    mockMemberContext.getServiceName(), MockScalingFactor.MemoryConsumption);
+            double memoryConsumption = MockHealthStatistics.getInstance()
+                    .getStatistics(mockMemberContext.getServiceName(), MockScalingFactor.MemoryConsumption);
 
             if (log.isDebugEnabled()) {
                 log.debug(String.format("Publishing memory consumption: [member-id] %s [value] %f",
                         mockMemberContext.getMemberId(), memoryConsumption));
             }
-            healthStatisticsPublisher.publish(
-                    mockMemberContext.getClusterId(),
-                    mockMemberContext.getClusterInstanceId(),
-                    mockMemberContext.getNetworkPartitionId(),
-                    mockMemberContext.getMemberId(),
-                    mockMemberContext.getPartitionId(),
-                    MEMORY_CONSUMPTION,
-                    memoryConsumption
-            );
+            healthStatisticsPublisher
+                    .publish(mockMemberContext.getClusterId(), mockMemberContext.getClusterInstanceId(),
+                            mockMemberContext.getNetworkPartitionId(), mockMemberContext.getMemberId(),
+                            mockMemberContext.getPartitionId(), MEMORY_CONSUMPTION, memoryConsumption);
         } catch (NoStatisticsFoundException ignore) {
         } catch (Exception e) {
             if (log.isErrorEnabled()) {
@@ -84,23 +79,17 @@ public class MockHealthStatisticsNotifier implements Runnable {
             }
         }
 
-
         try {
-            double loadAvereage = MockHealthStatistics.getInstance().getStatistics(
-                    mockMemberContext.getServiceName(), MockScalingFactor.LoadAverage);
+            double loadAvereage = MockHealthStatistics.getInstance()
+                    .getStatistics(mockMemberContext.getServiceName(), MockScalingFactor.LoadAverage);
             if (log.isDebugEnabled()) {
                 log.debug(String.format("Publishing load average: [member-id] %s [value] %f",
                         mockMemberContext.getMemberId(), loadAvereage));
             }
-            healthStatisticsPublisher.publish(
-                    mockMemberContext.getClusterId(),
-                    mockMemberContext.getClusterInstanceId(),
-                    mockMemberContext.getNetworkPartitionId(),
-                    mockMemberContext.getMemberId(),
-                    mockMemberContext.getPartitionId(),
-                    LOAD_AVERAGE,
-                    loadAvereage
-            );
+            healthStatisticsPublisher
+                    .publish(mockMemberContext.getClusterId(), mockMemberContext.getClusterInstanceId(),
+                            mockMemberContext.getNetworkPartitionId(), mockMemberContext.getMemberId(),
+                            mockMemberContext.getPartitionId(), LOAD_AVERAGE, loadAvereage);
         } catch (NoStatisticsFoundException ignore) {
         } catch (Exception e) {
             if (log.isErrorEnabled()) {
@@ -109,17 +98,14 @@ public class MockHealthStatisticsNotifier implements Runnable {
         }
 
         try {
-            int requestsInFlight = MockHealthStatistics.getInstance().getStatistics(
-                    mockMemberContext.getServiceName(), MockScalingFactor.RequestsInFlight);
+            int requestsInFlight = MockHealthStatistics.getInstance()
+                    .getStatistics(mockMemberContext.getServiceName(), MockScalingFactor.RequestsInFlight);
             if (log.isDebugEnabled()) {
-                log.debug(String.format("Publishing requests in flight: [member-id] %s [value] %f",
+                log.debug(String.format("Publishing requests in flight: [member-id] %s [value] %d",
                         mockMemberContext.getMemberId(), requestsInFlight));
             }
-            inFlightRequestPublisher.publish(
-                    mockMemberContext.getClusterId(),
-                    mockMemberContext.getClusterInstanceId(),
-                    mockMemberContext.getNetworkPartitionId(),
-                    requestsInFlight);
+            inFlightRequestPublisher.publish(mockMemberContext.getClusterId(), mockMemberContext.getClusterInstanceId(),
+                    mockMemberContext.getNetworkPartitionId(), requestsInFlight);
         } catch (NoStatisticsFoundException ignore) {
         } catch (Exception e) {
             if (log.isErrorEnabled()) {

http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/test/java/org/apache/stratos/mock/iaas/test/MockIaasServiceTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/test/java/org/apache/stratos/mock/iaas/test/MockIaasServiceTest.java b/components/org.apache.stratos.mock.iaas/src/test/java/org/apache/stratos/mock/iaas/test/MockIaasServiceTest.java
index 8b7aa1f..c9c0478 100644
--- a/components/org.apache.stratos.mock.iaas/src/test/java/org/apache/stratos/mock/iaas/test/MockIaasServiceTest.java
+++ b/components/org.apache.stratos.mock.iaas/src/test/java/org/apache/stratos/mock/iaas/test/MockIaasServiceTest.java
@@ -19,16 +19,20 @@
 
 package org.apache.stratos.mock.iaas.test;
 
+import org.apache.activemq.broker.BrokerService;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.statistics.publisher.ThriftClientConfig;
 import org.apache.stratos.mock.iaas.config.MockIaasConfig;
 import org.apache.stratos.mock.iaas.domain.MockInstanceContext;
 import org.apache.stratos.mock.iaas.domain.MockInstanceMetadata;
 import org.apache.stratos.mock.iaas.persistence.PersistenceManagerType;
 import org.apache.stratos.mock.iaas.services.impl.MockConstants;
 import org.apache.stratos.mock.iaas.services.impl.MockIaasServiceImpl;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.io.File;
 import java.net.URL;
 import java.util.List;
 
@@ -41,58 +45,93 @@ public class MockIaasServiceTest {
 
     private static Log log = LogFactory.getLog(MockIaasServiceTest.class);
     private static final String CONFIG_FILE_PATH = "/mock-iaas.xml";
+    private static BrokerService broker;
+
+    @BeforeClass
+    public static void init() {
+        URL configFileUrl = MockIaasServiceTest.class.getResource(CONFIG_FILE_PATH);
+        System.setProperty(MockIaasConfig.MOCK_IAAS_CONFIG_FILE_PATH, configFileUrl.getPath());
+        System.setProperty(MockConstants.PERSISTENCE_MANAGER_TYPE, PersistenceManagerType.Mock.toString());
+        System.setProperty(ThriftClientConfig.THRIFT_CLIENT_CONFIG_FILE_PATH,
+                MockIaasServiceTest.class.getResource("/thrift-client-config.xml").getPath());
+        System.setProperty("carbon.home", MockIaasServiceTest.class.getResource("/").getPath());
+        System.setProperty("jndi.properties.dir", MockIaasServiceTest.class.getResource("/").getPath());
+        initializeActiveMQ();
+        startActiveMQ();
+    }
 
-    @Test
-    public void testStartInstance() {
-
+    private static void initializeActiveMQ() {
         try {
-            URL configFileUrl = getClass().getResource(CONFIG_FILE_PATH);
-            System.setProperty(MockIaasConfig.MOCK_IAAS_CONFIG_FILE_PATH, configFileUrl.getPath());
-            System.setProperty(MockConstants.PERSISTENCE_MANAGER_TYPE, PersistenceManagerType.Mock.toString());
-
-            MockIaasServiceImpl mockIaasService = new MockIaasServiceImpl();
-            MockInstanceContext mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member1",
-                    "cluster-instance1", "network-p1", "p1");
-            MockInstanceMetadata metadata = mockIaasService.startInstance(mockInstanceContext);
-            assertNotNull("Could not start mock instance", metadata);
-            assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata.getInstanceId()));
+            log.info("Initializing ActiveMQ...");
+            broker = new BrokerService();
+            broker.setDataDirectory(MockIaasServiceTest.class.getResource("/").getPath() +
+                    File.separator + ".." + File.separator + "activemq-data");
+            broker.setBrokerName("testBroker");
+            broker.addConnector("tcp://localhost:61617");
         } catch (Exception e) {
-            log.error(e);
-            assertTrue(e.getMessage(), false);
+            throw new RuntimeException("Could not initialize ActiveMQ", e);
         }
     }
 
-    @Test
-    public void testGetInstances() {
+    private static void startActiveMQ() {
+        try {
+            long time1 = System.currentTimeMillis();
+            broker.start();
+            long time2 = System.currentTimeMillis();
+            log.info(String.format("ActiveMQ started in %d sec", (time2 - time1) / 1000));
+        } catch (Exception e) {
+            throw new RuntimeException("Could not start ActiveMQ", e);
+        }
+    }
 
+    private void stopActiveMQ() {
         try {
-            URL configFileUrl = getClass().getResource(CONFIG_FILE_PATH);
-            System.setProperty(MockIaasConfig.MOCK_IAAS_CONFIG_FILE_PATH, configFileUrl.getPath());
-            System.setProperty(MockConstants.PERSISTENCE_MANAGER_TYPE, PersistenceManagerType.Mock.toString());
-
-            MockIaasServiceImpl mockIaasService = new MockIaasServiceImpl();
-            MockInstanceContext mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member1",
-                    "cluster-instance1", "network-p1", "p1");
-            MockInstanceMetadata metadata1 = mockIaasService.startInstance(mockInstanceContext);
-            assertNotNull("Could not start mock instance", metadata1);
-            assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata1.getInstanceId()));
-
-            mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member2",
-                    "cluster-instance1", "network-p1", "p1");
-            MockInstanceMetadata metadata2 = mockIaasService.startInstance(mockInstanceContext);
-            assertNotNull("Could not start mock instance", metadata2);
-            assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata2.getInstanceId()));
-
-            List<MockInstanceMetadata> instances = mockIaasService.getInstances();
-            assertNotNull(instances);
-            assertTrue("Mock instance 1 not found in get instances result", instanceExist(instances, metadata1.getInstanceId()));
-            assertTrue("Mock instance 2 not found in get instances result", instanceExist(instances, metadata2.getInstanceId()));
+            broker.stop();
         } catch (Exception e) {
-            log.error(e);
-            assertTrue(e.getMessage(), false);
+            throw new RuntimeException("Could not stop ActiveMQ", e);
+        }
+    }
+
+    private void sleep(long time) {
+        try {
+            Thread.sleep(time);
+        } catch (InterruptedException ignore) {
         }
     }
 
+    @Test
+    public void testStartInstance() throws Exception {
+        MockIaasServiceImpl mockIaasService = new MockIaasServiceImpl();
+        MockInstanceContext mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member1",
+                "cluster-instance1", "network-p1", "p1");
+        MockInstanceMetadata metadata = mockIaasService.startInstance(mockInstanceContext);
+        assertNotNull("Could not start mock instance", metadata);
+        assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata.getInstanceId()));
+    }
+
+    @Test
+    public void testGetInstances() throws Exception {
+        MockIaasServiceImpl mockIaasService = new MockIaasServiceImpl();
+        MockInstanceContext mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member1",
+                "cluster-instance1", "network-p1", "p1");
+        MockInstanceMetadata metadata1 = mockIaasService.startInstance(mockInstanceContext);
+        assertNotNull("Could not start mock instance", metadata1);
+        assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata1.getInstanceId()));
+
+        mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member2", "cluster-instance1",
+                "network-p1", "p1");
+        MockInstanceMetadata metadata2 = mockIaasService.startInstance(mockInstanceContext);
+        assertNotNull("Could not start mock instance", metadata2);
+        assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata2.getInstanceId()));
+
+        List<MockInstanceMetadata> instances = mockIaasService.getInstances();
+        assertNotNull(instances);
+        assertTrue("Mock instance 1 not found in get instances result",
+                instanceExist(instances, metadata1.getInstanceId()));
+        assertTrue("Mock instance 2 not found in get instances result",
+                instanceExist(instances, metadata2.getInstanceId()));
+    }
+
     private boolean instanceExist(List<MockInstanceMetadata> instances, String instanceId) {
         for (MockInstanceMetadata instance : instances) {
             if (instance.getInstanceId().equals(instanceId)) {
@@ -103,25 +142,15 @@ public class MockIaasServiceTest {
     }
 
     @Test
-    public void testTerminateInstance() {
-
-        try {
-            URL configFileUrl = getClass().getResource(CONFIG_FILE_PATH);
-            System.setProperty(MockIaasConfig.MOCK_IAAS_CONFIG_FILE_PATH, configFileUrl.getPath());
-            System.setProperty(MockConstants.PERSISTENCE_MANAGER_TYPE, PersistenceManagerType.Mock.toString());
-
-            MockIaasServiceImpl mockIaasService = new MockIaasServiceImpl();
-            MockInstanceContext mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member1",
-                    "cluster-instance1", "network-p1", "p1");
-            MockInstanceMetadata metadata = mockIaasService.startInstance(mockInstanceContext);
-            assertNotNull("Could not start mock instance", metadata);
-            assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata.getInstanceId()));
-
-            mockIaasService.terminateInstance(metadata.getInstanceId());
-            assertNull("Could not terminate mock instance", mockIaasService.getInstance(metadata.getInstanceId()));
-        } catch (Exception e) {
-            log.error(e);
-            assertTrue(e.getMessage(), false);
-        }
+    public void testTerminateInstance() throws Exception {
+        MockIaasServiceImpl mockIaasService = new MockIaasServiceImpl();
+        MockInstanceContext mockInstanceContext = new MockInstanceContext("app1", "service1", "cluster1", "member1",
+                "cluster-instance1", "network-p1", "p1");
+        MockInstanceMetadata metadata = mockIaasService.startInstance(mockInstanceContext);
+        assertNotNull("Could not start mock instance", metadata);
+        assertNotNull("Mock instance not found", mockIaasService.getInstance(metadata.getInstanceId()));
+
+        mockIaasService.terminateInstance(metadata.getInstanceId());
+        assertNull("Could not terminate mock instance", mockIaasService.getInstance(metadata.getInstanceId()));
     }
 }

http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/test/resources/jndi.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/test/resources/jndi.properties b/components/org.apache.stratos.mock.iaas/src/test/resources/jndi.properties
new file mode 100644
index 0000000..beefe3c
--- /dev/null
+++ b/components/org.apache.stratos.mock.iaas/src/test/resources/jndi.properties
@@ -0,0 +1,22 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+connectionfactoryName=TopicConnectionFactory
+java.naming.provider.url=tcp://localhost:61617
+java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory

http://git-wip-us.apache.org/repos/asf/stratos/blob/5344c394/components/org.apache.stratos.mock.iaas/src/test/resources/thrift-client-config.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.mock.iaas/src/test/resources/thrift-client-config.xml b/components/org.apache.stratos.mock.iaas/src/test/resources/thrift-client-config.xml
new file mode 100644
index 0000000..f828e0d
--- /dev/null
+++ b/components/org.apache.stratos.mock.iaas/src/test/resources/thrift-client-config.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<!-- Apache thrift client configuration for publishing statistics to WSO2 CEP and WSO2 DAS -->
+<thriftClientConfiguration>
+     <config>
+        <cep>
+             <node id="node-01">
+                  <statsPublisherEnabled>true</statsPublisherEnabled>
+                  <username>admincep1</username>
+                  <password>1234cep1</password>
+                  <ip>192.168.10.10</ip>
+                  <port>9300</port>
+             </node>
+             <node id="node-02">
+                  <statsPublisherEnabled>true</statsPublisherEnabled>
+                  <username>admincep2</username>
+                  <password>1234cep2</password>
+                  <ip>192.168.10.20</ip>
+                  <port>9300</port>
+             </node>
+        </cep>
+        <das>
+             <node id="node-01">
+                  <statsPublisherEnabled>true</statsPublisherEnabled>
+                  <username>admindas1</username>
+                  <password>1234das1</password>
+                  <ip>192.168.10.11</ip>
+                  <port>9301</port>
+             </node>
+        </das>
+    </config>  
+</thriftClientConfiguration>
\ No newline at end of file