Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • lennart.thiesen/de.ugoe.cs.rwm.mocci
  • rwm/de.ugoe.cs.rwm.mocci
2 results
Show changes
Showing
with 1565 additions and 214 deletions
/**
* Copyright (c) 2016-2017 Inria
*
*
* 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:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Dec 05 12:12:23 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
* Generated at Wed Dec 19 10:30:40 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.modmacao.occi.platform.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind:
* - scheme: http://schemas.ugoe.cs.rwm/monitoring#
* - term: processor
* - title: Processor Resource
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: processor - title: Processor
* Resource
*/
public class ProcessorConnector extends monitoring.impl.ProcessorImpl
{
public class DataprocessorConnector extends monitoring.impl.DataprocessorImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(ProcessorConnector.class);
private static Logger LOGGER = LoggerFactory.getLogger(DataprocessorConnector.class);
// Start of user code Processorconnector_constructor
/**
* Constructs a processor connector.
*/
ProcessorConnector()
{
DataprocessorConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
......@@ -45,14 +42,13 @@ public class ProcessorConnector extends monitoring.impl.ProcessorImpl
//
// OCCI CRUD callback operations.
//
// Start of user code ProcessorocciCreate
/**
* Called when this Processor instance is completely created.
*/
@Override
public void occiCreate()
{
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -63,8 +59,7 @@ public class ProcessorConnector extends monitoring.impl.ProcessorImpl
* Called when this Processor instance must be retrieved.
*/
@Override
public void occiRetrieve()
{
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -75,8 +70,7 @@ public class ProcessorConnector extends monitoring.impl.ProcessorImpl
* Called when this Processor instance is completely updated.
*/
@Override
public void occiUpdate()
{
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -87,8 +81,7 @@ public class ProcessorConnector extends monitoring.impl.ProcessorImpl
* Called when this Processor instance will be deleted.
*/
@Override
public void occiDelete()
{
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -98,82 +91,118 @@ public class ProcessorConnector extends monitoring.impl.ProcessorImpl
// Processor actions.
//
// Start of user code Processor_Kind_undeploy_action
// Start of user code Processor_Kind_configure_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: undeploy
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void undeploy()
{
LOGGER.debug("Action undeploy() called on " + this);
public void configure() {
LOGGER.debug("Action configure() called on " + this);
switch (this.getOcciComponentState().getValue()) {
// TODO: Implement how to undeploy this processor.
case Status.DEPLOYED_VALUE:
this.setOcciComponentState(Status.INACTIVE);
break;
default:
break;
}
}
// End of user code
// Start of user code Processor_Kind_deploy_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: deploy
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy()
{
public void deploy() {
LOGGER.debug("Action deploy() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.UNDEPLOYED_VALUE:
this.setOcciComponentState(Status.DEPLOYED);
break;
// TODO: Implement how to deploy this processor.
default:
break;
}
}
// End of user code
// Start of user code Processor_Kind_configure_action
// Start of user code Processor_Kind_undeploy_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: configure
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void configure()
{
LOGGER.debug("Action configure() called on " + this);
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.ACTIVE_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
break;
// TODO: Implement how to configure this processor.
case Status.INACTIVE_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.DEPLOYED_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.ERROR_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
break;
default:
break;
}
}
// End of user code
// Start of user code Processor_Kind_Start_action
// Start of user code Processor_Kind_Stop_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: start
* - title: Start the application.
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void start()
{
LOGGER.debug("Action start() called on " + this);
// TODO: Implement how to start this processor.
public void stop() {
LOGGER.debug("Action stop() called on " + this);
setOcciComponentState(Status.INACTIVE);
}
// End of user code
// Start of user code Processor_Kind_Stop_action
// Start of user code Processor_Kind_Start_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: stop
* - title: Stop the application.
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void stop()
{
LOGGER.debug("Action stop() called on " + this);
public void start() {
LOGGER.debug("Action start() called on " + this);
switch (this.getOcciComponentState().getValue()) {
// TODO: Implement how to stop this processor.
case Status.INACTIVE_VALUE:
this.setOcciComponentState(Status.ACTIVE);
break;
case Status.UNDEPLOYED_VALUE:
this.setOcciComponentState(Status.ACTIVE);
break;
default:
break;
}
}
// End of user code
}
}
/**
* Copyright (c) 2016-2017 Inria
*
* 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:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Thu Jan 03 13:17:39 CET 2019 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: monitoringproperty - title:
* MonitoringProperty Component
*/
public class MonitorablepropertyConnector extends monitoring.impl.MonitorablepropertyImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(MonitorablepropertyConnector.class);
// Start of user code Monitoringpropertyconnector_constructor
/**
* Constructs a monitoringproperty connector.
*/
MonitorablepropertyConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code MonitoringpropertyocciCreate
/**
* Called when this Monitoringproperty instance is completely created.
*/
@Override
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Monitoringproperty_occiRetrieve_method
/**
* Called when this Monitoringproperty instance must be retrieved.
*/
@Override
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Monitoringproperty_occiUpdate_method
/**
* Called when this Monitoringproperty instance is completely updated.
*/
@Override
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code MonitoringpropertyocciDelete_method
/**
* Called when this Monitoringproperty instance will be deleted.
*/
@Override
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
//
// Monitoringproperty actions.
//
}
/**
* Copyright (c) 2016-2017 Inria
*
*
* 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:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Dec 05 12:12:23 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
* Generated at Thu Jan 03 13:17:39 CET 2019 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind:
* - scheme: http://schemas.ugoe.cs.rwm/monitoring#
* - term: monitoringproperty
* - title: MonitoringProperty Mixin
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: martpublisher - title:
* MartPublisher Mixin
*/
public class MonitoringpropertyConnector extends monitoring.impl.MonitoringpropertyImpl
{
public class OcciresultproviderConnector extends monitoring.impl.OcciresultproviderImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(MonitoringpropertyConnector.class);
private static Logger LOGGER = LoggerFactory.getLogger(OcciresultproviderConnector.class);
// Start of user code Monitoringpropertyconnector_constructor
// Start of user code Martpublisherconnector_constructor
/**
* Constructs a monitoringproperty connector.
* Constructs a martpublisher connector.
*/
MonitoringpropertyConnector()
{
OcciresultproviderConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
}
}
/**
* Copyright (c) 2016-2017 Inria
*
*
* 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:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Dec 05 12:12:23 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
* Generated at Wed Dec 19 10:30:40 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import java.util.NoSuchElementException;
import org.eclipse.cmf.occi.core.Link;
import org.modmacao.occi.platform.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import monitoring.Monitorableproperty;
import monitoring.Sensor;
/**
* Connector implementation for the OCCI kind:
* - scheme: http://schemas.ugoe.cs.rwm/monitoring#
* - term: publisher
* - title: Publisher Resource
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: publisher - title: Publisher
* Resource
*/
public class PublisherConnector extends monitoring.impl.PublisherImpl
{
public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(PublisherConnector.class);
private static Logger LOGGER = LoggerFactory.getLogger(ResultproviderConnector.class);
private Thread simulation;
// private Occiresultprovider occiResProv;
// Start of user code Publisherconnector_constructor
/**
* Constructs a publisher connector.
*/
PublisherConnector()
{
ResultproviderConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code PublisherocciCreate
/**
* Called when this Publisher instance is completely created.
*/
@Override
public void occiCreate()
{
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
......@@ -63,9 +68,16 @@ public class PublisherConnector extends monitoring.impl.PublisherImpl
* Called when this Publisher instance must be retrieved.
*/
@Override
public void occiRetrieve()
{
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
if (this.getOcciComponentState().getValue() == Status.ACTIVE.getValue()) {
if (simulation == null) {
ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor()));
simulation = new Thread(sim);
simulation.start();
}
}
// TODO: Implement this callback or remove this method.
}
// End of user code
......@@ -75,8 +87,7 @@ public class PublisherConnector extends monitoring.impl.PublisherImpl
* Called when this Publisher instance is completely updated.
*/
@Override
public void occiUpdate()
{
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -86,10 +97,13 @@ public class PublisherConnector extends monitoring.impl.PublisherImpl
/**
* Called when this Publisher instance will be deleted.
*/
@SuppressWarnings("deprecation")
@Override
public void occiDelete()
{
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
if (simulation != null) {
simulation.stop();
}
// TODO: Implement this callback or remove this method.
}
// End of user code
......@@ -98,82 +112,157 @@ public class PublisherConnector extends monitoring.impl.PublisherImpl
// Publisher actions.
//
// Start of user code Publisher_Kind_undeploy_action
// Start of user code Publisher_Kind_configure_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: undeploy
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void undeploy()
{
LOGGER.debug("Action undeploy() called on " + this);
public void configure() {
LOGGER.debug("Action configure() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.DEPLOYED_VALUE:
this.setOcciComponentState(Status.INACTIVE);
break;
// TODO: Implement how to undeploy this publisher.
default:
break;
}
// TODO: Implement how to configure this publisher.
}
// 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:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy()
{
public void deploy() {
LOGGER.debug("Action deploy() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.UNDEPLOYED_VALUE:
this.setOcciComponentState(Status.DEPLOYED);
break;
default:
break;
}
// TODO: Implement how to deploy this publisher.
}
// End of user code
// Start of user code Publisher_Kind_configure_action
// Start of user code Publisher_Kind_undeploy_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: configure
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@SuppressWarnings("deprecation")
@Override
public void configure()
{
LOGGER.debug("Action configure() called on " + this);
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
switch (this.getOcciComponentState().getValue()) {
// TODO: Implement how to configure this publisher.
case Status.ACTIVE_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
if (simulation != null) {
simulation.stop();
}
break;
case Status.INACTIVE_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.DEPLOYED_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
break;
case Status.ERROR_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
break;
default:
break;
}
}
// End of user code
// Start of user code Publisher_Kind_Start_action
// Start of user code Publisher_Kind_Stop_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: start
* - title: Start the application.
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@SuppressWarnings("deprecation")
@Override
public void start()
{
LOGGER.debug("Action start() called on " + this);
// TODO: Implement how to start this publisher.
public void stop() {
LOGGER.debug("Action stop() called on " + this);
if (simulation != null) {
simulation.stop();
}
setOcciComponentState(Status.INACTIVE);
}
// End of user code
// Start of user code Publisher_Kind_Stop_action
// Start of user code Publisher_Kind_Start_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: stop
* - title: Stop the application.
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void stop()
{
LOGGER.debug("Action stop() called on " + this);
public void start() {
LOGGER.debug("Action start() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.INACTIVE_VALUE:
this.setOcciComponentState(Status.ACTIVE);
if (simulation == null || simulation.isAlive() == false) {
ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor()));
simulation = new Thread(sim);
simulation.start();
}
break;
case Status.UNDEPLOYED_VALUE:
this.setOcciComponentState(Status.ACTIVE);
if (simulation == null) {
ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor()));
simulation = new Thread(sim);
simulation.start();
}
break;
// TODO: Implement how to stop this publisher.
default:
break;
}
}
// End of user code
private Sensor getSensor() {
for (Link link : this.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!");
}
}
}
/**
* 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 java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public final class ResultproviderHelper {
Properties props;
private final static String FILENAME = "resultprovider.properties";
public ResultproviderHelper() {
loadProperties();
}
/**
* Getter method for providing the properties of this ResultProviderHelper.
* Properties will be read from local file resultprovider.properties.
*
* @return The properties
*/
public Properties getProperties() {
if (props == null) {
loadProperties();
}
return props;
}
private void loadProperties() {
props = new Properties();
InputStream input = null;
try {
input = this.getClass().getClassLoader().getResourceAsStream(FILENAME);
props.load(input);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
/**
* 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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cmf.occi.core.AttributeState;
import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import monitoring.Monitorableproperty;
public class ResultproviderSimulation implements Runnable {
private static Logger LOGGER = LoggerFactory.getLogger(ResultproviderSimulation.class);
private Monitorableproperty monProp;
private OCCIFactoryImpl factory = new OCCIFactoryImpl();
private int interval;
private List<String> results;
public ResultproviderSimulation(Monitorableproperty monProp) {
this.monProp = monProp;
String property = getProperty(monProp.getMonitoringProperty());
LOGGER.info("Monitoring property for" + monProp.getMonitoringProperty() + ": " + property);
List<String> items = new ArrayList<String>(Arrays.asList(property.split("\\s*,\\s*")));
this.interval = Integer.parseInt(items.get(items.size() - 1));
items.remove(items.get(items.size() - 1));
String itemsString = String.join(",", items);
Pattern p = Pattern.compile("\'([^\']*)\'");
Matcher m = p.matcher(itemsString);
if (m.find() == true) {
items.clear();
while (m.find()) {
items.add(m.group(1));
}
}
this.results = items;
LOGGER.info("Creating Simulation for: " + monProp.getMonitoringProperty() + "; with values: " + results
+ "; and interval: " + interval);
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
AttributeState monPropAttr = factory.createAttributeState();
monPropAttr.setName("monitoring.result");
int randomElementIndex = ThreadLocalRandom.current().nextInt(results.size());
String value = results.get(randomElementIndex);
monPropAttr.setValue(value);
monProp.setMonitoringResult(value);
LOGGER.info(
"MonProp: " + monProp.getMonitoringProperty() + ", set to: " + value + "(" + monProp.getId() + ")");
monProp.getAttributes().add(monPropAttr);
}
}
private String getProperty(String monitoringProperty) {
return new ResultproviderHelper().getProperties().getProperty(monitoringProperty);
}
}
/**
* Copyright (c) 2016-2017 Inria
*
*
* 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:
* - Philippe Merle <philippe.merle@inria.fr>
* - Faiez Zalila <faiez.zalila@inria.fr>
*
* Generated at Wed Dec 05 12:12:23 CET 2018 from platform:/resource/monitoring/model/monitoring.occie by org.eclipse.cmf.occi.core.gen.connector
*/
package de.ugoe.cs.rwm.mocci.connector;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cmf.occi.core.Link;
import org.modmacao.cm.ConfigurationManagementTool;
import org.modmacao.cm.ansible.AnsibleCMTool;
import org.modmacao.core.connector.ApplicationConnector;
import org.modmacao.occi.platform.Component;
import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Connector implementation for the OCCI kind:
* - scheme: http://schemas.ugoe.cs.rwm/monitoring#
* - term: sensor
* - title: Sensor Component
* Connector implementation for the OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: sensor - title: Sensor
* Component
*/
public class SensorConnector extends monitoring.impl.SensorImpl
{
public class SensorConnector extends monitoring.impl.SensorImpl {
/**
* Initialize the logger.
*/
......@@ -48,8 +41,7 @@ public class SensorConnector extends monitoring.impl.SensorImpl
/**
* Constructs a sensor connector.
*/
SensorConnector()
{
SensorConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
......@@ -57,14 +49,13 @@ public class SensorConnector extends monitoring.impl.SensorImpl
//
// OCCI CRUD callback operations.
//
// Start of user code SensorocciCreate
/**
* Called when this Sensor instance is completely created.
*/
@Override
public void occiCreate()
{
public void occiCreate() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -75,8 +66,7 @@ public class SensorConnector extends monitoring.impl.SensorImpl
* Called when this Sensor instance must be retrieved.
*/
@Override
public void occiRetrieve()
{
public void occiRetrieve() {
LOGGER.debug("occiRetrieve() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -87,8 +77,7 @@ public class SensorConnector extends monitoring.impl.SensorImpl
* Called when this Sensor instance is completely updated.
*/
@Override
public void occiUpdate()
{
public void occiUpdate() {
LOGGER.debug("occiUpdate() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -99,8 +88,7 @@ public class SensorConnector extends monitoring.impl.SensorImpl
* Called when this Sensor instance will be deleted.
*/
@Override
public void occiDelete()
{
public void occiDelete() {
LOGGER.debug("occiDelete() called on " + this);
// TODO: Implement this callback or remove this method.
}
......@@ -112,224 +100,206 @@ public class SensorConnector extends monitoring.impl.SensorImpl
// Start of user code Sensor_Kind_deploy_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: deploy
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy()
{
public void deploy() {
LOGGER.debug("Action deploy() called on " + this);
// Application State Machine.
switch(getOcciAppState().getValue()) {
switch (getOcciAppState().getValue()) {
case Status.UNDEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=undeployed, action=\"deploy\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.deploy();
}
setOcciAppState(Status.DEPLOYED);
}
setOcciAppState(Status.DEPLOYED);
break;
default:
break;
}
}
// End of user code
// Start of user code Sensor_Kind_undeploy_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: undeploy
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void undeploy()
{
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
// Application State Machine.
switch(getOcciAppState().getValue()) {
switch (getOcciAppState().getValue()) {
case Status.ACTIVE_VALUE:
LOGGER.debug("Fire transition(state=active, action=\"undeploy\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.stop();
}
this.stop();
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
setOcciAppState(Status.UNDEPLOYED);
setOcciAppState(Status.UNDEPLOYED);
break;
case Status.INACTIVE_VALUE:
LOGGER.debug("Fire transition(state=inactive, action=\"undeploy\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
setOcciAppState(Status.UNDEPLOYED);
setOcciAppState(Status.UNDEPLOYED);
break;
case Status.DEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=deployed, action=\"undeploy\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
setOcciAppState(Status.UNDEPLOYED);
setOcciAppState(Status.UNDEPLOYED);
break;
case Status.ERROR_VALUE:
LOGGER.debug("Fire transition(state=error, action=\"undeploy\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
setOcciAppState(Status.UNDEPLOYED);
setOcciAppState(Status.UNDEPLOYED);
break;
default:
break;
}
}
}
// End of user code
// Start of user code Sensor_Kind_Stop_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: stop
* - title: Stop the application.
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void stop()
{
public void stop() {
LOGGER.debug("Action stop() called on " + this);
// Application State Machine.
switch(getOcciAppState().getValue()) {
switch (getOcciAppState().getValue()) {
case Status.ACTIVE_VALUE:
LOGGER.debug("Fire transition(state=active, action=\"stop\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.stop();
}
setOcciAppState(Status.INACTIVE);
setOcciAppState(Status.INACTIVE);
break;
default:
break;
}
}
// TODO: Implement how to stop this sensor.
}
// End of user code
// Start of user code Sensor_Kind_configure_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: configure
* - title:
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure()
{
int status = -1;
public void configure() {
LOGGER.debug("Action configure() called on " + this);
// Application State Machine.
switch(getOcciAppState().getValue()) {
switch (getOcciAppState().getValue()) {
case Status.DEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=deployed, action=\"configure\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.configure();
}
setOcciAppState(Status.INACTIVE);
setOcciAppState(Status.INACTIVE);
break;
default:
break;
}
}
}
// End of user code
// Start of user code Sensor_Kind_Start_action
/**
* Implement OCCI action:
* - scheme: http://schemas.modmacao.org/occi/platform/component/action#
* - term: start
* - title: Start the application.
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void start()
{
int status = -1;
public void start() {
LOGGER.debug("Action start() called on " + this);
// Application State Machine.
switch(getOcciAppState().getValue()) {
switch (getOcciAppState().getValue()) {
case Status.INACTIVE_VALUE:
LOGGER.debug("Fire transition(state=inactive, action=\"start\")...");
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.start();
}
setOcciAppState(Status.ACTIVE);
break;
setOcciAppState(Status.ACTIVE);
break;
case Status.UNDEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=undeployed, action=\"start\")...");
// First deploy components
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.deploy();
}
this.deploy();
// then configure them
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.configure();
}
this.configure();
// then start them
for (Component component: this.getConnectedComponents()) {
for (Component component : this.getConnectedComponents()) {
component.start();
}
setOcciAppState(Status.ACTIVE);
setOcciAppState(Status.ACTIVE);
break;
default:
break;
}
}
}
// End of user code
private List<Component> getConnectedComponents() {
LinkedList<Component> connectedComponents = new LinkedList<Component>();
for (Link link: this.getLinks()) {
for (Link link : this.getLinks()) {
if (link instanceof Componentlink) {
connectedComponents.add((Component) link.getTarget());
}
}
return connectedComponents;
}
private boolean assertCompsStatusEquals(List<Component> components, Status status) {
for (Component component: components) {
if (component.getOcciComponentState().getValue() != status.getValue()) {
LOGGER.debug("Missmatching state of component " + component.getTitle() + " detected. "
+ "Expected " + status.getName() + " but was "
+ component.getOcciComponentState().getName() + ".");
return false;
}
}
return true;
}
}
}
}
/*******************************************************************************
* Copyright (c) 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>
*******************************************************************************/
/**
*
*/
/**
* Main package for mocci connector dummy.
*
* @author erbel
*
*/
package de.ugoe.cs.rwm.mocci.connector;
\ No newline at end of file
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();
}
assertFalse(monProp.getMonitoringResult().contains(","));
}
@Test
public void startSimulationWithSensorQuotes() {
Resultprovider rp = createResultprovider(Status.UNDEPLOYED);
Monitorableproperty monProp = getMonProp(getSensor(rp));
monProp.setMonitoringProperty("MecoTaskResultForEach");
assertTrue(monProp.getMonitoringResult() == null);
rp.start();
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(monProp.getMonitoringResult().contains(","));
}
@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());
}
}
......@@ -3,6 +3,5 @@
<classpathentry kind="src" path="src-gen"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="src" path="/de.ugoe.cs.rwm.mocci.model"/>
<classpathentry kind="output" path="bin"/>
</classpath>
connection.project.dir=..
connection.project.dir=../de.ugoe.cs.rwm.mocci.connector.dummy
eclipse.preferences.version=1
......@@ -9,6 +9,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Require-Bundle: org.slf4j.api,
org.eclipse.cmf.occi.core,
de.ugoe.cs.rwm.mocci.model,
org.modmacao.occi.platform
de.ugoe.cs.rwm.mocci.model
Export-Package: de.ugoe.cs.rwm.mocci.connector
# Monitoring Connector
Each element in the monitoring extension has a single file in the connector implementing how to react on different REST requests addressing the corresponding OCCI element.
As the elements of the monitoring extension mainly inherit from elements of the enhanced platform extension provided by [MoDMaCAO](https://github.com/occiware/MoDMaCAO), the implementation of the lifecycle actions is quite similar. To handle the management of each individual component of a sensor, configuration management scripts have to be attached to them. Thus, in comparison to the [dummy connector](https://gitlab.gwdg.de/rwm/de.ugoe.cs.rwm.mocci/tree/master/de.ugoe.cs.rwm.mocci.connector.dummy), this connector allows for an actual deployment and management of sensors in a cloud environment. The skeleton for the connector of the OCCI monitoring extension is generated using [OCCI-Studio](https://github.com/occiware/OCCI-Studio).
## Attaching Configuration Management Scripts
To attach a configuration management script to a component, a user mixin serving as tag has to be created.
Moreover, the component managed over the defined script has to have this mixin attached.
Finally, the script itself is located on the MartServer, typically in a folder called roles, and has the same name
as the mixin tag.
The following figure gives an example of such an attachment.
Here, the blue element is the User Mixin which is attached to the DataGatherer which is managed over lifecycle
actions as described in the configuration management script called glances, located in the roles folder of the MartServer.
![Attachment](./example.jpg "Attachment")
*Note:* Currently, MoDMaCAO only provides a connector for [ansible](https://docs.ansible.com/).
/de/