Improving logs by adding application id

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

Branch: refs/heads/master
Commit: 95a7060733576e3191348721e01ef8dc13249cac
Parents: 2254dde
Author: Vishanth <[email protected]>
Authored: Fri May 15 15:24:52 2015 +0530
Committer: Imesh Gunaratne <[email protected]>
Committed: Fri May 15 16:35:33 2015 +0530

----------------------------------------------------------------------
 .../services/impl/AutoscalerServiceImpl.java    | 49 +++++++++++---------
 1 file changed, 26 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/95a70607/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 9986df3..390a402 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
@@ -69,11 +69,10 @@ import 
org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
 import org.wso2.carbon.registry.api.RegistryException;
 
 import java.rmi.RemoteException;
-import java.text.MessageFormat;
 import java.util.*;
 
 /**
- * Auto Scaler Service API is responsible getting Partitions and Policies.
+ * Autoscaler Service API is responsible getting Partitions and Policies.
  */
 public class AutoscalerServiceImpl implements AutoscalerService {
 
@@ -169,18 +168,19 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
         }
 
         if 
(AutoscalerContext.getInstance().getApplicationContext(applicationId) == null) {
-            String msg = "Application is not found as ApplicationContext. 
Please add application before updating it";
-            log.error(msg);
-            throw new ApplicationDefinitionException(msg);
+            String message = "Application is not found as ApplicationContext. 
Please add application before updating it: " +
+                    "[application-id] " + applicationId;
+            log.error(message);
+            throw new ApplicationDefinitionException(message);
         }
 
         if (ApplicationHolder.getApplications().getApplication(applicationId) 
== null) {
-            String msg = "Application is not found as Application. Please add 
application before updating it";
-            log.error(msg);
-            throw new ApplicationDefinitionException(msg);
+            String message = "Application is not found as Application. Please 
add application before updating it: " +
+                    "[application-id] " + applicationId;
+            log.error(message);
+            throw new ApplicationDefinitionException(message);
         }
 
-
         ApplicationParser applicationParser = new DefaultApplicationParser();
         Application application = applicationParser.parse(applicationContext);
 
@@ -270,7 +270,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
             applicationContext.setStatus(ApplicationContext.STATUS_DEPLOYED);
             
AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
 
-            log.info("Waiting for application clusters to be created: 
[application] " + applicationId);
+            log.info("Waiting for application clusters to be created: 
[application-id] " + applicationId);
             return true;
         } catch (Exception e) {
             ApplicationContext applicationContext = 
RegistryManager.getInstance().
@@ -280,7 +280,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
                 
applicationContext.setStatus(ApplicationContext.STATUS_CREATED);
                 
AutoscalerContext.getInstance().updateApplicationContext(applicationContext);
             }
-            String message = "Application deployment failed";
+            String message = "Application deployment failed: [application-id]" 
+ applicationId;
             log.error(message, e);
             throw new RuntimeException(message, e);
         }
@@ -354,7 +354,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
                 }
             }
         } catch (Exception e) {
-            String message = "Could not add application signup";
+            String message = "Could not add application signup: 
[application-id]" + applicationContext.getApplicationId();
             log.error(message, e);
             throw new RuntimeException(message, e);
         }
