From e0e516e4dcc8fea316be7515485aad73c3f8b240 Mon Sep 17 00:00:00 2001
From: erbel <johannes.erbel@cs.uni-goettingen.de>
Date: Thu, 17 Jan 2019 15:23:13 +0100
Subject: [PATCH] Separated Scenario and Initial Deploy

---
 README.md                                     | 39 +++++++++++++++++++
 build.gradle                                  |  2 +-
 doc/horizontal.md                             | 33 ++++++++++++++++
 doc/openstack.md                              | 23 ++++++-----
 doc/vertical.md                               | 33 ++++++++++++++++
 .../ugoe/cs/rwm/mocci/InitialDeployment.java  |  9 +++--
 src/main/java/de/ugoe/cs/rwm/mocci/MAPE.java  |  6 ---
 .../java/de/ugoe/cs/rwm/mocci/MapeTest.java   |  6 +--
 8 files changed, 128 insertions(+), 23 deletions(-)
 create mode 100644 doc/horizontal.md
 create mode 100644 doc/vertical.md

diff --git a/README.md b/README.md
index ef331e5..9b73f06 100644
--- a/README.md
+++ b/README.md
@@ -4,8 +4,47 @@
 Mocci is an extension for the Open Cloud Computing Interface (OCCI) to enable a model-driven management of monitoring instruments in the cloud, as well as storing their results within an OCCI runtime model.
 Together with other tools from the OCCI ecosystem it provides a testing and execution environment for self-adaptive systems.
 
+It consist of the following components:
+1. [Monitoring Extension](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/tree/master/de.ugoe.cs.rwm.mocci.model)
+2. [Monitoring Connector](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/tree/master/de.ugoe.cs.rwm.mocci.connector)
+3. [Monitoring Dummy Connector](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/tree/master/de.ugoe.cs.rwm.mocci.connector.dummy)
+4. [Editor](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/tree/master/de.ugoe.cs.rwm.mocci.model.edit)
+5. [A self-adaptation example](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci)
+
 The following instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
 
