From 904847dc37915c7cfecee8893b2c2372cd48c68c Mon Sep 17 00:00:00 2001 From: erbel <johannes.erbel@cs.uni-goettingen.de> Date: Tue, 15 Jan 2019 15:19:01 +0100 Subject: [PATCH] Added adjustable MonitorableProperties --- .../build.gradle | 1 + .../resultprovider.properties | 2 + .../connector/ResultproviderConnector.java | 8 ++- .../mocci/connector/ResultproviderHelper.java | 49 ++++++++++++++ .../connector/ResultproviderSimulation.java | 64 +++++++++++++++++++ 5 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 de.ugoe.cs.rwm.mocci.connector.dummy/resultprovider.properties create mode 100644 de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderHelper.java create mode 100644 de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderSimulation.java diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/build.gradle b/de.ugoe.cs.rwm.mocci.connector.dummy/build.gradle index d234050..65d47fc 100644 --- a/de.ugoe.cs.rwm.mocci.connector.dummy/build.gradle +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/build.gradle @@ -59,6 +59,7 @@ sourceSets { processResources { from("."){ include("plugin.xml") + include("resultprovider.properties") } } diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/resultprovider.properties b/de.ugoe.cs.rwm.mocci.connector.dummy/resultprovider.properties new file mode 100644 index 0000000..5ff259b --- /dev/null +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/resultprovider.properties @@ -0,0 +1,2 @@ +CPU = None,Low,Medium,High,Critical,3000 +Mem = None1,Low1,Medium1,High1,Critical1,4000 \ No newline at end of file diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderConnector.java b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderConnector.java index f88fa75..22a8150 100644 --- a/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderConnector.java +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderConnector.java @@ -58,6 +58,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl { LOGGER.debug("Constructor called on " + this); + } // End of user code // @@ -88,9 +89,10 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl public void occiRetrieve() { LOGGER.debug("occiRetrieve() called on " + this); + if(this.getOcciComponentState().getValue() == Status.ACTIVE.getValue()) { if(simulation == null) { - CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); + ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor())); simulation = new Thread(sim); simulation.start(); } @@ -252,7 +254,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl case Status.INACTIVE_VALUE: this.setOcciComponentState(Status.ACTIVE); if(simulation == null) { - CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); + ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor())); simulation = new Thread(sim); simulation.start(); } @@ -262,7 +264,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl case Status.UNDEPLOYED_VALUE: this.setOcciComponentState(Status.ACTIVE); if(simulation == null) { - CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); + ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor())); simulation = new Thread(sim); simulation.start(); } diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderHelper.java b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderHelper.java new file mode 100644 index 0000000..da357ff --- /dev/null +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderHelper.java @@ -0,0 +1,49 @@ +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(); + } + } + } +} + + +} diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderSimulation.java b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderSimulation.java new file mode 100644 index 0000000..a8f560a --- /dev/null +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ResultproviderSimulation.java @@ -0,0 +1,64 @@ +package de.ugoe.cs.rwm.mocci.connector; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; + +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 static Random random; + private int interval; + private List<String> results; + + public ResultproviderSimulation(Monitorableproperty monProp) { + this.monProp = monProp; + String property = getProperty(monProp.getMonitoringProperty()); + List<String> items = new ArrayList<String>(Arrays.asList(property.split("\\s*,\\s*"))); + this.interval = Integer.parseInt(items.get(items.size()-1)); + String lastItem = items.get(items.size()-1); + items.remove(items.get(items.size()-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); + + } + +} + + -- GitLab