use of edu.iu.harp.server.Server in project twister2 by DSC-SPIDAL.
the class HarpWorker method execute.
@Override
public void execute(Config config, JobAPI.Job job, IWorkerController workerController, IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
int workerID = workerController.getWorkerInfo().getWorkerID();
List<JobMasterAPI.WorkerInfo> workersList = null;
try {
workersList = workerController.getAllWorkers();
} catch (TimeoutException timeoutException) {
LOG.log(Level.SEVERE, timeoutException.getMessage(), timeoutException);
return;
}
LOG.info(String.format("Worker %s starting with %d workers, " + "after waiting for all to start. \n %s", workerID, workersList.size(), workersList.toString()));
JobMasterAPI.WorkerInfo workerInfo = workerController.getWorkerInfo();
// Building Harp Specific parameters
Map<String, Integer> rackToIntegerMap = this.getRackToIntegerMap(workersList);
LinkedList<Integer> nodeRackIDs = new LinkedList<>(rackToIntegerMap.values());
// todo check the suitability
int noOfPhysicalNodes = nodeRackIDs.size();
Map<Integer, List<String>> nodesOfRackMap = this.getNodesOfRackMap(workersList, rackToIntegerMap);
Workers workers = new Workers(nodesOfRackMap, nodeRackIDs, noOfPhysicalNodes, workerID);
DataMap dataMap = new DataMap();
int harpPort = Constant.DEFAULT_WORKER_POART_BASE + workerID;
Server server;
try {
server = new Server(workerInfo.getWorkerIP(), harpPort, new EventQueue(), dataMap, workers);
} catch (Exception e) {
LOG.log(Level.SEVERE, String.format("Failed to start harp server %s:%d " + "on twister worker %s:%d", workerInfo.getWorkerIP(), harpPort, workerInfo.getWorkerIP(), workerInfo.getPort()), e);
throw new RuntimeException("Failed to start Harp Server");
}
SyncClient syncClient = new SyncClient(workers);
LOG.info("Starting Harp Sync client");
syncClient.start();
LOG.info(String.format("Starting harp server on port : %d", harpPort));
server.start();
LOG.info(String.format("Harp server started. %s:%d " + "on twister worker %s:%d", workerInfo.getWorkerIP(), harpPort, workerInfo.getWorkerIP(), workerInfo.getPort()));
try {
LOG.info("Trying master barrier");
doMasterBarrier("start-worker", "handshake", dataMap, workers);
LOG.info("Master barrier done");
} catch (IOException e) {
LOG.log(Level.SEVERE, "Failed to do master barrier", e);
server.stop();
syncClient.stop();
throw new RuntimeException("Failed to do master barrier");
}
// call executeHarp that will be coded by user
this.executeHarp(config, workerID, workerController.getNumberOfWorkers(), workerController, persistentVolume, volatileVolume, dataMap, workers);
// stopping servers, releasing resources
LOG.info("Execution completed. Shutting harp Sync Client down....");
syncClient.stop();
LOG.info("Harp Sync Client stopped.");
LOG.info("Shutting harp server down....");
server.stop(true);
LOG.info("Harp server stopped.");
}
Aggregations