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/06/25 20:33:55 UTC
stratos git commit: adding validation for deployment policy and
autoscaling policy
Repository: stratos
Updated Branches:
refs/heads/master 2ee26c15c -> 31c101fe6
adding validation for deployment policy and autoscaling policy
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/31c101fe
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/31c101fe
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/31c101fe
Branch: refs/heads/master
Commit: 31c101fe6b864160322a28b93f3897dd95a6436a
Parents: 2ee26c1
Author: reka <rt...@gmail.com>
Authored: Thu Jun 25 23:58:55 2015 +0530
Committer: reka <rt...@gmail.com>
Committed: Thu Jun 25 23:58:55 2015 +0530
----------------------------------------------------------------------
.../services/impl/AutoscalerServiceImpl.java | 66 +++++++++++++++-----
1 file changed, 52 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/31c101fe/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
index 54ff1b3..3f2120c 100644
--- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
+++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/services/impl/AutoscalerServiceImpl.java
@@ -26,6 +26,13 @@ import org.apache.stratos.autoscaler.applications.ApplicationHolder;
import org.apache.stratos.autoscaler.applications.parser.ApplicationParser;
import org.apache.stratos.autoscaler.applications.parser.DefaultApplicationParser;
import org.apache.stratos.autoscaler.applications.pojo.*;
+import org.apache.stratos.autoscaler.applications.pojo.ApplicationClusterContext;
+import org.apache.stratos.autoscaler.applications.pojo.ApplicationContext;
+import org.apache.stratos.autoscaler.applications.pojo.ArtifactRepositoryContext;
+import org.apache.stratos.autoscaler.applications.pojo.CartridgeContext;
+import org.apache.stratos.autoscaler.applications.pojo.ComponentContext;
+import org.apache.stratos.autoscaler.applications.pojo.GroupContext;
+import org.apache.stratos.autoscaler.applications.pojo.SubscribableInfoContext;
import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
import org.apache.stratos.autoscaler.client.AutoscalerCloudControllerClient;
import org.apache.stratos.autoscaler.context.AutoscalerContext;
@@ -50,6 +57,7 @@ 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.services.AutoscalerService;
+import org.apache.stratos.autoscaler.stub.pojo.*;
import org.apache.stratos.autoscaler.util.AutoscalerUtil;
import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidCartridgeTypeExceptionException;
import org.apache.stratos.cloud.controller.stub.CloudControllerServiceInvalidPartitionExceptionException;
@@ -89,7 +97,8 @@ public class AutoscalerServiceImpl implements AutoscalerService {
}
@Override
- public boolean addAutoScalingPolicy(AutoscalePolicy autoscalePolicy) throws AutoScalingPolicyAlreadyExistException {
+ public boolean addAutoScalingPolicy(AutoscalePolicy autoscalePolicy)
+ throws AutoScalingPolicyAlreadyExistException {
return PolicyManager.getInstance().addAutoscalePolicy(autoscalePolicy);
}
@@ -101,12 +110,13 @@ public class AutoscalerServiceImpl implements AutoscalerService {
@Override
public boolean removeAutoScalingPolicy(String autoscalePolicyId) throws UnremovablePolicyException,
PolicyDoesNotExistException {
- //if (removableAutoScalerPolicy(autoscalePolicyId)) {
+ if (removableAutoScalerPolicy(autoscalePolicyId)) {
return PolicyManager.getInstance().removeAutoscalePolicy(autoscalePolicyId);
- /* } else {
- throw new UnremovablePolicyException("This autoscaler policy cannot be removed, since it is used in " +
+ } else {
+ throw new UnremovablePolicyException("This autoscaler policy cannot be removed, " +
+ "since it is used in " +
"applications.");
- }*/
+ }
}
/**
@@ -116,18 +126,46 @@ public class AutoscalerServiceImpl implements AutoscalerService {
* @return
*/
private boolean removableAutoScalerPolicy(String autoscalePolicyId) {
- boolean canRemove = true;
- Collection<ApplicationContext> appContexts = AutoscalerContext.getInstance().getApplicationContexts();
- for (ApplicationContext app : appContexts) {
- CartridgeContext[] cartrideContexts = app.getComponents().getCartridgeContexts();
- for (CartridgeContext cartridgeContext : cartrideContexts) {
- SubscribableInfoContext subscribableInfoContexts = cartridgeContext.getSubscribableInfoContext();
- if (subscribableInfoContexts.getAutoscalingPolicy().equals(autoscalePolicyId)) {
- canRemove = false;
+ Collection<ApplicationContext> applicationContexts = AutoscalerContext.getInstance().
+ getApplicationContexts();
+ for (ApplicationContext applicationContext : applicationContexts) {
+ if(applicationContext.getComponents().getCartridgeContexts() != null) {
+ for(CartridgeContext cartridgeContext : applicationContext.getComponents().
+ getCartridgeContexts()) {
+ if(autoscalePolicyId.equals(cartridgeContext.getSubscribableInfoContext().
+ getAutoscalingPolicy())) {
+ return false;
+ }
}
}
+
+ if(applicationContext.getComponents().getGroupContexts() != null) {
+ return findAutoscalingPolicyInGroup(applicationContext.getComponents().getGroupContexts(),
+ autoscalePolicyId);
+ }
}
- return canRemove;
+ return true;
+ }
+
+
+ private boolean findAutoscalingPolicyInGroup(GroupContext[] groupContexts,
+ String autoscalePolicyId) {
+ for(GroupContext groupContext : groupContexts) {
+ if(groupContext.getCartridgeContexts() != null) {
+ for(CartridgeContext cartridgeContext : groupContext.getCartridgeContexts()) {
+ if(autoscalePolicyId.equals(cartridgeContext.getSubscribableInfoContext().
+ getAutoscalingPolicy())) {
+ return false;
+ }
+ }
+
+ }
+ if(groupContext.getGroupContexts() != null) {
+ return findAutoscalingPolicyInGroup(groupContext.getGroupContexts(),
+ autoscalePolicyId);
+ }
+ }
+ return true;
}
/**