You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/10 18:51:55 UTC
[20/45] fixing component version issues and adding currently
refactored components to the parent pom
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/CartridgeAgentServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/CartridgeAgentServiceComponent.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/CartridgeAgentServiceComponent.java
new file mode 100644
index 0000000..b31cc7a
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/CartridgeAgentServiceComponent.java
@@ -0,0 +1,142 @@
+/**
+ * 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.cartridge.agent.internal;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cartridge.agent.ClusteringClient;
+import org.apache.stratos.cartridge.agent.ELBMembershipListener;
+import org.apache.stratos.cartridge.agent.registrant.RegistrantDatabase;
+import org.apache.stratos.cartridge.agent.registrant.RegistrantHealthChecker;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.utils.CarbonUtils;
+import org.wso2.carbon.utils.ConfigurationContextService;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * @scr.component name="org.wso2.carbon.cartridge.agent" immediate="true"
+ *
+ * @scr.reference name="config.context.service"
+ * interface="org.wso2.carbon.utils.ConfigurationContextService"
+ * cardinality="1..1" policy="dynamic"
+ * bind="setConfigurationContextService"
+ * unbind="unsetConfigurationContextService"
+ */
+public class CartridgeAgentServiceComponent {
+ private static final Log log = LogFactory.getLog(CartridgeAgentServiceComponent.class);
+
+ protected void activate(ComponentContext ctx) {
+ RegistrantHealthChecker healthChecker;
+ ConfigurationContext configurationContext = DataHolder.getServerConfigContext();
+
+ FileInputStream confFileIPStream = null;
+ try {
+ long start = System.currentTimeMillis();
+ log.info("Starting WSO2 Cartridge Agent...");
+ Properties conf = new Properties();
+ confFileIPStream = new FileInputStream(CarbonUtils.getCarbonConfigDirPath() +
+ File.separator + "agent.properties");
+ conf.load(confFileIPStream);
+ for (String name : conf.stringPropertyNames()) {
+ String value = conf.getProperty(name);
+ System.setProperty(name, value);
+ }
+
+ RegistrantDatabase registrantDatabase = new RegistrantDatabase();
+// AxisServer axisServer = new AxisServer();
+// ConfigurationContext configurationContext = axisServer.getConfigurationContext();
+ ClusteringClient clusteringClient = new ClusteringClient(registrantDatabase);
+ configurationContext.setProperty(CartridgeAgentConstants.CLUSTERING_CLIENT, clusteringClient);
+
+ String healthCheckInterval = conf.getProperty("registrant.heathCheckInterval");
+ String threadPoolSize = conf.getProperty("registrant.healthCheckThreadPoolSize");
+ int healthCheckIntervalInt =
+ (healthCheckInterval == null) ? 2000 : Integer.parseInt(healthCheckInterval);
+ int threadPoolSizeInt =
+ (threadPoolSize == null) ? 10 : Integer.parseInt(healthCheckInterval);
+ log.info("Registrant health check interval: " + healthCheckIntervalInt + "s");
+ healthChecker = new RegistrantHealthChecker(registrantDatabase,
+ clusteringClient,
+ configurationContext,
+ healthCheckIntervalInt,
+ threadPoolSizeInt
+ );
+ clusteringClient.init(conf,
+ configurationContext,
+ new ELBMembershipListener(clusteringClient,
+ configurationContext,
+ registrantDatabase,
+ healthChecker));
+ healthChecker.startAll();
+ DataHolder.setHealthChecker(healthChecker);
+ /*configurationContext.deployService(AxisService.createService(CartridgeAgentService.class.getName().toString(),
+ configurationContext.getAxisConfiguration()));*/
+// axisServer.deployService(CartridgeAgentService.class.getName());
+
+
+ // Starting cliet..
+// String trustStorePath = conf.getProperty("wso2.carbon.truststore");
+// System.setProperty("javax.net.ssl.trustStore", trustStorePath);
+// System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
+// // new InstanceStateNotificationClient().notify(null, null);
+//
+// System.setProperty("adc.host", conf.getProperty("adc.host"));
+// System.setProperty("adc.port", conf.getProperty("adc.port"));
+ // ----------------------
+
+ Runtime.getRuntime().addShutdownHook(new Thread(){
+
+ @Override
+ public void run() {
+ log.info("Shutting down WSO2 Cartridge Agent...");
+ }
+ });
+ log.info("Started Cartridge Agent in " + (System.currentTimeMillis() - start) + "ms");
+ } catch (Exception e) {
+ log.fatal("Could not start Cartridge Agent", e);
+ //System.exit(1);
+ } finally {
+ if (confFileIPStream != null) {
+ try {
+ confFileIPStream.close();
+ } catch (IOException e) {
+ log.error("Cannot close agent.properties file", e);
+ }
+ }
+ }
+
+ }
+
+ protected void deactivate(ComponentContext ctx) {
+ }
+
+ protected void setConfigurationContextService(ConfigurationContextService contextService) {
+ DataHolder.setServerConfigContext(contextService.getServerConfigContext());
+ }
+
+ protected void unsetConfigurationContextService(ConfigurationContextService contextService) {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/DataHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/DataHolder.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/DataHolder.java
new file mode 100644
index 0000000..955c931
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/internal/DataHolder.java
@@ -0,0 +1,45 @@
+/**
+ * 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.cartridge.agent.internal;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.stratos.cartridge.agent.registrant.RegistrantHealthChecker;
+
+public class DataHolder {
+ private static ConfigurationContext serverConfigContext;
+ private static RegistrantHealthChecker healthChecker;
+
+ public static void setServerConfigContext(ConfigurationContext serverConfigContext) {
+ DataHolder.serverConfigContext = serverConfigContext;
+ }
+
+ public static void setHealthChecker(RegistrantHealthChecker healthChecker) {
+ DataHolder.healthChecker = healthChecker;
+ }
+
+ public static ConfigurationContext getServerConfigContext() {
+ return serverConfigContext;
+ }
+
+ public static RegistrantHealthChecker getHealthChecker() {
+ return healthChecker;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/PortMapping.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/PortMapping.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/PortMapping.java
new file mode 100644
index 0000000..3d1bc8b
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/PortMapping.java
@@ -0,0 +1,90 @@
+/**
+ * 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.cartridge.agent.registrant;
+
+import java.io.Serializable;
+
+/**
+ * This class provides the mapping between the actual port & proxy port of a {@link org.apache.stratos.cartridge.agent.registrant.Registrant}
+ *
+ * e.g. if the Registrant is serving HTTP requests on port 9763, and the requests to that port have
+ * to be proxied via port 80 on the ELB, the <code>primaryPort</code> has to be specified as 9763
+ * & <code>proxyPort</code> has to be specified as 80.
+ *
+ * @see org.apache.stratos.cartridge.agent.registrant.Registrant
+ */
+@SuppressWarnings("unused")
+public class PortMapping implements Serializable {
+
+ private static final long serialVersionUID = 8020727939469156788L;
+ public static final String PORT_TYPE_HTTP = "http";
+ public static final String PORT_TYPE_HTTPS = "https";
+
+ private int primaryPort;
+ private int proxyPort;
+ private String type;
+
+ public PortMapping() {
+ }
+
+ public int getPrimaryPort() {
+ return primaryPort;
+ }
+
+ public int getProxyPort() {
+ return proxyPort;
+ }
+
+ public void setPrimaryPort(int primaryPort) {
+ this.primaryPort = primaryPort;
+ }
+
+ public void setProxyPort(int proxyPort) {
+ this.proxyPort = proxyPort;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ if (type.equalsIgnoreCase(PORT_TYPE_HTTP) && type.equalsIgnoreCase(PORT_TYPE_HTTPS)) {
+ throw new RuntimeException("Invalid port type " + type);
+ }
+ this.type = type;
+ }
+
+ public boolean equals (Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ PortMapping that = (PortMapping) o;
+ return (type.equalsIgnoreCase(that.type) &&
+ (primaryPort == that.primaryPort) &&
+ (proxyPort == that.proxyPort));
+ }
+
+ @Override
+ public int hashCode() {
+ return type.hashCode() +
+ Integer.toString(primaryPort).hashCode() +
+ Integer.toString(proxyPort).hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/Registrant.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/Registrant.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/Registrant.java
new file mode 100644
index 0000000..a6ed860
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/Registrant.java
@@ -0,0 +1,199 @@
+/**
+ * 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.cartridge.agent.registrant;
+
+import org.apache.axis2.clustering.ClusteringAgent;
+import org.apache.axis2.clustering.ClusteringFault;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ * This class represents a process which registers itself with this Cartridge Agent
+ */
+@SuppressWarnings("unused")
+public class Registrant implements Serializable {
+
+ private static final long serialVersionUID = 1026289225178520964L;
+
+ private String key;
+ //private int tenantId;
+ private String tenantRange;
+ private String service;
+ private String hostName;
+ private PortMapping[] portMappings;
+ private String remoteHost;
+ private transient ClusteringAgent clusteringAgent;
+ private int minInstanceCount;
+ private int maxInstanceCount;
+ private int maxRequestsPerSecond;
+ private int roundsToAverage;
+ private double alarmingUpperRate;
+ private double alarmingLowerRate;
+ private double scaleDownFactor;
+
+
+ public String getService() {
+ return service;
+ }
+
+ public String getTenantRange() {
+ return tenantRange;
+ }
+
+ public void setTenantRange(String tenantRange) {
+ this.tenantRange = tenantRange;
+ }
+
+ public void setService(String service) {
+ this.service = service;
+ }
+
+ public String getHostName() {
+ return hostName;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ public PortMapping[] getPortMappings() {
+ return Arrays.copyOf(portMappings, portMappings.length);
+ }
+
+ public void setPortMappings(PortMapping[] portMappings) {
+ this.portMappings = Arrays.copyOf(portMappings, portMappings.length);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public int getMinInstanceCount() {
+ return minInstanceCount;
+ }
+
+ public void setMinInstanceCount(int minInstanceCount) {
+ this.minInstanceCount = minInstanceCount;
+ }
+
+ public int getMaxInstanceCount() {
+ return maxInstanceCount;
+ }
+
+ public void setMaxInstanceCount(int maxInstanceCount) {
+ this.maxInstanceCount = maxInstanceCount;
+ }
+
+ public String retrieveClusterDomain() {
+ // alias.hostname.php.domain
+ return hostName+"."+service+".domain";
+ }
+
+ public void start(ClusteringAgent clusteringAgent) throws ClusteringFault {
+ this.clusteringAgent = clusteringAgent;
+ clusteringAgent.init();
+ }
+
+ public void stop() {
+ if (clusteringAgent != null) {
+ clusteringAgent.stop();
+ }
+ clusteringAgent = null;
+ }
+
+ public boolean running() {
+ return clusteringAgent != null;
+ }
+
+ public String getRemoteHost() {
+ return remoteHost;
+ }
+
+ public void setRemoteHost(String remoteHost) {
+ this.remoteHost = remoteHost;
+ }
+
+ public int getMaxRequestsPerSecond() {
+ return maxRequestsPerSecond;
+ }
+
+ public void setMaxRequestsPerSecond(int maxRequestsPerSecond) {
+ this.maxRequestsPerSecond = maxRequestsPerSecond;
+ }
+
+ public int getRoundsToAverage() {
+ return roundsToAverage;
+ }
+
+ public void setRoundsToAverage(int roundsToAverage) {
+ this.roundsToAverage = roundsToAverage;
+ }
+
+ public double getAlarmingUpperRate() {
+ return alarmingUpperRate;
+ }
+
+ public void setAlarmingUpperRate(double alarmingUpperRate) {
+ this.alarmingUpperRate = alarmingUpperRate;
+ }
+
+ public double getAlarmingLowerRate() {
+ return alarmingLowerRate;
+ }
+
+ public void setAlarmingLowerRate(double alarmingLowerRate) {
+ this.alarmingLowerRate = alarmingLowerRate;
+ }
+
+ public double getScaleDownFactor() {
+ return scaleDownFactor;
+ }
+
+ public void setScaleDownFactor(double scaleDownFactor) {
+ this.scaleDownFactor = scaleDownFactor;
+ }
+
+ @Override
+ public String toString() {
+ return "Registrant{" +
+ "key='" + key + '\'' +
+ ", remoteHost='" + remoteHost + '\'' +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Registrant that = (Registrant) o;
+ return key.equals(that.key);
+ }
+
+ @Override
+ public int hashCode() {
+ return key.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantDatabase.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantDatabase.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantDatabase.java
new file mode 100644
index 0000000..dc511dc
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantDatabase.java
@@ -0,0 +1,143 @@
+/**
+ * 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.cartridge.agent.registrant;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cartridge.agent.InstanceStateNotificationClientThread;
+import org.apache.stratos.cartridge.agent.exception.CartridgeAgentException;
+
+import java.io.*;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * This class represents a database for {@link Registrant}s. Registrants added to this database will be
+ * persisted, so that when the Cartridge Agent is restarted, the Registrants can be restored.
+ *
+ * @see Registrant
+ */
+public class RegistrantDatabase {
+ private static final Log log = LogFactory.getLog(RegistrantDatabase.class);
+
+ private List<Registrant> registrants = new CopyOnWriteArrayList<Registrant>();
+
+ public void add(Registrant registrant) throws CartridgeAgentException {
+ if (registrants.contains(registrant) && registrant.running()) {
+ throw new CartridgeAgentException("Active registrant with key " +
+ registrant.getKey() + " already exists");
+ }
+ synchronized (registrant) {
+ if (!isAlreadyAdded(registrant)) {
+ persist(registrant);
+ registrants.add(registrant);
+ log.info("Added registrant " + registrant);
+
+ } else {
+ log.info("Registrant " + registrant + "has been already added");
+ }
+ }
+ }
+
+ private void persist(Registrant registrant) throws CartridgeAgentException {
+ try {
+ ObjectOutput out = null;
+ try {
+ // Serialize to a file
+ if (!new File("registrants").exists() && !new File("registrants").mkdirs()) {
+ throw new IOException("Cannot create registrants directory");
+ }
+ out = new ObjectOutputStream(new FileOutputStream("registrants" + File.separator +
+ registrant.getKey() + ".ser"));
+ out.writeObject(registrant);
+ out.close();
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ } catch (IOException e) {
+ log.error("Could not serialize registrant " + registrant, e);
+ }
+ }
+
+ public void stopAll() {
+ for (Registrant registrant : registrants) {
+ new Thread(new InstanceStateNotificationClientThread(registrant, "INACTIVE")).start();
+ registrant.stop();
+ }
+ }
+
+ public boolean containsActive(Registrant registrant) {
+ return registrants.contains(registrant) &&
+ registrants.get(registrants.indexOf(registrant)).running();
+ }
+
+ public List<Registrant> getRegistrants() {
+ return Collections.unmodifiableList(registrants);
+ }
+
+ public boolean isAlreadyAdded(Registrant registrant) {
+
+ boolean alreadyAdded = false;
+ for (Registrant registrantFromDb : registrants) {
+ if(registrantFromDb.getRemoteHost().equals(registrant.getRemoteHost())) {
+
+ PortMapping[] portMappingofRegistrantOfDB = registrantFromDb.getPortMappings();
+ PortMapping[] portMappingofRegistrant = registrant.getPortMappings();
+
+ if(portMappingofRegistrant.length != portMappingofRegistrantOfDB.length) {
+ continue;
+
+ } else {
+ alreadyAdded = checkPortMappings(registrant, registrantFromDb);
+ }
+
+ } else {
+ continue;
+ }
+ }
+ return alreadyAdded;
+ }
+
+ private boolean checkPortMappings (Registrant newRegistrant, Registrant existingRegistrant) {
+
+ PortMapping[] portMappingsOfNewRegistrant = newRegistrant.getPortMappings();
+ PortMapping[] portMappingsOfExistingRegistrant = existingRegistrant.getPortMappings();
+
+ for (PortMapping portMappingOfNewRegistrant : portMappingsOfNewRegistrant) {
+ boolean matchFound = false;
+ for (PortMapping portMappingOfExistingRegistrant : portMappingsOfExistingRegistrant) {
+ if(portMappingOfExistingRegistrant.equals(portMappingOfNewRegistrant)) {
+ matchFound = true;
+ break;
+ }
+ }
+ if(!matchFound) {
+ return false;
+ }
+ }
+ if(log.isDebugEnabled()) {
+ log.debug("***********************************Found matching registrant for " + newRegistrant + " in the Registrant database");
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantHealthChecker.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantHealthChecker.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantHealthChecker.java
new file mode 100644
index 0000000..2f8a227
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantHealthChecker.java
@@ -0,0 +1,115 @@
+/**
+ * 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.cartridge.agent.registrant;
+
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.axis2.clustering.management.GroupManagementAgent;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cartridge.agent.ClusteringClient;
+import org.apache.stratos.cartridge.agent.InstanceStateNotificationClientThread;
+
+/**
+ * This health checker periodically checks the health of the {@link Registrant}s
+ *
+ * If a registrant is found to be unhealthy, then it is stopped. This task will also try to
+ * connect to reactivate a registrant which was previously found to be unhealthy.
+ *
+ * If the Elastic Load Balancer (ELB) is not running, this health checker will not continue with
+ * registrant health checks since it is futile to try to connect the registrants to the
+ * unavailable ELB.
+ */
+public class RegistrantHealthChecker {
+ private static final Log log = LogFactory.getLog(RegistrantHealthChecker.class);
+
+ private RegistrantDatabase database;
+ private ClusteringClient clusteringClient;
+ private ConfigurationContext configurationContext;
+ private ScheduledExecutorService scheduler;
+ private volatile boolean isELBRunning;
+ private int healthCheckInterval;
+
+ public RegistrantHealthChecker(RegistrantDatabase database,
+ ClusteringClient clusteringClient,
+ ConfigurationContext configurationContext,
+ int healthCheckInterval,
+ int threadPoolSize) {
+ this.database = database;
+ this.clusteringClient = clusteringClient;
+ this.configurationContext = configurationContext;
+ this.healthCheckInterval = healthCheckInterval;
+ scheduler = Executors.newScheduledThreadPool(threadPoolSize);
+ }
+
+ public void startAll() {
+ List<Registrant> registrants = database.getRegistrants();
+ for (Registrant registrant : registrants) {
+ scheduler.scheduleWithFixedDelay(new HealthCheckerTask(registrant), 45,
+ healthCheckInterval, TimeUnit.SECONDS);
+ if (log.isDebugEnabled()) {
+ log.debug("Started a health checker for " + registrant + " ...");
+ }
+ }
+ }
+
+ public void start(Registrant registrant){
+ scheduler.scheduleWithFixedDelay(new HealthCheckerTask(registrant), 45,
+ healthCheckInterval, TimeUnit.SECONDS);
+ if (log.isDebugEnabled()) {
+ log.debug("Added a health checker for " + registrant + " ...");
+ }
+ }
+
+ public void setELBRunning(boolean ELBRunning) {
+ isELBRunning = ELBRunning;
+ }
+
+ private final class HealthCheckerTask implements Runnable {
+ Registrant registrant;
+ public HealthCheckerTask(Registrant registrant){
+ this.registrant = registrant;
+ }
+ public void run() {
+ if(!isELBRunning){
+ return;
+ }
+ try {
+ boolean healthyRegistrant = RegistrantUtil.isHealthy(registrant);
+ if (!healthyRegistrant && registrant.running()) {
+ registrant.stop();
+ new Thread(new InstanceStateNotificationClientThread(registrant, "INACTIVE")).start();
+ log.warn("Stopped registrant " + registrant + " since it is unhealthy." );
+ } else if (healthyRegistrant && !registrant.running()) {
+ registrant.stop();
+ new Thread(new InstanceStateNotificationClientThread(registrant, "INACTIVE")).start();
+ clusteringClient.joinGroup(registrant, configurationContext);
+ log.info("Restarted registrant " + registrant + " after it became active");
+ }
+ } catch (Exception e) {
+ log.error("Error occurred while running registrant health check", e);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantUtil.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantUtil.java
new file mode 100644
index 0000000..60208b4
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/registrant/RegistrantUtil.java
@@ -0,0 +1,177 @@
+/**
+ * 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.cartridge.agent.registrant;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cartridge.agent.ClusteringClient;
+import org.apache.stratos.cartridge.agent.exception.CartridgeAgentException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.net.*;
+
+/**
+ * Utility method collection for handling {@link Registrant}s
+ *
+ * @see Registrant
+ */
+public class RegistrantUtil {
+ private static final Log log = LogFactory.getLog(RegistrantUtil.class);
+ private static boolean registrantsReloaded = false;
+ /**
+ * Before adding a member, we will try to verify whether we can connect to it
+ *
+ * @param registrant The member whose connectvity needs to be verified
+ * @return true, if the member can be contacted; false, otherwise.
+ */
+ public static boolean isHealthy(Registrant registrant) {
+ if (log.isDebugEnabled()) {
+ log.debug("Trying to connect to registrant " + registrant + "...");
+ }
+ if(log.isDebugEnabled()) {
+ log.debug("***********************************************isHealthy() method for registrant " + registrant);
+ }
+ String registrantRemoteHost = registrant.getRemoteHost();
+ log.debug("remote host : " + registrantRemoteHost);
+ if(registrantRemoteHost == null){
+ registrantRemoteHost = "localhost";
+ }
+ InetAddress addr;
+ try {
+ addr = InetAddress.getByName(registrantRemoteHost);
+ if(log.isDebugEnabled()) {
+ log.debug("***********************************************Host resolved for registrant " + registrant);
+ }
+ } catch (UnknownHostException e) {
+ log.error("Registrant " + registrant + " is unhealthy");
+ return false;
+ }
+ PortMapping[] portMappings = registrant.getPortMappings();
+
+ int maxRetries = Integer.parseInt(System.getProperty("clustering.maxRetries"));
+
+ for (int retries = maxRetries; retries > 0; retries--) {
+ try {
+ for (PortMapping portMapping : portMappings) {
+ int port = portMapping.getPrimaryPort();
+ if(log.isDebugEnabled()) {
+ log.debug("***********************************************primary port" + port + " registrant " + registrant);
+ }
+ if (port != -1 && port != 0) {
+ if(log.isDebugEnabled()) {
+ log.debug("***********************************************connecting to " + registrant +
+ " re-try: " + retries);
+ }
+ SocketAddress httpSockaddr = new InetSocketAddress(addr, port);
+ new Socket().connect(httpSockaddr, 10000);
+ if(log.isDebugEnabled()) {
+ log.debug("***********************************************connected successfully to port: " + port);
+ }
+ }
+ }
+ return true;
+ } catch (IOException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Error occurred.. " + e.getMessage());
+ }
+ String msg = e.getMessage();
+ if (!msg.contains("Connection refused") && !msg.contains("connect timed out")) {
+ String msg2 = "Cannot connect to registrant " + registrant;
+ log.error(msg2, e);
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ignored) {
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Reload all the registrants persisted in the file system
+ * @param clusteringClient ClusteringClient
+ * @param configurationContext ConfigurationContext
+ * @param registrantDatabase RegistrantDatabase
+ * @throws CartridgeAgentException If reloading registrants fails
+ */
+ public static void reloadRegistrants(ClusteringClient clusteringClient,
+ ConfigurationContext configurationContext,
+ RegistrantDatabase registrantDatabase) throws CartridgeAgentException {
+
+ if(registrantsReloaded) {
+ log.info("Registrants already re-loaded, therefore not re-loading again");
+ return;
+ }
+
+ File registrants = new File("registrants");
+ if (!registrants.exists()) {
+ log.info("Registrant information doesn't exist in the file system");
+ return;
+ }
+ File[] files = registrants.listFiles();
+ if (files == null) {
+ log.error("Directory 'Registrants' is invalid");
+ return;
+
+ } else if (files.length == 0) {
+ log.info("No registrant information found in the Registrants directory");
+ return;
+ }
+
+ for (File file : files) {
+ try {
+ Registrant registrant =
+ deserializeRegistrant("registrants" + File.separator + file.getName());
+ if (!registrantDatabase.containsActive(registrant)) {
+ clusteringClient.joinGroup(registrant, configurationContext);
+ }
+ } catch (IOException e) {
+ log.error("Cannot deserialize registrant file " + file.getName(), e);
+ }
+ }
+ registrantsReloaded = true;
+ }
+
+ private static Registrant deserializeRegistrant(String fileName) throws IOException {
+ Registrant registrant = null;
+ ObjectInputStream in = null;
+
+ try {
+ // Deserialize from a file
+ File file = new File(fileName);
+ in = new ObjectInputStream(new FileInputStream(file));
+ // Deserialize the object
+ registrant = (Registrant) in.readObject();
+ } catch (ClassNotFoundException ignored) {
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ return registrant;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/service/CartridgeAgentService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/service/CartridgeAgentService.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/service/CartridgeAgentService.java
new file mode 100644
index 0000000..2136164
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/service/CartridgeAgentService.java
@@ -0,0 +1,68 @@
+/**
+ * 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.cartridge.agent.service;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cartridge.agent.ClusteringClient;
+import org.apache.stratos.cartridge.agent.exception.CartridgeAgentException;
+import org.apache.stratos.cartridge.agent.internal.CartridgeAgentConstants;
+import org.apache.stratos.cartridge.agent.internal.DataHolder;
+import org.apache.stratos.cartridge.agent.registrant.Registrant;
+
+/**
+ * Web service used for allowing {@link Registrant}s to register themselves with the Cartridge Agent
+ *
+ * @see Registrant
+ */
+@SuppressWarnings("unused")
+public class CartridgeAgentService {
+ private static final Log log = LogFactory.getLog(CartridgeAgentService.class);
+
+ public boolean register(Registrant registrant) throws CartridgeAgentException {
+
+ MessageContext messageContext = MessageContext.getCurrentMessageContext();
+ ConfigurationContext configurationContext = messageContext.getConfigurationContext();
+ ClusteringClient clusteringClient =
+ (ClusteringClient) configurationContext.getProperty(CartridgeAgentConstants.CLUSTERING_CLIENT);
+ if (registrant.getRemoteHost() == null || registrant.getRemoteHost().isEmpty()) {
+ String remoteAddr = (String) messageContext.getProperty("REMOTE_ADDR");
+ registrant.setRemoteHost(remoteAddr);
+ }
+ log.info("Trying to add new registrant " + registrant + "...");
+ clusteringClient.joinGroup(registrant, configurationContext);
+// Main.getHealthChecker().start(registrant);
+ DataHolder.getHealthChecker().start(registrant);
+ return true;
+
+ }
+
+ public boolean unregister(String domain, String subDomain, String hostName) throws CartridgeAgentException {
+
+ MessageContext messageContext = MessageContext.getCurrentMessageContext();
+ ConfigurationContext configurationContext = messageContext.getConfigurationContext();
+ ClusteringClient clusteringClient =
+ (ClusteringClient) configurationContext.getProperty(CartridgeAgentConstants.CLUSTERING_CLIENT);
+ clusteringClient.removeClusterDomain(domain, subDomain, hostName, configurationContext);
+ return true;
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.agent/src/main/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.cartridge.agent/src/main/resources/META-INF/services.xml
new file mode 100644
index 0000000..1eb8777
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.agent/src/main/resources/META-INF/services.xml
@@ -0,0 +1,37 @@
+<!--
+ ~ 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.
+ ~
+ -->
+<serviceGroup>
+ <service name="CartridgeAgentService" scope="transportsession">
+ <transports>
+ <transport>https</transport>
+ </transports>
+ <description>
+ Admin service for ADC activities
+ </description>
+ <parameter name="ServiceClass">org.wso2.carbon.cartridge.agent.service.CartridgeAgentService
+ </parameter>
+ <parameter name="enableMTOM">true</parameter>
+ <parameter name="adminService" locked="true">false</parameter>
+ <parameter name="hiddenService" locked="true">false</parameter>
+ <parameter name="AuthorizationAction" locked="true">
+ /permission/admin/manage/modify/webapp </parameter>
+ <parameter name="DoAuthentication" locked="true">true</parameter>
+ </service>
+</serviceGroup>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/2.1.1/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/2.1.1/pom.xml b/components/org.apache.stratos.cartridge.messages/2.1.1/pom.xml
deleted file mode 100644
index ee78a78..0000000
--- a/components/org.apache.stratos.cartridge.messages/2.1.1/pom.xml
+++ /dev/null
@@ -1,77 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ 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.
- ~
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.apache.stratos</groupId>
- <artifactId>stratos-components-parent</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <relativePath>../../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>org.apache.stratos.cartridge.messages</artifactId>
- <packaging>bundle</packaging>
- <name>Apache Stratos Cartridge Agent - Messages</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.axis2.wso2</groupId>
- <artifactId>axis2</artifactId>
- <version>${axis2.wso2.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>1.4.0</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
- <Bundle-Name>${project.artifactId}</Bundle-Name>
- <Export-Package>
- org.apache.stratos.cartridge.messages.*
- </Export-Package>
- <Import-Package>
- !org.apache.commons.logging,
- org.apache.commons.logging; version=0.0.0,
- *; resolution:=optional
- </Import-Package>
- <DynamicImport-Package>*</DynamicImport-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java b/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java
deleted file mode 100644
index d70d131..0000000
--- a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * 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.cartridge.messages;
-
-public class ClusterDomain {
-
- private String domain;
- private String subDomain;
- private String hostName;
- //private int tenantId;
- private String tenantRange;
- private int minInstances;
- private int maxInstances;
- private String serviceName;
- private int maxRequestsPerSecond;
- private int roundsToAverage;
- private double alarmingUpperRate;
- private double alarmingLowerRate;
- private double scaleDownFactor;
-
- public String getDomain() {
- return domain;
- }
- public void setDomain(String domain) {
- this.domain = domain;
- }
- public String getSubDomain() {
- return subDomain;
- }
- public void setSubDomain(String subDomain) {
- this.subDomain = subDomain;
- }
- public String getHostName() {
- return hostName;
- }
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
- /*public int getTenantId() {
- return tenantId;
- }
- public void setTenantId(int tenantId) {
- this.tenantId = tenantId;
- }*/
- public int getMinInstances() {
- return minInstances;
- }
- public void setMinInstances(int minInstances) {
- this.minInstances = minInstances;
- }
- public int getMaxInstances() {
- return maxInstances;
- }
- public void setMaxInstances(int maxInstances) {
- this.maxInstances = maxInstances;
- }
- public String getServiceName() {
- return serviceName;
- }
- public void setServiceName(String serviceName) {
- this.serviceName = serviceName;
- }
- public String getTenantRange() {
- return tenantRange;
- }
- public void setTenantRange(String tenantRange) {
- this.tenantRange = tenantRange;
- }
- public int getMaxRequestsPerSecond() {
- return maxRequestsPerSecond;
- }
- public void setMaxRequestsPerSecond(int maxRequestsPerSecond) {
- this.maxRequestsPerSecond = maxRequestsPerSecond;
- }
- public int getRoundsToAverage() {
- return roundsToAverage;
- }
- public void setRoundsToAverage(int roundsToAverage) {
- this.roundsToAverage = roundsToAverage;
- }
- public double getAlarmingUpperRate() {
- return alarmingUpperRate;
- }
- public void setAlarmingUpperRate(double alarmingUpperRate) {
- this.alarmingUpperRate = alarmingUpperRate;
- }
- public double getAlarmingLowerRate() {
- return alarmingLowerRate;
- }
- public void setAlarmingLowerRate(double alarmingLowerRate) {
- this.alarmingLowerRate = alarmingLowerRate;
- }
- public double getScaleDownFactor() {
- return scaleDownFactor;
- }
- public void setScaleDownFactor(double scaleDownFactor) {
- this.scaleDownFactor = scaleDownFactor;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java b/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java
deleted file mode 100644
index cdea820..0000000
--- a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * 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.cartridge.messages;
-
-/**
- * TODO: class description
- */
-public interface ClusterDomainManager {
-
- void addClusterDomain(ClusterDomain clusterDomain);
-
- /**
- * This will remove the corresponding ServiceConfiguration.
- * @param domain
- * @param subDomain
- * @param hostName
- */
- void removeClusterDomain(String domain, String subDomain, String hostName);
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java b/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java
deleted file mode 100644
index 7c54a8d..0000000
--- a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * 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.cartridge.messages;
-
-import org.apache.axis2.clustering.ClusteringCommand;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.clustering.ClusteringMessage;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * TODO: class description
- */
-public class CreateClusterDomainMessage extends ClusteringMessage {
- private static final Log log = LogFactory.getLog(CreateClusterDomainMessage.class);
- public static final String CLUSTER_DOMAIN_MANAGER = "cluster.domain.manager";
- private String service;
- private String clusterDomain;
- private String hostName;
- //private int tenantId;
- private String tenantRange;
- private int minInstances;
- private int maxInstances;
- private int maxRequestsPerSecond;
- private int roundsToAverage;
- private double alarmingUpperRate;
- private double alarmingLowerRate;
- private double scaleDownFactor;
-
-
- public CreateClusterDomainMessage(String service, String clusterDomain,
- String hostName, String tenantRange,
- int minInstances, int maxInstances,
- int maxRequestsPerSecond, int roundsToAverage,
- double alarmingUpperRate, double alarmingLowerRate,
- double scaleDownFactor) {
- this.service = service;
- this.clusterDomain = clusterDomain;
- this.hostName = hostName;
- this.tenantRange = tenantRange;
- this.minInstances = minInstances;
- this.maxInstances = maxInstances;
- this.maxRequestsPerSecond = maxRequestsPerSecond;
- this.roundsToAverage = roundsToAverage;
- this.alarmingUpperRate = alarmingUpperRate;
- this.alarmingLowerRate = alarmingLowerRate;
- this.scaleDownFactor = scaleDownFactor;
- }
-
- @Override
- public ClusteringCommand getResponse() {
- return new ClusteringCommand() {
- @Override
- public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
- log.info("Received response to CreateClusterDomainMessage");
- }
- };
- }
-
- @Override
- public void execute(final ConfigurationContext configurationContext) throws ClusteringFault {
- log.info("Received ***" + this);
- Runnable runnable = new Runnable() {
- public void run() {
- try {
- Thread.sleep(2000);
- } catch (InterruptedException ignored) {
- }
- ClusterDomainManager clusterDomainManager =
- (ClusterDomainManager) configurationContext.getProperty(CLUSTER_DOMAIN_MANAGER);
- if (clusterDomainManager != null) {
- clusterDomainManager.addClusterDomain(createClusterDomain());
- } else {
- log.warn(CLUSTER_DOMAIN_MANAGER + " has not been defined in ConfigurationContext");
- }
- }
-
- private ClusterDomain createClusterDomain() {
-
- ClusterDomain clusterDomainObj = new ClusterDomain();
- clusterDomainObj.setDomain(clusterDomain);
- clusterDomainObj.setHostName(hostName);
- clusterDomainObj.setMaxInstances(maxInstances);
- clusterDomainObj.setMinInstances(minInstances);
- clusterDomainObj.setSubDomain(null); // TODO subdomain
- clusterDomainObj.setTenantRange(tenantRange);
- clusterDomainObj.setServiceName(service);
- clusterDomainObj.setMaxRequestsPerSecond(maxRequestsPerSecond);
- clusterDomainObj.setRoundsToAverage(roundsToAverage);
- clusterDomainObj.setAlarmingUpperRate(alarmingUpperRate);
- clusterDomainObj.setAlarmingLowerRate(alarmingLowerRate);
- clusterDomainObj.setScaleDownFactor(scaleDownFactor);
-
- if(log.isDebugEnabled())
- log.debug("Cluster Domain is created with minInstances:" + minInstances + ", maxInstances: " + maxInstances);
-
- return clusterDomainObj;
- }
- };
- new Thread(runnable).start();
- }
-
- @Override
- public String toString() {
- return "CreateClusterDomainMessage{" +
- "service='" + service + '\'' +
- ", clusterDomain='" + clusterDomain + '\'' +
- ", hostName='" + hostName + '\'' +
- ", tenantId=" + tenantRange +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java b/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java
deleted file mode 100644
index b154424..0000000
--- a/components/org.apache.stratos.cartridge.messages/2.1.1/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * 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.cartridge.messages;
-
-import org.apache.axis2.clustering.ClusteringCommand;
-import org.apache.axis2.clustering.ClusteringFault;
-import org.apache.axis2.clustering.ClusteringMessage;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class CreateRemoveClusterDomainMessage extends ClusteringMessage{
-
- private static final Log log = LogFactory.getLog(CreateClusterDomainMessage.class);
- public static final String CLUSTER_DOMAIN_MANAGER = "cluster.domain.manager";
- private String domain;
- private String subDomain;
- private String hostName;
-
-
-
- public CreateRemoveClusterDomainMessage(String domain, String subDomain, String hostName) {
- this.domain = domain;
- this.subDomain = subDomain;
- this.hostName = hostName;
- }
-
- @Override
- public ClusteringCommand getResponse() {
- return new ClusteringCommand() {
- @Override
- public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
- log.info("Received response to CreateRemoveClusterDomainMessage");
- }
- };
- }
-
- @Override
- public void execute(final ConfigurationContext configurationContext) throws ClusteringFault {
-
- log.info("Received ***" + this);
- Runnable runnable = new Runnable() {
- public void run() {
- try {
- Thread.sleep(2000);
- } catch (InterruptedException ignored) {
- }
- ClusterDomainManager clusterDomainManager =
- (ClusterDomainManager) configurationContext.getProperty(CLUSTER_DOMAIN_MANAGER);
- log.info(" ***** Received clusterDomain Manager ** " + clusterDomainManager);
- if (clusterDomainManager != null) {
- clusterDomainManager.removeClusterDomain(domain, subDomain, hostName);
- } else {
- log.warn(CLUSTER_DOMAIN_MANAGER + " has not been defined in ConfigurationContext");
- }
- }
- };
- new Thread(runnable).start();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/pom.xml b/components/org.apache.stratos.cartridge.messages/pom.xml
new file mode 100644
index 0000000..9c0c332
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.messages/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ ~
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.cartridge.messages</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos Cartridge Agent - Messages</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ <version>${axis2.wso2.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.apache.stratos.cartridge.messages.*
+ </Export-Package>
+ <Import-Package>
+ !org.apache.commons.logging,
+ org.apache.commons.logging; version=0.0.0,
+ *; resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java
new file mode 100644
index 0000000..d70d131
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomain.java
@@ -0,0 +1,117 @@
+/**
+ * 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.cartridge.messages;
+
+public class ClusterDomain {
+
+ private String domain;
+ private String subDomain;
+ private String hostName;
+ //private int tenantId;
+ private String tenantRange;
+ private int minInstances;
+ private int maxInstances;
+ private String serviceName;
+ private int maxRequestsPerSecond;
+ private int roundsToAverage;
+ private double alarmingUpperRate;
+ private double alarmingLowerRate;
+ private double scaleDownFactor;
+
+ public String getDomain() {
+ return domain;
+ }
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+ public String getSubDomain() {
+ return subDomain;
+ }
+ public void setSubDomain(String subDomain) {
+ this.subDomain = subDomain;
+ }
+ public String getHostName() {
+ return hostName;
+ }
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+ /*public int getTenantId() {
+ return tenantId;
+ }
+ public void setTenantId(int tenantId) {
+ this.tenantId = tenantId;
+ }*/
+ public int getMinInstances() {
+ return minInstances;
+ }
+ public void setMinInstances(int minInstances) {
+ this.minInstances = minInstances;
+ }
+ public int getMaxInstances() {
+ return maxInstances;
+ }
+ public void setMaxInstances(int maxInstances) {
+ this.maxInstances = maxInstances;
+ }
+ public String getServiceName() {
+ return serviceName;
+ }
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+ public String getTenantRange() {
+ return tenantRange;
+ }
+ public void setTenantRange(String tenantRange) {
+ this.tenantRange = tenantRange;
+ }
+ public int getMaxRequestsPerSecond() {
+ return maxRequestsPerSecond;
+ }
+ public void setMaxRequestsPerSecond(int maxRequestsPerSecond) {
+ this.maxRequestsPerSecond = maxRequestsPerSecond;
+ }
+ public int getRoundsToAverage() {
+ return roundsToAverage;
+ }
+ public void setRoundsToAverage(int roundsToAverage) {
+ this.roundsToAverage = roundsToAverage;
+ }
+ public double getAlarmingUpperRate() {
+ return alarmingUpperRate;
+ }
+ public void setAlarmingUpperRate(double alarmingUpperRate) {
+ this.alarmingUpperRate = alarmingUpperRate;
+ }
+ public double getAlarmingLowerRate() {
+ return alarmingLowerRate;
+ }
+ public void setAlarmingLowerRate(double alarmingLowerRate) {
+ this.alarmingLowerRate = alarmingLowerRate;
+ }
+ public double getScaleDownFactor() {
+ return scaleDownFactor;
+ }
+ public void setScaleDownFactor(double scaleDownFactor) {
+ this.scaleDownFactor = scaleDownFactor;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java
new file mode 100644
index 0000000..cdea820
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/ClusterDomainManager.java
@@ -0,0 +1,35 @@
+/**
+ * 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.cartridge.messages;
+
+/**
+ * TODO: class description
+ */
+public interface ClusterDomainManager {
+
+ void addClusterDomain(ClusterDomain clusterDomain);
+
+ /**
+ * This will remove the corresponding ServiceConfiguration.
+ * @param domain
+ * @param subDomain
+ * @param hostName
+ */
+ void removeClusterDomain(String domain, String subDomain, String hostName);
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java
new file mode 100644
index 0000000..7c54a8d
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateClusterDomainMessage.java
@@ -0,0 +1,129 @@
+/**
+ * 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.cartridge.messages;
+
+import org.apache.axis2.clustering.ClusteringCommand;
+import org.apache.axis2.clustering.ClusteringFault;
+import org.apache.axis2.clustering.ClusteringMessage;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * TODO: class description
+ */
+public class CreateClusterDomainMessage extends ClusteringMessage {
+ private static final Log log = LogFactory.getLog(CreateClusterDomainMessage.class);
+ public static final String CLUSTER_DOMAIN_MANAGER = "cluster.domain.manager";
+ private String service;
+ private String clusterDomain;
+ private String hostName;
+ //private int tenantId;
+ private String tenantRange;
+ private int minInstances;
+ private int maxInstances;
+ private int maxRequestsPerSecond;
+ private int roundsToAverage;
+ private double alarmingUpperRate;
+ private double alarmingLowerRate;
+ private double scaleDownFactor;
+
+
+ public CreateClusterDomainMessage(String service, String clusterDomain,
+ String hostName, String tenantRange,
+ int minInstances, int maxInstances,
+ int maxRequestsPerSecond, int roundsToAverage,
+ double alarmingUpperRate, double alarmingLowerRate,
+ double scaleDownFactor) {
+ this.service = service;
+ this.clusterDomain = clusterDomain;
+ this.hostName = hostName;
+ this.tenantRange = tenantRange;
+ this.minInstances = minInstances;
+ this.maxInstances = maxInstances;
+ this.maxRequestsPerSecond = maxRequestsPerSecond;
+ this.roundsToAverage = roundsToAverage;
+ this.alarmingUpperRate = alarmingUpperRate;
+ this.alarmingLowerRate = alarmingLowerRate;
+ this.scaleDownFactor = scaleDownFactor;
+ }
+
+ @Override
+ public ClusteringCommand getResponse() {
+ return new ClusteringCommand() {
+ @Override
+ public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
+ log.info("Received response to CreateClusterDomainMessage");
+ }
+ };
+ }
+
+ @Override
+ public void execute(final ConfigurationContext configurationContext) throws ClusteringFault {
+ log.info("Received ***" + this);
+ Runnable runnable = new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ignored) {
+ }
+ ClusterDomainManager clusterDomainManager =
+ (ClusterDomainManager) configurationContext.getProperty(CLUSTER_DOMAIN_MANAGER);
+ if (clusterDomainManager != null) {
+ clusterDomainManager.addClusterDomain(createClusterDomain());
+ } else {
+ log.warn(CLUSTER_DOMAIN_MANAGER + " has not been defined in ConfigurationContext");
+ }
+ }
+
+ private ClusterDomain createClusterDomain() {
+
+ ClusterDomain clusterDomainObj = new ClusterDomain();
+ clusterDomainObj.setDomain(clusterDomain);
+ clusterDomainObj.setHostName(hostName);
+ clusterDomainObj.setMaxInstances(maxInstances);
+ clusterDomainObj.setMinInstances(minInstances);
+ clusterDomainObj.setSubDomain(null); // TODO subdomain
+ clusterDomainObj.setTenantRange(tenantRange);
+ clusterDomainObj.setServiceName(service);
+ clusterDomainObj.setMaxRequestsPerSecond(maxRequestsPerSecond);
+ clusterDomainObj.setRoundsToAverage(roundsToAverage);
+ clusterDomainObj.setAlarmingUpperRate(alarmingUpperRate);
+ clusterDomainObj.setAlarmingLowerRate(alarmingLowerRate);
+ clusterDomainObj.setScaleDownFactor(scaleDownFactor);
+
+ if(log.isDebugEnabled())
+ log.debug("Cluster Domain is created with minInstances:" + minInstances + ", maxInstances: " + maxInstances);
+
+ return clusterDomainObj;
+ }
+ };
+ new Thread(runnable).start();
+ }
+
+ @Override
+ public String toString() {
+ return "CreateClusterDomainMessage{" +
+ "service='" + service + '\'' +
+ ", clusterDomain='" + clusterDomain + '\'' +
+ ", hostName='" + hostName + '\'' +
+ ", tenantId=" + tenantRange +
+ '}';
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java
new file mode 100644
index 0000000..b154424
--- /dev/null
+++ b/components/org.apache.stratos.cartridge.messages/src/main/java/org/apache/stratos/cartridge/messages/CreateRemoveClusterDomainMessage.java
@@ -0,0 +1,77 @@
+/**
+ * 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.cartridge.messages;
+
+import org.apache.axis2.clustering.ClusteringCommand;
+import org.apache.axis2.clustering.ClusteringFault;
+import org.apache.axis2.clustering.ClusteringMessage;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class CreateRemoveClusterDomainMessage extends ClusteringMessage{
+
+ private static final Log log = LogFactory.getLog(CreateClusterDomainMessage.class);
+ public static final String CLUSTER_DOMAIN_MANAGER = "cluster.domain.manager";
+ private String domain;
+ private String subDomain;
+ private String hostName;
+
+
+
+ public CreateRemoveClusterDomainMessage(String domain, String subDomain, String hostName) {
+ this.domain = domain;
+ this.subDomain = subDomain;
+ this.hostName = hostName;
+ }
+
+ @Override
+ public ClusteringCommand getResponse() {
+ return new ClusteringCommand() {
+ @Override
+ public void execute(ConfigurationContext configurationContext) throws ClusteringFault {
+ log.info("Received response to CreateRemoveClusterDomainMessage");
+ }
+ };
+ }
+
+ @Override
+ public void execute(final ConfigurationContext configurationContext) throws ClusteringFault {
+
+ log.info("Received ***" + this);
+ Runnable runnable = new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException ignored) {
+ }
+ ClusterDomainManager clusterDomainManager =
+ (ClusterDomainManager) configurationContext.getProperty(CLUSTER_DOMAIN_MANAGER);
+ log.info(" ***** Received clusterDomain Manager ** " + clusterDomainManager);
+ if (clusterDomainManager != null) {
+ clusterDomainManager.removeClusterDomain(domain, subDomain, hostName);
+ } else {
+ log.warn(CLUSTER_DOMAIN_MANAGER + " has not been defined in ConfigurationContext");
+ }
+ }
+ };
+ new Thread(runnable).start();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.cloud.controller/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/pom.xml b/components/org.apache.stratos.cloud.controller/pom.xml
index 11f4834..85bc531 100644
--- a/components/org.apache.stratos.cloud.controller/pom.xml
+++ b/components/org.apache.stratos.cloud.controller/pom.xml
@@ -22,7 +22,6 @@
<groupId>org.apache.stratos</groupId>
<artifactId>stratos-components-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -142,7 +141,7 @@
<dependency>
<groupId>org.apache.stratos</groupId>
<artifactId>org.apache.stratos.lb.common</artifactId>
- <version>4.1.3</version>
+ <version>${apache.stratos.version}</version>
</dependency>