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 2015/04/23 13:47:04 UTC
[3/3] stratos git commit: fixing application restoring issue in the
stratos restart
fixing application restoring issue in the stratos restart
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/0c515aa0
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/0c515aa0
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/0c515aa0
Branch: refs/heads/master
Commit: 0c515aa013850575ddcfa2e299da5f0ec250ebc3
Parents: e760f68
Author: reka <rt...@gmail.com>
Authored: Thu Apr 23 17:16:37 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Thu Apr 23 17:16:37 2015 +0530
----------------------------------------------------------------------
.../internal/AutoscalerServiceComponent.java | 21 ++++++-
.../autoscaler/pojo/policy/PolicyManager.java | 21 +++++++
.../autoscaler/registry/RegistryManager.java | 61 +++++++++++-------
.../context/CloudControllerContext.java | 66 +++++++++++++-------
.../domain/application/ParentComponent.java | 7 ++-
5 files changed, 126 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/0c515aa0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java
index d1c4c7c..d161398 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServiceComponent.java
@@ -28,10 +28,12 @@ import org.apache.stratos.autoscaler.context.AutoscalerContext;
import org.apache.stratos.autoscaler.event.receiver.health.AutoscalerHealthStatEventReceiver;
import org.apache.stratos.autoscaler.event.receiver.topology.AutoscalerTopologyEventReceiver;
import org.apache.stratos.autoscaler.exception.AutoScalerException;
+import org.apache.stratos.autoscaler.exception.policy.InvalidDeploymentPolicyException;
import org.apache.stratos.autoscaler.exception.policy.InvalidPolicyException;
import org.apache.stratos.autoscaler.pojo.policy.PolicyManager;
import org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy;
import org.apache.stratos.autoscaler.pojo.policy.deployment.ApplicationPolicy;
+import org.apache.stratos.autoscaler.pojo.policy.deployment.DeploymentPolicy;
import org.apache.stratos.autoscaler.registry.RegistryManager;
import org.apache.stratos.autoscaler.status.processor.cluster.ClusterStatusProcessorChain;
import org.apache.stratos.autoscaler.status.processor.group.GroupStatusProcessorChain;
@@ -149,7 +151,8 @@ public class AutoscalerServiceComponent {
}
}
- private void executeCoordinatorTasks() throws InvalidPolicyException {
+ private void executeCoordinatorTasks() throws InvalidPolicyException,
+ InvalidDeploymentPolicyException {
// Start topology receiver
asTopologyReceiver = new AutoscalerTopologyEventReceiver();
@@ -176,8 +179,20 @@ public class AutoscalerServiceComponent {
PolicyManager.getInstance().addASPolicyToInformationModel(asPolicy);
}
- // Add application policies to information model
- List<ApplicationPolicy> applicationPolicies = RegistryManager.getInstance().retrieveApplicationPolicies();
+ // Add Deployment policies to information model
+ List<DeploymentPolicy> depPolicies = RegistryManager.getInstance().
+ retrieveDeploymentPolicies();
+ Iterator<DeploymentPolicy> depPolicyIterator = depPolicies.iterator();
+ while (depPolicyIterator.hasNext()) {
+ DeploymentPolicy depPolicy = depPolicyIterator.next();
+ PolicyManager.getInstance().addDeploymentPolicyToInformationModel(depPolicy);
+ }
+
+
+
+ // Add application policies to information model
+ List<ApplicationPolicy> applicationPolicies = RegistryManager.getInstance().
+ retrieveApplicationPolicies();
Iterator<ApplicationPolicy> applicationPolicyIterator = applicationPolicies.iterator();
while (applicationPolicyIterator.hasNext()) {
ApplicationPolicy applicationPolicy = applicationPolicyIterator.next();
http://git-wip-us.apache.org/repos/asf/stratos/blob/0c515aa0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
index 8d92c1b..997c593 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/pojo/policy/PolicyManager.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.exception.AutoScalerException;
+import org.apache.stratos.autoscaler.exception.policy.InvalidDeploymentPolicyException;
import org.apache.stratos.autoscaler.exception.policy.InvalidPolicyException;
import org.apache.stratos.autoscaler.pojo.policy.autoscale.AutoscalePolicy;
import org.apache.stratos.autoscaler.pojo.policy.deployment.ApplicationPolicy;
@@ -133,6 +134,26 @@ public class PolicyManager {
}
}
+ /**
+ * Retrieve deployment policies from registy and add it to in memory model
+ *
+ * @param deploymentPolicy
+ * @throws InvalidDeploymentPolicyException
+ */
+ public void addDeploymentPolicyToInformationModel(DeploymentPolicy deploymentPolicy)
+ throws InvalidDeploymentPolicyException {
+ if (!deploymentPolicyListMap.containsKey(deploymentPolicy.getDeploymentPolicyID())) {
+ if (log.isDebugEnabled()) {
+ log.debug("Adding deployment policy: " + deploymentPolicy.getDeploymentPolicyID());
+ }
+ deploymentPolicyListMap.put(deploymentPolicy.getDeploymentPolicyID(), deploymentPolicy);
+ } else {
+ String errMsg = "Specified deployment policy [" +
+ deploymentPolicy.getDeploymentPolicyID() + "] already exists";
+ log.error(errMsg);
+ throw new InvalidDeploymentPolicyException(errMsg);
+ }
+ }
public boolean updateDeploymentPolicy(DeploymentPolicy policy) throws InvalidPolicyException {
if (StringUtils.isEmpty(policy.getDeploymentPolicyID())) {
http://git-wip-us.apache.org/repos/asf/stratos/blob/0c515aa0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
index 68dc252..771f362 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
@@ -353,6 +353,11 @@ public class RegistryManager {
return resourceExist(resourcePath);
}
+ /**
+ * Retrieve Autoscaling policies from registry
+ *
+ * @return all the Autoscaling policies
+ */
public List<AutoscalePolicy> retrieveASPolicies() {
try {
startTenantFlow();
@@ -390,36 +395,46 @@ public class RegistryManager {
}
}
+ /**
+ * Retrieve deployment policies from registry
+ *
+ * @return all the deployment policies
+ */
public List<DeploymentPolicy> retrieveDeploymentPolicies() {
- List<DeploymentPolicy> depPolicyList = new ArrayList<DeploymentPolicy>();
- RegistryManager registryManager = RegistryManager.getInstance();
- String[] depPolicyResourceList = (String[]) registryManager.retrieve(AutoscalerConstants.AUTOSCALER_RESOURCE
- + AutoscalerConstants.DEPLOYMENT_POLICY_RESOURCE);
-
- if (depPolicyResourceList != null) {
- DeploymentPolicy depPolicy;
- for (String resourcePath : depPolicyResourceList) {
- Object serializedObj = registryManager.retrieve(resourcePath);
- if (serializedObj != null) {
- try {
- Object dataObj = Deserializer.deserializeFromByteArray((byte[]) serializedObj);
- if (dataObj instanceof DeploymentPolicy) {
- depPolicy = (DeploymentPolicy) dataObj;
- if (log.isDebugEnabled()) {
- log.debug(depPolicy.toString());
+ try{
+ startTenantFlow();
+ List<DeploymentPolicy> depPolicyList = new ArrayList<DeploymentPolicy>();
+ RegistryManager registryManager = RegistryManager.getInstance();
+ String[] depPolicyResourceList = (String[]) registryManager.retrieve(AutoscalerConstants.AUTOSCALER_RESOURCE
+ + AutoscalerConstants.DEPLOYMENT_POLICY_RESOURCE);
+
+ if (depPolicyResourceList != null) {
+ DeploymentPolicy depPolicy;
+ for (String resourcePath : depPolicyResourceList) {
+ Object serializedObj = registryManager.retrieve(resourcePath);
+ if (serializedObj != null) {
+ try {
+ Object dataObj = Deserializer.deserializeFromByteArray((byte[]) serializedObj);
+ if (dataObj instanceof DeploymentPolicy) {
+ depPolicy = (DeploymentPolicy) dataObj;
+ if (log.isDebugEnabled()) {
+ log.debug(depPolicy.toString());
+ }
+ depPolicyList.add(depPolicy);
+ } else {
+ return null;
}
- depPolicyList.add(depPolicy);
- } else {
- return null;
+ } catch (Exception e) {
+ String msg = "Unable to retrieve data from Registry. Hence, any historical deployment policies will not get reflected.";
+ log.warn(msg, e);
}
- } catch (Exception e) {
- String msg = "Unable to retrieve data from Registry. Hence, any historical deployment policies will not get reflected.";
- log.warn(msg, e);
}
}
}
+ return depPolicyList;
+ } finally {
+ endTenantFlow();
}
- return depPolicyList;
}
public List<ApplicationPolicy> retrieveApplicationPolicies() {
http://git-wip-us.apache.org/repos/asf/stratos/blob/0c515aa0/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 04c7637..ed9d041 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
@@ -510,7 +510,8 @@ public class CloudControllerContext implements Serializable {
/**
* Remove a registered Kubernetes host from registry
*/
- public synchronized boolean removeKubernetesHost(String kubernetesHostId) throws NonExistingKubernetesHostException {
+ public synchronized boolean removeKubernetesHost(String kubernetesHostId)
+ throws NonExistingKubernetesHostException {
if (kubernetesHostId == null) {
throw new NonExistingKubernetesHostException("Kubernetes host id can not be null");
}
@@ -518,11 +519,13 @@ public class CloudControllerContext implements Serializable {
log.info("Removing Kubernetes Host: " + kubernetesHostId);
}
try {
- KubernetesCluster kubernetesClusterStored = getKubernetesClusterContainingHost(kubernetesHostId);
+ KubernetesCluster kubernetesClusterStored = getKubernetesClusterContainingHost(
+ kubernetesHostId);
// Kubernetes master can not be removed
if (kubernetesClusterStored.getKubernetesMaster().getHostId().equals(kubernetesHostId)) {
- throw new NonExistingKubernetesHostException("Kubernetes master is not allowed to be removed [id] " + kubernetesHostId);
+ throw new NonExistingKubernetesHostException("Kubernetes master is not allowed " +
+ "to be removed [id] " + kubernetesHostId);
}
List<KubernetesHost> kubernetesHostList = new ArrayList<KubernetesHost>();
@@ -533,7 +536,8 @@ public class CloudControllerContext implements Serializable {
}
// member count will be equal only when host object was not found
if (kubernetesHostList.size() == kubernetesClusterStored.getKubernetesHosts().length) {
- throw new NonExistingKubernetesHostException("Kubernetes host not found for [id] " + kubernetesHostId);
+ throw new NonExistingKubernetesHostException("Kubernetes host not found for [id] "
+ + kubernetesHostId);
}
KubernetesHost[] kubernetesHostsArray = new KubernetesHost[kubernetesHostList.size()];
kubernetesHostList.toArray(kubernetesHostsArray);
@@ -542,7 +546,8 @@ public class CloudControllerContext implements Serializable {
kubernetesClusterStored.setKubernetesHosts(kubernetesHostsArray);
if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes host removed successfully: [id] %s", kubernetesHostId));
+ log.info(String.format("Kubernetes host removed successfully: [id] %s",
+ kubernetesHostId));
}
return true;
@@ -583,7 +588,8 @@ public class CloudControllerContext implements Serializable {
}
- public KubernetesHost[] getKubernetesHostsInGroup(String kubernetesClusterId) throws NonExistingKubernetesClusterException {
+ public KubernetesHost[] getKubernetesHostsInGroup(String kubernetesClusterId)
+ throws NonExistingKubernetesClusterException {
if (StringUtils.isEmpty(kubernetesClusterId)) {
throw new NonExistingKubernetesClusterException("Kubernetes cluster id is null");
}
@@ -592,7 +598,8 @@ public class CloudControllerContext implements Serializable {
if (kubernetesCluster != null) {
return kubernetesCluster.getKubernetesHosts();
}
- throw new NonExistingKubernetesClusterException("Kubernetes cluster not found: [kubernetes-cluster-id] "
+ throw new NonExistingKubernetesClusterException("Kubernetes cluster " +
+ "not found: [kubernetes-cluster-id] "
+ kubernetesClusterId);
}
@@ -605,7 +612,8 @@ public class CloudControllerContext implements Serializable {
if (kubernetesCluster != null) {
return kubernetesCluster.getKubernetesMaster();
}
- throw new NonExistingKubernetesClusterException("Kubernetes master not found: [kubernetes-cluster-id] "
+ throw new NonExistingKubernetesClusterException("Kubernetes master " +
+ "not found: [kubernetes-cluster-id] "
+ kubernetesClusterId);
}
@@ -618,10 +626,12 @@ public class CloudControllerContext implements Serializable {
if (kubernetesCluster != null) {
return kubernetesCluster;
}
- throw new NonExistingKubernetesClusterException("Kubernetes cluster not found: [kubernetes-cluster-id] " + kubernetesClusterId);
+ throw new NonExistingKubernetesClusterException("Kubernetes cluster " +
+ "not found: [kubernetes-cluster-id] " + kubernetesClusterId);
}
- public KubernetesCluster getKubernetesClusterContainingHost(String hostId) throws NonExistingKubernetesClusterException {
+ public KubernetesCluster getKubernetesClusterContainingHost(String hostId)
+ throws NonExistingKubernetesClusterException {
if (StringUtils.isEmpty(hostId)) {
return null;
}
@@ -637,11 +647,13 @@ public class CloudControllerContext implements Serializable {
}
}
}
- throw new NonExistingKubernetesClusterException("Kubernetes cluster not found containing host id: " + hostId);
+ throw new NonExistingKubernetesClusterException("Kubernetes cluster not " +
+ "found containing host id: " + hostId);
}
public KubernetesCluster[] getKubernetesClusters() {
- return kubernetesClustersMap.values().toArray(new KubernetesCluster[kubernetesClustersMap.size()]);
+ return kubernetesClustersMap.values().toArray(
+ new KubernetesCluster[kubernetesClustersMap.size()]);
}
public boolean isClustered() {
@@ -669,20 +681,32 @@ public class CloudControllerContext implements Serializable {
private void updateContextFromRegistry() {
if ((!isClustered()) || (isCoordinator())) {
try {
- Object dataObj = RegistryManager.getInstance().read(CloudControllerConstants.DATA_RESOURCE);
+ Object dataObj = RegistryManager.getInstance().
+ read(CloudControllerConstants.DATA_RESOURCE);
if (dataObj != null) {
if (dataObj instanceof CloudControllerContext) {
CloudControllerContext serializedObj = (CloudControllerContext) dataObj;
copyMap(serializedObj.kubernetesClustersMap, kubernetesClustersMap);
- copyMap(serializedObj.clusterIdToMemberContextListMap, clusterIdToMemberContextListMap);
- copyMap(serializedObj.memberIdToMemberContextMap, memberIdToMemberContextMap);
- copyMap(serializedObj.kubClusterIdToKubClusterContextMap, kubClusterIdToKubClusterContextMap);
+ copyMap(serializedObj.clusterIdToMemberContextListMap,
+ clusterIdToMemberContextListMap);
+ copyMap(serializedObj.memberIdToMemberContextMap,
+ memberIdToMemberContextMap);
+ copyMap(serializedObj.kubClusterIdToKubClusterContextMap,
+ kubClusterIdToKubClusterContextMap);
copyMap(serializedObj.clusterIdToContextMap, clusterIdToContextMap);
- copyMap(serializedObj.cartridgeTypeToPartitionIdsMap, cartridgeTypeToPartitionIdsMap);
- copyMap(serializedObj.cartridgeTypeToCartridgeMap, cartridgeTypeToCartridgeMap);
- copyMap(serializedObj.serviceGroupNameToServiceGroupMap, serviceGroupNameToServiceGroupMap);
- copyMap(serializedObj.networkPartitionIDToNetworkPartitionMap, networkPartitionIDToNetworkPartitionMap);
+ copyMap(serializedObj.cartridgeTypeToPartitionIdsMap,
+ cartridgeTypeToPartitionIdsMap);
+ copyMap(serializedObj.cartridgeTypeToCartridgeMap,
+ cartridgeTypeToCartridgeMap);
+ copyMap(serializedObj.serviceGroupNameToServiceGroupMap,
+ serviceGroupNameToServiceGroupMap);
+ copyMap(serializedObj.networkPartitionIDToNetworkPartitionMap,
+ networkPartitionIDToNetworkPartitionMap);
+ copyMap(serializedObj.partitionToIaasProviderByCartridge,
+ partitionToIaasProviderByCartridge);
+ copyMap(serializedObj.cartridgeTypeToIaasProviders,
+ cartridgeTypeToIaasProviders);
if (log.isDebugEnabled()) {
log.debug("Cloud controller context is read from the registry");
@@ -805,4 +829,4 @@ public class CloudControllerContext implements Serializable {
List<IaasProvider> iaasProviderList = cartridgeTypeToIaasProviders.get(cartridgeType);
return iaasProviderList;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/0c515aa0/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/ParentComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/ParentComponent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/ParentComponent.java
index 4a64357..fdd83ef 100644
--- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/ParentComponent.java
+++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/application/ParentComponent.java
@@ -285,6 +285,7 @@ public abstract class ParentComponent<T extends Instance> implements Serializabl
return appGroups;
}
+
/**
* Adds InstanceContext of a child to the instanceIdToInstanceContextMap.
*
@@ -379,9 +380,9 @@ public abstract class ParentComponent<T extends Instance> implements Serializabl
for (Group group : groups) {
if (group.getClusterDataMap() != null && !group.getClusterDataMap().isEmpty()) {
clusterData.addAll(group.getClusterDataMap().values());
- if (group.getGroups() != null) {
- getClusterData(clusterData, group.getGroups());
- }
+ }
+ if (group.getGroups() != null && !group.getGroups().isEmpty()) {
+ getClusterData(clusterData, group.getGroups());
}
}
}