Skip to content
Snippets Groups Projects
Commit 51cc3620 authored by erbel's avatar erbel
Browse files

Added Example MAPE loop

parent 904847dc
No related branches found
No related tags found
1 merge request!2Dev/mon prop resource
package de.ugoe.cs.rwm.mocci;
import java.nio.file.Path;
import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl;
import org.eclipse.cmf.occi.infrastructure.impl.InfrastructureFactoryImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.resource.Resource;
import org.modmacao.occi.platform.impl.PlatformFactoryImpl;
import org.modmacao.placement.impl.PlacementFactoryImpl;
import de.ugoe.cs.rwm.docci.connector.Connector;
import monitoring.impl.MonitoringFactoryImpl;
public abstract class AbsScaler {
protected InfrastructureFactoryImpl iFactory = new InfrastructureFactoryImpl();
protected OCCIFactoryImpl factory = new OCCIFactoryImpl();
protected MonitoringFactoryImpl mFactory = new MonitoringFactoryImpl();
protected PlatformFactoryImpl pFactory = new PlatformFactoryImpl();
protected PlacementFactoryImpl placeFactory = new PlacementFactoryImpl();
protected Resource runtimeModel;
protected Connector conn;
protected Path runtimePath;
protected org.eclipse.cmf.occi.core.Resource getResourceById(EList<org.eclipse.cmf.occi.core.Resource> eList, String string) {
for(org.eclipse.cmf.occi.core.Resource res: eList ) {
if(res.getId().equals(string)) {
return res;
}
}
return null;
}
}
package de.ugoe.cs.rwm.mocci;
import java.nio.file.Path;
import org.eclipse.cmf.occi.core.Configuration;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.infrastructure.Compute;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.modmacao.occi.platform.Component;
import de.ugoe.cs.rwm.docci.ModelUtility;
import de.ugoe.cs.rwm.docci.connector.Connector;
import monitoring.Monitorableproperty;
public class DownScaler extends AbsScaler {
public DownScaler(Connector conn, Path runtimePath) {
this.conn = conn;
this.runtimePath = runtimePath;
}
public Resource downScaleNodes() {
EList<EObject> toDelete = new BasicEList<EObject>();
runtimeModel = ModelUtility.loadOCCIintoEMFResource(conn.loadRuntimeModel(runtimePath));
Configuration config = ((Configuration) runtimeModel.getContents().get(0));
boolean downScale = false;
for(org.eclipse.cmf.occi.core.Resource res : config.getResources()) {
if(res instanceof Compute) {
Compute comp = (Compute) res;
if(comp.getTitle().contains("hadoop-worker-additional")) {
Monitorableproperty monProp = getAttachedCPUMonProp(comp);
if(monProp != null && monProp.getMonitoringResult() != null) {
if(monProp.getMonitoringResult().equals("None")) {
System.out.println(" VM with None CPU utilization found: " + comp.getId());
toDelete.add(comp);
toDelete.addAll(linksAndComponents(comp));
System.out.println(" Deleting Entities Around: " + comp.getTitle() +" ("+comp.getId()+")");
downScale = true;
break;
}
}
}
}
}
if(downScale == false) {
System.out.println(" Every Compute busy/Only one worker! Skipping downScale!");
}
runtimeModel.getContents().removeAll(toDelete);
return runtimeModel;
}
private Monitorableproperty getAttachedCPUMonProp(Compute comp) {
for(Link link: comp.getRlinks()) {
//System.out.println("LINK: " + link);
if(link instanceof Monitorableproperty) {
Monitorableproperty monProp = (Monitorableproperty) link;
//System.out.println("MonPROP: " + monProp);
//System.out.println("Prop: " + monProp.getMonitoringProperty());
if(monProp.getMonitoringProperty().equals("CPU")) {
return monProp;
}
}
}
return null;
}
private EList<EObject> linksAndComponents(Compute comp) {
EList<EObject> toDelete = new BasicEList<EObject>();
toDelete.addAll(comp.getLinks());
toDelete.addAll(comp.getRlinks());
for(Link link: comp.getRlinks()) {
if(link.getSource() instanceof Component) {
toDelete.add(link.getSource());
}
if(link instanceof Monitorableproperty) {
toDelete.add(link.getSource());
}
}
return toDelete;
}
}
...@@ -9,15 +9,21 @@ import org.eclipse.cmf.occi.core.Link; ...@@ -9,15 +9,21 @@ import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl; import org.eclipse.cmf.occi.core.impl.OCCIFactoryImpl;
import org.eclipse.cmf.occi.infrastructure.Compute; import org.eclipse.cmf.occi.infrastructure.Compute;
import org.eclipse.cmf.occi.infrastructure.ComputeStatus; import org.eclipse.cmf.occi.infrastructure.ComputeStatus;
import org.eclipse.cmf.occi.infrastructure.Networkinterface;
import org.eclipse.cmf.occi.infrastructure.impl.InfrastructureFactoryImpl; import org.eclipse.cmf.occi.infrastructure.impl.InfrastructureFactoryImpl;
import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.epsilon.emc.emf.CachedResourceSet;
import org.json.JSONArray;
import org.modmacao.occi.platform.Component; import org.modmacao.occi.platform.Component;
import org.modmacao.occi.platform.Componentlink; import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.PlatformPackage; import org.modmacao.occi.platform.PlatformPackage;
import org.modmacao.occi.platform.Status;
import org.modmacao.occi.platform.impl.PlatformFactoryImpl; import org.modmacao.occi.platform.impl.PlatformFactoryImpl;
import org.modmacao.placement.Placementlink;
import org.modmacao.placement.impl.PlacementFactoryImpl;
import de.ugoe.cs.rwm.docci.MartDeployer; import de.ugoe.cs.rwm.docci.MartDeployer;
import de.ugoe.cs.rwm.docci.ModelUtility; import de.ugoe.cs.rwm.docci.ModelUtility;
...@@ -46,35 +52,28 @@ public class MAPE { ...@@ -46,35 +52,28 @@ public class MAPE {
protected static final Path RUNTIMEPATH = Paths.get(System.getProperty("user.home") + "/.rwm/runtime.occic"); protected static final Path RUNTIMEPATH = Paths.get(System.getProperty("user.home") + "/.rwm/runtime.occic");
static Connector conn = new LocalhostConnector("localhost", 8080, "ubuntu"); static Connector conn = new LocalhostConnector("localhost", 8080, "ubuntu");
static MartDeployer deployer = new MartDeployer(conn); static MartDeployer deployer = new MartDeployer(conn);
static MartExecutor executor = new MartExecutor(conn); static MartQuery executor = new MartQuery(conn);
static InfrastructureFactoryImpl iFactory = new InfrastructureFactoryImpl();
static OCCIFactoryImpl factory = new OCCIFactoryImpl();
static MonitoringFactoryImpl mFactory = new MonitoringFactoryImpl();
static PlatformFactoryImpl pFactory = new PlatformFactoryImpl();
static Resource runtimeModel; static Resource runtimeModel;
static int interval;
/**Making javadoc happy. /**Making javadoc happy.
* @param args Making javadoc happy. * @param args Making javadoc happy.
*/ */
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Starting MAPE loop");
RegistryAndLoggerSetup.setup(); RegistryAndLoggerSetup.setup();
interval=10000;
String query = "/monitorableproperty?attribute=monitoring.result&value=Critical";
initialDeploy(); initialDeploy();
String monitor ="";
String analysis ="";
while(true) { while(true) {
try { try {
monitor = monitor(query); System.out.println("\n--------------------Waiting for new Cycle: Sleeping " + interval +"--------------------");
analysis = analyze(monitor); Thread.sleep(interval);
Monitor monitor = monitor();
String analysis = analyze(monitor);
runtimeModel = plan(analysis); runtimeModel = plan(analysis);
execute(runtimeModel); execute(runtimeModel);
System.out.println("Sleep 10000");
Thread.sleep(10000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -82,152 +81,55 @@ public class MAPE { ...@@ -82,152 +81,55 @@ public class MAPE {
} }
} }
private static String monitor(String query) { private static Monitor monitor() {
MartExecutor exec = new MartExecutor(conn); int critCPUs = getNumberOfCriticalCPUs();
String result = exec.executeGetOperation(query); int noneCPUs = getNumberOfNoneCPUs();
System.out.println("Monitor: " + result); int allCPUs = getNumberOfAllCPUs();
return exec.executeGetOperation(query); Monitor mon = new Monitor(critCPUs, noneCPUs, allCPUs);
System.out.println("Monitor: " + "Monitored CPUs: " + allCPUs + "| Critical CPUs: "+ critCPUs + "| None CPUs: " + noneCPUs);
return mon;
} }
private static String analyze(String monitor) {
private static String analyze(Monitor monitor) {
int noneCPUs = monitor.getNoneCPUs();
int critCPUs = monitor.getCritCPUs();
int allCPUs = monitor.getAllCPUs();
if(monitor.contains("/compute/")){ if(noneCPUs == 0 && critCPUs > allCPUs/2 && allCPUs <= 6){
System.out.println("Analyze: Critical Compute Detected"); System.out.println("Analyze: Critical State Detected");
return "upScale"; return "upScale";
} } else {
else { System.out.println("Analyze: Non Critical State Detected");
System.out.println("Analyze: No Critical Compute Detected");
return "downScale"; return "downScale";
} }
} }
private static Resource plan(String analysis) { private static Resource plan(String analysis) {
System.out.println("Planning:");
switch (analysis) { switch (analysis) {
case "upScale": System.out.println("upScale!"); case "upScale": System.out.println("Plan: upScale!");
return upScaleNodes(); UpScaler upscaler = new UpScaler(conn, RUNTIMEPATH);
case "downScale": System.out.println("downScale!"); return upscaler.upScaleNodes();
return downScaleNodes(); case "downScale": System.out.println("Plan: downScale!");
DownScaler downscaler = new DownScaler(conn, RUNTIMEPATH);
return downscaler.downScaleNodes();
} }
return null; return null;
} }
private static void execute(Resource runtimeModel) { private static void execute(Resource runtimeModel) {
System.out.println("Execute: Deploying adjusted Model");
deployer.deploy(runtimeModel); deployer.deploy(runtimeModel);
} }
private static Resource downScaleNodes() {
EList<EObject> toDelete = new BasicEList<EObject>();
runtimeModel = ModelUtility.loadOCCIintoEMFResource(conn.loadRuntimeModel(RUNTIMEPATH));
System.out.println(((Configuration) runtimeModel.getContents().get(0)).getResources());
for(org.eclipse.cmf.occi.core.Resource res : ((Configuration) runtimeModel.getContents().get(0)).getResources()) {
if(res instanceof Compute) {
Compute comp = (Compute) res;
if(comp.getTitle().contains("worker-additional")) {
toDelete.add(comp);
toDelete.addAll(linksAndComponents(comp));
break;
}
}
}
System.out.println(((Configuration) runtimeModel.getContents().get(0)).getResources());
runtimeModel.getContents().removeAll(toDelete);
System.out.println("Deleting Compute:" + toDelete);
System.out.println(((Configuration) runtimeModel.getContents().get(0)).getResources());
return runtimeModel;
}
private static EList<EObject> linksAndComponents(Compute comp) {
EList<EObject> toDelete = new BasicEList<EObject>();
toDelete.addAll(comp.getLinks());
toDelete.addAll(comp.getRlinks());
for(Link link: comp.getRlinks()) {
if(link.getSource() instanceof Component) {
toDelete.add(link.getSource());
}
if(link instanceof Monitorableproperty) {
toDelete.add(link.getSource());
}
}
return toDelete;
}
private static Resource upScaleNodes() {
runtimeModel = ModelUtility.loadOCCIintoEMFResource(conn.loadRuntimeModel(RUNTIMEPATH));
Configuration config = ((Configuration) runtimeModel.getContents().get(0));
Compute comp = iFactory.createCompute();
comp.setTitle("hadoop-worker-additional");
comp.setOcciComputeState(ComputeStatus.ACTIVE);
AttributeState attr = factory.createAttributeState();
attr.setName("occi.compute.state");
attr.setValue("active");
comp.getAttributes().add(attr);
((Configuration) runtimeModel.getContents().get(0)).getResources().add(comp);
System.out.println("Compute Node added");
//executor.executeOperation("PUT", comp, null);
Sensor sens = mFactory.createSensor();
sens.setTitle("CPUSensor");
config.getResources().add(sens);
//executor.executeOperation("PUT", sens, null);
Monitorableproperty mp = mFactory.createMonitorableproperty();
mp.setTitle("monProp");
mp.setMonitoringProperty("CPU");
mp.setSource(sens);
mp.setTarget(comp);
//executor.executeOperation("PUT", mp, null);
Datagatherer dg = mFactory.createDatagatherer();
dg.setTitle("CPUGatherer");
config.getResources().add(dg);
executor.executeOperation("PUT", dg, null);
Componentlink c1 = pFactory.createComponentlink();
c1.setSource(sens);
c1.setTarget(dg);
//executor.executeOperation("PUT", c1, null);
Dataprocessor dp = mFactory.createDataprocessor();
dp.setTitle("CPUProcessor");
config.getResources().add(dp);
//executor.executeOperation("PUT", dp, null);
Componentlink c2 = pFactory.createComponentlink();
c2.setSource(sens);
c2.setTarget(dp);
//executor.executeOperation("PUT", c2, null);
Resultprovider rp = mFactory.createResultprovider();
rp.setTitle("CPUProvider");
config.getResources().add(rp);
//executor.executeOperation("PUT", rp, null);
Componentlink c3 = pFactory.createComponentlink();
c3.setSource(sens);
c3.setTarget(rp);
//executor.executeOperation("PUT", c3, null);
return runtimeModel;
}
public static void initialDeploy() { public static void initialDeploy() {
System.out.println("Initial Deployment");
Path occiPath = Paths.get(ModelUtility.getPathToResource("occi/hadoopClusterNewExtWithMem.occic")); Path occiPath = Paths.get(ModelUtility.getPathToResource("occi/hadoopClusterNewExtWithMem.occic"));
Resource model = ModelUtility.loadOCCIintoEMFResource(occiPath); Resource model = ModelUtility.loadOCCIintoEMFResource(occiPath);
System.out.println("OCCI2OCCITransformator");
Transformator trans = TransformatorFactory.getTransformator("OCCI2OCCI"); Transformator trans = TransformatorFactory.getTransformator("OCCI2OCCI");
trans.transform(model, occiPath); trans.transform(model, occiPath);
...@@ -235,12 +137,57 @@ public static void initialDeploy() { ...@@ -235,12 +137,57 @@ public static void initialDeploy() {
trans2.setTransformationProperties(manNWRuntimeId, sshKey, userData, manNWid); trans2.setTransformationProperties(manNWRuntimeId, sshKey, userData, manNWid);
trans2.transform(occiPath, occiPath); trans2.transform(occiPath, occiPath);
deployer.deploy(occiPath);
executor.executeGetOperation("/resultprovider");
}
private static int getNumberOfNoneCPUs() {
String query = "/monitorableproperty?attribute=monitoring.result&value=None";
String result = executor.executeGetOperation(query);
if(result.equals("{ }") == false) {
String substring = result.substring(result.indexOf("["), (result.lastIndexOf("]")+1));
JSONArray arr = new JSONArray(substring);
if(arr.length() == 0) {
return 1;
} else {
return arr.length();
}
} else {
return 0;
}
}
deployer.deploy(occiPath); private static int getNumberOfCriticalCPUs() {
String query = "/monitorableproperty?attribute=monitoring.result&value=Critical";
String result = executor.executeGetOperation(query);
if(result.equals("{ }") == false) {
String substring = result.substring(result.indexOf("["), (result.lastIndexOf("]")+1));
JSONArray arr = new JSONArray(substring);
if(arr.length() == 0) {
return 1;
} else {
return arr.length();
}
} else {
return 0;
}
} }
private static int getNumberOfAllCPUs() {
String query = "/monitorableproperty?attribute=monitoring.property&value=CPU";
String result = executor.executeGetOperation(query);
if(result.equals("{ }") == false) {
String substring = result.substring(result.indexOf("["), (result.lastIndexOf("]")+1));
JSONArray arr = new JSONArray(substring);
if(arr.length() == 0) {
return 1;
} else {
return arr.length();
}
} else {
return 0;
}
}
} }
\ No newline at end of file
package de.ugoe.cs.rwm.mocci;
import java.net.HttpURLConnection;
import org.eclipse.cmf.occi.core.Action;
import org.eclipse.cmf.occi.core.AttributeState;
import org.eclipse.cmf.occi.core.Entity;
import org.eclipse.cmf.occi.core.Link;
import org.eclipse.cmf.occi.core.Mixin;
import org.eclipse.cmf.occi.core.MixinBase;
import org.eclipse.emf.ecore.EObject;
import de.ugoe.cs.rwm.docci.connector.Connector;
import de.ugoe.cs.rwm.docci.executor.AbsExecutor;
import de.ugoe.cs.rwm.docci.executor.MartExecutor;
/**
* Handles execution of OCCI Model Elements.
*
* @author erbel
*
*/
public class MartQuery extends MartExecutor {
/**
* Creates an Executor to the OCCI API of the specified connection. Sets
* maxTries to 3.
*
* @param conn
*/
public MartQuery(Connector conn) {
super(conn);
}
/**
* Creates Executor to the OCCI API of the specified connection. maxTries is
* hereby the maximum amount of retries for a request. Should be at least 2 to
* handle connection issues.
*
* @param conn
* @param maxTries
*/
public MartQuery(Connector conn, int maxTries) {
super(conn, maxTries);
}
public String executeGetOperation(String query) {
String adaptedAddress = "http://" + connector.getAddress() + ":" + connector.getPort() + query;
HttpURLConnection conn = establishConnection(adaptedAddress, null, false, null);
conn.setRequestProperty("Accept", "application/json");
//System.out.println("GET" + " " + adaptedAddress);
return getOutput(conn);
}
}
package de.ugoe.cs.rwm.mocci;
public class Monitor {
private int critCPUs;
private int noneCPUs;
private int allCPUs;
public int getAllCPUs() {
return allCPUs;
}
public void setAllCPUs(int allCPUs) {
this.allCPUs = allCPUs;
}
public Monitor(int critCPUs, int noneCPUs, int allCPUs) {
this.critCPUs = critCPUs;
this.noneCPUs = noneCPUs;
this.allCPUs = allCPUs;
}
public int getCritCPUs() {
return critCPUs;
}
public void setCritCPUs(int critCPUs) {
this.critCPUs = critCPUs;
}
public int getNoneCPUs() {
return noneCPUs;
}
public void setNoneCPUs(int noneCPUs) {
this.noneCPUs = noneCPUs;
}
}
...@@ -11,7 +11,9 @@ import org.modmacao.placement.PlacementPackage; ...@@ -11,7 +11,9 @@ import org.modmacao.placement.PlacementPackage;
import de.ugoe.cs.rwm.cocci.Comparator; import de.ugoe.cs.rwm.cocci.Comparator;
import de.ugoe.cs.rwm.docci.Deployer; import de.ugoe.cs.rwm.docci.Deployer;
import de.ugoe.cs.rwm.docci.appdeployer.MartAppDeployerSlave;
import de.ugoe.cs.rwm.docci.connector.Connector; import de.ugoe.cs.rwm.docci.connector.Connector;
import de.ugoe.cs.rwm.docci.deprovisioner.Deprovisioner;
import de.ugoe.cs.rwm.docci.executor.Executor; import de.ugoe.cs.rwm.docci.executor.Executor;
import de.ugoe.cs.rwm.docci.provisioner.Provisioner; import de.ugoe.cs.rwm.docci.provisioner.Provisioner;
import de.ugoe.cs.rwm.docci.retriever.ModelRetriever; import de.ugoe.cs.rwm.docci.retriever.ModelRetriever;
...@@ -35,9 +37,11 @@ public class RegistryAndLoggerSetup { ...@@ -35,9 +37,11 @@ public class RegistryAndLoggerSetup {
Logger.getLogger(Connector.class.getName()).setLevel(Level.OFF); Logger.getLogger(Connector.class.getName()).setLevel(Level.OFF);
Logger.getLogger(ModelRetriever.class.getName()).setLevel(Level.OFF); Logger.getLogger(ModelRetriever.class.getName()).setLevel(Level.OFF);
Logger.getLogger(Comparator.class.getName()).setLevel(Level.OFF); Logger.getLogger(Comparator.class.getName()).setLevel(Level.OFF);
Logger.getLogger(Provisioner.class.getName()).setLevel(Level.INFO); Logger.getLogger(Provisioner.class.getName()).setLevel(Level.OFF);
Logger.getLogger(Deployer.class.getName()).setLevel(Level.OFF); Logger.getLogger(Deployer.class.getName()).setLevel(Level.OFF);
Logger.getLogger(Deprovisioner.class.getName()).setLevel(Level.OFF);
Logger.getLogger(Executor.class.getName()).setLevel(Level.OFF); Logger.getLogger(Executor.class.getName()).setLevel(Level.OFF);
Logger.getLogger(MartAppDeployerSlave.class.getName()).setLevel(Level.OFF);
} }
private static void registrySetup() { private static void registrySetup() {
......
package de.ugoe.cs.rwm.mocci;
import java.nio.file.Path;
import org.eclipse.cmf.occi.core.AttributeState;
import org.eclipse.cmf.occi.core.Configuration;
import org.eclipse.cmf.occi.infrastructure.Compute;
import org.eclipse.cmf.occi.infrastructure.ComputeStatus;
import org.eclipse.cmf.occi.infrastructure.Networkinterface;
import org.eclipse.emf.ecore.resource.Resource;
import org.modmacao.occi.platform.Component;
import org.modmacao.occi.platform.Componentlink;
import org.modmacao.occi.platform.Status;
import org.modmacao.placement.Placementlink;
import de.ugoe.cs.rwm.docci.ModelUtility;
import de.ugoe.cs.rwm.docci.connector.Connector;
import monitoring.Datagatherer;
import monitoring.Dataprocessor;
import monitoring.Monitorableproperty;
import monitoring.Resultprovider;
import monitoring.Sensor;
public class UpScaler extends AbsScaler {
public UpScaler(Connector conn, Path runtimePath) {
this.conn = conn;
this.runtimePath = runtimePath;
}
@SuppressWarnings("unused")
public Resource upScaleNodes() {
runtimeModel = ModelUtility.loadOCCIintoEMFResource(conn.loadRuntimeModel(runtimePath));
Configuration config = ((Configuration) runtimeModel.getContents().get(0));
Compute monVM = (Compute) getResourceById(config.getResources(), "urn:uuid:37829092-c690-494a-98fa-335b2fd660ea");
Compute comp = addCompute(config);
Component worker = addWorkerComponent(config, comp);
Sensor sens = addSensor(config, comp);
Datagatherer dg = addDataGatherer(config, comp, sens);
Dataprocessor dp = addDataProcessor(config, monVM, sens, dg);
Resultprovider rp = addResultProvider(config, monVM, sens, dp);
return runtimeModel;
}
private Compute addCompute(Configuration config) {
System.out.println("Adding Compute Node to Model");
Compute comp = iFactory.createCompute();
comp.setTitle("hadoop-worker-additional");
comp.setOcciComputeState(ComputeStatus.ACTIVE);
AttributeState attr = factory.createAttributeState();
attr.setName("occi.compute.state");
attr.setValue("active");
comp.getAttributes().add(attr);
config.getResources().add(comp);
//executor.executeOperation("PUT", comp, null);
Networkinterface nwi = iFactory.createNetworkinterface();
nwi.setTarget(getResourceById(config.getResources(), "urn:uuid:29d78078-fb4c-47aa-a9af-b8aaf3339591"));
nwi.setSource(comp);
Networkinterface nwimon = iFactory.createNetworkinterface();
nwimon.setTarget(getResourceById(config.getResources(), "urn:uuid:7a9fca2c-24fb-473c-aa9c-8dc9e68a432a"));
nwimon.setSource(comp);
return comp;
}
private Component addWorkerComponent(Configuration config, Compute comp) {
System.out.println("Adding Worker Component to Model");
Component worker = pFactory.createComponent();
worker.setTitle("worker-component");
worker.setOcciComponentState(Status.ACTIVE);
config.getResources().add(worker);
AttributeState attr = factory.createAttributeState();
attr.setName("occi.core.id");
attr.setValue(worker.getId());
worker.getAttributes().add(attr);
Placementlink pLink = placeFactory.createPlacementlink();
pLink.setSource(worker);
pLink.setTarget(comp);
Componentlink compLink = pFactory.createComponentlink();
compLink.setSource(getResourceById(config.getResources(), "urn:uuid:a4888ba9-a0ea-48f2-a29e-901c876ab42d"));
compLink.setTarget(worker);
return worker;
}
private Sensor addSensor(Configuration config, Compute comp) {
System.out.println("Adding Sensor to Model");
Sensor sens = mFactory.createSensor();
sens.setTitle("CPUSensor");
config.getResources().add(sens);
//executor.executeOperation("PUT", sens, null);
AttributeState attr = factory.createAttributeState();
attr.setName("occi.core.id");
attr.setValue(sens.getId());
sens.getAttributes().add(attr);
Monitorableproperty mp = mFactory.createMonitorableproperty();
mp.setTitle("monProp");
mp.setMonitoringProperty("CPU");
AttributeState attrProp = factory.createAttributeState();
attrProp.setName("monitoring.property");
attrProp.setValue("CPU");
mp.getAttributes().add(attrProp);
mp.setSource(sens);
mp.setTarget(comp);
//executor.executeOperation("PUT", mp, null);
return sens;
}
private Datagatherer addDataGatherer(Configuration config, Compute comp, Sensor sens) {
System.out.println(" Adding Datagatherer to Model");
Datagatherer dg = mFactory.createDatagatherer();
dg.setTitle("CPUGatherer");
config.getResources().add(dg);
AttributeState attr = factory.createAttributeState();
attr.setName("occi.core.id");
attr.setValue(dg.getId());
dg.getAttributes().add(attr);
//executor.executeOperation("PUT", dg, null);
Componentlink c1 = pFactory.createComponentlink();
c1.setSource(sens);
c1.setTarget(dg);
//executor.executeOperation("PUT", c1, null);
Placementlink pl = placeFactory.createPlacementlink();
pl.setSource(dg);
pl.setTarget(comp);
return dg;
}
private Dataprocessor addDataProcessor(Configuration config, Compute comp, Sensor sens, Datagatherer dg) {
System.out.println(" Adding Dataprocessor to Model");
Dataprocessor dp = mFactory.createDataprocessor();
dp.setTitle("CPUProcessor");
config.getResources().add(dp);
AttributeState attr = factory.createAttributeState();
attr.setName("occi.core.id");
attr.setValue(dp.getId());
dp.getAttributes().add(attr);
Componentlink c2 = pFactory.createComponentlink();
c2.setSource(sens);
c2.setTarget(dp);
Placementlink pl = placeFactory.createPlacementlink();
pl.setSource(dp);
pl.setTarget(comp);
Componentlink cl = pFactory.createComponentlink();
cl.setSource(dp);
cl.setTarget(dg);
return dp;
}
private Resultprovider addResultProvider(Configuration config, Compute comp, Sensor sens, Dataprocessor dp) {
System.out.println(" Adding Resultprovider to Model");
Resultprovider rp = mFactory.createResultprovider();
rp.setTitle("CPUProvider");
config.getResources().add(rp);
AttributeState attr = factory.createAttributeState();
attr.setName("occi.core.id");
attr.setValue(rp.getId());
rp.getAttributes().add(attr);
Componentlink c3 = pFactory.createComponentlink();
c3.setSource(sens);
c3.setTarget(rp);
Placementlink pl = placeFactory.createPlacementlink();
pl.setSource(rp);
pl.setTarget(comp);
Componentlink cl = pFactory.createComponentlink();
cl.setSource(rp);
cl.setTarget(dp);
return rp;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment