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 2232 additions and 0 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 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;
/**
* Connector EFactory for the OCCI extension: - name: monitoring - scheme:
* http://schemas.ugoe.cs.rwm/monitoring#
*/
public class ConnectorFactory extends monitoring.impl.MonitoringFactoryImpl {
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: sensor - title: Sensor
* Component
*/
@Override
public monitoring.Sensor createSensor() {
return new SensorConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: datagatherer - title:
* DataGatherer Resource
*/
@Override
public monitoring.Datagatherer createDatagatherer() {
return new DatagathererConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: processor - title: Processor
* Resource
*/
@Override
public monitoring.Dataprocessor createDataprocessor() {
return new DataprocessorConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: publisher - title: Publisher
* Resource
*/
@Override
public monitoring.Resultprovider createResultprovider() {
return new ResultproviderConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: martpublisher - title:
* MartPublisher Mixin
*/
@Override
public monitoring.Occiresultprovider createOcciresultprovider() {
return new OcciresultproviderConnector();
}
/**
* EFactory method for OCCI kind: - scheme:
* http://schemas.ugoe.cs.rwm/monitoring# - term: monitoringproperty - title:
* MonitoringProperty Component
*/
@Override
public monitoring.Monitorableproperty createMonitorableproperty() {
return new MonitorablepropertyConnector();
}
}
/**
* 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 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: datagatherer - title:
* DataGatherer Resource
*/
public class DatagathererConnector extends monitoring.impl.DatagathererImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(DatagathererConnector.class);
// Start of user code Datagathererconnector_constructor
/**
* Constructs a datagatherer connector.
*/
DatagathererConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code DatagathererocciCreate
/**
* Called when this Datagatherer 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 Datagatherer_occiRetrieve_method
/**
* Called when this Datagatherer 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 Datagatherer_occiUpdate_method
/**
* Called when this Datagatherer 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 DatagathererocciDelete_method
/**
* Called when this Datagatherer 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
//
// Datagatherer actions.
//
// Start of user code Datagatherer_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure() {
LOGGER.debug("Action configure() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.DEPLOYED_VALUE:
this.setOcciComponentState(Status.INACTIVE);
break;
default:
break;
}
}
// End of user code
// Start of user code Datagatherer_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
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;
}
}
// End of user code
// Start of user code Datagatherer_Kind_undeploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.ACTIVE_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
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 Datagatherer_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void stop() {
LOGGER.debug("Action stop() called on " + this);
setOcciComponentState(Status.INACTIVE);
}
// End of user code
// Start of user code Datagatherer_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void start() {
LOGGER.debug("Action start() called on " + this);
switch (this.getOcciComponentState().getValue()) {
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 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
*/
public class DataprocessorConnector extends monitoring.impl.DataprocessorImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(DataprocessorConnector.class);
// Start of user code Processorconnector_constructor
/**
* Constructs a processor connector.
*/
DataprocessorConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code ProcessorocciCreate
/**
* Called when this Processor 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 Processor_occiRetrieve_method
/**
* Called when this Processor 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 Processor_occiUpdate_method
/**
* Called when this Processor 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 ProcessorocciDelete_method
/**
* Called when this Processor 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
//
// Processor actions.
//
// Start of user code Processor_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure() {
LOGGER.debug("Action configure() called on " + this);
switch (this.getOcciComponentState().getValue()) {
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:
*/
@Override
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;
}
}
// End of user code
// Start of user code Processor_Kind_undeploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@Override
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.ACTIVE_VALUE:
this.setOcciComponentState(Status.UNDEPLOYED);
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 Processor_Kind_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@Override
public void stop() {
LOGGER.debug("Action stop() called on " + this);
setOcciComponentState(Status.INACTIVE);
}
// End of user code
// Start of user code Processor_Kind_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
public void start() {
LOGGER.debug("Action start() called on " + this);
switch (this.getOcciComponentState().getValue()) {
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 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: martpublisher - title:
* MartPublisher Mixin
*/
public class OcciresultproviderConnector extends monitoring.impl.OcciresultproviderImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(OcciresultproviderConnector.class);
// Start of user code Martpublisherconnector_constructor
/**
* Constructs a martpublisher connector.
*/
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 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
*/
public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(ResultproviderConnector.class);
private Thread simulation;
// private Occiresultprovider occiResProv;
// Start of user code Publisherconnector_constructor
/**
* Constructs a publisher connector.
*/
ResultproviderConnector() {
LOGGER.debug("Constructor called on " + this);
}
// 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() {
LOGGER.debug("occiCreate() called on " + this);
// TODO: Implement this callback or remove this method.
}
// End of user code
// Start of user code Publisher_occiRetrieve_method
/**
* Called when this Publisher instance must be retrieved.
*/
@Override
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
// Start of user code Publisher_occiUpdate_method
/**
* Called when this Publisher 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 PublisherocciDelete_method
/**
* Called when this Publisher instance will be deleted.
*/
@SuppressWarnings("deprecation")
@Override
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
//
// Publisher actions.
//
// Start of user code Publisher_Kind_configure_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: configure
* - title:
*/
@Override
public void configure() {
LOGGER.debug("Action configure() called on " + this);
switch (this.getOcciComponentState().getValue()) {
case Status.DEPLOYED_VALUE:
this.setOcciComponentState(Status.INACTIVE);
break;
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:
*/
@Override
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;
}
}
// End of user code
// Start of user code Publisher_Kind_undeploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: undeploy
* - title:
*/
@SuppressWarnings("deprecation")
@Override
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
switch (this.getOcciComponentState().getValue()) {
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_Stop_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: stop -
* title: Stop the application.
*/
@SuppressWarnings("deprecation")
@Override
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_Start_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: start -
* title: Start the application.
*/
@Override
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;
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.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
*/
public class SensorConnector extends monitoring.impl.SensorImpl {
/**
* Initialize the logger.
*/
private static Logger LOGGER = LoggerFactory.getLogger(SensorConnector.class);
// Start of user code Sensorconnector_constructor
/**
* Constructs a sensor connector.
*/
SensorConnector() {
LOGGER.debug("Constructor called on " + this);
// TODO: Implement this constructor.
}
// End of user code
//
// OCCI CRUD callback operations.
//
// Start of user code SensorocciCreate
/**
* Called when this Sensor 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 Sensor_occiRetrieve_method
/**
* Called when this Sensor 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 Sensor_occiUpdate_method
/**
* Called when this Sensor 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 SensorocciDelete_method
/**
* Called when this Sensor 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
//
// Sensor actions.
//
// Start of user code Sensor_Kind_deploy_action
/**
* Implement OCCI action: - scheme:
* http://schemas.modmacao.org/occi/platform/component/action# - term: deploy -
* title:
*/
@Override
public void deploy() {
LOGGER.debug("Action deploy() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.UNDEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=undeployed, action=\"deploy\")...");
for (Component component : this.getConnectedComponents()) {
component.deploy();
}
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:
*/
@Override
public void undeploy() {
LOGGER.debug("Action undeploy() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.ACTIVE_VALUE:
LOGGER.debug("Fire transition(state=active, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.stop();
}
this.stop();
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
setOcciAppState(Status.UNDEPLOYED);
break;
case Status.INACTIVE_VALUE:
LOGGER.debug("Fire transition(state=inactive, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
setOcciAppState(Status.UNDEPLOYED);
break;
case Status.DEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=deployed, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
setOcciAppState(Status.UNDEPLOYED);
break;
case Status.ERROR_VALUE:
LOGGER.debug("Fire transition(state=error, action=\"undeploy\")...");
for (Component component : this.getConnectedComponents()) {
component.undeploy();
}
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.
*/
@Override
public void stop() {
LOGGER.debug("Action stop() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.ACTIVE_VALUE:
LOGGER.debug("Fire transition(state=active, action=\"stop\")...");
for (Component component : this.getConnectedComponents()) {
component.stop();
}
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:
*/
@Override
public void configure() {
LOGGER.debug("Action configure() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.DEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=deployed, action=\"configure\")...");
for (Component component : this.getConnectedComponents()) {
component.configure();
}
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.
*/
@Override
public void start() {
LOGGER.debug("Action start() called on " + this);
// Application State Machine.
switch (getOcciAppState().getValue()) {
case Status.INACTIVE_VALUE:
LOGGER.debug("Fire transition(state=inactive, action=\"start\")...");
for (Component component : this.getConnectedComponents()) {
component.start();
}
setOcciAppState(Status.ACTIVE);
break;
case Status.UNDEPLOYED_VALUE:
LOGGER.debug("Fire transition(state=undeployed, action=\"start\")...");
// First deploy components
for (Component component : this.getConnectedComponents()) {
component.deploy();
}
this.deploy();
// then configure them
for (Component component : this.getConnectedComponents()) {
component.configure();
}
this.configure();
// then start them
for (Component component : this.getConnectedComponents()) {
component.start();
}
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()) {
if (link instanceof Componentlink) {
connectedComponents.add((Component) link.getTarget());
}
}
return connectedComponents;
}
}
/*******************************************************************************
* 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());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<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="output" path="bin"/>
</classpath>
/build/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>de.ugoe.cs.rwm.mocci.connector</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>