Reformat the class ClusterMonitorFactory

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

Branch: refs/heads/master
Commit: 2b77329a94ae6f1b4fa8b33f6b43a2d852dce942
Parents: 8554704
Author: gayan <[email protected]>
Authored: Fri Nov 28 17:29:14 2014 +0530
Committer: gayan <[email protected]>
Committed: Fri Nov 28 18:29:15 2014 +0530

----------------------------------------------------------------------
 .../monitor/cluster/ClusterMonitorFactory.java  | 322 ++++++++++---------
 1 file changed, 164 insertions(+), 158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/2b77329a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
index e5a5bda..36a86b3 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java
@@ -57,162 +57,168 @@ public class ClusterMonitorFactory {
        public static AbstractClusterMonitor getMonitor(Cluster cluster)
                        throws PolicyValidationException, 
PartitionValidationException {
 
-        AbstractClusterMonitor clusterMonitor;
-        if (cluster.isKubernetesCluster()) {
-            clusterMonitor = getDockerServiceClusterMonitor(cluster);
-        } else if (cluster.isLbCluster()) {
-            clusterMonitor = getVMLbClusterMonitor(cluster);
-        } else {
-            clusterMonitor = getVMServiceClusterMonitor(cluster);
-        }
-
-        return clusterMonitor;
-    }
-
-    private static VMServiceClusterMonitor getVMServiceClusterMonitor(Cluster 
cluster)
-            throws PolicyValidationException, PartitionValidationException {
-
-        if (null == cluster) {
-            return null;
-        }
-
-        VMServiceClusterMonitor clusterMonitor = new 
VMServiceClusterMonitor(cluster.getServiceName(), cluster.getClusterId());
-
-        // find lb reference type
-        java.util.Properties props = cluster.getProperties();
-
-        if (props != null) {
-            if (props.containsKey(StratosConstants.LOAD_BALANCER_REF)) {
-                String value = 
props.getProperty(StratosConstants.LOAD_BALANCER_REF);
-                clusterMonitor.setLbReferenceType(value);
-                if (log.isDebugEnabled()) {
-                    log.debug("Set the lb reference type: " + value);
-                }
-            }
-
-            // set hasPrimary property
-            // hasPrimary is true if there are primary members available in 
that cluster
-            
clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(IS_PRIMARY)));
-        }
-
-
-        log.info("VMServiceClusterMonitor created: " + 
clusterMonitor.toString());
-        return clusterMonitor;
-    }
-
-    private static VMLbClusterMonitor getVMLbClusterMonitor(Cluster cluster)
-            throws PolicyValidationException, PartitionValidationException {
-
-        if (null == cluster) {
-            return null;
-        }
-
-        VMLbClusterMonitor clusterMonitor =
-                new VMLbClusterMonitor(cluster.getServiceName(), 
cluster.getClusterId());
-        clusterMonitor.setStatus(ClusterStatus.Created);
-
-        log.info("VMLbClusterMonitor created: " + clusterMonitor.toString());
-        return clusterMonitor;
-    }
-
-    /**
-     * @param cluster - the cluster which needs to be monitored
-     * @return - the cluster monitor
-     */
-    private static KubernetesServiceClusterMonitor 
getDockerServiceClusterMonitor(Cluster cluster)
-            throws PolicyValidationException {
-
-        if (null == cluster) {
-            return null;
-        }
-
-//        String autoscalePolicyName = cluster.getAutoscalePolicyName();
-//
-//        AutoscalePolicy autoscalePolicy =
-//                PolicyManager.getInstance()
-//                        .getAutoscalePolicy(autoscalePolicyName);
-//        if (log.isDebugEnabled()) {
-//            log.debug("Autoscaling policy name: " + autoscalePolicyName);
-//        }
-//
-//        AutoscalePolicy policy = 
PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
-//
-//        if (policy == null) {
-//            String msg = String.format("Autoscaling policy is null: 
[policy-name] %s", autoscalePolicyName);
-//            log.error(msg);
-//            throw new PolicyValidationException(msg);
-//        }
-//
-        java.util.Properties properties = cluster.getProperties();
-        if (properties == null) {
-            String message = String.format("Properties not found in kubernetes 
cluster: [cluster-id] %s",
-                    cluster.getClusterId());
-            log.error(message);
-            throw new RuntimeException(message);
-        }
-//        String minReplicasProperty = 
properties.getProperty(StratosConstants.KUBERNETES_MIN_REPLICAS);
-//        int minReplicas = 0;
-//        if (minReplicasProperty != null && !minReplicasProperty.isEmpty()) {
-//            minReplicas = Integer.parseInt(minReplicasProperty);
-//        }
-//
-//        int maxReplicas = 0;
-//        String maxReplicasProperty = 
properties.getProperty(StratosConstants.KUBERNETES_MAX_REPLICAS);
-//        if (maxReplicasProperty != null && !maxReplicasProperty.isEmpty()) {
-//            maxReplicas = Integer.parseInt(maxReplicasProperty);
-//        }
-//
-//        String kubernetesHostClusterID = 
properties.getProperty(StratosConstants.KUBERNETES_CLUSTER_ID);
-//        KubernetesClusterContext kubernetesClusterCtxt = new 
KubernetesClusterContext(kubernetesHostClusterID,
-//                cluster.getClusterId(), cluster.getServiceName(),  
autoscalePolicy, minReplicas, maxReplicas);
-
-
-        KubernetesServiceClusterMonitor dockerClusterMonitor = new 
KubernetesServiceClusterMonitor(cluster.getServiceName(), 
cluster.getClusterId());
-
-        //populate the members after restarting
-        for (Member member : cluster.getMembers()) {
-            String memberId = member.getMemberId();
-            String clusterId = member.getClusterId();
-            MemberContext memberContext = new MemberContext();
-            memberContext.setMemberId(memberId);
-            memberContext.setClusterId(clusterId);
-            memberContext.setInitTime(member.getInitTime());
-
-            // if there is at least one member in the topology, that means 
service has been created already
-            // this is to avoid calling startContainer() method again
-            //kubernetesClusterCtxt.setServiceClusterCreated(true);
-
-            if (MemberStatus.Activated.equals(member.getStatus())) {
-                if (log.isDebugEnabled()) {
-                    String msg = String.format("Active member loaded from 
topology and added to active member list, %s", member.toString());
-                    log.debug(msg);
-                }
-                
dockerClusterMonitor.getKubernetesClusterCtxt().addActiveMember(memberContext);
-            } else if (MemberStatus.Created.equals(member.getStatus())
-                    || MemberStatus.Starting.equals(member.getStatus())) {
-                if (log.isDebugEnabled()) {
-                    String msg = String.format("Pending member loaded from 
topology and added to pending member list, %s", member.toString());
-                    log.debug(msg);
-                }
-                
dockerClusterMonitor.getKubernetesClusterCtxt().addPendingMember(memberContext);
-            }
-
-            //kubernetesClusterCtxt.addMemberStatsContext(new 
MemberStatsContext(memberId));
-            if (log.isInfoEnabled()) {
-                log.info(String.format("Member stat context has been added: 
[member] %s", memberId));
-            }
-        }
-
-        // find lb reference type
-        if (properties.containsKey(StratosConstants.LOAD_BALANCER_REF)) {
-            String value = 
properties.getProperty(StratosConstants.LOAD_BALANCER_REF);
-            dockerClusterMonitor.setLbReferenceType(value);
-            if (log.isDebugEnabled()) {
-                log.debug("Set the lb reference type: " + value);
-            }
-        }
-
-        log.info("KubernetesServiceClusterMonitor created: " + 
dockerClusterMonitor.toString());
-        return dockerClusterMonitor;
-    }
+               AbstractClusterMonitor clusterMonitor;
+               if (cluster.isKubernetesCluster()) {
+                       clusterMonitor = 
getDockerServiceClusterMonitor(cluster);
+               } else if (cluster.isLbCluster()) {
+                       clusterMonitor = getVMLbClusterMonitor(cluster);
+               } else {
+                       clusterMonitor = getVMServiceClusterMonitor(cluster);
+               }
+
+               return clusterMonitor;
+       }
+
+       private static VMServiceClusterMonitor 
getVMServiceClusterMonitor(Cluster cluster)
+                       throws PolicyValidationException, 
PartitionValidationException {
+
+               if (null == cluster) {
+                       return null;
+               }
+
+               VMServiceClusterMonitor clusterMonitor =
+                               new 
VMServiceClusterMonitor(cluster.getServiceName(), cluster.getClusterId());
+
+               // find lb reference type
+               java.util.Properties props = cluster.getProperties();
+
+               if (props != null) {
+                       if 
(props.containsKey(StratosConstants.LOAD_BALANCER_REF)) {
+                               String value = 
props.getProperty(StratosConstants.LOAD_BALANCER_REF);
+                               clusterMonitor.setLbReferenceType(value);
+                               if (log.isDebugEnabled()) {
+                                       log.debug("Set the lb reference type: " 
+ value);
+                               }
+                       }
+
+                       // set hasPrimary property
+                       // hasPrimary is true if there are primary members 
available in that cluster
+                       
clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(IS_PRIMARY)));
+               }
+
+               log.info("VMServiceClusterMonitor created: " + 
clusterMonitor.toString());
+               return clusterMonitor;
+       }
+
+       private static VMLbClusterMonitor getVMLbClusterMonitor(Cluster cluster)
+                       throws PolicyValidationException, 
PartitionValidationException {
+
+               if (null == cluster) {
+                       return null;
+               }
+
+               VMLbClusterMonitor clusterMonitor =
+                               new 
VMLbClusterMonitor(cluster.getServiceName(), cluster.getClusterId());
+               clusterMonitor.setStatus(ClusterStatus.Created);
+
+               log.info("VMLbClusterMonitor created: " + 
clusterMonitor.toString());
+               return clusterMonitor;
+       }
+
+       /**
+        * @param cluster - the cluster which needs to be monitored
+        * @return - the cluster monitor
+        */
+       private static KubernetesServiceClusterMonitor 
getDockerServiceClusterMonitor(Cluster cluster)
+                       throws PolicyValidationException {
+
+               if (null == cluster) {
+                       return null;
+               }
+
+               //        String autoscalePolicyName = 
cluster.getAutoscalePolicyName();
+               //
+               //        AutoscalePolicy autoscalePolicy =
+               //                PolicyManager.getInstance()
+               //                        
.getAutoscalePolicy(autoscalePolicyName);
+               //        if (log.isDebugEnabled()) {
+               //            log.debug("Autoscaling policy name: " + 
autoscalePolicyName);
+               //        }
+               //
+               //        AutoscalePolicy policy = 
PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
+               //
+               //        if (policy == null) {
+               //            String msg = String.format("Autoscaling policy is 
null: [policy-name] %s", autoscalePolicyName);
+               //            log.error(msg);
+               //            throw new PolicyValidationException(msg);
+               //        }
+               //
+               java.util.Properties properties = cluster.getProperties();
+               if (properties == null) {
+                       String message = String.format("Properties not found in 
kubernetes cluster: [cluster-id] %s",
+                                                      cluster.getClusterId());
+                       log.error(message);
+                       throw new RuntimeException(message);
+               }
+               //        String minReplicasProperty = 
properties.getProperty(StratosConstants.KUBERNETES_MIN_REPLICAS);
+               //        int minReplicas = 0;
+               //        if (minReplicasProperty != null && 
!minReplicasProperty.isEmpty()) {
+               //            minReplicas = 
Integer.parseInt(minReplicasProperty);
+               //        }
+               //
+               //        int maxReplicas = 0;
+               //        String maxReplicasProperty = 
properties.getProperty(StratosConstants.KUBERNETES_MAX_REPLICAS);
+               //        if (maxReplicasProperty != null && 
!maxReplicasProperty.isEmpty()) {
+               //            maxReplicas = 
Integer.parseInt(maxReplicasProperty);
+               //        }
+               //
+               //        String kubernetesHostClusterID = 
properties.getProperty(StratosConstants.KUBERNETES_CLUSTER_ID);
+               //        KubernetesClusterContext kubernetesClusterCtxt = new 
KubernetesClusterContext
+               // (kubernetesHostClusterID,
+               //                cluster.getClusterId(), 
cluster.getServiceName(),  autoscalePolicy, minReplicas,
+               // maxReplicas);
+
+               KubernetesServiceClusterMonitor dockerClusterMonitor =
+                               new 
KubernetesServiceClusterMonitor(cluster.getServiceName(), 
cluster.getClusterId());
+
+               //populate the members after restarting
+               for (Member member : cluster.getMembers()) {
+                       String memberId = member.getMemberId();
+                       String clusterId = member.getClusterId();
+                       MemberContext memberContext = new MemberContext();
+                       memberContext.setMemberId(memberId);
+                       memberContext.setClusterId(clusterId);
+                       memberContext.setInitTime(member.getInitTime());
+
+                       // if there is at least one member in the topology, 
that means service has been created already
+                       // this is to avoid calling startContainer() method 
again
+                       //kubernetesClusterCtxt.setServiceClusterCreated(true);
+
+                       if (MemberStatus.Activated.equals(member.getStatus())) {
+                               if (log.isDebugEnabled()) {
+                                       String msg = String.format("Active 
member loaded from topology and added to active member list, " +
+                                                                  "%s",
+                                                                  
member.toString());
+                                       log.debug(msg);
+                               }
+                               
dockerClusterMonitor.getKubernetesClusterCtxt().addActiveMember(memberContext);
+                       } else if 
(MemberStatus.Created.equals(member.getStatus())
+                                  || 
MemberStatus.Starting.equals(member.getStatus())) {
+                               if (log.isDebugEnabled()) {
+                                       String msg =
+                                                       String.format("Pending 
member loaded from topology and added to pending member list, %s",
+                                                                     
member.toString());
+                                       log.debug(msg);
+                               }
+                               
dockerClusterMonitor.getKubernetesClusterCtxt().addPendingMember(memberContext);
+                       }
+
+                       //kubernetesClusterCtxt.addMemberStatsContext(new 
MemberStatsContext(memberId));
+                       if (log.isInfoEnabled()) {
+                               log.info(String.format("Member stat context has 
been added: [member] %s", memberId));
+                       }
+               }
+
+               // find lb reference type
+               if (properties.containsKey(StratosConstants.LOAD_BALANCER_REF)) 
{
+                       String value = 
properties.getProperty(StratosConstants.LOAD_BALANCER_REF);
+                       dockerClusterMonitor.setLbReferenceType(value);
+                       if (log.isDebugEnabled()) {
+                               log.debug("Set the lb reference type: " + 
value);
+                       }
+               }
+
+               log.info("KubernetesServiceClusterMonitor created: " + 
dockerClusterMonitor.toString());
+               return dockerClusterMonitor;
+       }
 }

Reply via email to