Data model updated accordingly as discussed. Also, active attribute added in...

Data model updated accordingly as discussed. Also, active attribute added in worker class and application can filter by this attribute.
parent b03642b2
......@@ -14,7 +14,7 @@ public class Application {
/** Application workers. */
private ArrayList<Worker> workers = new ArrayList<>();
/**
* Application constructor.
* @param appName Name of the application
......@@ -55,6 +55,20 @@ public class Application {
public ArrayList<Worker> getWorkers() {
return this.workers;
}
/**
* Get active workers only.
* @return Application active workers
*/
public ArrayList<Worker> getActiveWorkers() {
ArrayList<Worker> activeWorkers = new ArrayList<>();
for (Worker w : workers) {
if (w.isActive()) {
activeWorkers.add(w);
}
}
return activeWorkers;
}
/**
* Get application name
......@@ -67,8 +81,9 @@ public class Application {
@Override
public String toString() {
String result = "Application: " + name + " \n";
result += " - master: " + master + "\n";
result += " - master: " + master.toString() + "\n";
result += " - workers: " + workers + "\n";
result += " - active workers: " + getActiveWorkers() + "\n";
return result;
}
}
package model;
import java.util.ArrayList;
import java.util.stream.Collectors;
/** This class simulates an ELASTIC system composed of many applications and nodes using COMPSs. Objects instantiated by this class can be
* distributed and synchronized among nodes. */
public class ElasticSystem {
/** List of nodes in the system. */
private ArrayList<Node> nodes;
/** Applications in the system. */
private ArrayList<Application> apps;
/**
* System constructor empty.
*
*/
public ElasticSystem() {
apps = new ArrayList<>();
nodes = new ArrayList<>();
}
/**
* System constructor with already defined apps and nodes.
* @param apps List of applications
* @param nodes List of nodes
*/
public ElasticSystem(final ArrayList<Application> apps, final ArrayList<Node> nodes) {
this.apps = new ArrayList<>(apps);
this.nodes = new ArrayList<>(nodes);
}
/**
* Add a new node to the system.
* @param node Node to be added
*/
public void addNode(final Node node) {
nodes.add(node);
}
/**
* Add a new application to the system.
* @param app Application to be added
*/
public void addApplication(final Application app) {
apps.add(app);
}
/**
* Get system nodes.
* @return System nodes
*/
public ArrayList<Node> getNodes() {
return this.nodes;
}
/**
* Get applications in the system
* @return apps
*/
public ArrayList<Application> getApplications() {
return this.apps;
}
@Override
public String toString() {
String result = "Applications: " + apps.stream().map(Application::getName).collect(Collectors.toList()) + " \n";
result += " - nodes: " + nodes.stream().map(Node::getName).collect(Collectors.toList()) + "\n";
return result;
}
}
package model;
import es.bsc.dataclay.DataClayObject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* This class represents a master process.
......@@ -13,6 +16,8 @@ public class Master extends DataClayObject {
/** Master process PID. */
private int pid;
/** Applications executed by this master. */
private Application app;
/**
* Constructor.
......@@ -56,10 +61,27 @@ public class Master extends DataClayObject {
public void setPid(int pid) {
this.pid = pid;
}
/**
* Get application executed by this master
* @return application executed by the master
*/
public Application getApplication() {
return app;
}
/**
* Set application executed by the master
* @param application launched by the master
*/
public void setApplication(final Application app) {
this.app = app;
}
@Override
public String toString() {
return " master { pid = " + pid + " , node = " + node.toString() + "}";
return " master { pid = " + pid + " , node = " + node.toString()
+ " , application = " + app.getName() + "}";
}
}
......@@ -2,6 +2,7 @@ package model;
import es.bsc.dataclay.DataClayObject;
import java.util.ArrayList;
/**
* This class represents a COMPSs node.
......@@ -17,6 +18,11 @@ public class Node extends DataClayObject {
/** Node capacity. */
private int capacity;
/** List of all masters present in a given node. */
private ArrayList<Master> masters = new ArrayList<>();
/** List of all workers present in a given node. */
private ArrayList<Worker> workers = new ArrayList<>();
/**
* Constructor.
......@@ -79,6 +85,38 @@ public class Node extends DataClayObject {
public void setName(String name) {
this.name = name;
}
/**
* Adds a master in the given node in order to be able to traverse the other way around.
* @param master Master in the current node.
*/
public void addMaster(final Master master) {
masters.add(master);
}
/**
* Returns the list of master objects present in a specific node.
* @return List of master objects
*/
public ArrayList<Master> getMasters() {
return masters;
}
/**
* Adds a new worker to the list of workers on a specific node in order to be able to traverse the classes the other way around.
* @param
*/
public void addWorker(final Worker worker) {
workers.add(worker);
}
/**
* Returns the list of worker objects present in a specific node.
* @return List of workers
*/
public ArrayList<Worker> getWorkers() {
return workers;
}
@Override
public String toString() {
......
package model;
import es.bsc.dataclay.DataClayObject;
import java.util.ArrayList;
import java.util.stream.Collectors;
/**
* This class represents a worker process.
......@@ -16,6 +18,12 @@ public class Worker extends DataClayObject {
/** Worker process PID. */
private int pid;
/** Boolean showing if worker is running applications. */
private boolean active;
/** Application this worker is executing. */
private Application app;
/**
* Constructor.
......@@ -23,10 +31,11 @@ public class Worker extends DataClayObject {
* @param address Worker process address.
* @param pid Worker process PID
*/
public Worker(final Node node, final String address, final int pid) {
public Worker(final Node node, final String address, final int pid, final boolean active) {
this.node = node;
this.address = address;
this.pid = pid;
this.active = active;
}
/**
......@@ -77,10 +86,43 @@ public class Worker extends DataClayObject {
public void setPid(int pid) {
this.pid = pid;
}
/**
* Get active value for worker
* @return boolean active if worker executing apps
*/
public boolean isActive() {
return active;
}
/**
* Set active value to the parameter passed to it
* @param active boolean value: true if executing, false otherwise
*/
public void setActive(final boolean active) {
this.active = active;
}
/**
* Get application that worker is executing
* @return list of all applications
*/
public Application getApplication() {
return app;
}
/**
* Sets an application to the worker
* @param app new application that this worker is executing
*/
public void setApplication(final Application app) {
this.app = app;
}
@Override
public String toString() {
return " worker { pid = " + pid + " , address = " + address + ", node = " + node.toString() + "}";
return " worker { pid = " + pid + " , address = " + address + ", node = " + node.toString() + ", application = "
+ app.getName() + "}";
}
}
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