Updated Branches: refs/heads/master 0e111bbf5 -> 3a43bac88
Add listASPolicies osgi command Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/56faec29 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/56faec29 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/56faec29 Branch: refs/heads/master Commit: 56faec291279257189975620dff22a28788d8ed4 Parents: 0e111bb Author: Udara Liyanage <[email protected]> Authored: Mon Jan 27 10:28:52 2014 -0500 Committer: Udara Liyanage <[email protected]> Committed: Mon Jan 27 10:28:52 2014 -0500 ---------------------------------------------------------------------- .../org.apache.stratos.autoscaler/pom.xml | 1 + .../autoscaler/commands/ASPolicyCommands.java | 52 ++++++++++++++++++++ .../autoscaler/internal/ASBundleActivater.java | 50 +++++++++++++++++++ .../policy/model/AutoscalePolicy.java | 8 ++- 4 files changed, 110 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/56faec29/components/org.apache.stratos.autoscaler/pom.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/pom.xml b/components/org.apache.stratos.autoscaler/pom.xml index f7f8b31..23949fa 100644 --- a/components/org.apache.stratos.autoscaler/pom.xml +++ b/components/org.apache.stratos.autoscaler/pom.xml @@ -195,6 +195,7 @@ org.osgi.framework.*;resolution:=optional, *;resolution:=optional </Import-Package> + <Bundle-Activator>org.apache.stratos.autoscaler.internal.ASBundleActivater</Bundle-Activator> <DynamicImport-Package>*</DynamicImport-Package> <!--<Axis2Deployer>AutoscalerPolicyDeployer</Axis2Deployer> <Axis2Deployer>DeploymentPolicyDeployer</Axis2Deployer>--> http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/56faec29/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/commands/ASPolicyCommands.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/commands/ASPolicyCommands.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/commands/ASPolicyCommands.java new file mode 100644 index 0000000..21e5215 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/commands/ASPolicyCommands.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.autoscaler.commands; + +import org.apache.stratos.autoscaler.policy.PolicyManager; +import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; +import org.eclipse.osgi.framework.console.CommandInterpreter; +import org.eclipse.osgi.framework.console.CommandProvider; + +import org.apache.commons.lang.StringUtils; + +public class ASPolicyCommands implements CommandProvider{ + + public String getHelp() { + return "tlistASPolicies - list AutoScaling policies\n"; + } + + public void _listASPolicies (CommandInterpreter ci){ + String policyId = ci.nextArgument(); + + PolicyManager pm = PolicyManager.getInstance(); + + if(StringUtils.isBlank(policyId)){ + AutoscalePolicy[] aspolicyArr = pm.getAutoscalePolicyList(); + for(AutoscalePolicy asPoolicy : aspolicyArr){ + ci.println(asPoolicy.toString()); + } + }else{ + AutoscalePolicy asPolicy = pm.getAutoscalePolicy(policyId); + if(asPolicy != null){ + ci.println(asPolicy); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/56faec29/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/ASBundleActivater.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/ASBundleActivater.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/ASBundleActivater.java new file mode 100644 index 0000000..2eb6191 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/internal/ASBundleActivater.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.stratos.autoscaler.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.autoscaler.commands.ASPolicyCommands; +import org.apache.stratos.autoscaler.commands.DeploymentPolicyCommands; +import org.apache.stratos.autoscaler.commands.PartitionsCommands; +import org.eclipse.osgi.framework.console.CommandProvider; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class ASBundleActivater implements BundleActivator{ + + private static final Log log = LogFactory.getLog(ASBundleActivater.class); + + @Override + public void start(BundleContext context) throws Exception { + if(log.isDebugEnabled()) + log.debug("AutoScaler bundle is activated."); + + context.registerService(CommandProvider.class.getName(),new ASPolicyCommands(), null); + context.registerService(CommandProvider.class.getName(),new DeploymentPolicyCommands(), null); + context.registerService(CommandProvider.class.getName(),new PartitionsCommands(), null); + } + + + @Override + public void stop(BundleContext context) throws Exception { + if(log.isDebugEnabled()) + log.debug("AutoScaler bundle is deActivated."); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/56faec29/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/AutoscalePolicy.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/AutoscalePolicy.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/AutoscalePolicy.java index 8269bad..9a9f419 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/AutoscalePolicy.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/AutoscalePolicy.java @@ -127,5 +127,11 @@ public class AutoscalePolicy implements Serializable { public void setDescription(String description) { this.description = description; } - + + @Override + public String toString() { + return "ASPolicy [id=" + id + ", desplayName=" + displayName + + ", description=" + description + "]"; + } + }
