use of edu.iu.dsc.tws.api.resource.IReceiverFromDriver in project twister2 by DSC-SPIDAL.
the class JobMasterClientExample method simulateClient.
/**
* a method to simulate JMWorkerAgent running in workers
*/
public static void simulateClient(Config config, JobAPI.Job job, int workerID) {
String workerIP = JMWorkerController.convertStringToIP("localhost").getHostAddress();
int workerPort = 10000 + (int) (Math.random() * 10000);
JobMasterAPI.NodeInfo nodeInfo = NodeInfoUtils.createNodeInfo("node.ip", "rack01", null);
JobAPI.ComputeResource computeResource = job.getComputeResource(0);
Map<String, Integer> additionalPorts = generateAdditionalPorts(config, workerPort);
JobMasterAPI.WorkerInfo workerInfo = WorkerInfoUtils.createWorkerInfo(workerID, workerIP, workerPort, nodeInfo, computeResource, additionalPorts);
int restartCount = K8sWorkerUtils.getAndInitRestartCount(config, job.getJobId(), workerInfo);
long start = System.currentTimeMillis();
WorkerRuntime.init(config, job, workerInfo, restartCount);
long delay = System.currentTimeMillis() - start;
LOG.severe("worker-" + workerID + " startupDelay " + delay);
IWorkerStatusUpdater statusUpdater = WorkerRuntime.getWorkerStatusUpdater();
IWorkerController workerController = WorkerRuntime.getWorkerController();
ISenderToDriver senderToDriver = WorkerRuntime.getSenderToDriver();
WorkerRuntime.addReceiverFromDriver(new IReceiverFromDriver() {
@Override
public void driverMessageReceived(Any anyMessage) {
LOG.info("Received message from IDriver: \n" + anyMessage);
senderToDriver.sendToDriver(anyMessage);
}
});
try {
List<JobMasterAPI.WorkerInfo> workerList = workerController.getAllWorkers();
LOG.info("All workers joined... IDs: " + getIDs(workerList));
} catch (TimeoutException timeoutException) {
LOG.log(Level.SEVERE, timeoutException.getMessage(), timeoutException);
return;
}
// wait
sleeeep(2 * 1000);
try {
workerController.waitOnBarrier();
LOG.info("All workers reached the barrier. Proceeding.......");
} catch (TimeoutException timeoutException) {
LOG.log(Level.SEVERE, timeoutException.getMessage(), timeoutException);
}
// int id = job.getNumberOfWorkers() - 1;
// JobMasterAPI.WorkerInfo info = workerController.getWorkerInfoForID(id);
// LOG.info("WorkerInfo for " + id + ": \n" + info);
// wait up to 3sec
sleeeep((long) (Math.random() * 10 * 1000));
// start the worker
try {
throwException(workerID);
} catch (Throwable t) {
// update worker status to FAILED
statusUpdater.updateWorkerStatus(JobMasterAPI.WorkerState.FAILED);
WorkerRuntime.close();
// System.exit(1);
throw t;
}
statusUpdater.updateWorkerStatus(JobMasterAPI.WorkerState.COMPLETED);
WorkerRuntime.close();
System.out.println("Client has finished the computation. Client exiting.");
}
Aggregations