use of edu.iu.dsc.tws.api.resource.Twister2Worker in project twister2 by DSC-SPIDAL.
the class Twister2WorkerStarter method execute.
@Override
public void execute(Config config, JobAPI.Job job, IWorkerController workerController, IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
int workerID = workerController.getWorkerInfo().getWorkerID();
WorkerEnvironment workerEnv = WorkerEnvironment.init(config, job, workerController, persistentVolume, volatileVolume);
String workerClass = job.getWorkerClassName();
Twister2Worker worker;
try {
Object object = ReflectionUtils.newInstance(workerClass);
worker = (Twister2Worker) object;
LOG.info("loaded worker class: " + workerClass);
worker.execute(workerEnv);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
LOG.severe(String.format("failed to load the worker class %s", workerClass));
throw new RuntimeException(e);
}
// If the execute returns without any errors we assume that the job completed properly
if (JobMasterContext.isJobMasterUsed(config) && !job.getDriverClassName().isEmpty()) {
ISenderToDriver senderToDriver = WorkerRuntime.getSenderToDriver();
JobExecutionState.WorkerJobState workerState = JobExecutionState.WorkerJobState.newBuilder().setFailure(false).setJobName(config.getStringValue(Context.JOB_ID)).setWorkerMessage("Worker Completed").build();
senderToDriver.sendToDriver(workerState);
}
}
Aggregations