+## Getting Started
+To getting started with MOCCI we provide a hands on experience in form of a virtualbox image in which everything required is already configured and ready to go.
+Alternatively, to manually setup the single components instructions can be found at the end of this document.
+
+### VirtualBox
+To get a quick start in the OCCI ecosystem and the MOCCI monitoring extension download the following VM image. This image contains a version of OCCI-Studio with the MoDMaCAO and MOCCI plugins pre-installed.
+Moreover, it contains a checked out version of MOCCI and a local version of the MARTserver.
+```
+Insert Link here!
+```
+
+
+After the download has finished, open Virtualbox and import the virtual appliance:
+1. Click on File->Import Appliance...
+2. Choose the destination of the downloaded image.
+3. Adjust the appliance settings according to your System.
+   1. For a smooth experience 8Gb Ram, and 2 CPUs are recommended.
+4. Press Import.
+
+Next start the virtual machine:
+1. Choose the recently imported VM and press Start.
+2. The username, and password are both: mocci
+
+## Step-by-step example scenarios
+To test MOCCI, we provide step-by-step instructions for two example scenarios.
+
+1. [Vertical Scaling](doc/vertical.md): This scenario scales a VM up and down according to its CPU utilization.
+2. [Horizontal Scaling](doc/horizontal.md): This scenario dynamically adds and releases worker nodes in a hadoop cluster.
+
+*Note:* Please note that the execution of the example scenarios in an distributed environment, e.g., requires access to it as well as connectors implementing how the differen requests should be handled.
+Thus, the provided scenarios are based on monitoring data simulated by the [MOCCI connector dummy](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/tree/master/de.ugoe.cs.rwm.mocci.connector.dummy).
+
 ## OCCI-Studio and MoDMaCAO
 [OCCI-Studio](https://github.com/occiware/OCCI-Studio) is an IDE providing many convenient tools to develop around OCCI. For example, it provides a model editor, graphically and textually. Moreover, it allows to design OCCI extensions and automatically generate code from it.
 In addition to OCCI-Studio the [Model-Driven Configuration Management of Cloud Applications with OCCI (MoDMaCAO)](https://github.com/occiware/MoDMaCAO) extension suite is needed.
diff --git a/build.gradle b/build.gradle
index c7ec961..0b7ee8d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -121,7 +121,7 @@ project(':de.ugoe.cs.rwm.mocci.connector.dummy') {
 
 jar {
     manifest {
-        attributes 'Main-Class': 'de.ugoe.cs.rwm.mocci.MAPE'
+        attributes 'Main-Class': 'de.ugoe.cs.rwm.mocci.SimpleScenario'
     }
 }
 
diff --git a/doc/horizontal.md b/doc/horizontal.md
new file mode 100644
index 0000000..863b8c8
--- /dev/null
+++ b/doc/horizontal.md
@@ -0,0 +1,33 @@
+# Vertical Scaling Scenario
+In this scenario a hadoop cluster with one worker node getting monitored is deployed.
+As soon as the CPU utilization of the worker node reaches a critical level, a request against the OCCI
+API is performed, increasing the number of cores and memory available to the machine.
+
+## Instructions
+In order to provide an easy use of the MART Server, a docker container embedding the server and all required plugins is provided.
+However, to use specialized plugins currently the docker image has to be recreated. Thus, a brief explanation of the single steps are given in the following:
+
+1. Install [docker](https://docs.docker.com/install/)
+2. Clone the [MOCCI repository](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci)
+3. Optional: Add martserver-plugins and roles to be used by the server. Adjust the authorized_keys file for ssh access.
+4. Navigate to src/test/resources/
+5. Create docker image: sudo docker build -t mart-server .
+6. Test the docker image: sudo docker run -p 8080:8080 -p 22:22 mart-server
+7. Store the docker image: sudo docker save mart-server $>$ mart-server.tar
+8. To access the container you can use an ssh connection: ssh -i \$key root@localhost
+
+To build this container a fatjar of the MartServer is used. To use newer versions please refer to the [documentation of the MartServer](https://github.com/occiware/MartServer/blob/master/doc/server.md) in how to create a docker container.
+
+## Loading a Docker Container
+To initialize the proposed OCCI extensions, the following plugins need to be added to the OCCI-Studio. 
+These allow to correctly depict OCCI models in the textual and graphical editor. To Install plugins the following steps have
+to be performed:
+
+1. Download/Navigate to the archive containing the docker image
+2. Load the docker image: docker load $<$ mart-server.tar
+3. Start the image: sudo docker run -p 8080:8080 -p 22:22 mart-server
+4. Start with bash: sudo docker run -p 8080:8080 -p 22:22 -i -t mart-server /bin/bash
+5. To access the container you can use an ssh connection: ssh -i \$key root@localhost
+
+## Configuring the MartServer to be used in OpenStack
+[Documentation on how to setup and configure the MartServer for an OpenStack Cloud](doc/openstack.md)
\ No newline at end of file
diff --git a/doc/openstack.md b/doc/openstack.md
index a750926..fe39bb4 100644
--- a/doc/openstack.md
+++ b/doc/openstack.md
@@ -9,20 +9,21 @@ First you need to setup a Virtual Machine hosting the MartServer:
 3. Install [ansible](https://docs.ansible.com/) on the machine running the MART Server.
 4. Deploy either the Docker container or export the MartServer project
 
-Moreover a management network is required over which the MartServer connects to spawned virtual machines:
+Moreover, a management network is required over which the MartServer connects to spawned virtual machines:
 1. Create a network
 2. Attach the MartServer VM to the network
 
 TODO insert conceptual figure.
 
 ## Extension adjustments
-When performing the proposed approach on a specific cloud, some extension have to be configured, as they need access to the user name and its tenant for example.
-Moreover, each cloud provider has different entry points for their API and may have different kinds of offers regarding their offered computing capabilities.
+When performing the proposed approach in a cloud, some connectors have to be configured to gain access to specific information, e.g.,  user credentials.
+Moreover, each cloud provider has different entry points for their API and may have different kinds of offers regarding their offered vm images and flavors.
 
 ### Configuration Tool Adjustments
-To use configuration management tools adjustments have to be performed.
-Currently, only ansible is supported.
-Hereby, the path to the ansible roles on the MART server has be defined, as well as the location of the playbook, the ansible user and the location of the private key to be used for the configuration.
+To use the configuration management tools of MoDMaCAO some adjustments have to be performed.
+These adjustments configure the path to the ansible roles located on the MART server, as well as the location of the playbook.
+Moreover, the ansible user and the location of the private key to be used have to be configured.
+
 The settings itself can be found at martserver-plugins/org.modmacao.cm.jar in the ansible.properties file.
 An example of this configuraiton is shown in the following Listing:
 ```
@@ -34,8 +35,9 @@ private_key_path = /home/ubuntu/.ssh/key.pem
 
 ### Provider specifics
 In order to translate the REST requests to requests of the cloud API, the MART server requires a connector for the corresponding cloud. 
-In order to use a connector, the connector's jar has to be placed in themartserver-plugins folder before the server is started. 
-Currently, we only provide a prototypical connector for OpenStack. However, also this connector has to be configured.
+Therefore, the connector's jar has to be placed in the martserver-plugins folder before the server is started. 
+Currently, only a prototypical [connector for OpenStack](https://github.com/occiware/MoDMaCAO) is provided as part of the MoDMaCAO framework.
+However, also this connector has to be configured.
 The settings itself can be found at in martserver-plugins/org.modmacao.openstack.connector.jar in the openstack.properties file. An example is shown in the following Listing:
 ```
 openstack_username = jerbel
@@ -46,6 +48,7 @@ openstack_default_network = d52754e0-6729-4034-adbb-8f1f3800f2c6
 openstack_default_image = adf63ddc-debe-4d7e-b899-b936e989439f
 openstack_default_flavor = 36637a26-fded-4635-b6c5-ec8ec0745eab
 ```
+*Note:* This connector currently only supports version 2 of the openstack authentication service.
 
 ### Images and Flavors
 Each vm possesses a flavor and an image. While the image describes the OS of the compute instance, the flavor describes its size.
@@ -62,10 +65,10 @@ An example of such an extension is given in martserver-plugins\org.modmacao.open
 In order to create your own extension, we recommend using OCCI-Studio, as it provides not only a Sirius designer for the Extension, but also allows to completely generate the required code from the modeled Extension.
 Then, the Extension has only be packed and put into the martserver-plugins folder to be ready for use. 
  
-Please Note: When creating a new Extension it has to be registered within the IDE, model, and code.
+*Note:* When creating a new Extension it has to be registered within the IDE, model, and code.
 
 ### User Data Adjustments
-User data describes a specific behaviour which shall be executed when starting a VM for the first time.
+User data describes a specific behavior which shall be executed when starting a VM for the first time.
 n the OCCI model, the user data is described as a Mixin within each compute resource encoded as Base64.
 When encoded the Base64 represents a cloud init script. 
 This has to be configured in such a manner that hot-plugging of networkinterfaces is allowed in each VM.
diff --git a/doc/vertical.md b/doc/vertical.md
new file mode 100644
index 0000000..717ac8e
--- /dev/null
+++ b/doc/vertical.md
@@ -0,0 +1,33 @@
+# Setting up the MartServer
+The MART Server implements the OCCI API used to orchestrate the Cloud deployments.
+This is major component serving as entry point for our application.
+In the following a description of how a Docker container for the MART Server can be created, stored, loaded, and started.
+
+## Creating a Docker Container
+In order to provide an easy use of the MART Server, a docker container embedding the server and all required plugins is provided.
+However, to use specialized plugins currently the docker image has to be recreated. Thus, a brief explanation of the single steps are given in the following:
+
+1. Install [docker](https://docs.docker.com/install/)
+2. Clone the [MOCCI repository](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci)
+3. Optional: Add martserver-plugins and roles to be used by the server. Adjust the authorized_keys file for ssh access.
+4. Navigate to src/test/resources/
+5. Create docker image: sudo docker build -t mart-server .
+6. Test the docker image: sudo docker run -p 8080:8080 -p 22:22 mart-server
+7. Store the docker image: sudo docker save mart-server $>$ mart-server.tar
+8. To access the container you can use an ssh connection: ssh -i \$key root@localhost
+
+To build this container a fatjar of the MartServer is used. To use newer versions please refer to the [documentation of the MartServer](https://github.com/occiware/MartServer/blob/master/doc/server.md) in how to create a docker container.
+
+## Loading a Docker Container
+To initialize the proposed OCCI extensions, the following plugins need to be added to the OCCI-Studio. 
+These allow to correctly depict OCCI models in the textual and graphical editor. To Install plugins the following steps have
+to be performed:
+
+1. Download/Navigate to the archive containing the docker image
+2. Load the docker image: docker load $<$ mart-server.tar
+3. Start the image: sudo docker run -p 8080:8080 -p 22:22 mart-server
+4. Start with bash: sudo docker run -p 8080:8080 -p 22:22 -i -t mart-server /bin/bash
+5. To access the container you can use an ssh connection: ssh -i \$key root@localhost
+
+## Configuring the MartServer to be used in OpenStack
+[Documentation on how to setup and configure the MartServer for an OpenStack Cloud](doc/openstack.md)
\ No newline at end of file
diff --git a/src/main/java/de/ugoe/cs/rwm/mocci/InitialDeployment.java b/src/main/java/de/ugoe/cs/rwm/mocci/InitialDeployment.java
index 3d046b1..46d3f64 100644
--- a/src/main/java/de/ugoe/cs/rwm/mocci/InitialDeployment.java
+++ b/src/main/java/de/ugoe/cs/rwm/mocci/InitialDeployment.java
@@ -13,6 +13,7 @@ import org.eclipse.emf.ecore.resource.Resource;
 import de.ugoe.cs.rwm.docci.MartDeployer;
 import de.ugoe.cs.rwm.docci.ModelUtility;
 import de.ugoe.cs.rwm.docci.connector.Connector;
+import de.ugoe.cs.rwm.docci.connector.LocalhostConnector;
 import de.ugoe.cs.rwm.docci.executor.MartExecutor;
 import de.ugoe.cs.rwm.tocci.Transformator;
 import de.ugoe.cs.rwm.tocci.TransformatorFactory;
@@ -25,11 +26,13 @@ public class InitialDeployment {
 	private static String userData = "I2Nsb3VkLWNvbmZpZwoKIyBVcGdyYWRlIHRoZSBpbnN0YW5jZSBvbiBmaXJzdCBib290CiMgKGllIHJ1biBhcHQtZ2V0IHVwZ3JhZGUpCiMKIyBEZWZhdWx0OiBmYWxzZQojIEFsaWFzZXM6IGFwdF91cGdyYWRlCnBhY2thZ2VfdXBncmFkZTogdHJ1ZQoKcGFja2FnZXM6CiAtIHB5dGhvbgoKd3JpdGVfZmlsZXM6CiAgLSBwYXRoOiAvZXRjL25ldHdvcmsvaW50ZXJmYWNlcy5kLzUwLWNsb3VkLWluaXQuY2ZnCiAgICBjb250ZW50OiB8CiAgICAgIGF1dG8gbG8KICAgICAgaWZhY2UgbG8gaW5ldCBsb29wYmFjawogICAgICAKICAgICAgYXV0byBlbnMwCiAgICAgIGFsbG93LWhvdHBsdWcgZW5zMAogICAgICBpZmFjZSBlbnMwIGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnMxCiAgICAgIGFsbG93LWhvdHBsdWcgZW5zMQogICAgICBpZmFjZSBlbnMxIGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnMyCiAgICAgIGFsbG93LWhvdHBsdWcgZW5zMgogICAgICBpZmFjZSBlbnMyIGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnMzCiAgICAgIGFsbG93LWhvdHBsdWcgZW5zMwogICAgICBpZmFjZSBlbnMzIGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnM0CiAgICAgIGFsbG93LWhvdHBsdWcgZW5zNAogICAgICBpZmFjZSBlbnM0IGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnM1CiAgICAgIGFsbG93LWhvdHBsdWcgZW5zNQogICAgICBpZmFjZSBlbnM1IGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnM2CiAgICAgIGFsbG93LWhvdHBsdWcgZW5zNgogICAgICBpZmFjZSBlbnM2IGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnM3CiAgICAgIGFsbG93LWhvdHBsdWcgZW5zNwogICAgICBpZmFjZSBlbnM3IGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnM4CiAgICAgIGFsbG93LWhvdHBsdWcgZW5zOAogICAgICBpZmFjZSBlbnM4IGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnM5CiAgICAgIGFsbG93LWhvdHBsdWcgZW5zOQogICAgICBpZmFjZSBlbnM5IGluZXQgZGhjcAogICAgICAKICAgICAgYXV0byBlbnMxMAogICAgICBhbGxvdy1ob3RwbHVnIGVuczEwCiAgICAgIGlmYWNlIGVuczEwIGluZXQgZGhjcAoKIyMj";
 	private Connector conn;
 	
-	public InitialDeployment(Connector conn) {
-		this.conn = conn;
+	public static void main (String args[]) {
+		Connector conn = new LocalhostConnector("localhost", 8080, "ubuntu");
+		RegistryAndLoggerSetup.setup();
+		deploy(conn);
 	}
 	
-	public void deploy() {
+	public static void deploy(Connector conn) {
 		System.out.println("Initial Deployment");
 		Path occiPath = getModelPath("de/ugoe/cs/rwm/mocci/occi/hadoopClusterNewExtWithMem.occic");
 		Resource model = ModelUtility.loadOCCIintoEMFResource(occiPath);
diff --git a/src/main/java/de/ugoe/cs/rwm/mocci/MAPE.java b/src/main/java/de/ugoe/cs/rwm/mocci/MAPE.java
index 3446bad..da284f7 100644
--- a/src/main/java/de/ugoe/cs/rwm/mocci/MAPE.java
+++ b/src/main/java/de/ugoe/cs/rwm/mocci/MAPE.java
@@ -28,7 +28,6 @@ public class MAPE {
 	public static void main(String[] args) {
 		System.out.println("Starting MAPE loop");
 		RegistryAndLoggerSetup.setup();
-		initialDeploy(conn);
 		
 		while(true) {
 			try {
@@ -46,11 +45,6 @@ public class MAPE {
 		}
 	}
 
-private static void initialDeploy(Connector conn) {
-		InitialDeployment depl = new InitialDeployment(conn);
-		depl.deploy();
-	}
-
 public static Monitor monitor() {
 		int critCPUs = getNumberOfCriticalCPUs();
 		int noneCPUs = getNumberOfNoneCPUs();
diff --git a/src/test/java/de/ugoe/cs/rwm/mocci/MapeTest.java b/src/test/java/de/ugoe/cs/rwm/mocci/MapeTest.java
index 645f120..7b3e969 100644
--- a/src/test/java/de/ugoe/cs/rwm/mocci/MapeTest.java
+++ b/src/test/java/de/ugoe/cs/rwm/mocci/MapeTest.java
@@ -29,14 +29,14 @@ public class MapeTest {
 	}
 	
 	@Before
-	public void deprovisionEverything() {
+	public void resetEverything() {
 		CachedResourceSet.getCache().clear();
 		Path occiPath = Paths.get(ModelUtility.getPathToResource("occi/Empty.occic"));
 		Connector conn = new LocalhostConnector("localhost", 8080, "ubuntu");
 		MartDeployer deployer = new MartDeployer(conn);
 		deployer.deploy(occiPath);
-		InitialDeployment depl = new InitialDeployment(conn);
-		depl.deploy();
+		
+		InitialDeployment.deploy(conn);
 	}
 	
 	@Test
-- 
GitLab