@@ -482,7 +482,8 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
             if (appMonitor.isTerminating()) {
 
                 if (appMonitor.isForce()) {
-                    log.warn("Force un-deployment is already in progress, 
hence not invoking again");
+                    log.warn(String.format("Force un-deployment is already in 
progress, hence not invoking again " +
+                            "[application-id] %s", applicationId));
                     return false;
                 } else {
                     log.info(String.format("Previous graceful un-deployment is 
in progress for " +
@@ -574,7 +575,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
 
     public boolean updateClusterMonitor(String clusterId, Properties 
properties) throws InvalidArgumentException {
         if (log.isDebugEnabled()) {
-            log.debug(String.format("Updating Cluster monitor [Cluster id] %s 
", clusterId));
+            log.debug(String.format("Updating Cluster monitor [cluster-id] %s 
", clusterId));
         }
         AutoscalerContext asCtx = AutoscalerContext.getInstance();
         ClusterMonitor monitor = asCtx.getClusterMonitor(clusterId);
@@ -582,7 +583,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
         if (monitor != null) {
             monitor.handleDynamicUpdates(properties);
         } else {
-            log.debug(String.format("Updating Cluster monitor failed: Cluster 
monitor [Cluster id] %s not found.",
+            log.debug(String.format("Updating Cluster monitor failed: Cluster 
monitor [cluster-id] %s not found.",
                     clusterId));
         }
         return true;
@@ -591,7 +592,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
     public boolean addServiceGroup(ServiceGroup servicegroup) throws 
InvalidServiceGroupException {
 
         if (servicegroup == null || 
StringUtils.isEmpty(servicegroup.getName())) {
-            String msg = "Cartridge group can not be null service name can not 
be empty.";
+            String msg = "Cartridge group cannot be null or service name 
cannot be empty.";
             log.error(msg);
             throw new IllegalArgumentException(msg);
         }
@@ -606,7 +607,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
         }
 
         if (log.isDebugEnabled()) {
-            log.debug(MessageFormat.format("Adding cartridge group {0}", 
servicegroup.getName()));
+            log.debug(String.format("Adding cartridge group %s", 
servicegroup.getName()));
         }
 
         String[] subGroups = servicegroup.getCartridges();
@@ -839,7 +840,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
         String applicationPolicyId = applicationPolicy.getId();
         ApplicationPolicy existingApplicationPolicy = 
PolicyManager.getInstance().getApplicationPolicy(applicationPolicyId);
         if (existingApplicationPolicy == null) {
-            String msg = String.format("No such application poliicy found 
[application-policy-id] %s", applicationPolicyId);
+            String msg = String.format("No such application policy found 
[application-policy-id] %s", applicationPolicyId);
             log.error(msg);
             throw new ApplicatioinPolicyNotExistsException(msg);
         }
@@ -859,7 +860,7 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
 
     private void terminateAllApplicationMembersForcefully(String 
applicationId) {
         if (StringUtils.isEmpty(applicationId)) {
-            throw new IllegalArgumentException("Application Id can not be 
empty");
+            throw new IllegalArgumentException("Application Id cannot be 
empty");
         }
 
         Application application;
@@ -867,7 +868,8 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
             ApplicationManager.acquireReadLockForApplication(applicationId);
             application = 
ApplicationManager.getApplications().getApplication(applicationId);
             if (application == null) {
-                log.warn(String.format("Could not find application, thus no 
members to be terminated [application-id] %s", applicationId));
+                log.warn(String.format("Could not find application, thus no 
members to be terminated " +
+                        "[application-id] %s", applicationId));
                 return;
             }
         } finally {
@@ -876,7 +878,6 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
 
 
         Set<ClusterDataHolder> allClusters = 
application.getClusterDataRecursively();
-        //CloudControllerServiceClient cloudControllerServiceClient = 
CloudControllerServiceClient.getInstance().ter
         for (ClusterDataHolder clusterDataHolder : allClusters) {
             String serviceType = clusterDataHolder.getServiceType();
             String clusterId = clusterDataHolder.getClusterId();
@@ -896,10 +897,12 @@ public class AutoscalerServiceImpl implements 
AutoscalerService {
 
             for (String memberIdToTerminate : memberListToTerminate) {
                 try {
-                    log.info(String.format("Terminating member forcefully 
[member-id] %s of the cluster [cluster-id] %s [application-id] %s", 
memberIdToTerminate, clusterId, application));
+                    log.info(String.format("Terminating member forcefully 
[member-id] %s of the cluster [cluster-id] %s " +
+                            "[application-id] %s", memberIdToTerminate, 
clusterId, application));
                     
CloudControllerServiceClient.getInstance().terminateInstanceForcefully(memberIdToTerminate);
                 } catch (Exception e) {
-                    log.error(String.format("Forcefull termination of member 
%s is failed, but continuing forcefull deletion of other members", 
memberIdToTerminate));
+                    log.error(String.format("Forceful termination of member %s 
has failed, but continuing forceful " +
+                            "deletion of other members", memberIdToTerminate));
                 }
             }
         }

Reply via email to