Skip to content
Snippets Groups Projects
Commit fdf2bfa4 authored by erbel's avatar erbel
Browse files

Dev/ref

parent 8a7a436b
No related branches found
No related tags found
No related merge requests found
Showing
with 851 additions and 171 deletions
...@@ -29,7 +29,8 @@ test: ...@@ -29,7 +29,8 @@ test:
script: script:
- mv src/test/resources/martserver-plugins ~/martserver-plugins/ - mv src/test/resources/martserver-plugins ~/martserver-plugins/
- gradle check - gradle check
- cat build/reports/jacoco/index.html - gradle jacocoRootReport
- cat build/reports/jacoco/jacocoRootReport/html/index.html
artifacts: artifacts:
paths: paths:
- build/reports/ - build/reports/
......
# MOCCI # MOCCI
[![build status](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/badges/master/pipeline.svg)](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/commits/master) [![build status](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/badges/master/pipeline.svg)](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/commits/master)
[![coverage report](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/badges/master/coverage.svg)](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/commits/master)
MOCCI is an extension for the [Open Cloud Computing Interface (OCCI)](http://occi-wg.org/about/specification/) to enable a model-driven management of monitoring devices in the cloud, as well as storing their results within an OCCI-compliant runtime model. Together with other tools from the OCCI ecosystem it provides a testing and execution environment for self-adaptive systems with an EMF-based architecture runtime model ([Snapshot in JSON format](./doc/browser.png)). In the following you will find a getting started guide in which a preconfigured VirtualBox image is downloaded to perform example scenarios and an tutorial on how to enrich existing OCCI models with monitoring functionality. Moreover, an introduction to MOCCI's components is provided, as well as links and description on how to integrate MOCCI with other pre-existing tooling from the OCCI ecosystem. The paper submitted to this artifact and the VirtualBox image can be found [here](https://owncloud.gwdg.de/index.php/s/5u2ddnyyNlzecM5) with the password being mocci. MOCCI is an extension for the [Open Cloud Computing Interface (OCCI)](http://occi-wg.org/about/specification/) to enable a model-driven management of monitoring devices in the cloud, as well as storing their results within an OCCI-compliant runtime model. Together with other tools from the OCCI ecosystem it provides a testing and execution environment for self-adaptive systems with an EMF-based architecture runtime model ([Snapshot in JSON format](./doc/browser.png)). In the following you will find a getting started guide in which a preconfigured VirtualBox image is downloaded to perform example scenarios and an tutorial on how to enrich existing OCCI models with monitoring functionality. Moreover, an introduction to MOCCI's components is provided, as well as links and description on how to integrate MOCCI with other pre-existing tooling from the OCCI ecosystem. The paper submitted to this artifact and the VirtualBox image can be found [here](https://owncloud.gwdg.de/index.php/s/5u2ddnyyNlzecM5) with the password being mocci.
......
apply plugin: 'jacoco'
apply plugin: "com.github.psxpaul.execfork" apply plugin: "com.github.psxpaul.execfork"
apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'com.github.johnrengelman.shadow'
...@@ -45,11 +44,19 @@ allprojects { ...@@ -45,11 +44,19 @@ allprojects {
classpath = configurations.compile classpath = configurations.compile
failOnError = true failOnError = true
} }
test {
testLogging.showStandardStreams = true
testLogging {
exceptionFormat = 'full'
}
}
} }
configure([project(':de.ugoe.cs.rwm.mocci.connector'), project(':de.ugoe.cs.rwm.mocci.connector.dummy'), rootProject]) { configure([project(':de.ugoe.cs.rwm.mocci.connector'), project(':de.ugoe.cs.rwm.mocci.connector.dummy'), rootProject]) {
apply plugin: 'checkstyle' apply plugin: 'checkstyle'
apply plugin: 'findbugs' apply plugin: 'findbugs'
apply plugin: 'jacoco'
checkstyle { checkstyle {
toolVersion = '8.2' toolVersion = '8.2'
...@@ -72,6 +79,22 @@ configure([project(':de.ugoe.cs.rwm.mocci.connector'), project(':de.ugoe.cs.rwm. ...@@ -72,6 +79,22 @@ configure([project(':de.ugoe.cs.rwm.mocci.connector'), project(':de.ugoe.cs.rwm.
html.enabled true html.enabled true
} }
} }
test.finalizedBy jacocoTestReport
jacoco {
toolVersion = "0.8.1"
}
jacocoTestReport {
additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
sourceDirectories = files(sourceSets.main.allSource.srcDirs)
classDirectories = files(sourceSets.main.output)
reports {
xml.enabled false
csv.enabled false
}
}
} }
sourceSets { sourceSets {
...@@ -159,26 +182,9 @@ configurations.all { ...@@ -159,26 +182,9 @@ configurations.all {
test { test {
exclude 'de/ugoe/cs/rwm/mocci/live/**' exclude 'de/ugoe/cs/rwm/mocci/live/**'
//exclude 'de/ugoe/cs/rwm/mocci/**' //exclude 'de/ugoe/cs/rwm/mocci/**'
testLogging.showStandardStreams = true
testLogging {
exceptionFormat = 'full'
}
} }
tasks.test.dependsOn("startMartServer") tasks.test.dependsOn("startMartServer")
test.finalizedBy jacocoTestReport
jacoco {
toolVersion = "0.8.1"
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/reports/jacoco")
}
}
task startMartServer(type: com.github.psxpaul.task.JavaExecFork) { task startMartServer(type: com.github.psxpaul.task.JavaExecFork) {
classpath = files("src/test/resources/org.occiware.mart.jetty.jar") classpath = files("src/test/resources/org.occiware.mart.jetty.jar")
main = 'org.occiware.mart.jetty.MartServer' main = 'org.occiware.mart.jetty.MartServer'
...@@ -188,6 +194,18 @@ task startMartServer(type: com.github.psxpaul.task.JavaExecFork) { ...@@ -188,6 +194,18 @@ task startMartServer(type: com.github.psxpaul.task.JavaExecFork) {
} }
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.test
additionalSourceDirs = files([project(':de.ugoe.cs.rwm.mocci.connector.dummy'), rootProject].sourceSets.main.allSource.srcDirs)
sourceDirectories = files([project(':de.ugoe.cs.rwm.mocci.connector.dummy'), rootProject].sourceSets.main.allSource.srcDirs)
classDirectories = files([project(':de.ugoe.cs.rwm.mocci.connector.dummy'), rootProject].sourceSets.main.output)
executionData = files([project(':de.ugoe.cs.rwm.mocci.connector.dummy'), rootProject].jacocoTestReport.executionData)
reports {
xml.enabled false
csv.enabled false
}
}
uploadArchives { uploadArchives {
repositories { repositories {
mavenDeployer { mavenDeployer {
......
...@@ -19,17 +19,22 @@ dependencies { ...@@ -19,17 +19,22 @@ dependencies {
sourceSets { sourceSets {
main { main {
java { java {
srcDir 'src-gen' srcDir 'src-gen'
} }
//output.classesDir = "$workDir/client/program" //output.classesDir = "$workDir/client/program"
}
} }
test {
java.srcDir 'src-test'
}
}
processResources { processResources {
from("."){ from("."){
include("plugin.xml") include("plugin.xml")
include("resultprovider.properties") include("resultprovider.properties")
} }
} }
......
/**
* Copyright (c) 2018-2019 University of Goettingen
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* - Johannes Erbel <johannes.erbel@cs.uni-goettingen.de>
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.modmacao.occi.platform.Component;
import org.modmacao.occi.platform.Status;
public class ComponentManager {
private Component comp;
public ComponentManager(Component comp) {
this.comp = comp;
}
public void undeploy() {
switch (comp.getOcciComponentState().getValue()) {
case Status.ACTIVE_VALUE:
comp.stop();
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.INACTIVE_VALUE:
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.DEPLOYED_VALUE:
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.ERROR_VALUE:
comp.setOcciComponentState(Status.UNDEPLOYED);
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
public void deploy() {
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.UNDEPLOYED_VALUE:
comp.setOcciComponentState(Status.DEPLOYED);
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
public void configure() {
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.DEPLOYED_VALUE:
comp.setOcciComponentState(Status.INACTIVE);
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
public void start() {
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.INACTIVE_VALUE:
comp.setOcciComponentState(Status.ACTIVE);
break;
case Status.UNDEPLOYED_VALUE:
comp.setOcciComponentState(Status.ERROR);
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
public void stop() {
// Component State Machine.
switch (comp.getOcciComponentState().getValue()) {
case Status.ACTIVE_VALUE:
comp.setOcciComponentState(Status.INACTIVE);
break;
default:
break;
}
}
// End of user code
}
\ No newline at end of file
...@@ -223,7 +223,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl ...@@ -223,7 +223,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl
case Status.INACTIVE_VALUE: case Status.INACTIVE_VALUE:
this.setOcciComponentState(Status.ACTIVE); this.setOcciComponentState(Status.ACTIVE);
if (simulation == null) { if (simulation == null || simulation.isAlive() == false) {
ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor())); ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor()));
simulation = new Thread(sim); simulation = new Thread(sim);
simulation.start(); simulation.start();
......
package de.ugoe.cs.rwm.mocci.connector.dummy;
import static org.junit.Assert.assertTrue;
import java.util.NoSuchElementException;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.infrastructure.Compute;
import org.eclipse.cmf.occi.infrastructure.InfrastructureFactory;
import org.junit.BeforeClass;
import org.junit.Test;
import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.PlatformFactory;
import org.modmacao.occi.platform.Status;
import de.ugoe.cs.rwm.mocci.connector.ConnectorFactory;
import monitoring.Datagatherer;
import monitoring.Monitorableproperty;
import monitoring.Sensor;
public class DatagathererTest {
ConnectorFactory fac = new ConnectorFactory();
PlatformFactory pFac = PlatformFactory.eINSTANCE;
@BeforeClass
public static void OCCIRegistrySetup() {
TestUtility.extensionRegistrySetup();
}
@Test
public void occiCreateDatagatherer() {
Datagatherer dg = fac.createDatagatherer();
dg.occiCreate();
assertTrue(true);
}
@Test
public void getDatagathererInactive() {
Datagatherer dg = createDatagatherer(Status.UNDEPLOYED);
Monitorableproperty monProp = getMonProp(getSensor(dg));
assertTrue(monProp.getMonitoringResult() == null);
dg.occiRetrieve();
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult() == null);
}
@Test
public void DatagathererLifecycleToStart() {
Datagatherer dg = createDatagatherer(Status.UNDEPLOYED);
dg.deploy();
assertTrue(inState(dg, Status.DEPLOYED));
dg.configure();
assertTrue(inState(dg, Status.INACTIVE));
dg.start();
assertTrue(inState(dg, Status.ACTIVE));
}
@Test
public void DatagathererLifecycleToUndeployed() {
Datagatherer dg = createDatagatherer(Status.ACTIVE);
dg.stop();
assertTrue(inState(dg, Status.INACTIVE));
dg.undeploy();
assertTrue(inState(dg, Status.UNDEPLOYED));
Datagatherer rp2 = createDatagatherer(Status.DEPLOYED);
rp2.undeploy();
assertTrue(inState(dg, Status.UNDEPLOYED));
}
@Test
public void DatagathererLifecycleDeployToUndeployed() {
Datagatherer dg = createDatagatherer(Status.DEPLOYED);
dg.undeploy();
assertTrue(inState(dg, Status.UNDEPLOYED));
}
@Test
public void DatagathererLifecycleActiveToUndeploy() {
Datagatherer dg = createDatagatherer(Status.UNDEPLOYED);
dg.start();
dg.undeploy();
assertTrue(inState(dg, Status.UNDEPLOYED));
}
@Test
public void DatagathererLifecycleActiveToStop() {
Datagatherer dg = createDatagatherer(Status.UNDEPLOYED);
dg.start();
dg.stop();
assertTrue(inState(dg, Status.INACTIVE));
dg.start();
assertTrue(inState(dg, Status.ACTIVE));
}
@Test
public void occiDatagathererRequests() {
Datagatherer dg = createDatagatherer(Status.UNDEPLOYED);
dg.occiCreate();
dg.occiRetrieve();
dg.occiUpdate();
dg.occiDelete();
assertTrue(true);
}
private Boolean inState(Datagatherer dg, Status deployed) {
return dg.getOcciComponentState().getValue() == deployed.getValue();
}
private Sensor getSensor(Datagatherer dg) {
for (Link link : dg.getRlinks()) {
if (link.getSource() instanceof Sensor) {
return ((Sensor) link.getSource());
}
}
throw new NoSuchElementException("No containing sensor found!");
}
private Monitorableproperty getMonProp(Sensor sensor) {
for (Link link : sensor.getLinks()) {
if (link instanceof Monitorableproperty) {
return ((Monitorableproperty) link);
}
}
throw new NoSuchElementException("No monitorableproperty found in sensor!");
}
private Datagatherer createDatagatherer(Status state) {
Sensor sens = fac.createSensor();
Datagatherer dg = fac.createDatagatherer();
dg.setOcciComponentState(state);
Componentlink cLink = pFac.createComponentlink();
cLink.setSource(sens);
cLink.setTarget(dg);
Compute vm = InfrastructureFactory.eINSTANCE.createCompute();
Monitorableproperty monProp = fac.createMonitorableproperty();
monProp.setSource(sens);
monProp.setTarget(vm);
monProp.setMonitoringProperty("CPU");
return dg;
}
}
package de.ugoe.cs.rwm.mocci.connector.dummy;
import static org.junit.Assert.assertTrue;
import java.util.NoSuchElementException;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.infrastructure.Compute;
import org.eclipse.cmf.occi.infrastructure.InfrastructureFactory;
import org.junit.BeforeClass;
import org.junit.Test;
import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.PlatformFactory;
import org.modmacao.occi.platform.Status;
import de.ugoe.cs.rwm.mocci.connector.ConnectorFactory;
import monitoring.Dataprocessor;
import monitoring.Monitorableproperty;
import monitoring.Sensor;
public class DataprocessorTest {
ConnectorFactory fac = new ConnectorFactory();
PlatformFactory pFac = PlatformFactory.eINSTANCE;
@BeforeClass
public static void OCCIRegistrySetup() {
TestUtility.extensionRegistrySetup();
}
@Test
public void occiCreateDataprocessor() {
Dataprocessor dp = fac.createDataprocessor();
dp.occiCreate();
assertTrue(true);
}
@Test
public void getDataprocessorInactive() {
Dataprocessor dp = createDataprocessor(Status.UNDEPLOYED);
Monitorableproperty monProp = getMonProp(getSensor(dp));
assertTrue(monProp.getMonitoringResult() == null);
dp.occiRetrieve();
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult() == null);
}
@Test
public void DataprocessorLifecycleToStart() {
Dataprocessor dp = createDataprocessor(Status.UNDEPLOYED);
dp.deploy();
assertTrue(inState(dp, Status.DEPLOYED));
dp.configure();
assertTrue(inState(dp, Status.INACTIVE));
dp.start();
assertTrue(inState(dp, Status.ACTIVE));
}
@Test
public void DataprocessorLifecycleToUndeployed() {
Dataprocessor dp = createDataprocessor(Status.ACTIVE);
dp.stop();
assertTrue(inState(dp, Status.INACTIVE));
dp.undeploy();
assertTrue(inState(dp, Status.UNDEPLOYED));
Dataprocessor rp2 = createDataprocessor(Status.DEPLOYED);
rp2.undeploy();
assertTrue(inState(dp, Status.UNDEPLOYED));
}
@Test
public void DataprocessorLifecycleDeployToUndeployed() {
Dataprocessor dp = createDataprocessor(Status.DEPLOYED);
dp.undeploy();
assertTrue(inState(dp, Status.UNDEPLOYED));
}
@Test
public void DataprocessorLifecycleActiveToUndeploy() {
Dataprocessor dp = createDataprocessor(Status.UNDEPLOYED);
dp.start();
dp.undeploy();
assertTrue(inState(dp, Status.UNDEPLOYED));
}
@Test
public void DataprocessorLifecycleActiveToStop() {
Dataprocessor dp = createDataprocessor(Status.UNDEPLOYED);
dp.start();
dp.stop();
assertTrue(inState(dp, Status.INACTIVE));
dp.start();
assertTrue(inState(dp, Status.ACTIVE));
}
@Test
public void occiDataprocessorRequests() {
Dataprocessor dp = createDataprocessor(Status.UNDEPLOYED);
dp.occiCreate();
dp.occiRetrieve();
dp.occiUpdate();
dp.occiDelete();
assertTrue(true);
}
private Boolean inState(Dataprocessor dp, Status deployed) {
return dp.getOcciComponentState().getValue() == deployed.getValue();
}
private Sensor getSensor(Dataprocessor dp) {
for (Link link : dp.getRlinks()) {
if (link.getSource() instanceof Sensor) {
return ((Sensor) link.getSource());
}
}
throw new NoSuchElementException("No containing sensor found!");
}
private Monitorableproperty getMonProp(Sensor sensor) {
for (Link link : sensor.getLinks()) {
if (link instanceof Monitorableproperty) {
return ((Monitorableproperty) link);
}
}
throw new NoSuchElementException("No monitorableproperty found in sensor!");
}
private Dataprocessor createDataprocessor(Status state) {
Sensor sens = fac.createSensor();
Dataprocessor dp = fac.createDataprocessor();
dp.setOcciComponentState(state);
Componentlink cLink = pFac.createComponentlink();
cLink.setSource(sens);
cLink.setTarget(dp);
Compute vm = InfrastructureFactory.eINSTANCE.createCompute();
Monitorableproperty monProp = fac.createMonitorableproperty();
monProp.setSource(sens);
monProp.setTarget(vm);
monProp.setMonitoringProperty("CPU");
return dp;
}
}
package de.ugoe.cs.rwm.mocci.connector.dummy;
import static org.junit.Assert.assertEquals;
import java.util.Properties;
import org.junit.Test;
import de.ugoe.cs.rwm.mocci.connector.ResultproviderHelper;
public class HelperTest {
@Test
public void testGetProperties() {
ResultproviderHelper helper = new ResultproviderHelper();
Properties props = helper.getProperties();
assertEquals("None,Low,Medium,High,Critical,3000", props.getProperty("CPU"));
}
}
package de.ugoe.cs.rwm.mocci.connector.dummy;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
import org.modmacao.occi.platform.PlatformFactory;
import de.ugoe.cs.rwm.mocci.connector.ConnectorFactory;
import monitoring.Monitorableproperty;
public class MonitorablepropertyTest {
ConnectorFactory fac = new ConnectorFactory();
PlatformFactory pFac = PlatformFactory.eINSTANCE;
@BeforeClass
public static void OCCIRegistrySetup() {
TestUtility.extensionRegistrySetup();
}
@Test
public void occiDataprocessorRequests() {
Monitorableproperty monprop = fac.createMonitorableproperty();
monprop.occiCreate();
monprop.occiRetrieve();
monprop.occiUpdate();
monprop.occiDelete();
assertTrue(true);
}
}
package de.ugoe.cs.rwm.mocci.connector.dummy;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import java.util.NoSuchElementException;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.infrastructure.Compute;
import org.eclipse.cmf.occi.infrastructure.InfrastructureFactory;
import org.junit.BeforeClass;
import org.junit.Test;
import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.PlatformFactory;
import org.modmacao.occi.platform.Status;
import de.ugoe.cs.rwm.mocci.connector.ConnectorFactory;
import de.ugoe.cs.rwm.mocci.connector.ResultproviderConnector;
import monitoring.Monitorableproperty;
import monitoring.Occiresultprovider;
import monitoring.Resultprovider;
import monitoring.Sensor;
public class ResultproviderTest {
ConnectorFactory fac = new ConnectorFactory();
PlatformFactory pFac = PlatformFactory.eINSTANCE;
@BeforeClass
public static void OCCIRegistrySetup() {
TestUtility.extensionRegistrySetup();
}
@Test(expected = NoSuchElementException.class)
public void startSimulationWithoutSensor() {
Resultprovider rp = fac.createResultprovider();
rp.start();
}
@Test
public void startSimulationWithSensor() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
Monitorableproperty monProp = getMonProp(getSensor(rp));
assertTrue(monProp.getMonitoringResult() == null);
rp.start();
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult() != null);
}
@Test
public void occiCreateResultprovider() {
Resultprovider rp = fac.createResultprovider();
rp.occiCreate();
assertTrue(true);
}
@Test
public void getResultproviderActiveState() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
rp.setOcciComponentState(Status.ACTIVE);
Monitorableproperty monProp = getMonProp(getSensor(rp));
assertTrue(monProp.getMonitoringResult() == null);
rp.occiRetrieve();
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult() != null);
}
@Test
public void getResultproviderInactive() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
Monitorableproperty monProp = getMonProp(getSensor(rp));
assertTrue(monProp.getMonitoringResult() == null);
rp.occiRetrieve();
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult() == null);
}
@Test
public void stopResultproviderInactive() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
rp.start();
Thread t = getSimulationThread(rp);
assertTrue(t.isAlive());
rp.occiDelete();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertFalse(t.isAlive());
}
@Test
public void ResultproviderLifecycleToStart() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
rp.deploy();
assertTrue(inState(rp, Status.DEPLOYED));
rp.configure();
assertTrue(inState(rp, Status.INACTIVE));
rp.start();
assertTrue(inState(rp, Status.ACTIVE));
}
@Test
public void ResultproviderLifecycleToUndeployed() {
Resultprovider rp = createResultprovider(Status.ACTIVE);
rp.stop();
assertTrue(inState(rp, Status.INACTIVE));
rp.undeploy();
assertTrue(inState(rp, Status.UNDEPLOYED));
Resultprovider rp2 = createResultprovider(Status.DEPLOYED);
rp2.undeploy();
assertTrue(inState(rp, Status.UNDEPLOYED));
}
@Test
public void ResultproviderLifecycleDeployToUndeployed() {
Resultprovider rp = createResultprovider(Status.DEPLOYED);
rp.undeploy();
assertTrue(inState(rp, Status.UNDEPLOYED));
}
@Test
public void ResultproviderLifecycleActiveToUndeploy() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
rp.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread t = getSimulationThread(rp);
assertTrue(t.isAlive());
rp.undeploy();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertFalse(t.isAlive());
assertTrue(inState(rp, Status.UNDEPLOYED));
}
@Test
public void ResultproviderLifecycleActiveToStop() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
rp.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread t = getSimulationThread(rp);
assertTrue(t.isAlive());
rp.stop();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertFalse(t.isAlive());
assertTrue(inState(rp, Status.INACTIVE));
rp.start();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread newT = getSimulationThread(rp);
assertTrue(newT.isAlive());
assertTrue(inState(rp, Status.ACTIVE));
}
@Test
public void occiRequestsResultprovider() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
rp.occiCreate();
rp.occiRetrieve();
rp.occiUpdate();
rp.occiDelete();
assertTrue(true);
}
@Test
public void occiResultproviderRequests() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
Occiresultprovider orp = fac.createOcciresultprovider();
rp.getParts().add(orp);
assertTrue(true);
}
private Boolean inState(Resultprovider rp, Status deployed) {
return rp.getOcciComponentState().getValue() == deployed.getValue();
}
private Thread getSimulationThread(Resultprovider rp) {
Class<ResultproviderConnector> rpc = ResultproviderConnector.class;
Field f = null;
try {
f = rpc.getDeclaredField("simulation");
f.setAccessible(true);
return (Thread) f.get(rp);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
assertTrue(false);
}
throw new NoSuchElementException("Simulation thread could not be found!");
}
private Sensor getSensor(Resultprovider rp) {
for (Link link : rp.getRlinks()) {
if (link.getSource() instanceof Sensor) {
return ((Sensor) link.getSource());
}
}
throw new NoSuchElementException("No containing sensor found!");
}
private Monitorableproperty getMonProp(Sensor sensor) {
for (Link link : sensor.getLinks()) {
if (link instanceof Monitorableproperty) {
return ((Monitorableproperty) link);
}
}
throw new NoSuchElementException("No monitorableproperty found in sensor!");
}
private Resultprovider createResultprovider(Status state) {
Sensor sens = fac.createSensor();
Resultprovider rp = fac.createResultprovider();
rp.setOcciComponentState(state);
Componentlink cLink = pFac.createComponentlink();
cLink.setSource(sens);
cLink.setTarget(rp);
Compute vm = InfrastructureFactory.eINSTANCE.createCompute();
Monitorableproperty monProp = fac.createMonitorableproperty();
monProp.setSource(sens);
monProp.setTarget(vm);
monProp.setMonitoringProperty("CPU");
return rp;
}
}
package de.ugoe.cs.rwm.mocci.connector.dummy;
import static org.junit.Assert.assertTrue;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.infrastructure.Compute;
import org.eclipse.cmf.occi.infrastructure.InfrastructureFactory;
import org.junit.BeforeClass;
import org.junit.Test;
import org.modmacao.occi.platform.Component;
import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.PlatformFactory;
import org.modmacao.occi.platform.Status;
import de.ugoe.cs.rwm.mocci.connector.ConnectorFactory;
import monitoring.Datagatherer;
import monitoring.Dataprocessor;
import monitoring.Monitorableproperty;
import monitoring.Resultprovider;
import monitoring.Sensor;
public class SensorTest {
ConnectorFactory fac = new ConnectorFactory();
PlatformFactory pFac = PlatformFactory.eINSTANCE;
@BeforeClass
public static void OCCIRegistrySetup() {
TestUtility.extensionRegistrySetup();
}
@Test
public void startSensorLifecycleToStart() {
Sensor sens = createSensor(Status.UNDEPLOYED);
sens.deploy();
assertTrue(inState(sens, Status.DEPLOYED));
sens.configure();
assertTrue(inState(sens, Status.INACTIVE));
sens.start();
assertTrue(inState(sens, Status.ACTIVE));
}
@Test
public void startSensorLifecycleToUndeploy() {
Sensor sens = createSensor(Status.ACTIVE);
sens.stop();
assertTrue(inState(sens, Status.INACTIVE));
sens.undeploy();
assertTrue(inState(sens, Status.UNDEPLOYED));
}
@Test
public void stopSensorActiveToUndeploy() {
Sensor sens = createSensor(Status.ACTIVE);
sens.undeploy();
assertTrue(inState(sens, Status.UNDEPLOYED));
}
@Test
public void stopSensorUndeployToStart() {
Sensor sens = createSensor(Status.UNDEPLOYED);
sens.start();
assertTrue(inState(sens, Status.ACTIVE));
}
@Test
public void startSensorDeployToUndeploy() {
Sensor sens = createSensor(Status.DEPLOYED);
sens.undeploy();
assertTrue(inState(sens, Status.UNDEPLOYED));
}
@Test
public void occiSensorRequests() {
Sensor sens = createSensor(Status.UNDEPLOYED);
sens.occiCreate();
sens.occiRetrieve();
sens.occiUpdate();
sens.occiDelete();
assertTrue(true);
}
private Boolean inState(Sensor sens, Status state) {
System.out.println(sens.getOcciAppState());
if (sens.getOcciAppState().getValue() != state.getValue()) {
return false;
}
for (Link link : sens.getLinks()) {
if (link instanceof Componentlink) {
Component comp = (Component) link.getTarget();
System.out.println(comp.getOcciComponentState());
if ((comp.getOcciComponentState().getValue() == state.getValue()) == false) {
return false;
}
}
}
return true;
}
private Sensor createSensor(Status state) {
Sensor sens = fac.createSensor();
sens.setOcciAppState(state);
Resultprovider rp = fac.createResultprovider();
rp.setOcciComponentState(state);
rp.setOcciComponentState(state);
Componentlink cLink = pFac.createComponentlink();
cLink.setSource(sens);
cLink.setTarget(rp);
Compute vm = InfrastructureFactory.eINSTANCE.createCompute();
Monitorableproperty monProp = fac.createMonitorableproperty();
monProp.setSource(sens);
monProp.setTarget(vm);
monProp.setMonitoringProperty("CPU");
Datagatherer dg = fac.createDatagatherer();
dg.setOcciComponentState(state);
Componentlink cLink2 = pFac.createComponentlink();
cLink2.setSource(sens);
cLink2.setTarget(dg);
Dataprocessor dp = fac.createDataprocessor();
dp.setOcciComponentState(state);
Componentlink cLink3 = pFac.createComponentlink();
cLink3.setSource(sens);
cLink3.setTarget(dp);
return sens;
}
}
package de.ugoe.cs.rwm.mocci.connector.dummy;
import org.eclipse.cmf.occi.core.OCCIPackage;
import org.eclipse.cmf.occi.core.util.OcciRegistry;
import org.eclipse.cmf.occi.infrastructure.InfrastructurePackage;
import org.modmacao.occi.platform.PlatformPackage;
import monitoring.MonitoringPackage;
public class TestUtility {
public static void extensionRegistrySetup() {
InfrastructurePackage.eINSTANCE.eClass();
OCCIPackage.eINSTANCE.eClass();
PlatformPackage.eINSTANCE.eClass();
MonitoringPackage.eINSTANCE.eClass();
OcciRegistry.getInstance().registerExtension("http://schemas.modmacao.org/occi/platform#",
PlatformPackage.class.getClassLoader().getResource("model/platform.occie").toString());
OcciRegistry.getInstance().registerExtension("http://schemas.ogf.org/occi/infrastructure#",
InfrastructurePackage.class.getClassLoader().getResource("model/Infrastructure.occie").toString());
OcciRegistry.getInstance().registerExtension("http://schemas.ogf.org/occi/core#",
OCCIPackage.class.getClassLoader().getResource("model/Core.occie").toString());
OcciRegistry.getInstance().registerExtension("http://schemas.ugoe.cs.rwm/monitoring#",
MonitoringPackage.class.getClassLoader().getResource("model/monitoring.occie").toString());
}
}
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment