Java Code Examples for org.apache.reef.driver.evaluator.AllocatedEvaluator#submitContextAndTask()

The following examples show how to use org.apache.reef.driver.evaluator.AllocatedEvaluator#submitContextAndTask() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DriverFailOnFail.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public void onNext(final AllocatedEvaluator eval) {

  try {

    LOG.log(Level.INFO, "Submit task: Fail2");

    final Configuration contextConfig = ContextConfiguration.CONF
        .set(ContextConfiguration.IDENTIFIER, "Fail2")
        .build();

    final Configuration taskConfig = TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, "Fail2")
        .set(TaskConfiguration.TASK, FailTaskCall.class)
        .build();

    eval.submitContextAndTask(contextConfig, taskConfig);

  } catch (final BindException ex) {
    LOG.log(Level.WARNING, "Configuration error", ex);
    throw new RuntimeException(ex);
  }
}
 
Example 2
Source File: HelloDriver.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Uses the AllocatedEvaluator to launch a CLR task.
 *
 * @param allocatedEvaluator
 */
void onNextCLR(final AllocatedEvaluator allocatedEvaluator) {
  try {
    allocatedEvaluator.setProcess(clrProcessFactory.newEvaluatorProcess());
    final Configuration contextConfiguration = ContextConfiguration.CONF
        .set(ContextConfiguration.IDENTIFIER, "HelloREEFContext")
        .build();

    final Configuration taskConfiguration = getCLRTaskConfiguration("Hello_From_CLR");

    allocatedEvaluator.submitContextAndTask(contextConfiguration, taskConfiguration);
  } catch (final BindException ex) {
    final String message = "Unable to setup Task or Context configuration.";
    LOG.log(Level.SEVERE, message, ex);
    throw new RuntimeException(message, ex);
  }
}
 
Example 3
Source File: HelloDriver.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Uses the AllocatedEvaluator to launch a JVM task.
 *
 * @param allocatedEvaluator
 */
void onNextJVM(final AllocatedEvaluator allocatedEvaluator) {
  try {
    final Configuration contextConfiguration = ContextConfiguration.CONF
        .set(ContextConfiguration.IDENTIFIER, "HelloREEFContext")
        .build();

    final Configuration taskConfiguration = TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, "HelloREEFTask")
        .set(TaskConfiguration.TASK, HelloTask.class)
        .build();

    allocatedEvaluator.submitContextAndTask(contextConfiguration, taskConfiguration);
  } catch (final BindException ex) {
    final String message = "Unable to setup Task or Context configuration.";
    LOG.log(Level.SEVERE, message, ex);
    throw new RuntimeException(message, ex);
  }
}
 
Example 4
Source File: Driver.java    From reef with Apache License 2.0 4 votes vote down vote up
@Override
public void onNext(final AllocatedEvaluator eval) {

  try {

    taskId = failTaskName + "_" + eval.getId();
    LOG.log(Level.INFO, "Submit task: {0}", taskId);

    final Configuration contextConfig =
        ContextConfiguration.CONF.set(ContextConfiguration.IDENTIFIER, taskId).build();

    ConfigurationModule taskConfig =
        TaskConfiguration.CONF.set(TaskConfiguration.IDENTIFIER, taskId);

    switch (failTaskName) {
    case "FailTask":
      taskConfig = taskConfig.set(TaskConfiguration.TASK, FailTask.class);
      break;
    case "FailTaskCall":
      taskConfig = taskConfig.set(TaskConfiguration.TASK, FailTaskCall.class);
      break;
    case "FailTaskMsg":
      taskConfig = taskConfig
            .set(TaskConfiguration.TASK, FailTaskMsg.class)
            .set(TaskConfiguration.ON_MESSAGE, FailTaskMsg.class);
      break;
    case "FailTaskSuspend":
      taskConfig = taskConfig
            .set(TaskConfiguration.TASK, FailTaskSuspend.class)
            .set(TaskConfiguration.ON_SUSPEND, FailTaskSuspend.class);
      break;
    case "FailTaskStart":
      taskConfig = taskConfig
            .set(TaskConfiguration.TASK, FailTaskStart.class)
            .set(TaskConfiguration.ON_TASK_STARTED, FailTaskStart.class);
      break;
    case "FailTaskStop":
      taskConfig = taskConfig
            .set(TaskConfiguration.TASK, FailTaskStop.class)
            .set(TaskConfiguration.ON_TASK_STOP, FailTaskStop.class)
            .set(TaskConfiguration.ON_CLOSE, FailTaskStop.CloseEventHandler.class);
      break;
    case "FailTaskClose":
      taskConfig = taskConfig
            .set(TaskConfiguration.TASK, FailTaskClose.class)
            .set(TaskConfiguration.ON_CLOSE, FailTaskClose.class);
      break;
    default:
      break;
    }

    eval.submitContextAndTask(contextConfig, taskConfig.build());

  } catch (final BindException ex) {
    LOG.log(Level.WARNING, "Configuration error", ex);
    throw new DriverSideFailure("Configuration error", ex);
  }
}
 
Example 5
Source File: JobDriver.java    From reef with Apache License 2.0 4 votes vote down vote up
@Override
public void onNext(final AllocatedEvaluator eval) {

  LOG.log(Level.INFO, "TIME: Allocated Evaluator {0}", eval.getId());

  final boolean runTask;
  final int nEval;
  final int nTask;

  synchronized (JobDriver.this) {
    runTask = numTasksStarted < numTasks;
    if (runTask) {
      ++numEvaluatorsStarted;
      if (isPiggyback) {
        ++numTasksStarted;
      }
    }
    nEval = numEvaluatorsStarted;
    nTask = numTasksStarted;
  }

  if (runTask) {

    final String contextId = String.format("Context_%06d", nEval);
    LOG.log(Level.INFO, "TIME: Submit Context {0} to Evaluator {1}",
        new Object[]{contextId, eval.getId()});

    try {

      final JavaConfigurationBuilder contextConfigBuilder =
          Tang.Factory.getTang().newConfigurationBuilder();

      contextConfigBuilder.addConfiguration(ContextConfiguration.CONF
          .set(ContextConfiguration.IDENTIFIER, contextId)
          .build());

      contextConfigBuilder.bindNamedParameter(Launch.Delay.class, delayStr);

      if (isPiggyback) {

        final String taskId = String.format("StartTask_%08d", nTask);
        final Configuration taskConfig = getTaskConfiguration(taskId);

        LOG.log(Level.INFO, "TIME: Submit Task {0} to Evaluator {1}",
            new Object[]{taskId, eval.getId()});

        eval.submitContextAndTask(contextConfigBuilder.build(), taskConfig);

      } else {
        eval.submitContext(contextConfigBuilder.build());
      }

    } catch (final BindException ex) {
      LOG.log(Level.SEVERE, "Failed to submit Context to Evaluator: " + eval.getId(), ex);
      throw new RuntimeException(ex);
    }
  } else {
    LOG.log(Level.INFO, "TIME: Close Evaluator {0}", eval.getId());
    eval.close();
  }
}