diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/META-INF/MANIFEST.MF b/de.ugoe.cs.rwm.mocci.connector.dummy/META-INF/MANIFEST.MF index c9e37426b17fc135698c6bcfbbd26f01c9b528e9..5b7d2586dc2e2d871dfde3a728ae870e4717e761 100644 --- a/de.ugoe.cs.rwm.mocci.connector.dummy/META-INF/MANIFEST.MF +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/META-INF/MANIFEST.MF @@ -9,5 +9,6 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Require-Bundle: org.slf4j.api, org.eclipse.cmf.occi.core, - de.ugoe.cs.rwm.mocci.model + de.ugoe.cs.rwm.mocci.model, + org.modmacao.core Export-Package: de.ugoe.cs.rwm.mocci.connector diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/CPUSimulation.java b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/CPUSimulation.java new file mode 100644 index 0000000000000000000000000000000000000000..b04c677278ece568090b09387496edfbf2494863 --- /dev/null +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/CPUSimulation.java @@ -0,0 +1,45 @@ +package de.ugoe.cs.rwm.mocci.connector; + +import java.util.Random; + +import org.eclipse.cmf.occi.core.AttributeState; +import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl; + +import monitoring.Monitorableproperty; + +public class CPUSimulation implements Runnable{ + + private Monitorableproperty monProp; + private OCCIFactoryImpl factory = new OCCIFactoryImpl(); + private static Random random; + + public CPUSimulation(Monitorableproperty monProp) { + this.monProp = monProp; + } + + @Override + public void run() { + while(true) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println(monProp.getId()); + + AttributeState monPropAttr = factory.createAttributeState(); + monPropAttr.setName("monitoring.result"); + String value = CpuValue.getRandomValue().toString(); + monPropAttr.setValue(value); + System.out.println("MonProp: " + monProp.getTitle() + ", set to: " + value); + monProp.getAttributes().add(monPropAttr); + } + + } + + + +} + + diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ComponentManager.java b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ComponentManager.java new file mode 100644 index 0000000000000000000000000000000000000000..5ead91811f66c141323d785c1584e980ebebbc58 --- /dev/null +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/ComponentManager.java @@ -0,0 +1,161 @@ +package de.ugoe.cs.rwm.mocci.connector; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.cmf.occi.core.Link; +import org.eclipse.cmf.occi.core.MixinBase; +import org.modmacao.cm.ConfigurationManagementTool; +import org.modmacao.cm.ansible.AnsibleCMTool; +import org.modmacao.occi.platform.Component; +import org.modmacao.occi.platform.Status; + + +public class ComponentManager { + + private Component comp; + + public ComponentManager(Component comp) { + this.comp = comp; + } + + + public void undeploy() { + + switch(comp.getOcciComponentState().getValue()) { + + case Status.ACTIVE_VALUE: + + comp.stop(); + comp.setOcciComponentState(Status.UNDEPLOYED); + break; + + + case Status.INACTIVE_VALUE: + comp.setOcciComponentState(Status.UNDEPLOYED); + break; + + + case Status.DEPLOYED_VALUE: + comp.setOcciComponentState(Status.UNDEPLOYED); + break; + + + case Status.ERROR_VALUE: + comp.setOcciComponentState(Status.UNDEPLOYED); + break; + + default: + break; + } + } + // End of user code + // Start of user code Publisher_Kind_deploy_action + /** + * Implement OCCI action: + * - scheme: http://schemas.modmacao.org/occi/platform/component/action# + * - term: deploy + * - title: + */ + public void deploy() + { + int status = -1; + + // Component State Machine. + switch(comp.getOcciComponentState().getValue()) { + + case Status.UNDEPLOYED_VALUE: + comp.setOcciComponentState(Status.DEPLOYED); + break; + + default: + break; +} + } + // End of user code + // Start of user code Publisher_Kind_configure_action + /** + * Implement OCCI action: + * - scheme: http://schemas.modmacao.org/occi/platform/component/action# + * - term: configure + * - title: + */ + public void configure() + { + int status = -1; + + // Component State Machine. + switch(comp.getOcciComponentState().getValue()) { + + case Status.DEPLOYED_VALUE: + comp.setOcciComponentState(Status.INACTIVE); + break; + + default: + break; +} + } + // End of user code + // Start of user code Publisher_Kind_Start_action + /** + * Implement OCCI action: + * - scheme: http://schemas.modmacao.org/occi/platform/component/action# + * - term: start + * - title: Start the application. + */ + public void start() + { + int status = -1; + + // Component State Machine. + switch(comp.getOcciComponentState().getValue()) { + + case Status.INACTIVE_VALUE: + comp.setOcciComponentState(Status.ACTIVE); + break; + + + case Status.UNDEPLOYED_VALUE: + comp.setOcciComponentState(Status.ERROR); + break; + + default: + break; +} + } + // End of user code + // Start of user code Publisher_Kind_Stop_action + /** + * Implement OCCI action: + * - scheme: http://schemas.modmacao.org/occi/platform/component/action# + * - term: stop + * - title: Stop the application. + */ + public void stop() + { + int status = -1; + // Component State Machine. + switch(comp.getOcciComponentState().getValue()) { + + case Status.ACTIVE_VALUE: + + comp.setOcciComponentState(Status.INACTIVE); + + break; + + default: + break; +} + } + // End of user code + + private boolean assertCompsStatusEquals(List<Component> components, Status status) { + for (Component component: components) { + if (component.getOcciComponentState().getValue() != status.getValue()) { + return false; + } + } + return true; +} + +} \ No newline at end of file diff --git a/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/CpuValue.java b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/CpuValue.java new file mode 100644 index 0000000000000000000000000000000000000000..ffa0bab060d606855a4b885d0e8b48f8aaf8c128 --- /dev/null +++ b/de.ugoe.cs.rwm.mocci.connector.dummy/src-gen/de/ugoe/cs/rwm/mocci/connector/CpuValue.java @@ -0,0 +1,15 @@ +package de.ugoe.cs.rwm.mocci.connector; + +import java.util.Random; + + +public enum CpuValue { + Critical, High, Medium, Low, None; + + + + public static CpuValue getRandomValue() { + Random random = new Random(); + return values()[random.nextInt(values().length)]; + } +} \ 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 0edcbf5e8fbe91c5e797dd6f02481fd7ce055bc7..7ebdce190208b619f0ead42c6967ef87623fd14c 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 @@ -23,6 +23,8 @@ import org.eclipse.cmf.occi.core.Link; import org.eclipse.cmf.occi.core.MixinBase; import org.eclipse.cmf.occi.core.Resource; import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl; +import org.modmacao.occi.platform.Component; +import org.modmacao.occi.platform.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,10 +46,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl * Initialize the logger. */ private static Logger LOGGER = LoggerFactory.getLogger(ResultproviderConnector.class); - private OCCIFactoryImpl factory = new OCCIFactoryImpl(); - private Sensor sensor; - private Monitorableproperty monProp; - private Resource monObject; + private Thread simulation; //private Occiresultprovider occiResProv; @@ -58,14 +57,16 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl ResultproviderConnector() { LOGGER.debug("Constructor called on " + this); - //occiResProv = getMartMixin(); - // 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. @@ -74,6 +75,7 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl public void occiCreate() { LOGGER.debug("occiCreate() called on " + this); + // TODO: Implement this callback or remove this method. } // End of user code @@ -86,6 +88,13 @@ 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())); + simulation = new Thread(sim); + simulation.start(); + } + } // TODO: Implement this callback or remove this method. } // End of user code @@ -129,7 +138,15 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl public void configure() { LOGGER.debug("Action configure() called on " + this); - setRuntimeInformation(); + 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 @@ -144,10 +161,16 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl public void deploy() { LOGGER.debug("Action deploy() called on " + this); - setRuntimeInformation(); + switch(this.getOcciComponentState().getValue()) { - - // TODO: Implement how to deploy this publisher. + case Status.UNDEPLOYED_VALUE: + this.setOcciComponentState(Status.DEPLOYED); + break; + + default: + break; +} + } // End of user code @@ -162,8 +185,33 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl public void undeploy() { LOGGER.debug("Action undeploy() called on " + this); - setRuntimeInformation(); - // TODO: Implement how to undeploy this publisher. + 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 @@ -177,8 +225,10 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl public void stop() { LOGGER.debug("Action stop() called on " + this); - setRuntimeInformation(); - // TODO: Implement how to stop this publisher. + if(simulation!= null) { + simulation.stop(); + } + setOcciComponentState(Status.INACTIVE); } // End of user code // Start of user code Publisher_Kind_Start_action @@ -192,48 +242,35 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl public void start() { LOGGER.debug("Action start() called on " + this); - setRuntimeInformation(); - } - - - private void setRuntimeInformation() { - sensor = getSensor(); - AttributeState sensorAttr = factory.createAttributeState(); - sensorAttr.setName("sensor"); - sensorAttr.setValue(sensor.getLocation()); - System.out.println("Sensor: " + sensor); - this.attributes.add(sensorAttr); - - monProp = getMonProp(sensor); - AttributeState monPropAttr = factory.createAttributeState(); - monPropAttr.setName("monitorable.property"); - monPropAttr.setValue(monProp.getLocation()); - System.out.println("MonProp: " + monProp); - this.attributes.add(monPropAttr); - - AttributeState monPropNameAttr = factory.createAttributeState(); - monPropNameAttr.setName("monitorable.property.property"); - monPropNameAttr.setValue(monProp.getMonitoringProperty()); - this.attributes.add(monPropNameAttr); - - monObject = monProp.getTarget(); - AttributeState monObjectAttr = factory.createAttributeState(); - monObjectAttr.setName("monitorable.property.target"); - monObjectAttr.setValue(monObject.getLocation()); + switch(this.getOcciComponentState().getValue()) { + + case Status.INACTIVE_VALUE: + this.setOcciComponentState(Status.ACTIVE); + if(simulation == null) { + CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); + simulation = new Thread(sim); + simulation.start(); + } + break; + + + case Status.UNDEPLOYED_VALUE: + this.setOcciComponentState(Status.ACTIVE); + if(simulation == null) { + CPUSimulation sim = new CPUSimulation(getMonProp(getSensor())); + simulation = new Thread(sim); + simulation.start(); + } + break; + + default: + break; } + } // End of user code - private Occiresultprovider getMartMixin() { - for(MixinBase mixinBase: this.getParts()) { - if(mixinBase instanceof Occiresultprovider) { - LOGGER.info("Occiresultprovider found: " + this.title); - return ((Occiresultprovider)mixinBase); - } - } - return null; - } private Sensor getSensor() { for(Link link: this.getRlinks()) { @@ -252,4 +289,5 @@ public class ResultproviderConnector extends monitoring.impl.ResultproviderImpl } throw new NoSuchElementException("No monitorableproperty found in sensor!"); } + }