Definition of a 3-node, 2-app ElasticSystem example

parent 8013e970
......@@ -6,7 +6,7 @@ VoIP:
norm: 10
priority: 2
balance: 0.25
rttmax: 5
rttmax: 100
pllmax: 1e-2
iface: Wi-Fi
......@@ -30,7 +30,7 @@ videoStream:
norm: 10
priority: 5
balance: 0.25
rttmax: 5
rttmax: 300
pllmax: 1e-6
iface: Wi-Fi
......
......@@ -12,20 +12,25 @@ import utils.HardwareInfo;
public class NetMonitor extends ResourceManager {
HardwareInfo hardwareInfo;
Node node;
public NetMonitor(ElasticSystem elasticSystem, HardwareInfo hardwareInfo) {
public NetMonitor(ElasticSystem elasticSystem) {
super(elasticSystem);
this.hardwareInfo = hardwareInfo;
this.node = getNodeByIP("10.0.2.15"); //TODO: get IP as I should
this.hardwareInfo = new HardwareInfo();
//this.node = getNodeByIP("10.0.2.15"); //TODO: get IP as I should
}
public NetMonitor() {
this.hardwareInfo = new HardwareInfo();
}
public void setLinksRTT() {
public void setLinksRTT(Node node) {
List<CommunicationLink> commsList = this.node.getCommunicationLinks().stream().
filter(cl -> cl.getIpNode1().equals("10.0.2.15")).
List<CommunicationLink> commsList = node.getCommunicationLinks().stream().
filter(cl -> cl.getIpNode1().equals(node.getIpEth())).
collect(Collectors.toList());
commsList.stream().forEach(cl -> {
......
......@@ -19,23 +19,24 @@ import utils.HardwareInfo;
public class CommsMonitoringTask extends TimerTask {
ResourceManagerComms resourceManager;
NetMonitor netMonitor;
FileUtils fileUtils;
HardwareInfo hardWareInfo;
Node node;
public CommsMonitoringTask(ResourceManagerComms resourceManager) {
public CommsMonitoringTask(ResourceManagerComms resourceManager, NetMonitor netMonitor) {
this.resourceManager = resourceManager;
this.netMonitor = netMonitor;
this.fileUtils = new FileUtils();
this.hardWareInfo = new HardwareInfo();
this.node = resourceManager.getNodeByIP("10.0.2.15"); //TODO: get IP as I should
}
@Override
public void run() {
this.resourceManager.getConfig(Constants.CONFIG_FILE_PATH);
this.resourceManager.getCosts(this.node);
this.netMonitor.setLinksRTT(this.resourceManager.getNodeByIP("192.168.137.17"));
this.resourceManager.getCosts(this.resourceManager.getNodeByIP("192.168.137.17"));
/*Map<String, Integer> intResultsMap = this.resourceManager
.checkThresholds(hardWareInfo.getTelemetry(), Arrays.asList("devLevel", "rttmax"), Arrays.asList("devLevel", "pllmax"));
......
......@@ -4,16 +4,19 @@ import java.util.Timer;
import es.bsc.dataclay.api.DataClay;
import es.bsc.dataclay.api.DataClayException;
import netMonitor.NetMonitor;
import resourceManager.ResourceManagerComms;
public class NFRMonitor {
ResourceManagerComms resourceManager;
NetMonitor netMonitor;
long period;
public NFRMonitor(ResourceManagerComms resourceManager, long period) {
public NFRMonitor(ResourceManagerComms resourceManager, NetMonitor netMonitor, long period) {
this.resourceManager = resourceManager;
this.netMonitor = netMonitor;
this.period = period;
}
......@@ -21,7 +24,7 @@ public class NFRMonitor {
final Timer timer = new Timer();
CommsMonitoringTask mTask = new CommsMonitoringTask(this.resourceManager);
CommsMonitoringTask mTask = new CommsMonitoringTask(this.resourceManager,this.netMonitor);
timer.scheduleAtFixedRate(mTask, 0, this.period);
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
......
......@@ -4,32 +4,206 @@ import java.io.FileNotFoundException;
import java.net.SocketException;
import java.util.ArrayList;
import es.bsc.compss.nfr.model.COMPSsApplication;
import es.bsc.compss.nfr.model.CommunicationLink;
import es.bsc.compss.nfr.model.ElasticSystem;
import es.bsc.compss.nfr.model.Node;
import es.bsc.compss.nfr.model.Worker;
import es.bsc.dataclay.api.DataClay;
import es.bsc.dataclay.api.DataClayException;
import es.bsc.dataclay.exceptions.metadataservice.ObjectNotRegisteredException;
import netMonitor.NetMonitor;
import resourceManager.ResourceManagerComms;
import utils.Constants;
import utils.HardwareInfo;
public class NFRTool {
public static void main(String[] args) throws DataClayException, ObjectNotRegisteredException, FileNotFoundException, SocketException {
public static void main(String[] args)
throws DataClayException, ObjectNotRegisteredException, FileNotFoundException, SocketException {
//ElasticSystem system = ElasticSystem.getByAlias("system");
//NFRMonitor nfrMonitor= new NFRMonitor(new ResourceManagerComms(), Constants.PERIOD);
//nfrMonitor.runMonitor();
HardwareInfo h = new HardwareInfo("enp0s3");
ArrayList<String> gfg = new ArrayList<String>() {
{
add("8.8.8.8");
add("4.4.4.4");
add("127.0.0.1");
}
};
System.out.println(h.getLinksRTT(gfg).toString());
DataClay.init();
/////////////////////////////////////////////////////////////////////////////////////////////////
// App A definition:
String name = "AppA";
String uuid = "A";
final int monitoringPeriod = 1;
String infoNature = "delaySensitive";
COMPSsApplication appA = new COMPSsApplication(name, uuid, monitoringPeriod);
appA.setInfoNature(infoNature);
// App B definition:
name = "AppB";
uuid = "B";
infoNature = "TCPservices";
COMPSsApplication appB = new COMPSsApplication(name, uuid, monitoringPeriod);
appB.setInfoNature(infoNature);
/////////////////////////////////////////////////////////////////////////////////////////////////
// Node 1 definition:
String ipWifi = "182.168.137.17";
String ipLte = "172.10.0.2";
String ipEth = "192.168.137.10"; // TODO: check value
float cpuThreshold = 0;
float energyThreshold = 0;
float signalWifi = -30;
int numCores = 4;
Node node1 = new Node(ipWifi, ipLte, ipEth, cpuThreshold, energyThreshold, signalWifi, numCores);
// Node 2 definition:
ipWifi = "182.168.137.20";
ipLte = "172.10.0.4";
ipEth = "192.168.137.20"; // TODO: check value
cpuThreshold = 0;
energyThreshold = 0;
signalWifi = -30;
numCores = 4;
Node node2 = new Node(ipWifi, ipLte, ipEth, cpuThreshold, energyThreshold, signalWifi, numCores);
// Node 3 definition:
ipWifi = "182.168.137.1";
ipLte = "172.10.0.6";
ipEth = "192.168.137.30"; // TODO: check value
cpuThreshold = 0;
energyThreshold = 0;
signalWifi = -30;
numCores = 4;
Node node3 = new Node(ipWifi, ipLte, ipEth, cpuThreshold, energyThreshold, signalWifi, numCores);
/////////////////////////////////////////////////////////////////////////////////////////////////
// Worker 1A definition:
final int pid1A = 32145;
final boolean active1A = true;
final float cpuUsage1A = 0;
final int computingUnits1A = 4;
final float communicationCost1A = 0;
Worker worker1A = new Worker(node1, pid1A, active1A, appA, cpuUsage1A, computingUnits1A, node1.getIpEth(),
communicationCost1A);
// Attach worker to Node and COMPSsApplication
node1.addWorker(worker1A);
appA.addWorker(worker1A);
// Worker 1B definition:
final int pid1B = 32146;
final boolean active1B = true;
final float cpuUsage1B = 0;
final int computingUnits1B = 4;
final float communicationCost1B = 0;
Worker worker1B = new Worker(node1, pid1B, active1B, appA, cpuUsage1B, computingUnits1B, node1.getIpEth(),
communicationCost1B);
// Attach worker to Node and COMPSsApplication
node1.addWorker(worker1B);
appB.addWorker(worker1B);
// Worker 2A definition:
final int pid2A = 32147;
final boolean active2A = true;
final float cpuUsage2A = 0;
final int computingUnits2A = 4;
final float communicationCost2A = 0;
Worker worker2A = new Worker(node2, pid2A, active2A, appA, cpuUsage2A, computingUnits2A, node1.getIpEth(),
communicationCost2A);
// Attach worker to Node and COMPSsApplication
node2.addWorker(worker2A);
appA.addWorker(worker2A);
// Worker 2B definition:
final int pid2B = 32148;
final boolean active2B = true;
final float cpuUsage2B = 0;
final int computingUnits2B = 4;
final float communicationCost2B = 0;
Worker worker2B = new Worker(node2, pid2B, active2B, appB, cpuUsage2B, computingUnits2B, node1.getIpEth(),
communicationCost2B);
// Attach worker to Node and COMPSsApplication
node2.addWorker(worker2B);
appB.addWorker(worker2B);
// Worker 3A definition:
final int pid3A = 32149;
final boolean active3A = true;
final float cpuUsage3A = 0;
final int computingUnits3A = 4;
final float communicationCost3A = 0;
Worker worker3A = new Worker(node3, pid3A, active3A, appA, cpuUsage3A, computingUnits3A, node3.getIpEth(),
communicationCost3A);
// Attach worker to Node and COMPSsApplication
node1.addWorker(worker3A);
appA.addWorker(worker3A);
// Worker 3B definition:
final int pid3B = 32150;
final boolean active3B = true;
final float cpuUsage3B = 0;
final int computingUnits3B = 4;
final float communicationCost3B = 0;
Worker worker3B = new Worker(node3, pid3B, active3B, appB, cpuUsage3B, computingUnits3B, node3.getIpEth(),
communicationCost3B);
// Attach worker to Node and COMPSsApplication
node3.addWorker(worker3B);
appB.addWorker(worker3B);
/////////////////////////////////////////////////////////////////////////////////////////////////
// CommunicationLink21 definition
final float delayRtt = 0;
final float plr = 0;
CommunicationLink communicationLink21 = new CommunicationLink(node1, node2, node1.getIpEth(), node2.getIpEth(),
delayRtt, plr);
node1.addCommunicationLink(communicationLink21);
node2.addCommunicationLink(communicationLink21);
/////////////////////////////////////////////////////////////////////////////////////////////////
// CommunicationLink31 definition
CommunicationLink communicationLink31 = new CommunicationLink(node1, node3, node1.getIpEth(), node3.getIpEth(),
delayRtt, plr);
node1.addCommunicationLink(communicationLink31);
node3.addCommunicationLink(communicationLink31);
/////////////////////////////////////////////////////////////////////////////////////////////////
// CommunicationLink32 definition
CommunicationLink communicationLink32 = new CommunicationLink(node2, node3, node2.getIpEth(), node3.getIpEth(),
delayRtt, plr);
node2.addCommunicationLink(communicationLink32);
node3.addCommunicationLink(communicationLink32);
ArrayList<Node> systemNodes = new ArrayList<Node>() {
{
add(node1);
add(node2);
add(node3);
}
};
ArrayList<COMPSsApplication> systemApps = new ArrayList<COMPSsApplication>() {
{
add(appA);
add(appB);
}
};
ElasticSystem system = new ElasticSystem(systemApps, systemNodes);
NFRMonitor nfrMonitor = new NFRMonitor(new ResourceManagerComms(system), new NetMonitor(system), Constants.PERIOD);
nfrMonitor.runMonitor();
// HardwareInfo h = new HardwareInfo("enp0s3");
/*
* ArrayList<String> gfg = new ArrayList<String>() { { add("8.8.8.8");
* add("4.4.4.4"); add("127.0.0.1"); } };
* System.out.println(h.getLinksRTT(gfg).toString());
*/
}
}
......@@ -113,42 +113,40 @@ public class ResourceManagerComms extends ResourceManager {
// need infoNature
String infoNature = worker.getApplication().getInfoNature();
try {
/*
* float balance = Float.valueOf(
* this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH,
* Arrays.asList(infoNature, "balance")));
*/
float priority = Float.valueOf(
this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH, Arrays.asList(infoNature, "priority")));
float norm = Float.valueOf(
this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH, Arrays.asList(infoNature, "norm")));
float rttmax = Float.valueOf(
this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH, Arrays.asList(infoNature, "rttmax")));
// We need to get the RTT for each Link in workerLinks from dataClay
double commsCost = 0;
for (int ll = 0; ll < workerLinks.size(); ll++) {
// float monitoredRTT = workerLinks.get(ll).getDelayRtt();
if (workerLinks.get(ll).getDelayRtt() >= rttmax) {
worker.setActive(false); // Is inactive true or false?
worker.setCommunicationCost(Float.POSITIVE_INFINITY);
return;
} else {
commsCost = commsCost + (priority / norm)
- (Math.log(Math.max(0, 1 - (workerLinks.get(ll).getDelayRtt() / rttmax))));
}
/*
* float balance = Float.valueOf(
* this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH,
* Arrays.asList(infoNature, "balance")));
*/
float priority = Float.valueOf(
this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH, Arrays.asList(infoNature, "priority")));
float norm = Float
.valueOf(this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH, Arrays.asList(infoNature, "norm")));
float rttmax = Float.valueOf(
this.fileUtils.getYmlNodeScalar(Constants.APP_ATTRIB_PATH, Arrays.asList(infoNature, "rttmax")));
// We need to get the RTT for each Link in workerLinks from dataClay
double commsCost = 0;
for (int ll = 0; ll < workerLinks.size(); ll++) {
// float monitoredRTT = workerLinks.get(ll).getDelayRtt();
if (workerLinks.get(ll).getDelayRtt() >= rttmax) {
worker.setActive(false); // Is inactive true or false?
worker.setCommunicationCost(Float.POSITIVE_INFINITY);
return;
} else {
commsCost = commsCost + (priority / norm)
- (Math.log(Math.max(0, 1 - (workerLinks.get(ll).getDelayRtt() / rttmax))));
}
worker.setCommunicationCost((float) commsCost);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
worker.setCommunicationCost((float) commsCost);
/*Double obj = new Double(commsCost);
float f = obj.floatValue();*/
}
public void getCosts(Node node) {
// Is Inactive True or False???
List<Worker> activeWorkers = node.getWorkers().stream().filter(w -> w.isActive()).collect(Collectors.toList());
for (int ww = 0; ww < activeWorkers.size(); ww++) {
getCost(activeWorkers.get(ww));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment