You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/04 14:26:40 UTC
[09/10] Apache Stratos Cloud Controller Component refactoring
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
new file mode 100644
index 0000000..79987b0
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
@@ -0,0 +1,110 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.deployers;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+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.stratos.cloud.controller.axiom.AxiomXpathParser;
+import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+
+/**
+ * All the {@link IaasProvider}s will get deployed / undeployed / updated via this class.
+ */
+public class CloudControllerDeployer extends AbstractDeployer{
+
+ private static final Log log = LogFactory.getLog(CloudControllerDeployer.class);
+ private static final String FILE_NAME = "cloud-controller";
+ private Map<String, List<IaasProvider>> fileToIaasProviderListMap;
+
+ @Override
+ public void init(ConfigurationContext arg0) {
+ fileToIaasProviderListMap = new ConcurrentHashMap<String, List<IaasProvider>>();
+ }
+
+ @Override
+ public void setDirectory(String arg0) {
+ // component xml handles this
+
+ }
+
+ @Override
+ public void setExtension(String arg0) {
+ // component xml handles this
+ }
+
+ public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
+
+ log.debug("Started to deploy the deployment artifact: "+deploymentFileData.getFile());
+
+ // since cloud-controller.xml resides in repository/conf
+ if (deploymentFileData.getName().contains(FILE_NAME)) {
+
+ AxiomXpathParser parser = new AxiomXpathParser(deploymentFileData.getFile());
+
+ // parse the file
+ parser.parse();
+
+ // deploy iaases
+ parser.setIaasProvidersList();
+ parser.setDataPublisherRelatedData();
+ parser.setTopologySyncRelatedData();
+
+ // update map
+ fileToIaasProviderListMap.put(deploymentFileData.getAbsolutePath(),
+ new ArrayList<IaasProvider>(
+ FasterLookUpDataHolder.getInstance()
+ .getIaasProviders()));
+
+ log.info("Successfully deployed the cloud-controller XML file specified at " +
+ deploymentFileData.getAbsolutePath());
+ }
+
+ }
+
+
+ public void undeploy(String file) throws DeploymentException {
+
+ if (file.contains(FILE_NAME)) {
+ // reset
+ FasterLookUpDataHolder.getInstance().setSerializationDir("");
+
+ // grab the entry from Map
+ if(fileToIaasProviderListMap.containsKey(file)){
+ // remove 'em
+ FasterLookUpDataHolder.getInstance().getIaasProviders().removeAll(fileToIaasProviderListMap.get(file));
+
+ log.info("Successfully undeployed the cloud-controller XML file specified at "+file);
+ }
+ // only one cloud-controller file, hence delete 'em all
+// FasterLookUpDataHolder.getInstance().setIaasProviders(new ArrayList<IaasProvider>());
+
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
new file mode 100644
index 0000000..2e37bef
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
@@ -0,0 +1,152 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.deployers;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+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.stratos.cloud.controller.axiom.AxiomXpathParser;
+import org.apache.stratos.cloud.controller.consumers.TopologyBuilder;
+import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
+import org.apache.stratos.cloud.controller.util.ServiceContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.utils.CarbonUtils;
+
+/**
+ * All the {@link org.apache.stratos.cloud.controller.util.Cartridge}s will get deployed / undeployed / updated via this class.
+ */
+public class ServiceDeployer extends AbstractDeployer{
+
+ private static final Log log = LogFactory.getLog(ServiceDeployer.class);
+
+ private FasterLookUpDataHolder serviceContextLookUpStructure;
+ private Map<String, List<ServiceContext>> fileToServiceContextListMap;
+ private File servicesSchema, serviceSchema;
+
+ @Override
+ public void init(ConfigurationContext arg0) {
+ fileToServiceContextListMap = new ConcurrentHashMap<String, List<ServiceContext>>();
+ String etcDir = CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc" + File.separator;
+ servicesSchema = new File(etcDir+"services.xsd");
+ serviceSchema = new File(etcDir+"service.xsd");
+ }
+
+ @Override
+ public void setDirectory(String arg0) {
+ // component xml handles this
+ }
+
+ @Override
+ public void setExtension(String arg0) {
+ // component xml handles this
+ }
+
+ public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
+
+ log.debug("Started to deploy the deployment artefact: "+deploymentFileData.getFile());
+ serviceContextLookUpStructure = FasterLookUpDataHolder.getInstance();
+
+ AxiomXpathParser parser = new AxiomXpathParser(deploymentFileData.getFile());
+ parser.parse();
+
+ // validate
+ try {
+ validateService(parser);
+
+ } catch (Exception e) {
+ String msg = "Invalid deployment artefact at "+deploymentFileData.getAbsolutePath();
+ // back up the file
+ File f = deploymentFileData.getFile();
+ f.renameTo(new File(deploymentFileData.getAbsolutePath()+".back"));
+ log.error(msg, e);
+ throw new DeploymentException(msg, e);
+ }
+
+ // deploy
+ List<ServiceContext> services = parser.getServiceContexts();
+
+ // notify consumer by adding the diff
+ try {
+ serviceContextLookUpStructure.getSharedTopologyDiffQueue().put(services);
+ } catch (InterruptedException ignore) {
+ }
+
+ // update map
+ fileToServiceContextListMap.put(deploymentFileData.getAbsolutePath(), new ArrayList<ServiceContext>(services));
+
+ log.info("Successfully deployed the Service definition specified at "+deploymentFileData.getAbsolutePath());
+ }
+
+ private void validateService(AxiomXpathParser parser) throws Exception {
+ boolean validated = false;
+ Exception firstException = null;
+
+ try{
+ // first try to validate using services schema
+ parser.validate(servicesSchema);
+ validated = true;
+ log.debug("Service validation was successful.");
+
+ }catch (Exception e) {
+ firstException = e;
+ }
+
+ if(!validated){
+ try{
+ // Now try to validate using service schema
+ parser.validate(serviceSchema);
+ validated = true;
+ log.debug("Service validation was successful.");
+
+ }catch (Exception e) {
+ String msg = "Service XML validation failed. Invalid Service XML: "+parser.getXmlSource().getAbsolutePath();
+ log.error(msg, firstException);
+ throw firstException;
+ }
+ }
+
+
+ }
+
+ public void undeploy(String file) throws DeploymentException {
+
+ serviceContextLookUpStructure = FasterLookUpDataHolder.getInstance();
+
+ // grab the entry from Map
+ if(fileToServiceContextListMap.containsKey(file)){
+ // remove 'em all
+ for (ServiceContext ctxt : fileToServiceContextListMap.get(file)) {
+ serviceContextLookUpStructure.removeServiceContext(ctxt);
+ // remove from the topology
+ TopologyBuilder.removeTopologyAndPublish(ctxt);
+ }
+
+ log.info("Successfully undeployed the Service definition specified at "+file);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java
new file mode 100644
index 0000000..08e57f5
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class CloudControllerException extends RuntimeException {
+
+ private static final long serialVersionUID = -6326227079367867222L;
+
+ public CloudControllerException(String msg) {
+ super(msg);
+ }
+
+ public CloudControllerException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java
new file mode 100644
index 0000000..33ec80b
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class DeserializationException extends RuntimeException {
+
+ private static final long serialVersionUID = -2426068347954381831L;
+
+ public DeserializationException(String msg) {
+ super(msg);
+ }
+
+ public DeserializationException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java
new file mode 100644
index 0000000..363dc38
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class InvalidCartridgeDefinitionException extends Exception {
+
+ private static final long serialVersionUID = -6326227079367867222L;
+
+ public InvalidCartridgeDefinitionException(String msg) {
+ super(msg);
+ }
+
+ public InvalidCartridgeDefinitionException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java
new file mode 100644
index 0000000..d0bab7e
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java
@@ -0,0 +1,36 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class InvalidXMLException extends RuntimeException {
+
+ private static final long serialVersionUID = -6326227079367867222L;
+
+ public InvalidXMLException(String msg) {
+ super(msg);
+ }
+
+ public InvalidXMLException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+ public InvalidXMLException(Exception ex) {
+ super(ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java
new file mode 100644
index 0000000..db268f2
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class MalformedConfigurationFileException extends RuntimeException {
+
+ private static final long serialVersionUID = -1662095377704279326L;
+
+ public MalformedConfigurationFileException(String msg) {
+ super(msg);
+ }
+
+ public MalformedConfigurationFileException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java
new file mode 100644
index 0000000..c85d47a
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. 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.cloud.controller.exception;
+
+/**
+ * This will throw when no instance is found
+ */
+public class NoInstanceFoundException extends Exception {
+
+ /**
+ * For serializing requirement
+ */
+ private static final long serialVersionUID = -435060299292679892L;
+
+
+ public NoInstanceFoundException(String msg) {
+ super(msg);
+ }
+
+ public NoInstanceFoundException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java
new file mode 100644
index 0000000..b2e2302
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class SerializationException extends RuntimeException {
+
+ private static final long serialVersionUID = -3701458642228072331L;
+
+ public SerializationException(String msg) {
+ super(msg);
+ }
+
+ public SerializationException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java
new file mode 100644
index 0000000..96e2236
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class UnregisteredCartridgeException extends Exception {
+
+ private static final long serialVersionUID = -6326227079367867222L;
+
+ public UnregisteredCartridgeException(String msg) {
+ super(msg);
+ }
+
+ public UnregisteredCartridgeException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
new file mode 100644
index 0000000..166be6d
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
@@ -0,0 +1,32 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.exception;
+
+public class UnregisteredServiceException extends Exception {
+
+ private static final long serialVersionUID = -6326227079367867222L;
+
+ public UnregisteredServiceException(String msg) {
+ super(msg);
+ }
+
+ public UnregisteredServiceException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
new file mode 100644
index 0000000..71aa720
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
@@ -0,0 +1,181 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.hector;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+
+import me.prettyprint.cassandra.model.BasicColumnDefinition;
+import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
+import me.prettyprint.cassandra.model.CqlQuery;
+import me.prettyprint.cassandra.model.CqlRows;
+import me.prettyprint.cassandra.serializers.StringSerializer;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
+import me.prettyprint.cassandra.service.ThriftCfDef;
+import me.prettyprint.hector.api.Cluster;
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.beans.Row;
+import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
+import me.prettyprint.hector.api.ddl.ColumnIndexType;
+import me.prettyprint.hector.api.ddl.ComparatorType;
+import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
+import me.prettyprint.hector.api.factory.HFactory;
+import me.prettyprint.hector.api.query.QueryResult;
+
+public class CassandraDataRetriever {
+
+ private static final Log log = LogFactory.getLog(CassandraDataRetriever.class);
+ private static FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+ private final static StringSerializer se = StringSerializer.get();
+ private static Cluster cluster;
+ private static Keyspace keyspace;
+ private static boolean isInit;
+
+ public static void init() {
+
+ if(isInit){
+ return;
+ }
+ getCassandraKeyspace();
+ indexCounterColumn("payload_status");
+ isInit = true;
+ }
+
+ public static void connect() {
+
+ if(keyspace == null){
+ handleException("Cannot find the key space.");
+ }
+
+ String colFamily = CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY;
+
+ CqlQuery<String,String,String> cqlQuery = new CqlQuery<String,String,String>(keyspace, se, se, se);
+ cqlQuery.setQuery("select payload_nodeId from "+colFamily+" where payload_status='RUNNING'");
+// cqlQuery.setQuery("select * from "+colFamily+" where payload_domain='nirmal'");
+ QueryResult<CqlRows<String,String,String>> result = cqlQuery.execute();
+
+ if (result != null && result.get() != null) {
+ List<Row<String, String, String>> list = result.get().getList();
+ for (Row<?, ?, ?> row : list) {
+ System.out.println(".");
+ List<?> columns = row.getColumnSlice().getColumns();
+ for (Iterator<?> iterator = columns.iterator(); iterator.hasNext();) {
+ HColumn<?, ?> column = (HColumn<?, ?>) iterator.next();
+ System.out.print(column.getName() + ":" + column.getValue()
+ + "\t");
+ }
+ System.out.println("");
+ }
+ }
+
+// ColumnQuery<String, String, String> columnQuery =
+// HFactory.createStringColumnQuery(keyspace);
+// KeyIterator<String> keyIterator = new KeyIterator<String>(keyspace, colFamily, StringSerializer.get());
+// for ( String key : keyIterator ) {
+//
+// columnQuery.setColumnFamily(colFamily).setKey(key).setName("payload_nodeId");
+// QueryResult<HColumn<String, String>> result = columnQuery.execute();
+// HColumn<String, String> hColumn = result.get();
+// System.out.println("Column: " + hColumn.getName() + " Value : " + hColumn.getValue() + "\n");
+// }
+
+// //Read Data
+// for (String key : keyList) {
+// System.out.println("\nretrieving Key " + rowKey + "From Column Family " + columnFamily + "\n");
+// for (String columnName : columnList.split(":")) {
+// //sout data
+// }
+// }
+
+
+ }
+
+ private static void indexCounterColumn(String idxColumnName) {
+
+ KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE);
+
+ List<ColumnFamilyDefinition> cdfs = keyspaceDefinition.getCfDefs();
+ ColumnFamilyDefinition cfd = null;
+ for (ColumnFamilyDefinition c : cdfs) {
+ if (c.getName().equals(CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY)) {
+ System.out.println(c.getName());
+ cfd = c;
+ break;
+ }
+ }
+
+ BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition(cfd);
+
+ BasicColumnDefinition bcdf = new BasicColumnDefinition();
+ bcdf.setName(StringSerializer.get().toByteBuffer(idxColumnName));
+ bcdf.setIndexName(idxColumnName + "index");
+ bcdf.setIndexType(ColumnIndexType.KEYS);
+ bcdf.setValidationClass(ComparatorType.UTF8TYPE.getClassName());
+
+ columnFamilyDefinition.addColumnDefinition(bcdf);
+ cluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition));
+
+ }
+
+ private static void getCassandraKeyspace() {
+ if (cluster == null) {
+ Map<String, String> credentials = new HashMap<String, String>();
+ credentials.put("username", dataHolder.getCassandraUser());
+ credentials.put("password", dataHolder.getCassandraPassword());
+
+ cluster =
+ retrieveCassandraCluster(CloudControllerConstants.DEFAULT_CASSANDRA_CLUSTER_NAME,
+ dataHolder.getCassandraConnUrl(), credentials);
+
+ keyspace =
+ HFactory.createKeyspace(CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE,
+ cluster);
+ }
+
+ }
+
+ private static Cluster retrieveCassandraCluster(String clusterName, String connectionUrl,
+ Map<String, String> credentials) {
+
+ CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator(connectionUrl);
+ hostConfigurator.setRetryDownedHosts(false);
+ Cluster cluster = HFactory.createCluster(clusterName, hostConfigurator, credentials);
+ return cluster;
+ }
+
+ private static void handleException(String msg) {
+
+ log.error(msg);
+ throw new CloudControllerException(msg);
+ }
+
+// private void handleException(String msg, Exception e) {
+//
+// log.error(msg, e);
+// throw new AutoscalerServiceException(msg, e);
+// }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
new file mode 100644
index 0000000..fbbf940
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
@@ -0,0 +1,167 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.hive;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.transport.http.HttpTransportProperties;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceHiveExecutionException;
+import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub;
+import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub.QueryResult;
+import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub.QueryResultRow;
+import org.wso2.carbon.base.ServerConfiguration;
+import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.wso2.carbon.utils.CarbonUtils;
+
+public class HiveQueryExecutor {
+ private static final Log log = LogFactory.getLog(HiveQueryExecutor.class);
+ private HiveExecutionServiceStub hiveService;
+ private String payloadPrefix = CloudControllerConstants.PAYLOAD_PREFIX;
+ private String hiveTable = "cloudController";
+ private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+
+ public HiveQueryExecutor() {
+
+ ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
+ String bamServerUrl = serverConfig.getFirstProperty("BamServerURL");
+ String serviceName = "HiveExecutionService";
+ HttpTransportProperties.Authenticator authenticator;
+
+ try {
+ hiveService = new HiveExecutionServiceStub(bamServerUrl+"/services/"+serviceName);
+
+ // admin service authentication
+ authenticator = new HttpTransportProperties.Authenticator();
+ authenticator.setUsername(dataHolder.getBamUsername());
+ authenticator.setPassword(dataHolder.getBamPassword());
+ authenticator.setPreemptiveAuthentication(true);
+
+ ServiceClient client = hiveService._getServiceClient();
+ Options option = client.getOptions();
+ option.setManageSession(true);
+ option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
+ option.setTimeOutInMilliSeconds(120000);
+
+ } catch (AxisFault e) {
+ String msg = "Cannot get a connection to "+serviceName;
+ handleException(msg, e);
+ }
+ }
+
+ public QueryResult[] execute(String query){
+ try {
+ return hiveService.executeHiveScript(query);
+ } catch (RemoteException e) {
+ handleException("Query : '"+query+"' - "+e.getMessage(), e);
+ } catch (HiveExecutionServiceHiveExecutionException e) {
+ handleException("Query : '"+query+"' - "+e.getMessage(), e);
+ }
+
+ return new QueryResult[0];
+ }
+
+ public void createHiveTable(){
+ String query =
+ "CREATE EXTERNAL TABLE IF NOT EXISTS "+hiveTable+" (id STRING, " +
+ payloadPrefix+CloudControllerConstants.NODE_ID_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.CARTRIDGE_TYPE_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.DOMAIN_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.HOST_NAME_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.HYPERVISOR_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.IAAS_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.IMAGE_ID_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.LOGIN_PORT_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.PRIV_IP_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.PUB_IP_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.STATUS_COL+" STRING," +
+ payloadPrefix+CloudControllerConstants.SUB_DOMAIN_COL+" STRING" +
+ ") STORED BY 'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' " +
+ "WITH SERDEPROPERTIES ( \"cassandra.host\" = \""+dataHolder.getCassandraConnUrl().split(":")[0]+"\"," +
+ "\"cassandra.port\" = \""+dataHolder.getCassandraConnUrl().split(":")[1]+
+ "\",\"cassandra.ks.name\" = \""+CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE+"\"," +
+ "\"cassandra.ks.username\" = \""+dataHolder.getCassandraUser()+
+ "\", \"cassandra.ks.password\" = \""+dataHolder.getCassandraPassword()+"\"," +
+ "\"cassandra.cf.name\" = \""+CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY+"\"," +
+ "\"cassandra.columns.mapping\" = \"" +
+ payloadPrefix+CloudControllerConstants.NODE_ID_COL+"," +
+ payloadPrefix+CloudControllerConstants.CARTRIDGE_TYPE_COL+"," +
+ payloadPrefix+CloudControllerConstants.DOMAIN_COL+"," +
+ payloadPrefix+CloudControllerConstants.HOST_NAME_COL+"," +
+ payloadPrefix+CloudControllerConstants.HYPERVISOR_COL+"," +
+ payloadPrefix+CloudControllerConstants.IAAS_COL+"," +
+ payloadPrefix+CloudControllerConstants.IMAGE_ID_COL+"," +
+ payloadPrefix+CloudControllerConstants.LOGIN_PORT_COL+"," +
+ payloadPrefix+CloudControllerConstants.PRIV_IP_COL+"," +
+ payloadPrefix+CloudControllerConstants.PUB_IP_COL+"," +
+ payloadPrefix+CloudControllerConstants.STATUS_COL+"," +
+ payloadPrefix+CloudControllerConstants.SUB_DOMAIN_COL +
+ "\");";
+
+ execute(query);
+ }
+
+ public List<String> getRunningNodeIds() {
+ List<String> nodeIds = new ArrayList<String>();
+ String query =
+// "select " + payloadPrefix + AutoscalerConstant.NODE_ID_COL + " from " +
+// hiveTable + " where payload_status='RUNNING' OR payload_status='PENDING' ;";
+
+// "select id1 from (select distinct payload_nodeId from cloud1 where payload_status='RUNNING' OR payload_status='PENDING') table1
+//LEFT OUTER JOIN
+//(select distinct payload_nodeId as nodeId from cloud1 where payload_status='TERMINATED') table2
+//ON(table2.nodeId = table1.payload_nodeId)
+//where table2.nodeId is null;";
+ "select table1.id1 from (select distinct "+payloadPrefix+CloudControllerConstants.NODE_ID_COL+
+ " as id1 from "+ hiveTable +" where "+payloadPrefix+CloudControllerConstants.STATUS_COL+
+ "='RUNNING' OR "+payloadPrefix+CloudControllerConstants.STATUS_COL+"='PENDING') table1 " +
+ "LEFT OUTER JOIN " +"(select distinct "+payloadPrefix+CloudControllerConstants.NODE_ID_COL+
+ " as id2 from "+hiveTable+" where "+payloadPrefix+CloudControllerConstants.STATUS_COL+"='TERMINATED') table2 " +
+ "ON(table1.id1 = table2.id2) where table2.id2 is null;";
+
+ QueryResult[] result = execute(query);
+
+ for (QueryResult queryResult : result) {
+ if(queryResult == null || queryResult.getResultRows() == null){
+ continue;
+ }
+ for (QueryResultRow row : queryResult.getResultRows()) {
+ if (row != null && row.getColumnValues() != null && row.getColumnValues().length != 0) {
+ nodeIds.add(row.getColumnValues()[0]);
+ }
+ }
+ }
+
+ return nodeIds;
+
+ }
+
+ private void handleException(String msg, Exception e){
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
new file mode 100644
index 0000000..3dee581
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
@@ -0,0 +1,275 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.iaases;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jclouds.aws.ec2.AWSEC2AsyncClient;
+import org.jclouds.aws.ec2.AWSEC2Client;
+import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
+import org.jclouds.aws.ec2.domain.RegionNameAndPublicKeyMaterial;
+import org.jclouds.aws.ec2.functions.ImportOrReturnExistingKeypair;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.ec2.domain.KeyPair;
+import org.jclouds.ec2.domain.PublicIpInstanceIdPair;
+import org.jclouds.rest.RestContext;
+import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.jcloud.ComputeServiceBuilderUtil;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+public class AWSEC2Iaas extends Iaas{
+
+ private static final Log log = LogFactory.getLog(AWSEC2Iaas.class);
+ private static final String SUCCESSFUL_LOG_LINE = "A key-pair is created successfully in ";
+ private static final String FAILED_LOG_LINE = "Key-pair is unable to create in ";
+
+ @Override
+ public void buildComputeServiceAndTemplate(IaasProvider iaasInfo) {
+
+ // builds and sets Compute Service
+ ComputeServiceBuilderUtil.buildDefaultComputeService(iaasInfo);
+
+ // builds and sets Template
+ buildTemplate(iaasInfo);
+
+ }
+
+ private void buildTemplate(IaasProvider iaas) {
+ if (iaas.getComputeService() == null) {
+ String msg = "Compute service is null for IaaS provider: " + iaas.getName();
+ log.fatal(msg);
+ throw new CloudControllerException(msg);
+ }
+
+ TemplateBuilder templateBuilder = iaas.getComputeService().templateBuilder();
+
+ // set image id specified
+ templateBuilder.imageId(iaas.getImage());
+
+ if (iaas.getProperty("instanceType") != null) {
+ // set instance type eg: m1.large
+ templateBuilder.hardwareId(iaas.getProperty("instanceType"));
+ }
+
+ // build the Template
+ Template template = templateBuilder.build();
+
+ // if you wish to auto assign IPs, instance spawning call should be blocking, but if you
+ // wish to assign IPs manually, it can be non-blocking.
+ // is auto-assign-ip mode or manual-assign-ip mode?
+ boolean blockUntilRunning = Boolean.parseBoolean(iaas.getProperty("autoAssignIp"));
+ template.getOptions().as(TemplateOptions.class).blockUntilRunning(blockUntilRunning);
+
+ // this is required in order to avoid creation of additional security groups by jclouds.
+ template.getOptions().as(TemplateOptions.class).inboundPorts(new int[]{});
+
+ // set EC2 specific options
+ if (iaas.getProperty("subnetId") != null) {
+ template.getOptions().as(AWSEC2TemplateOptions.class).subnetId(iaas.getProperty("subnetId"));
+ }
+
+ if (iaas.getProperty("availabilityZone") != null) {
+ template.getOptions().as(AWSEC2TemplateOptions.class)
+ .placementGroup(iaas.getProperty("availabilityZone"));
+ }
+
+ if (iaas.getProperty("securityGroups") != null) {
+ template.getOptions()
+ .as(AWSEC2TemplateOptions.class)
+ .securityGroups(iaas.getProperty("securityGroups")
+ .split(CloudControllerConstants.ENTRY_SEPARATOR));
+
+ }
+
+ if (iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER) != null) {
+ template.getOptions()
+ .as(AWSEC2TemplateOptions.class)
+ .userData(ComputeServiceBuilderUtil.getUserData(CarbonUtils.getCarbonHome() +
+ File.separator +
+ iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER)));
+ }
+
+ if (iaas.getProperty("keyPair") != null) {
+ template.getOptions().as(AWSEC2TemplateOptions.class)
+ .keyPair(iaas.getProperty("keyPair"));
+ }
+
+ // set Template
+ iaas.setTemplate(template);
+ }
+
+ @Override
+ public void setDynamicPayload(IaasProvider iaasInfo) {
+
+ if (iaasInfo.getTemplate() != null && iaasInfo.getPayload() != null) {
+
+ iaasInfo.getTemplate().getOptions().as(AWSEC2TemplateOptions.class)
+ .userData(iaasInfo.getPayload());
+ }
+
+ }
+
+ @Override
+ public synchronized boolean createKeyPairFromPublicKey(IaasProvider iaasInfo, String region, String keyPairName,
+ String publicKey) {
+
+ String ec2Msg = " ec2. Region: "+region+" - Key Pair Name: ";
+
+ ComputeServiceContext context = iaasInfo.getComputeService().getContext();
+ @SuppressWarnings("unchecked")
+ RestContext<AWSEC2Client, AWSEC2AsyncClient> restContext = context.unwrap(RestContext.class);
+ AWSEC2Client ec2Client = restContext.getApi();
+
+ ImportOrReturnExistingKeypair importer = new ImportOrReturnExistingKeypair(ec2Client);
+
+ RegionNameAndPublicKeyMaterial regionNameAndKey = new RegionNameAndPublicKeyMaterial(region, keyPairName, publicKey);
+ KeyPair keyPair = importer.apply(regionNameAndKey);
+
+ if (keyPair != null) {
+
+ iaasInfo.getTemplate().getOptions().as(AWSEC2TemplateOptions.class)
+ .keyPair(keyPair.getKeyName());
+
+ log.info(SUCCESSFUL_LOG_LINE + ec2Msg + keyPair.getKeyName());
+ return true;
+ }
+
+ log.error(FAILED_LOG_LINE+ec2Msg);
+
+ return false;
+ }
+
+ @Override
+ public synchronized String associateAddress(IaasProvider iaasInfo, NodeMetadata node) {
+
+ ComputeServiceContext context = iaasInfo.getComputeService().getContext();
+ @SuppressWarnings("unchecked")
+ RestContext<AWSEC2Client, AWSEC2AsyncClient> restContext =
+ context.unwrap(RestContext.class);
+ AWSEC2Client ec2Client = restContext.getApi();
+ String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
+
+ String ip = null;
+
+ // first try to find an unassigned IP.
+ ArrayList<PublicIpInstanceIdPair> unassignedIps =
+ Lists.newArrayList(Iterables.filter(ec2Client.getElasticIPAddressServices()
+ .describeAddressesInRegion(region,
+ new String[0]),
+ new Predicate<PublicIpInstanceIdPair>() {
+
+ @Override
+ public boolean apply(PublicIpInstanceIdPair arg0) {
+ return arg0.getInstanceId() == null;
+ }
+
+ }));
+
+
+ if (!unassignedIps.isEmpty()) {
+ // try to prevent multiple parallel launches from choosing the same
+ // ip.
+ Collections.shuffle(unassignedIps);
+ ip = Iterables.getLast(unassignedIps).getPublicIp();
+ }
+
+ // if no unassigned IP is available, we'll try to allocate an IP.
+ if (ip == null || ip.isEmpty()) {
+ try {
+ ip = ec2Client.getElasticIPAddressServices().allocateAddressInRegion(region);
+ log.info("Assigned ip [" + ip +"]");
+
+ } catch (Exception e) {
+ String msg = "Failed to allocate an IP address. All IP addresses are in use.";
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+ }
+
+ String id = node.getProviderId();
+
+ // wait till the fixed IP address gets assigned - this is needed before we associate a
+ // public IP
+
+ while (node.getPrivateAddresses() == null) {
+ CloudControllerUtil.sleep(1000);
+ }
+
+ int retries = 0;
+ while (retries < 12 && !associatePublicIp(ec2Client, region, ip, id)) {
+
+ // wait for 5s
+ CloudControllerUtil.sleep(5000);
+ retries++;
+ }
+
+ // FIXME make this debug
+ log.info("Successfully associated an IP address " + ip + " for node with id: " +
+ node.getId());
+
+ return ip;
+
+ }
+
+ /**
+ * @param ec2Client
+ * @param region
+ * @param ip
+ * @param id
+ */
+ private boolean associatePublicIp(AWSEC2Client ec2Client, String region, String ip, String id) {
+ try {
+ ec2Client.getElasticIPAddressServices().associateAddressInRegion(region, ip, id);
+ log.info("Successfully associated public IP ");
+ return true;
+ } catch (Exception e) {
+ log.error("Exception in associating public IP " + e.getMessage());
+ return false;
+ }
+ }
+
+ @Override
+ public synchronized void releaseAddress(IaasProvider iaasInfo, String ip) {
+
+ ComputeServiceContext context = iaasInfo.getComputeService().getContext();
+ @SuppressWarnings("unchecked")
+ RestContext<AWSEC2Client, AWSEC2AsyncClient> restContext =
+ context.unwrap(RestContext.class);
+ AWSEC2Client ec2Client = restContext.getApi();
+ String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
+
+ ec2Client.getElasticIPAddressServices().disassociateAddressInRegion(region, ip);
+ ec2Client.getElasticIPAddressServices().releaseAddressInRegion(region, ip);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
new file mode 100644
index 0000000..1db370a
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
@@ -0,0 +1,269 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.iaases;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.jcloud.ComputeServiceBuilderUtil;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.NodeMetadataBuilder;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.openstack.nova.v2_0.NovaAsyncClient;
+import org.jclouds.openstack.nova.v2_0.NovaClient;
+import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
+import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
+import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
+import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPClient;
+import org.jclouds.openstack.nova.v2_0.extensions.KeyPairClient;
+import org.jclouds.rest.InsufficientResourcesException;
+import org.jclouds.rest.RestContext;
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+public class OpenstackNovaIaas extends Iaas {
+
+ private static final Log log = LogFactory.getLog(OpenstackNovaIaas.class);
+ private static final String SUCCESSFUL_LOG_LINE = "A key-pair is created successfully in ";
+ private static final String FAILED_LOG_LINE = "Key-pair is unable to create in ";
+
+ @Override
+ public void buildComputeServiceAndTemplate(IaasProvider iaasInfo) {
+
+ // builds and sets Compute Service
+ ComputeServiceBuilderUtil.buildDefaultComputeService(iaasInfo);
+
+ // builds and sets Template
+ buildTemplate(iaasInfo);
+
+ }
+
+ private void buildTemplate(IaasProvider iaas) {
+ if (iaas.getComputeService() == null) {
+ throw new CloudControllerException("Compute service is null for IaaS provider: " +
+ iaas.getName());
+ }
+
+ // // if domain to template map is null
+ // if (entity.getDomainToTemplateMap() == null) {
+ // // we initialize it
+ // entity.setDomainToTemplateMap(new HashMap<String, Template>());
+ // }
+
+ TemplateBuilder templateBuilder = iaas.getComputeService().templateBuilder();
+ templateBuilder.imageId(iaas.getImage());
+
+ // to avoid creation of template objects in each and every time, we create all
+ // at once!
+ // for (org.apache.cartridge.autoscaler.service.util.ServiceContext temp :
+ // serviceContexts) {
+
+ String instanceType;
+
+ // set instance type
+ if (((instanceType = iaas.getProperty("instanceType")) != null)) {
+
+ templateBuilder.hardwareId(instanceType);
+ }
+
+ Template template = templateBuilder.build();
+
+ // if you wish to auto assign IPs, instance spawning call should be blocking, but if you
+ // wish to assign IPs manually, it can be non-blocking.
+ // is auto-assign-ip mode or manual-assign-ip mode?
+ boolean blockUntilRunning = Boolean.parseBoolean(iaas.getProperty("autoAssignIp"));
+ template.getOptions().as(TemplateOptions.class).blockUntilRunning(blockUntilRunning);
+
+ // this is required in order to avoid creation of additional security groups by Jclouds.
+ template.getOptions().as(TemplateOptions.class).inboundPorts(new int[]{});
+
+ if (iaas.getProperty("securityGroups") != null) {
+ template.getOptions()
+ .as(NovaTemplateOptions.class)
+ .securityGroupNames(iaas.getProperty("securityGroups")
+ .split(CloudControllerConstants.ENTRY_SEPARATOR));
+ }
+
+ if (iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER) != null) {
+ template.getOptions()
+ .as(NovaTemplateOptions.class)
+ .userData(ComputeServiceBuilderUtil.getUserData(CarbonUtils.getCarbonHome() +
+ File.separator +
+ iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER)));
+ }
+
+ if (iaas.getProperty("keyPair") != null) {
+ template.getOptions().as(NovaTemplateOptions.class)
+ .keyPairName(iaas.getProperty("keyPair"));
+ }
+
+ // set Template
+ iaas.setTemplate(template);
+ }
+
+ @Override
+ public void setDynamicPayload(IaasProvider iaasInfo) {
+
+ if (iaasInfo.getTemplate() != null && iaasInfo.getPayload() != null) {
+
+ iaasInfo.getTemplate().getOptions().as(NovaTemplateOptions.class).userData(iaasInfo.getPayload());
+ }
+
+ }
+
+ @Override
+ public synchronized boolean createKeyPairFromPublicKey(IaasProvider iaasInfo, String region, String keyPairName,
+ String publicKey) {
+
+ String openstackNovaMsg = " Openstack-nova. Region: " + region + " - Name: ";
+
+ ComputeServiceContext context = iaasInfo.getComputeService().getContext();
+ @SuppressWarnings("unchecked")
+ RestContext<NovaClient, NovaAsyncClient> restContext = context.unwrap(RestContext.class);
+
+ KeyPairClient api = restContext.getApi().getKeyPairExtensionForZone(region).get();
+
+ KeyPair keyPair = api.createKeyPairWithPublicKey(keyPairName, publicKey);
+
+ if (keyPair != null) {
+
+ iaasInfo.getTemplate().getOptions().as(NovaTemplateOptions.class)
+ .keyPairName(keyPair.getName());
+
+ log.info(SUCCESSFUL_LOG_LINE + openstackNovaMsg + keyPair.getName());
+ return true;
+ }
+
+ log.error(FAILED_LOG_LINE + openstackNovaMsg);
+ return false;
+
+ }
+
+ @Override
+ public synchronized String associateAddress(IaasProvider iaasInfo, NodeMetadata node) {
+
+ ComputeServiceContext context = iaasInfo.getComputeService().getContext();
+ @SuppressWarnings("unchecked")
+ RestContext<NovaClient, NovaAsyncClient> restContext = context.unwrap(RestContext.class);
+
+ NovaClient novaClient = restContext.getApi();
+ String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
+
+ FloatingIPClient floatingIp = novaClient.getFloatingIPExtensionForZone(region).get();
+
+ String ip=null;
+ // first try to find an unassigned IP.
+ ArrayList<FloatingIP> unassignedIps =
+ Lists.newArrayList(Iterables.filter(floatingIp.listFloatingIPs(),
+ new Predicate<FloatingIP>() {
+
+ @Override
+ public boolean apply(FloatingIP arg0) {
+ //FIXME is this the correct filter?
+ return arg0.getFixedIp() == null;
+ }
+
+ }));
+
+ if (!unassignedIps.isEmpty()) {
+ // try to prevent multiple parallel launches from choosing the same
+ // ip.
+ Collections.shuffle(unassignedIps);
+ ip = Iterables.getLast(unassignedIps).getIp();
+ }
+
+ // if no unassigned IP is available, we'll try to allocate an IP.
+ if (ip == null || ip.isEmpty()) {
+
+ try {
+ ip = floatingIp.allocate().getIp();
+
+ } catch (InsufficientResourcesException e) {
+ String msg = "Failed to allocate an IP address. All IP addresses are in use.";
+ log.error(msg, e);
+ throw new CloudControllerException(msg, e);
+ }
+ }
+
+ // wait till the fixed IP address gets assigned - this is needed before we associate a public IP
+
+ while(node.getPrivateAddresses() == null){
+ CloudControllerUtil.sleep(1000);
+ }
+
+ int retries =0;
+ while(retries < 5 && !associateIp(floatingIp, ip, node.getProviderId()) ){
+
+ // wait for 5s
+ CloudControllerUtil.sleep(5000);
+ retries++;
+ }
+
+ NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip)).build();
+
+ log.info("Successfully associated an IP address "+ip+" for node with id: "+node.getId());
+
+ return ip;
+ }
+
+ @Override
+ public synchronized void releaseAddress(IaasProvider iaasInfo, String ip){
+
+ ComputeServiceContext context = iaasInfo.getComputeService().getContext();
+ @SuppressWarnings("unchecked")
+ RestContext<NovaClient, NovaAsyncClient> restContext = context.unwrap(RestContext.class);
+
+ NovaClient novaClient = restContext.getApi();
+ String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
+
+ FloatingIPClient floatingIpClient = novaClient.getFloatingIPExtensionForZone(region).get();
+
+ for (FloatingIP floatingIP: floatingIpClient.listFloatingIPs()) {
+ if(floatingIP.getIp().equals(ip)){
+ floatingIpClient.deallocate(floatingIP.getId());
+ break;
+ }
+ }
+
+ }
+
+ private boolean associateIp(FloatingIPClient client, String ip, String id){
+ try{
+ client.addFloatingIPToServer(ip, id);
+ return true;
+ }catch(RuntimeException ex){
+ return false;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/35006acc/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
new file mode 100644
index 0000000..9c320a2
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
@@ -0,0 +1,164 @@
+/*
+* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. 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.cloud.controller.iaases;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.jcloud.ComputeServiceBuilderUtil;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
+import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
+import org.apache.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+
+public class VCloudIaas extends Iaas{
+
+ private static final Log log = LogFactory.getLog(VCloudIaas.class);
+
+ @Override
+ public void buildComputeServiceAndTemplate(IaasProvider iaasInfo) {
+
+ // builds and sets Compute Service
+ ComputeServiceBuilderUtil.buildDefaultComputeService(iaasInfo);
+
+ // builds and sets Template
+ buildTemplate(iaasInfo);
+
+ }
+
+ private void buildTemplate(IaasProvider iaas) {
+ if (iaas.getComputeService() == null) {
+ String msg = "Compute service is null for IaaS provider: " + iaas.getName();
+ log.fatal(msg);
+ throw new CloudControllerException(msg);
+ }
+
+ TemplateBuilder templateBuilder = iaas.getComputeService().templateBuilder();
+
+ // set image id specified
+ templateBuilder.imageId(iaas.getImage());
+
+ // build the Template
+ Template template = templateBuilder.build();
+
+ // if you wish to auto assign IPs, instance spawning call should be blocking, but if you
+ // wish to assign IPs manually, it can be non-blocking.
+ // is auto-assign-ip mode or manual-assign-ip mode? - default mode is non-blocking
+ boolean blockUntilRunning = Boolean.parseBoolean(iaas.getProperty("autoAssignIp"));
+ template.getOptions().as(TemplateOptions.class).blockUntilRunning(blockUntilRunning);
+
+ // this is required in order to avoid creation of additional security groups by Jclouds.
+ template.getOptions().as(TemplateOptions.class).inboundPorts(22, 80, 8080, 443, 8243);
+
+ template.getOptions().as(VCloudTemplateOptions.class).ipAddressAllocationMode(IpAddressAllocationMode.POOL);
+
+ // set Template
+ iaas.setTemplate(template);
+ }
+
+ @Override
+ public void setDynamicPayload(IaasProvider iaasInfo) {
+
+ // in VCloud case we need to run a script
+ if (iaasInfo.getTemplate() != null && iaasInfo.getPayload() != null) {
+
+ Template template = iaasInfo.getTemplate();
+ String script = "";
+ String launchParams ="", key="";
+
+ // open the zip file stream
+ ZipInputStream stream = new ZipInputStream(new ByteArrayInputStream(iaasInfo.getPayload()));
+
+ try
+ {
+
+ // now iterate through each item in the stream. The get next
+ // entry call will return a ZipEntry for each file in the
+ // stream
+ ZipEntry entry;
+ while((entry = stream.getNextEntry())!=null)
+ {
+ StringWriter writer = new StringWriter();
+ IOUtils.copy(stream, writer);
+
+ if(entry.getName().contains("launch-params")){
+ launchParams = writer.toString();
+ } else if(entry.getName().contains("id_rsa")){
+ key = writer.toString();
+ }
+
+ }
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
+ }
+ finally
+ {
+ // we must always close the zip file.
+ try {
+ stream.close();
+ } catch (IOException e) {
+
+ log.error("failed to close the ZIP stream", e);
+ }
+ }
+
+ script = "mkdir /var/lib/cloud && mkdir /var/lib/cloud/instance && mkdir /var/lib/cloud/instance/payload && " +
+ "echo \""+launchParams+"\" > /var/lib/cloud/instance/payload/launch-params && " +
+ "echo \""+key+"\" > /var/lib/cloud/instance/payload/id_rsa && " +
+ "cd /opt/ && " +
+ "chmod 755 wso2-openstack-init.sh && "+
+ "./wso2-openstack-init.sh";
+
+ template.getOptions().overrideLoginUser(iaasInfo.getProperty("loginUser")).overrideLoginPassword(iaasInfo.getProperty("loginPassword")).runScript(script);
+ }
+
+ }
+
+ @Override
+ public boolean createKeyPairFromPublicKey(IaasProvider iaasInfo, String region, String keyPairName,
+ String publicKey) {
+
+ //TODO
+ return false;
+ }
+
+ @Override
+ public String associateAddress(IaasProvider iaasInfo, NodeMetadata node) {
+
+ // TODO
+ return "";
+
+ }
+
+ @Override
+ public void releaseAddress(IaasProvider iaasInfo, String ip) {
+ //TODO
+ }
+
+}