Java Code Examples for org.apache.reef.driver.context.ActiveContext#submitTask()

The following examples show how to use org.apache.reef.driver.context.ActiveContext#submitTask() . 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: EvaluatorReuseTestDriver.java    From reef with Apache License 2.0 6 votes vote down vote up
private void startTask(final ActiveContext context) {
  if (counter < numberOfIterations) {
    try {
      this.lastMessage = "ECHO-" + counter;
      client.sendMessageToClient(("Submitting iteration " + counter).getBytes(StandardCharsets.UTF_8));
      final String memento = DatatypeConverter.printBase64Binary(this.lastMessage.getBytes(StandardCharsets.UTF_8));
      context.submitTask(TaskConfiguration.CONF
          .set(TaskConfiguration.IDENTIFIER, this.lastMessage)
          .set(TaskConfiguration.TASK, EchoTask.class)
          .set(TaskConfiguration.MEMENTO, memento)
          .build());
      counter += 1;
    } catch (final BindException e) {
      context.close();
      throw new RuntimeException(e);
    }
  } else {
    client.sendMessageToClient("Done. Closing the Context".getBytes(StandardCharsets.UTF_8));
    context.close();
  }
}
 
Example 2
Source File: MultipleCommGroupsDriver.java    From reef with Apache License 2.0 6 votes vote down vote up
private void submitTask(final ActiveContext activeContext, final int groupIndex) {
  final String taskId = taskIds[groupIndex][taskCounter[groupIndex].getAndIncrement()];
  LOG.log(Level.INFO, "Got active context {0}. Submit {1}", new Object[]{activeContext, taskId});
  final Configuration partialTaskConf;
  if (taskId.equals(taskIds[groupIndex][0])) {
    partialTaskConf = TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, taskId)
        .set(TaskConfiguration.TASK, MasterTask.class)
        .build();
  } else {
    partialTaskConf = TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, taskId)
        .set(TaskConfiguration.TASK, SlaveTask.class)
        .build();
  }
  commGroupDriverList.get(groupIndex).addTask(partialTaskConf);
  activeContext.submitTask(groupCommDriver.getTaskConfiguration(partialTaskConf));
}
 
Example 3
Source File: FailDriverDelayedMsg.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public void onNext(final ActiveContext context) {
  LOG.log(Level.INFO, "ENTER: FailDriverDelayedMsg.send(ActiveContext): {0}", context);
  try {
    context.submitTask(TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, "Task_" + context.getId())
        .set(TaskConfiguration.TASK, NoopTask.class)
        .set(TaskConfiguration.ON_MESSAGE, NoopTask.DriverMessageHandler.class)
        .set(TaskConfiguration.ON_SUSPEND, NoopTask.TaskSuspendHandler.class)
        .set(TaskConfiguration.ON_TASK_STOP, NoopTask.TaskStopHandler.class)
        .set(TaskConfiguration.ON_CLOSE, NoopTask.TaskCloseHandler.class)
        .set(TaskConfiguration.ON_SEND_MESSAGE, NoopTask.class)
        .build());
  } catch (final BindException ex) {
    LOG.log(Level.WARNING, "Task configuration error", ex);
    throw new RuntimeException(ex);
  }
}
 
Example 4
Source File: TaskResubmitDriver.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public void onNext(final FailedTask failedTask) {

  LOG.log(Level.INFO, "FailedTask: {0}", failedTask);

  final Throwable ex = failedTask.getReason().get();
  if (!TestUtils.hasCause(ex, SimulatedTaskFailure.class)) {
    final String msg = "Expected SimulatedTaskFailure from " + failedTask.getId();
    LOG.log(Level.SEVERE, msg, ex);
    throw new TaskSideFailure(msg, ex);
  }

  final ActiveContext activeContext = failedTask.getActiveContext().get();
  if (++TaskResubmitDriver.this.failuresSeen <= 1) { // resubmit the task
    activeContext.submitTask(getTaskConfiguration());
  } else { // Close the context
    activeContext.close();
  }
}
 
Example 5
Source File: Scheduler.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Submit a task to the ActiveContext.
 */
public synchronized void submitTask(final ActiveContext context) {
  final TaskEntity task = taskQueue.poll();
  final Integer taskId = task.getId();
  final String command = task.getCommand();

  final Configuration taskConf = TaskConfiguration.CONF
      .set(TaskConfiguration.TASK, ShellTask.class)
      .set(TaskConfiguration.IDENTIFIER, taskId.toString())
      .build();
  final Configuration commandConf = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(Command.class, command)
      .build();

  final Configuration merged = Configurations.merge(taskConf, commandConf);
  context.submitTask(merged);
  runningTasks.add(task);
}
 
Example 6
Source File: HttpShellJobDriver.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Submit a Task that execute the command to a single Evaluator.
 * This method is called from <code>submitTask(cmd)</code>.
 */
