You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/09/13 04:49:22 UTC
git commit: docker cluster monitor
Repository: stratos
Updated Branches:
refs/heads/docker-integration 57a19044d -> 5ab19f5d0
docker cluster monitor
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5ab19f5d
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5ab19f5d
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5ab19f5d
Branch: refs/heads/docker-integration
Commit: 5ab19f5d071048d1fa1f535e871475a11cd11705
Parents: 57a1904
Author: R-Rajkumar <rr...@gmail.com>
Authored: Fri Sep 12 20:57:10 2014 +0530
Committer: R-Rajkumar <rr...@gmail.com>
Committed: Fri Sep 12 20:57:10 2014 +0530
----------------------------------------------------------------------
.../stratos/autoscaler/AutoscalerContext.java | 33 ++++
.../autoscaler/KubernetesClusterContext.java | 20 +++
.../cloud/controller/CloudControllerClient.java | 47 ++++-
.../AutoscalerTopologyEventReceiver.java | 85 +++++++--
.../monitor/KubernetesClusterMonitor.java | 180 +++++++++++++++++++
.../stratos/autoscaler/util/AutoscalerUtil.java | 45 +++++
.../cloud/controller/pojo/ClusterContext.java | 9 +
.../topology/TopologyEventPublisher.java | 2 +-
.../common/constants/StratosConstants.java | 3 +-
.../event/topology/ClusterRemovedEvent.java | 8 +-
10 files changed, 414 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
index c49d582..e3eb598 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/AutoscalerContext.java
@@ -23,6 +23,7 @@ package org.apache.stratos.autoscaler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.monitor.ClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.KubernetesClusterMonitor;
import org.apache.stratos.autoscaler.monitor.LbClusterMonitor;
import java.util.HashMap;
@@ -38,6 +39,7 @@ public class AutoscalerContext {
try {
setMonitors(new HashMap<String, ClusterMonitor>());
setLbMonitors(new HashMap<String, LbClusterMonitor>());
+ setKubernetesClusterMonitors(new HashMap<String, KubernetesClusterMonitor>());
} catch (Exception e) {
log.error("Rule evaluateMinCheck error", e);
}
@@ -47,6 +49,8 @@ public class AutoscalerContext {
private Map<String, ClusterMonitor> monitors;
// Map<LBClusterId, LBClusterMonitor>
private Map<String, LbClusterMonitor> lbMonitors;
+ // Map<ClusterId, KubernetesClusterMonitor>
+ private Map<String, KubernetesClusterMonitor> kubernetesClusterMonitors;
private static class Holder {
private static final AutoscalerContext INSTANCE = new AutoscalerContext();
@@ -109,4 +113,33 @@ public class AutoscalerContext {
public void addLbMonitor(LbClusterMonitor monitor) {
lbMonitors.put(monitor.getClusterId(), monitor);
}
+
+ public void addKubernetesClusterMonitor(KubernetesClusterMonitor kubernetesClusterMonitor) {
+ kubernetesClusterMonitors.put(kubernetesClusterMonitor.getClusterId(), kubernetesClusterMonitor);
+ }
+
+ public KubernetesClusterMonitor getKubernetesClusterMonitor(String clusterId) {
+ return kubernetesClusterMonitors.get(clusterId);
+ }
+
+ public boolean kubernetesClusterMonitorExist(String clusterId) {
+ return kubernetesClusterMonitors.containsKey(clusterId);
+ }
+
+ public Map<String, KubernetesClusterMonitor> getKubernetesClusterMonitors() {
+ return kubernetesClusterMonitors;
+ }
+
+ public void setKubernetesClusterMonitors(Map<String, KubernetesClusterMonitor> kubernetesClusterMonitors) {
+ this.kubernetesClusterMonitors = kubernetesClusterMonitors;
+ }
+
+ public KubernetesClusterMonitor removeKubernetesClusterMonitor(String clusterId) {
+ if(!kubernetesClusterMonitorExist(clusterId)) {
+ log.fatal("Kubernetes cluster monitor not found for cluster id: "+clusterId);
+ return null;
+ }
+ log.info("Removed KubernetesClusterMonitor [cluster id]: " + clusterId);
+ return kubernetesClusterMonitors.remove(clusterId);
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/KubernetesClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/KubernetesClusterContext.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/KubernetesClusterContext.java
new file mode 100644
index 0000000..f369ac9
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/KubernetesClusterContext.java
@@ -0,0 +1,20 @@
+package org.apache.stratos.autoscaler;
+
+import java.io.Serializable;
+
+public class KubernetesClusterContext implements Serializable{
+
+ private static final long serialVersionUID = 808741789615481596L;
+ String kubernetesClusterID;
+
+ public KubernetesClusterContext(String kubernetesClusterID){
+ this.kubernetesClusterID = kubernetesClusterID;
+ }
+
+ public String getKubernetesClusterID() {
+ return kubernetesClusterID;
+ }
+ public void setKubernetesClusterID(String kubernetesClusterID) {
+ this.kubernetesClusterID = kubernetesClusterID;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
index dff493d..10bb997 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java
@@ -24,16 +24,21 @@ import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.Constants;
+import org.apache.stratos.autoscaler.api.AutoScalerServiceImpl;
import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
import org.apache.stratos.autoscaler.exception.PartitionValidationException;
import org.apache.stratos.autoscaler.exception.SpawningException;
import org.apache.stratos.autoscaler.exception.TerminationException;
+import org.apache.stratos.autoscaler.interfaces.AutoScalerServiceInterface;
import org.apache.stratos.autoscaler.util.ConfUtil;
import org.apache.stratos.cloud.controller.stub.*;
import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition;
import org.apache.stratos.cloud.controller.stub.pojo.MemberContext;
import org.apache.stratos.cloud.controller.stub.pojo.Properties;
import org.apache.stratos.cloud.controller.stub.pojo.Property;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.common.kubernetes.KubernetesGroup;
+import org.apache.stratos.common.kubernetes.KubernetesMaster;
import java.rmi.RemoteException;
@@ -226,6 +231,46 @@ public class CloudControllerClient {
}
}
-
+ public synchronized MemberContext createContainer(String kubernetesClusterId, String clusterId) throws SpawningException {
+ try {
+
+ AutoScalerServiceInterface service = new AutoScalerServiceImpl();
+ KubernetesMaster kubernetesMaster = service.getMasterForKubernetesGroup(kubernetesClusterId);
+ String kubernetesMasterIP = kubernetesMaster.getHostIpAddress();
+ KubernetesGroup kubernetesGroup = service.getKubernetesGroup(kubernetesClusterId);
+ int lower = kubernetesGroup.getPortRange().getLower();
+ int upper = kubernetesGroup.getPortRange().getUpper();
+ String portRange = Integer.toString(lower) + "-" + Integer.toString(upper);
+
+ MemberContext member = new MemberContext();
+ member.setClusterId(clusterId);
+ member.setInitTime(System.currentTimeMillis());
+ Properties memberContextProps = new Properties();
+ Property kubernetesClusterMasterIPProps = new Property();
+ kubernetesClusterMasterIPProps.setName(StratosConstants.KUBERNETES_MASTER_IP);
+ kubernetesClusterMasterIPProps.setValue(kubernetesMasterIP);
+ memberContextProps.addProperties(kubernetesClusterMasterIPProps);
+ Property kubernetesClusterPortRangeProps = new Property();
+ kubernetesClusterPortRangeProps.setName(StratosConstants.KUBERNETES_PORT_RANGE);
+ kubernetesClusterPortRangeProps.setValue(portRange);
+ memberContextProps.addProperties(kubernetesClusterPortRangeProps);
+ member.setProperties(memberContextProps);
+ long startTime = System.currentTimeMillis();
+ MemberContext memberContext = stub.startContainer(member);
+
+ if(log.isDebugEnabled()) {
+ long endTime = System.currentTimeMillis();
+ log.debug(String.format("Service call startContainer() returned in %dms", (endTime - startTime)));
+ }
+ return memberContext;
+ } catch (CloudControllerServiceUnregisteredCartridgeExceptionException e) {
+ String message = e.getFaultMessage().getUnregisteredCartridgeException().getMessage();
+ log.error(message, e);
+ throw new SpawningException(message, e);
+ } catch (RemoteException e) {
+ log.error(e.getMessage(), e);
+ throw new SpawningException(e.getMessage(), e);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
index fed35bc..972cb65 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/message/receiver/topology/AutoscalerTopologyEventReceiver.java
@@ -29,6 +29,7 @@ import org.apache.stratos.autoscaler.exception.PolicyValidationException;
import org.apache.stratos.autoscaler.exception.TerminationException;
import org.apache.stratos.autoscaler.monitor.AbstractMonitor;
import org.apache.stratos.autoscaler.monitor.ClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.KubernetesClusterMonitor;
import org.apache.stratos.autoscaler.monitor.LbClusterMonitor;
import org.apache.stratos.autoscaler.partition.PartitionManager;
import org.apache.stratos.autoscaler.policy.PolicyManager;
@@ -184,7 +185,9 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
TopologyManager.acquireReadLock();
Service service = TopologyManager.getTopology().getService(e.getServiceName());
Cluster cluster = service.getCluster(e.getClusterId());
- if(AutoscalerContext.getInstance().monitorExist((cluster.getClusterId()))) {
+ if(AutoscalerContext.getInstance().kubernetesClusterMonitorExist(cluster.getClusterId())) {
+ AutoscalerContext.getInstance().getKubernetesClusterMonitor(e.getClusterId()).setStatus(e.getStatus());
+ } else if(AutoscalerContext.getInstance().monitorExist((cluster.getClusterId()))) {
AutoscalerContext.getInstance().getMonitor(e.getClusterId()).setStatus(e.getStatus());
} else if (AutoscalerContext.getInstance().lbMonitorExist((cluster.getClusterId()))) {
AutoscalerContext.getInstance().getLBMonitor(e.getClusterId()).setStatus(e.getStatus());
@@ -210,9 +213,19 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
String clusterId = e.getClusterId();
String deploymentPolicy = e.getDeploymentPolicy();
- AbstractMonitor monitor;
-
- if (e.isLbCluster()) {
+ AbstractMonitor monitor = null;
+ KubernetesClusterMonitor kubernetesClusterMonitor = null;
+
+ if (e.isKubernetesCluster()) {
+
+ kubernetesClusterMonitor =
+ AutoscalerContext.getInstance().removeKubernetesClusterMonitor(clusterId);
+ if(kubernetesClusterMonitor != null) {
+ // destroy drools sessions
+ log.info(String.format("Kubernetes cluster monitor has been removed successfully: [cluster] %s ",
+ clusterId));
+ }
+ } else if (e.isLbCluster()) {
DeploymentPolicy depPolicy = PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicy);
if (depPolicy != null) {
List<NetworkPartitionLbHolder> lbHolders = PartitionManager.getInstance()
@@ -564,6 +577,51 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
}
}
+ private class KubernetesClusterMonitorAdder implements Runnable {
+ private Cluster cluster;
+
+ public KubernetesClusterMonitorAdder(Cluster cluster) {
+ this.cluster = cluster;
+ }
+
+ public void run() {
+ KubernetesClusterMonitor monitor = null;
+ int retries = 5;
+ boolean success = false;
+ do {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e1) {
+ }
+
+ try {
+ monitor = AutoscalerUtil.getKubernetesClusterMonitor(cluster);
+ success = true;
+
+ } catch (Exception e) {
+ String msg = "Kubernetes cluster monitor creation failed for cluster: " + cluster.getClusterId();
+ log.debug(msg, e);
+ retries--;
+ }
+ } while (!success && retries != 0);
+
+ if (monitor == null) {
+ String msg = "Kubernetes cluster monitor creation failed, even after retrying for 5 times, "
+ + "for cluster: " + cluster.getClusterId();
+ log.error(msg);
+ throw new RuntimeException(msg);
+ }
+
+ Thread th = new Thread(monitor);
+ th.start();
+ AutoscalerContext.getInstance().addKubernetesClusterMonitor(monitor);
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Kubernetes cluster monitor has been added successfully: [cluster] %s",
+ cluster.getClusterId()));
+ }
+ }
+ }
+
@SuppressWarnings("unused")
private void runTerminateAllRule(AbstractMonitor monitor) {
@@ -588,16 +646,15 @@ public class AutoscalerTopologyEventReceiver implements Runnable {
protected synchronized void startClusterMonitor(Cluster cluster) {
Thread th = null;
- if (cluster.isLbCluster()
- && !AutoscalerContext.getInstance()
- .lbMonitorExist(
- cluster.getClusterId())) {
- th = new Thread(new LBClusterMonitorAdder(
- cluster));
- } else if (!cluster.isLbCluster() && !AutoscalerContext.getInstance()
- .monitorExist(cluster.getClusterId())) {
- th = new Thread(
- new ClusterMonitorAdder(cluster));
+ if (cluster.isKubernetesCluster()
+ && !AutoscalerContext.getInstance().kubernetesClusterMonitorExist(cluster.getClusterId())) {
+ th = new Thread(new KubernetesClusterMonitorAdder(cluster));
+ } else if (cluster.isLbCluster()
+ && !AutoscalerContext.getInstance().lbMonitorExist(cluster.getClusterId())) {
+ th = new Thread(new LBClusterMonitorAdder(cluster));
+ } else if (!cluster.isLbCluster()
+ && !AutoscalerContext.getInstance().monitorExist(cluster.getClusterId())) {
+ th = new Thread(new ClusterMonitorAdder(cluster));
}
if (th != null) {
th.start();
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java
new file mode 100644
index 0000000..dc355d5
--- /dev/null
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/KubernetesClusterMonitor.java
@@ -0,0 +1,180 @@
+package org.apache.stratos.autoscaler.monitor;
+
+import java.util.Properties;
+
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.KubernetesClusterContext;
+import org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
+import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
+import org.apache.stratos.autoscaler.util.AutoScalerConstants;
+import org.apache.stratos.autoscaler.util.ConfUtil;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.messaging.domain.topology.ClusterStatus;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+
+public class KubernetesClusterMonitor implements Runnable{
+
+ private static final Log log = LogFactory.getLog(KubernetesClusterMonitor.class);
+
+ protected KubernetesClusterContext kubernetesClusterCtxt;
+ protected String clusterId;
+ protected String serviceId;
+ protected AutoscalePolicy autoscalePolicy;
+ protected int monitorInterval;
+ protected boolean isDestroyed;
+ private ClusterStatus status;
+ private String lbReferenceType;
+ private boolean hasPrimary;
+ private int numberOfReplicasInServiceCluster = 0;
+
+ public KubernetesClusterMonitor(KubernetesClusterContext kubernetesClusterCtxt, String serviceClusterID, String serviceId,
+ AutoscalePolicy autoscalePolicy) {
+ this.clusterId = serviceClusterID;
+ this.serviceId = serviceId;
+ this.kubernetesClusterCtxt = kubernetesClusterCtxt;
+ this.autoscalePolicy = autoscalePolicy;
+ readConfigurations();
+ }
+
+ private void readConfigurations () {
+ // same as VM cluster monitor interval
+ XMLConfiguration conf = ConfUtil.getInstance(null).getConfiguration();
+ monitorInterval = conf.getInt(AutoScalerConstants.AUTOSCALER_MONITOR_INTERVAL, 90000);
+ if (log.isDebugEnabled()) {
+ log.debug("Kubernetes Cluster Monitor task interval: " + getMonitorInterval());
+ }
+ }
+
+ @Override
+ public void run() {
+ try {
+ // TODO make this configurable,
+ // this is the delay the min check of normal cluster monitor to wait
+ // until LB monitor is added
+ Thread.sleep(60000);
+ } catch (InterruptedException ignore) {
+ }
+
+ while (!isDestroyed()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Kubernetes cluster monitor is running.. " + this.toString());
+ }
+ try {
+ if (!ClusterStatus.In_Maintenance.equals(status)) {
+ monitor();
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Kubernetes cluster monitor is suspended as the cluster is in "
+ + ClusterStatus.In_Maintenance + " mode......");
+ }
+ }
+ } catch (Exception e) {
+ log.error("Kubernetes cluster monitor: Monitor failed." + this.toString(),
+ e);
+ }
+ try {
+ Thread.sleep(monitorInterval);
+ } catch (InterruptedException ignore) {
+ }
+ }
+ }
+
+ private void monitor() {
+
+ String kubernetesClusterId = this.kubernetesClusterCtxt.getKubernetesClusterID();
+
+ try {
+ TopologyManager.acquireReadLock();
+ Properties props = TopologyManager.getTopology().getService(serviceId).getCluster(clusterId).getProperties();
+ int minReplicas = Integer.parseInt(props.getProperty(StratosConstants.KUBERNETES_MIN_REPLICAS));
+
+ if (this.numberOfReplicasInServiceCluster < minReplicas) {
+
+ int numOfAdditionalReplicas = minReplicas - this.numberOfReplicasInServiceCluster;
+
+ for (int i = 0; i < numOfAdditionalReplicas; i++) {
+ try {
+ CloudControllerClient.getInstance().createContainer(kubernetesClusterId, clusterId);
+ this.numberOfReplicasInServiceCluster++;
+ } catch (Throwable e) {
+ String message = "Cannot create a container";
+ log.error(message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+ }
+ } finally {
+ TopologyManager.releaseReadLock();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "KubernetesClusterMonitor "
+ + "[ kubernetesHostClusterId=" + this.kubernetesClusterCtxt.getKubernetesClusterID()
+ + ", clusterId=" + clusterId
+ + ", serviceId=" + serviceId + "]";
+ }
+
+ public String getServiceId() {
+ return serviceId;
+ }
+
+ public void setServiceId(String serviceId) {
+ this.serviceId = serviceId;
+ }
+
+ public String getClusterId() {
+ return clusterId;
+ }
+
+ public void setClusterId(String clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ public AutoscalePolicy getAutoscalePolicy() {
+ return autoscalePolicy;
+ }
+
+ public void setAutoscalePolicy(AutoscalePolicy autoscalePolicy) {
+ this.autoscalePolicy = autoscalePolicy;
+ }
+
+ public int getMonitorInterval() {
+ return monitorInterval;
+ }
+
+ public ClusterStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(ClusterStatus status) {
+ this.status = status;
+ }
+
+ public boolean isDestroyed() {
+ return isDestroyed;
+ }
+
+ public void setDestroyed(boolean isDestroyed) {
+ this.isDestroyed = isDestroyed;
+ }
+
+ public String getLbReferenceType() {
+ return lbReferenceType;
+ }
+
+ public void setLbReferenceType(String lbReferenceType) {
+ this.lbReferenceType = lbReferenceType;
+ }
+
+ public boolean isHasPrimary() {
+ return hasPrimary;
+ }
+
+ public void setHasPrimary(boolean hasPrimary) {
+ this.hasPrimary = hasPrimary;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
index 8eaf1dd..1bc9ce7 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
@@ -22,6 +22,7 @@ package org.apache.stratos.autoscaler.util;
import org.apache.axiom.om.OMElement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.autoscaler.KubernetesClusterContext;
import org.apache.stratos.autoscaler.MemberStatsContext;
import org.apache.stratos.autoscaler.NetworkPartitionContext;
import org.apache.stratos.autoscaler.NetworkPartitionLbHolder;
@@ -31,6 +32,7 @@ import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
import org.apache.stratos.autoscaler.exception.PartitionValidationException;
import org.apache.stratos.autoscaler.exception.PolicyValidationException;
import org.apache.stratos.autoscaler.monitor.ClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.KubernetesClusterMonitor;
import org.apache.stratos.autoscaler.monitor.LbClusterMonitor;
import org.apache.stratos.autoscaler.partition.PartitionGroup;
import org.apache.stratos.autoscaler.partition.PartitionManager;
@@ -40,6 +42,7 @@ import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition;
import org.apache.stratos.cloud.controller.stub.pojo.MemberContext;
import org.apache.stratos.cloud.controller.stub.pojo.Property;
import org.apache.stratos.cloud.controller.stub.pojo.Properties;
+import org.apache.stratos.common.constants.StratosConstants;
import org.apache.stratos.messaging.domain.topology.Cluster;
import org.apache.stratos.messaging.domain.topology.ClusterStatus;
import org.apache.stratos.messaging.domain.topology.Member;
@@ -47,6 +50,7 @@ import org.apache.stratos.messaging.domain.topology.MemberStatus;
import org.apache.stratos.messaging.util.Constants;
import javax.xml.namespace.QName;
+
import java.util.*;
/**
@@ -314,7 +318,48 @@ public class AutoscalerUtil {
log.info("LB Cluster monitor created: "+clusterMonitor.toString());
return clusterMonitor;
}
+
+ public static KubernetesClusterMonitor getKubernetesClusterMonitor(Cluster cluster) {
+
+ if (null == cluster) {
+ return null;
+ }
+
+ String autoscalePolicyName = cluster.getAutoscalePolicyName();
+ if (log.isDebugEnabled()) {
+ log.debug("Autoscaler policy name: " + autoscalePolicyName);
+ }
+
+ AutoscalePolicy policy = PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
+ java.util.Properties props = cluster.getProperties();
+ String kubernetesHostClusterID = props.getProperty(StratosConstants.KUBERNETES_CLUSTER_ID);
+ KubernetesClusterContext kubernetesClusterCtxt = new KubernetesClusterContext(kubernetesHostClusterID);
+
+ KubernetesClusterMonitor kubernetesClusterMonitor = new KubernetesClusterMonitor(
+ kubernetesClusterCtxt,
+ cluster.getClusterId(),
+ cluster.getServiceName(),
+ policy);
+
+ kubernetesClusterMonitor.setStatus(ClusterStatus.Created);
+
+ // find lb reference type
+ if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
+ String value = props.getProperty(Constants.LOAD_BALANCER_REF);
+ kubernetesClusterMonitor.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
+ kubernetesClusterMonitor.setHasPrimary(Boolean.parseBoolean(props.getProperty(Constants.IS_PRIMARY)));
+ log.info("Kubernetes cluster monitor created: "+ kubernetesClusterMonitor.toString());
+ return kubernetesClusterMonitor;
+ }
+
public static Properties getProperties(final OMElement elt) {
Iterator<?> it = elt.getChildrenWithName(new QName(AutoScalerConstants.PROPERTY_ELEMENT));
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
index 9d374a7..081d632 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ClusterContext.java
@@ -37,6 +37,7 @@ public class ClusterContext implements Serializable{
private String payload;
private String hostName;
private boolean isLbCluster;
+ private boolean isKubernetesCluster;
private boolean isVolumeRequired;
private Volume[] volumes;
// timeout in milliseconds - this would be the per member time that CC waits before forcefully terminate instances on an unregistration.
@@ -87,6 +88,14 @@ public class ClusterContext implements Serializable{
public void setLbCluster(boolean isLbCluster) {
this.isLbCluster = isLbCluster;
}
+
+ public boolean isKubernetesCluster() {
+ return isKubernetesCluster;
+ }
+
+ public void setKubernetesCluster(boolean isKubernetesCluster) {
+ this.isKubernetesCluster = isKubernetesCluster;
+ }
public boolean isVolumeRequired() {
return isVolumeRequired;
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java
index fe86198..4a44b8a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java
@@ -87,7 +87,7 @@ public class TopologyEventPublisher {
public static void sendClusterRemovedEvent(ClusterContext ctxt, String deploymentPolicy) {
- ClusterRemovedEvent clusterRemovedEvent = new ClusterRemovedEvent(ctxt.getCartridgeType(), ctxt.getClusterId(), deploymentPolicy, ctxt.isLbCluster());
+ ClusterRemovedEvent clusterRemovedEvent = new ClusterRemovedEvent(ctxt.getCartridgeType(), ctxt.getClusterId(), deploymentPolicy, ctxt.isLbCluster(), ctxt.isKubernetesCluster());
if(log.isInfoEnabled()) {
log.info(String.format("Publishing cluster removed event: [service] %s [cluster] %s", ctxt.getCartridgeType(), ctxt.getClusterId()));
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
index 5058293..b02a1cb 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/constants/StratosConstants.java
@@ -143,5 +143,6 @@ public class StratosConstants {
// Kubernetes related constants
public static final String KUBERNETES_CLUSTER_ID = "kubernetes.cluster.id";
public static final String KUBERNETES_MASTER_IP = "kubernetes.master.ip";
-
+ public static final String KUBERNETES_MIN_REPLICAS = "kubernetes.replicas.min";
+ public static final String KUBERNETES_PORT_RANGE = "kubernetes.port.range";
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5ab19f5d/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterRemovedEvent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterRemovedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterRemovedEvent.java
index 43ba836..c23e5a7 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterRemovedEvent.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/ClusterRemovedEvent.java
@@ -31,12 +31,14 @@ public class ClusterRemovedEvent extends TopologyEvent implements Serializable {
private final String clusterId;
private final String deploymentPolicy;
private final boolean isLbCluster;
+ private final boolean isKubernetesCluster;
- public ClusterRemovedEvent(String serviceName, String clusterId, String deploymentPolicy, boolean isLbCluster) {
+ public ClusterRemovedEvent(String serviceName, String clusterId, String deploymentPolicy, boolean isLbCluster, boolean isKubernetesCluster) {
this.serviceName = serviceName;
this.clusterId = clusterId;
this.isLbCluster = isLbCluster;
this.deploymentPolicy = deploymentPolicy;
+ this.isKubernetesCluster = isKubernetesCluster;
}
public String getServiceName() {
@@ -54,4 +56,8 @@ public class ClusterRemovedEvent extends TopologyEvent implements Serializable {
public String getDeploymentPolicy() {
return deploymentPolicy;
}
+
+ public boolean isKubernetesCluster() {
+ return isKubernetesCluster;
+ }
}