You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2013/11/28 17:03:39 UTC
[3/8] more refactoring to CC
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ServiceContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ServiceContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ServiceContext.java
new file mode 100644
index 0000000..df025f9
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/ServiceContext.java
@@ -0,0 +1,366 @@
+/*
+ * 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 org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import java.io.*;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+/**
+ * We keep information regarding a service (i.e. a cartridge instance)
+ * in this object.
+ */
+public class ServiceContext implements Serializable{
+ private static Log log = LogFactory.getLog(ServiceContext.class);
+
+ private static final long serialVersionUID = -6740964802890082678L;
+ private File file;
+ private String clusterId;
+ private String tenantRange;
+ private String hostName;
+ private String payloadFilePath = "/tmp/" + CloudControllerConstants.PAYLOAD_NAME + ".zip";
+ private String cartridgeType;
+ private Cartridge cartridge;
+ private StringBuilder payload;
+ private String autoScalerPolicyName;
+
+ /**
+ * Key - Value pair.
+ */
+ private Map<String, String> properties = new HashMap<String, String>();
+ /**
+ * Key - IaaS Type
+ * Value - {@link IaasContext} object
+ */
+ private Map<String, IaasContext> iaasCtxts = new HashMap<String, IaasContext>();
+
+ public Map<String, IaasContext> getIaasCtxts() {
+ return iaasCtxts;
+ }
+
+ public String getClusterId() {
+ return clusterId;
+ }
+
+ public boolean setClusterId(String domainName) {
+ if (!"".equals(domainName)) {
+ this.clusterId = domainName;
+ return true;
+ }
+
+ return false;
+ }
+
+ public void setProperty(String key, String value) {
+ properties.put(key, value);
+ }
+
+ public String getProperty(String key) {
+
+ if(properties.containsKey(key)){
+ return properties.get(key);
+ }
+
+ return "";
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties) {
+ this.properties = properties;
+ }
+
+
+ public Cartridge getCartridge() {
+ return cartridge;
+ }
+
+ public void setCartridge(Cartridge cartridge) {
+ this.cartridge = cartridge;
+ }
+
+ public String getTenantRange() {
+ return tenantRange;
+ }
+
+ public void setTenantRange(String tenantRange) {
+ this.tenantRange = tenantRange;
+ }
+
+ public IaasContext addIaasContext(String iaasType){
+ IaasContext ctxt = new IaasContext(iaasType);
+ iaasCtxts.put(iaasType, ctxt);
+ return ctxt;
+ }
+
+ public IaasContext getIaasContext(String type){
+ return iaasCtxts.get(type);
+ }
+
+ public void setIaasContextMap(Map<String, IaasContext> map){
+ iaasCtxts = map;
+ }
+
+ public String getPayloadFile() {
+ return payloadFilePath;
+ }
+
+ public void setPayloadFile(String payloadFile) {
+ this.payloadFilePath = payloadFile;
+ }
+
+ public String getHostName() {
+ if(cartridge != null && (hostName == null || hostName.isEmpty())){
+ return cartridge.getHostName();
+ }
+ return hostName;
+ }
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ public String getCartridgeType() {
+ return cartridgeType;
+ }
+
+ public void setCartridgeType(String cartridgeType) {
+ this.cartridgeType = cartridgeType;
+ }
+
+ public StringBuilder getPayload() {
+ return payload;
+ }
+
+ public void setPayload(StringBuilder payload) {
+ this.payload = payload;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ public String toXml() {
+ String str = "<service domain=\"" + clusterId +
+ "\" tenantRange=\"" + tenantRange + "\" policyName=\"" + autoScalerPolicyName + "\">\n" +
+ "\t<cartridge type=\"" + cartridgeType +
+ "\"/>\n" + "\t<host>" + hostName +
+ "</host>\n" + "\t<payload>" + payload +
+ "</payload>\n" +
+ propertiesToXml() +
+ "</service>";
+ return str;
+ }
+
+ public String propertiesToXml() {
+ StringBuilder builder = new StringBuilder("");
+ for (Iterator<Map.Entry<String, String>> iterator = getProperties().entrySet().iterator(); iterator.hasNext();) {
+ Map.Entry<String, String> prop = iterator.next();
+
+ String key = prop.getKey();
+ String value = prop.getValue();
+ if (key != null) {
+ builder.append("\t<property name=\""+key +"\" value=\"" + (value == null ? "" : value) +"\"/>\n");
+ }
+
+ }
+
+ return builder.toString();
+ }
+
+ public byte[] generatePayload() {
+ String payloadStringTempFile = "launch-params";
+
+ FileWriter fstream;
+ try {
+ fstream = new FileWriter(payloadStringTempFile);
+
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+ BufferedWriter out = new BufferedWriter(fstream);
+ try {
+ out.write(payload.toString());
+ out.close();
+
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+
+
+ FileInputStream fis;
+ try {
+ fis = new FileInputStream(payloadStringTempFile);
+ } catch (FileNotFoundException e) {
+ String msg = "Failed while persisting the payload of clusterId : "
+ + clusterId;
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(this.payloadFilePath);
+
+ } catch (FileNotFoundException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+
+ ZipOutputStream zos = new ZipOutputStream(fos);
+ addToZipFile(System.getProperty("user.dir"), payloadStringTempFile, zos);
+
+ File folder = new File(CarbonUtils.getCarbonHome() + File.separator
+ + "repository" + File.separator + "resources" + File.separator
+ + "user-data");
+
+ if(folder != null && folder.exists()) {
+ for (File fileEntry : folder.listFiles()) {
+ if (fileEntry != null && !fileEntry.isDirectory()) {
+ addToZipFile(folder.getPath(), fileEntry.getName(), zos);
+ }
+ }
+ }
+
+ try {
+ zos.close();
+ fos.close();
+
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+ byte [] payloadData = null;
+ File file = null;
+ FileInputStream fileInputStream = null;
+ try {
+ file = new File(payloadFilePath);
+ payloadData = new byte[(int)file.length()];
+ fileInputStream = new FileInputStream(file);
+ try {
+ fileInputStream.read(payloadData);
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+ } catch (FileNotFoundException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+ try {
+ fileInputStream.close();
+ file.delete();
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+
+ return payloadData;
+ }
+
+ /**
+ * Adds content to a zip file
+ *
+ * @param dir Name of directory
+ * @param fileName Name of file to add
+ * @param zos ZipOutputStream subscription to write
+ * @throws CloudControllerException in an error
+ */
+ private void addToZipFile(String dir, String fileName, ZipOutputStream zos) throws CloudControllerException {
+
+ log.info("Writing '" + fileName + "' to zip file");
+
+ File file = new File(dir + File.separator + fileName);
+ FileInputStream fis;
+ try {
+ fis = new FileInputStream(file);
+
+ } catch (FileNotFoundException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+
+ ZipEntry zipEntry = new ZipEntry(fileName);
+ try {
+ zos.putNextEntry(zipEntry);
+
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+
+ byte[] bytes = new byte[1024];
+ int length;
+
+ try {
+ while ((length = fis.read(bytes)) >= 0) {
+ zos.write(bytes, 0, length);
+ }
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+
+ try {
+ zos.closeEntry();
+ fis.close();
+
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+ }
+
+ public boolean equals(Object obj) {
+ if (obj instanceof ServiceContext) {
+ return this.clusterId.equals(((ServiceContext) obj).getClusterId());
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
+ append(clusterId).
+ toHashCode();
+ }
+
+ public String getAutoScalerPolicyName() {
+ return autoScalerPolicyName;
+ }
+
+ public void setAutoScalerPolicyName(String autoScalerPolicyName) {
+ this.autoScalerPolicyName = autoScalerPolicyName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/TopologyConfig.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/TopologyConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/TopologyConfig.java
new file mode 100644
index 0000000..2d309a1
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/TopologyConfig.java
@@ -0,0 +1,59 @@
+/*
+ * 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.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Configuration related to Topology synchronization
+ *
+ */
+public class TopologyConfig implements Serializable{
+
+ private static final long serialVersionUID = 4435173744617096911L;
+
+ /**
+ * Key - Value pair.
+ */
+ private Map<String, String> properties = new HashMap<String, String>();
+
+ public void setProperty(String key, String value) {
+ properties.put(key, value);
+ }
+
+ public String getProperty(String key) {
+
+ if(properties.containsKey(key)){
+ return properties.get(key);
+ }
+
+ return null;
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties) {
+ this.properties = properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Zone.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Zone.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Zone.java
new file mode 100644
index 0000000..803bef5
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/pojo/Zone.java
@@ -0,0 +1,90 @@
+package org.apache.stratos.cloud.controller.pojo;
+
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.domain.Template;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Zone extends Region {
+ private String id;
+ private String type;
+ private List<Host> listOfHosts;
+
+ private Map<String, String> properties = new HashMap<String, String>();
+ private transient ComputeService computeService;
+
+ private transient Template template;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map<String, String> properties) {
+ this.properties = properties;
+ }
+
+ public void setProperty(String key, String value) {
+
+ if (key != null && value != null) {
+ getProperties().put(key, value);
+ }
+ }
+
+ public String getProperty(String key) {
+ if(getProperties().get(key) != null) {
+ return getProperties().get(key);
+ } else {
+ return super.getProperty(key);
+ }
+ }
+
+ public List<Host> getListOfHosts() {
+ return listOfHosts;
+ }
+
+ public void setListOfHosts(List<Host> listOfHosts) {
+ this.listOfHosts = listOfHosts;
+ }
+
+ public void addHost(Host host) {
+ this.listOfHosts.add(host);
+ }
+
+ public void removeHost(Host host) {
+ this.listOfHosts.remove(host);
+ }
+
+ public ComputeService getComputeService() {
+ return computeService;
+ }
+
+ public void setComputeService(ComputeService computeService) {
+ this.computeService = computeService;
+ }
+
+ public Template getTemplate() {
+ return template;
+ }
+
+ public void setTemplate(Template template) {
+ this.template = template;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java
index dcc1042..80cfe8f 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/publisher/CartridgeInstanceDataPublisherTask.java
@@ -21,9 +21,14 @@ package org.apache.stratos.cloud.controller.publisher;
import com.google.common.collect.MapDifference;
import com.google.common.collect.MapDifference.ValueDifference;
import com.google.common.collect.Maps;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInstanceData;
+import org.apache.stratos.cloud.controller.pojo.IaasContext;
+import org.apache.stratos.cloud.controller.pojo.IaasProvider;
+import org.apache.stratos.cloud.controller.pojo.ServiceContext;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.stratos.cloud.controller.util.*;
import org.jclouds.compute.ComputeService;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
index 1412e32..ebdcbc4 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/runtime/FasterLookUpDataHolder.java
@@ -18,8 +18,13 @@
*/
package org.apache.stratos.cloud.controller.runtime;
+import org.apache.stratos.cloud.controller.pojo.Cartridge;
import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.DataPublisherConfig;
+import org.apache.stratos.cloud.controller.pojo.IaasProvider;
import org.apache.stratos.cloud.controller.pojo.MemberContext;
+import org.apache.stratos.cloud.controller.pojo.ServiceContext;
+import org.apache.stratos.cloud.controller.pojo.TopologyConfig;
import org.apache.stratos.cloud.controller.registry.RegistryManager;
import org.apache.stratos.cloud.controller.util.*;
import org.apache.stratos.messaging.broker.publish.EventPublisher;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
index 795bf2c..f87953e 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java
@@ -20,14 +20,14 @@ package org.apache.stratos.cloud.controller.topology;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.deployment.partition.Partition;
+import org.apache.stratos.cloud.controller.pojo.Cartridge;
import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.PortMapping;
import org.apache.stratos.cloud.controller.pojo.Registrant;
+import org.apache.stratos.cloud.controller.pojo.ServiceContext;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
-import org.apache.stratos.cloud.controller.util.Cartridge;
import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
-import org.apache.stratos.cloud.controller.util.PortMapping;
-import org.apache.stratos.cloud.controller.util.ServiceContext;
-import org.apache.stratos.messaging.domain.policy.Partition;
import org.apache.stratos.messaging.domain.topology.*;
import org.apache.stratos.messaging.event.instance.status.MemberActivatedEvent;
import org.apache.stratos.messaging.event.instance.status.MemberStartedEvent;
@@ -75,22 +75,22 @@ public class TopologyBuilder {
}
- public static void handlePartitionCreated(Partition partition) {
-
- Topology topology = TopologyManager.getInstance().getTopology();
- if (partition == null) {
- throw new RuntimeException(String.format("Partition is empty"));
- }
- try {
- TopologyManager.getInstance().acquireWriteLock();
- topology.addPartition(partition);
- TopologyManager.getInstance().updateTopology(topology);
- } finally {
- TopologyManager.getInstance().releaseWriteLock();
- }
- TopologyEventSender.sendPartitionCreatedEvent(partition);
-
- }
+// public static void handlePartitionCreated(Partition partition) {
+//
+// Topology topology = TopologyManager.getInstance().getTopology();
+// if (partition == null) {
+// throw new RuntimeException(String.format("Partition is empty"));
+// }
+// try {
+// TopologyManager.getInstance().acquireWriteLock();
+// topology.addPartition(partition);
+// TopologyManager.getInstance().updateTopology(topology);
+// } finally {
+// TopologyManager.getInstance().releaseWriteLock();
+// }
+// TopologyEventSender.sendPartitionCreatedEvent(partition);
+//
+// }
// public static void handlePartitionUpdated(Partition newPartition, Partition oldPartition) {
//
@@ -241,14 +241,13 @@ public class TopologyBuilder {
member.setIaasNodeId(iaasNodeId);
member.setStatus(MemberStatus.Created);
member.setMemberIp(privateIp);
- member.setPartition(partition);
cluster.addMember(member);
cluster.addMemberToIaasNodeId(member);
TopologyManager.getInstance().updateTopology(topology);
} finally {
TopologyManager.getInstance().releaseWriteLock();
}
- TopologyEventSender.sendInstanceSpawnedEvent(serviceName, clusterId, memberId, iaasNodeId, partition);
+ TopologyEventSender.sendInstanceSpawnedEvent(serviceName, clusterId, memberId, iaasNodeId);
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
index 1ccb4a7..82aa692 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyEventSender.java
@@ -19,15 +19,14 @@ package org.apache.stratos.cloud.controller.topology;
*/
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.pojo.Cartridge;
import org.apache.stratos.cloud.controller.pojo.ClusterContext;
+import org.apache.stratos.cloud.controller.pojo.PortMapping;
import org.apache.stratos.cloud.controller.pojo.Registrant;
+import org.apache.stratos.cloud.controller.pojo.ServiceContext;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
-import org.apache.stratos.cloud.controller.util.Cartridge;
import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
-import org.apache.stratos.cloud.controller.util.PortMapping;
-import org.apache.stratos.cloud.controller.util.ServiceContext;
import org.apache.stratos.messaging.broker.publish.EventPublisher;
-import org.apache.stratos.messaging.domain.policy.Partition;
import org.apache.stratos.messaging.domain.topology.Port;
import org.apache.stratos.messaging.domain.topology.Topology;
import org.apache.stratos.messaging.event.Event;
@@ -65,15 +64,15 @@ public class TopologyEventSender {
}
}
- public static void sendPartitionCreatedEvent(Partition partition) {
- PartitionCreatedEvent partitionCreatedEvent =
- new PartitionCreatedEvent(partition);
-
- if(log.isInfoEnabled()) {
- log.info(String.format("Publishing partition created event: [partition] %s", partition.getId()));
- }
- publishEvent(partitionCreatedEvent);
- }
+// public static void sendPartitionCreatedEvent(Partition partition) {
+// PartitionCreatedEvent partitionCreatedEvent =
+// new PartitionCreatedEvent(partition);
+//
+// if(log.isInfoEnabled()) {
+// log.info(String.format("Publishing partition created event: [partition] %s", partition.getId()));
+// }
+// publishEvent(partitionCreatedEvent);
+// }
// public static void sendPartitionUpdatedEvent(Partition partition, String oldPartitionId) {
// PartitionUpdatedEvent partitionUpdatedEvent =
@@ -138,13 +137,11 @@ public class TopologyEventSender {
}
- public static void sendInstanceSpawnedEvent(String serviceName, String clusterId, String memberId, String nodeId,
- Partition partition) {
+ public static void sendInstanceSpawnedEvent(String serviceName, String clusterId, String memberId, String nodeId) {
InstanceSpawnedEvent instanceSpawnedEvent = new InstanceSpawnedEvent(serviceName,
clusterId,
memberId,
nodeId);
- instanceSpawnedEvent.setPartition(partition);
if(log.isInfoEnabled()) {
log.info(String.format("Publishing instance spawned event: [service] %s [cluster] %s [member] %s [node] %s", serviceName, clusterId, memberId, nodeId));
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/AppType.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/AppType.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/AppType.java
deleted file mode 100644
index 2ddbe7a..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/AppType.java
+++ /dev/null
@@ -1,62 +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.cloud.controller.util;
-
-import java.io.Serializable;
-
-/**
- * domain mapping related data.
- *
- */
-public class AppType implements Serializable{
-
- private static final long serialVersionUID = 3550489774139807168L;
- private String name;
- private boolean appSpecificMapping = true;
-
- public AppType(){
-
- }
-
- public AppType(String name){
- this.setName(name);
- }
-
- public AppType(String name, boolean appSpecificMapping){
- this.setName(name);
- this.setAppSpecificMapping(appSpecificMapping);
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public boolean isAppSpecificMapping() {
- return appSpecificMapping;
- }
-
- public void setAppSpecificMapping(boolean appSpecificMapping) {
- this.appSpecificMapping = appSpecificMapping;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java
deleted file mode 100644
index fe864b9..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Cartridge.java
+++ /dev/null
@@ -1,288 +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.cloud.controller.util;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.commons.lang.builder.HashCodeBuilder;
-
-/**
- * Holds information regarding a Cartridge.
- */
-public class Cartridge implements Serializable{
-
- private static final long serialVersionUID = 6637409027085059072L;
-
- private String type;
-
- private String hostName;
-
- private String provider;
-
- private String displayName;
-
- private String description;
-
- private String baseDir;
-
- private String version;
-
- private boolean multiTenant;
-
- private List<PortMapping> portMappings = new ArrayList<PortMapping>();
-
- private List<AppType> appTypeMappings = new ArrayList<AppType>();
-
- /**
- * Property map of this Cartridge.
- */
- private Map<String, String> properties = new HashMap<String, String>();
-
- /**
- * A Cartridge can have 1..n {@link IaasProvider}s
- */
- private List<IaasProvider> iaases = new ArrayList<IaasProvider>();
-
- private List<String> deploymentDirs = new ArrayList<String>();
-
- private IaasProvider lastlyUsedIaas;
-
- /**
- * Key - partition id
- * Value - Corresponding IaasProvider.
- */
- private Map<String, IaasProvider> partitionToIaasProvider = new ConcurrentHashMap<String, IaasProvider>();
-
- public Cartridge(){}
-
- public Cartridge(String type, String host, String provider, String version, boolean multiTenant) {
- this.type = type;
- this.hostName = host;
- this.provider = provider;
- this.version = version;
- this.multiTenant = multiTenant;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public void addIaasProvider(String partitionId, IaasProvider iaasProvider) {
- partitionToIaasProvider.put(partitionId, iaasProvider);
- }
-
- public void addIaasProviders(Map<String, IaasProvider> map) {
- for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext();) {
- String key = (String) iterator.next();
- IaasProvider value = map.get(key);
-
- partitionToIaasProvider.put(key, value);
- }
- }
-
- public IaasProvider getIaasProviderOfPartition(String partitionId) {
- return partitionToIaasProvider.get(partitionId);
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- public String getProperty(String key) {
- return properties.get(key);
- }
-
- public void setProperties(Map<String, String> properties) {
- this.properties = properties;
- }
-
- public void addIaasProvider(IaasProvider iaas) {
- for (IaasProvider anIaas : iaases) {
- if(anIaas.equals(iaas)){
- int idx = iaases.indexOf(anIaas);
- iaases.remove(idx);
- iaases.add(idx, iaas);
- return;
- }
- }
- this.iaases.add(iaas);
- }
-
- public IaasProvider getIaasProvider(String iaasType){
- for (IaasProvider iaas : iaases) {
- if(iaas.getType().equals(iaasType)){
- return iaas;
- }
- }
-
- return null;
- }
-
- public List<IaasProvider> getIaases() {
- return iaases;
- }
-
- public void setIaases(List<IaasProvider> iaases) {
- this.iaases = iaases;
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof Cartridge) {
- return this.type.equals(((Cartridge)obj).getType());
- }
- return false;
- }
-
- public int hashCode() {
- return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
- append(type).
- toHashCode();
- }
-
- public IaasProvider getLastlyUsedIaas() {
- return lastlyUsedIaas;
- }
-
- public void setLastlyUsedIaas(IaasProvider lastlyUsedIaas) {
- this.lastlyUsedIaas = lastlyUsedIaas;
- }
-
-// public boolean isJcloudsObjectsBuilt() {
-// return isJcloudsObjectsBuilt;
-// }
-//
-// public void setJcloudsObjectsBuilt(boolean isJcloudsObjectsBuilt) {
-// this.isJcloudsObjectsBuilt = isJcloudsObjectsBuilt;
-// }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getHostName() {
- return hostName;
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
- public void reset(){
-// lastlyUsedIaas = null;
- }
-
- public List<String> getDeploymentDirs() {
- return deploymentDirs;
- }
-
- public void setDeploymentDirs(List<String> deploymentDirs) {
- this.deploymentDirs = deploymentDirs;
- }
-
- public void addDeploymentDir(String dir){
- deploymentDirs.add(dir);
- }
-
- public void addPortMapping(PortMapping mapping){
- portMappings.add(mapping);
- }
-
- public void addAppType(AppType type){
- appTypeMappings.add(type);
- }
-
- public String getProvider() {
- return provider;
- }
-
- public void setProvider(String provider) {
- this.provider = provider;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public boolean isMultiTenant() {
- return multiTenant;
- }
-
- public void setMultiTenant(boolean multiTenant) {
- this.multiTenant = multiTenant;
- }
-
- public String getBaseDir() {
- return baseDir;
- }
-
- public void setBaseDir(String baseDir) {
- this.baseDir = baseDir;
- }
-
- public List<PortMapping> getPortMappings() {
- return portMappings;
- }
-
- public void setPortMappings(List<PortMapping> portMappings) {
- this.portMappings = portMappings;
- }
-
- public List<AppType> getAppTypeMappings() {
- return appTypeMappings;
- }
-
- public void setAppTypeMappings(List<AppType> appTypeMappings) {
- this.appTypeMappings = appTypeMappings;
- }
-
- public Map<String, IaasProvider> getPartitionToIaasProvider() {
- return partitionToIaasProvider;
- }
-
- public void setPartitionToIaasProvider(Map<String, IaasProvider> partitionToIaasProvider) {
- this.partitionToIaasProvider = partitionToIaasProvider;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java
deleted file mode 100644
index a9bc054..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInfo.java
+++ /dev/null
@@ -1,165 +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.cloud.controller.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.stratos.messaging.util.Property;
-
-/**
- * Holds useful information for externals, regarding a Cartridge.
- */
-public class CartridgeInfo {
-
- private String type;
-
- private String hostName;
-
- private String displayName;
-
- private String description;
-
- private String[] deploymentDirs;
-
- private PortMapping[] portMappings;
-
- private AppType[] appTypes;
-
- private String provider;
-
- private String version;
-
- private boolean multiTenant;
-
- private String baseDir;
-
- private Property[] properties;
-
- public CartridgeInfo(){
-
- }
-
- public CartridgeInfo(String type, String host, String desc, List<String> deploymentDirs, String provider) {
- this.type = type;
- this.hostName = host;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public String getHostName() {
- return hostName;
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
- public String[] getDeploymentDirs() {
- return deploymentDirs;
- }
-
- public void setDeploymentDirs(List<String> deploymentDirsList) {
- if(deploymentDirsList == null){
- deploymentDirsList = new ArrayList<String>();
- }
- this.deploymentDirs = new String[deploymentDirsList.size()];
-
- deploymentDirsList.toArray(deploymentDirs);
-
- }
-
- public String getProvider() {
- return provider;
- }
-
- public void setProvider(String provider) {
- this.provider = provider;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public boolean isMultiTenant() {
- return multiTenant;
- }
-
- public void setMultiTenant(boolean multiTenant) {
- this.multiTenant = multiTenant;
- }
-
- public String getBaseDir() {
- return baseDir;
- }
-
- public void setBaseDir(String baseDir) {
- this.baseDir = baseDir;
- }
-
- public PortMapping[] getPortMappings() {
- return portMappings;
- }
-
- public void setPortMappings(PortMapping[] portMappings) {
- this.portMappings = portMappings;
- }
-
- public AppType[] getAppTypes() {
- return appTypes;
- }
-
- public void setAppTypes(AppType[] appTypes) {
- this.appTypes = appTypes;
- }
-
- public Property[] getProperties() {
- return properties;
- }
-
- public void setProperties(Property[] properties) {
- this.properties = properties;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInstanceData.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInstanceData.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInstanceData.java
deleted file mode 100644
index a3507d3..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CartridgeInstanceData.java
+++ /dev/null
@@ -1,130 +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.cloud.controller.util;
-
-import org.jclouds.compute.domain.NodeMetadata;
-
-/**
- * This class holds the data to be published to BAM.
- */
-public class CartridgeInstanceData {
-
- // Cartridge type
- private String type;
-
- private String nodeId;
-
- private String domain;
-
- private String subDomain;
-
- private String iaas;
-
- private String status;
-
- private String tenantRange;
-
- private String alias;
-
- private boolean isMultiTenant;
-
- private NodeMetadata metaData;
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public String getNodeId() {
- return nodeId;
- }
-
- public void setNodeId(String nodeId) {
- this.nodeId = nodeId;
- }
-
- 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 getIaas() {
- return iaas;
- }
-
- public void setIaas(String iaas) {
- this.iaas = iaas;
- }
-
- public String getStatus() {
- return status;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public NodeMetadata getMetaData() {
- return metaData;
- }
-
- public void setMetaData(NodeMetadata metaData) {
- this.metaData = metaData;
- }
-
- public String getTenantRange() {
- return tenantRange;
- }
-
- public void setTenantRange(String tenantRange) {
- this.tenantRange = tenantRange;
- }
-
- public boolean isMultiTenant() {
- return isMultiTenant;
- }
-
- public void setMultiTenant(boolean isMultiTenant) {
- this.isMultiTenant = isMultiTenant;
- }
-
- public String getAlias() {
- return alias;
- }
-
- public void setAlias(String alias) {
- this.alias = alias;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
index 8eeef23..4b77fc5 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
@@ -21,7 +21,11 @@ package org.apache.stratos.cloud.controller.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.messaging.util.Property;
+import org.apache.stratos.cloud.controller.pojo.AppType;
+import org.apache.stratos.cloud.controller.pojo.Cartridge;
+import org.apache.stratos.cloud.controller.pojo.CartridgeInfo;
+import org.apache.stratos.cloud.controller.pojo.PortMapping;
+import org.apache.stratos.cloud.controller.pojo.Property;
import java.util.ArrayList;
import java.util.Iterator;
@@ -91,12 +95,12 @@ public class CloudControllerUtil {
* @return java.util.Properties
*/
public static Properties toJavaUtilProperties(
- org.apache.stratos.messaging.util.Properties properties) {
+ org.apache.stratos.cloud.controller.pojo.Properties properties) {
Properties javaProps = new Properties();
if (properties != null && properties.getProperties() != null) {
- for (org.apache.stratos.messaging.util.Property property : properties.getProperties()) {
+ for (org.apache.stratos.cloud.controller.pojo.Property property : properties.getProperties()) {
javaProps.put(property.getName(), property.getValue());
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java
deleted file mode 100644
index 3c2a27b..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/DataPublisherConfig.java
+++ /dev/null
@@ -1,80 +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.cloud.controller.util;
-
-/**
- * @author nirmal
- *
- */
-public class DataPublisherConfig {
-
- private String bamUsername = CloudControllerConstants.DEFAULT_BAM_SERVER_USER_NAME;
- private String bamPassword = CloudControllerConstants.DEFAULT_BAM_SERVER_PASSWORD;
- private String dataPublisherCron = CloudControllerConstants.PUB_CRON_EXPRESSION;
- private String cassandraConnUrl = CloudControllerConstants.DEFAULT_CASSANDRA_URL;
- private String cassandraUser = CloudControllerConstants.DEFAULT_CASSANDRA_USER;
- private String cassandraPassword = CloudControllerConstants.DEFAULT_CASSANDRA_PASSWORD;
-
- public String getBamUsername() {
- return bamUsername;
- }
-
- public void setBamUsername(String bamUsername) {
- this.bamUsername = bamUsername;
- }
-
- public String getBamPassword() {
- return bamPassword;
- }
-
- public void setBamPassword(String bamPassword) {
- this.bamPassword = bamPassword;
- }
-
- public String getDataPublisherCron() {
- return dataPublisherCron;
- }
-
- public void setDataPublisherCron(String dataPublisherCron) {
- this.dataPublisherCron = dataPublisherCron;
- }
- public String getCassandraConnUrl() {
- return cassandraConnUrl;
- }
-
- public void setCassandraConnUrl(String cassandraHostAddr) {
- this.cassandraConnUrl = cassandraHostAddr;
- }
-
- public String getCassandraUser() {
- return cassandraUser;
- }
-
- public void setCassandraUser(String cassandraUser) {
- this.cassandraUser = cassandraUser;
- }
-
- public String getCassandraPassword() {
- return cassandraPassword;
- }
-
- public void setCassandraPassword(String cassandraPassword) {
- this.cassandraPassword = cassandraPassword;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Host.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Host.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Host.java
deleted file mode 100644
index 8271042..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Host.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.apache.stratos.cloud.controller.util;
-
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.domain.Template;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class Host extends Zone {
- private String id;
- private String type;
- private Map<String, String> properties = new HashMap<String, String>();
-
- private transient ComputeService computeService;
-
- private transient Template template;
-
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, String> properties) {
- this.properties = properties;
- }
-
- public void setProperty(String key, String value) {
-
- if (key != null && value != null) {
- getProperties().put(key, value);
- }
- }
-
- public String getProperty(String key) {
- if(getProperties().get(key) != null) {
- return getProperties().get(key);
- } else {
- return super.getProperty(key);
- }
- }
-
- public ComputeService getComputeService() {
- return computeService;
- }
-
- public void setComputeService(ComputeService computeService) {
- this.computeService = computeService;
- }
-
- public Template getTemplate() {
- return template;
- }
-
- public void setTemplate(Template template) {
- this.template = template;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasContext.java
deleted file mode 100644
index a82c4e3..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasContext.java
+++ /dev/null
@@ -1,162 +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.cloud.controller.util;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jclouds.compute.domain.NodeMetadata;
-
-/**
- *
- * Holds runtime data of an IaaS
- */
-public class IaasContext implements Serializable{
-
- private static final long serialVersionUID = 3370272526949562217L;
-
- private String type;
-
- private List<String> nodeIds;
-
- /**
- * Key - node id
- * Value - public ip
- */
- private Map<String, String> nodeToPublicIp;
-
- /**
- * Key - node id
- * Value - NodeMetadata object which has information on this node.
- */
- private transient Map<String, NodeMetadata> nodes;
-
- private List<String> toBeRemovedNodeIds;
-
- public IaasContext(String iaasType) {
- this.type = iaasType;
- nodeToPublicIp = new HashMap<String, String>();
- nodeIds = new ArrayList<String>();
- nodes = new HashMap<String, NodeMetadata>();
- toBeRemovedNodeIds = new ArrayList<String>();
- }
-
- public Map<String, String> getNodeToPublicIp() {
- return nodeToPublicIp;
- }
-
- public Map<String, NodeMetadata> getNodes() {
- return nodes;
- }
-
- public void setToBeRemovedNodeIds(List<String> list) {
- this.toBeRemovedNodeIds = list;
- }
-
- public List<String> getAllNodeIds() {
- List<String> allNodeIds = new ArrayList<String>(nodeIds);
- allNodeIds.addAll(toBeRemovedNodeIds);
- return allNodeIds;
- }
-
- public List<String> getNodeIds() {
- return nodeIds;
- }
-
- public List<String> getToBeRemovedNodeIds() {
- return toBeRemovedNodeIds;
- }
-
- public boolean didISpawn(String nodeId) {
- if(nodeIds.contains(nodeId) || toBeRemovedNodeIds.contains(nodeId)){
- return true;
- }
- return false;
- }
-
- public void addNodeId(String nodeId) {
- nodeIds.add(nodeId);
- }
-
- public void addNodeToPublicIp(String nodeId, String publicIp) {
- nodeToPublicIp.put(nodeId, publicIp);
- }
-
- public void addToBeRemovedNodeId(String nodeId) {
- toBeRemovedNodeIds.add(nodeId);
- }
-
- public void removeNodeId(String nodeId) {
- if(nodeIds.remove(nodeId)){
- toBeRemovedNodeIds.add(nodeId);
- }
- }
-
- public void removeToBeRemovedNodeId(String nodeId) {
- toBeRemovedNodeIds.remove(nodeId);
- }
-
- public void setNodeIds(List<String> nodeIds) {
- this.nodeIds = nodeIds;
- }
-
- public String lastlySpawnedNode() {
- return nodeIds.get(nodeIds.size()-1);
- }
-
- public void addNodeMetadata(NodeMetadata node) {
- if(nodes == null){
- nodes = new HashMap<String, NodeMetadata>();
- }
- nodes.put(node.getId(), node);
- }
-
- public void removeNodeMetadata(NodeMetadata node) {
- if (nodes != null) {
- nodes.remove(node.getId());
- }
- }
-
- public void removeNodeIdToPublicIp(String nodeId){
- nodeToPublicIp.remove(nodeId);
- }
-
- public NodeMetadata getNode(String nodeId) {
- if(nodes == null) {
- return null;
- }
- return nodes.get(nodeId);
- }
-
- public String getPublicIp(String nodeId){
- return nodeToPublicIp.get(nodeId);
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java
deleted file mode 100644
index 81f4c4b..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/IaasProvider.java
+++ /dev/null
@@ -1,271 +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.cloud.controller.util;
-
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.stratos.cloud.controller.interfaces.Iaas;
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.domain.Template;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This is the basic data structure which holds an IaaS specific details.
- * NOTE: If you add a new attribute, please assign it in the constructor too.
- */
-public class IaasProvider implements Serializable{
-
- private static final long serialVersionUID = -940288190885166118L;
-
- /**
- * Type of the IaasProvider.
- */
- private String type;
-
- private List<Region> listOfRegions;
-
- /**
- * Fully qualified class name of an implementation of {@link org.apache.stratos.cloud.controller.interfaces.Iaas}
- */
- private String className;
-
- /**
- * human description of this IaaS provider
- */
- private String name;
-
- /**
- * Property map of this IaaS provider.
- */
- private Map<String, String> properties = new HashMap<String, String>();
-
- /**
- * Image identifier.
- */
- private String image;
-
-
- /**
- * Scale up order and scale down order of the IaaS.
- */
- private int scaleUpOrder = -1, scaleDownOrder = -1;
-
- private String provider, identity, credential;
-
- private transient ComputeService computeService;
-
- private transient Template template;
-
- private byte[] payload;
-
- /**
- * Corresponding {@link org.apache.stratos.cloud.controller.interfaces.Iaas} implementation
- */
- private transient Iaas iaas;
-
- public IaasProvider(){}
-
- public IaasProvider(IaasProvider anIaasProvider){
- this.type = anIaasProvider.getType();
- this.name = anIaasProvider.getName();
- this.className = anIaasProvider.getClassName();
- this.properties = anIaasProvider.getProperties();
- this.image = anIaasProvider.getImage();
- this.scaleUpOrder = anIaasProvider.getScaleUpOrder();
- this.scaleDownOrder = anIaasProvider.getScaleDownOrder();
- this.provider = anIaasProvider.getProvider();
- this.identity = anIaasProvider.getIdentity();
- this.credential = anIaasProvider.getCredential();
- this.computeService = anIaasProvider.getComputeService();
- this.template = anIaasProvider.getTemplate();
- this.payload = anIaasProvider.getPayload();
- this.iaas = anIaasProvider.getIaas();
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String id) {
- this.type = id;
- }
-
- public String getProperty(String key) {
- return properties.get(key);
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- public void setProperty(String key, String value) {
-
- if(key != null && value != null){
- properties.put(key, value);
- }
- }
-
- public void setProperties(Map<String, String> properties) {
- this.properties = properties;
- }
-
- public String getImage() {
- return image;
- }
-
- public void setImage(String image) {
- this.image = image;
- }
-
- public int getScaleUpOrder() {
- return scaleUpOrder;
- }
-
- public void setScaleUpOrder(int scaleUpOrder) {
- this.scaleUpOrder = scaleUpOrder;
- }
-
- public int getScaleDownOrder() {
- return scaleDownOrder;
- }
-
- public void setScaleDownOrder(int scaleDownOrder) {
- this.scaleDownOrder = scaleDownOrder;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getProvider() {
- return provider;
- }
-
- public void setProvider(String provider) {
- this.provider = provider;
- }
-
- public String getIdentity() {
- return identity;
- }
-
- public void setIdentity(String identity) {
- this.identity = identity;
- }
-
- public String getCredential() {
- return credential;
- }
-
- public void setCredential(String credential) {
- this.credential = credential;
- }
-
- public ComputeService getComputeService() {
- return computeService;
- }
-
- public void setComputeService(ComputeService computeService) {
- this.computeService = computeService;
- }
-
- public Template getTemplate() {
- return template;
- }
-
- public void setTemplate(Template template) {
- this.template = template;
- }
-
-
-
- public boolean equals(Object o) {
- if(o instanceof IaasProvider){
- return ((IaasProvider) o).getType().equals(this.getType());
- }
-
- return false;
- }
-
- public int hashCode() {
- return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
- append(type).
- toHashCode();
- }
-
- public IaasProvider copy(){
- return new IaasProvider(this);
- }
-
- public String getClassName() {
- return className;
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- public byte [] getPayload() {
- return payload;
- }
-
- public void setPayload(byte[]payload) {
- this.payload = payload;
- }
-
- public Iaas getIaas() {
- return iaas;
- }
-
- public void setIaas(Iaas iaas) {
- this.iaas = iaas;
- }
-
- public void reset(){
-// nodeIds = new ArrayList<String>();
-// nodes = new HashMap<String, NodeMetadata>();
-// toBeRemovedNodeIds = new ArrayList<String>();
- }
-
- /**
- * Partition the IaaS using different region
- */
- public List<Region> getListOfRegions() {
- return listOfRegions;
- }
-
- public void setListOfRegions(List<Region> listOfRegions) {
- this.listOfRegions = listOfRegions;
- }
-
- public void addRegion(Region region) {
- this.listOfRegions.add(region);
- }
-
- public void removeRegion(Region region) {
- this.listOfRegions.remove(region);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/LocationScope.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/LocationScope.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/LocationScope.java
deleted file mode 100644
index d29ced2..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/LocationScope.java
+++ /dev/null
@@ -1,70 +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.cloud.controller.util;
-
-/**
- * this contains the scope of a IaaS spanned across the geography.
- */
-public class LocationScope {
- private String zone;
- private String network;
- private String host;
- private String region;
- private String cloud;
-
- public String getZone() {
- return zone;
- }
-
- public void setZone(String zone) {
- this.zone = zone;
- }
-
- public String getNetwork() {
- return network;
- }
-
- public void setNetwork(String network) {
- this.network = network;
- }
-
- public String getHost() {
- return host;
- }
-
- public void setHost(String host) {
- this.host = host;
- }
-
- public String getRegion() {
- return region;
- }
-
- public void setRegion(String region) {
- this.region = region;
- }
-
- public String getCloud() {
- return cloud;
- }
-
- public void setCloud(String cloud) {
- this.cloud = cloud;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PortMapping.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PortMapping.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PortMapping.java
deleted file mode 100644
index 9f9a0e4..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PortMapping.java
+++ /dev/null
@@ -1,64 +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.cloud.controller.util;
-
-import java.io.Serializable;
-
-public class PortMapping implements Serializable{
-
- private static final long serialVersionUID = -5387564414633460306L;
- private String protocol;
- private String port;
- private String proxyPort;
-
- public PortMapping(){
-
- }
-
- public PortMapping(String protocol, String port, String proxyPort){
- this.protocol = protocol;
- this.port = port;
- this.proxyPort = proxyPort;
- }
-
- public String getProtocol() {
- return protocol;
- }
-
- public void setProtocol(String protocol) {
- this.protocol = protocol;
- }
-
- public String getPort() {
- return port;
- }
-
- public void setPort(String port) {
- this.port = port;
- }
-
- public String getProxyPort() {
- return proxyPort;
- }
-
- public void setProxyPort(String proxyPort) {
- this.proxyPort = proxyPort;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Region.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Region.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Region.java
deleted file mode 100644
index 561285a..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Region.java
+++ /dev/null
@@ -1,125 +0,0 @@
-package org.apache.stratos.cloud.controller.util;
-
-import org.jclouds.compute.ComputeService;
-import org.jclouds.compute.domain.Template;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class Region extends IaasProvider {
- private String imageId;
- private String identity;
- private String credential;
- private String id;
- private String type;
- private List<Zone> listOfZones;
-
- private transient ComputeService computeService;
-
- private transient Template template;
-
- private Map<String, String> properties = new HashMap<String, String>();
-
- public String getProperty(String key) {
- if(getProperties().get(key) != null) {
- return getProperties().get(key);
- } else {
- return super.getProperty(key);
- }
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- public void setProperty(String key, String value) {
-
- if (key != null && value != null) {
- getProperties().put(key, value);
- }
- }
-
- public void setProperties(Map<String, String> properties) {
- this.properties = properties;
- }
-
-
- public String getImageId() {
- return imageId;
- }
-
- public void setImageId(String imageId) {
- this.imageId = imageId;
- }
-
- public String getIdentity() {
- if(identity == null) {
- return super.getIdentity();
- }
- return identity;
- }
-
- public void setIdentity(String identity) {
- this.identity = identity;
- }
-
- public String getCredential() {
- if(credential == null) {
- return super.getCredential();
- }
- return credential;
- }
-
- public void setCredential(String credential) {
- this.credential = credential;
- }
-
- public ComputeService getComputeService() {
- return computeService;
- }
-
- public void setComputeService(ComputeService computeService) {
- this.computeService = computeService;
- }
-
- public Template getTemplate() {
- return template;
- }
-
- public void setTemplate(Template template) {
- this.template = template;
- }
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public List<Zone> getListOfZones() {
- return listOfZones;
- }
-
- public void setListOfZones(List<Zone> listOfZones) {
- this.listOfZones = listOfZones;
- }
-
- public void addZone(Zone zone) {
- this.listOfZones.add(zone);
- }
-
- public void removeZone(Zone zone) {
- this.listOfZones.remove(zone);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/2eaac66e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java
deleted file mode 100644
index 0b4c4a2..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceContext.java
+++ /dev/null
@@ -1,382 +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.cloud.controller.util;
-
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.messaging.domain.policy.Partition;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import java.io.*;
-import java.util.*;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-/**
- * We keep information regarding a service (i.e. a cartridge instance)
- * in this object.
- */
-public class ServiceContext implements Serializable{
- private static Log log = LogFactory.getLog(ServiceContext.class);
-
- private static final long serialVersionUID = -6740964802890082678L;
- private File file;
- private String clusterId;
- private String tenantRange;
- private String hostName;
- private String payloadFilePath = "/tmp/" + CloudControllerConstants.PAYLOAD_NAME + ".zip";
- private String cartridgeType;
- private Cartridge cartridge;
- private StringBuilder payload;
- private String autoScalerPolicyName;
- private List<Partition> partitionList = new ArrayList<Partition>();
-
- /**
- * Key - Value pair.
- */
- private Map<String, String> properties = new HashMap<String, String>();
- /**
- * Key - IaaS Type
- * Value - {@link IaasContext} object
- */
- private Map<String, IaasContext> iaasCtxts = new HashMap<String, IaasContext>();
-
- public Map<String, IaasContext> getIaasCtxts() {
- return iaasCtxts;
- }
-
- public String getClusterId() {
- return clusterId;
- }
-
- public boolean setClusterId(String domainName) {
- if (!"".equals(domainName)) {
- this.clusterId = domainName;
- return true;
- }
-
- return false;
- }
-
- public void setProperty(String key, String value) {
- properties.put(key, value);
- }
-
- public String getProperty(String key) {
-
- if(properties.containsKey(key)){
- return properties.get(key);
- }
-
- return "";
- }
-
- public Map<String, String> getProperties() {
- return properties;
- }
-
- public void setProperties(Map<String, String> properties) {
- this.properties = properties;
- }
-
-
- public Cartridge getCartridge() {
- return cartridge;
- }
-
- public void setCartridge(Cartridge cartridge) {
- this.cartridge = cartridge;
- }
-
- public String getTenantRange() {
- return tenantRange;
- }
-
- public void setTenantRange(String tenantRange) {
- this.tenantRange = tenantRange;
- }
-
- public IaasContext addIaasContext(String iaasType){
- IaasContext ctxt = new IaasContext(iaasType);
- iaasCtxts.put(iaasType, ctxt);
- return ctxt;
- }
-
- public IaasContext getIaasContext(String type){
- return iaasCtxts.get(type);
- }
-
- public void setIaasContextMap(Map<String, IaasContext> map){
- iaasCtxts = map;
- }
-
- public String getPayloadFile() {
- return payloadFilePath;
- }
-
- public void setPayloadFile(String payloadFile) {
- this.payloadFilePath = payloadFile;
- }
-
- public String getHostName() {
- if(cartridge != null && (hostName == null || hostName.isEmpty())){
- return cartridge.getHostName();
- }
- return hostName;
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
- public String getCartridgeType() {
- return cartridgeType;
- }
-
- public void setCartridgeType(String cartridgeType) {
- this.cartridgeType = cartridgeType;
- }
-
- public StringBuilder getPayload() {
- return payload;
- }
-
- public void setPayload(StringBuilder payload) {
- this.payload = payload;
- }
-
- public File getFile() {
- return file;
- }
-
- public void setFile(File file) {
- this.file = file;
- }
-
- public String toXml() {
- String str = "<service domain=\"" + clusterId +
- "\" tenantRange=\"" + tenantRange + "\" policyName=\"" + autoScalerPolicyName + "\">\n" +
- "\t<cartridge type=\"" + cartridgeType +
- "\"/>\n" + "\t<host>" + hostName +
- "</host>\n" + "\t<payload>" + payload +
- "</payload>\n" +
- propertiesToXml() +
- "</service>";
- return str;
- }
-
- public String propertiesToXml() {
- StringBuilder builder = new StringBuilder("");
- for (Iterator<Map.Entry<String, String>> iterator = getProperties().entrySet().iterator(); iterator.hasNext();) {
- Map.Entry<String, String> prop = iterator.next();
-
- String key = prop.getKey();
- String value = prop.getValue();
- if (key != null) {
- builder.append("\t<property name=\""+key +"\" value=\"" + (value == null ? "" : value) +"\"/>\n");
- }
-
- }
-
- return builder.toString();
- }
-
- public byte[] generatePayload() {
- String payloadStringTempFile = "launch-params";
-
- FileWriter fstream;
- try {
- fstream = new FileWriter(payloadStringTempFile);
-
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
- BufferedWriter out = new BufferedWriter(fstream);
- try {
- out.write(payload.toString());
- out.close();
-
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
-
-
- FileInputStream fis;
- try {
- fis = new FileInputStream(payloadStringTempFile);
- } catch (FileNotFoundException e) {
- String msg = "Failed while persisting the payload of clusterId : "
- + clusterId;
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(this.payloadFilePath);
-
- } catch (FileNotFoundException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
-
- ZipOutputStream zos = new ZipOutputStream(fos);
- addToZipFile(System.getProperty("user.dir"), payloadStringTempFile, zos);
-
- File folder = new File(CarbonUtils.getCarbonHome() + File.separator
- + "repository" + File.separator + "resources" + File.separator
- + "user-data");
-
- if(folder != null && folder.exists()) {
- for (File fileEntry : folder.listFiles()) {
- if (fileEntry != null && !fileEntry.isDirectory()) {
- addToZipFile(folder.getPath(), fileEntry.getName(), zos);
- }
- }
- }
-
- try {
- zos.close();
- fos.close();
-
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
- byte [] payloadData = null;
- File file = null;
- FileInputStream fileInputStream = null;
- try {
- file = new File(payloadFilePath);
- payloadData = new byte[(int)file.length()];
- fileInputStream = new FileInputStream(file);
- try {
- fileInputStream.read(payloadData);
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
- } catch (FileNotFoundException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
- try {
- fileInputStream.close();
- file.delete();
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
-
- return payloadData;
- }
-
- /**
- * Adds content to a zip file
- *
- * @param dir Name of directory
- * @param fileName Name of file to add
- * @param zos ZipOutputStream subscription to write
- * @throws CloudControllerException in an error
- */
- private void addToZipFile(String dir, String fileName, ZipOutputStream zos) throws CloudControllerException {
-
- log.info("Writing '" + fileName + "' to zip file");
-
- File file = new File(dir + File.separator + fileName);
- FileInputStream fis;
- try {
- fis = new FileInputStream(file);
-
- } catch (FileNotFoundException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
-
- ZipEntry zipEntry = new ZipEntry(fileName);
- try {
- zos.putNextEntry(zipEntry);
-
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
-
- byte[] bytes = new byte[1024];
- int length;
-
- try {
- while ((length = fis.read(bytes)) >= 0) {
- zos.write(bytes, 0, length);
- }
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
-
- try {
- zos.closeEntry();
- fis.close();
-
- } catch (IOException e) {
- log.error(e.getMessage());
- throw new CloudControllerException(e.getMessage(), e);
- }
- }
-
- public boolean equals(Object obj) {
- if (obj instanceof ServiceContext) {
- return this.clusterId.equals(((ServiceContext) obj).getClusterId());
- }
- return false;
- }
-
- public int hashCode() {
- return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
- append(clusterId).
- toHashCode();
- }
-
- public String getAutoScalerPolicyName() {
- return autoScalerPolicyName;
- }
-
- public void setAutoScalerPolicyName(String autoScalerPolicyName) {
- this.autoScalerPolicyName = autoScalerPolicyName;
- }
-
- public List<Partition> getPartitionList() {
- return partitionList;
- }
-
- public void setPartitionList(List<Partition> partitionList) {
- this.partitionList = partitionList;
- }
-
- public void addPartition(Partition partition) {
- this.partitionList.add(partition);
- }
-
- public void removePartition(Partition partition) {
- this.partitionList.remove(partition);
- }
-}