fixing https://issues.apache.org/jira/browse/STRATOS-645 - for autoscaler
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/ea1844f0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/ea1844f0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/ea1844f0 Branch: refs/heads/master Commit: ea1844f0f75773bb85f205ea848e35895e670b93 Parents: 9f4c29f Author: Nirmal Fernando <[email protected]> Authored: Wed May 7 04:23:44 2014 +0530 Committer: Nirmal Fernando <[email protected]> Committed: Wed May 7 04:23:44 2014 +0530 ---------------------------------------------------------------------- .../org.apache.stratos.autoscaler/pom.xml | 2 - .../deployers/AutoscalerPolicyDeployer.java | 114 ------------------- .../deployers/AutoscalerPolicyReader.java | 113 ------------------ .../policy/model/LoadAverageThresholds.java | 52 +++++++++ .../autoscaler/policy/model/LoadThresholds.java | 30 ++--- .../model/MemoryConsumptionThresholds.java | 52 +++++++++ .../model/RequestsInFlightThresholds.java | 53 +++++++++ 7 files changed, 172 insertions(+), 244 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ea1844f0/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 cbc4090..d0d1167 100644 --- a/components/org.apache.stratos.autoscaler/pom.xml +++ b/components/org.apache.stratos.autoscaler/pom.xml @@ -196,8 +196,6 @@ </Import-Package> <Bundle-Activator>org.apache.stratos.autoscaler.internal.ASBundleActivater</Bundle-Activator> <DynamicImport-Package>*</DynamicImport-Package> - <!--<Axis2Deployer>AutoscalerPolicyDeployer</Axis2Deployer> - <Axis2Deployer>DeploymentPolicyDeployer</Axis2Deployer>--> <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> <Embed-Directory>lib</Embed-Directory> </instructions> http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ea1844f0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyDeployer.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyDeployer.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyDeployer.java deleted file mode 100644 index 861dab8..0000000 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyDeployer.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * 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.policy.deployers; - -import java.io.File; - -import org.apache.axis2.context.ConfigurationContext; -import org.apache.axis2.deployment.AbstractDeployer; -import org.apache.axis2.deployment.DeploymentException; -import org.apache.axis2.deployment.repository.util.DeploymentFileData; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.autoscaler.exception.InvalidPolicyException; -import org.apache.stratos.autoscaler.policy.PolicyManager; -import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; - -/** - * - * The Axis2 deployer class for Autoscale-policy definitions. - */ -public class AutoscalerPolicyDeployer extends AbstractDeployer { - - private static final Log log = LogFactory.getLog(AutoscalerPolicyDeployer.class); - - private static String fileExt="xml"; //default - private static String deployDirectory=null; - - @Override - public void init(ConfigurationContext context) { - if(deployDirectory!=null){ - File deployDir = new File(new File(context.getAxisConfiguration().getRepository().getPath()),deployDirectory); - if(!deployDir.exists()){ - //create policies deployment directory if not exist - try { - deployDir.mkdirs(); - } catch (Exception e) { - log.error("Unable to create policies deployment directory", e); - } - } - } - } - - @Override - public void setDirectory(String dir) { - deployDirectory = dir; - } - - @Override - public void setExtension(String ext) { - fileExt = ext; - } - - @Override - public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException { - - File policyFile = deploymentFileData.getFile(); - log.debug("Started to deploy the policy: " + policyFile); - - try { - - AutoscalerPolicyReader reader = new AutoscalerPolicyReader(policyFile); - - AutoscalePolicy policy = reader.read(); - PolicyManager.getInstance().deployAutoscalePolicy(policy); - - log.info("Successfully deployed the policy specified at " - + deploymentFileData.getAbsolutePath()); - - } catch (Exception e) { - String msg = "Invalid policy artifact at " + deploymentFileData.getAbsolutePath(); - // back up the file - File fileToBeRenamed = policyFile; - fileToBeRenamed.renameTo(new File(deploymentFileData.getAbsolutePath() + ".back")); - log.error(msg, e); - throw new DeploymentException(msg, e); - } - } - - @Override - public void undeploy(String fileName) throws DeploymentException { - /* - - String policyName = policyFile.getName().replaceAll("." + fileExt + "$", ""); - try { - PolicyManager.getInstance().removeAutoscalePolicy(policyFile); - log.info("Successfully undeployed the policy specified at " + fileName); - } catch (InvalidPolicyException e) { - log.error("unable to remove policy " + policyName , e); - throw new DeploymentException("unable to remove policy " + policyName ,e); - } - */ - } - - - - -} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ea1844f0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyReader.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyReader.java deleted file mode 100644 index c0c79a9..0000000 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AutoscalerPolicyReader.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.policy.deployers; - -import java.io.File; - -import javax.xml.namespace.QName; - -import org.apache.axiom.om.OMElement; -import org.apache.axis2.deployment.DeploymentException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.autoscaler.exception.InvalidPolicyException; -import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; -import org.apache.stratos.autoscaler.policy.model.LoadAverage; -import org.apache.stratos.autoscaler.policy.model.LoadThresholds; -import org.apache.stratos.autoscaler.policy.model.MemoryConsumption; -import org.apache.stratos.autoscaler.policy.model.RequestsInFlight; - -/** - * - * The Reader class for Autoscale-policy definitions. - */ -public class AutoscalerPolicyReader extends AbstractPolicyReader<AutoscalePolicy> { - - private static final Log log = LogFactory.getLog(AutoscalerPolicyReader.class); - - public AutoscalerPolicyReader(File file) { - super(file); - } - - public AutoscalePolicy read() throws InvalidPolicyException{ - AutoscalePolicy policy = new AutoscalePolicy(); - try { - OMElement docEle = getDocument(); - if("autoscalePolicy".equalsIgnoreCase(docEle.getLocalName())){ - policy.setId(docEle.getAttributeValue(new QName("id"))); - OMElement displayNameEle = docEle.getFirstChildWithName(new QName("displayName")); - if(displayNameEle!=null){ - policy.setDisplayName(displayNameEle.getText()); - } - OMElement descriptionEle = docEle.getFirstChildWithName(new QName("description")); - if(descriptionEle!=null){ - policy.setDescription(descriptionEle.getText()); - } - - //LoadThresholds - OMElement loadThresholdsEle = docEle.getFirstChildWithName(new QName("loadThresholds")); - LoadThresholds loadThresholds = new LoadThresholds(); - - //RequestsInFlight - OMElement reqInFlightEle = loadThresholdsEle.getFirstChildWithName(new QName("requestsInFlight")); - RequestsInFlight reqInFlight = new RequestsInFlight(); - reqInFlight.setAverage(Float.valueOf(readValueAttr(reqInFlightEle,"average"))); - reqInFlight.setGradient(Float.valueOf(readValueAttr(reqInFlightEle,"gradient"))); - reqInFlight.setSecondDerivative(Float.valueOf(readValueAttr(reqInFlightEle,"secondDerivative"))); - reqInFlight.setScaleDownMarginOfGradient(Float.valueOf(readValueAttr(reqInFlightEle,"scaleDownMarginOfGradient"))); - reqInFlight.setScaleDownMarginOfSecondDerivative(Float.valueOf(readValueAttr(reqInFlightEle,"scaleDownMarginOfSecondDerivative"))); - loadThresholds.setRequestsInFlight(reqInFlight); - - //MemoryConsumption - OMElement memConsumptionEle = loadThresholdsEle.getFirstChildWithName(new QName("memoryConsumption")); - MemoryConsumption memConsumption = new MemoryConsumption(); - memConsumption.setAverage(Float.valueOf(readValueAttr(memConsumptionEle,"average"))); - memConsumption.setGradient(Float.valueOf(readValueAttr(memConsumptionEle,"gradient"))); - memConsumption.setSecondDerivative(Float.valueOf(readValueAttr(memConsumptionEle,"secondDerivative"))); - memConsumption.setScaleDownMarginOfGradient(Float.valueOf(readValueAttr(memConsumptionEle,"scaleDownMarginOfGradient"))); - memConsumption.setScaleDownMarginOfSecondDerivative(Float.valueOf(readValueAttr(memConsumptionEle,"scaleDownMarginOfSecondDerivative"))); - loadThresholds.setMemoryConsumption(memConsumption); - - //LoadAverage - OMElement loadAvrEle = loadThresholdsEle.getFirstChildWithName(new QName("loadAverage")); - LoadAverage loadAvr = new LoadAverage(); - loadAvr.setAverage(Float.valueOf(readValueAttr(loadAvrEle,"average"))); - loadAvr.setGradient(Float.valueOf(readValueAttr(loadAvrEle,"gradient"))); - loadAvr.setSecondDerivative(Float.valueOf(readValueAttr(loadAvrEle,"secondDerivative"))); - loadAvr.setScaleDownMarginOfGradient(Float.valueOf(readValueAttr(loadAvrEle,"scaleDownMarginOfGradient"))); - loadAvr.setScaleDownMarginOfSecondDerivative(Float.valueOf(readValueAttr(loadAvrEle,"scaleDownMarginOfSecondDerivative"))); - loadThresholds.setLoadAverage(loadAvr); - - policy.setLoadThresholds(loadThresholds); - - } else{ - throw new DeploymentException("File is not a valid autoscale policy"); - } - - } catch (Exception e){ - log.error("Malformed autoscale policy file", e); - throw new InvalidPolicyException("Malformed autoscale policy file",e); - } finally{ - closeStream(); - } - return policy; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ea1844f0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadAverageThresholds.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadAverageThresholds.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadAverageThresholds.java new file mode 100644 index 0000000..81365e6 --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadAverageThresholds.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.policy.model; + +import java.io.Serializable; + +/** + * The model class for LoadAverage definition. + */ +public class LoadAverageThresholds implements Serializable{ + + private static final long serialVersionUID = -2109860338694123343L; + private float upperLimit = 80.0F; + private float lowerLimit = 20.0F; + + public float getUpperLimit() { + return upperLimit; + } + public void setUpperLimit(float upperLimit) { + this.upperLimit = upperLimit; + } + public float getLowerLimit() { + return lowerLimit; + } + public void setLowerLimit(float lowerLimit) { + this.lowerLimit = lowerLimit; + } + + @Override + public String toString() { + return "LoadAverage [upperLimit=" + upperLimit + ", lowerLimit=" + + lowerLimit + "]"; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ea1844f0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadThresholds.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadThresholds.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadThresholds.java index 61677d7..22e00a6 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadThresholds.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/LoadThresholds.java @@ -27,19 +27,19 @@ import java.io.Serializable; public class LoadThresholds implements Serializable{ private static final long serialVersionUID = -8148571245537655867L; - private RequestsInFlight requestsInFlight; - private MemoryConsumption memoryConsumption; - private LoadAverage loadAverage; + private RequestsInFlightThresholds requestsInFlight; + private MemoryConsumptionThresholds memoryConsumption; + private LoadAverageThresholds loadAverage; /** * Gets the value of the requestsInFlight property. * * @return * possible object is - * {@link RequestsInFlight } + * {@link RequestsInFlightThresholds } * */ - public RequestsInFlight getRequestsInFlight() { + public RequestsInFlightThresholds getRequestsInFlight() { return requestsInFlight; } @@ -48,10 +48,10 @@ public class LoadThresholds implements Serializable{ * * @param value * allowed object is - * {@link RequestsInFlight } + * {@link RequestsInFlightThresholds } * */ - public void setRequestsInFlight(RequestsInFlight value) { + public void setRequestsInFlight(RequestsInFlightThresholds value) { this.requestsInFlight = value; } @@ -60,10 +60,10 @@ public class LoadThresholds implements Serializable{ * * @return * possible object is - * {@link MemoryConsumption } + * {@link MemoryConsumptionThresholds } * */ - public MemoryConsumption getMemoryConsumption() { + public MemoryConsumptionThresholds getMemoryConsumption() { return memoryConsumption; } @@ -72,10 +72,10 @@ public class LoadThresholds implements Serializable{ * * @param value * allowed object is - * {@link MemoryConsumption } + * {@link MemoryConsumptionThresholds } * */ - public void setMemoryConsumption(MemoryConsumption value) { + public void setMemoryConsumption(MemoryConsumptionThresholds value) { this.memoryConsumption = value; } @@ -84,10 +84,10 @@ public class LoadThresholds implements Serializable{ * * @return * possible object is - * {@link LoadAverage } + * {@link LoadAverageThresholds } * */ - public LoadAverage getLoadAverage() { + public LoadAverageThresholds getLoadAverage() { return loadAverage; } @@ -96,10 +96,10 @@ public class LoadThresholds implements Serializable{ * * @param value * allowed object is - * {@link LoadAverage } + * {@link LoadAverageThresholds } * */ - public void setLoadAverage(LoadAverage value) { + public void setLoadAverage(LoadAverageThresholds value) { this.loadAverage = value; } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ea1844f0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/MemoryConsumptionThresholds.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/MemoryConsumptionThresholds.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/MemoryConsumptionThresholds.java new file mode 100644 index 0000000..5d637ba --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/MemoryConsumptionThresholds.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.policy.model; + +import java.io.Serializable; + +/** + * The model class for MemoryConsumption definition. + */ +public class MemoryConsumptionThresholds implements Serializable { + + private static final long serialVersionUID = 5755634390464664663L; + private float upperLimit = 80.0F; + private float lowerLimit = 20.0F; + + public float getUpperLimit() { + return upperLimit; + } + public void setUpperLimit(float upperLimit) { + this.upperLimit = upperLimit; + } + public float getLowerLimit() { + return lowerLimit; + } + public void setLowerLimit(float lowerLimit) { + this.lowerLimit = lowerLimit; + } + + @Override + public String toString() { + return "MemoryConsumption [upperLimit=" + upperLimit + ", lowerLimit=" + + lowerLimit + "]"; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ea1844f0/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/RequestsInFlightThresholds.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/RequestsInFlightThresholds.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/RequestsInFlightThresholds.java new file mode 100644 index 0000000..19b4eaa --- /dev/null +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/model/RequestsInFlightThresholds.java @@ -0,0 +1,53 @@ +/* + * 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.policy.model; + +import java.io.Serializable; + +/** + * The model class for RequestsInFlight definition. + */ +public class RequestsInFlightThresholds implements Serializable{ + + private static final long serialVersionUID = 8113964958155294290L; + private float upperLimit = 80.0F; + private float lowerLimit = 20.0F; + + public float getLowerLimit() { + return lowerLimit; + } + public void setLowerLimit(float lowerLimit) { + this.lowerLimit = lowerLimit; + } + public float getUpperLimit() { + return upperLimit; + } + public void setUpperLimit(float upperLimit) { + this.upperLimit = upperLimit; + } + @Override + public String toString() { + return "RequestsInFlight [upperLimit=" + upperLimit + ", lowerLimit=" + + lowerLimit + "]"; + } + + + +} \ No newline at end of file
