Repository: stratos Updated Branches: refs/heads/docker-grouping-merge 13245dcc2 -> a279f9c11
Introducing method org.apache.stratos.common.Properties.addProperty() and removing unused deployers in autoscaler component Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/378a6e5c Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/378a6e5c Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/378a6e5c Branch: refs/heads/docker-grouping-merge Commit: 378a6e5c2c1bd97f264521699f1020c3bf427b2a Parents: 7db5adf Author: Imesh Gunaratne <[email protected]> Authored: Tue Nov 4 15:35:59 2014 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Nov 4 15:35:59 2014 +0530 ---------------------------------------------------------------------- .../autoscaler/api/AutoScalerServiceImpl.java | 5 - .../applications/ApplicationUtils.java | 2 +- .../cloud/controller/CloudControllerClient.java | 4 +- .../monitor/cluster/AbstractClusterMonitor.java | 2 +- .../monitor/cluster/ClusterMonitorFactory.java | 12 +- .../KubernetesServiceClusterMonitor.java | 4 +- .../monitor/cluster/VMClusterMonitor.java | 2 +- .../cluster/VMServiceClusterMonitor.java | 4 +- .../partition/deployers/PartitionDeployer.java | 117 -------------- .../partition/deployers/PartitionReader.java | 154 ------------------- .../policy/deployers/AbstractPolicyReader.java | 93 ----------- .../deployers/DeploymentPolicyDeployer.java | 114 -------------- .../deployers/DeploymentPolicyReader.java | 130 ---------------- .../stratos/autoscaler/util/AutoscalerUtil.java | 4 +- .../src/main/resources/META-INF/component.xml | 16 -- .../policy/DeploymentPolicyDeployerTest.java | 68 ++++---- .../org/apache/stratos/common/Properties.java | 59 +++---- .../org/apache/stratos/common/Property.java | 12 +- 18 files changed, 93 insertions(+), 709 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/api/AutoScalerServiceImpl.java ---------------------------------------------------------------------- diff --git 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 index 91bbe76..fb50681 100644 --- 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 @@ -342,11 +342,6 @@ public class AutoScalerServiceImpl implements AutoScalerServiceInterface { return null; } - @Override - public void updateClusterMonitor(String clusterId, org.apache.stratos.common.Properties properties) throws InvalidArgumentException { - - } - public boolean checkClusterLBExistenceAgainstPolicy(String clusterId, String deploymentPolicyId) { for (PartitionGroup partitionGroup : PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId).getPartitionGroups()) { http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java index 0886353..3479f2f 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/applications/ApplicationUtils.java @@ -27,7 +27,7 @@ import org.apache.stratos.autoscaler.applications.payload.PayloadFactory; import org.apache.stratos.autoscaler.exception.ApplicationDefinitionException; import org.apache.stratos.cloud.controller.stub.pojo.CartridgeInfo; import org.apache.stratos.cloud.controller.stub.pojo.PortMapping; -import org.apache.stratos.common.xsd.Property; +import org.apache.stratos.common.Property; import java.util.*; import java.util.regex.Pattern; http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java index 4270669..374e092 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/client/cloud/controller/CloudControllerClient.java @@ -38,8 +38,8 @@ import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.common.kubernetes.KubernetesGroup; import org.apache.stratos.common.kubernetes.KubernetesMaster; -import org.apache.stratos.common.xsd.Properties; -import org.apache.stratos.common.xsd.Property; +import org.apache.stratos.common.Properties; +import org.apache.stratos.common.Property; import java.rmi.RemoteException; import java.util.ArrayList; http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java index f8e81b8..14f02dd 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/AbstractClusterMonitor.java @@ -31,7 +31,7 @@ import org.apache.stratos.autoscaler.monitor.events.MonitorScalingEvent; import org.apache.stratos.autoscaler.monitor.events.MonitorStatusEvent; import org.apache.stratos.autoscaler.monitor.events.MonitorTerminateAllEvent; import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; -import org.apache.stratos.common.xsd.Properties; +import org.apache.stratos.common.Properties; import org.apache.stratos.messaging.domain.topology.ClusterStatus; import org.apache.stratos.messaging.event.health.stat.AverageLoadAverageEvent; import org.apache.stratos.messaging.event.health.stat.AverageMemoryConsumptionEvent; http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java index 8c99d99..3a164f3 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/ClusterMonitorFactory.java @@ -40,8 +40,8 @@ import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; import org.apache.stratos.common.constants.StratosConstants; -import org.apache.stratos.common.xsd.Properties; -import org.apache.stratos.common.xsd.Property; +import org.apache.stratos.common.Properties; +import org.apache.stratos.common.Property; import org.apache.stratos.messaging.domain.topology.Cluster; import org.apache.stratos.messaging.domain.topology.ClusterStatus; import org.apache.stratos.messaging.domain.topology.Member; @@ -209,10 +209,10 @@ public class ClusterMonitorFactory { java.util.Properties properties) { Properties props = new Properties(); for (Map.Entry<Object, Object> e : properties.entrySet()) { - Property prop = new Property(); - prop.setName((String) e.getKey()); - prop.setValue((String) e.getValue()); - props.addProperties(prop); + Property property = new Property(); + property.setName((String) e.getKey()); + property.setValue((String) e.getValue()); + props.addProperty(property); } return props; } http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java index 324da34..d6dc3a3 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/KubernetesServiceClusterMonitor.java @@ -29,8 +29,8 @@ import org.apache.stratos.autoscaler.exception.InvalidArgumentException; import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; import org.apache.stratos.autoscaler.util.AutoScalerConstants; import org.apache.stratos.autoscaler.util.ConfUtil; -import org.apache.stratos.common.xsd.Properties; -import org.apache.stratos.common.xsd.Property; +import org.apache.stratos.common.Properties; +import org.apache.stratos.common.Property; import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.messaging.domain.topology.ClusterStatus; http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java index cd617ee..5931b88 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMClusterMonitor.java @@ -33,7 +33,7 @@ import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy; import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; import org.apache.stratos.autoscaler.status.checker.StatusChecker; import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; -import org.apache.stratos.common.xsd.Properties; +import org.apache.stratos.common.Properties; import org.apache.stratos.messaging.domain.topology.Cluster; import org.apache.stratos.messaging.domain.topology.Member; import org.apache.stratos.messaging.domain.topology.Service; http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java index a8b9329..2b0e4fd 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/cluster/VMServiceClusterMonitor.java @@ -35,8 +35,8 @@ import org.apache.stratos.autoscaler.rule.AutoscalerRuleEvaluator; import org.apache.stratos.autoscaler.util.AutoScalerConstants; import org.apache.stratos.autoscaler.util.ConfUtil; import org.apache.stratos.cloud.controller.stub.pojo.MemberContext; -import org.apache.stratos.common.xsd.Properties; -import org.apache.stratos.common.xsd.Property; +import org.apache.stratos.common.Properties; +import org.apache.stratos.common.Property; import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.messaging.domain.applications.ApplicationStatus; import org.apache.stratos.messaging.domain.applications.GroupStatus; http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java deleted file mode 100644 index 635fd09..0000000 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java +++ /dev/null @@ -1,117 +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.partition.deployers; - -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.partition.PartitionManager; -import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; - -import java.io.File; -import java.util.Iterator; -import java.util.List; - -/** - * - * The Axis2 deployer class for partition definitions definitions. - */ -public class PartitionDeployer extends AbstractDeployer { - - private static final Log log = LogFactory.getLog(PartitionDeployer.class); - - @SuppressWarnings("unused") - private String extension="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) { - extension = ext; - } - - @Override - public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException { - - File partitionFile = deploymentFileData.getFile(); - log.debug("Started to deploy the partitions of file: " + partitionFile); - - try { - - PartitionReader reader = new PartitionReader(partitionFile); - - List<Partition> partitionList = reader.getPartitionList(); - Iterator<Partition> it = partitionList.iterator(); - - while (it.hasNext()) { - Partition partition = it.next(); - try { - PartitionManager.getInstance().addNewPartition(partition); - } catch (Exception e) { - String msg = - "Invalid partition: " + partition.getId() + " in file: " + - partitionFile.getAbsolutePath()+". Cause: "+ e.getMessage(); - log.error(msg, e); - continue; - } - } - - - } catch (Exception e) { - String msg = "Invalid partition definition file: " + deploymentFileData.getAbsolutePath(); - // back up the file - File fileToBeRenamed = partitionFile; - fileToBeRenamed.renameTo(new File(deploymentFileData.getAbsolutePath() + ".back")); - log.error(msg, e); - throw new DeploymentException(msg, e); - } - } - - @Override - public void undeploy(String fileName) throws DeploymentException { - //TODO undeploy logic - } - - - - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java deleted file mode 100644 index 85956cf..0000000 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java +++ /dev/null @@ -1,154 +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.partition.deployers; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import javax.xml.namespace.QName; - -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMNode; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; -import org.apache.axiom.om.xpath.AXIOMXPath; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.autoscaler.util.AutoScalerConstants; -import org.apache.stratos.autoscaler.util.AutoscalerUtil; -import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; -import org.apache.stratos.common.xsd.Properties; -import org.jaxen.JaxenException; - -/** - * - * The Reader class for Deployment-policy definitions. - */ -public class PartitionReader{ - - private static final Log log = LogFactory.getLog(PartitionReader.class); - private static OMElement documentElement; - private File partitionFIle; - - public PartitionReader(File partitionFile){ - this.partitionFIle = partitionFile; - } - - public List<Partition> getPartitionList(){ - this.parse(this.partitionFIle); - String partitionXpath = "/"+AutoScalerConstants.PARTITIONS_ELEMENT + "/"+AutoScalerConstants.PARTITION_ELEMENT; - List<OMNode> partitionXMLNodes = getMatchingNodes(partitionXpath); - Iterator<OMNode> itr = partitionXMLNodes.iterator(); - List<Partition> partitonList = new ArrayList<Partition>(); - while (itr.hasNext()) { - OMNode node = itr.next(); - Partition partition = this.getPartition(node); - if (partition != null) { - partitonList.add(partition); - } - } - return partitonList; - } - - private Partition getPartition(final OMNode item) { - Partition partition = null; - - if (item.getType() == OMNode.ELEMENT_NODE) { - - OMElement partitionElt = (OMElement) item; - String partitionId = partitionElt.getAttributeValue(new QName("id")); - - if (partitionId == null) { - String msg ="Essential " + AutoScalerConstants.ID_ELEMENT + "element " + - "has not specified."; - log.warn("Partition is ignored. "+msg); - return null; - } - - partition = new Partition(); - partition.setId(partitionId); - Properties properties = AutoscalerUtil.getProperties(partitionElt); - if (properties != null) { - partition.setProperties(properties); - } - String providerValue = readValue(partitionElt, "provider"); - if (providerValue != null) { - partition.setProvider(providerValue); - } - String maxValue = readValue(partitionElt, "max"); - if (maxValue != null) { - partition.setPartitionMax(Integer.valueOf(maxValue)); - } - String minValue = readValue(partitionElt, "min"); - if (minValue != null) { - partition.setPartitionMin(Integer.valueOf(minValue)); - } - - } - return partition; - } - - public void parse(File xmlSource){ - - if (xmlSource.exists()) { - try { - documentElement = new StAXOMBuilder(xmlSource.getPath()).getDocumentElement(); - - } catch (Exception ex) { - String msg = "Error occurred when parsing the " + xmlSource.getPath() + "."; - //handleException(msg, ex); - } - } else { - String msg = "Configuration file cannot be found : " + xmlSource.getPath(); - //handleException(msg); - } - } - /** - * @param xpath XPATH expression to be read. - * @return List matching OMNode list - */ - @SuppressWarnings("unchecked") - public List<OMNode> getMatchingNodes(final String xpath) { - - AXIOMXPath axiomXpath; - List<OMNode> nodeList = null; - try { - axiomXpath = new AXIOMXPath(xpath); - nodeList = axiomXpath.selectNodes(documentElement); - } catch (JaxenException e) { - String msg = "Error occurred while reading the Xpath (" + xpath + ")"; - //log.error(msg, e); - } - - return nodeList; - } - - - - protected String readValue(OMElement ele, String qName) { - OMElement valueContainer = ele.getFirstChildWithName(new QName(qName)); - if(valueContainer == null) { - return null; - } - String value = valueContainer.getText(); - return value; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AbstractPolicyReader.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AbstractPolicyReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AbstractPolicyReader.java deleted file mode 100644 index 52efa90..0000000 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/AbstractPolicyReader.java +++ /dev/null @@ -1,93 +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 java.io.FileInputStream; -import java.io.IOException; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.autoscaler.exception.InvalidPolicyException; - -/** - * Abstract super-class, with some common logic, for reading policies. The only - * method subclasses must implement is read(). - */ -public abstract class AbstractPolicyReader<T> { - - private static final Log log = LogFactory.getLog(AbstractPolicyReader.class); - - protected File file; - private FileInputStream fStream; - - protected AbstractPolicyReader(File file) { - this.setFile(file); - } - - public File getFile() { - return file; - } - - public void setFile(File file) { - this.file = file; - } - - public abstract T read() throws InvalidPolicyException; - - protected OMElement getDocument() throws Exception { - fStream = new FileInputStream(file); - XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(fStream); - StAXOMBuilder builder = new StAXOMBuilder(parser); - return builder.getDocumentElement(); - } - - protected void closeStream() { - try { - if (fStream != null) { - fStream.close(); - } - } catch (IOException e) { - log.debug("Unable to close the input stream", e); - } - } - - protected String readValueAttr(OMElement ele, String qName) { - OMElement valueContainer = ele.getFirstChildWithName(new QName(qName)); - String value = valueContainer.getAttributeValue(new QName("value")); - return value; - } - - protected String readValue(OMElement ele, String qName) { - OMElement valueContainer = ele.getFirstChildWithName(new QName(qName)); - if(valueContainer == null) { - return null; - } - String value = valueContainer.getText(); - return value; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyDeployer.java ---------------------------------------------------------------------- diff --git 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 deleted file mode 100644 index a402915..0000000 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyDeployer.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.deployment.policy.DeploymentPolicy; -import org.apache.stratos.autoscaler.policy.PolicyManager; - -/** - * - * The Axis2 deployer class for Deployment-Policy definitions. - */ -public class DeploymentPolicyDeployer extends AbstractDeployer { - - private static final Log log = LogFactory.getLog(DeploymentPolicyDeployer.class); - - @SuppressWarnings("unused") - private String extension ="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) { - extension = ext; - } - - @Override - public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException { - - File policyFile = deploymentFileData.getFile(); - log.debug("Started to deploy the policy: " + policyFile); - - try { - - DeploymentPolicyReader reader = new DeploymentPolicyReader(policyFile); - - DeploymentPolicy policy = reader.read(); - PolicyManager.getInstance().addDeploymentPolicyToInformationModel(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 { - /* - File policyFile = new File(fileName); - String policyName = policyFile.getName().replaceAll("." + fileExt + "$", ""); - try { - PolicyManager.getInstance().removeDeploymentPolicy(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/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java deleted file mode 100644 index 704feaf..0000000 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/policy/deployers/DeploymentPolicyReader.java +++ /dev/null @@ -1,130 +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 java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -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.deployment.policy.DeploymentPolicy; -import org.apache.stratos.autoscaler.exception.InvalidPolicyException; -import org.apache.stratos.autoscaler.partition.PartitionGroup; -import org.apache.stratos.autoscaler.util.AutoscalerUtil; -import org.apache.stratos.cloud.controller.stub.deployment.partition.Partition; -import org.apache.stratos.common.xsd.Properties; - -/** - * - * The Reader class for Deployment-policy definitions. - */ -public class DeploymentPolicyReader extends AbstractPolicyReader<DeploymentPolicy> { - - private static final Log log = LogFactory.getLog(DeploymentPolicyReader.class); - - - public DeploymentPolicyReader(File file) { - super(file); - } - - public DeploymentPolicy read() throws InvalidPolicyException{ - DeploymentPolicy policy = new DeploymentPolicy(); - try { - OMElement docEle = getDocument(); - if("deploymentPolicy".equalsIgnoreCase(docEle.getLocalName())){ - policy.setId(docEle.getAttributeValue(new QName("id"))); - - //Partition-Groups - Iterator<?> partitionGroupItr = docEle.getChildrenWithLocalName("partitionGroup"); - while(partitionGroupItr.hasNext()){ - List<PartitionGroup> partitionGroups = new ArrayList<PartitionGroup>(); - Object nextGroup = partitionGroupItr.next(); - if(nextGroup instanceof OMElement){ - OMElement groupEle = (OMElement) nextGroup; - PartitionGroup group = new PartitionGroup(); - group.setId(groupEle.getAttributeValue(new QName("id"))); - group.setPartitionAlgo(readValue(groupEle, "partitionAlgo")); - - List<Partition> partitions = new ArrayList<Partition>() ; - //Partitions - Iterator<?> partitionItr = groupEle.getChildrenWithLocalName("partition"); - while(partitionItr.hasNext()){ - Object next = partitionItr.next(); - if(next instanceof OMElement){ - OMElement partitionElt = (OMElement) next; - - String partitionId = partitionElt.getAttributeValue(new QName("id")); - if (partitionId != null) { - Partition partition = new Partition(); - partition.setId(partitionId); - String maxValue = readValue(partitionElt, "max"); - if (maxValue != null) { - partition.setPartitionMax(Integer.valueOf(maxValue)); - } - String minValue = readValue(partitionElt, "min"); - if (minValue != null) { - partition.setPartitionMin(Integer.valueOf(minValue)); - } - String providerValue = readValue(partitionElt, "provider"); - if (providerValue != null) { - partition.setProvider(providerValue); - } - - Properties properties = AutoscalerUtil.getProperties(partitionElt); - if (properties != null) { - partition.setProperties(properties); - } - partitions.add(partition); - } else { - log.warn("Invalid Partition id: null. Partition will be ignored."); - } - } - } - if(group.getPartitions() == null) { - group.setPartitions(new Partition[0]); - } - group.setPartitions(partitions.toArray(group.getPartitions())); - partitionGroups.add(group); - } - if(policy.getPartitionGroups() == null) { - policy.setPartitionGroups(new PartitionGroup[0]); - } - policy.setPartitionGroups(partitionGroups.toArray(policy.getPartitionGroups())); - } - } else{ - throw new DeploymentException("File is not a valid deployment policy"); - } - - } catch (Exception e){ - log.error("Malformed deployment policy file", e); - throw new InvalidPolicyException("Malformed deployment policy file",e); - } finally{ - closeStream(); - } - return policy; - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java index f9eea5a..c0ac178 100644 --- a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java +++ b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java @@ -28,8 +28,8 @@ import org.apache.axiom.om.OMElement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.autoscaler.registry.RegistryManager; -import org.apache.stratos.common.xsd.Properties; -import org.apache.stratos.common.xsd.Property; +import org.apache.stratos.common.Properties; +import org.apache.stratos.common.Property; import org.apache.stratos.messaging.domain.applications.Application; import org.apache.stratos.messaging.domain.applications.Applications; http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml index 255bdde..2467480 100644 --- a/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml +++ b/components/org.apache.stratos.autoscaler/src/main/resources/META-INF/component.xml @@ -18,22 +18,6 @@ --> <component xmlns="http://products.wso2.org/carbon"> <deployers> - <!-- - <deployer> - <directory>autoscale-policies</directory> - <extension>xml</extension> - <class>org.apache.stratos.autoscaler.policy.deployers.AutoscalerPolicyDeployer</class> - </deployer> - <deployer> - <directory>deployment-policies</directory> - <extension>xml</extension> - <class>org.apache.stratos.autoscaler.policy.deployers.DeploymentPolicyDeployer</class> - </deployer> - <deployer> - <directory>partitions</directory> - <extension>xml</extension> - <class>org.apache.stratos.autoscaler.partition.deployers.PartitionDeployer</class> - </deployer>--> </deployers> <ManagementPermissions> <ManagementPermission> http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/deployment/policy/DeploymentPolicyDeployerTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/deployment/policy/DeploymentPolicyDeployerTest.java b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/deployment/policy/DeploymentPolicyDeployerTest.java index b7ef179..fd341c0 100644 --- a/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/deployment/policy/DeploymentPolicyDeployerTest.java +++ b/components/org.apache.stratos.autoscaler/src/test/java/org/apache/stratos/autoscaler/deployment/policy/DeploymentPolicyDeployerTest.java @@ -16,37 +16,37 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.stratos.autoscaler.deployment.policy; - -import static org.junit.Assert.*; - -import java.io.File; - -import org.apache.stratos.autoscaler.exception.InvalidPolicyException; -import org.apache.stratos.autoscaler.policy.deployers.DeploymentPolicyReader; -import org.junit.Before; -import org.junit.Test; - -/** - * @author nirmal - * - */ -public class DeploymentPolicyDeployerTest { - - DeploymentPolicyReader reader; - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - reader = new DeploymentPolicyReader(new File("src/test/resources/deployment-policy.xml")); - } - - @Test - public void test() throws InvalidPolicyException { - - DeploymentPolicy policy = reader.read(); - } - -} +//package org.apache.stratos.autoscaler.deployment.policy; +// +//import static org.junit.Assert.*; +// +//import java.io.File; +// +//import org.apache.stratos.autoscaler.exception.InvalidPolicyException; +//import org.apache.stratos.autoscaler.policy.deployers.DeploymentPolicyReader; +//import org.junit.Before; +//import org.junit.Test; +// +///** +// * @author nirmal +// * +// */ +//public class DeploymentPolicyDeployerTest { +// +// DeploymentPolicyReader reader; +// +// /** +// * @throws java.lang.Exception +// */ +// @Before +// public void setUp() throws Exception { +// reader = new DeploymentPolicyReader(new File("src/test/resources/deployment-policy.xml")); +// } +// +// @Test +// public void test() throws InvalidPolicyException { +// +// DeploymentPolicy policy = reader.read(); +// } +// +//} http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Properties.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Properties.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Properties.java index 25fea6e..1b8ef93 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Properties.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Properties.java @@ -18,8 +18,14 @@ */ package org.apache.stratos.common; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.io.Serializable; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.List; /** * Had to wrap {@link Property} array using a class, since there's a bug in current @@ -27,54 +33,53 @@ import java.util.Arrays; */ public class Properties implements Serializable { - private Property[] properties; + private static final long serialVersionUID = -9094584151615076171L; + private static final Log log = LogFactory.getLog(Properties.class); + + private List<Property> properties; + + public Properties() { + this.properties = new ArrayList<Property>(); + } public Property[] getProperties() { - return properties; + return properties.toArray(new Property[properties.size()]); } - public void setProperties(Property[] properties) { - if(properties == null) { - this.properties = new Property[0]; - } else { - this.properties = Arrays.copyOf(properties, properties.length); + public void addProperty(Property property) { + try { + this.properties.add((Property) property.clone()); + } catch (CloneNotSupportedException e) { + log.error(e); } } + public void setProperties(Property[] properties) { + this.properties = new ArrayList<Property>(); + Collections.addAll(this.properties, properties.clone()); + } + @Override public String toString() { - return "Properties [properties=" + Arrays.toString(properties) + "]"; + return "Properties [properties=" + this.getProperties() + "]"; } @Override - public boolean equals(Object anObject) { - if (anObject == null) { - return false; - } - if (this == anObject) { + public boolean equals(Object object) { + if (object == null) { return false; } - if (!(anObject instanceof Properties)) { - return false; - } - Properties propertiesObj = (Properties) anObject; - if (this.properties == null) { - if (propertiesObj.getProperties() != null) { - return false; - } - } else if (!Arrays.equals(this.properties, propertiesObj.getProperties())) { + if (!(object instanceof Properties)) { return false; } - return true; + Properties propertiesObject = (Properties) object; + return Arrays.equals(propertiesObject.getProperties(), this.getProperties()); } @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.properties == null) ? 0 : Arrays.hashCode(this.properties)); - return result; + return this.hashCode(); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/378a6e5c/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Property.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Property.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Property.java index 2658916..7ac6b02 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Property.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/Property.java @@ -23,14 +23,14 @@ import java.io.Serializable; /** * Holds a property */ -public class Property implements Serializable { +public class Property implements Serializable, Cloneable { private static final long serialVersionUID = -2191782657999410197L; + private String name; private String value; public Property() { - } public Property(String name, String value) { @@ -55,6 +55,14 @@ public class Property implements Serializable { } @Override + protected Object clone() throws CloneNotSupportedException { + Property clone = new Property(); + clone.setName(this.getName()); + clone.setValue(this.getValue()); + return clone; + } + + @Override public String toString() { return "Property [name=" + name + ", value=" + value + "]"; }
