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

Added adjustable MonitorableProperties

parent ce6f9c92
No related branches found
No related tags found
No related merge requests found
...@@ -59,6 +59,7 @@ sourceSets { ...@@ -59,6 +59,7 @@ sourceSets {
processResources { processResources {
from("."){ from("."){
include("plugin.xml") include("plugin.xml")
include("resultprovider.properties")
} }
} }
......
CPU = None,Low,Medium,High,Critical,3000
Mem = None1,Low1,Medium1,High1,Critical1,4000
\ No newline at end of file
...@@ -58,6 +58,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl ...@@ -58,6 +58,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl
{ {
LOGGER.debug("Constructor called on " + this); LOGGER.debug("Constructor called on " + this);
} }
// End of user code // End of user code
// //
...@@ -88,9 +89,10 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl ...@@ -88,9 +89,10 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl
public void occiRetrieve() public void occiRetrieve()
{ {
LOGGER.debug("occiRetrieve() called on " + this); LOGGER.debug("occiRetrieve() called on " + this);
if(this.getOcciComponentState().getValue() == Status.ACTIVE.getValue()) { if(this.getOcciComponentState().getValue() == Status.ACTIVE.getValue()) {
if(simulation == null) { if(simulation == null) {
CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor()));
simulation = new Thread(sim); simulation = new Thread(sim);
simulation.start(); simulation.start();
} }
...@@ -252,7 +254,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl ...@@ -252,7 +254,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl
case Status.INACTIVE_VALUE: case Status.INACTIVE_VALUE:
this.setOcciComponentState(Status.ACTIVE); this.setOcciComponentState(Status.ACTIVE);
if(simulation == null) { if(simulation == null) {
CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor()));
simulation = new Thread(sim); simulation = new Thread(sim);
simulation.start(); simulation.start();
} }
...@@ -262,7 +264,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl ...@@ -262,7 +264,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl
case Status.UNDEPLOYED_VALUE: case Status.UNDEPLOYED_VALUE:
this.setOcciComponentState(Status.ACTIVE); this.setOcciComponentState(Status.ACTIVE);
if(simulation == null) { if(simulation == null) {
CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); ResultproviderSimulation sim = new ResultproviderSimulation(getMonProp(getSensor()));
simulation = new Thread(sim); simulation = new Thread(sim);
simulation.start(); simulation.start();
} }
......
package de.ugoe.cs.rwm.mocci.connector;
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();
}
}
}
}
}
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment