You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ud...@apache.org on 2013/11/30 10:19:50 UTC
[5/9] git commit: Merge branch 'm4' Add partition deployer Conflicts:
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
components/org.apache.stratos.autoscaler/src/main/java/org/apache/
Merge branch 'm4'
Add partition deployer
Conflicts:
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/OneAfterAnother.java
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/algorithm/RoundRobin.java
components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/util/AutoscalerUtil.java
components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.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/0a06ba28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/0a06ba28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/0a06ba28
Branch: refs/heads/master
Commit: 0a06ba28662283e191b26f7f74b2f915e8ce9288
Parents: 7afbe41 dca46e3
Author: Udara Liyanage <ud...@wso2.com>
Authored: Fri Nov 29 14:01:47 2013 -0500
Committer: Udara Liyanage <ud...@wso2.com>
Committed: Fri Nov 29 14:10:31 2013 -0500
----------------------------------------------------------------------
.../exception/InvalidPartitionException.java | 40 +++++
.../partition/deployers/PartitionDeployer.java | 103 +++++++++++
.../partition/deployers/PartitionReader.java | 174 +++++++++++++++++++
.../autoscaler/util/AutoScalerConstants.java | 33 ++++
.../src/main/resources/META-INF/component.xml | 5 +
5 files changed, 355 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0a06ba28/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionDeployer.java
index 0000000,6bba10e..e14f332
mode 000000,100644..100644
--- 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
@@@ -1,0 -1,103 +1,103 @@@
+ /*
+ * 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.List;
++
+ 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.cloud.controller.deployment.partition.Partition;
+
+ /**
+ *
+ * The Axis2 deployer class for party definitions definitions.
+ */
+ public class PartitionDeployer extends AbstractDeployer {
+
+ private static final Log log = LogFactory.getLog(PartitionDeployer.class);
+
+ private static String fileExt="xml"; //default
+ private static String deployDirectory=null;
+
+ @Override
+ public void init(ConfigurationContext context) {
- System.out.println("********Deploying init");
+ 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 partitionFile = deploymentFileData.getFile();
+ log.debug("Started to deploy the policy: " + partitionFile);
- System.out.println("********Deploying stated " + partitionFile);
+
+ try {
- /*
++
+ PartitionReader reader = new PartitionReader(partitionFile);
+
+ List<Partition> partitionList = reader.getPartitionList();
+
+
+ log.info("Successfully deployed the partition specified at "
+ + deploymentFileData.getAbsolutePath());
- */
++
+ } catch (Exception e) {
+ String msg = "Invalid partition artifact at " + 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 {
- System.out.println("****************************************************");
-
++ //TODO undeploy logic
+ }
+
+
+
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0a06ba28/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
----------------------------------------------------------------------
diff --cc components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/partition/deployers/PartitionReader.java
index 0000000,a6c45f1..4f635e7
mode 000000,100644..100644
--- 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
@@@ -1,0 -1,144 +1,174 @@@
+ /*
+ * 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.axis2.deployment.DeploymentException;
+ import org.apache.commons.logging.Log;
+ import org.apache.commons.logging.LogFactory;
+ import org.apache.stratos.autoscaler.exception.InvalidPartitionException;
-import org.apache.stratos.autoscaler.policy.InvalidPolicyException;
-import org.apache.stratos.autoscaler.policy.model.DeploymentPolicy;
-import org.apache.stratos.autoscaler.policy.model.Partition;
++import org.apache.stratos.cloud.controller.deployment.partition.Partition;
++import org.apache.stratos.cloud.controller.pojo.Properties;
++import org.apache.stratos.cloud.controller.pojo.Property;
+ import org.apache.stratos.autoscaler.util.AutoScalerConstants;
+ 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() throws InvalidPartitionException{
+ this.parse(this.partitionFIle);
- List<OMNode> partitionXMLNodes = getMatchingNodes("/partitions/partition");
++ 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();
+ //System.out.println("node " + node);
+ partitonList.add(this.getPartition(node));
+ }
+ return partitonList;
+ }
+
+ private Partition getPartition(final OMNode item) {
+ Partition partition = null;
+ String id = null;
+
+ if (item.getType() == OMNode.ELEMENT_NODE) {
+
+ OMElement iaasElt = (OMElement) item;
+ Iterator<?> it =
+ iaasElt.getChildrenWithName(new QName(AutoScalerConstants.ID_ELEMENT));
+
+ if (it.hasNext()) {
+ OMElement providerElt = (OMElement) it.next();
+ id = providerElt.getText();
+ }
+
+ if (it.hasNext()) {
+ log.warn( " contains more than one " + AutoScalerConstants.ID_ELEMENT +
+ " elements!" + " Elements other than the first will be neglected.");
+ }
+
+ if (id == null) {
+ String msg ="Essential " + AutoScalerConstants.ID_ELEMENT + "element " +
+ "has not specified in ";
+ // handleException(msg);
+ }
- //boolean partitionExist = TopologyManager.getInstance().getTopology().partitionExist(id);
++ // boolean partitionExist = TopologyManager.getInstance().getTopology().partitionExist(id);
+ boolean partitionExist =false;
+ if(!partitionExist){
+ partition = new Partition();
+ partition.setId(id);
- //loadProperties(iaasElt, partition.getProperties());
- //handle partition created event
- //TopologyBuilder.handlePartitionCreated(partition);
++ partition.setProperties(getProperties(iaasElt));
++
+ }
+ }
+ 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 static List<OMNode> getMatchingNodes(final String xpath) {
++ 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);
- //throw new CloudControllerException(msg, e);
+ }
+
+ return nodeList;
+ }
++
++ private Properties getProperties(final OMElement elt) {
++
++ Iterator<?> it = elt.getChildrenWithName(new QName(AutoScalerConstants.PROPERTY_ELEMENT));
++ ArrayList<Property> propertyList = new ArrayList<Property>();
++
++ while (it.hasNext()) {
++ OMElement prop = (OMElement) it.next();
++
++ if (prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_NAME_ATTR)) == null ||
++ prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_VALUE_ATTR)) == null) {
++
++ String msg =
++ "Property element's, name and value attributes should be specified " +
++ "in ";
++
++ //handleException(msg);
++ }
++
++ String name = prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_NAME_ATTR)).getAttributeValue();
++ String value = prop.getAttribute(new QName(AutoScalerConstants.PROPERTY_VALUE_ATTR)).getAttributeValue();
++
++ Property property = new Property();
++ property.setName(name);
++ property.setValue(value);
++ propertyList.add(property);
++ }
++
++ Property[] propertyArray = propertyList.toArray(new Property[propertyList.size()]);
++ Properties preoperties = new Properties();
++ preoperties.setProperties(propertyArray);
++ return preoperties;
++ }
+
+ }
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/0a06ba28/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 0000000,b1fd9c5..de51f9b
mode 000000,100644..100644
--- 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
@@@ -1,0 -1,30 +1,33 @@@
+ /*
+ * 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.util;
+
+ public final class AutoScalerConstants {
+
+ /**
+ * Constant values for Auto Scaler
+ */
+ public static final String ID_ELEMENT = "id";
+ public static final String PARTITION_ELEMENT = "partition";
+ public static final String PARTITIONS_ELEMENT = "partitions";
++ public static final String PROPERTY_ELEMENT = "property";
++ public static final String PROPERTY_NAME_ATTR= "name";
++ public static final String PROPERTY_VALUE_ATTR = "value";
+
+ }