private void submit(final ActiveContext context, final String command) {
  try {
    LOG.log(Level.INFO, "Send command {0} to context: {1}", new Object[]{command, context});
    final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
    cb.addConfiguration(
        TaskConfiguration.CONF
            .set(TaskConfiguration.IDENTIFIER, context.getId() + "_task")
            .set(TaskConfiguration.TASK, ShellTask.class)
            .build()
    );
    cb.bindNamedParameter(Command.class, command);
    context.submitTask(cb.build());
  } catch (final BindException ex) {
    LOG.log(Level.SEVERE, "Bad Task configuration for context: " + context.getId(), ex);
    context.close();
    throw new RuntimeException(ex);
  }
}
 
Example 7
Source File: GroupCommServiceInjectionDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(final ActiveContext activeContext) {
  final Configuration paramConf = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(GroupCommServiceInjectionParameter.class, Integer.toString(OFFSET))
      .build();

  if (masterTaskSubmitted.compareAndSet(false, true)) {
    final Configuration masterTaskPartialConf = TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, GroupCommServiceInjectionMasterTask.TASK_ID)
        .set(TaskConfiguration.TASK, GroupCommServiceInjectionMasterTask.class)
        .build();
    commGroupDriver.addTask(masterTaskPartialConf);

    final Configuration masterTaskFinalConf = groupCommDriver.getTaskConfiguration(
        Configurations.merge(paramConf, masterTaskPartialConf));
    activeContext.submitTask(masterTaskFinalConf);

  } else {
    final Configuration slaveTaskPartialConf = TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, GroupCommServiceInjectionSlaveTask.TASK_ID)
        .set(TaskConfiguration.TASK, GroupCommServiceInjectionSlaveTask.class)
        .build();
    commGroupDriver.addTask(slaveTaskPartialConf);

    final Configuration slaveTaskFinalConf = groupCommDriver.getTaskConfiguration(
        Configurations.merge(paramConf, slaveTaskPartialConf));
    activeContext.submitTask(slaveTaskFinalConf);
  }
}
 
Example 8
Source File: StatePassingDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
private void nextPass(final ActiveContext activeContext) {
  try {
    activeContext.submitTask(TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, "StatePassing-" + pass)
        .set(TaskConfiguration.TASK, StatePassingTask.class)
        .build());
    ++pass;
  } catch (final BindException e) {
    throw new RuntimeException(e);
  }
}
 
Example 9
Source File: JobDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(final ActiveContext context) {

  LOG.log(Level.INFO, "TIME: Active Context {0}", context.getId());

  if (isPiggyback) {
    return; // Task already submitted
  }

  final boolean runTask;
  final int nTask;

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

  if (runTask) {
    final String taskId = String.format("StartTask_%08d", nTask);
    LOG.log(Level.INFO, "TIME: Submit Task {0} to Evaluator {1}",
        new Object[]{taskId, context.getEvaluatorId()});
    context.submitTask(getTaskConfiguration(taskId));
  } else {
    context.close();
  }
}
 
Example 10
Source File: JobDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(final CompletedTask task) {

  final ActiveContext context = task.getActiveContext();
  LOG.log(Level.INFO, "TIME: Completed Task {0} on Evaluator {1}",
      new Object[]{task.getId(), context.getEvaluatorId()});

  final boolean runTask;
  final int nTask;
  synchronized (JobDriver.this) {
    runTask = numTasksStarted < numTasks;
    if (runTask) {
      ++numTasksStarted;
    }
    nTask = numTasksStarted;
  }

  if (runTask) {
    final String taskId = String.format("Task_%08d", nTask);
    LOG.log(Level.INFO, "TIME: Submit Task {0} to Evaluator {1}",
        new Object[]{taskId, context.getEvaluatorId()});
    context.submitTask(getTaskConfiguration(taskId));
  } else {
    LOG.log(Level.INFO, "TIME: Close Evaluator {0}", context.getEvaluatorId());
    context.close();
  }
}
 
Example 11
Source File: OutputServiceDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(final ActiveContext activeContext) {
  LOG.log(Level.INFO,
      "Submitting OutputServiceREEF task to AllocatedEvaluator: {0}",
      activeContext.getEvaluatorDescriptor());
  final Configuration taskConfiguration = TaskConfiguration.CONF
      .set(TaskConfiguration.IDENTIFIER, "Task-" + taskId.getAndIncrement())
      .set(TaskConfiguration.TASK, OutputServiceTask.class)
      .build();
  activeContext.submitTask(taskConfiguration);
}
 
