You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sh...@apache.org on 2016/04/23 04:00:24 UTC
[12/35] airavata git commit: Adding the cloud-provisioning project
Adding the cloud-provisioning project
Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/975edba0
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/975edba0
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/975edba0
Branch: refs/heads/master
Commit: 975edba02f87e52fa036cf6f6d21231888e44ced
Parents: 232d346
Author: Mangirish Wagle <va...@gmail.com>
Authored: Tue Apr 12 00:40:12 2016 -0400
Committer: Suresh Marru <sm...@apache.org>
Committed: Fri Apr 15 15:29:57 2016 -0400
----------------------------------------------------------------------
modules/cloud/cloud-provisioning/README | 7 +
modules/cloud/cloud-provisioning/pom.xml | 52 ++++++
.../airavata/cloud/intf/CloudInterface.java | 72 ++++++++
.../cloud/intf/impl/OpenstackIntfImpl.java | 172 +++++++++++++++++++
.../cloud/openstack/OS4JClientProvider.java | 117 +++++++++++++
.../apache/airavata/cloud/util/CloudRef.java | 40 +++++
.../apache/airavata/cloud/util/Constants.java | 34 ++++
.../main/resources/jetstream_openrc.properties | 29 ++++
.../airavata/cloud/test/CloudIntfTest.java | 118 +++++++++++++
.../src/test/resources/test_data.properties | 27 +++
10 files changed, 668 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/README
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/README b/modules/cloud/cloud-provisioning/README
new file mode 100644
index 0000000..1b161a0
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/README
@@ -0,0 +1,7 @@
+This is the initial project created as an interface to various clouds.
+Currently supporting, Openstack on Jetstream using Openstack4j.
+
+To Test Run:-
+1) Replace the credentials in src/main/resources/jetstream_openrc.properties with the Jetstream credentials.
+2) Update the publicKeyFile, jetstream_imageId, jetstream_flavorId and jetstream_networkId to the local path in src/test/resources/test_data.properties. This are the parameters used by the unit tests.
+3) Run JUnit Test org.apache.airavata.cloud.test.CloudIntfTest.
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/pom.xml
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/pom.xml b/modules/cloud/cloud-provisioning/pom.xml
new file mode 100644
index 0000000..0554f0c
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/pom.xml
@@ -0,0 +1,52 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.airavata.cloud</groupId>
+ <artifactId>cloud-provisioning</artifactId>
+ <version>0.0.1</version>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.pacesys</groupId>
+ <artifactId>openstack4j</artifactId>
+ <version>2.0.9</version>
+ <classifier>withdeps</classifier>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.21</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.7.21</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <directory>target</directory>
+ <outputDirectory>target/classes</outputDirectory>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ <testOutputDirectory>target/test-classes</testOutputDirectory>
+ <sourceDirectory>src/main/java</sourceDirectory>
+ <testSourceDirectory>src/test/java</testSourceDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ </testResource>
+ </testResources>
+ <plugins>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
new file mode 100644
index 0000000..f9d9520
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
@@ -0,0 +1,72 @@
+/*
+ *
+ * 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.airavata.cloud.intf;
+
+import org.openstack4j.model.compute.Keypair;
+import org.openstack4j.model.compute.Server;
+
+public interface CloudInterface {
+
+ /**
+ * Method to create Server.
+ * @param serverName
+ * @param imageId
+ * @param flavorId
+ * @param networkId
+ * @param keyPairName
+ * @return Server object.
+ */
+ public Server createServer(String serverName, String imageId, String flavorId, String networkId, String keyPairName);
+
+ /**
+ * Returns the Server object pertaining to the serverId.
+ * @param serverId
+ * @return
+ */
+ public Server getServer(String serverId);
+
+ /**
+ * Method to delete Server.
+ * @param serverId
+ * @return
+ */
+ public void deleteServer(String serverId);
+
+ /**
+ * Creates a public key pair on the cloud
+ * @param publicKey
+ */
+ public Keypair createKeyPair(String keyPairName, String publicKey);
+
+ /**
+ * Returns the keypair object associated to the keyPairName.
+ * @param keyPairName
+ * @return
+ */
+ public Keypair getKeyPair(String keyPairName);
+
+ /**
+ * Deletes a public key pair on the cloud
+ * @param publicKey
+ */
+ public void deleteKeyPair(String keyPairName);
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
new file mode 100644
index 0000000..cb202c4
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
@@ -0,0 +1,172 @@
+/*
+ *
+ * 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.airavata.cloud.intf.impl;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.airavata.cloud.intf.CloudInterface;
+import org.apache.airavata.cloud.openstack.OS4JClientProvider;
+import org.openstack4j.api.Builders;
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.compute.Keypair;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.compute.ServerCreate;
+
+public class OpenstackIntfImpl implements CloudInterface {
+
+ /** The properties. */
+ private String propertiesFile;
+ private Properties properties;
+
+ OSClient os = null;
+
+ /**
+ * Default Constructor
+ * Initializing the properties.
+ */
+ public OpenstackIntfImpl(String propFile) {
+ try {
+
+ this.propertiesFile = propFile;
+ InputStream inputStream = getClass().getClassLoader()
+ .getResourceAsStream(propertiesFile);
+
+ if(inputStream != null) {
+ properties = new Properties();
+ properties.load(inputStream);
+ }
+ else {
+ throw new FileNotFoundException("property file: " + propertiesFile + " not found!");
+ }
+
+ // Initialize the OSClient.
+ os = OS4JClientProvider.getOSClient(properties);
+ }
+ catch(Exception ex) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ }
+ }
+
+ @Override
+ public Server createServer(String serverName, String imageId, String flavorId, String networkId, String keyPairName) {
+ try {
+
+
+ List<String> srvNet = new LinkedList<String>();
+ srvNet.add(networkId);
+
+ ServerCreate sc = Builders.server()
+ .name(serverName)
+ .flavor(flavorId)
+ .image(imageId)
+ .networks(srvNet)
+ .keypairName(keyPairName)
+ .addPersonality("/etc/motd", "Welcome to the new VM! Restricted access only")
+ .build();
+
+ //Boot the Server
+ Server newServer = os.compute().servers().boot(sc);
+
+ return newServer;
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ return null;
+ }
+ }
+
+ @Override
+ public Server getServer(String serverId) {
+ try {
+
+ Server server = os.compute().servers().get(serverId);
+
+ return server;
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ return null;
+ }
+ }
+
+ @Override
+ public void deleteServer(String serverId) {
+ try {
+
+ os.compute().servers().delete(serverId);
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ }
+ }
+
+ @Override
+ public Keypair createKeyPair(String keyPairName, String publicKey) {
+ try {
+
+ Keypair keyp = os.compute().keypairs().create(keyPairName, publicKey);
+
+ return keyp;
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ return null;
+ }
+ }
+
+ @Override
+ public Keypair getKeyPair(String keyPairName) {
+ try {
+
+ Keypair keyp = os.compute().keypairs().get(keyPairName);
+
+ return keyp;
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ return null;
+ }
+ }
+
+ @Override
+ public void deleteKeyPair(String keyPairName) {
+ try {
+
+ os.compute().keypairs().delete(keyPairName);
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/openstack/OS4JClientProvider.java
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/openstack/OS4JClientProvider.java b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/openstack/OS4JClientProvider.java
new file mode 100644
index 0000000..394d1bf
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/openstack/OS4JClientProvider.java
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.airavata.cloud.openstack;
+
+import java.util.Properties;
+
+import org.apache.airavata.cloud.util.Constants;
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.common.Identifier;
+import org.openstack4j.openstack.OSFactory;
+
+public class OS4JClientProvider {
+
+ private static OSClient os = null;
+ private static Integer apiVersion = null;
+
+
+ public static OSClient getOSClient(Properties properties) {
+
+ try {
+ String endPoint = properties.getProperty(Constants.OS_AUTH_URL);
+ String userName = properties.getProperty(Constants.OS_USERNAME);
+ String password = properties.getProperty(Constants.OS_PASSWORD);
+ String domain = properties.getProperty(Constants.OS_USER_DOMAIN_NAME);
+ String apiVersion = properties.getProperty(Constants.OS_IDENTITY_API_VERSION);
+
+ // Initialize client for api version 3.
+ if( apiVersion.equals("3") ) {
+ String project = properties.getProperty(Constants.OS_PROJECT_DOMAIN_NAME);
+ getOSClientV3(endPoint, userName, password, domain, project);
+ }
+ // Initialize client for api version 2.
+ else if( apiVersion.equals("2") ) {
+ getOSClientV2(endPoint, userName, password, domain);
+ }
+ else {
+ throw new Exception("Non- supported Openstack API version " + properties.getProperty("OS_IDENTITY_API_VERSION"));
+ }
+ }
+ catch(Exception ex) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ }
+ return os;
+ }
+
+ /**
+ * Function that authenticates to openstack using v3 APIs.
+ * @param endPoint
+ * @param userName
+ * @param password
+ * @param domain
+ * @param project
+ * @return OSClient object that can be used for other OpenStack operations.
+ */
+ public static void getOSClientV3(String endPoint, String userName, String password,
+ String domain, String project) {
+
+ if(os == null || apiVersion == null ||apiVersion != 3 || ! os.getEndpoint().equals(endPoint)) {
+
+ Identifier domainIdentifier = Identifier.byName(domain);
+ Identifier projectIdentifier = Identifier.byName(project);
+ os = OSFactory.builderV3()
+ .scopeToProject(projectIdentifier, domainIdentifier)
+ .endpoint(endPoint)
+ .credentials(userName, password, domainIdentifier)
+ .authenticate();
+
+ apiVersion = 3;
+ }
+ }
+
+ /**
+ * Function that authenticates to openstack using v2 APIs.
+ * @param endPoint
+ * @param userName
+ * @param password
+ * @param domain
+ * @param project
+ * @return OSClient object that can be used for other Openstack operations.
+ */
+ public static void getOSClientV2(String endPoint, String userName, String password,
+ String domain) {
+
+ if(os == null || apiVersion == null ||apiVersion != 2 || ! os.getEndpoint().equals(endPoint)) {
+
+ Identifier domainIdentifier = Identifier.byName(domain);
+ //Identifier projectIdentifier = Identifier.byName(project);
+ os = OSFactory.builderV3()
+ //.scopeToProject(projectIdentifier, domainIdentifier)
+ .endpoint(endPoint)
+ .credentials(userName, password, domainIdentifier)
+ .authenticate();
+
+ apiVersion = 2;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/CloudRef.java
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/CloudRef.java b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/CloudRef.java
new file mode 100644
index 0000000..e2a7c36
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/CloudRef.java
@@ -0,0 +1,40 @@
+/*
+ *
+ * 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.airavata.cloud.util;
+
+public enum CloudRef {
+
+ JETSTREAM("jetstream"),
+ AMAZON("amazon"),
+ COMET("comet");
+
+ String cloudType;
+
+ private CloudRef(String type) {
+ this.cloudType = type;
+ }
+
+ @Override
+ public String toString() {
+ return this.cloudType;
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
new file mode 100644
index 0000000..275a0e7
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with tproperties.getProperty("OS_PROJECT_DOMAIN_NAME")his 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.airavata.cloud.util;
+
+public class Constants {
+
+ // OpenStack openrc string constants.
+ public static final String OS_AUTH_URL = "OS_AUTH_URL";
+ public static final String OS_IDENTITY_API_VERSION = "OS_IDENTITY_API_VERSION";
+ public static final String OS_USERNAME = "OS_USERNAME";
+ public static final String OS_PASSWORD = "OS_PASSWORD";
+ public static final String OS_USER_DOMAIN_NAME = "OS_USER_DOMAIN_NAME";
+ public static final String OS_PROJECT_DOMAIN_NAME = "OS_PROJECT_DOMAIN_NAME";
+
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties b/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
new file mode 100644
index 0000000..9487bc1
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
@@ -0,0 +1,29 @@
+#
+#
+# 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.
+#
+
+# Authentication properties
+OS_PROJECT_DOMAIN_NAME=scigap
+OS_USER_DOMAIN_NAME=tacc
+OS_PROJECT_NAME=scigap
+OS_TENANT_NAME=scigap
+OS_USERNAME=scigap
+OS_PASSWORD=xxxxxxxx
+OS_AUTH_URL=https://jblb.jetstream-cloud.org:35357/v3
+OS_IDENTITY_API_VERSION=3
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java b/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
new file mode 100644
index 0000000..71a8a53
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
@@ -0,0 +1,118 @@
+/*
+ *
+ * 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.airavata.cloud.test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.Scanner;
+
+import org.apache.airavata.cloud.intf.CloudInterface;
+import org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl;
+import org.junit.Test;
+import org.openstack4j.model.compute.Keypair;
+import org.openstack4j.model.compute.Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CloudIntfTest {
+
+ /** The properties. */
+ private String propertiesFile = "test_data.properties";
+ private Properties properties;
+
+ // Initializing Logger
+ private Logger logger = LoggerFactory.getLogger(CloudIntfTest.class);
+
+ public CloudIntfTest() {
+ try {
+
+ InputStream inputStream = getClass().getClassLoader()
+ .getResourceAsStream(propertiesFile);
+
+ if(inputStream != null) {
+ properties = new Properties();
+ properties.load(inputStream);
+ }
+ else {
+ throw new FileNotFoundException("property file: " + propertiesFile + " not found!");
+ }
+
+ }
+ catch(Exception ex) {
+ ex.printStackTrace();
+ // TODO: Check with the team on how to handle exceptions.
+ }
+ }
+
+ /**
+ * Test that will create keypair, create server with keypair, delete server, delete keypair.
+ */
+ @Test
+ public void jetstreamCreateDeleteServerTest() {
+ try {
+ CloudInterface cloudIntf = new OpenstackIntfImpl("jetstream_openrc.properties");
+ // Sample data. This can be determined by the inputs from Airavata.
+ String imageId = properties.getProperty("jetstream_imageId");
+ String flavorId = properties.getProperty("jetstream_flavorId");
+ String networkId = properties.getProperty("jetstream_networkId");
+
+ /* Create Keypair */
+ String publicKeyFile = properties.getProperty("publicKeyFile");
+ String keyPairName = "testKey";
+
+ Scanner fileScan = new Scanner(new FileInputStream(publicKeyFile));
+ String publicKey = fileScan.nextLine();
+
+ Keypair kp = cloudIntf.getKeyPair(keyPairName);
+ if(kp == null) {
+ kp = cloudIntf.createKeyPair(keyPairName, publicKey);
+ }
+
+ logger.info("Keypair created/ retrieved: " + kp.getFingerprint());
+
+ /* Create Server */
+ Server newServer = cloudIntf.createServer("AiravataTest", imageId, flavorId, networkId, kp.getName());
+ logger.info("Server Created: " + newServer.getId());
+
+ /* Delete Server */
+ cloudIntf.deleteServer(newServer.getId());
+ logger.info("Server deleted: " + newServer.getId());
+
+ Server deleted = cloudIntf.getServer(newServer.getId());
+
+ /* Delete Keypair */
+ cloudIntf.deleteKeyPair(kp.getName());
+ logger.info("Keypair deleted: " + kp.getName());
+
+ assertTrue(newServer != null && deleted == null);
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ fail();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/airavata/blob/975edba0/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties b/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties
new file mode 100644
index 0000000..2ebf7c7
--- /dev/null
+++ b/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties
@@ -0,0 +1,27 @@
+#
+#
+# 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.
+#
+
+# Common properties
+publicKeyFile=/path/id_rsa.pub
+
+# Jetstream properties
+jetstream_imageId=7048bb41-bbbbb-4caa-9370-xxxxxxxxxxx
+jetstream_flavorId=3
+jetstream_networkId=4367cd20-cccc-4dc2-97e8-kkkkkkkkkkk