Removing merge conflicts
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/e390488b Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/e390488b Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/e390488b Branch: refs/heads/master Commit: e390488b5a136965d6da3fbf3e8ddafba6c84ef8 Parents: 8a5de9c Author: gayan <[email protected]> Authored: Fri Nov 28 18:51:59 2014 +0530 Committer: gayan <[email protected]> Committed: Fri Nov 28 18:51:59 2014 +0530 ---------------------------------------------------------------------- .../monitor/cluster/ClusterMonitorFactory.java | 353 +++++++++---------- .../rule/AutoscalerRuleEvaluator.java | 23 -- 2 files changed, 168 insertions(+), 208 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/e390488b/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 36a86b3..2d1cd7d 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 @@ -21,204 +21,187 @@ package org.apache.stratos.autoscaler.monitor.cluster; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -<<<<<<< HEAD import org.apache.stratos.autoscaler.exception.partition.PartitionValidationException; import org.apache.stratos.autoscaler.exception.policy.PolicyValidationException; import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; -======= -import org.apache.stratos.autoscaler.exception.PartitionValidationException; -import org.apache.stratos.autoscaler.exception.PolicyValidationException; -import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; import org.apache.stratos.common.constants.StratosConstants; ->>>>>>> 96c4da0... Rebase the master and merge changes of PR 121 import org.apache.stratos.messaging.domain.topology.Cluster; import org.apache.stratos.messaging.domain.topology.ClusterStatus; import org.apache.stratos.messaging.domain.topology.Member; import org.apache.stratos.messaging.domain.topology.MemberStatus; -<<<<<<< HEAD - -======= ->>>>>>> 96c4da0... Rebase the master and merge changes of PR 121 /* * Factory class for creating cluster monitors. */ public class ClusterMonitorFactory { - private static final Log log = LogFactory.getLog(ClusterMonitorFactory.class); + private static final Log log = LogFactory.getLog(ClusterMonitorFactory.class); public static final String IS_PRIMARY = "PRIMARY"; - - /** - * @param cluster the cluster to be monitored - * @return the created cluster monitor - * @throws PolicyValidationException when deployment policy is not valid - * @throws PartitionValidationException when partition is not valid - */ - 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; - } + /** + * @param cluster the cluster to be monitored + * @return the created cluster monitor + * @throws PolicyValidationException when deployment policy is not valid + * @throws PartitionValidationException when partition is not valid + */ + 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; + } } http://git-wip-us.apache.org/repos/asf/stratos/blob/e390488b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java index ae307fb..9eac1da 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/rule/AutoscalerRuleEvaluator.java @@ -214,7 +214,6 @@ public class AutoscalerRuleEvaluator { return ksession; } -<<<<<<< HEAD // public static String getLbClusterId(ClusterLevelPartitionContext clusterMonitorPartitionContext, String nwpartitionId) { // Properties props = clusterMonitorPartitionContext.getProperties(); // String value = @@ -235,28 +234,6 @@ public class AutoscalerRuleEvaluator { // } // return lbClusterId; // } -======= - public static String getLbClusterId(ClusterLevelPartitionContext clusterMonitorPartitionContext, String nwpartitionId) { - Properties props = clusterMonitorPartitionContext.getProperties(); - String value = - (String) props.get(StratosConstants.LOAD_BALANCER_REF); - - if (value == null){ - return null; - } - - String lbClusterId = null; - - NetworkPartitionLbHolder networkPartitionLbHolder = PartitionManager.getInstance().getNetworkPartitionLbHolder(nwpartitionId); - if (value.equals(StratosConstants.DEFAULT_LOAD_BALANCER)) { - lbClusterId = networkPartitionLbHolder.getDefaultLbClusterId(); - } else if (value.equals(StratosConstants.SERVICE_AWARE_LOAD_BALANCER)) { - String serviceName = clusterMonitorPartitionContext.getServiceName(); - lbClusterId = networkPartitionLbHolder.getLBClusterIdOfService(serviceName); - } - return lbClusterId; - } ->>>>>>> 684e52c... Rebase the master and merge changes of PR 121 private static KnowledgeBase readKnowledgeBase(String drlFileName) { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
