Search in sources :

Example 1 with Twister2Worker

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);
    }
}
Also used : ISenderToDriver(edu.iu.dsc.tws.api.resource.ISenderToDriver) JobExecutionState(edu.iu.dsc.tws.proto.system.JobExecutionState) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) Twister2Worker(edu.iu.dsc.tws.api.resource.Twister2Worker)

Aggregations

ISenderToDriver (edu.iu.dsc.tws.api.resource.ISenderToDriver)1 Twister2Worker (edu.iu.dsc.tws.api.resource.Twister2Worker)1 WorkerEnvironment (edu.iu.dsc.tws.api.resource.WorkerEnvironment)1 JobExecutionState (edu.iu.dsc.tws.proto.system.JobExecutionState)1