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 2014/03/20 18:28:14 UTC

[1/2] git commit: STRATOS-539: Support passing payload to vCloud instance via Customization Script

Repository: incubator-stratos
Updated Branches:
  refs/heads/master 24766f958 -> aced00716


STRATOS-539: Support passing payload to vCloud instance via Customization Script


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/361dbeca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/361dbeca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/361dbeca

Branch: refs/heads/master
Commit: 361dbeca64e369869e62e86a8b3c0bdcf9a25499
Parents: 06bb534
Author: M. Isuru Tharanga Chrishantha Perera <is...@apache.org>
Authored: Thu Mar 20 22:57:22 2014 +0530
Committer: M. Isuru Tharanga Chrishantha Perera <is...@apache.org>
Committed: Thu Mar 20 22:57:22 2014 +0530

----------------------------------------------------------------------
 .../org.apache.stratos.cloud.controller/pom.xml |   1 +
 .../cloud/controller/iaases/VCloudIaas.java     | 140 ++++++++++---------
 .../resources/conf/scripts/sh/customization     |   2 +
 .../src/main/resources/p2.inf                   |   1 +
 .../distribution/src/main/assembly/bin.xml      |   4 +
 5 files changed, 85 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/361dbeca/components/org.apache.stratos.cloud.controller/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/pom.xml b/components/org.apache.stratos.cloud.controller/pom.xml
index c998706..9b89a35 100644
--- a/components/org.apache.stratos.cloud.controller/pom.xml
+++ b/components/org.apache.stratos.cloud.controller/pom.xml
@@ -71,6 +71,7 @@
                         <Import-Package>
                         	  !org.apache.commons.logging,
                             org.apache.commons.logging; version=0.0.0,
+                            org.apache.commons.io.*,
                             org.wso2.carbon.utils.*,
                             <!--org.jclouds.compute*;version="${jclouds.version}";resolution:=optional,
                             org.jclouds*;version="${jclouds.version}",-->   

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/361dbeca/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
index 595857d..b8ea1b9 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
@@ -18,7 +18,10 @@
  */
 package org.apache.stratos.cloud.controller.iaases;
 
-import org.apache.commons.io.IOUtils;
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.exception.CloudControllerException;
@@ -33,18 +36,18 @@ 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 java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+import org.wso2.carbon.utils.CarbonUtils;
 
 public class VCloudIaas extends Iaas {
 
 
 	private static final Log log = LogFactory.getLog(VCloudIaas.class);
 	
+	private static final String SHELL_TYPE = "shellType";
+	private static final String SCRIPTS_PATH = "scripts";
+	private static final String CUSTOMIZATION_SCRIPT = "customization";
+	private static final String PAYLOAD = "PAYLOAD";
+	
 	public VCloudIaas(IaasProvider iaasProvider) {
 		super(iaasProvider);
 	}
@@ -105,67 +108,78 @@ public class VCloudIaas extends Iaas {
 
 	@Override
 	public void setDynamicPayload() {
-
+		// in vCloud case we need to run a script
 		IaasProvider iaasInfo = getIaasProvider();
-		
-		// 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);
-				}
+
+		if (iaasInfo.getTemplate() == null || iaasInfo.getPayload() == null) {
+			if (log.isDebugEnabled()) {
+				log.debug("Payload for vCloud not found");
+			}
+			return;
+		}
+
+		String shellType = iaasInfo.getProperty(SHELL_TYPE);
+
+		if (shellType == null || shellType.isEmpty()) {
+			if (log.isDebugEnabled()) {
+				log.debug("Shell Type for vCloud Customization script not found from properties");
+			}
+			return;
+		}
+
+		if (log.isDebugEnabled()) {
+			log.debug(String.format("Shell Type '%s' will be used for vCloud Customization script", shellType));
+		}
+
+		// Payload is a String value
+		String payload = new String(iaasInfo.getPayload());
+
+		if (log.isDebugEnabled()) {
+			log.debug(String.format("Payload '%s' will be used for vCloud Customization script", shellType));
+		}
+
+		Template template = iaasInfo.getTemplate();
+
+		File scriptPath = new File(CarbonUtils.getCarbonConfigDirPath(), SCRIPTS_PATH);
+
+		File customizationScriptFile = new File(new File(scriptPath, shellType), CUSTOMIZATION_SCRIPT);
+
+		if (!customizationScriptFile.exists()) {
+			if (log.isWarnEnabled()) {
+				log.warn(String.format("The vCloud Customization script '%s' does not exist",
+						customizationScriptFile.getAbsolutePath()));
+			}
+			return;
+		}
+
+		String customizationScript = null;
+
+		try {
+			customizationScript = FileUtils.readFileToString(customizationScriptFile);
+		} catch (IOException e) {
+			if (log.isErrorEnabled()) {
+				log.error(
+						String.format("Error reading the vCloud Customization script '%s'",
+								customizationScriptFile.getAbsolutePath()), e);
+			}
+		}
+
+		if (customizationScript == null || customizationScript.isEmpty()) {
+			if (log.isDebugEnabled()) {
+				log.debug("No content vCloud Customization script not found from properties");
 			}
+			return;
+		}
+
+		// Set payload
+		customizationScript = customizationScript.replaceAll(PAYLOAD, payload);
 
-			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);
+		if (log.isDebugEnabled()) {
+			log.debug(String.format("The vCloud Customization script\n%s", customizationScript));
 		}
 
+		// Run the script
+		template.getOptions().runScript(customizationScript);
 	}
 
 	@Override

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/361dbeca/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/scripts/sh/customization
----------------------------------------------------------------------
diff --git a/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/scripts/sh/customization b/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/scripts/sh/customization
new file mode 100644
index 0000000..b567c80
--- /dev/null
+++ b/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/scripts/sh/customization
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "PAYLOAD" > /tmp/payload

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/361dbeca/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/p2.inf
----------------------------------------------------------------------
diff --git a/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/p2.inf b/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/p2.inf
index d2aa499..9a8d28c 100644
--- a/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/p2.inf
+++ b/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/p2.inf
@@ -23,3 +23,4 @@ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../featur
 org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.apache.stratos.cloud.controller_${feature.version}/conf/etc/services.xsd,target:${installFolder}/../../conf/etc/services.xsd,overwrite:true);\
 org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/cartridges);\
 org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/services);\
