You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by re...@apache.org on 2013/11/08 12:29:23 UTC
[1/5] introducing partitions into the cloud contrller
Updated Branches:
refs/heads/master 6772f9ac8 -> b0ec40cf1
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
index ddaaf83..ec0e198 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
@@ -18,21 +18,21 @@
*/
package org.apache.stratos.cloud.controller.deployers;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.deployment.AbstractDeployer;
import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.deployment.repository.util.DeploymentFileData;
-import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
-import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
+import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.stratos.cloud.controller.util.IaasProvider;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
/**
* All the {@link IaasProvider}s will get deployed / undeployed / updated via this class.
*/
@@ -72,6 +72,7 @@ public class CloudControllerDeployer extends AbstractDeployer{
// load iaases
parser.setIaasProvidersList();
+ parser.setPartitionsList();
parser.setDataPublisherRelatedData();
parser.setTopologySyncRelatedData();
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/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 15a3dd8..c525acc 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
@@ -39,17 +39,17 @@ public class TopologyBuilder {
private static final Log log = LogFactory.getLog(TopologyBuilder.class);
- public static void handleServiceCreated(List<Cartridge> cartridgeList) {
+ public static void handleServiceCreated(List<Cartridge> cartridgeList) {
Service service;
Topology topology = TopologyManager.getInstance().getTopology();
- if(cartridgeList == null) {
+ if (cartridgeList == null) {
throw new RuntimeException(String.format("Cartridge list is empty"));
}
try {
TopologyManager.getInstance().acquireWriteLock();
- for(Cartridge cartridge : cartridgeList) {
- if(!topology.serviceExists(cartridge.getType())) {
- service = new Service(cartridge.getType());
+ for (Cartridge cartridge : cartridgeList) {
+ if (!topology.serviceExists(cartridge.getType())) {
+ service = new Service(cartridge.getType());
topology.addService(service);
TopologyManager.getInstance().updateTopology(topology);
}
@@ -61,12 +61,61 @@ public class TopologyBuilder {
}
- public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
+ 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);
+ } finally {
+ TopologyManager.getInstance().releaseWriteLock();
+ }
+ TopologyEventSender.sendPartitionCreatedEvent(partition);
+
+ }
+
+ public static void handlePartitionUpdated(Partition newPartition, Partition oldPartition) {
+
+ Topology topology = TopologyManager.getInstance().getTopology();
+ if (newPartition == null || oldPartition == null) {
+ throw new RuntimeException(String.format("Partition is empty"));
+ }
+ try {
+ TopologyManager.getInstance().acquireWriteLock();
+ topology.removePartition(oldPartition);
+ topology.addPartition(newPartition);
+ } finally {
+ TopologyManager.getInstance().releaseWriteLock();
+ }
+ TopologyEventSender.sendPartitionUpdatedEvent(newPartition, oldPartition.getId());
+
+ }
+
+ public static void handlePartitionRemoved(Partition partition) {
+
+ Topology topology = TopologyManager.getInstance().getTopology();
+ if (partition == null) {
+ throw new RuntimeException(String.format("Partition is empty"));
+ }
+ try {
+ TopologyManager.getInstance().acquireWriteLock();
+ topology.removePartition(partition);
+ } finally {
+ TopologyManager.getInstance().releaseWriteLock();
+ }
+ TopologyEventSender.sendPartitionRemovedEvent(partition);
+ }
+
+
+ public static void handleServiceRemoved(List<Cartridge> cartridgeList) {
Topology topology = TopologyManager.getInstance().getTopology();
- for(Cartridge cartridge : cartridgeList) {
- if(topology.getService(cartridge.getType()).getClusters().size() == 0) {
- if(topology.serviceExists(cartridge.getType())) {
+ for (Cartridge cartridge : cartridgeList) {
+ if (topology.getService(cartridge.getType()).getClusters().size() == 0) {
+ if (topology.serviceExists(cartridge.getType())) {
try {
TopologyManager.getInstance().acquireWriteLock();
topology.removeService(cartridge.getType());
@@ -87,59 +136,59 @@ public class TopologyBuilder {
public static void handleClusterCreated(ServiceContext serviceContext) {
Topology topology = TopologyManager.getInstance().getTopology();
- Service service;
- try {
- TopologyManager.getInstance().acquireWriteLock();
- service = topology.getService(serviceContext.getCartridgeType());
- if(service == null) {
- service = new Service(serviceContext.getClusterId());
+ Service service;
+ try {
+ TopologyManager.getInstance().acquireWriteLock();
+ service = topology.getService(serviceContext.getCartridgeType());
+ if (service == null) {
+ service = new Service(serviceContext.getClusterId());
+ Cluster cluster = new Cluster(serviceContext.getCartridgeType(),
+ serviceContext.getClusterId(),
+ serviceContext.getAutoScalerPolicyName());
+ cluster.setHostName(serviceContext.getHostName());
+ cluster.setTenantRange(serviceContext.getTenantRange());
+ cluster.setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
+ service.addCluster(cluster);
+ topology.addService(service);
+ } else {
+ if (service.clusterExists(serviceContext.getClusterId())) {
+ //update the cluster
+ service.getCluster(serviceContext.getClusterId()).
+ setHostName(serviceContext.getHostName());
+ service.getCluster(serviceContext.getClusterId()).
+ setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
+ service.getCluster(serviceContext.getClusterId()).
+ setTenantRange(serviceContext.getTenantRange());
+ } else {
Cluster cluster = new Cluster(serviceContext.getCartridgeType(),
- serviceContext.getClusterId(),
- serviceContext.getAutoScalerPolicyName());
+ serviceContext.getClusterId(),
+ serviceContext.getAutoScalerPolicyName());
cluster.setHostName(serviceContext.getHostName());
cluster.setTenantRange(serviceContext.getTenantRange());
cluster.setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
service.addCluster(cluster);
- topology.addService(service);
- } else {
- if (service.clusterExists(serviceContext.getClusterId())) {
- //update the cluster
- service.getCluster(serviceContext.getClusterId()).
- setHostName(serviceContext.getHostName());
- service.getCluster(serviceContext.getClusterId()).
- setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
- service.getCluster(serviceContext.getClusterId()).
- setTenantRange(serviceContext.getTenantRange());
- } else {
- Cluster cluster = new Cluster(serviceContext.getCartridgeType(),
- serviceContext.getClusterId(),
- serviceContext.getAutoScalerPolicyName());
- cluster.setHostName(serviceContext.getHostName());
- cluster.setTenantRange(serviceContext.getTenantRange());
- cluster.setAutoscalePolicyName(serviceContext.getAutoScalerPolicyName());
- service.addCluster(cluster);
- }
}
- TopologyManager.getInstance().updateTopology(topology);
- TopologyEventSender.sendClusterCreatedEvent(serviceContext);
+ }
+ TopologyManager.getInstance().updateTopology(topology);
+ TopologyEventSender.sendClusterCreatedEvent(serviceContext);
- } finally {
- TopologyManager.getInstance().releaseWriteLock();
- }
+ } finally {
+ TopologyManager.getInstance().releaseWriteLock();
+ }
}
public static void handleClusterRemoved(ServiceContext serviceContext) {
Topology topology = TopologyManager.getInstance().getTopology();
Service service = topology.getService(serviceContext.getCartridgeType());
- if(service == null) {
+ if (service == null) {
throw new RuntimeException(String.format("Service %s does not exist",
- serviceContext.getCartridgeType()));
+ serviceContext.getCartridgeType()));
}
- if(!service.clusterExists(serviceContext.getClusterId())) {
+ if (!service.clusterExists(serviceContext.getClusterId())) {
throw new RuntimeException(String.format("Cluster %s does not exist for service %s",
- serviceContext.getClusterId(),
- serviceContext.getCartridgeType()));
+ serviceContext.getClusterId(),
+ serviceContext.getCartridgeType()));
}
try {
@@ -160,7 +209,7 @@ public class TopologyBuilder {
Cluster cluster = service.getCluster(clusterId);
//TODO adding the IaaS scope to the member
- if(cluster.memberExists(memberId)) {
+ if (cluster.memberExists(memberId)) {
throw new RuntimeException(String.format("Member %s already exists", memberId));
}
@@ -185,26 +234,26 @@ public class TopologyBuilder {
Service service = topology.getService(memberStartedEvent.getServiceName());
if (service == null) {
throw new RuntimeException(String.format("Service %s does not exist",
- memberStartedEvent.getServiceName()));
+ memberStartedEvent.getServiceName()));
}
if (!service.clusterExists(memberStartedEvent.getClusterId())) {
throw new RuntimeException(String.format("Cluster %s does not exist in service %s",
- memberStartedEvent.getClusterId(),
- memberStartedEvent.getServiceName()));
+ memberStartedEvent.getClusterId(),
+ memberStartedEvent.getServiceName()));
}
Member member = service.getCluster(memberStartedEvent.getClusterId()).
- getMember(memberStartedEvent.getMemberId());
+ getMember(memberStartedEvent.getMemberId());
if (member == null) {
throw new RuntimeException(String.format("Member %s does not exist",
memberStartedEvent.getMemberId()));
}
- try {
- TopologyManager.getInstance().acquireWriteLock();
- member.setStatus(MemberStatus.Starting);
- log.info("member started event adding status started");
+ try {
+ TopologyManager.getInstance().acquireWriteLock();
+ member.setStatus(MemberStatus.Starting);
+ log.info("member started event adding status started");
- TopologyManager.getInstance().updateTopology(topology);
+ TopologyManager.getInstance().updateTopology(topology);
} finally {
TopologyManager.getInstance().releaseWriteLock();
}
@@ -217,36 +266,36 @@ public class TopologyBuilder {
Cluster cluster = service.getCluster(memberActivatedEvent.getClusterId());
Member member = cluster.getMember(memberActivatedEvent.getMemberId());
- if(service == null) {
- throw new RuntimeException(String.format("Service %s does not exist",
- memberActivatedEvent.getServiceName()));
+ if (service == null) {
+ throw new RuntimeException(String.format("Service %s does not exist",
+ memberActivatedEvent.getServiceName()));
}
- if(cluster == null) {
+ if (cluster == null) {
throw new RuntimeException(String.format("Cluster %s does not exist",
- memberActivatedEvent.getClusterId()));
+ memberActivatedEvent.getClusterId()));
}
- if(member == null) {
+ if (member == null) {
throw new RuntimeException(String.format("Member %s does not exist",
- memberActivatedEvent.getMemberId()));
+ memberActivatedEvent.getMemberId()));
}
org.apache.stratos.messaging.event.topology.MemberActivatedEvent memberActivatedEventTopology =
- new org.apache.stratos.messaging.event.topology.MemberActivatedEvent(memberActivatedEvent.getServiceName(),
- memberActivatedEvent.getClusterId(), memberActivatedEvent.getMemberId());
+ new org.apache.stratos.messaging.event.topology.MemberActivatedEvent(memberActivatedEvent.getServiceName(),
+ memberActivatedEvent.getClusterId(), memberActivatedEvent.getMemberId());
try {
TopologyManager.getInstance().acquireWriteLock();
member.setStatus(MemberStatus.Activated);
log.info("member started event adding status activated");
Cartridge cartridge = FasterLookUpDataHolder.getInstance().
- getCartridge(memberActivatedEvent.getServiceName());
+ getCartridge(memberActivatedEvent.getServiceName());
List<PortMapping> portMappings = cartridge.getPortMappings();
Port port;
//adding ports to the event
- for(PortMapping portMapping : portMappings) {
+ for (PortMapping portMapping : portMappings) {
port = new Port(portMapping.getProtocol(),
Integer.parseInt(portMapping.getPort()),
Integer.parseInt(portMapping.getProxyPort()));
@@ -269,7 +318,7 @@ public class TopologyBuilder {
Member member = cluster.getMemberFromIaasNodeId(nodeId);
String memberId = member.getMemberId();
- if(member == null) {
+ if (member == null) {
throw new RuntimeException(String.format("Member with nodeID %s does not exist",
nodeId));
}
@@ -285,8 +334,8 @@ public class TopologyBuilder {
}
public static void handleMemberSuspended() {
- //TODO
- try {
+ //TODO
+ try {
TopologyManager.getInstance().acquireWriteLock();
} finally {
TopologyManager.getInstance().releaseWriteLock();
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/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 6e0e68a..09c1202 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
@@ -24,6 +24,7 @@ import org.apache.stratos.cloud.controller.util.Cartridge;
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.topology.Partition;
import org.apache.stratos.messaging.domain.topology.Port;
import org.apache.stratos.messaging.domain.topology.Topology;
import org.apache.stratos.messaging.event.Event;
@@ -56,6 +57,29 @@ public class TopologyEventSender {
}
}
+ public static void sendPartitionCreatedEvent(Partition partition) {
+ PartitionCreatedEvent partitionCreatedEvent =
+ new PartitionCreatedEvent(partition.getId(),
+ partition.getScope());
+ partitionCreatedEvent.setProperties(partition.getProperties());
+ publishEvent(partitionCreatedEvent);
+ }
+
+ public static void sendPartitionUpdatedEvent(Partition partition, String oldPartitionId) {
+ PartitionUpdatedEvent partitionUpdatedEvent =
+ new PartitionUpdatedEvent(partition.getId(),
+ partition.getScope(),
+ oldPartitionId);
+ partitionUpdatedEvent.setProperties(partition.getProperties());
+ publishEvent(partitionUpdatedEvent);
+ }
+
+ public static void sendPartitionRemovedEvent(Partition partition) {
+ PartitionRemovedEvent partitionRemovedEvent =
+ new PartitionRemovedEvent(partition.getId());
+ publishEvent(partitionRemovedEvent);
+ }
+
public static void sendServiceRemovedEvent(List<Cartridge> cartridgeList) {
ServiceRemovedEvent serviceRemovedEvent;
for(Cartridge cartridge : cartridgeList) {
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java
index 41c60eb..8d8d58a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyManager.java
@@ -19,14 +19,16 @@
package org.apache.stratos.cloud.controller.topology;
import com.google.gson.Gson;
+import org.apache.commons.io.FileUtils;
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.registry.RegistryManager;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
import org.apache.stratos.messaging.domain.topology.Topology;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
import javax.jms.TextMessage;
+import java.io.File;
+import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -37,9 +39,11 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
public class TopologyManager {
private static final Log log = LogFactory.getLog(TopologyManager.class);
- private volatile ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+ private volatile ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
private volatile ReentrantReadWriteLock.ReadLock readLock = lock.readLock();
private volatile ReentrantReadWriteLock.WriteLock writeLock = lock.writeLock();
+ private File topologyFile = new File(CloudControllerConstants.TOPOLOGY_FILE_PATH);
+ private File backup = new File(CloudControllerConstants.TOPOLOGY_FILE_PATH + ".back");
private volatile Topology topology;
private static TopologyManager instance;
private BlockingQueue<TextMessage> sharedTopologyDiffQueue = new LinkedBlockingQueue<TextMessage>();
@@ -72,17 +76,31 @@ public class TopologyManager {
}
public synchronized Topology getTopology() {
+ String currentContent = null;
synchronized (TopologyManager.class) {
- if (this.topology == null) {
+ if(this.topology == null) {
//need to initialize the topology
- this.topology = (Topology) RegistryManager.getInstance().retrieveTopology();
- if (this.topology == null) {
- //we never persisted the topology before
+ if(this.topologyFile.exists()) {
+ try {
+ currentContent = FileUtils.readFileToString(this.topologyFile);
+ Gson gson = new Gson();
+ this.topology = gson.fromJson(currentContent, Topology.class);
+ if(log.isDebugEnabled()) {
+ log.debug("The current topology is: " + currentContent);
+ }
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
+ }
+ } else {
+ if(log.isDebugEnabled()) {
+ log.debug("Creating new topology");
+ }
this.topology = new Topology();
}
}
}
- if (log.isDebugEnabled()) {
+ if(log.isDebugEnabled()) {
log.debug("The current topology is: " + toJson());
}
return this.topology;
@@ -90,23 +108,34 @@ public class TopologyManager {
public synchronized void updateTopology(Topology topology) {
synchronized (TopologyManager.class) {
- this.topology = topology;
- //Persist data in registry.
+ this.topology = topology;
+ if (this.topologyFile.exists()) {
+ this.backup.delete();
+ this.topologyFile.renameTo(backup);
+ }
+ Gson gson = new Gson();
+ String message = gson.toJson(topology);
+ // overwrite the topology file
try {
- RegistryManager.getInstance().persistTopology(
- TopologyManager.getInstance().getTopology());
- } catch (RegistryException e) {
-
- String msg = "Failed to persist the Cloud Controller data in registry. Further, transaction roll back also failed.";
- log.fatal(msg);
- throw new CloudControllerException(msg, e);
+ FileUtils.writeStringToFile(this.topologyFile, message);
+ if(log.isDebugEnabled()) {
+ log.debug("The updated topology is: " + message);
+ }
+ } catch (IOException e) {
+ log.error(e.getMessage());
+ throw new CloudControllerException(e.getMessage(), e);
}
}
+
+ }
+
+ public void setTopology(Topology topology) {
+ this.topology = topology;
}
public String toJson() {
Gson gson = new Gson();
- return gson.toJson(topology);
+ return gson.toJson(topology);
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
index 13bf788..25d6793 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerConstants.java
@@ -31,6 +31,10 @@ public final class CloudControllerConstants {
public static final String SERIALIZATION_DIR_ELEMENT = "serializationDir";
public static final String IAAS_PROVIDERS_ELEMENT = "iaasProviders";
public static final String IAAS_PROVIDER_ELEMENT = "iaasProvider";
+ public static final String PARTITION_ELEMENT = "partition";
+ public static final String PARTITIONS_ELEMENT = "partitions";
+ public static final String REGION_ELEMENT = "region";
+ public static final String ZONE_ELEMENT = "zone";
public static final String DEPLOYMENT_ELEMENT = "deployment";
public static final String PORT_MAPPING_ELEMENT = "portMapping";
public static final String APP_TYPES_ELEMENT = "appTypes";
@@ -60,6 +64,9 @@ public final class CloudControllerConstants {
public static final String MAX_INSTANCE_LIMIT_ELEMENT = "maxInstanceLimit";
public static final String PROVIDER_ELEMENT = "provider";
public static final String IDENTITY_ELEMENT = "identity";
+ public static final String TYPE_ELEMENT = "type";
+ public static final String SCOPE_ELEMENT = "type";
+ public static final String ID_ELEMENT = "id";
public static final String CREDENTIAL_ELEMENT = "credential";
public static final String DEFAULT_SERVICE_ELEMENT = "default";
public static final String SERVICE_ELEMENT = "service";
@@ -137,6 +144,15 @@ public final class CloudControllerConstants {
*/
public static final String IAAS_PROVIDER_XPATH = "/"+CLOUD_CONTROLLER_ELEMENT+"/"+
IAAS_PROVIDERS_ELEMENT+"/"+IAAS_PROVIDER_ELEMENT;
+ public static final String PARTITION_XPATH = "/"+CLOUD_CONTROLLER_ELEMENT+"/"+
+ PARTITIONS_ELEMENT+"/"+PARTITION_ELEMENT;
+ public static final String REGION_XPATH = "/"+CLOUD_CONTROLLER_ELEMENT+"/"+
+ IAAS_PROVIDERS_ELEMENT+"/"+IAAS_PROVIDER_ELEMENT + "/" + REGION_ELEMENT;
+ public static final String ZONE_XPATH = "/"+CLOUD_CONTROLLER_ELEMENT+"/"+
+ IAAS_PROVIDERS_ELEMENT+"/"+IAAS_PROVIDER_ELEMENT + REGION_ELEMENT + "/" + ZONE_ELEMENT;
+ public static final String HOST_XPATH = "/"+CLOUD_CONTROLLER_ELEMENT+"/"+
+ IAAS_PROVIDERS_ELEMENT+"/"+IAAS_PROVIDER_ELEMENT + REGION_ELEMENT + "/" + ZONE_ELEMENT
+ + "/" + HOST_ELEMENT ;
public static final String PROPERTY_ELEMENT_XPATH = "/"+PROPERTY_ELEMENT;
public static final String IMAGE_ID_ELEMENT_XPATH = "/"+IMAGE_ID_ELEMENT;
public static final String SCALE_UP_ORDER_ELEMENT_XPATH = "/"+SCALE_UP_ORDER_ELEMENT;
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/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
new file mode 100644
index 0000000..6a001d6
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Host.java
@@ -0,0 +1,46 @@
+package org.apache.stratos.cloud.controller.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Host {
+ private String id;
+ private String type;
+ private Map<String, String> properties = new HashMap<String, String>();
+
+
+ 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) {
+ return getProperties().get(key);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Zone.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Zone.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Zone.java
index 41831cf..168629d 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Zone.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/Zone.java
@@ -1,11 +1,13 @@
package org.apache.stratos.cloud.controller.util;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
public class Zone {
private String id;
private String type;
+ private List<Host> listOfHosts;
private Map<String, String> properties = new HashMap<String, String>();
@@ -43,4 +45,20 @@ public class Zone {
public String getProperty(String key) {
return getProperties().get(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);
+ }
}
[4/5] git commit: initialize the map
Posted by re...@apache.org.
initialize the map
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/fd027662
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/fd027662
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/fd027662
Branch: refs/heads/master
Commit: fd02766294223e71c9bba93b18973e07b541465f
Parents: e3c9535
Author: rekathiru <rt...@gmail.com>
Authored: Fri Nov 8 16:58:31 2013 +0530
Committer: rekathiru <rt...@gmail.com>
Committed: Fri Nov 8 16:58:31 2013 +0530
----------------------------------------------------------------------
.../java/org/apache/stratos/messaging/domain/topology/Topology.java | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/fd027662/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
index 450df23..2bb560a 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java
@@ -34,6 +34,7 @@ public class Topology implements Serializable {
public Topology() {
this.serviceMap = new HashMap<String, Service>();
+ partitionMap = new HashMap<String, Partition>();
}
public Collection<Service> getServices() {
[2/5] introducing partitions into the cloud contrller
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/e3c9535c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/axiom/AxiomXpathParser.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/axiom/AxiomXpathParser.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/axiom/AxiomXpathParser.java
index bd387d1..31abf60 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/axiom/AxiomXpathParser.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/axiom/AxiomXpathParser.java
@@ -18,6 +18,7 @@
*/
package org.apache.stratos.cloud.controller.axiom;
+import com.google.gson.Gson;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNode;
@@ -30,7 +31,9 @@ import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.exception.CloudControllerException;
import org.apache.stratos.cloud.controller.exception.MalformedConfigurationFileException;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
+import org.apache.stratos.cloud.controller.topology.TopologyManager;
import org.apache.stratos.cloud.controller.util.*;
+import org.apache.stratos.messaging.domain.topology.Partition;
import org.jaxen.JaxenException;
import org.w3c.dom.Element;
import org.wso2.securevault.SecretResolver;
@@ -46,204 +49,201 @@ import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* This class is parsing configuration files using Axiom Xpath.
*/
public class AxiomXpathParser {
- private static final Log log = LogFactory.getLog(AxiomXpathParser.class);
- private OMElement documentElement;
- private final File xmlSource;
+ private static final Log log = LogFactory.getLog(AxiomXpathParser.class);
+ private OMElement documentElement;
+ private final File xmlSource;
- public AxiomXpathParser(final File xmlFile) {
- xmlSource = xmlFile;
- }
+ public AxiomXpathParser(final File xmlFile) {
+ xmlSource = xmlFile;
+ }
- /**
+ /**
* @param cartridgeElementString Cartridges section as a {@link String}
- * @param aCartridge {@link org.apache.stratos.cloud.controller.util.Cartridge} instance.
- * @param appTypesNodes nodes of App types.
+ * @param aCartridge {@link org.apache.stratos.cloud.controller.util.Cartridge} instance.
+ * @param appTypesNodes nodes of App types.
*/
private void getAppTypes(String cartridgeElementString, Cartridge aCartridge,
List<?> appTypesNodes) {
- Object nodeObj;
- if (!appTypesNodes.isEmpty()) {
- if ((nodeObj = appTypesNodes.get(0)) instanceof OMNode) {
- OMNode appTypeNode = (OMNode) nodeObj;
-
- if (appTypeNode.getType() == OMNode.ELEMENT_NODE) {
-
- OMElement appTypesElt = (OMElement) appTypeNode;
-
- for (Iterator<?> iterator =
- appTypesElt.getChildrenWithName(new QName(
- CloudControllerConstants.APP_TYPE_ELEMENT)); iterator.hasNext();) {
- OMElement appElt = (OMElement) iterator.next();
-
- String name =
- appElt.getAttributeValue(new QName(
- CloudControllerConstants.NAME_ATTR));
- String appSpecificMapping =
- appElt.getAttributeValue(new QName(
- CloudControllerConstants.APP_SPECIFIC_MAPPING_ATTR));
-
- AppType appType;
-
- if (appSpecificMapping == null) {
- appType = new AppType(name);
- } else {
- appType =
- new AppType(name,
- Boolean.valueOf(appSpecificMapping));
- }
-
- aCartridge.addAppType(appType);
- }
-
- } else {
- String msg =
- "Essential '" + CloudControllerConstants.APP_TYPE_ELEMENT +
- "' element cannot" + " be found in " +
- cartridgeElementString + " of " +
- xmlSource;
- handleException(msg);
- }
-
- }
- }
+ Object nodeObj;
+ if (!appTypesNodes.isEmpty()) {
+ if ((nodeObj = appTypesNodes.get(0)) instanceof OMNode) {
+ OMNode appTypeNode = (OMNode) nodeObj;
+
+ if (appTypeNode.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement appTypesElt = (OMElement) appTypeNode;
+
+ for (Iterator<?> iterator =
+ appTypesElt.getChildrenWithName(new QName(
+ CloudControllerConstants.APP_TYPE_ELEMENT)); iterator.hasNext();) {
+ OMElement appElt = (OMElement) iterator.next();
+
+ String name =
+ appElt.getAttributeValue(new QName(
+ CloudControllerConstants.NAME_ATTR));
+ String appSpecificMapping =
+ appElt.getAttributeValue(new QName(
+ CloudControllerConstants.APP_SPECIFIC_MAPPING_ATTR));
+
+ AppType appType;
+
+ if (appSpecificMapping == null) {
+ appType = new AppType(name);
+ } else {
+ appType =
+ new AppType(name,
+ Boolean.valueOf(appSpecificMapping));
+ }
+
+ aCartridge.addAppType(appType);
+ }
+
+ } else {
+ String msg =
+ "Essential '" + CloudControllerConstants.APP_TYPE_ELEMENT +
+ "' element cannot" + " be found in " +
+ cartridgeElementString + " of " +
+ xmlSource;
+ handleException(msg);
+ }
+
+ }
+ }
}
- /**
- * @return a List of {@link Cartridge}s.
- */
- public List<Cartridge> getCartridgesList() {
+ /**
+ * @return a List of {@link Cartridge}s.
+ */
+ public List<Cartridge> getCartridgesList() {
+
+ FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+
+ List<IaasProvider> iaasProviders = dataHolder.getIaasProviders();
+
+ if (iaasProviders == null) {
+ dataHolder.setIaasProviders((iaasProviders = new ArrayList<IaasProvider>()));
+ }
+
+ List<Cartridge> cartridges = new ArrayList<Cartridge>();
- FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+ String xpath = CloudControllerConstants.CARTRIDGES_ELEMENT_XPATH;
- List<IaasProvider> iaasProviders = dataHolder.getIaasProviders();
+ // cartridges can be found from this XPATH
+ List<?> cartridgeNodes = getMatchingNodes(xpath, documentElement);
- if (iaasProviders == null) {
- dataHolder.setIaasProviders((iaasProviders = new ArrayList<IaasProvider>()));
- }
+ if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
+ // or from this XPATH
+ xpath = CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH;
+ cartridgeNodes = getMatchingNodes(xpath, documentElement);
+ }
- List<Cartridge> cartridges = new ArrayList<Cartridge>();
+ if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
+ log.warn("No cartridge found in this configuration file : " + xmlSource.getPath());
+ return cartridges;
+ }
- String xpath = CloudControllerConstants.CARTRIDGES_ELEMENT_XPATH;
-
- // cartridges can be found from this XPATH
- List<?> cartridgeNodes = getMatchingNodes(xpath, documentElement);
+ for (Object obj : cartridgeNodes) {
- if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
- // or from this XPATH
- xpath = CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH;
- cartridgeNodes = getMatchingNodes(xpath, documentElement);
- }
+ if (obj instanceof OMNode) {
+ OMNode cartridgeNode = (OMNode) obj;
- if (cartridgeNodes == null || cartridgeNodes.isEmpty()) {
- log.warn("No cartridge found in this configuration file : " + xmlSource.getPath());
- return cartridges;
- }
+ if (cartridgeNode.getType() == OMNode.ELEMENT_NODE) {
- for (Object obj : cartridgeNodes) {
+ OMElement cartridgeElement = (OMElement) cartridgeNode;
- if (obj instanceof OMNode) {
- OMNode cartridgeNode = (OMNode) obj;
+ // retrieve Attributes of a Cartridge definition
+ String type = cartridgeElement.getAttributeValue(new QName(
+ CloudControllerConstants.TYPE_ATTR));
+ String host = cartridgeElement.getAttributeValue(new QName(
+ CloudControllerConstants.HOST_ATTR));
+ String provider = cartridgeElement.getAttributeValue(new QName(
+ CloudControllerConstants.PROVIDER_ATTR));
- if (cartridgeNode.getType() == OMNode.ELEMENT_NODE) {
+ String version =
+ cartridgeElement.getAttributeValue(new QName(
+ CloudControllerConstants.VERSION_ATTR));
- OMElement cartridgeElement = (OMElement) cartridgeNode;
+ boolean multiTenant = Boolean.valueOf(cartridgeElement.getAttributeValue(new QName(
+ CloudControllerConstants.MULTI_TENANT_ATTR)));
- // retrieve Attributes of a Cartridge definition
- String type = cartridgeElement.getAttributeValue(new QName(
- CloudControllerConstants.TYPE_ATTR));
- String host = cartridgeElement.getAttributeValue(new QName(
- CloudControllerConstants.HOST_ATTR));
- String provider = cartridgeElement.getAttributeValue(new QName(
- CloudControllerConstants.PROVIDER_ATTR));
-
- String version =
- cartridgeElement.getAttributeValue(new QName(
- CloudControllerConstants.VERSION_ATTR));
+ Cartridge aCartridge;
- boolean multiTenant = Boolean.valueOf(cartridgeElement.getAttributeValue(new QName(
- CloudControllerConstants.MULTI_TENANT_ATTR)));
+ if ((aCartridge = dataHolder.getCartridge(type)) == null) {
- Cartridge aCartridge;
+ aCartridge = new Cartridge(type, host, provider, version, multiTenant);
+ }
- if ((aCartridge = dataHolder.getCartridge(type)) == null) {
+ // read displayName
+ Iterator<?> itName =
+ cartridgeElement.getChildrenWithName(new QName(
+ CloudControllerConstants.DISPLAY_NAME_ELEMENT));
- aCartridge = new Cartridge(type, host, provider, version, multiTenant);
- }
-
- // read displayName
- Iterator<?> itName =
- cartridgeElement.getChildrenWithName(new QName(
- CloudControllerConstants.DISPLAY_NAME_ELEMENT));
+ if (itName.hasNext()) {
+ OMElement name = (OMElement) itName.next();
- if (itName.hasNext()) {
- OMElement name = (OMElement) itName.next();
+ aCartridge.setDisplayName(name.getText());
+ }
- aCartridge.setDisplayName(name.getText());
- }
-
- // read description
- Iterator<?> it =
- cartridgeElement.getChildrenWithName(new QName(
- CloudControllerConstants.DESCRIPTION_ELEMENT));
+ // read description
+ Iterator<?> it =
+ cartridgeElement.getChildrenWithName(new QName(
+ CloudControllerConstants.DESCRIPTION_ELEMENT));
- if (it.hasNext()) {
- OMElement desc = (OMElement) it.next();
+ if (it.hasNext()) {
+ OMElement desc = (OMElement) it.next();
- aCartridge.setDescription(desc.getText());
- }
+ aCartridge.setDescription(desc.getText());
+ }
- // load properties of this cartridge
- loadProperties(cartridgeElement, aCartridge.getProperties());
+ // load properties of this cartridge
+ loadProperties(cartridgeElement, aCartridge.getProperties());
- // retrieve the list of IaaS providers
- List<?> iaasProviderNodes = getMatchingNodes(xpath + CloudControllerConstants.IAAS_PROVIDER_ELEMENT_XPATH,
- cartridgeElement);
+ // retrieve the list of IaaS providers
+ List<?> iaasProviderNodes = getMatchingNodes(xpath + CloudControllerConstants.IAAS_PROVIDER_ELEMENT_XPATH,
+ cartridgeElement);
- getIaasProviders(iaasProviders, cartridgeElement.toString(), aCartridge, iaasProviderNodes);
+ getIaasProviders(iaasProviders, cartridgeElement.toString(), aCartridge, iaasProviderNodes);
- // load dirs
- List<?> deploymentNodes = getMatchingNodes(xpath + CloudControllerConstants.DEPLOYMENT_ELEMENT_XPATH,
- cartridgeElement);
+ // load dirs
+ List<?> deploymentNodes = getMatchingNodes(xpath + CloudControllerConstants.DEPLOYMENT_ELEMENT_XPATH,
+ cartridgeElement);
setDeploymentDirs(cartridgeElement.toString(), aCartridge, deploymentNodes);
- // load port mappings
- List<?> portMappingNodes =
- getMatchingNodes(xpath +
- CloudControllerConstants.PORT_MAPPING_ELEMENT_XPATH,
- cartridgeElement);
- getPortMappings(cartridgeElement.toString(), aCartridge, portMappingNodes);
+ // load port mappings
+ List<?> portMappingNodes =
+ getMatchingNodes(xpath +
+ CloudControllerConstants.PORT_MAPPING_ELEMENT_XPATH,
+ cartridgeElement);
+ getPortMappings(cartridgeElement.toString(), aCartridge, portMappingNodes);
- // load appTypes
- List<?> appTypesNodes =
- getMatchingNodes(xpath +
- CloudControllerConstants.APP_TYPES_ELEMENT_XPATH,
- cartridgeElement);
- getAppTypes(cartridgeElement.toString(), aCartridge, appTypesNodes);
+ // load appTypes
+ List<?> appTypesNodes =
+ getMatchingNodes(xpath +
+ CloudControllerConstants.APP_TYPES_ELEMENT_XPATH,
+ cartridgeElement);
+ getAppTypes(cartridgeElement.toString(), aCartridge, appTypesNodes);
- cartridges.add(aCartridge);
+ cartridges.add(aCartridge);
- if (dataHolder.getCartridge(type) == null) {
- dataHolder.addCartridge(aCartridge);
- }
- }
- }
- }
+ if (dataHolder.getCartridge(type) == null) {
+ dataHolder.addCartridge(aCartridge);
+ }
+ }
+ }
+ }
- return cartridges;
+ return cartridges;
- }
+ }
- /**
+ /**
* @param iaasProviders
* @param cartridgeElementString
* @param aCartridge
@@ -252,996 +252,1507 @@ public class AxiomXpathParser {
private void getIaasProviders(List<IaasProvider> iaasProviders,
String cartridgeElementString, Cartridge aCartridge,
List<?> iaasProviderNodes) {
- for (Object nodeObj : iaasProviderNodes) {
- if (nodeObj instanceof OMNode) {
- OMNode iaasProviderNode = (OMNode) nodeObj;
+ for (Object nodeObj : iaasProviderNodes) {
+ if (nodeObj instanceof OMNode) {
+ OMNode iaasProviderNode = (OMNode) nodeObj;
+
+ if (iaasProviderNode.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement iaasElt = (OMElement) iaasProviderNode;
+
+ // add the IaasProvider to this cartridge
+ aCartridge.addIaasProvider(getIaasProvider(iaasElt, iaasProviders));
+
+ } else {
+ String msg =
+ "Essential '" +
+ CloudControllerConstants.IAAS_PROVIDER_ELEMENT +
+ "' element cannot" + " be found in " +
+ cartridgeElementString + " of " +
+ xmlSource;
+ handleException(msg);
+ }
+
+ }
+ }
+ }
+
+ private Element getDOMElement(final OMElement omElement) {
+
+ // Get the StAX reader from the created element
+ XMLStreamReader llomReader = omElement.getXMLStreamReader();
+
+ // Create the DOOM OMFactory
+ OMFactory doomFactory = DOOMAbstractFactory.getOMFactory();
+
+ // Create the new builder
+ StAXOMBuilder doomBuilder = new StAXOMBuilder(doomFactory, llomReader);
+
+ // Get the document element
+ OMElement newElem = doomBuilder.getDocumentElement();
+
+ return newElem instanceof Element ? (Element) newElem : null;
+ }
+
+ private OMElement getElement(final Object obj) {
+ OMNode node;
+ if ((obj instanceof OMNode) && (node = (OMNode) obj).getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement element = (OMElement) node;
+
+ return element;
- if (iaasProviderNode.getType() == OMNode.ELEMENT_NODE) {
+ }
- OMElement iaasElt = (OMElement) iaasProviderNode;
+ return null;
+ }
+
+ private OMElement getElement(final OMElement rootElt, final String eltStr, final String xpath) {
+ List<?> nodes = getMatchingNodes(xpath, rootElt);
+ neglectingWarn(eltStr, nodes.size());
+ OMElement element = getElement(nodes.get(0));
+ return element;
+ }
- // add the IaasProvider to this cartridge
- aCartridge.addIaasProvider(getIaasProvider(iaasElt, iaasProviders));
+ private OMElement getFirstChildElement(final OMElement root, final String childName) {
+ Iterator<?> it = root.getChildrenWithName(new QName(childName));
+ if (it.hasNext()) {
+ return (OMElement) it.next();
+ }
- } else {
- String msg =
- "Essential '" +
- CloudControllerConstants.IAAS_PROVIDER_ELEMENT +
- "' element cannot" + " be found in " +
- cartridgeElementString + " of " +
- xmlSource;
- handleException(msg);
- }
+ return null;
+ }
- }
- }
+ /**
+ * @param xpath XPATH expression to be read.
+ * @param elt OMElement to be used for the search.
+ * @return List matching OMNode list
+ */
+ @SuppressWarnings("unchecked")
+ public OMNode getFirstMatchingNode(final String xpath, final OMElement elt) {
+
+ AXIOMXPath axiomXpath;
+ List<OMNode> nodeList = null;
+ try {
+ axiomXpath = new AXIOMXPath(xpath);
+ nodeList = axiomXpath.selectNodes(elt);
+ } catch (JaxenException e) {
+ String msg = "Error occurred while reading the Xpath (" + xpath + ")";
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+
+ return nodeList != null ? nodeList.get(0) : null;
}
- private Element getDOMElement(final OMElement omElement) {
-
- // Get the StAX reader from the created element
- XMLStreamReader llomReader = omElement.getXMLStreamReader();
-
- // Create the DOOM OMFactory
- OMFactory doomFactory = DOOMAbstractFactory.getOMFactory();
-
- // Create the new builder
- StAXOMBuilder doomBuilder = new StAXOMBuilder(doomFactory, llomReader);
-
- // Get the document element
- OMElement newElem = doomBuilder.getDocumentElement();
-
- return newElem instanceof Element ? (Element) newElem : null;
- }
-
- private OMElement getElement(final Object obj) {
- OMNode node;
- if ((obj instanceof OMNode) && (node = (OMNode) obj).getType() == OMNode.ELEMENT_NODE) {
-
- OMElement element = (OMElement) node;
-
- return element;
-
- }
-
- return null;
- }
-
- private OMElement getElement(final OMElement rootElt, final String eltStr, final String xpath) {
- List<?> nodes = getMatchingNodes(xpath, rootElt);
- neglectingWarn(eltStr, nodes.size());
- OMElement element = getElement(nodes.get(0));
- return element;
- }
-
- private OMElement getFirstChildElement(final OMElement root, final String childName) {
- Iterator<?> it = root.getChildrenWithName(new QName(childName));
- if (it.hasNext()) {
- return (OMElement) it.next();
- }
-
- return null;
- }
-
- /**
- *
- * @param xpath
- * XPATH expression to be read.
- * @param elt
- * OMElement to be used for the search.
- * @return List matching OMNode list
- */
- @SuppressWarnings("unchecked")
- public OMNode getFirstMatchingNode(final String xpath, final OMElement elt) {
-
- AXIOMXPath axiomXpath;
- List<OMNode> nodeList = null;
- try {
- axiomXpath = new AXIOMXPath(xpath);
- nodeList = axiomXpath.selectNodes(elt);
- } catch (JaxenException e) {
- String msg = "Error occurred while reading the Xpath (" + xpath + ")";
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
-
- return nodeList != null ? nodeList.get(0) : null;
- }
-
- private IaasProvider getIaasProvider(final OMNode item, List<IaasProvider> iaases) {
-
- IaasProvider iaas = null;
-
- if (item.getType() == OMNode.ELEMENT_NODE) {
-
- OMElement iaasElt = (OMElement) item;
-
- if (iaases != null) {
- // check whether this is a reference to a predefined IaaS.
- for (IaasProvider iaasProvider : iaases) {
- if (iaasProvider.getType()
- .equals(iaasElt.getAttribute(new QName(
- CloudControllerConstants.TYPE_ATTR))
- .getAttributeValue())) {
- iaas = new IaasProvider(iaasProvider);
- break;
- }
- }
- }
-
- if (iaas == null) {
- iaas = new IaasProvider();
- }
-
- if (iaas.getType() == null) {
- iaas.setType(iaasElt.getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
- .getAttributeValue());
- }
-
- if ("".equals(iaas.getType())) {
- String msg =
- "'" + CloudControllerConstants.IAAS_PROVIDER_ELEMENT + "' element's '" +
- CloudControllerConstants.TYPE_ATTR +
- "' attribute should be specified!";
-
- handleException(msg);
-
- }
-
- // this is not mandatory
- String name =
- (iaasElt.getAttribute(new QName(CloudControllerConstants.NAME_ATTR)) == null)
- ? iaas.getName()
- : iaasElt.getAttributeValue(new QName(
- CloudControllerConstants.NAME_ATTR));
-
- iaas.setName(name);
-
- String xpath = CloudControllerConstants.IAAS_PROVIDER_ELEMENT_XPATH;
-
- // load other elements
- loadClassName(iaas, iaasElt);
+ private IaasProvider getIaasProvider(final OMNode item, List<IaasProvider> iaases) {
+
+ IaasProvider iaas = null;
+
+ if (item.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement iaasElt = (OMElement) item;
+
+ if (iaases != null) {
+ // check whether this is a reference to a predefined IaaS.
+ for (IaasProvider iaasProvider : iaases) {
+ if (iaasProvider.getType()
+ .equals(iaasElt.getAttribute(new QName(
+ CloudControllerConstants.TYPE_ATTR))
+ .getAttributeValue())) {
+ iaas = new IaasProvider(iaasProvider);
+ break;
+ }
+ }
+ }
+
+ if (iaas == null) {
+ iaas = new IaasProvider();
+ }
+
+ if (iaas.getType() == null) {
+ iaas.setType(iaasElt.getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
+ .getAttributeValue());
+ }
+
+ if ("".equals(iaas.getType())) {
+ String msg =
+ "'" + CloudControllerConstants.IAAS_PROVIDER_ELEMENT + "' element's '" +
+ CloudControllerConstants.TYPE_ATTR +
+ "' attribute should be specified!";
+
+ handleException(msg);
+
+ }
+
+ // this is not mandatory
+ String name =
+ (iaasElt.getAttribute(new QName(CloudControllerConstants.NAME_ATTR)) == null)
+ ? iaas.getName()
+ : iaasElt.getAttributeValue(new QName(
+ CloudControllerConstants.NAME_ATTR));
+
+ iaas.setName(name);
+
+ String xpath = CloudControllerConstants.IAAS_PROVIDER_ELEMENT_XPATH;
+
+ // load other elements
+ loadClassName(iaas, iaasElt);
+ loadProvider(iaas, iaasElt);
+ //load region
+ loadRegion(iaas);
// loadMaxInstanceLimit(iaas, iaasElt);
- loadProperties(iaasElt, iaas.getProperties());
- loadTemplate(iaas, iaasElt);
+ loadProperties(iaasElt, iaas.getProperties());
+ loadTemplate(iaas, iaasElt);
// loadScalingOrders(iaas, iaasElt);
- loadProvider(iaas, iaasElt);
- loadIdentity(iaas, iaasElt);
- loadCredentials(iaas, iaasElt, xpath);
- }
-
- return iaas;
- }
-
- /**
- *
- * @param xpath
- * XPATH expression to be read.
- * @return List matching OMNode list
- */
- @SuppressWarnings("unchecked")
- public List<OMNode> getMatchingNodes(final String xpath) {
-
- AXIOMXPath axiomXpath;
- List<OMNode> nodeList = null;
- try {
- axiomXpath = new AXIOMXPath(xpath);
- nodeList = axiomXpath.selectNodes(documentElement);
- } catch (JaxenException e) {
- String msg = "Error occurred while reading the Xpath (" + xpath + ")";
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
-
- return nodeList;
- }
-
- /**
- *
- * @param xpath
- * XPATH expression to be read.
- * @param elt
- * OMElement to be used for the search.
- * @return List matching OMNode list
- */
- @SuppressWarnings("unchecked")
- public List<OMNode> getMatchingNodes(final String xpath, final OMElement elt) {
-
- AXIOMXPath axiomXpath;
- List<OMNode> nodeList = null;
- try {
- axiomXpath = new AXIOMXPath(xpath);
- nodeList = axiomXpath.selectNodes(elt);
- } catch (JaxenException e) {
- String msg = "Error occurred while reading the Xpath (" + xpath + ")";
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
-
- return nodeList;
- }
-
- /**
+ loadIdentity(iaas, iaasElt);
+ loadCredentials(iaas, iaasElt, xpath);
+ }
+
+ return iaas;
+ }
+
+ private Partition getPartition(final OMNode item, Collection<Partition> partitions) {
+ Partition partition = null;
+ String id = null;
+ String type = null;
+
+ if (item.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement iaasElt = (OMElement) item;
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(CloudControllerConstants.ID_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement providerElt = (OMElement) it.next();
+ id = providerElt.getText();
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.ID_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (id == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.ID_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ Iterator<?> it1 =
+ iaasElt.getChildrenWithName(new QName(CloudControllerConstants.SCOPE_ELEMENT));
+
+ if (it1.hasNext()) {
+ OMElement providerElt = (OMElement) it1.next();
+ type = providerElt.getText();
+ }
+
+ if (it1.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.SCOPE_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (type == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.SCOPE_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+
+ if (partitions != null) {
+ // check whether this is a reference to a predefined Region.
+ for (Partition partition1 : partitions) {
+ //load region id
+ if (partition1.getId().equals(id)) {
+ partition = partition1;
+ break;
+ }
+ }
+ }
+
+ if (partition == null) {
+ partition = new Partition();
+ partition.setId(id);
+ partition.setScope(type);
+ loadProperties(iaasElt, partition.getProperties());
+ //handle partition created event
+ } else {
+ Partition partition1 = new Partition();
+ partition1.setId(id);
+ partition1.setScope(type);
+ loadProperties(iaasElt, partition1.getProperties());
+ Gson gson = new Gson();
+ String partitionS = gson.toJson(partition);
+ String partition1S = gson.toJson(partition1);
+ if (!partitionS.endsWith(partition1S)) {
+ //handle update partition
+ partition.setId(id);
+ partition.setScope(type);
+ loadProperties(iaasElt, partition.getProperties());
+
+ }
+
+ }
+
+ }
+ return partition;
+ }
+
+ private Region getRegion(final OMNode item, List<Region> regions, IaasProvider provider) {
+
+ Region region = null;
+ String type = null;
+
+ if (item.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement regionElm = (OMElement) item;
+
+ OMElement iaasElt = (OMElement) regionElm.getParent();
+ if (!iaasElt.getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
+ .getAttributeValue().equals(provider.getType())) {
+ return region;
+ }
+
+ Iterator<?> it =
+ regionElm.getChildrenWithName(new QName(CloudControllerConstants.TYPE_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement providerElt = (OMElement) it.next();
+ type = providerElt.getText();
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.TYPE_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (type == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.TYPE_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ if (regions != null) {
+ // check whether this is a reference to a predefined Region.
+ for (Region region1 : regions) {
+ //load region id
+
+ if (region1.getType().equals(type)) {
+ region = region1;
+ break;
+ }
+ }
+ }
+ if (region == null) {
+ region = new Region();
+ region.setType(type);
+ }
+
+ Iterator<?> it1 =
+ regionElm.getChildrenWithName(new QName(CloudControllerConstants.ID_ELEMENT));
+
+ if (it1.hasNext()) {
+ OMElement providerElt = (OMElement) it1.next();
+ region.setId(providerElt.getText());
+ }
+
+ if (it1.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.TYPE_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (region.getId() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.TYPE_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ if (provider.getCredential() != null) {
+ log.warn("Provider credential will be overwritten by region credential");
+ }
+ loadCredentials(region, regionElm);
+
+ if (provider.getIdentity() != null) {
+ log.warn("Provider identity will be overwritten by region credential");
+ }
+ loadIdentity(region, regionElm);
+ loadProperties(regionElm, region.getProperties());
+ //load zone
+ loadZone(region);
+
+ }
+ return region;
+ }
+
+ private Zone getZone(final OMNode item, List<Zone> zones, Region region) {
+
+ Zone zone = null;
+ String type = null;
+ String typeRegion = null;
+
+ if (item.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement zoneElm = (OMElement) item;
+
+ OMElement regionElt = (OMElement) zoneElm.getParent();
+
+ Iterator<?> it2 =
+ regionElt.getChildrenWithName(new QName(CloudControllerConstants.TYPE_ELEMENT));
+
+ if (it2.hasNext()) {
+ OMElement providerElt = (OMElement) it2.next();
+ typeRegion = providerElt.getText();
+ }
+ if(!region.getType().equals(typeRegion)) {
+ return zone;
+ }
+ Iterator<?> it =
+ zoneElm.getChildrenWithName(new QName(CloudControllerConstants.TYPE_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement providerElt = (OMElement) it.next();
+ type = providerElt.getText();
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.TYPE_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (type == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.TYPE_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ if (zones != null) {
+ // check whether this is a reference to a predefined Region.
+ for (Zone zone1 : zones) {
+ //load region id
+
+ if (zone1.getType().equals(type)) {
+ zone = zone1;
+ break;
+ }
+ }
+ }
+ if (zone == null) {
+ zone = new Zone();
+ zone.setType(type);
+ }
+
+ Iterator<?> it1 =
+ zoneElm.getChildrenWithName(new QName(CloudControllerConstants.ID_ELEMENT));
+
+ if (it1.hasNext()) {
+ OMElement providerElt = (OMElement) it1.next();
+ zone.setId(providerElt.getText());
+ }
+
+ if (it1.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.TYPE_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (region.getId() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.TYPE_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+ loadProperties(zoneElm, zone.getProperties());
+ //load Host
+ loadHost(zone);
+
+ }
+ return zone;
+ }
+
+ private Host getHost(final OMNode item, List<Host> hosts, Zone zone) {
+
+ Host host = null;
+ String type = null;
+ String typeZone = null;
+
+ if (item.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement hostElt = (OMElement) item;
+
+ OMElement zoneElt = (OMElement) hostElt.getParent();
+
+ Iterator<?> it2 =
+ zoneElt.getChildrenWithName(new QName(CloudControllerConstants.TYPE_ELEMENT));
+
+ if (it2.hasNext()) {
+ OMElement providerElt = (OMElement) it2.next();
+ typeZone = providerElt.getText();
+ }
+ if(!zone.getType().equals(typeZone)) {
+ return host;
+ }
+ Iterator<?> it =
+ hostElt.getChildrenWithName(new QName(CloudControllerConstants.TYPE_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement providerElt = (OMElement) it.next();
+ type = providerElt.getText();
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.TYPE_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (type == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.TYPE_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ if (hosts != null) {
+ // check whether this is a reference to a predefined Region.
+ for (Host host1 : hosts) {
+ //load region id
+
+ if (host1.getType().equals(type)) {
+ host = host1;
+ break;
+ }
+ }
+ }
+ if (host == null) {
+ host = new Host();
+ host.setType(type);
+ }
+
+ Iterator<?> it1 =
+ hostElt.getChildrenWithName(new QName(CloudControllerConstants.ID_ELEMENT));
+
+ if (it1.hasNext()) {
+ OMElement providerElt = (OMElement) it1.next();
+ host.setId(providerElt.getText());
+ }
+
+ if (it1.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.TYPE_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (host.getId() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.TYPE_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+ loadProperties(hostElt, host.getProperties());
+
+ }
+ return host;
+ }
+
+ /**
+ * @param xpath XPATH expression to be read.
+ * @return List matching OMNode list
+ */
+ @SuppressWarnings("unchecked")
+ public List<OMNode> getMatchingNodes(final String xpath) {
+
+ AXIOMXPath axiomXpath;
+ List<OMNode> nodeList = null;
+ try {
+ axiomXpath = new AXIOMXPath(xpath);
+ nodeList = axiomXpath.selectNodes(documentElement);
+ } catch (JaxenException e) {
+ String msg = "Error occurred while reading the Xpath (" + xpath + ")";
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+
+ return nodeList;
+ }
+
+
+ /**
+ * @param xpath XPATH expression to be read.
+ * @param elt OMElement to be used for the search.
+ * @return List matching OMNode list
+ */
+ @SuppressWarnings("unchecked")
+ public List<OMNode> getMatchingNodes(final String xpath, final OMElement elt) {
+
+ AXIOMXPath axiomXpath;
+ List<OMNode> nodeList = null;
+ try {
+ axiomXpath = new AXIOMXPath(xpath);
+ nodeList = axiomXpath.selectNodes(elt);
+ } catch (JaxenException e) {
+ String msg = "Error occurred while reading the Xpath (" + xpath + ")";
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+
+ return nodeList;
+ }
+
+ /**
* @param cartridgeElementString Cartridges section as a {@link String}
- * @param aCartridge {@link Cartridge} instance.
- * @param portMappingNodes nodes of port mapping elements
+ * @param aCartridge {@link Cartridge} instance.
+ * @param portMappingNodes nodes of port mapping elements
*/
private void getPortMappings(String cartridgeElementString, Cartridge aCartridge,
List<?> portMappingNodes) {
- Object nodeObj;
- if (!portMappingNodes.isEmpty()) {
- if ((nodeObj = portMappingNodes.get(0)) instanceof OMNode) {
- OMNode portMappingNode = (OMNode) nodeObj;
-
- if (portMappingNode.getType() == OMNode.ELEMENT_NODE) {
-
- OMElement portMappingElt = (OMElement) portMappingNode;
-
- for (Iterator<?> iterator =
- portMappingElt.getChildrenWithName(new QName(
- CloudControllerConstants.HTTP_ELEMENT)); iterator.hasNext();) {
- OMElement httpElt = (OMElement) iterator.next();
-
- String port =
- httpElt.getAttributeValue(new QName(
- CloudControllerConstants.PORT_ATTR));
- String proxyPort =
- httpElt.getAttributeValue(new QName(
- CloudControllerConstants.PROXY_PORT_ATTR));
-
- PortMapping mapping =
- new PortMapping(
- CloudControllerConstants.HTTP_ELEMENT,
- port, proxyPort);
-
- aCartridge.addPortMapping(mapping);
- }
-
- for (Iterator<?> iterator =
- portMappingElt.getChildrenWithName(new QName(
- CloudControllerConstants.HTTPS_ELEMENT)); iterator.hasNext();) {
- OMElement httpsElt = (OMElement) iterator.next();
-
- String port =
- httpsElt.getAttributeValue(new QName(
- CloudControllerConstants.PORT_ATTR));
- String proxyPort =
- httpsElt.getAttributeValue(new QName(
- CloudControllerConstants.PROXY_PORT_ATTR));
-
- PortMapping mapping =
- new PortMapping(
- CloudControllerConstants.HTTPS_ELEMENT,
- port, proxyPort);
-
- aCartridge.addPortMapping(mapping);
- }
-
- } else {
- String msg =
- "Essential '" +
- CloudControllerConstants.PORT_MAPPING_ELEMENT +
- "' element cannot" + " be found in " +
- cartridgeElementString + " of " +
- xmlSource;
- handleException(msg);
- }
-
- }
- }
+ Object nodeObj;
+ if (!portMappingNodes.isEmpty()) {
+ if ((nodeObj = portMappingNodes.get(0)) instanceof OMNode) {
+ OMNode portMappingNode = (OMNode) nodeObj;
+
+ if (portMappingNode.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement portMappingElt = (OMElement) portMappingNode;
+
+ for (Iterator<?> iterator =
+ portMappingElt.getChildrenWithName(new QName(
+ CloudControllerConstants.HTTP_ELEMENT)); iterator.hasNext();) {
+ OMElement httpElt = (OMElement) iterator.next();
+
+ String port =
+ httpElt.getAttributeValue(new QName(
+ CloudControllerConstants.PORT_ATTR));
+ String proxyPort =
+ httpElt.getAttributeValue(new QName(
+ CloudControllerConstants.PROXY_PORT_ATTR));
+
+ PortMapping mapping =
+ new PortMapping(
+ CloudControllerConstants.HTTP_ELEMENT,
+ port, proxyPort);
+
+ aCartridge.addPortMapping(mapping);
+ }
+
+ for (Iterator<?> iterator =
+ portMappingElt.getChildrenWithName(new QName(
+ CloudControllerConstants.HTTPS_ELEMENT)); iterator.hasNext();) {
+ OMElement httpsElt = (OMElement) iterator.next();
+
+ String port =
+ httpsElt.getAttributeValue(new QName(
+ CloudControllerConstants.PORT_ATTR));
+ String proxyPort =
+ httpsElt.getAttributeValue(new QName(
+ CloudControllerConstants.PROXY_PORT_ATTR));
+
+ PortMapping mapping =
+ new PortMapping(
+ CloudControllerConstants.HTTPS_ELEMENT,
+ port, proxyPort);
+
+ aCartridge.addPortMapping(mapping);
+ }
+
+ } else {
+ String msg =
+ "Essential '" +
+ CloudControllerConstants.PORT_MAPPING_ELEMENT +
+ "' element cannot" + " be found in " +
+ cartridgeElementString + " of " +
+ xmlSource;
+ handleException(msg);
+ }
+
+ }
+ }
}
- public List<ServiceContext> getServiceContexts() {
+ public List<ServiceContext> getServiceContexts() {
+
+ List<ServiceContext> serviceContextList = new ArrayList<ServiceContext>();
- List<ServiceContext> serviceContextList = new ArrayList<ServiceContext>();
+ // services can be found from this XPATH
+ String xpath = CloudControllerConstants.SERVICES_ELEMENT_XPATH;
+ List<?> serviceNodes = getMatchingNodes(xpath, documentElement);
- // services can be found from this XPATH
- String xpath = CloudControllerConstants.SERVICES_ELEMENT_XPATH;
- List<?> serviceNodes = getMatchingNodes(xpath, documentElement);
+ if (serviceNodes == null || serviceNodes.isEmpty()) {
+ // or from this XPATH
+ xpath = CloudControllerConstants.SERVICE_ELEMENT_XPATH;
+ serviceNodes = getMatchingNodes(xpath, documentElement);
+ }
- if (serviceNodes == null || serviceNodes.isEmpty()) {
- // or from this XPATH
- xpath = CloudControllerConstants.SERVICE_ELEMENT_XPATH;
- serviceNodes = getMatchingNodes(xpath, documentElement);
- }
+ if (serviceNodes == null || serviceNodes.isEmpty()) {
+ log.warn("No service found in this configuration file : " + xmlSource.getPath());
+ return serviceContextList;
+ }
- if (serviceNodes == null || serviceNodes.isEmpty()) {
- log.warn("No service found in this configuration file : " + xmlSource.getPath());
- return serviceContextList;
- }
+ for (Object obj : serviceNodes) {
+ ServiceContext serviceCtxt = new ServiceContext();
- for (Object obj : serviceNodes) {
- ServiceContext serviceCtxt = new ServiceContext();
+ // set the definition file
+ serviceCtxt.setFile(xmlSource);
- // set the definition file
- serviceCtxt.setFile(xmlSource);
-
- if (obj instanceof OMNode) {
- OMNode serviceNode = (OMNode) obj;
+ if (obj instanceof OMNode) {
+ OMNode serviceNode = (OMNode) obj;
- if (serviceNode.getType() == OMNode.ELEMENT_NODE) {
+ if (serviceNode.getType() == OMNode.ELEMENT_NODE) {
- OMElement node = (OMElement) serviceNode;
+ OMElement node = (OMElement) serviceNode;
- if (node.getAttribute(new QName(CloudControllerConstants.SERVICE_DOMAIN_ATTR)) == null) {
- String msg =
- "Essential '" + CloudControllerConstants.SERVICE_DOMAIN_ATTR + "' " +
- "attribute of '" + CloudControllerConstants.SERVICE_ELEMENT +
- "' element cannot be found in " + xmlSource;
+ if (node.getAttribute(new QName(CloudControllerConstants.SERVICE_DOMAIN_ATTR)) == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.SERVICE_DOMAIN_ATTR + "' " +
+ "attribute of '" + CloudControllerConstants.SERVICE_ELEMENT +
+ "' element cannot be found in " + xmlSource;
- handleException(msg);
- }
+ handleException(msg);
+ }
- // set domain name
- serviceCtxt.setClusterId(node.getAttribute(new QName(
+ // set domain name
+ serviceCtxt.setClusterId(node.getAttribute(new QName(
CloudControllerConstants.SERVICE_DOMAIN_ATTR))
.getAttributeValue());
- // set tenant range
- serviceCtxt.setTenantRange(node.getAttribute(new QName(
- CloudControllerConstants.SERVICE_TENANT_RANGE_ATTR))
- .getAttributeValue());
+ // set tenant range
+ serviceCtxt.setTenantRange(node.getAttribute(new QName(
+ CloudControllerConstants.SERVICE_TENANT_RANGE_ATTR))
+ .getAttributeValue());
serviceCtxt.setAutoScalerPolicyName(node.getAttribute(new QName(
- CloudControllerConstants.POLICY_NAME))
- .getAttributeValue());
-
- OMNode cartridgeNode =
- getFirstMatchingNode(xpath +
- CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH,
- node);
-
- if (cartridgeNode != null && cartridgeNode.getType() == OMNode.ELEMENT_NODE) {
-
- OMElement cartridgeElt = (OMElement) cartridgeNode;
-
- String type =
- cartridgeElt.getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
- .getAttributeValue();
-
- if ("".equals(type)) {
- String msg =
- "Essential '" + CloudControllerConstants.TYPE_ATTR + "' " +
- " attribute of '" +
- CloudControllerConstants.CARTRIDGE_ELEMENT + "' of '" +
- CloudControllerConstants.SERVICE_ELEMENT +
- "' element cannot be found in " + xmlSource;
-
- handleException(msg);
- }
-
- // set Cartridge type
- serviceCtxt.setCartridgeType(type);
-
- }
- if (serviceCtxt.getCartridgeType() == null) {
- String msg =
- "Essential '" + CloudControllerConstants.CARTRIDGE_ELEMENT +
- "' element" + " has not specified in " + xmlSource;
- handleException(msg);
- }
-
- // load payload
- loadPayload(getMatchingNodes(xpath + CloudControllerConstants.PAYLOAD_ELEMENT_XPATH,
- node), serviceCtxt);
-
- // load host name
- loadHostName(getMatchingNodes(xpath + CloudControllerConstants.HOST_ELEMENT_XPATH,
- node), serviceCtxt);
-
- // load properties
- loadProperties(node, serviceCtxt.getProperties());
-
- }
- }
-
- FasterLookUpDataHolder.getInstance().addServiceContext(serviceCtxt);
- // add each domain specific template to list
- serviceContextList.add(serviceCtxt);
- }
-
- return serviceContextList;
-
- }
-
- public File getXmlSource() {
- return xmlSource;
- }
-
- private void handleException(final String msg) {
- log.error(msg);
- throw new MalformedConfigurationFileException(msg);
- }
-
- private void handleException(final String msg, final Exception e) {
- log.error(msg, e);
- throw new MalformedConfigurationFileException(msg, e);
- }
-
- private void loadClassName(final IaasProvider iaas, final OMElement iaasElt) {
-
- Iterator<?> it =
- iaasElt.getChildrenWithName(new QName(
- CloudControllerConstants.CLASS_NAME_ELEMENT));
-
- if (it.hasNext()) {
- OMElement classNameElt = (OMElement) it.next();
- iaas.setClassName(classNameElt.getText());
- }
-
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " +
- CloudControllerConstants.CLASS_NAME_ELEMENT + " elements!" +
- " Elements other than the first will be neglected.");
- }
-
- if (iaas.getClassName() == null) {
- String msg =
- "Essential '" + CloudControllerConstants.CLASS_NAME_ELEMENT + "' element " +
- "has not specified in " + xmlSource;
- handleException(msg);
- }
-
- }
-
- private void loadCredentials(final IaasProvider iaas, final OMElement iaasElt,
- final String xpath) {
-
- Iterator<?> it =
- iaasElt.getChildrenWithName(new QName(
- CloudControllerConstants.CREDENTIAL_ELEMENT));
-
- if (it.hasNext()) {
- OMElement credentialElt = (OMElement) it.next();
-
- // retrieve the value using secure vault
- SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
- String alias =
- credentialElt.getAttributeValue(new QName(
- CloudControllerConstants.ALIAS_ATTRIBUTE));
-
- // retrieve the secured password
- if (secretResolver != null && secretResolver.isInitialized() &&
- secretResolver.isTokenProtected(alias)) {
-
- iaas.setCredential(secretResolver.resolve(alias));
-
- }
-
- // if we still cannot find a value, we try to assign the value which
- // is specified
- // in the element, if any
- if (iaas.getCredential() == null) {
- log.warn("Unable to find a value for " + CloudControllerConstants.CREDENTIAL_ELEMENT +
- " element from Secure Vault." +
- "Hence we will try to assign the plain text value (if specified).");
- iaas.setCredential(credentialElt.getText());
- }
- }
-
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " +
- CloudControllerConstants.CREDENTIAL_ELEMENT + " elements!" +
- " Elements other than the first will be neglected.");
- }
-
- if (iaas.getCredential() == null) {
- String msg =
- "Essential '" + CloudControllerConstants.CREDENTIAL_ELEMENT + "' element" +
- " has not specified in " + xmlSource;
- handleException(msg);
- }
-
- }
-
- private void loadHostName(final List<OMNode> nodes, final ServiceContext serviceCtxt) {
-
- if (nodes == null || nodes.isEmpty()) {
- return;
- }
+ CloudControllerConstants.POLICY_NAME))
+ .getAttributeValue());
+
+ OMNode cartridgeNode =
+ getFirstMatchingNode(xpath +
+ CloudControllerConstants.CARTRIDGE_ELEMENT_XPATH,
+ node);
+
+ if (cartridgeNode != null && cartridgeNode.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement cartridgeElt = (OMElement) cartridgeNode;
+
+ String type =
+ cartridgeElt.getAttribute(new QName(CloudControllerConstants.TYPE_ATTR))
+ .getAttributeValue();
+
+ if ("".equals(type)) {
+ String msg =
+ "Essential '" + CloudControllerConstants.TYPE_ATTR + "' " +
+ " attribute of '" +
+ CloudControllerConstants.CARTRIDGE_ELEMENT + "' of '" +
+ CloudControllerConstants.SERVICE_ELEMENT +
+ "' element cannot be found in " + xmlSource;
+
+ handleException(msg);
+ }
+
+ // set Cartridge type
+ serviceCtxt.setCartridgeType(type);
- // read host element
- if (nodes.get(0).getType() == OMNode.ELEMENT_NODE) {
-
- OMElement node = (OMElement) nodes.get(0);
-
- if (node.getText() != null) {
- serviceCtxt.setHostName(node.getText());
- }
+ }
+ if (serviceCtxt.getCartridgeType() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.CARTRIDGE_ELEMENT +
+ "' element" + " has not specified in " + xmlSource;
+ handleException(msg);
+ }
- }
- }
+ // load payload
+ loadPayload(getMatchingNodes(xpath + CloudControllerConstants.PAYLOAD_ELEMENT_XPATH,
+ node), serviceCtxt);
- private void loadIdentity(final IaasProvider iaas, final OMElement iaasElt) {
+ // load host name
+ loadHostName(getMatchingNodes(xpath + CloudControllerConstants.HOST_ELEMENT_XPATH,
+ node), serviceCtxt);
- Iterator<?> it =
- iaasElt.getChildrenWithName(new QName(CloudControllerConstants.IDENTITY_ELEMENT));
+ // load properties
+ loadProperties(node, serviceCtxt.getProperties());
- if (it.hasNext()) {
- OMElement identityElt = (OMElement) it.next();
+ }
+ }
- // retrieve the value using secure vault
- SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
- String alias =
- identityElt.getAttributeValue(new QName(
- CloudControllerConstants.ALIAS_ATTRIBUTE));
+ FasterLookUpDataHolder.getInstance().addServiceContext(serviceCtxt);
+ // add each domain specific template to list
+ serviceContextList.add(serviceCtxt);
+ }
- // retrieve the secured password
- if (secretResolver != null && secretResolver.isInitialized() &&
- secretResolver.isTokenProtected(alias)) {
+ return serviceContextList;
- iaas.setIdentity(secretResolver.resolve(alias));
+ }
+
+ public File getXmlSource() {
+ return xmlSource;
+ }
+
+ private void handleException(final String msg) {
+ log.error(msg);
+ throw new MalformedConfigurationFileException(msg);
+ }
+
+ private void handleException(final String msg, final Exception e) {
+ log.error(msg, e);
+ throw new MalformedConfigurationFileException(msg, e);
+ }
+
+ private void loadClassName(final IaasProvider iaas, final OMElement iaasElt) {
- }
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(
+ CloudControllerConstants.CLASS_NAME_ELEMENT));
- // if we still cannot find a value, we try to assign the value which
- // is specified
- // in the element, if any
- if (iaas.getIdentity() == null) {
- log.warn("Unable to find a value for " + CloudControllerConstants.IDENTITY_ELEMENT +
- " element from Secure Vault." +
- "Hence we will try to assign the plain text value (if specified).");
- iaas.setIdentity(identityElt.getText());
- }
- }
+ if (it.hasNext()) {
+ OMElement classNameElt = (OMElement) it.next();
+ iaas.setClassName(classNameElt.getText());
+ }
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " + CloudControllerConstants.IDENTITY_ELEMENT +
- " elements!" + " Elements other than the first will be neglected.");
- }
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " +
+ CloudControllerConstants.CLASS_NAME_ELEMENT + " elements!" +
+ " Elements other than the first will be neglected.");
+ }
- if (iaas.getIdentity() == null) {
- String msg =
- "Essential '" + CloudControllerConstants.IDENTITY_ELEMENT + "' element" +
- " has not specified in " + xmlSource;
- handleException(msg);
- }
+ if (iaas.getClassName() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.CLASS_NAME_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
- }
+ }
- /*private void loadMaxInstanceLimit(IaasProvider iaas, final OMElement iaasElt) {
+ private void loadCredentials(final IaasProvider iaas, final OMElement iaasElt,
+ final String xpath) {
+
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(
+ CloudControllerConstants.CREDENTIAL_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement credentialElt = (OMElement) it.next();
+
+ // retrieve the value using secure vault
+ SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
+ String alias =
+ credentialElt.getAttributeValue(new QName(
+ CloudControllerConstants.ALIAS_ATTRIBUTE));
+
+ // retrieve the secured password
+ if (secretResolver != null && secretResolver.isInitialized() &&
+ secretResolver.isTokenProtected(alias)) {
+
+ iaas.setCredential(secretResolver.resolve(alias));
+
+ }
+
+ // if we still cannot find a value, we try to assign the value which
+ // is specified
+ // in the element, if any
+ if (iaas.getCredential() == null) {
+ log.warn("Unable to find a value for " + CloudControllerConstants.CREDENTIAL_ELEMENT +
+ " element from Secure Vault." +
+ "Hence we will try to assign the plain text value (if specified).");
+ iaas.setCredential(credentialElt.getText());
+ }
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " +
+ CloudControllerConstants.CREDENTIAL_ELEMENT + " elements!" +
+ " Elements other than the first will be neglected.");
+ }
+
+ if (iaas.getCredential() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.CREDENTIAL_ELEMENT + "' element" +
+ " has not specified in " + xmlSource;
+ handleException(msg);
+ }
- Iterator<?> it =
- iaasElt.getChildrenWithName(new QName(
- CloudControllerConstants.MAX_INSTANCE_LIMIT_ELEMENT));
+ }
- if (it.hasNext()) {
- OMElement maxInstanceLimitElt = (OMElement) it.next();
+ private void loadCredentials(Region region, final OMElement iaasElt) {
+
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(
+ CloudControllerConstants.CREDENTIAL_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement credentialElt = (OMElement) it.next();
+
+ // retrieve the value using secure vault
+ SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
+ String alias =
+ credentialElt.getAttributeValue(new QName(
+ CloudControllerConstants.ALIAS_ATTRIBUTE));
+
+ // retrieve the secured password
+ if (secretResolver != null && secretResolver.isInitialized() &&
+ secretResolver.isTokenProtected(alias)) {
+
+ region.setCredential(secretResolver.resolve(alias));
+
+ }
+
+ // if we still cannot find a value, we try to assign the value which
+ // is specified
+ // in the element, if any
+ if (region.getCredential() == null) {
+ log.warn("Unable to find a value for " + CloudControllerConstants.CREDENTIAL_ELEMENT +
+ " element from Secure Vault." +
+ "Hence we will try to assign the plain text value (if specified).");
+ region.setCredential(credentialElt.getText());
+ }
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " +
+ CloudControllerConstants.CREDENTIAL_ELEMENT + " elements!" +
+ " Elements other than the first will be neglected.");
+ }
+
+ if (region.getCredential() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.CREDENTIAL_ELEMENT + "' element" +
+ " has not specified in " + xmlSource;
+ handleException(msg);
+ }
- try {
- iaas.setMaxInstanceLimit(Integer.parseInt(maxInstanceLimitElt.getText()));
- } catch (NumberFormatException e) {
- String msg =
- CloudControllerConstants.MAX_INSTANCE_LIMIT_ELEMENT +
- " element contained" + " in " + xmlSource + "" +
- " has a value which is not an Integer value.";
- handleException(msg, e);
- }
+ }
- }
+ private void loadHostName(final List<OMNode> nodes, final ServiceContext serviceCtxt) {
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " +
- CloudControllerConstants.MAX_INSTANCE_LIMIT_ELEMENT + " elements!" +
- " Elements other than the first will be neglected.");
- }
+ if (nodes == null || nodes.isEmpty()) {
+ return;
+ }
- }*/
+ // read host element
+ if (nodes.get(0).getType() == OMNode.ELEMENT_NODE) {
- private void loadPayload(final List<OMNode> nodes, final ServiceContext serviceCtxt) {
+ OMElement node = (OMElement) nodes.get(0);
- if (nodes == null || nodes.isEmpty()) {
- return;
- }
+ if (node.getText() != null) {
+ serviceCtxt.setHostName(node.getText());
+ }
- // read payload element
- if (nodes.get(0).getType() == OMNode.ELEMENT_NODE) {
+ }
+ }
- OMElement node = (OMElement) nodes.get(0);
+ private void loadIdentity(final IaasProvider iaas, final OMElement iaasElt) {
+
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(CloudControllerConstants.IDENTITY_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement identityElt = (OMElement) it.next();
+
+ // retrieve the value using secure vault
+ SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
+ String alias =
+ identityElt.getAttributeValue(new QName(
+ CloudControllerConstants.ALIAS_ATTRIBUTE));
+
+ // retrieve the secured password
+ if (secretResolver != null && secretResolver.isInitialized() &&
+ secretResolver.isTokenProtected(alias)) {
+
+ iaas.setIdentity(secretResolver.resolve(alias));
+
+ }
+
+ // if we still cannot find a value, we try to assign the value which
+ // is specified
+ // in the element, if any
+ if (iaas.getIdentity() == null) {
+ log.warn("Unable to find a value for " + CloudControllerConstants.IDENTITY_ELEMENT +
+ " element from Secure Vault." +
+ "Hence we will try to assign the plain text value (if specified).");
+ iaas.setIdentity(identityElt.getText());
+ }
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.IDENTITY_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (iaas.getIdentity() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.IDENTITY_ELEMENT + "' element" +
+ " has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ }
- if (node.getText() != null) {
- StringBuilder payload = new StringBuilder(node.getText());
- serviceCtxt.setPayload(payload);
+ private void loadIdentity(final Region region, final OMElement iaasElt) {
- }
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(CloudControllerConstants.IDENTITY_ELEMENT));
- }
-
- }
-
- private void loadProperties(final OMElement elt, final Map<String, String> propertyMap) {
-
- Iterator<?> it =
- elt.getChildrenWithName(new QName(CloudControllerConstants.PROPERTY_ELEMENT));
-
- while (it.hasNext()) {
- OMElement prop = (OMElement) it.next();
-
- if (prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_NAME_ATTR)) == null ||
- prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_VALUE_ATTR)) == null) {
-
- String msg =
- "Property element's, name and value attributes should be specified " +
- "in " + xmlSource;
-
- handleException(msg);
- }
-
- propertyMap.put(prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_NAME_ATTR))
- .getAttributeValue(),
- prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_VALUE_ATTR))
- .getAttributeValue());
- }
-
- }
-
- private void loadProvider(final IaasProvider iaas, final OMElement iaasElt) {
-
- Iterator<?> it =
- iaasElt.getChildrenWithName(new QName(CloudControllerConstants.PROVIDER_ELEMENT));
-
- if (it.hasNext()) {
- OMElement providerElt = (OMElement) it.next();
- iaas.setProvider(providerElt.getText());
- }
-
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " + CloudControllerConstants.PROVIDER_ELEMENT +
- " elements!" + " Elements other than the first will be neglected.");
- }
-
- if (iaas.getProvider() == null) {
- String msg =
- "Essential '" + CloudControllerConstants.PROVIDER_ELEMENT + "' element " +
- "has not specified in " + xmlSource;
- handleException(msg);
- }
+ if (it.hasNext()) {
+ OMElement identityElt = (OMElement) it.next();
- }
-
- /* Have to handle at the autoscaler level...
- private void loadScalingOrders(final IaasProvider iaas, final OMElement iaasElt) {
- // set scale up order
- Iterator<?> it =
- iaasElt.getChildrenWithName(new QName(
- CloudControllerConstants.SCALE_UP_ORDER_ELEMENT));
-
- if (it.hasNext()) {
- OMElement scaleUpOrderElt = (OMElement) it.next();
-
- try {
- iaas.setScaleUpOrder(Integer.parseInt(scaleUpOrderElt.getText()));
- } catch (NumberFormatException e) {
- String msg =
- CloudControllerConstants.SCALE_UP_ORDER_ELEMENT + " element contained" +
- " in " + xmlSource + "" +
- " has a value which is not an Integer value.";
- handleException(msg, e);
- }
- }
-
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " +
- CloudControllerConstants.SCALE_UP_ORDER_ELEMENT + " elements!" +
- " Elements other than the first will be neglected.");
- }
+ // retrieve the value using secure vault
+ SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
+ String alias =
+ identityElt.getAttributeValue(new QName(
+ CloudControllerConstants.ALIAS_ATTRIBUTE));
- if (iaas.getScaleUpOrder() == -1) {
- String msg =
- "Essential '" + CloudControllerConstants.SCALE_UP_ORDER_ELEMENT + "' element" +
- " has not specified in " + xmlSource;
- handleException(msg);
- }
-
- // set scale down order
- it = iaasElt.getChildrenWithName(new QName(CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT));
-
- if (it.hasNext()) {
- OMElement scaleDownElt = (OMElement) it.next();
-
- try {
- iaas.setScaleDownOrder(Integer.parseInt(scaleDownElt.getText()));
- } catch (NumberFormatException e) {
- String msg =
- CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT + " element contained" +
- " in " + xmlSource + "" +
- " has a value which is not an Integer value.";
- handleException(msg, e);
- }
- }
-
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " +
- CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT + " elements!" +
- " Elements other than the first will be neglected.");
- }
-
- if (iaas.getScaleDownOrder() == -1) {
- String msg =
- "Essential '" + CloudControllerConstants.SCALE_DOWN_ORDER_ELEMENT + "' element" +
- " has not specified in " + xmlSource;
- handleException(msg);
- }
-
- }*/
-
- private void loadTemplate(final IaasProvider iaas, final OMElement iaasElt) {
-
- Iterator<?> it =
- iaasElt.getChildrenWithName(new QName(CloudControllerConstants.IMAGE_ID_ELEMENT));
-
- if (it.hasNext()) {
- OMElement imageElt = (OMElement) it.next();
- iaas.setImage(imageElt.getText());
- }
-
- if (it.hasNext()) {
- log.warn(xmlSource + " contains more than one " + CloudControllerConstants.IMAGE_ID_ELEMENT +
- " elements!" + " Elements other than the first will be neglected.");
- }
-
- }
-
- private void neglectingWarn(final String elt, final int size) {
- if (size > 1) {
- log.warn(xmlSource + " contains more than one " + elt + " elements!" +
- " Elements other than the first will be neglected.");
- }
- }
-
- public void parse() {
-
- if (xmlSource.exists()) {
- try {
- documentElement = new StAXOMBuilder(xmlSource.getPath()).getDocumentElement();
-
- } catch (Exception ex) {
- String msg = "Error occurred when parsing the " + xmlSource.getPath() + ".";
- handleException(msg, ex);
- }
- } else {
- String msg = "Configuration file cannot be found : " + xmlSource.getPath();
- handleException(msg);
- }
- }
-
- private void plainTextWarn(final String elt) {
- log.warn("Unable to find a value for " + elt + " element from Secure Vault." +
- "Hence we will try to assign the plain text value (if specified).");
- }
-
- private String resolveSecret(final OMElement elt) {
- // retrieve the value using secure vault
- SecretResolver secretResolver = SecretResolverFactory.create(documentElement, false);
-
- String alias = elt.getAttributeValue(new QName(CloudControllerConstants.ALIAS_ATTRIBUTE));
-
- // retrieve the secured password
- if (secretResolver != null && secretResolver.isInitialized() &&
- secretResolver.isTokenProtected(alias)) {
-
- return secretResolver.resolve(alias);
-
- }
-
- return null;
- }
-
- public void setDataPublisherRelatedData() {
-
- String eltStr = CloudControllerConstants.DATA_PUBLISHER_ELEMENT;
- // get dataPublisher element
- OMElement element =
- getElement(documentElement, eltStr,
- CloudControllerConstants.DATA_PUBLISHER_XPATH);
-
- if (element == null) {
- return;
- }
-
- FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
- // get enable attribute
- boolean isEnable =
- Boolean.parseBoolean(element.getAttributeValue(new QName(
- CloudControllerConstants.ENABLE_ATTR)));
- dataHolder.setEnableBAMDataPublisher(isEnable);
-
- if (isEnable) {
- // get bam server info
- OMElement childElement =
- getFirstChildElement(element,
- CloudControllerConstants.BAM_SERVER_ELEMENT);
- OMElement elt;
-
- if (childElement != null) {
- // set bam user name
- elt =
- getFirstChildElement(childElement,
- CloudControllerConstants.BAM_SERVER_ADMIN_USERNAME_ELEMENT);
- if (elt != null) {
- dataHolder.setBamUsername(elt.getText());
- }
- // set bam password
- elt =
- getFirstChildElement(childElement,
- CloudControllerConstants.BAM_SERVER_ADMIN_PASSWORD_ELEMENT);
- if (elt != null) {
- String password = resolveSecret(elt);
- if (password == null) {
- plainTextWarn(CloudControllerConstants.BAM_SERVER_ADMIN_PASSWORD_ELEMENT);
- password = elt.getText();
- }
-
- if (password != null) {
- dataHolder.setBamPassword(password);
- }
- }
- }
-
- // set cron
- childElement = getFirstChildElement(element, CloudControllerConstants.CRON_ELEMENT);
- if (childElement != null) {
- dataHolder.setDataPublisherCron(childElement.getText());
- }
-
- // set cassandra info
- childElement = getFirstChildElement(element, CloudControllerConstants.CASSANDRA_INFO_ELEMENT);
-
- if (childElement != null) {
- // set connection url
- elt = getFirstChildElement(childElement, CloudControllerConstants.CONNECTION_URL_ELEMENT);
- if (elt != null) {
- dataHolder.setCassandraConnUrl(elt.getText());
- }
-
- // set user name
- elt = getFirstChildElement(childElement, CloudControllerConstants.USER_NAME_ELEMENT);
- if (elt != null) {
- dataHolder.setCassandraUser(elt.getText());
- }
- // set password
- elt = getFirstChildElement(childElement, CloudControllerConstants.PASSWORD_ELEMENT);
- if (elt != null) {
- String password = resolveSecret(elt);
- if (password == null) {
- plainTextWarn(CloudControllerConstants.PASSWORD_ELEMENT);
- password = elt.getText();
- }
-
- if (password != null) {
- dataHolder.setCassandraPassword(password);
- }
- }
- }
-
- }
-
- }
-
- /**
+ // retrieve the secured password
+ if (secretResolver != null && secretResolver.isInitialized() &&
+ secretResolver.isTokenProtected(alias)) {
+
+ region.setIdentity(secretResolver.resolve(alias));
+
+ }
+
+ // if we still cannot find a value, we try to assign the value which
+ // is specified
+ // in the element, if any
+ if (region.getIdentity() == null) {
+ log.warn("Unable to find a value for " + CloudControllerConstants.IDENTITY_ELEMENT +
+ " element from Secure Vault." +
+ "Hence we will try to assign the plain text value (if specified).");
+ region.setIdentity(identityElt.getText());
+ }
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.IDENTITY_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (region.getIdentity() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.IDENTITY_ELEMENT + "' element" +
+ " has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ }
+
+ /*private void loadMaxInstanceLimit(IaasProvider iaas, final OMElement iaasElt) {
+
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(
+ CloudControllerConstants.MAX_INSTANCE_LIMIT_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement maxInstanceLimitElt = (OMElement) it.next();
+
+ try {
+ iaas.setMaxInstanceLimit(Integer.parseInt(maxInstanceLimitElt.getText()));
+ } catch (NumberFormatException e) {
+ String msg =
+ CloudControllerConstants.MAX_INSTANCE_LIMIT_ELEMENT +
+ " element contained" + " in " + xmlSource + "" +
+ " has a value which is not an Integer value.";
+ handleException(msg, e);
+ }
+
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " +
+ CloudControllerConstants.MAX_INSTANCE_LIMIT_ELEMENT + " elements!" +
+ " Elements other than the first will be neglected.");
+ }
+
+ }*/
+
+ private void loadPayload(final List<OMNode> nodes, final ServiceContext serviceCtxt) {
+
+ if (nodes == null || nodes.isEmpty()) {
+ return;
+ }
+
+ // read payload element
+ if (nodes.get(0).getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement node = (OMElement) nodes.get(0);
+
+ if (node.getText() != null) {
+ StringBuilder payload = new StringBuilder(node.getText());
+ serviceCtxt.setPayload(payload);
+
+ }
+
+ }
+
+ }
+
+ private void loadProperties(final OMElement elt, final Map<String, String> propertyMap) {
+
+ Iterator<?> it =
+ elt.getChildrenWithName(new QName(CloudControllerConstants.PROPERTY_ELEMENT));
+
+ while (it.hasNext()) {
+ OMElement prop = (OMElement) it.next();
+
+ if (prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_NAME_ATTR)) == null ||
+ prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_VALUE_ATTR)) == null) {
+
+ String msg =
+ "Property element's, name and value attributes should be specified " +
+ "in " + xmlSource;
+
+ handleException(msg);
+ }
+
+ propertyMap.put(prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_NAME_ATTR))
+ .getAttributeValue(),
+ prop.getAttribute(new QName(CloudControllerConstants.PROPERTY_VALUE_ATTR))
+ .getAttributeValue());
+ }
+
+ }
+
+ private void loadProvider(final IaasProvider iaas, final OMElement iaasElt) {
+
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(CloudControllerConstants.PROVIDER_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement providerElt = (OMElement) it.next();
+ iaas.setProvider(providerElt.getText());
+ }
+
+ if (it.hasNext()) {
+ log.warn(xmlSource + " contains more than one " + CloudControllerConstants.PROVIDER_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (iaas.getProvider() == null) {
+ String msg =
+ "Essential '" + CloudControllerConstants.PROVIDER_ELEMENT + "' element " +
+ "has not specified in " + xmlSource;
+ handleException(msg);
+ }
+
+ }
+
+ private void loadRegion(final IaasProvider iaas) {
+ List<Region> regions = iaas.getListOfRegions();
+
+ if (regions == null) {
+ iaas.setListOfRegions((regions = new ArrayList<Region>()));
+ }
+
+ List<OMNode> nodeList = getMatchingNodes(CloudControllerConstants.REGION_XPATH);
+
+ // this is a valid scenario. User can have 0..1 iaas provider elements
+ // in cloud-controller xml.
+ if (nodeList == null || nodeList.isEmpty()) {
+ return;
+ }
+
+ for (OMNode node : nodeList) {
+ regions.add(getRegion(node, regions, iaas));
+ }
+ }
+
+ private void loadZone(final Region region) {
+ List<Zone> zones = region.getListOfZones();
+
+ if (zones == null) {
+ region.setListOfZones((zones = new ArrayList<Zone>()));
+ }
+
+ List<OMNode> nodeList = getMatchingNodes(CloudControllerConstants.ZONE_XPATH);
+
+ // this is a valid scenario. User can have 0..1 iaas provider elements
+ // in cloud-controller xml.
+ if (nodeList == null || nodeList.isEmpty()) {
+ return;
+ }
+
+ for (OMNode node : nodeList) {
+ zones.add(getZone(node, zones, region));
+ }
+ }
+
+ private void loadHost(final Zone zone) {
+ List<Host> hosts = zone.getListOfHosts();
+
+ if (hosts == null) {
+ zone.setListOfHosts((hosts = new ArrayList<Host>()));
+ }
+
+ List<OMNode> nodeList = getMatchingNodes(CloudControllerConstants.HOST_XPATH);
+
+ // this is a valid scenario. User can have 0..1 iaas provider elements
+ // in cloud-controller xml.
+ if (nodeList == null || nodeList.isEmpty()) {
+ return;
+ }
+
+ for (OMNode node : n
<TRUNCATED>
[3/5] git commit: introducing partitions into the cloud contrller
Posted by re...@apache.org.
introducing partitions into the cloud contrller
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/e3c9535c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/e3c9535c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/e3c9535c
Branch: refs/heads/master
Commit: e3c9535ca55e90f31551e969d9c74b0640736a84
Parents: 11d8cbe
Author: rekathiru <rt...@gmail.com>
Authored: Fri Nov 8 16:57:10 2013 +0530
Committer: rekathiru <rt...@gmail.com>
Committed: Fri Nov 8 16:57:10 2013 +0530
----------------------------------------------------------------------
.../controller/axiom/AxiomXpathParser.java | 2607 +++++++++++-------
.../deployers/CloudControllerDeployer.java | 15 +-
.../controller/topology/TopologyBuilder.java | 189 +-
.../topology/TopologyEventSender.java | 24 +
.../controller/topology/TopologyManager.java | 65 +-
.../util/CloudControllerConstants.java | 16 +
.../stratos/cloud/controller/util/Host.java | 46 +
.../stratos/cloud/controller/util/Zone.java | 18 +
8 files changed, 1837 insertions(+), 1143 deletions(-)
----------------------------------------------------------------------
[5/5] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-stratos
Posted by re...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/b0ec40cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/b0ec40cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/b0ec40cf
Branch: refs/heads/master
Commit: b0ec40cf1e9f01ba56231d9908be8704a9c9a2be
Parents: fd02766 6772f9a
Author: rekathiru <rt...@gmail.com>
Authored: Fri Nov 8 16:59:01 2013 +0530
Committer: rekathiru <rt...@gmail.com>
Committed: Fri Nov 8 16:59:01 2013 +0530
----------------------------------------------------------------------
.../modules/health-stats/pom.xml | 145 +++++++++++++++++++
.../health-stats/src/main/assembly/bin.xml | 62 ++++++++
.../src/main/bin/health-publisher.sh | 30 ++++
.../agent/health/publisher/HealthPublisher.java | 122 ++++++++++++++++
.../health/publisher/HealthPublisherClient.java | 62 ++++++++
.../cartridge/agent/health/publisher/Main.java | 53 +++++++
.../src/main/resources/jndi.properties | 22 +++
.../src/main/resources/log4j.properties | 37 +++++
.../src/main/security/client-truststore.jks | Bin 0 -> 35240 bytes
products/cartridge-agent/pom.xml | 1 +
10 files changed, 534 insertions(+)
----------------------------------------------------------------------