You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2015/11/17 12:51:07 UTC
[1/3] stratos git commit: fixing for updating
configurations/definitions not getting picked
Repository: stratos
Updated Branches:
refs/heads/stratos-4.1.x 246c83418 -> c9115e4db
fixing for updating configurations/definitions not getting picked
Conflicts:
components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/60c1a14d
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/60c1a14d
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/60c1a14d
Branch: refs/heads/stratos-4.1.x
Commit: 60c1a14d2cb8edbe5b49737bd0489d64af8f3c16
Parents: 246c834
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Nov 17 10:37:27 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Nov 17 15:31:45 2015 +0530
----------------------------------------------------------------------
.../context/CloudControllerContext.java | 116 ++++++++--
.../cloud/controller/domain/IaasProvider.java | 68 ++++--
.../controller/domain/NetworkInterface.java | 16 ++
.../cloud/controller/iaases/ec2/EC2Iaas.java | 12 +
.../impl/CloudControllerServiceImpl.java | 14 +-
.../controller/util/CloudControllerUtil.java | 217 ++++++++++++++-----
6 files changed, 352 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/60c1a14d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/context/CloudControllerContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/context/CloudControllerContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/context/CloudControllerContext.java
index b935ffc..2c87707 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/context/CloudControllerContext.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/context/CloudControllerContext.java
@@ -22,16 +22,20 @@ import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.config.CloudControllerConfig;
import org.apache.stratos.cloud.controller.domain.*;
import org.apache.stratos.cloud.controller.domain.kubernetes.KubernetesCluster;
import org.apache.stratos.cloud.controller.domain.kubernetes.KubernetesClusterContext;
import org.apache.stratos.cloud.controller.domain.kubernetes.KubernetesHost;
import org.apache.stratos.cloud.controller.domain.kubernetes.KubernetesMaster;
+import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
import org.apache.stratos.cloud.controller.exception.NonExistingKubernetesClusterException;
import org.apache.stratos.cloud.controller.exception.NonExistingKubernetesHostException;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
import org.apache.stratos.cloud.controller.internal.ServiceReferenceHolder;
import org.apache.stratos.cloud.controller.registry.RegistryManager;
import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
import org.apache.stratos.common.services.DistributedObjectProvider;
import org.apache.stratos.common.threading.StratosThreadPool;
import org.wso2.carbon.databridge.agent.thrift.AsyncDataPublisher;
@@ -69,6 +73,8 @@ public class CloudControllerContext implements Serializable {
private static final String CC_CARTRIDGE_TYPE_TO_IAAS_PROVIDER_MAP = "CC_CARTRIDGE_TYPE_TO_IAAS_PROVIDER_MAP";
private static final String CC_APPLICATION_ID_TO_CLUSTER_ID_TO_PORT_MAPPING_MAP
= "CC_APPLICATION_ID_TO_CLUSTER_ID_TO_PORT_MAPPING_MAP";
+ private static final String CC_PARTITION_ID_TO_PARTITION_MAP =
+ "CC_PARTITION_ID_TO_PARTITION_MAP";
private static final String CC_CLUSTER_CTX_WRITE_LOCK = "CC_CLUSTER_CTX_WRITE_LOCK";
private static final String CC_MEMBER_CTX_WRITE_LOCK = "CC_MEMBER_CTX_WRITE_LOCK";
@@ -149,6 +155,13 @@ public class CloudControllerContext implements Serializable {
private Map<String, ServiceGroup> serviceGroupNameToServiceGroupMap;
/**
+ * Map of partitions
+ * Key - partition id
+ * Value partition
+ */
+ private Map<String, Partition> partitionIdToPartitionMap;
+
+ /**
* Map of network partitions
* Key - network partition id
* Value network partition
@@ -210,6 +223,7 @@ public class CloudControllerContext implements Serializable {
cartridgeTypeToIaasProviders = distributedObjectProvider.getMap(CC_CARTRIDGE_TYPE_TO_IAAS_PROVIDER_MAP);
applicationIdToClusterIdToPortMappings = distributedObjectProvider
.getMap(CC_APPLICATION_ID_TO_CLUSTER_ID_TO_PORT_MAPPING_MAP);
+ partitionIdToPartitionMap = distributedObjectProvider.getMap(CC_PARTITION_ID_TO_PARTITION_MAP);
if (!unitTest) {
// Update context from the registry
@@ -718,6 +732,7 @@ public class CloudControllerContext implements Serializable {
copyMap(serializedObj.cartridgeTypeToIaasProviders, cartridgeTypeToIaasProviders);
copyMap(serializedObj.applicationIdToClusterIdToPortMappings,
applicationIdToClusterIdToPortMappings);
+ copyMap(serializedObj.partitionIdToPartitionMap, partitionIdToPartitionMap);
if (log.isDebugEnabled()) {
log.debug("Cloud controller context is read from the registry");
@@ -748,18 +763,16 @@ public class CloudControllerContext implements Serializable {
}
}
- public Map<String, Map<String, IaasProvider>> getPartitionToIaasProviderByCartridge() {
- return partitionToIaasProviderByCartridge;
- }
-
- public void setPartitionToIaasProvider(Map<String, Map<String, IaasProvider>> partitionToIaasProviderByCartridge) {
- this.partitionToIaasProviderByCartridge = partitionToIaasProviderByCartridge;
- }
-
public void addIaasProvider(String cartridgeType, String partitionId, IaasProvider iaasProvider) {
- Map<String, IaasProvider> partitionToIaasProvider = new ConcurrentHashMap<String, IaasProvider>();
- partitionToIaasProvider.put(partitionId, iaasProvider);
- partitionToIaasProviderByCartridge.put(cartridgeType, partitionToIaasProvider);
+ Map<String, IaasProvider> partitionToIaasProviders;
+ if (partitionToIaasProviderByCartridge.get(cartridgeType) != null) {
+ partitionToIaasProviders = partitionToIaasProviderByCartridge.get(cartridgeType);
+ } else {
+ partitionToIaasProviders = new ConcurrentHashMap<String, IaasProvider>();
+ }
+
+ partitionToIaasProviders.put(partitionId, iaasProvider);
+ partitionToIaasProviderByCartridge.put(cartridgeType, partitionToIaasProviders);
}
public void addIaasProviders(String cartridgeType, Map<String, IaasProvider> partitionToIaasProvidersMap) {
@@ -783,23 +796,63 @@ public class CloudControllerContext implements Serializable {
}
public IaasProvider getIaasProviderOfPartition(String cartridgeType, String partitionId) {
- if (log.isDebugEnabled()) {
- log.debug("Retrieving partition: " + partitionId + " for the Cartridge: " + this.hashCode() + ". "
- + "Current Partition List: " + getPartitionToIaasProvider(cartridgeType).keySet().toString());
+
+ IaasProvider cachedIaasProvider = getPartitionToIaasProvider(cartridgeType).get(partitionId);
+
+ // get relevant partition
+ Partition partition = partitionIdToPartitionMap.get(partitionId);
+ if (partition == null) {
+ log.warn("No partition found with partition id " + partitionId + ", will not " +
+ "re-build the IaasProvider");
+ // can't rebuild, return the previously cached IaasProvider object
+ return cachedIaasProvider;
}
- return getPartitionToIaasProvider(cartridgeType).get(partitionId);
- }
- public Map<String, IaasProvider> getPartitionToIaasProvider(String cartridgeType) {
- return this.partitionToIaasProviderByCartridge.get(cartridgeType);
- }
+ // get the relevant Cartridge
+ Cartridge cartridge = cartridgeTypeToCartridgeMap.get(cartridgeType);
+ if (cartridge == null) {
+ log.warn("No Cartridge definition found for cartridge type " + cartridgeType
+ + ", will not re-build the IaasProvider");
+ // can't rebuild, return the previously cached IaasProvider object
+ return cachedIaasProvider;
+ }
+
+ IaasProvider newIaasProvider = null;
+ try {
+ newIaasProvider = CloudControllerUtil.getUpdatedIaasProviderInstance(cartridge, partition);
+
+ } catch (InvalidIaasProviderException e) {
+ log.error("Error in rebuilding the IaasProvider ", e);
+ // can't rebuild, return the previously cached IaasProvider object
+ return cachedIaasProvider;
+ }
+
+ // if the two objects are equal, no need to build again
+ if (cachedIaasProvider.equals(newIaasProvider)) {
+ log.info("New IaaSProvider object is equal to the cached one, no need to re-build");
+ return cachedIaasProvider;
+ }
+
+ // build
+ newIaasProvider.buildIaas();
+ log.info("Successfully built new IaasProvider object: " + newIaasProvider.toString());
+ // cache the new IaasProvider object
+ addIaasProvider(cartridgeType, partitionId, newIaasProvider);
+ addIaasProvider(cartridgeType, newIaasProvider);
+
+ // persist
+ try {
+ CloudControllerContext.getInstance().persist();
+ } catch (RegistryException e) {
+ log.error("Error in persisting changes for new IaasProvider object: " + newIaasProvider
+ .toString(), e);
+ }
- public Map<String, List<IaasProvider>> getCartridgeTypeToIaasProviders() {
- return this.cartridgeTypeToIaasProviders;
+ return newIaasProvider;
}
- public void setCartridgeTypeToIaasProviders(Map<String, List<IaasProvider>> cartridgeTypeToIaasProviders) {
- this.cartridgeTypeToIaasProviders = cartridgeTypeToIaasProviders;
+ public Map<String, IaasProvider> getPartitionToIaasProvider(String cartridgeType) {
+ return this.partitionToIaasProviderByCartridge.get(cartridgeType);
}
public void addIaasProvider(String cartridgeType, IaasProvider iaasProvider) {
@@ -896,4 +949,21 @@ public class CloudControllerContext implements Serializable {
applicationIdToClusterIdToPortMappings.remove(applicationId);
}
}
+
+ public void addPartition (Partition partition) {
+
+ partitionIdToPartitionMap.put(partition.getId(), partition);
+ log.info("Cached partition " + partition.toString() + " in partitionIdToPartitionMap");
+ }
+
+ public Partition getPartition (String partitionId) {
+
+ return partitionIdToPartitionMap.get(partitionId);
+ }
+
+ public void removePartition (String partitionId) {
+
+ partitionIdToPartitionMap.remove(partitionId);
+ log.info("Removed partition " + partitionId + " from partitionIdToPartitionMap");
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/60c1a14d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/IaasProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/IaasProvider.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/IaasProvider.java
index 49bc65d..917ca21 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/IaasProvider.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/IaasProvider.java
@@ -27,6 +27,7 @@ import org.jclouds.compute.ComputeService;
import org.jclouds.compute.domain.Template;
import java.io.Serializable;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -58,7 +59,60 @@ public class IaasProvider implements Serializable {
*/
private Map<String, String> properties = new HashMap<String, String>();
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ IaasProvider that = (IaasProvider) o;
+
+ if (type != null ? !type.equals(that.type) : that.type != null) {
+ return false;
+ }
+ if (className != null ? !className.equals(that.className) : that.className != null) {
+ return false;
+ }
+ if (name != null ? !name.equals(that.name) : that.name != null) {
+ return false;
+ }
+ if (properties != null ? !properties.equals(that.properties) : that.properties != null) {
+ return false;
+ }
+ if (!Arrays.equals(networkInterfaces, that.networkInterfaces)) {
+ return false;
+ }
+ if (image != null ? !image.equals(that.image) : that.image != null) {
+ return false;
+ }
+ if (provider != null ? !provider.equals(that.provider) : that.provider != null) {
+ return false;
+ }
+ if (identity != null ? !identity.equals(that.identity) : that.identity != null) {
+ return false;
+ }
+ return !(credential != null ? !credential.equals(that.credential) : that.credential != null);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = type != null ? type.hashCode() : 0;
+ result = 31 * result + (className != null ? className.hashCode() : 0);
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ result = 31 * result + (properties != null ? properties.hashCode() : 0);
+ result = 31 * result + (networkInterfaces != null ? Arrays.hashCode(networkInterfaces) : 0);
+ result = 31 * result + (image != null ? image.hashCode() : 0);
+ result = 31 * result + (provider != null ? provider.hashCode() : 0);
+ result = 31 * result + (identity != null ? identity.hashCode() : 0);
+ result = 31 * result + (credential != null ? credential.hashCode() : 0);
+ return result;
+ }
+
/**
+
* Network Interfaces Configuration
*/
private NetworkInterface[] networkInterfaces;
@@ -187,20 +241,6 @@ public class IaasProvider implements Serializable {
this.template = template;
}
- public boolean equals(Object o) {
- if (o instanceof IaasProvider) {
- return ((IaasProvider) o).getType().equals(this.getType());
- }
-
- return false;
- }
-
- public int hashCode() {
- return new HashCodeBuilder(17, 31). // two randomly chosen prime numbers
- append(type).
- toHashCode();
- }
-
public IaasProvider copy() {
return new IaasProvider(this);
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/60c1a14d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java
index 43add4a..1747c47 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/NetworkInterface.java
@@ -114,4 +114,20 @@ public class NetworkInterface implements Serializable {
sb.append('}');
return sb.toString();
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ NetworkInterface that = (NetworkInterface) o;
+
+ return !(networkUuid != null ? !networkUuid.equals(that.networkUuid) : that.networkUuid != null);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return networkUuid != null ? networkUuid.hashCode() : 0;
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/60c1a14d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2Iaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2Iaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2Iaas.java
index ab1a31e..62fe0db 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2Iaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/ec2/EC2Iaas.java
@@ -97,6 +97,18 @@ public class EC2Iaas extends JcloudsIaas {
break;
}
}
+ } else if (iaasInfo.getProperty(CloudControllerConstants.ZONE_ELEMENT) != null) {
+ Set<? extends Location> locations = iaasInfo.getComputeService().listAssignableLocations();
+ for (Location location : locations) {
+ if (location.getScope().toString().equalsIgnoreCase(CloudControllerConstants.ZONE_ELEMENT) && location
+ .getId().equals(iaasInfo.getProperty(CloudControllerConstants.ZONE_ELEMENT))) {
+ templateBuilder.locationId(location.getId());
+ log.info("ZONE has been set as " + iaasInfo.getProperty
+ (CloudControllerConstants.ZONE_ELEMENT)
+ + " with id: " + location.getId());
+ break;
+ }
+ }
}
if (iaasInfo.getProperty(CloudControllerConstants.INSTANCE_TYPE) != null) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/60c1a14d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index c841a81..4fde614 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -38,11 +38,10 @@ import org.apache.stratos.common.Property;
import org.apache.stratos.common.domain.LoadBalancingIPType;
import org.apache.stratos.common.threading.StratosThreadPool;
import org.apache.stratos.messaging.domain.topology.*;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.util.*;
import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
+import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.locks.Lock;
@@ -1588,6 +1587,8 @@ public class CloudControllerServiceImpl implements CloudControllerService {
partition.setProvider(networkPartition.getProvider());
try {
validatePartition(partition);
+ // add Partition to partition map
+ CloudControllerContext.getInstance().addPartition(partition);
} catch (InvalidPartitionException e) {
//Following message is shown to the end user in all the the API clients(GUI/CLI/Rest API)
throw new InvalidNetworkPartitionException(String.format(
@@ -1638,6 +1639,13 @@ public class CloudControllerServiceImpl implements CloudControllerService {
log.error(message);
throw new NetworkPartitionNotExistsException(message);
}
+
+ // remove partitions from the partition map
+ for (Partition partition : cloudControllerContext.getNetworkPartition(networkPartitionId)
+ .getPartitions()) {
+ CloudControllerContext.getInstance().removePartition(partition.getId());
+ }
+
// removing from CC-Context
CloudControllerContext.getInstance().removeNetworkPartition(networkPartitionId);
// persisting CC-Context
@@ -1682,6 +1690,8 @@ public class CloudControllerServiceImpl implements CloudControllerService {
// Overwrites partition provider with network partition provider
partition.setProvider(networkPartition.getProvider());
validatePartition(partition);
+ // add Partition to partition map
+ CloudControllerContext.getInstance().addPartition(partition);
if (log.isInfoEnabled()) {
log.info(String.format("Partition validated successfully: [network-partition-id] %s "
+ "[partition-id] %s", networkPartition.getId(), partition.getId()));
http://git-wip-us.apache.org/repos/asf/stratos/blob/60c1a14d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
index 2133ef0..e5af849 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
@@ -37,11 +37,11 @@ import org.apache.stratos.cloud.controller.registry.RegistryManager;
import org.apache.stratos.common.Property;
import org.apache.stratos.common.domain.LoadBalancingIPType;
import org.apache.stratos.messaging.domain.topology.Topology;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
@@ -64,7 +64,7 @@ public class CloudControllerUtil {
}
}
- public static void extractIaaSProvidersFromCartridge(Cartridge cartridge) {
+ public static void extractIaaSProvidersFromCartridge(Cartridge cartridge) throws InvalidIaasProviderException {
if (cartridge == null) {
return;
}
@@ -75,67 +75,23 @@ public class CloudControllerUtil {
if (iaasConfigs != null) {
for (IaasConfig iaasConfig : iaasConfigs) {
if (iaasConfig != null) {
- IaasProvider iaasProvider = null;
+ IaasProvider matchingIaasProviderInCC = null;
if (iaases != null) {
// check whether this is a reference to a predefined IaaS.
for (IaasProvider iaas : iaases) {
if (iaas.getType().equals(iaasConfig.getType())) {
- iaasProvider = new IaasProvider(iaas);
+ matchingIaasProviderInCC = iaas;
break;
}
}
}
- if (iaasProvider == null) {
- iaasProvider = new IaasProvider();
- iaasProvider.setType(iaasConfig.getType());
+ if (matchingIaasProviderInCC == null) {
+ matchingIaasProviderInCC = new IaasProvider();
+ matchingIaasProviderInCC.setType(iaasConfig.getType());
}
- String className = iaasConfig.getClassName();
- if (className != null) {
- iaasProvider.setClassName(className);
- }
-
- String name = iaasConfig.getName();
- if (name != null) {
- iaasProvider.setName(name);
- }
-
- String identity = iaasConfig.getIdentity();
- if (identity != null) {
- iaasProvider.setIdentity(identity);
- }
-
- String credential = iaasConfig.getCredential();
- if (credential != null) {
- iaasProvider.setCredential(credential);
- }
-
- String provider = iaasConfig.getProvider();
- if (provider != null) {
- iaasProvider.setProvider(provider);
- }
- String imageId = iaasConfig.getImageId();
- if (imageId != null) {
- iaasProvider.setImage(imageId);
- }
-
- byte[] payload = iaasConfig.getPayload();
- if (payload != null) {
- iaasProvider.setPayload(payload);
- }
-
- org.apache.stratos.common.Properties props1 = iaasConfig.getProperties();
- if (props1 != null) {
- for (Property prop : props1.getProperties()) {
- iaasProvider.addProperty(prop.getName(), String.valueOf(prop.getValue()));
- }
- }
-
- NetworkInterfaces networkInterfaces = iaasConfig.getNetworkInterfaces();
- if (networkInterfaces != null && networkInterfaces.getNetworkInterfaces() != null) {
- iaasProvider.setNetworkInterfaces(networkInterfaces.getNetworkInterfaces());
- }
+ IaasProvider iaasProvider = createUpdatedIaasProviderObject(iaasConfig, matchingIaasProviderInCC);
CloudControllerContext.getInstance().addIaasProvider(cartridge.getType(), iaasProvider);
}
@@ -334,4 +290,161 @@ public class CloudControllerUtil {
public static String getAliasFromClusterId(String clusterId) {
return StringUtils.substringBefore(StringUtils.substringAfter(clusterId, "."), ".");
}
+
+ public static IaasProvider getUpdatedIaasProviderInstance (Cartridge cartridge, Partition partition)
+ throws InvalidIaasProviderException {
+
+ IaasConfig cartridgeIaasConfig = null;
+ for (IaasConfig anIaasConfig : cartridge.getIaasConfigs()) {
+ if (anIaasConfig.getType().equals(partition.getProvider())) {
+ cartridgeIaasConfig = anIaasConfig;
+ }
+ }
+
+ // get the correct IaaS Provider config from cloud-controller.xml
+ IaasProvider ccIaasProvider = CloudControllerConfig.getInstance().getIaasProvider(partition
+ .getProvider());
+
+ if (ccIaasProvider == null) {
+ String errorMsg = "No Iaas Provider configuration found in cloud-controller.xml for " +
+ "type " + partition.getProvider();
+ log.error(errorMsg);
+ throw new InvalidIaasProviderException(errorMsg);
+ }
+
+ IaasProvider iaasProvider = null;
+ // update with new cloud-controller.xml and cartridge definition changes
+ if (cartridgeIaasConfig == null) {
+ iaasProvider = ccIaasProvider;
+ } else {
+ iaasProvider = createUpdatedIaasProviderObject(cartridgeIaasConfig, ccIaasProvider);
+ }
+
+ // update with Partition properties
+ if (partition.getProperties() != null && partition.getProperties().getProperties() != null) {
+ for (Property property : partition.getProperties().getProperties()) {
+ iaasProvider.addProperty(property.getName(), property.getValue());
+ }
+ }
+
+ //TODO: make debug
+ logProperties(iaasProvider.getType(), iaasProvider.getProperties(), cartridge.getType(),
+ partition.getId());
+
+ //TODO: make debug
+ logNetworkInterfaces(iaasProvider.getType(), iaasProvider.getNetworkInterfaces());
+
+ return iaasProvider;
+ }
+
+ private static IaasProvider createUpdatedIaasProviderObject (IaasConfig cartridgeIaasConfig,
+ IaasProvider ccIaasProvider)
+ throws InvalidIaasProviderException {
+
+ // create a deep copy of the IaaSProvider, not a reference
+ IaasProvider newIaasProvider = new IaasProvider(ccIaasProvider);
+
+ // priority order
+ // 1. cartridge definition
+ // 2. cloud-controller.xml
+ newIaasProvider.setClassName(selectAttribute("className", cartridgeIaasConfig.getClassName(),
+ ccIaasProvider.getClassName(), true));
+
+ // should not log identity details even in debug logs
+ newIaasProvider.setIdentity(selectAttribute("identity", cartridgeIaasConfig.getIdentity(),
+ ccIaasProvider.getIdentity(), false));
+
+ // should not log credentials details even in debug logs
+ newIaasProvider.setCredential(selectAttribute("credential", cartridgeIaasConfig.getCredential(),
+ ccIaasProvider.getCredential(), false));
+
+ newIaasProvider.setProvider(selectAttribute("provider", cartridgeIaasConfig.getProvider(),
+ ccIaasProvider.getProvider(), true));
+
+ newIaasProvider.setImage(selectAttribute("imageId", cartridgeIaasConfig.getImageId(),
+ ccIaasProvider.getImage(), true));
+
+ byte[] payload = cartridgeIaasConfig.getPayload();
+ if (payload != null) {
+ newIaasProvider.setPayload(payload);
+ }
+
+ Map<String, String> ccIaasProperties = ccIaasProvider.getProperties();
+ if (ccIaasProperties != null) {
+ for (Map.Entry<String, String> ccIaasProperty : ccIaasProperties.entrySet()) {
+ newIaasProvider.addProperty(ccIaasProperty.getKey(), ccIaasProperty.getValue());
+ }
+ }
+
+ // add properties defined in Cartridge and cloud-controller.xml
+ org.apache.stratos.common.Properties cartridgeIaasProperties = cartridgeIaasConfig.getProperties();
+ if (cartridgeIaasProperties != null) {
+ for (Property prop : cartridgeIaasProperties.getProperties()) {
+ newIaasProvider.addProperty(prop.getName(), String.valueOf(prop.getValue()));
+ }
+ }
+
+ NetworkInterfaces networkInterfacesInCartridge = cartridgeIaasConfig.getNetworkInterfaces();
+ NetworkInterface[] networkInterfacesInCC = ccIaasProvider.getNetworkInterfaces();
+ if (networkInterfacesInCartridge != null && networkInterfacesInCartridge.getNetworkInterfaces().length > 0) {
+ newIaasProvider.setNetworkInterfaces(networkInterfacesInCartridge
+ .getNetworkInterfaces());
+ } else if (networkInterfacesInCC != null && networkInterfacesInCC.length > 0) {
+ newIaasProvider.setNetworkInterfaces(networkInterfacesInCC);
+ } else {
+ log.debug("No network interface definition set for IaaS provider " + newIaasProvider.getType());
+ }
+
+ return newIaasProvider;
+ }
+
+ private static String selectAttribute(String attributeName, String attributeDefinedInCartridge,
+ String attributeDefinedInCC, boolean logInfo) throws InvalidIaasProviderException {
+
+ if (attributeDefinedInCartridge != null) {
+ // TODO: make debug
+ if (logInfo) {
+ log.info("Selected " + attributeName + "=" +
+ attributeDefinedInCartridge + " from Cartridge Definition");
+ }
+ return attributeDefinedInCartridge;
+ } else if (attributeDefinedInCC != null) {
+ // TODO: make debug
+ if (logInfo) {
+ log.info("Selected " + attributeName + "=" +
+ attributeDefinedInCC + " from cloud-controller.xml configuration");
+ }
+ return attributeDefinedInCC;
+ } else {
+ String errorMsg = "Iaas Provider attribute " + attributeName + " not set in " +
+ "either cartridge definition of cloud-controller.xml";
+ log.error(errorMsg);
+ throw new InvalidIaasProviderException(errorMsg);
+ }
+ }
+
+ private static void logNetworkInterfaces (String iaasProviderType, NetworkInterface[] networkInterfaces) {
+
+ if (networkInterfaces != null) {
+ log.info("All Network interfaces in IaasProvider object for type: " +
+ iaasProviderType);
+ for (NetworkInterface nwInterface : networkInterfaces) {
+ log.info("Interface " + nwInterface.toString());
+ }
+ }
+ }
+
+ private static void logProperties(String iaasProviderType, Map<String, String> properties,
+ String cartridgeType, String partitionId) {
+
+ if (properties != null) {
+ log.info("Properties defined in IaasProvider object for type: " +
+ iaasProviderType + ", cartridge type: " + cartridgeType + ", partition: " +
+ partitionId);
+ for (Map.Entry<String, String> property : properties.entrySet()) {
+ log.info("Property key: " + property.getKey() + ", value: " +
+ property.getValue());
+ }
+ }
+ }
}
[3/3] stratos git commit: including a missing import
Posted by is...@apache.org.
including a missing import
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/c9115e4d
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/c9115e4d
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/c9115e4d
Branch: refs/heads/stratos-4.1.x
Commit: c9115e4db5cff3ec58f7ac9aa518480bf08541ba
Parents: 40b9fa6
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Nov 17 17:19:53 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Nov 17 17:19:53 2015 +0530
----------------------------------------------------------------------
.../controller/services/impl/CloudControllerServiceImpl.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/c9115e4d/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index 4fde614..a4ef6f8 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -38,10 +38,11 @@ import org.apache.stratos.common.Property;
import org.apache.stratos.common.domain.LoadBalancingIPType;
import org.apache.stratos.common.threading.StratosThreadPool;
import org.apache.stratos.messaging.domain.topology.*;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.util.*;
import java.util.Map.Entry;
-import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.locks.Lock;
@@ -967,7 +968,7 @@ public class CloudControllerServiceImpl implements CloudControllerService {
}
}
- Map<String, IaasProvider> partitionToIaasProviders = new ConcurrentHashMap<>();
+ Map<String, IaasProvider> partitionToIaasProviders = new ConcurrentHashMap<String, IaasProvider>();
if (log.isDebugEnabled()) {
log.debug("Deployment policy validation started for cartridge type: " + cartridgeType);
[2/3] stratos git commit: marking some verbose logs as debug logs
Posted by is...@apache.org.
marking some verbose logs as debug logs
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/40b9fa6e
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/40b9fa6e
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/40b9fa6e
Branch: refs/heads/stratos-4.1.x
Commit: 40b9fa6e1d8bff7f3d82bf7dfb3410087db71102
Parents: 60c1a14
Author: Isuru Haththotuwa <is...@apache.org>
Authored: Tue Nov 17 14:21:58 2015 +0530
Committer: Isuru Haththotuwa <is...@apache.org>
Committed: Tue Nov 17 15:32:08 2015 +0530
----------------------------------------------------------------------
.../controller/util/CloudControllerUtil.java | 30 ++++++++++----------
1 file changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/40b9fa6e/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
index e5af849..54cde0b 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
@@ -327,12 +327,14 @@ public class CloudControllerUtil {
}
}
- //TODO: make debug
- logProperties(iaasProvider.getType(), iaasProvider.getProperties(), cartridge.getType(),
- partition.getId());
+ if (log.isDebugEnabled()) {
+ logProperties(iaasProvider.getType(), iaasProvider.getProperties(), cartridge.getType(),
+ partition.getId());
+ }
- //TODO: make debug
- logNetworkInterfaces(iaasProvider.getType(), iaasProvider.getNetworkInterfaces());
+ if (log.isDebugEnabled()) {
+ logNetworkInterfaces(iaasProvider.getType(), iaasProvider.getNetworkInterfaces());
+ }
return iaasProvider;
}
@@ -402,16 +404,14 @@ public class CloudControllerUtil {
String attributeDefinedInCC, boolean logInfo) throws InvalidIaasProviderException {
if (attributeDefinedInCartridge != null) {
- // TODO: make debug
- if (logInfo) {
- log.info("Selected " + attributeName + "=" +
+ if (log.isDebugEnabled() && logInfo) {
+ log.debug("Selected " + attributeName + "=" +
attributeDefinedInCartridge + " from Cartridge Definition");
}
return attributeDefinedInCartridge;
} else if (attributeDefinedInCC != null) {
- // TODO: make debug
- if (logInfo) {
- log.info("Selected " + attributeName + "=" +
+ if (log.isDebugEnabled() && logInfo) {
+ log.debug("Selected " + attributeName + "=" +
attributeDefinedInCC + " from cloud-controller.xml configuration");
}
return attributeDefinedInCC;
@@ -426,10 +426,10 @@ public class CloudControllerUtil {
private static void logNetworkInterfaces (String iaasProviderType, NetworkInterface[] networkInterfaces) {
if (networkInterfaces != null) {
- log.info("All Network interfaces in IaasProvider object for type: " +
+ log.debug("All Network interfaces in IaasProvider object for type: " +
iaasProviderType);
for (NetworkInterface nwInterface : networkInterfaces) {
- log.info("Interface " + nwInterface.toString());
+ log.debug("Interface " + nwInterface.toString());
}
}
}
@@ -438,11 +438,11 @@ public class CloudControllerUtil {
String cartridgeType, String partitionId) {
if (properties != null) {
- log.info("Properties defined in IaasProvider object for type: " +
+ log.debug("Properties defined in IaasProvider object for type: " +
iaasProviderType + ", cartridge type: " + cartridgeType + ", partition: " +
partitionId);
for (Map.Entry<String, String> property : properties.entrySet()) {
- log.info("Property key: " + property.getKey() + ", value: " +
+ log.debug("Property key: " + property.getKey() + ", value: " +
property.getValue());
}
}