+org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.apache.stratos.cloud.controller_${feature.version}/conf/scripts,target:${installFolder}/../../conf/scripts,overwrite:true);\

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/361dbeca/products/cloud-controller/modules/distribution/src/main/assembly/bin.xml
----------------------------------------------------------------------
diff --git a/products/cloud-controller/modules/distribution/src/main/assembly/bin.xml b/products/cloud-controller/modules/distribution/src/main/assembly/bin.xml
index 132876d..3dbd2a0 100644
--- a/products/cloud-controller/modules/distribution/src/main/assembly/bin.xml
+++ b/products/cloud-controller/modules/distribution/src/main/assembly/bin.xml
@@ -162,6 +162,10 @@
                 <include>**/**.png</include>
             </includes>
         </fileSet>
+        <fileSet>
+            <directory>../p2-profile/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/scripts</directory>
+            <outputDirectory>apache-stratos-cc-${pom.version}/repository/conf/scripts</outputDirectory>
+        </fileSet>
 
         <!-- Kernel Patches-->
         <fileSet>


[2/2] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos

Posted by is...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-stratos


Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/aced0071
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/aced0071
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/aced0071

Branch: refs/heads/master
Commit: aced007169acd23069de9a8c3af3bc5ba703478e
Parents: 361dbec 24766f9
Author: M. Isuru Tharanga Chrishantha Perera <is...@apache.org>
Authored: Thu Mar 20 22:57:48 2014 +0530
Committer: M. Isuru Tharanga Chrishantha Perera <is...@apache.org>
Committed: Thu Mar 20 22:57:48 2014 +0530

----------------------------------------------------------------------
 .../modules/p2-profile-gen/carbon.product       |   34 -
 .../modules/p2-profile-gen/pom.xml              | 1040 ++++++------------
 tools/puppet3/manifests/nodes.pp                |   53 +-
 .../lb/templates/conf/axis2/axis2.xml.erb       |    4 +-
 tools/puppet3/modules/mysql/manifests/init.pp   |   26 +
 .../modules/mysql/templates/000-default.erb     |   41 +
 .../puppet3/modules/mysql/templates/my.cnf.erb  |  127 +++
 tools/puppet3/modules/tomcat/manifests/init.pp  |   41 +-
 .../modules/tomcat/templates/server.xml.erb     |  143 +++
 9 files changed, 703 insertions(+), 806 deletions(-)
----------------------------------------------------------------------