Merge branch 'registry'
Conflicts:
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/96ed75f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/96ed75f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/96ed75f1
Branch: refs/heads/master
Commit: 96ed75f14ad13f110eb9b1ae8e6fe2ad27b9da91
Parents: aebdb08 13ca853
Author: Udara Liyanage <[email protected]>
Authored: Tue Dec 10 10:33:48 2013 -0500
Committer: Udara Liyanage <[email protected]>
Committed: Tue Dec 10 14:58:35 2013 -0500
----------------------------------------------------------------------
.../autoscaler/api/AutoScalerServiceImpl.java | 12 +-
.../interfaces/AutoScalerServiceInterface.java | 3 +-
.../internal/AutoscalerServerComponent.java | 181 ++++++++++++++-----
.../autoscaler/partition/PartitionManager.java | 27 ++-
.../partition/deployers/PartitionDeployer.java | 2 +-
.../autoscaler/policy/PolicyManager.java | 117 +++++-------
.../deployers/AutoscalerPolicyDeployer.java | 7 +-
.../deployers/DeploymentPolicyDeployer.java | 6 +-
.../policy/model/AutoscalePolicy.java | 5 +-
.../autoscaler/policy/model/LoadAverage.java | 7 +-
.../autoscaler/policy/model/LoadThresholds.java | 5 +-
.../policy/model/MemoryConsumption.java | 7 +-
.../policy/model/RequestsInFlight.java | 7 +-
.../autoscaler/registry/RegistryManager.java | 21 ++-
.../autoscaler/util/AutoScalerConstants.java | 2 +
.../stratos/autoscaler/util/AutoscalerUtil.java | 2 +
.../stratos/autoscaler/util/Deserializer.java | 96 ++++++++++
17 files changed, 356 insertions(+), 151 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
index 584a724,ca47d52..4067a6d
---
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
+++
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java
@@@ -24,17 -24,17 +24,14 @@@ import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory;
import
org.apache.stratos.autoscaler.client.cloud.controller.CloudControllerClient;
import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
--import org.apache.stratos.autoscaler.exception.AutoScalerException;
++import org.apache.stratos.autoscaler.exception.InvalidPolicyException;
import org.apache.stratos.autoscaler.exception.PartitionValidationException;
import org.apache.stratos.autoscaler.interfaces.AutoScalerServiceInterface;
import org.apache.stratos.autoscaler.partition.PartitionGroup;
import org.apache.stratos.autoscaler.partition.PartitionManager;
import org.apache.stratos.autoscaler.policy.PolicyManager;
import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
--import org.apache.stratos.autoscaler.registry.RegistryManager;
--import org.apache.stratos.autoscaler.util.AutoScalerConstants;
import org.apache.stratos.cloud.controller.deployment.partition.Partition;
--import org.wso2.carbon.registry.core.exceptions.RegistryException;
/**
* Auto Scaler Service API is responsible getting Partitions and Policies.
@@@ -74,9 -74,9 +71,8 @@@ public class AutoScalerServiceImpl impl
}
@Override
-- public boolean addDeploymentPolicy(DeploymentPolicy depPolicy) {
-- // TODO Auto-generated method stub
-- return false;
++ public boolean addDeploymentPolicy(DeploymentPolicy depPolicy) throws
InvalidPolicyException {
++ return
PolicyManager.getInstance().deployDeploymentscalePolicy(depPolicy);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
index 0bf7a86,0bf7a86..d0deb75
---
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
+++
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
@@@ -1,6 -1,6 +1,7 @@@
package org.apache.stratos.autoscaler.interfaces;
import org.apache.stratos.autoscaler.deployment.policy.DeploymentPolicy;
++import org.apache.stratos.autoscaler.exception.InvalidPolicyException;
import org.apache.stratos.autoscaler.exception.PartitionValidationException;
import org.apache.stratos.autoscaler.partition.PartitionGroup;
import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
@@@ -12,7 -12,7 +13,7 @@@ public interface AutoScalerServiceInter
public boolean addPartition(Partition partition);
public DeploymentPolicy[] getAllDeploymentPolicies();
-- public boolean addDeploymentPolicy(DeploymentPolicy depPolicy);
++ public boolean addDeploymentPolicy(DeploymentPolicy depPolicy) throws
InvalidPolicyException;
public AutoscalePolicy[] getAllAutoScalingPolicy();
public boolean addAutoScalingPolicy(AutoscalePolicy aspolicy);
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
index 2d05f4e,40cd83a..ef872a0
---
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
+++
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/AutoscalerServerComponent.java
@@@ -18,34 -18,46 +18,45 @@@
*/
package org.apache.stratos.autoscaler.internal;
+ import java.util.ArrayList;
+ import java.util.Iterator;
+
-import org.apache.commons.collections.IterableMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
++import org.apache.stratos.autoscaler.exception.AutoScalerException;
import
org.apache.stratos.autoscaler.message.receiver.health.HealthEventMessageDelegator;
import
org.apache.stratos.autoscaler.message.receiver.health.HealthEventMessageReceiver;
+ import org.apache.stratos.autoscaler.partition.PartitionManager;
+ import org.apache.stratos.autoscaler.policy.PolicyManager;
+ import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
+ import org.apache.stratos.autoscaler.registry.RegistryManager;
import org.apache.stratos.autoscaler.rule.ExecutorTaskScheduler;
import org.apache.stratos.autoscaler.topology.AutoscalerTopologyReceiver;
+ import org.apache.stratos.autoscaler.util.AutoScalerConstants;
+ import org.apache.stratos.autoscaler.util.Deserializer;
import org.apache.stratos.autoscaler.util.ServiceReferenceHolder;
+ import org.apache.stratos.cloud.controller.deployment.partition.Partition;
import org.apache.stratos.messaging.broker.subscribe.TopicSubscriber;
import org.apache.stratos.messaging.util.Constants;
-import org.drools.lang.DRLExpressions.type_return;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.core.service.RegistryService;
/**
-- * @scr.component name=
-- * "org.apache.stratos.autoscaler.internal.AutoscalerServerComponent"
-- * immediate="true"
-- *
-- * @scr.reference name="registry.service"
-- * interface=
-- * "org.wso2.carbon.registry.core.service.RegistryService"
-- * cardinality="1..1" policy="dynamic"
bind="setRegistryService"
-- * unbind="unsetRegistryService"
-- */
++* @scr.component
name=org.apache.stratos.autoscaler.internal.AutoscalerServerComponent"
++* immediate="true"
++*
++* @scr.reference name="registry.service"
++* interface=
++* "org.wso2.carbon.registry.core.service.RegistryService"
++* cardinality="1..1" policy="dynamic" bind="setRegistryService"
++* unbind="unsetRegistryService"
++*/
public class AutoscalerServerComponent {
private static final Log log =
LogFactory.getLog(AutoscalerServerComponent.class);
++ private RegistryManager registryManager;
protected void activate(ComponentContext componentContext) throws
Exception {
@@@ -62,39 -74,55 +73,62 @@@
// Thread tropologyDelegatorThread = new
Thread(tropologyEventMessageDelegator);
// tropologyDelegatorThread.start();
-- Thread th = new Thread(new AutoscalerTopologyReceiver());
-- th.start();
-- if (log.isDebugEnabled()) {
-- log.debug("Topology message processor thread started");
-- }
--
-- TopicSubscriber healthStatTopicSubscriber = new
TopicSubscriber(Constants.HEALTH_STAT_TOPIC);
-- healthStatTopicSubscriber.setMessageListener(new
HealthEventMessageReceiver());
-- Thread healthStatTopicSubscriberThread = new
Thread(healthStatTopicSubscriber);
-- healthStatTopicSubscriberThread.start();
-- if (log.isDebugEnabled()) {
-- log.debug("Health Stat event message receiver thread started");
-- }
--
-- HealthEventMessageDelegator healthEventMessageDelegator = new
HealthEventMessageDelegator();
-- Thread healthDelegatorThread = new
Thread(healthEventMessageDelegator);
-- healthDelegatorThread.start();
--
-- if (log.isDebugEnabled()) {
-- log.debug("Health message processor thread started");
-- }
--
-- // Start scheduler for running rules
-- ExecutorTaskScheduler executor = new ExecutorTaskScheduler();
-- Thread executorThread = new Thread(executor);
-- executorThread.start();
-- if(log.isDebugEnabled()) {
-- log.debug("Rules executor thread started");
-- }
-
- if(log.isInfoEnabled()) {
- log.info("Autoscaler Server Component activated");
- }
+
- // Adding the registry stored partitions to the information model.
- ArrayList<Partition> partitions = this.retreivePartitions();
- Iterator<Partition> it = partitions.iterator();
- while(it.hasNext()){
- Partition par = it.next();
-
PartitionManager.getInstance().addPartitionToInformationModel(par);
- }
+
+ // Adding the registry stored AS policies to the information model.
- ArrayList<AutoscalePolicy> asPolicies = this.retreiveASPolicies();
- Iterator<AutoscalePolicy> asItr = asPolicies.iterator();
- while(asItr.hasNext()){
- AutoscalePolicy asPolicy = asItr.next();
-
PolicyManager.getInstance().addASPolicyToInformationModel(asPolicy);
- }
+
- if(log.isInfoEnabled()) {
- log.info("Autoscaler Server Component activated");
- }
++ try {
++ Thread th = new Thread(new
AutoscalerTopologyReceiver());
++ th.start();
++ if (log.isDebugEnabled()) {
++ log.debug("Topology message processor thread
started");
++ }
++ TopicSubscriber healthStatTopicSubscriber = new
TopicSubscriber(
++ Constants.HEALTH_STAT_TOPIC);
++ healthStatTopicSubscriber
++ .setMessageListener(new
HealthEventMessageReceiver());
++ Thread healthStatTopicSubscriberThread = new Thread(
++ healthStatTopicSubscriber);
++ healthStatTopicSubscriberThread.start();
++ if (log.isDebugEnabled()) {
++ log.debug("Health Stat event message receiver
thread started");
++ }
++ HealthEventMessageDelegator healthEventMessageDelegator
= new HealthEventMessageDelegator();
++ Thread healthDelegatorThread = new Thread(
++ healthEventMessageDelegator);
++ healthDelegatorThread.start();
++ if (log.isDebugEnabled()) {
++ log.debug("Health message processor thread
started");
++ }
++ // Start scheduler for running rules
++ ExecutorTaskScheduler executor = new
ExecutorTaskScheduler();
++ Thread executorThread = new Thread(executor);
++ executorThread.start();
++ if (log.isDebugEnabled()) {
++ log.debug("Rules executor thread started");
++ }
++ this.registryManager = RegistryManager.getInstance();
++ // Adding the registry stored partitions to the
information model.
++ ArrayList<Partition> partitions =
this.retreivePartitions();
++ Iterator<Partition> it = partitions.iterator();
++ while (it.hasNext()) {
++ Partition par = it.next();
++
PartitionManager.getInstance().addPartitionToInformationModel(
++ par);
++ }
++ ArrayList<AutoscalePolicy> asPolicies =
this.retreiveASPolicies();
++ Iterator<AutoscalePolicy> asItr = asPolicies.iterator();
++ while (asItr.hasNext()) {
++ AutoscalePolicy asPolicy = asItr.next();
++
PolicyManager.getInstance().addASPolicyToInformationModel(
++ asPolicy);
++ }
++ if (log.isInfoEnabled()) {
++ log.info("Autoscaler Server Component
activated");
++ }
++ } catch (Throwable e) {
++ log.error("Error in Activating the AS component " +
e.getStackTrace());
++ }
}
protected void setRegistryService(RegistryService registryService) {
@@@ -106,7 -134,7 +140,7 @@@
} catch (RegistryException e) {
String msg = "Failed when retrieving Governance System
Registry.";
log.error(msg, e);
-- //throw new CloudControllerException(msg, e);
++ throw new AutoScalerException(msg, e);
}
}
@@@ -116,4 -144,59 +150,63 @@@
}
ServiceReferenceHolder.getInstance().setRegistry(null);
}
+
+ private ArrayList<Partition> retreivePartitions(){
+ ArrayList<Partition> partitionList = new ArrayList<Partition>();
- String [] partitionsResourceList = (String
[])RegistryManager.getInstance().retrieve(AutoScalerConstants.AUTOSCALER_RESOURCE
+ AutoScalerConstants.PARTITION_RESOURCE);
++ String [] partitionsResourceList = (String
[])registryManager.retrieve(AutoScalerConstants.AUTOSCALER_RESOURCE +
AutoScalerConstants.PARTITION_RESOURCE);
+
- for(String resourcePath : partitionsResourceList){
- Object partition =
RegistryManager.getInstance().retrieve(resourcePath);
-
- if (partition != null) {
- try {
-
- Object dataObj = Deserializer
- .deserializeFromByteArray((byte[])
partition);
- if(dataObj instanceof Partition) {
- partitionList.add( (Partition) dataObj);
- } else {
- return null;
- }
- } catch (Exception e) {
- String msg = "Unable to retrieve data from Registry.
Hence, any historical data will not get reflected.";
- log.warn(msg, e);
- }
- }
- }
- return partitionList;
++ if (partitionsResourceList != null) {
++ for (String resourcePath :
partitionsResourceList) {
++ Object partition =
registryManager.retrieve(resourcePath);
++
++ if (partition != null) {
++ try {
++
++ Object dataObj =
Deserializer
++
.deserializeFromByteArray((byte[]) partition);
++ if (dataObj instanceof
Partition) {
++
partitionList.add((Partition) dataObj);
++ } else {
++ return null;
++ }
++ } catch (Exception e) {
++ String msg = "Unable to
retrieve data from Registry. Hence, any historical data will not get
reflected.";
++ log.warn(msg, e);
++ }
++ }
++ }
++ }
++ return partitionList;
+ }
+
+ private ArrayList<AutoscalePolicy> retreiveASPolicies(){
+ ArrayList<AutoscalePolicy> asPolicyList = new
ArrayList<AutoscalePolicy>();
- String [] partitionsResourceList = (String
[])RegistryManager.getInstance().retrieve(AutoScalerConstants.AUTOSCALER_RESOURCE
+ AutoScalerConstants.AS_POLICY_RESOURCE);
++ String [] partitionsResourceList = (String
[])registryManager.retrieve(AutoScalerConstants.AUTOSCALER_RESOURCE +
AutoScalerConstants.AS_POLICY_RESOURCE);
+
- for(String resourcePath : partitionsResourceList){
- Object asPolicy =
RegistryManager.getInstance().retrieve(resourcePath);
-
- if (asPolicy != null) {
- try {
-
- Object dataObj = Deserializer
- .deserializeFromByteArray((byte[])
asPolicy);
- if(dataObj instanceof AutoscalePolicy) {
- asPolicyList.add( (AutoscalePolicy) dataObj);
- } else {
- return null;
- }
- } catch (Exception e) {
- String msg = "Unable to retrieve data from Registry.
Hence, any historical data will not get reflected.";
- log.warn(msg, e);
- }
- }
- }
- return asPolicyList;
++ if (partitionsResourceList != null) {
++ for (String resourcePath :
partitionsResourceList) {
++ Object asPolicy =
registryManager.retrieve(resourcePath);
++
++ if (asPolicy != null) {
++ try {
++
++ Object dataObj =
Deserializer
++
.deserializeFromByteArray((byte[]) asPolicy);
++ if (dataObj instanceof
AutoscalePolicy) {
++
asPolicyList.add((AutoscalePolicy) dataObj);
++ } else {
++ return null;
++ }
++ } catch (Exception e) {
++ String msg = "Unable to
retrieve data from Registry. Hence, any historical data will not get
reflected.";
++ log.warn(msg, e);
++ }
++ }
++ }
++ }
++ return asPolicyList;
+ }
+
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java
index 52fd8f7,5ace9d5..63c228e
---
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java
+++
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/PartitionManager.java
@@@ -69,8 -74,8 +74,8 @@@ private static final Log log = LogFacto
try {
this.validatePartition(partition);
-- regManager.persist(partition, resourcePath);
-- partitionListMap.put(partitionId, partition);
++ RegistryManager.getInstance().persist(partition, resourcePath);
++ addPartitionToInformationModel(partition);
} catch (RegistryException e) {
throw new AutoScalerException(e);
} catch(PartitionValidationException e){
@@@ -94,8 -105,7 +105,8 @@@
}
- public boolean validatePartition(Partition partition) throws
PartitionValidationException{
- return
CloudControllerClient.getInstance().validatePartition(partition);
+ public boolean validatePartition(Partition partition) throws
PartitionValidationException{
- return
CloudControllerClient.getInstance().validatePartition(partition);
++ return true;
++ //return
CloudControllerClient.getInstance().validatePartition(partition);
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java
index 4ddeaf5,d8a82c9..0084cf9
---
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java
+++
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/PolicyManager.java
@@@ -39,12 -43,12 +43,13 @@@ import org.wso2.carbon.registry.core.ex
public class PolicyManager {
private static final Log log = LogFactory.getLog(PolicyManager.class);
+
+ private static final String asResourcePath =
AutoScalerConstants.AUTOSCALER_RESOURCE+ AutoScalerConstants.AS_POLICY_RESOURCE
+ "/";
++ private static final String deploymentPolicyResourcePath =
AutoScalerConstants.AUTOSCALER_RESOURCE+
AutoScalerConstants.DEPLOYMENT_POLICY_RESOURCE + "/";
private static Map<String,AutoscalePolicy> autoscalePolicyListMap = new
HashMap<String, AutoscalePolicy>();
- private static Map<File,String> autoscalePolicyfileNameMap = new
HashMap<File, String>();
private static Map<String,DeploymentPolicy> deploymentPolicyListMap =
new HashMap<String, DeploymentPolicy>();
- private static Map<File,String> deploymentPolicyfileNameMap = new
HashMap<File, String>();
private static PolicyManager instance = null;
@@@ -52,49 -56,43 +57,57 @@@
}
public static PolicyManager getInstance() {
- if (instance == null) {
- instance = new PolicyManager ();
+ if (instance == null) {
+ synchronized (PolicyManager.class){
+ if (instance == null) {
+ instance = new PolicyManager();
+ }
}
- return instance;
+ }
+ return instance;
}
-- /**
-- * Appends the specified policy
-- * @param policyFile
-- * @param policy
-- * @throws InvalidPolicyException
-- */
- public void addAutoscalePolicy(File policyFile,AutoscalePolicy policy)
throws InvalidPolicyException {
- if(autoscalePolicyfileNameMap.containsKey(policyFile)){
-
removeAutoscalePolicy(autoscalePolicyfileNameMap.get(policyFile));
- autoscalePolicyfileNameMap.remove(policyFile);
- } else{
- autoscalePolicyfileNameMap.put(policyFile,
policy.getId());
- }
- if (!autoscalePolicyListMap.containsKey(policy.getId())) {
- public void deployAutoscalePolicy(AutoscalePolicy policy) throws
InvalidPolicyException {
- this.persitASPolicy(asResourcePath+policy.getId(), policy);
++ // Add the policy to information model and persist.
++ public void deployAutoscalePolicy(AutoscalePolicy policy) throws
InvalidPolicyException {
+ this.addASPolicyToInformationModel(policy);
++ this.persitASPolicy(asResourcePath+policy.getId(), policy);
+ }
+
++ // Add the policy to information model and persist.
++ public boolean deployDeploymentscalePolicy(DeploymentPolicy policy)
throws InvalidPolicyException {
++ this.addDeploymentPolicyToInformationModel(policy);
++ this.persitDeploymentPolicy(deploymentPolicyResourcePath+
policy.getId(), policy);
++ return true;
++ }
++
+ public void addASPolicyToInformationModel(AutoscalePolicy asPolicy)
throws InvalidPolicyException{
+ if (!autoscalePolicyListMap.containsKey(asPolicy.getId())) {
if(log.isDebugEnabled()){
- log.debug("Adding policy :" + policy.getId());
- }
- autoscalePolicyListMap.put(policy.getId(), policy);
+ log.debug("Adding policy :" + asPolicy.getId());
+ }
+ autoscalePolicyListMap.put(asPolicy.getId(), asPolicy);
} else {
- throw new InvalidPolicyException("Specified policy [" +
policy.getId()
+ throw new InvalidPolicyException("Specified policy [" +
asPolicy.getId()
+ "] already exists");
}
}
- /**
- * Appends the specified policy
- * @param policy
- * @throws InvalidPolicyException
- */
- public void addAutoscalePolicy(AutoscalePolicy policy) throws
InvalidPolicyException {
- addAutoscalePolicy(new File(policy.getId().concat(".xml")),
policy);
+ private void persitASPolicy(String asResourcePath, AutoscalePolicy
policy){
+ try {
+ RegistryManager.getInstance().persist(policy,
asResourcePath);
+ } catch (RegistryException e) {
+ throw new AutoScalerException(e);
+ }
+ }
+
++ private void persitDeploymentPolicy(String depResourcePath,
DeploymentPolicy policy){
++ try {
++ RegistryManager.getInstance().persist(policy,
asResourcePath);
++ } catch (RegistryException e) {
++ throw new AutoScalerException(e);
++ }
+ }
+
/**
* Removes the specified policy
* @param policy
@@@ -140,19 -126,13 +141,8 @@@
return autoscalePolicyListMap.get(id);
}
-- /**
-- * Appends the specified policy
-- * @param policyFile
-- * @param policy
-- * @throws InvalidPolicyException
-- */
- public void addDeploymentPolicy(File policyFile,DeploymentPolicy
policy) throws InvalidPolicyException {
- if(deploymentPolicyfileNameMap.containsKey(policyFile)){
-
removeDeploymentPolicy(deploymentPolicyfileNameMap.get(policyFile));
- deploymentPolicyfileNameMap.remove(policyFile);
- } else{
- deploymentPolicyfileNameMap.put(policyFile,
policy.getId());
- }
- public void addDeploymentPolicy(DeploymentPolicy policy) throws
InvalidPolicyException {
++ // Add the deployment policy to As in memmory information model. Does
not persist.
++ public void addDeploymentPolicyToInformationModel(DeploymentPolicy
policy) throws InvalidPolicyException {
if (!deploymentPolicyListMap.containsKey(policy.getId())) {
if(log.isDebugEnabled()){
log.debug("Adding policy :" + policy.getId());
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyDeployer.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyDeployer.java
index d56c4c0,0d1ac36..1a1a00a
---
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyDeployer.java
+++
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyDeployer.java
@@@ -78,7 -77,7 +77,7 @@@ public class DeploymentPolicyDeployer e
DeploymentPolicyReader reader = new
DeploymentPolicyReader(policyFile);
DeploymentPolicy policy = reader.read();
-
PolicyManager.getInstance().addDeploymentPolicy(policyFile,policy);
- PolicyManager.getInstance().addDeploymentPolicy(policy);
++
PolicyManager.getInstance().addDeploymentPolicyToInformationModel(policy);
log.info("Successfully deployed the policy specified at
"
+ deploymentFileData.getAbsolutePath());
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/registry/RegistryManager.java
index 1aa1820,b5ce6be..5be5fd4
---
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
@@@ -79,4 -81,22 +81,21 @@@ public class RegistryManager
}
}
+
+ public Object retrieve(String resourcePath) {
-
+ try {
+ Resource resource = registryService.get(resourcePath);
+
+ return resource.getContent();
+
+ } catch (ResourceNotFoundException ignore) {
+ // this means, we've never persisted info in registry
+ return null;
+ } catch (RegistryException e) {
+ String msg = "Failed to retrieve data from registry.";
+ log.error(msg, e);
+ throw new AutoScalerException(msg, e);
+ }
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/96ed75f1/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
----------------------------------------------------------------------
diff --cc
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
index 462f39f,1a777e5..3530cc3
---
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
+++
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoScalerConstants.java
@@@ -35,5 -35,6 +35,7 @@@ public final class AutoScalerConstants
*/
public static final String AUTOSCALER_RESOURCE = "/autoscaler";
public static final String PARTITION_RESOURCE = "/partitions";
+ public static final String AS_POLICY_RESOURCE =
"/policies/autoscalingPolicies";
++ public static final String DEPLOYMENT_POLICY_RESOURCE =
"/policies/deploymentPolicies";
}