You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2014/11/04 06:29:57 UTC
[19/20] merging with 4.0.0-grouping until
93b0e165c4ddeb2334025cd5e4eefc3062c530ac
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
index d8d8514,0000000..504167a
mode 100644,000000..100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/application/ApplicationMonitorFactory.java
@@@ -1,230 -1,0 +1,232 @@@
+/*
+ * 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.autoscaler.monitor.application;
+
- import java.util.Map;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
++import org.apache.stratos.autoscaler.applications.ApplicationHolder;
+import org.apache.stratos.autoscaler.applications.dependency.context.ApplicationContext;
+import org.apache.stratos.autoscaler.applications.dependency.context.ClusterContext;
+import org.apache.stratos.autoscaler.applications.dependency.context.GroupContext;
+import org.apache.stratos.autoscaler.exception.DependencyBuilderException;
+import org.apache.stratos.autoscaler.exception.PartitionValidationException;
+import org.apache.stratos.autoscaler.exception.PolicyValidationException;
+import org.apache.stratos.autoscaler.exception.TopologyInConsistentException;
+import org.apache.stratos.autoscaler.monitor.Monitor;
+import org.apache.stratos.autoscaler.monitor.ParentComponentMonitor;
+import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitorFactory;
+import org.apache.stratos.autoscaler.monitor.cluster.VMClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
- import org.apache.stratos.common.xsd.Property;
+import org.apache.stratos.common.xsd.Properties;
++import org.apache.stratos.common.xsd.Property;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.Group;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.domain.topology.Topology;
- import org.apache.stratos.messaging.message.receiver.applications.ApplicationManager;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+
++import java.util.Map;
++
+/**
+ * Factory class to get the Monitors.
+ */
+public class ApplicationMonitorFactory {
+ private static final Log log = LogFactory.getLog(ApplicationMonitorFactory.class);
+
+ /**
+ * Factor method used to create relevant monitors based on the given context
+ *
+ * @param context Application/Group/Cluster context
+ * @param appId appId of the application which requires to create app monitor
+ * @param parentMonitor parent of the monitor
+ * @return Monitor which can be ApplicationMonitor/GroupMonitor/ClusterMonitor
+ * @throws TopologyInConsistentException throws while traversing thr topology
+ * @throws DependencyBuilderException throws while building dependency for app monitor
+ * @throws PolicyValidationException throws while validating the policy associated with cluster
+ * @throws PartitionValidationException throws while validating the partition used in a cluster
+ */
+ public static Monitor getMonitor(ParentComponentMonitor parentMonitor, ApplicationContext context, String appId)
+ throws TopologyInConsistentException,
+ DependencyBuilderException, PolicyValidationException, PartitionValidationException {
+ Monitor monitor;
+
+ if (context instanceof GroupContext) {
+ monitor = getGroupMonitor(parentMonitor, context, appId);
+ } else if (context instanceof ClusterContext) {
+ monitor = getClusterMonitor(parentMonitor, (ClusterContext) context, appId);
+ //Start the thread
+ Thread th = new Thread((AbstractClusterMonitor) monitor);
+ th.start();
+ } else {
+ monitor = getApplicationMonitor(appId);
+ }
+ return monitor;
+ }
+
+ /**
+ * This will create the GroupMonitor based on given groupId by going thr Topology
+ *
+ * @param parentMonitor parent of the monitor
+ * @param context groupId of the group
+ * @param appId appId of the relevant application
+ * @return Group monitor
+ * @throws DependencyBuilderException throws while building dependency for app monitor
+ * @throws TopologyInConsistentException throws while traversing thr topology
+ */
+ public static Monitor getGroupMonitor(ParentComponentMonitor parentMonitor, ApplicationContext context, String appId)
+ throws DependencyBuilderException,
+ TopologyInConsistentException {
+ GroupMonitor groupMonitor;
- ApplicationManager.acquireReadLockForApplication(appId);
++ ApplicationHolder.acquireReadLock();
+
+ try {
- Group group = ApplicationManager.getApplications().getApplication(appId).getGroupRecursively(context.getId());
++ Group group = ApplicationHolder.getApplications().
++ getApplication(appId).getGroupRecursively(context.getId());
+ groupMonitor = new GroupMonitor(group, appId);
+ groupMonitor.setAppId(appId);
- if(parentMonitor != null) {
++ if (parentMonitor != null) {
+ groupMonitor.setParent(parentMonitor);
+ //Setting the dependent behaviour of the monitor
- if(parentMonitor.isDependent() || (context.isDependent() && context.hasChild())) {
++ if (parentMonitor.isDependent() || (context.isDependent() && context.hasChild())) {
+ groupMonitor.setHasDependent(true);
+ } else {
+ groupMonitor.setHasDependent(false);
+ }
+ //TODO make sure when it is async
+
+ if (group.getStatus() != groupMonitor.getStatus()) {
+ //updating the status, if the group is not in created state when creating group Monitor
+ //so that groupMonitor will notify the parent (useful when restarting stratos)
+ groupMonitor.setStatus(group.getStatus());
+ }
+ }
+
+ } finally {
- ApplicationManager.releaseReadLockForApplication(appId);
++ ApplicationHolder.releaseReadLock();
+
+ }
+ return groupMonitor;
+
+ }
+
+ /**
+ * This will create a new app monitor based on the give appId by getting the
+ * application from Topology
+ *
+ * @param appId appId of the application which requires to create app monitor
+ * @return ApplicationMonitor
+ * @throws DependencyBuilderException throws while building dependency for app monitor
+ * @throws TopologyInConsistentException throws while traversing thr topology
+ */
+ public static ApplicationMonitor getApplicationMonitor(String appId)
+ throws DependencyBuilderException,
+ TopologyInConsistentException {
+ ApplicationMonitor applicationMonitor;
- ApplicationManager.acquireReadLockForApplication(appId);
++ ApplicationHolder.acquireReadLock();
+ try {
- Application application = ApplicationManager.getApplications().getApplication(appId);
++ Application application = ApplicationHolder.getApplications().getApplication(appId);
+ if (application != null) {
+ applicationMonitor = new ApplicationMonitor(application);
+ applicationMonitor.setHasDependent(false);
+
+ } else {
+ String msg = "[Application] " + appId + " cannot be found in the Topology";
+ throw new TopologyInConsistentException(msg);
+ }
+ } finally {
- ApplicationManager.releaseReadLockForApplication(appId);
++ ApplicationHolder.releaseReadLock();
++
+ }
+
+ return applicationMonitor;
+
+ }
+
+ /**
+ * Updates ClusterContext for given cluster
+ *
+ * @param parentMonitor parent of the monitor
+ * @param context
+ * @return ClusterMonitor - Updated ClusterContext
+ * @throws org.apache.stratos.autoscaler.exception.PolicyValidationException
+ * @throws org.apache.stratos.autoscaler.exception.PartitionValidationException
+ */
+ public static VMClusterMonitor getClusterMonitor(ParentComponentMonitor parentMonitor,
- ClusterContext context, String appId)
++ ClusterContext context, String appId)
+ throws PolicyValidationException,
+ PartitionValidationException,
+ TopologyInConsistentException {
+ //Retrieving the Cluster from Topology
+ String clusterId = context.getId();
+ String serviceName = context.getServiceName();
+
+ Cluster cluster;
+ AbstractClusterMonitor clusterMonitor;
+ //acquire read lock for the service and cluster
+ TopologyManager.acquireReadLockForCluster(serviceName, clusterId);
+ try {
+ Topology topology = TopologyManager.getTopology();
+ if (topology.serviceExists(serviceName)) {
+ Service service = topology.getService(serviceName);
+ if (service.clusterExists(clusterId)) {
+ cluster = service.getCluster(clusterId);
+ if (log.isDebugEnabled()) {
+ log.debug("Dependency check starting the [cluster]" + clusterId);
+ }
+ // startClusterMonitor(this, cluster);
+ //context.setCurrentStatus(Status.Created);
+ } else {
+ String msg = "[Cluster] " + clusterId + " cannot be found in the " +
+ "Topology for [service] " + serviceName;
+ throw new TopologyInConsistentException(msg);
+ }
+ } else {
+ String msg = "[Service] " + serviceName + " cannot be found in the Topology";
+ throw new TopologyInConsistentException(msg);
+
+ }
+
+
+ clusterMonitor = ClusterMonitorFactory.getMonitor(cluster);
+ if (clusterMonitor instanceof VMClusterMonitor) {
+ return (VMClusterMonitor) clusterMonitor;
+ } else if (clusterMonitor != null) {
+ log.warn("Unknown cluster monitor found: " + clusterMonitor.getClass().toString());
+ }
+ return null;
+ } finally {
+ TopologyManager.releaseReadLockForCluster(serviceName, clusterId);
+ }
+ }
+
+
+ private static Properties convertMemberPropsToMemberContextProps(
+ java.util.Properties properties) {
+ Properties props = new Properties();
+ for (Map.Entry<Object, Object> e : properties.entrySet()) {
+ Property prop = new Property();
+ prop.setName((String) e.getKey());
+ prop.setValue((String) e.getValue());
+ props.addProperties(prop);
+ }
+ return props;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
index a72e052,93f2675..94b3ecf
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
@@@ -34,9 -34,8 +34,9 @@@ import org.apache.stratos.autoscaler.ut
import org.apache.stratos.autoscaler.util.Serializer;
import org.apache.stratos.autoscaler.util.ServiceReferenceHolder;
import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition;
- import org.apache.stratos.messaging.domain.applications.Application;
- import org.apache.stratos.messaging.domain.applications.Applications;
+import org.apache.stratos.common.kubernetes.KubernetesGroup;
+ import org.apache.stratos.messaging.domain.applications.Application;
+ import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.Resource;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
@@@ -67,21 -82,6 +83,7 @@@ public class RegistryManager
return registryManager;
}
- private RegistryManager() {
- try {
- if (!registryService.resourceExists(AutoScalerConstants.AUTOSCALER_RESOURCE)) {
- registryService.put(AutoScalerConstants.AUTOSCALER_RESOURCE,
- registryService.newCollection());
- }
- } catch (RegistryException e) {
- String msg =
- "Failed to create the registry resource " +
- AutoScalerConstants.AUTOSCALER_RESOURCE;
- log.error(msg, e);
- throw new AutoScalerException(msg, e);
- }
- }
+
/**
* Persist an object in the local registry.
*
@@@ -146,15 -150,24 +152,23 @@@
}
+ public void persistApplication(Application application) {
- public void persistApplication (Application application) {
-
- String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.APPLICATIONS_RESOURCE +
- "/" + application.getUniqueIdentifier();
- persist(application, resourcePath);
- if(log.isDebugEnabled()) {
- log.debug("Application [ " + application.getUniqueIdentifier() +
- " ] persisted successfully in the Autoscaler Registry");
+ try {
+ PrivilegedCarbonContext.startTenantFlow();
+ PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
+ carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
+ carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
+
+ String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.APPLICATIONS_RESOURCE +
+ "/" + application.getUniqueIdentifier();
+ persist(application, resourcePath);
+ if (log.isDebugEnabled()) {
+ log.debug("Application [ " + application.getUniqueIdentifier() +
+ " ] persisted successfully in the Autoscaler Registry");
+ }
-
+ } finally {
+ PrivilegedCarbonContext.endTenantFlow();
}
}
@@@ -397,34 -457,35 +460,37 @@@
return group;
}
- public void removeAutoscalerPolicy(AutoscalePolicy autoscalePolicy) {
- String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.AS_POLICY_RESOURCE + "/" + autoscalePolicy.getId();
- this.delete(resourcePath);
- if(log.isDebugEnabled()) {
- log.debug(String.format("Autoscaler policy deleted from registry: [id] %s [name] %s [description] %s",
- autoscalePolicy.getId(), autoscalePolicy.getDisplayName(), autoscalePolicy.getDescription()));
- }
-
- }
-
- public void removeDeploymentPolicy(DeploymentPolicy depPolicy){
- String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.DEPLOYMENT_POLICY_RESOURCE;
- this.delete(resourcePath);
- if(log.isDebugEnabled()) {
- log.debug(String.format("Deployment policy deleted from registry: [id] %s" ,
- depPolicy.getId()));
- }
- }
-
- public void removeNetworkPartition(String networkPartition){
- String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.NETWORK_PARTITION_LB_HOLDER_RESOURCE;
- this.delete(resourcePath);
- if(log.isDebugEnabled()) {
- log.debug(String.format("Network partition deleted from registry: [id] %s" ,
- networkPartition));
- }
- }
++
+ public void removeAutoscalerPolicy(AutoscalePolicy autoscalePolicy) {
+ String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.AS_POLICY_RESOURCE + "/" + autoscalePolicy.getId();
+ this.delete(resourcePath);
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Autoscaler policy deleted from registry: [id] %s [name] %s [description] %s",
+ autoscalePolicy.getId(), autoscalePolicy.getDisplayName(), autoscalePolicy.getDescription()));
+ }
+
+ }
+
- public void removeDeploymentPolicy(DeploymentPolicy depPolicy) {
- String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.DEPLOYMENT_POLICY_RESOURCE;
- this.delete(resourcePath);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Deployment policy deleted from registry: [id] %s",
- depPolicy.getId()));
- }
- }
+
+ public void removeNetworkPartition(String networkPartition) {
+ String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.NETWORK_PARTITION_LB_HOLDER_RESOURCE;
+ this.delete(resourcePath);
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Network partition deleted from registry: [id] %s",
+ networkPartition));
+ }
+ }
+
+
++ public void removeDeploymentPolicy(DeploymentPolicy depPolicy) {
++ String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.DEPLOYMENT_POLICY_RESOURCE;
++ this.delete(resourcePath);
++ if (log.isDebugEnabled()) {
++ log.debug(String.format("Deployment policy deleted from registry: [id] %s",
++ depPolicy.getId()));
++ }
++ }
+
private void delete(String resourcePath) {
try {
registryService.beginTransaction();
@@@ -443,52 -504,4 +509,53 @@@
}
}
+
+ public void persistKubernetesGroup(KubernetesGroup kubernetesGroup) {
+ String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.KUBERNETES_RESOURCE
+ + "/" + kubernetesGroup.getGroupId();
+ persist(kubernetesGroup, resourcePath);
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("KubernetesGroup written to registry: [id] %s ", kubernetesGroup.getGroupId()));
+ }
+ }
+
+ public List<KubernetesGroup> retrieveKubernetesGroups() {
+ List<KubernetesGroup> kubernetesGroupList = new ArrayList<KubernetesGroup>();
+ RegistryManager registryManager = RegistryManager.getInstance();
+ String[] kubernetesGroupResourceList = (String[]) registryManager.retrieve(AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.KUBERNETES_RESOURCE);
+
+ if (kubernetesGroupResourceList != null) {
+ KubernetesGroup kubernetesGroup;
+ for (String resourcePath : kubernetesGroupResourceList) {
+ Object serializedObj = registryManager.retrieve(resourcePath);
+ if (serializedObj != null) {
+ try {
+ Object dataObj = Deserializer.deserializeFromByteArray((byte[]) serializedObj);
+ if (dataObj instanceof KubernetesGroup) {
+ kubernetesGroup = (KubernetesGroup) dataObj;
+ if (log.isDebugEnabled()) {
+ log.debug(kubernetesGroup.toString());
+ }
+ kubernetesGroupList.add(kubernetesGroup);
+ } else {
+ return null;
+ }
+ } catch (Exception e) {
+ String msg = "Unable to retrieve data from Registry. Hence, any historical Kubernetes groups deployments will not get reflected.";
+ log.warn(msg, e);
+ }
+ }
+ }
+ }
+ return kubernetesGroupList;
+ }
+
+ public void removeKubernetesGroup(KubernetesGroup kubernetesGroup) {
+ String resourcePath = AutoScalerConstants.AUTOSCALER_RESOURCE + AutoScalerConstants.KUBERNETES_RESOURCE + "/" + kubernetesGroup.getGroupId();
+ this.delete(resourcePath);
+ if (log.isDebugEnabled()) {
+ log.debug(String.format("Kubernetes group deleted from registry: [id] %s", kubernetesGroup.getGroupId()));
+ }
+ }
++
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
index 1b9d44d,87e4d67..ea73f04
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/status/checker/StatusChecker.java
@@@ -25,21 -23,19 +23,19 @@@ import org.apache.commons.logging.LogFa
import org.apache.stratos.autoscaler.AutoscalerContext;
import org.apache.stratos.autoscaler.NetworkPartitionContext;
import org.apache.stratos.autoscaler.PartitionContext;
+ import org.apache.stratos.autoscaler.applications.ApplicationHolder;
import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
import org.apache.stratos.autoscaler.grouping.topic.ClusterStatusEventPublisher;
-import org.apache.stratos.autoscaler.monitor.AbstractClusterMonitor;
-import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.cluster.VMClusterMonitor;
- import org.apache.stratos.messaging.domain.applications.Application;
- import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
- import org.apache.stratos.messaging.domain.applications.ClusterDataHolder;
- import org.apache.stratos.messaging.domain.applications.Group;
- import org.apache.stratos.messaging.domain.applications.GroupStatus;
- import org.apache.stratos.messaging.domain.applications.ParentComponent;
+ import org.apache.stratos.messaging.domain.applications.*;
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.applications.ApplicationManager;
import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+ import java.util.Map;
+
++
/**
* This will be used to evaluate the status of a group
* and notify the interested parties about the status changes.
@@@ -210,7 -206,7 +206,7 @@@ public class StatusChecker
groupThread.start();
}
- private boolean getClusterInActive(VMClusterMonitor monitor, String partitionId) {
- private boolean getClusterInActive(AbstractClusterMonitor monitor, String partitionId) {
++ private boolean getClusterInActive(VMClusterMonitor monitor, String partitionId) {
boolean clusterInActive = false;
for (NetworkPartitionContext networkPartitionContext : monitor.getNetworkPartitionCtxts().values()) {
for (PartitionContext partition : networkPartitionContext.getPartitionCtxts().values()) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
index b38cf85,e212873a..d43cc8c
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/impl/CloudControllerServiceImpl.java
@@@ -41,20 -36,11 +41,22 @@@ import org.apache.stratos.cloud.control
import org.apache.stratos.cloud.controller.registry.RegistryManager;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.stratos.cloud.controller.topology.TopologyBuilder;
+import org.apache.stratos.cloud.controller.topology.TopologyManager;
import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
+import org.apache.stratos.cloud.controller.util.PodActivationWatcher;
import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
+import org.apache.stratos.common.Property;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.kubernetes.client.KubernetesApiClient;
+import org.apache.stratos.kubernetes.client.exceptions.KubernetesClientException;
+import org.apache.stratos.kubernetes.client.model.Label;
+import org.apache.stratos.kubernetes.client.model.Pod;
+import org.apache.stratos.kubernetes.client.model.ReplicationController;
+import org.apache.stratos.kubernetes.client.model.Service;
+import org.apache.stratos.messaging.domain.topology.Member;
+ import org.apache.stratos.messaging.domain.topology.Cluster;
+ import org.apache.stratos.messaging.domain.topology.ClusterStatus;
import org.apache.stratos.messaging.domain.topology.MemberStatus;
import org.apache.stratos.messaging.util.Constants;
import org.jclouds.compute.ComputeService;
@@@ -1428,473 -1390,61 +1430,531 @@@ public class CloudControllerServiceImp
}
@Override
+ public MemberContext[] startContainers(ContainerClusterContext containerClusterContext)
+ throws UnregisteredCartridgeException {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("CloudControllerServiceImpl:startContainers");
+ }
+
+ handleNullObject(containerClusterContext, "Container start-up failed. ContainerClusterContext is null.");
+
+ String clusterId = containerClusterContext.getClusterId();
+ handleNullObject(clusterId, "Container start-up failed. Cluster id is null.");
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Received a container spawn request : " + containerClusterContext.toString());
+ }
+
+ ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
+ handleNullObject(ctxt, "Container start-up failed. Invalid cluster id. " + containerClusterContext.toString());
+
+ String cartridgeType = ctxt.getCartridgeType();
+
+ Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+
+ if (cartridge == null) {
+ String msg =
+ "Instance start-up failed. No matching Cartridge found [type] "+cartridgeType +". "+
+ containerClusterContext.toString();
+ LOG.error(msg);
+ throw new UnregisteredCartridgeException(msg);
+ }
+
+ try {
+ String minReplicas = validateProperty(StratosConstants.KUBERNETES_MIN_REPLICAS, ctxt);
+ String kubernetesClusterId = validateProperty(StratosConstants.KUBERNETES_CLUSTER_ID, ctxt);
+ String kubernetesMasterIp = validateProperty(StratosConstants.KUBERNETES_MASTER_IP, containerClusterContext);
+ String kubernetesPortRange = validateProperty(StratosConstants.KUBERNETES_PORT_RANGE, containerClusterContext);
+
+ KubernetesClusterContext kubClusterContext = getKubernetesClusterContext(kubernetesClusterId, kubernetesMasterIp, kubernetesPortRange);
+
+ KubernetesApiClient kubApi = kubClusterContext.getKubApi();
+
+ // first let's create a replication controller.
+ ContainerClusterContextToReplicationController controllerFunction = new ContainerClusterContextToReplicationController();
+ ReplicationController controller = controllerFunction.apply(containerClusterContext);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller is delegating request to start a replication controller "+controller+
+ " for "+ containerClusterContext + " to Kubernetes layer.");
+ }
+
+ kubApi.createReplicationController(controller);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller successfully started the controller "
+ + controller + " via Kubernetes layer.");
+ }
+
+ // secondly let's create a kubernetes service proxy to load balance these containers
+ ContainerClusterContextToKubernetesService serviceFunction = new ContainerClusterContextToKubernetesService();
+ Service service = serviceFunction.apply(containerClusterContext);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller is delegating request to start a service "+service+
+ " for "+ containerClusterContext + " to Kubernetes layer.");
+ }
+
+ kubApi.createService(service);
+
+ // set host port and update
+ ctxt.addProperty(StratosConstants.ALLOCATED_SERVICE_HOST_PORT, service.getPort());
+ dataHolder.addClusterContext(ctxt);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller successfully started the service "
+ + controller + " via Kubernetes layer.");
+ }
+
+ // create a label query
+ Label l = new Label();
+ l.setName(clusterId);
+ // execute the label query
+ Pod[] newlyCreatedPods = new Pod[0];
+ int expectedCount = Integer.parseInt(minReplicas);
+
+ for (int i = 0; i < expectedCount ; i++) {
+ newlyCreatedPods = kubApi.getSelectedPods(new Label[]{l});
+
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug("Pods Count: "+newlyCreatedPods.length+" for cluster: "+clusterId);
+ }
+ if(newlyCreatedPods.length == expectedCount) {
+ break;
+ }
+ Thread.sleep(10000);
+ }
+
+ if (newlyCreatedPods.length == 0) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(String.format("Pods are not created for cluster : %s, hence deleting the service", clusterId));
+ }
+ terminateAllContainers(clusterId);
+ return new MemberContext[0];
+ }
+
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug(String.format("Pods created : %s for cluster : %s",newlyCreatedPods.length, clusterId));
+ }
+
+ List<MemberContext> memberContexts = new ArrayList<MemberContext>();
+
+ PodToMemberContext podToMemberContextFunc = new PodToMemberContext();
+ // generate Member Contexts
+ for (Pod pod : newlyCreatedPods) {
+ MemberContext context = podToMemberContextFunc.apply(pod);
+ context.setCartridgeType(cartridgeType);
+ context.setClusterId(clusterId);
+
+ context.setProperties(CloudControllerUtil.addProperty(context
+ .getProperties(), StratosConstants.ALLOCATED_SERVICE_HOST_PORT,
+ String.valueOf(service.getPort())));
+
+ dataHolder.addMemberContext(context);
+
+ // wait till Pod status turns to running and send member spawned.
+ ScheduledThreadExecutor exec = ScheduledThreadExecutor.getInstance();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller is starting the instance start up thread.");
+ }
+ dataHolder.addScheduledFutureJob(context.getMemberId(), exec.schedule(new PodActivationWatcher(pod.getId(), context, kubApi), 5000));
+
+ memberContexts.add(context);
+ }
+
+ // persist in registry
+ persist();
+
+ LOG.info("Kubernetes entities are successfully starting up: " + memberContexts);
+
+ return memberContexts.toArray(new MemberContext[0]);
+
+ } catch (Exception e) {
+ String msg = "Failed to start an instance. " + containerClusterContext.toString()+" Cause: "+e.getMessage();
+ LOG.error(msg, e);
+ throw new IllegalStateException(msg, e);
+ }
+ }
+
+ private String validateProperty(String property, ClusterContext ctxt) {
+
+ String propVal = CloudControllerUtil.getProperty(ctxt.getProperties(), property);
+ handleNullObject(propVal, "Property validation failed. Cannot find '"+property+"' in " + ctxt);
+ return propVal;
+ }
+
+ private String validateProperty(String property, ContainerClusterContext ctxt) {
+
+ String propVal = CloudControllerUtil.getProperty(ctxt.getProperties(), property);
+ handleNullObject(propVal, "Property validation failed. '"+property+"' in " + ctxt);
+ return propVal;
+
+ }
+
+ private KubernetesClusterContext getKubernetesClusterContext(
+ String kubernetesClusterId, String kubernetesMasterIp,
+ String kubernetesPortRange) {
+
+ KubernetesClusterContext origCtxt = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
+ KubernetesClusterContext newCtxt = new KubernetesClusterContext(kubernetesClusterId, kubernetesPortRange, kubernetesMasterIp);
+
+ if (origCtxt == null) {
+ dataHolder.addKubernetesClusterContext(newCtxt);
+ return newCtxt;
+ }
+
+ if (!origCtxt.equals(newCtxt)) {
+ // if for some reason master IP etc. have changed
+ newCtxt.setAvailableHostPorts(origCtxt.getAvailableHostPorts());
+ dataHolder.addKubernetesClusterContext(newCtxt);
+ return newCtxt;
+ } else {
+ return origCtxt;
+ }
+ }
+
+ @Override
+ public MemberContext[] terminateAllContainers(String clusterId)
+ throws InvalidClusterException {
+
+ ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
+ handleNullObject(ctxt, "Kubernetes units temrination failed. Invalid cluster id. "+clusterId);
+
+ String kubernetesClusterId = CloudControllerUtil.getProperty(ctxt.getProperties(),
+ StratosConstants.KUBERNETES_CLUSTER_ID);
+ handleNullObject(kubernetesClusterId, "Kubernetes units termination failed. Cannot find '"+
+ StratosConstants.KUBERNETES_CLUSTER_ID+"'. " + ctxt);
+
+ KubernetesClusterContext kubClusterContext = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
+ handleNullObject(kubClusterContext, "Kubernetes units termination failed. Cannot find a matching Kubernetes Cluster for cluster id: "
+ +kubernetesClusterId);
+
+ KubernetesApiClient kubApi = kubClusterContext.getKubApi();
+ // delete the service
+ try {
+ kubApi.deleteService(CloudControllerUtil.getCompatibleId(clusterId));
+ } catch (KubernetesClientException e) {
+ // we're not going to throw this error, but proceed with other deletions
+ LOG.error("Failed to delete Kubernetes service with id: "+clusterId, e);
+ }
+
+ // set replicas=0 for the replication controller
+ try {
+ kubApi.updateReplicationController(clusterId, 0);
+ } catch (KubernetesClientException e) {
+ // we're not going to throw this error, but proceed with other deletions
+ LOG.error("Failed to update Kubernetes Controller with id: "+clusterId, e);
+ }
+
+ // delete pods forcefully
+ try {
+ // create a label query
+ Label l = new Label();
+ l.setName(clusterId);
+ // execute the label query
+ Pod[] pods = kubApi.getSelectedPods(new Label[]{l});
+
+ for (Pod pod : pods) {
+ try {
+ // delete pods forcefully
+ kubApi.deletePod(pod.getId());
+ } catch (KubernetesClientException ignore) {
+ // we can't do nothing here
+ LOG.warn(String.format("Failed to delete Pod [%s] forcefully!", pod.getId()));
+ }
+ }
+ } catch (KubernetesClientException e) {
+ // we're not going to throw this error, but proceed with other deletions
+ LOG.error("Failed to delete pods forcefully for cluster: "+clusterId, e);
+ }
+
+ // delete the replication controller.
+ try {
+ kubApi.deleteReplicationController(clusterId);
+ } catch (KubernetesClientException e) {
+ String msg = "Failed to delete Kubernetes Controller with id: "+clusterId;
+ LOG.error(msg, e);
+ throw new InvalidClusterException(msg, e);
+ }
+
+ String allocatedPort = CloudControllerUtil.getProperty(ctxt.getProperties(),
+ StratosConstants.ALLOCATED_SERVICE_HOST_PORT);
+
+ if (allocatedPort != null) {
+ kubClusterContext.deallocateHostPort(Integer
+ .parseInt(allocatedPort));
+ } else {
+ LOG.warn("Host port dealloacation failed due to a missing property: "
+ + StratosConstants.ALLOCATED_SERVICE_HOST_PORT);
+ }
+
+ List<MemberContext> membersToBeRemoved = dataHolder.getMemberContextsOfClusterId(clusterId);
+
+ for (MemberContext memberContext : membersToBeRemoved) {
+ logTermination(memberContext);
+ }
+
+ // persist
+ persist();
+
+ return membersToBeRemoved.toArray(new MemberContext[0]);
+ }
+
+ @Override
+ public MemberContext[] updateContainers(String clusterId, int replicas)
+ throws UnregisteredCartridgeException {
+
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("CloudControllerServiceImpl:updateContainers for cluster : "+clusterId);
+ }
+
+ ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
+ handleNullObject(ctxt, "Container update failed. Invalid cluster id. " + clusterId);
+
+ String cartridgeType = ctxt.getCartridgeType();
+
+ Cartridge cartridge = dataHolder.getCartridge(cartridgeType);
+
+ if (cartridge == null) {
+ String msg =
+ "Container update failed. No matching Cartridge found [type] "+cartridgeType
+ +". [cluster id] "+ clusterId;
+ LOG.error(msg);
+ throw new UnregisteredCartridgeException(msg);
+ }
+
+ try {
+ String kubernetesClusterId = validateProperty(StratosConstants.KUBERNETES_CLUSTER_ID, ctxt);
+
+ KubernetesClusterContext kubClusterContext = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
+
+ if (kubClusterContext == null) {
+ String msg =
+ "Instance start-up failed. No matching Kubernetes Context Found for [id] "+kubernetesClusterId
+ +". [cluster id] "+ clusterId;
+ LOG.error(msg);
+ throw new UnregisteredCartridgeException(msg);
+ }
+
+ KubernetesApiClient kubApi = kubClusterContext.getKubApi();
+ // create a label query
+ Label l = new Label();
+ l.setName(clusterId);
+
+ // get the current pods - useful when scale down
+ Pod[] previousStatePods = kubApi.getSelectedPods(new Label[]{l});
+
+ // update the replication controller - cluster id = replication controller id
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller is delegating request to update a replication controller "+clusterId+
+ " to Kubernetes layer.");
+ }
+
+ kubApi.updateReplicationController(clusterId, replicas);
+
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller successfully updated the controller "
+ + clusterId + " via Kubernetes layer.");
+ }
+
+ // execute the label query
+ Pod[] allPods = new Pod[0];
+
+ // wait replicas*5s time in the worst case ; best case = 0s
+ for (int i = 0; i < (replicas*previousStatePods.length+1) ; i++) {
+ allPods = kubApi.getSelectedPods(new Label[]{l});
+
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug("Pods Count: "+allPods.length+" for cluster: "+clusterId);
+ }
+ if(allPods.length == replicas) {
+ break;
+ }
+ Thread.sleep(10000);
+ }
+
+ if (LOG.isDebugEnabled()) {
+
+ LOG.debug(String.format("Pods created : %s for cluster : %s",allPods.length, clusterId));
+ }
+
+ List<MemberContext> memberContexts = new ArrayList<MemberContext>();
+
+ PodToMemberContext podToMemberContextFunc = new PodToMemberContext();
+ // generate Member Contexts
+ for (Pod pod : allPods) {
+ MemberContext context;
+ // if member context does not exist -> a new member (scale up)
+ if ((context = dataHolder.getMemberContextOfMemberId(pod.getId())) == null) {
+
+ context = podToMemberContextFunc.apply(pod);
+ context.setCartridgeType(cartridgeType);
+ context.setClusterId(clusterId);
+
+ context.setProperties(CloudControllerUtil.addProperty(context
+ .getProperties(), StratosConstants.ALLOCATED_SERVICE_HOST_PORT,
+ CloudControllerUtil.getProperty(ctxt.getProperties(),
+ StratosConstants.ALLOCATED_SERVICE_HOST_PORT)));
+
+ // wait till Pod status turns to running and send member spawned.
+ ScheduledThreadExecutor exec = ScheduledThreadExecutor.getInstance();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Cloud Controller is starting the instance start up thread.");
+ }
+ dataHolder.addScheduledFutureJob(context.getMemberId(), exec.schedule(new PodActivationWatcher(pod.getId(), context, kubApi), 5000));
+
+ memberContexts.add(context);
+
+ }
+ // publish data
+ // TODO
+// CartridgeInstanceDataPublisher.publish(context.getMemberId(), null, null, context.getClusterId(), cartridgeType, MemberStatus.Created.toString(), node);
+
+ }
+
+ if (memberContexts.isEmpty()) {
+ // terminated members
+ @SuppressWarnings("unchecked")
+ List<Pod> difference = ListUtils.subtract(Arrays.asList(previousStatePods), Arrays.asList(allPods));
+ for (Pod pod : difference) {
+ if (pod != null) {
+ MemberContext context = dataHolder.getMemberContextOfMemberId(pod.getId());
+ logTermination(context);
+ memberContexts.add(context);
+ }
+ }
+ }
+
+
+ // persist in registry
+ persist();
+
+ LOG.info("Kubernetes entities are successfully starting up. "+memberContexts);
+
+ return memberContexts.toArray(new MemberContext[0]);
+
+ } catch (Exception e) {
+ String msg = "Failed to update containers belong to cluster " + clusterId+". Cause: "+e.getMessage();
+ LOG.error(msg, e);
+ throw new IllegalStateException(msg, e);
+ }
+ }
+
+ @Override
+ public MemberContext terminateContainer(String memberId) throws MemberTerminationFailedException {
+
+ handleNullObject(memberId, "Failed to terminate member. Invalid Member id. [Member id] " + memberId);
+
+ MemberContext memberContext = dataHolder.getMemberContextOfMemberId(memberId);
+
+ handleNullObject(memberContext, "Failed to terminate member. Member id not found. [Member id] " + memberId);
+
+ String clusterId = memberContext.getClusterId();
+
+ handleNullObject(clusterId, "Failed to terminate member. Cluster id is null. [Member id] " + memberId);
+
+ ClusterContext ctxt = dataHolder.getClusterContext(clusterId);
+
+ handleNullObject(ctxt,
+ String.format("Failed to terminate member [Member id] %s. Invalid cluster id %s ", memberId, clusterId));
+
+ String kubernetesClusterId = CloudControllerUtil.getProperty(ctxt.getProperties(),
+ StratosConstants.KUBERNETES_CLUSTER_ID);
+
+ handleNullObject(kubernetesClusterId, String.format("Failed to terminate member [Member id] %s. Cannot find '"+
+ StratosConstants.KUBERNETES_CLUSTER_ID+"' in [cluster context] %s ", memberId, ctxt));
+
+ KubernetesClusterContext kubClusterContext = dataHolder.getKubernetesClusterContext(kubernetesClusterId);
+
+ handleNullObject(kubClusterContext, String.format("Failed to terminate member [Member id] %s. Cannot find a matching Kubernetes Cluster in [cluster context] %s ", memberId, ctxt));
+
+ KubernetesApiClient kubApi = kubClusterContext.getKubApi();
+ // delete the Pod
+ try {
+ // member id = pod id
+ kubApi.deletePod(memberId);
+
+ MemberContext memberToBeRemoved = dataHolder.getMemberContextOfMemberId(memberId);
+
+ logTermination(memberToBeRemoved);
+
+ return memberToBeRemoved;
+
+ } catch (KubernetesClientException e) {
+ String msg = String.format("Failed to terminate member [Member id] %s", memberId);
+ LOG.error(msg, e);
+ throw new MemberTerminationFailedException(msg, e);
+ }
+ }
+
+ private void handleNullObject(Object obj, String errorMsg) {
+ if (obj == null) {
+ LOG.error(errorMsg);
+ throw new IllegalArgumentException(errorMsg);
+ }
+ }
+
+ public void createApplicationClusters(String appId, ApplicationClusterContextDTO[] appClustersContexts) throws
+ ApplicationClusterRegistrationException {
+
+ // Create a Cluster Context obj. for each of the Clusters in the Application
+ if (appClustersContexts == null || appClustersContexts.length == 0) {
+ String errorMsg = "No application cluster information found, unable to create clusters" ;
+ log.error(errorMsg);
+ throw new ApplicationClusterRegistrationException(errorMsg);
+ }
+
+ List<Cluster> clusters = new ArrayList<Cluster>();
+
+ for (ApplicationClusterContextDTO appClusterCtxt : appClustersContexts) {
+ // add the context data
+ dataHolder.addClusterContext(new ClusterContext(appClusterCtxt.getClusterId(),
+ appClusterCtxt.getCartridgeType(), appClusterCtxt.getTextPayload(),
- appClusterCtxt.getHostName(), appClusterCtxt.isLbCluster()));
++ appClusterCtxt.getHostName(), appClusterCtxt.isLbCluster(), appClusterCtxt.getProperties()));
+ // create Cluster objects
+ Cluster newCluster = new Cluster(appClusterCtxt.getCartridgeType(), appClusterCtxt.getClusterId(),
+ appClusterCtxt.getDeploymentPolicyName(), appClusterCtxt.getAutoscalePolicyName(), appId);
+ newCluster.setLbCluster(false);
+ newCluster.setTenantRange("*");
+ newCluster.setStatus(ClusterStatus.Created);
+ newCluster.setHostNames(Arrays.asList(appClusterCtxt.getHostName()));
++ newCluster.setProperties(appClusterCtxt.getProperties());
+ clusters.add(newCluster);
+ }
+
+ TopologyBuilder.handleApplicationClustersCreated(appId, clusters);
+
+ persist();
+ }
+
+ // public void deployApplicationDefinition (ApplicationContext applicationContext) throws ApplicationDefinitionException {
+ //
+ // ApplicationParser applicationParser = new DefaultApplicationParser();
+ // Application application = applicationParser.parse(applicationContext);
+ //
+ // // Create a Cluster Context obj. for each of the Clusters in the Application
+ // for (ApplicationClusterContext applicationClusterContext : applicationParser.getApplicationClusterContexts()) {
+ // dataHolder.addClusterContext(new ClusterContext(applicationClusterContext.getClusterId(),
+ // applicationClusterContext.getCartridgeType(), applicationClusterContext.getTextPayload(),
+ // applicationClusterContext.getHostName(), applicationClusterContext.isLbCluster()));
+ // }
+ //
+ // /*TopologyBuilder.handleApplicationDeployed(application, applicationParser.getApplicationClusterContexts(),
+ // applicationParser.getPayloadData());
+ //*/
+ // persist();
+ // }
+ //
+ // @Override
+ // public void unDeployApplicationDefinition(String applicationId, int tenantId, String tenantDomain) throws ApplicationDefinitionException {
+ //
+ // //TopologyBuilder.handleApplicationUndeployed(applicationId);
+ // }
++>>>>>>> 4.0.0-grouping
+
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/interfaces/CloudControllerService.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ApplicationClusterContextDTO.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ApplicationClusterContextDTO.java
index 0000000,ad15d4c..1d4dda0
mode 000000,100644..100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ApplicationClusterContextDTO.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ApplicationClusterContextDTO.java
@@@ -1,0 -1,128 +1,140 @@@
+ /*
+ * 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.cloud.controller.pojo;
+
++import java.util.Properties;
++
+ public class ApplicationClusterContextDTO {
+
+ // cluster id
+ private String clusterId;
+ // cartridge type
+ private String cartridgeType;
+ // payload as a String
+ private String textPayload;
+ // host name
+ private String hostName;
+ // flag to indicate LB cluster
+ private boolean isLbCluster;
+ // autoscaling policy
+ private String autoscalePolicyName;
+ // deployment policy
+ private String deploymentPolicyName;
+ // tenant rance
+ private String tenantRange;
++ // propertis
++ private Properties properties;
++
+
+ public ApplicationClusterContextDTO () {
+ }
+
+ public String getClusterId() {
+ return clusterId;
+ }
+
+ public void setClusterId(String clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ public String getCartridgeType() {
+ return cartridgeType;
+ }
+
+ public void setCartridgeType(String cartridgeType) {
+ this.cartridgeType = cartridgeType;
+ }
+
+ public String getTextPayload() {
+ return textPayload;
+ }
+
+ public void setTextPayload(String textPayload) {
+ this.textPayload = textPayload;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ public boolean isLbCluster() {
+ return isLbCluster;
+ }
+
+ public void setLbCluster(boolean lbCluster) {
+ isLbCluster = lbCluster;
+ }
+
+ public String getAutoscalePolicyName() {
+ return autoscalePolicyName;
+ }
+
+ public void setAutoscalePolicyName(String autoscalePolicyName) {
+ this.autoscalePolicyName = autoscalePolicyName;
+ }
+
+ public String getDeploymentPolicyName() {
+ return deploymentPolicyName;
+ }
+
+ public void setDeploymentPolicyName(String deploymentPolicyName) {
+ this.deploymentPolicyName = deploymentPolicyName;
+ }
+
+ public String getTenantRange() {
+ return tenantRange;
+ }
+
+ public void setTenantRange(String tenantRange) {
+ this.tenantRange = tenantRange;
+ }
+
+ public boolean equals(Object other) {
+
+ if(other == null || !(other instanceof ApplicationClusterContextDTO)) {
+ return false;
+ }
+
+ if(this == other) {
+ return true;
+ }
+
+ ApplicationClusterContextDTO that = (ApplicationClusterContextDTO)other;
+
+ return this.cartridgeType.equals(that.cartridgeType) &&
+ this.clusterId.equals(that.clusterId);
+ }
+
+ public int hashCode () {
+ return this.cartridgeType.hashCode() + this.clusterId.hashCode();
+ }
+
++ public Properties getProperties() {
++ return properties;
++ }
++
++ public void setProperties(Properties properties) {
++ this.properties = properties;
++ }
+ }
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventPublisher.java
index c813eef,b855b7f..df5cf82
--- 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
@@@ -348,10 -345,4 +357,10 @@@ public class TopologyEventPublisher
publishEvent(clusterTerminatedEvent);
}
+
+ public static void publishEvent(Event event) {
+ String topic = Util.getMessageTopicName(event);
+ EventPublisher eventPublisher = EventPublisherPool.getPublisher(topic);
+ eventPublisher.publish(event);
+ }
- }
+ }
http://git-wip-us.apache.org/repos/asf/stratos/blob/85fd5ebd/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
index 7fdd6a4,ea1658f..3a7f176
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/util/Constants.java
@@@ -20,63 -20,62 +20,64 @@@ package org.apache.stratos.messaging.ut
public class Constants {
/* Message broker topic names */
- public static final String TOPOLOGY_TOPIC = "topology";
+ public static final String TOPOLOGY_TOPIC = "topology/#";
public static final String HEALTH_STAT_TOPIC = "summarized-health-stats";
- public static final String INSTANCE_STATUS_TOPIC = "instance-status";
- public static final String INSTANCE_NOTIFIER_TOPIC = "instance-notifier";
+ public static final String INSTANCE_STATUS_TOPIC = "instance/status/#";
+ public static final String INSTANCE_NOTIFIER_TOPIC = "instance/notifier/#";
+ public static final String APPLICATION_STATUS_TOPIC = "application-status";
public static final String APPLICATIONS_TOPIC = "applications";
- public static final String CLUSTER_STATUS_TOPIC = "applications";
+ public static final String CLUSTER_STATUS_TOPIC = "cluster-status";
+
public static final String PING_TOPIC = "ping";
- public static final String TENANT_TOPIC = "tenant";
- public static final String TENANT_RANGE_ALL = "*";
+ public static final String TENANT_TOPIC = "tenant/#";
+ public static final String TENANT_RANGE_ALL = "*";
- public static final String TENANT_RANGE_DELIMITER = "-";
- public static final String EVENT_CLASS_NAME = "event-class-name";
+ public static final String TENANT_RANGE_DELIMITER = "-";
+ public static final String EVENT_CLASS_NAME = "event-class-name";
- /* Topology filter constants */
- public static final String FILTER_VALUE_ASSIGN_OPERATOR="=";
- public static final String FILTER_KEY_VALUE_PAIR_SEPARATOR = "|";
- public static final String FILTER_VALUE_SEPARATOR = ",";
+ /* Topology filter constants */
+ public static final String FILTER_VALUE_ASSIGN_OPERATOR = "=";
+ public static final String FILTER_KEY_VALUE_PAIR_SEPARATOR = "|";
+ public static final String FILTER_VALUE_SEPARATOR = ",";
- public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
- public static final String TOPOLOGY_SERVICE_FILTER_SERVICE_NAME = "service-name";
+ public static final String TOPOLOGY_SERVICE_FILTER = "stratos.topology.service.filter";
+ public static final String TOPOLOGY_SERVICE_FILTER_SERVICE_NAME = "service-name";
- public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
- public static final String TOPOLOGY_CLUSTER_FILTER_CLUSTER_ID = "cluster-id";
+ public static final String TOPOLOGY_CLUSTER_FILTER = "stratos.topology.cluster.filter";
+ public static final String TOPOLOGY_CLUSTER_FILTER_CLUSTER_ID = "cluster-id";
- public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
- public static final String TOPOLOGY_MEMBER_FILTER_LB_CLUSTER_ID = "lb-cluster-id";
+ public static final String TOPOLOGY_MEMBER_FILTER = "stratos.topology.member.filter";
+ public static final String TOPOLOGY_MEMBER_FILTER_LB_CLUSTER_ID = "lb-cluster-id";
- public static final String REQUEST_BASE_CONTEXT = "org.wso2.carbon.context.RequestBaseContext";
-
- // to identify a lb cluster
- public static final String IS_LOAD_BALANCER = "load.balancer";
- public static final String LOAD_BALANCER_REF = "load.balancer.ref";
- public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
- public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
- public static final String NO_LOAD_BALANCER = "no.load.balancer";
- public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
- public static final String LOAD_BALANCED_SERVICE_TYPE = "load.balanced.service.type";
+ public static final String REQUEST_BASE_CONTEXT = "org.wso2.carbon.context.RequestBaseContext";
- // volume
- public static final String IS_VOLUME_REQUIRED = "volume.required";
- public static final String SHOULD_DELETE_VOLUME = "volume.delete.on.unsubscription";
- public static final String VOLUME_SIZE = "volume.size.gb";
- public static final String VOLUME_ID = "volume.id";
- public static final String DEVICE_NAME = "volume.device.name";
- public static final String GRACEFUL_SHUTDOWN_TIMEOUT = "graceful.shutdown.timeout";
+ // to identify a lb cluster
+ public static final String IS_LOAD_BALANCER = "load.balancer";
+ public static final String LOAD_BALANCER_REF = "load.balancer.ref";
+ public static final String SERVICE_AWARE_LOAD_BALANCER = "service.aware.load.balancer";
+ public static final String DEFAULT_LOAD_BALANCER = "default.load.balancer";
+ public static final String NO_LOAD_BALANCER = "no.load.balancer";
+ public static final String EXISTING_LOAD_BALANCERS = "existing.load.balancers";
+ public static final String LOAD_BALANCED_SERVICE_TYPE = "load.balanced.service.type";
- public static final String IS_PRIMARY = "PRIMARY";
+ // volume
+ public static final String IS_VOLUME_REQUIRED = "volume.required";
+ public static final String SHOULD_DELETE_VOLUME = "volume.delete.on.unsubscription";
+ public static final String VOLUME_SIZE = "volume.size.gb";
+ public static final String VOLUME_ID = "volume.id";
+ public static final String DEVICE_NAME = "volume.device.name";
+ public static final String GRACEFUL_SHUTDOWN_TIMEOUT = "graceful.shutdown.timeout";
- //System Properties
- public static final String AVERAGE_PING_INTERVAL_PROPERTY = "stratos.messaging.averagePingInterval";
- public static final String FAILOVER_PING_INTERVAL_PROPERTY = "stratos.messaging.failoverPingInterval";
+ public static final String IS_PRIMARY = "PRIMARY";
- //Default values
- public static final int DEFAULT_AVERAGE_PING_INTERVAL = 1000;
- public static final int DEFAULT_FAILOVER_PING_INTERVAL = 30000;
+ // System Properties
+ public static final String AVERAGE_PING_INTERVAL_PROPERTY =
+ "stratos.messaging.averagePingInterval";
+ public static final String FAILOVER_PING_INTERVAL_PROPERTY =
+ "stratos.messaging.failoverPingInterval";
+ // Default values
+ public static final int DEFAULT_AVERAGE_PING_INTERVAL = 1000;
+ public static final int DEFAULT_FAILOVER_PING_INTERVAL = 30000;
}