Example 12
Source File: BroadcastDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void onNext(final FailedTask failedTask) {

  LOG.log(Level.FINE, "Got failed Task: {0}", failedTask.getId());

  final ActiveContext activeContext = failedTask.getActiveContext().get();
  final Configuration partialTaskConf = Tang.Factory.getTang()
      .newConfigurationBuilder(
          TaskConfiguration.CONF
              .set(TaskConfiguration.IDENTIFIER, failedTask.getId())
              .set(TaskConfiguration.TASK, SlaveTask.class)
              .build(),
          PoisonedConfiguration.TASK_CONF
              .set(PoisonedConfiguration.CRASH_PROBABILITY, "0")
              .set(PoisonedConfiguration.CRASH_TIMEOUT, "1")
              .build())
      .bindNamedParameter(ModelDimensions.class, "" + dimensions)
      .build();

  // Do not add the task back:
  // allCommGroup.addTask(partialTaskConf);

  final Configuration taskConf = groupCommDriver.getTaskConfiguration(partialTaskConf);
  LOG.log(Level.FINER, "Submit SlaveTask conf: {0}", confSerializer.toString(taskConf));

  activeContext.submitTask(taskConf);
}
 
Example 13
Source File: SuspendDriver.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void onNext(final ActiveContext context) {
  LOG.log(Level.INFO, "Active Context: {0}", context.getId());
  try {
    context.submitTask(TaskConfiguration.CONF
        .set(TaskConfiguration.IDENTIFIER, context.getId() + "_task")
        .set(TaskConfiguration.TASK, SuspendTestTask.class)
        .set(TaskConfiguration.ON_SUSPEND, SuspendTestTask.SuspendHandler.class)
        .set(TaskConfiguration.ON_SEND_MESSAGE, SuspendTestTask.class)
        .build());
  } catch (final BindException ex) {
    LOG.log(Level.SEVERE, "Bad Task configuration for context: " + context.getId(), ex);
    throw new RuntimeException(ex);
  }
}
 
Example 14
Source File: LineCounter.java    From reef with Apache License 2.0 4 votes vote down vote up
@Override
public void onNext(final ActiveContext activeContext) {

  final String contextId = activeContext.getId();
  LOG.log(Level.FINER, "Context active: {0}", contextId);

  if (dataLoadingService.isDataLoadedContext(activeContext)) {

    final String lcContextId = "LineCountCtxt-" + ctrlCtxIds.getAndIncrement();
    LOG.log(Level.FINEST, "Submit LineCount context {0} to: {1}",
        new Object[]{lcContextId, contextId});

    final Configuration poisonedConfiguration = PoisonedConfiguration.CONTEXT_CONF
        .set(PoisonedConfiguration.CRASH_PROBABILITY, "0.4")
        .set(PoisonedConfiguration.CRASH_TIMEOUT, "1")
        .build();

    activeContext.submitContext(Tang.Factory.getTang()
        .newConfigurationBuilder(poisonedConfiguration,
            ContextConfiguration.CONF.set(ContextConfiguration.IDENTIFIER, lcContextId).build())
        .build());

  } else if (activeContext.getId().startsWith("LineCountCtxt")) {

    final String taskId = "LineCountTask-" + ctrlCtxIds.getAndIncrement();
    LOG.log(Level.FINEST, "Submit LineCount task {0} to: {1}", new Object[]{taskId, contextId});

    try {
      activeContext.submitTask(TaskConfiguration.CONF
          .set(TaskConfiguration.IDENTIFIER, taskId)
          .set(TaskConfiguration.TASK, LineCountingTask.class)
          .build());
    } catch (final BindException ex) {
      LOG.log(Level.SEVERE, "Configuration error in " + contextId, ex);
      throw new RuntimeException("Configuration error in " + contextId, ex);
    }
  } else {
    LOG.log(Level.FINEST, "Line count Compute Task {0} -- Closing", contextId);
    activeContext.close();
  }
}
 
Example 15
Source File: BGDDriver.java    From reef with Apache License 2.0 4 votes vote down vote up
@Override
public void onNext(final FailedTask failedTask) {

  final String failedTaskId = failedTask.getId();

  LOG.log(Level.WARNING, "Got failed Task: " + failedTaskId);

  if (jobRunning(failedTaskId)) {

    final ActiveContext activeContext = failedTask.getActiveContext().get();
    final Configuration partialTaskConf = getSlaveTaskConfiguration(failedTaskId);

    // Do not add the task back:
    // allCommGroup.addTask(partialTaskConf);

    final Configuration taskConf = groupCommDriver.getTaskConfiguration(partialTaskConf);
    LOG.log(Level.FINEST, "Submit SlaveTask conf: {0}", confSerializer.toString(taskConf));

    activeContext.submitTask(taskConf);
  }
}
 
Example 16
Source File: MockApplication.java    From reef with Apache License 2.0 4 votes vote down vote up
void submitTask(final ActiveContext context, final String identifier) {
  context.submitTask(TaskConfiguration.CONF
      .set(TaskConfiguration.IDENTIFIER, identifier)
      .set(TaskConfiguration.TASK, DummyTestTask.class)
      .build());
}