org.apache.reef.util.Optional Java Examples

The following examples show how to use org.apache.reef.util.Optional. 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: HeartBeatManager.java    From reef with Apache License 2.0 6 votes vote down vote up
private EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto getEvaluatorHeartbeatProto(
    final ReefServiceProtos.EvaluatorStatusProto evaluatorStatusProto,
    final Iterable<ReefServiceProtos.ContextStatusProto> contextStatusProtos,
    final Optional<ReefServiceProtos.TaskStatusProto> taskStatusProto) {

  final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto.Builder builder =
      EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto.newBuilder()
          .setTimestamp(System.currentTimeMillis())
          .setEvaluatorStatus(evaluatorStatusProto);

  for (final ReefServiceProtos.ContextStatusProto contextStatusProto : contextStatusProtos) {
    builder.addContextStatus(contextStatusProto);
  }

  if (taskStatusProto.isPresent()) {
    builder.setTaskStatus(taskStatusProto.get());
  }

  return builder.build();
}
 
Example #2
Source File: EvaluatorResourceManagerErrorHandler.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public void onNext(final RemoteMessage<ReefServiceProtos.RuntimeErrorProto> runtimeErrorProtoRemoteMessage) {
  final ReefServiceProtos.RuntimeErrorProto runtimeErrorProto = runtimeErrorProtoRemoteMessage.getMessage();
  final FailedRuntime error = new FailedRuntime(runtimeErrorProto);
  final String evaluatorId = error.getId();
  LOG.log(Level.WARNING, "Runtime error: " + error);

  final EvaluatorException evaluatorException = error.getReason().isPresent() ?
      new EvaluatorException(evaluatorId, error.getReason().get()) :
      new EvaluatorException(evaluatorId, "Runtime error");

  final Optional<EvaluatorManager> evaluatorManager = this.evaluators.get(evaluatorId);
  if (evaluatorManager.isPresent()) {
    evaluatorManager.get().onEvaluatorException(evaluatorException);
  } else {
    if (this.evaluators.wasClosed(evaluatorId)) {
      LOG.log(Level.WARNING, "Evaluator [" + evaluatorId + "] has raised exception after it was closed.");
    } else {
      LOG.log(Level.WARNING, "Unknown evaluator runtime error: " + error);
    }
  }
}
 
Example #3
Source File: GRPCDriverClientService.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public void failedTaskHandler(final TaskInfo request, final StreamObserver<Void> responseObserver) {
  try (ObserverCleanup cleanup = ObserverCleanup.of(responseObserver)) {
    LOG.log(Level.INFO, "Failed task id {0}", request.getTaskId());
    ActiveContextBridge context = request.hasContext() ?
        addContextIfMissing(request.getContext()) : null;
    this.clientDriverDispatcher.get().dispatch(
        new FailedTask(
            request.getTaskId(),
            request.getException().getMessage(),
            Optional.of(request.getException().getName()),
            request.getException().getData().isEmpty() ?
                Optional.<Throwable>of(new EvaluatorException(request.getException().getMessage())) :
                this.exceptionCodec.fromBytes(request.getException().getData().toByteArray()),
            Optional.<byte[]>empty(),
            Optional.<ActiveContext>ofNullable(context)));
  }
}
 
Example #4
Source File: AzureBatchEvaluatorShimManager.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * This method is invoked by the RemoteManager when a message from the evaluator shim is received.
 *
 * @param statusMessage the message from the evaluator shim indicating that the shim has started and is ready to
 *                      start the evaluator process.
 */
@Override
public void onNext(final RemoteMessage<EvaluatorShimProtocol.EvaluatorShimStatusProto> statusMessage) {

  EvaluatorShimProtocol.EvaluatorShimStatusProto message = statusMessage.getMessage();
  String containerId = message.getContainerId();
  String remoteId = message.getRemoteIdentifier();

  LOG.log(Level.INFO, "Got a status message from evaluator shim = {0} with containerId = {1} and status = {2}.",
      new String[]{remoteId, containerId, message.getStatus().toString()});

  if (message.getStatus() != EvaluatorShimProtocol.EvaluatorShimStatus.ONLINE) {
    LOG.log(Level.SEVERE, "Unexpected status returned from the evaluator shim: {0}. Ignoring the message.",
        message.getStatus().toString());
    return;
  }

  this.onResourceAllocated(containerId, remoteId, Optional.<CloudTask>empty());
}
 
Example #5
Source File: AllocatedEvaluatorImpl.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Submit Context, Service and Task with configuration strings.
 * This method should be called from bridge and the configuration strings are
 * serialized at .Net side
 * @param contextConfiguration
 * @param evaluatorConfiguration
 * @param serviceConfiguration
 * @param taskConfiguration
 */
private void launchWithConfigurationString(
    final String evaluatorConfiguration,
    final String contextConfiguration,
    final Optional<String> serviceConfiguration,
    final Optional<String> taskConfiguration) {
  try (LoggingScope lb = loggingScopeFactory.evaluatorLaunch(this.getId())) {
    final Configuration submissionEvaluatorConfiguration =
        makeEvaluatorConfiguration(
            contextConfiguration,
            Optional.ofNullable(evaluatorConfiguration),
            serviceConfiguration,
            taskConfiguration);

    resourceBuildAndLaunch(submissionEvaluatorConfiguration);
  }
}
 
Example #6
Source File: EvaluatorContext.java    From reef with Apache License 2.0 6 votes vote down vote up
public EvaluatorContext(final String contextIdentifier,
                        final String evaluatorIdentifier,
                        final EvaluatorDescriptor evaluatorDescriptor,
                        final Optional<String> parentID,
                        final ConfigurationSerializer configurationSerializer,
                        final ContextControlHandler contextControlHandler,
                        final EvaluatorMessageDispatcher messageDispatcher,
                        final ExceptionCodec exceptionCodec,
                        final ContextRepresenters contextRepresenters) {

  this.contextIdentifier = contextIdentifier;
  this.evaluatorIdentifier = evaluatorIdentifier;
  this.evaluatorDescriptor = evaluatorDescriptor;
  this.parentID = parentID;
  this.configurationSerializer = configurationSerializer;
  this.contextControlHandler = contextControlHandler;
  this.exceptionCodec = exceptionCodec;
  this.contextRepresenters = contextRepresenters;

  LOG.log(Level.FINE, "Instantiated 'EvaluatorContext'");
}
 
Example #7
Source File: GRPCDriverService.java    From reef with Apache License 2.0 6 votes vote down vote up
@Override
public void shutdown(
    final ShutdownRequest request,
    final StreamObserver<Void> responseObserver) {
  try (ObserverCleanup cleanup = ObserverCleanup.of(responseObserver)) {
    LOG.log(Level.INFO, "driver shutdown");
    if (request.hasException()) {
      final Optional<Throwable> exception = parseException(request.getException());
      if (exception.isPresent()) {
        LOG.log(Level.INFO, "driver exception", exception.get());
        GRPCDriverService.this.clock.stop(exception.get());
      } else {
        // exception that cannot be parsed in java
        GRPCDriverService.this.clock.stop(
            new NonSerializableException(
                request.getException().getMessage(),
                request.getException().getData().toByteArray()));
      }
    } else {
      LOG.log(Level.INFO, "clean shutdown");
      GRPCDriverService.this.clock.stop();
    }
  }
}
 
Example #8
Source File: ContextRuntime.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Spawns a new context without services of its own.
 * <p>
 * The new context will have a serviceInjector that is created by forking the one in this object. The
 * contextConfiguration is used to fork the contextInjector from that new serviceInjector.
 *
 * @param contextConfiguration the new context's context (local) Configuration.
 * @return a child context.
 * @throws ContextClientCodeException If the context can't be instantiate due to user code / configuration issues.
 * @throws IllegalStateException      If this method is called when there is either a task or child context already
 *                                    present.
 */
ContextRuntime spawnChildContext(
    final Configuration contextConfiguration) throws ContextClientCodeException {

  synchronized (this.contextLifeCycle) {

    if (this.task.isPresent()) {
      throw new IllegalStateException(
          "Attempting to to spawn a child context while a Task with id '" +
              this.task.get().getId() + "' is running.");
    }

    if (this.childContext.isPresent()) {
      throw new IllegalStateException(
          "Attempting to spawn a child context on a context that is not the topmost active context");
    }

    final Injector childServiceInjector = this.serviceInjector.forkInjector();
    final ContextRuntime newChildContext =
        new ContextRuntime(childServiceInjector, contextConfiguration, Optional.of(this));

    this.childContext = Optional.of(newChildContext);
    return newChildContext;
  }
}
 
Example #9
Source File: CommandBuilderTests.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void windowsCommandBuilderDriverTest() {
  JobSubmissionEvent event = mock(JobSubmissionEvent.class);

  Optional<Integer> memory = Optional.of(100);
  when(event.getDriverMemory()).thenReturn(memory);

  String actual = this.windowsCommandBuilder.buildDriverCommand(event);
  String expected = "powershell.exe /c \"Add-Type -AssemblyName System.IO.Compression.FileSystem;  " +
      "[System.IO.Compression.ZipFile]::ExtractToDirectory(\\\"$env:AZ_BATCH_TASK_WORKING_DIR\\local.jar\\\", " +
      "\\\"$env:AZ_BATCH_TASK_WORKING_DIR\\reef\\\");  {{JAVA_HOME}}/bin/java -Xmx100m -XX:PermSize=128m " +
      "-XX:MaxPermSize=128m -ea -classpath " +
      "'c:\\driverpath1;c:\\driverpath2;reef/local/*;reef/global/*;driverclasspathsuffix' " +
      "-Dproc_reef org.apache.reef.runtime.common.REEFLauncher reef/local/driver.conf\";";
  Assert.assertEquals(expected, actual);
}
 
Example #10
Source File: HeartBeatManager.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Called with a specific ContextStatus that must be delivered to the driver.
 */
public synchronized void sendContextStatus(
    final ReefServiceProtos.ContextStatusProto contextStatusProto) {

  // TODO[JIRA REEF-833]: Write a test that verifies correct order of heartbeats.
  final Collection<ReefServiceProtos.ContextStatusProto> contextStatusList = new ArrayList<>();
  contextStatusList.add(contextStatusProto);
  contextStatusList.addAll(this.contextManager.get().getContextStatusCollection());

  final EvaluatorRuntimeProtocol.EvaluatorHeartbeatProto heartbeatProto =
      this.getEvaluatorHeartbeatProto(
          this.evaluatorRuntime.get().getEvaluatorStatus(),
          contextStatusList, Optional.<ReefServiceProtos.TaskStatusProto>empty());

  this.sendHeartBeat(heartbeatProto);
}
 
Example #11
Source File: DefaultVortexMaster.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Add a new tasklet to pendingTasklets.
 */
@Override
public <TInput, TOutput> VortexFuture<TOutput>
    enqueueTasklet(final VortexFunction<TInput, TOutput> function, final TInput input,
                   final Optional<FutureCallback<TOutput>> callback) {
  // TODO[REEF-500]: Simple duplicate Vortex Tasklet launch.
  final VortexFuture<TOutput> vortexFuture;
  final int id = taskletIdCounter.getAndIncrement();
  if (callback.isPresent()) {
    vortexFuture = new VortexFuture<>(executor, this, id, callback.get());
  } else {
    vortexFuture = new VortexFuture<>(executor, this, id);
  }

  final Tasklet tasklet = new Tasklet<>(id, Optional.<Integer>empty(), function, input, vortexFuture);
  putDelegate(Collections.singletonList(tasklet), vortexFuture);
  this.pendingTasklets.addLast(tasklet);

  return vortexFuture;
}
 
Example #12
Source File: AllocatedEvaluatorImpl.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Make configuration for evaluator.
 * @param contextConfiguration
 * @param serviceConfiguration
 * @param taskConfiguration
 * @return Configuration
 */
private Configuration makeEvaluatorConfiguration(final Configuration contextConfiguration,
                                                 final Optional<Configuration> serviceConfiguration,
                                                 final Optional<Configuration> taskConfiguration) {

  final String contextConfigurationString = this.configurationSerializer.toString(contextConfiguration);

  final Optional<String> taskConfigurationString;
  if (taskConfiguration.isPresent()) {
    taskConfigurationString = Optional.of(this.configurationSerializer.toString(taskConfiguration.get()));
  } else {
    taskConfigurationString = Optional.empty();
  }

  final Optional<Configuration> mergedServiceConfiguration = makeRootServiceConfiguration(serviceConfiguration);
  if (mergedServiceConfiguration.isPresent()) {
    final String serviceConfigurationString = this.configurationSerializer.toString(mergedServiceConfiguration.get());
    return makeEvaluatorConfiguration(contextConfigurationString, Optional.<String>empty(),
        Optional.of(serviceConfigurationString), taskConfigurationString);
  } else {
    return makeEvaluatorConfiguration(
        contextConfigurationString, Optional.<String>empty(), Optional.<String>empty(), taskConfigurationString);
  }
}
 
Example #13
Source File: FailedEvaluatorBridge.java    From reef with Apache License 2.0 5 votes vote down vote up
public FailedEvaluatorBridge(
    final String id,
    final EvaluatorException evaluatorException,
    final List<FailedContext> failedContextList,
    final Optional<FailedTask> failedTask) {
  this.id = id;
  this.evaluatorException = evaluatorException;
  this.failedContextList = failedContextList;
  this.failedTask = failedTask;
}
 
Example #14
Source File: RemoteNodeManager.java    From reef with Apache License 2.0 5 votes vote down vote up
void onResourceRequest(final ResourceRequestEvent resourceRequestEvent) {
  final Optional<String> node = selectNode(resourceRequestEvent);
  final String nodeId;

  if (node.isPresent()) {
    nodeId = node.get();
  } else {
    // Allocate new container
    nodeId = this.getNode() + ":" + String.valueOf(sshPortNum);
  }

  final String processID = nodeId + "-" + String.valueOf(System.currentTimeMillis());
  final File processFolder = new File(this.rootFolder, processID);

  final SshProcessContainer sshProcessContainer = new SshProcessContainer(errorHandlerRID, nodeId, processID,
      processFolder, resourceRequestEvent.getMemorySize().get(), resourceRequestEvent.getVirtualCores().get(),
      null, this.fileNames, this.nodeFolder, this.processObserver, this.containerThreads);

  this.containers.put(processID, sshProcessContainer);

  final ResourceAllocationEvent alloc = ResourceEventImpl.newAllocationBuilder()
      .setIdentifier(processID)
      .setNodeId(nodeId)
      .setResourceMemory(resourceRequestEvent.getMemorySize().get())
      .setVirtualCores(resourceRequestEvent.getVirtualCores().get())
      .setRuntimeName("STANDALONE")
      .build();
  reefEventHandlers.onResourceAllocation(alloc);

  // set the status as RUNNING.
  updateRuntimeStatus();
}
 
Example #15
Source File: ContainerManager.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the rack where to allocate the container, selected from the list of
 * preferred rack names. If the list is empty, and there's space in the default
 * rack, then the default rack is returned. The relax locality semantic is
 * enabled if the list of rack names contains '/*', otherwise relax locality
 * is considered disabled.
 *
 * @param rackNames the list of preferred racks.
 * @return the rack name where to allocate the container.
 */
private Optional<String> getPreferredRack(final List<String> rackNames) {

  for (final String rackName : getRackNamesOrDefault(rackNames)) {

    // if it does not end with the any modifier, then we should do an exact match
    if (!rackName.endsWith(Constants.ANY_RACK)) {
      if (freeNodesPerRack.containsKey(rackName) && freeNodesPerRack.get(rackName).size() > 0) {
        return Optional.of(rackName);
      }
    } else {

      // if ends with the any modifier, we do a prefix match
      for (final String possibleRackName : this.availableRacks) {

        // remove the any modifier
        final String newRackName = rackName.substring(0, rackName.length() - 1);

        if (possibleRackName.startsWith(newRackName) &&
            this.freeNodesPerRack.get(possibleRackName).size() > 0) {
          return Optional.of(possibleRackName);
        }
      }
    }
  }

  return Optional.empty();
}
 
Example #16
Source File: DefaultVortexMaster.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Add aggregate-able Tasklets to pendingTasklets.
 */
@Override
public <TInput, TOutput> VortexAggregateFuture<TInput, TOutput>
    enqueueTasklets(final VortexAggregateFunction<TOutput> aggregateFunction,
                    final VortexFunction<TInput, TOutput> vortexFunction,
                    final VortexAggregatePolicy policy,
                    final List<TInput> inputs,
                    final Optional<FutureCallback<AggregateResult<TInput, TOutput>>> callback) {
  final int aggregateFunctionId = aggregateIdCounter.getAndIncrement();
  aggregateFunctionRepository.put(aggregateFunctionId, aggregateFunction, policy);
  final List<Tasklet> tasklets = new ArrayList<>(inputs.size());
  final Map<Integer, TInput> taskletIdInputMap = new HashMap<>(inputs.size());

  for (final TInput input : inputs) {
    taskletIdInputMap.put(taskletIdCounter.getAndIncrement(), input);
  }

  final VortexAggregateFuture<TInput, TOutput> vortexAggregateFuture;
  if (callback.isPresent()) {
    vortexAggregateFuture = new VortexAggregateFuture<>(executor, taskletIdInputMap, callback.get());
  } else {
    vortexAggregateFuture = new VortexAggregateFuture<>(executor, taskletIdInputMap, null);
  }

  for (final Map.Entry<Integer, TInput> taskletIdInputEntry : taskletIdInputMap.entrySet()) {
    final Tasklet tasklet = new Tasklet<>(taskletIdInputEntry.getKey(), Optional.of(aggregateFunctionId),
        vortexFunction, taskletIdInputEntry.getValue(), vortexAggregateFuture);
    tasklets.add(tasklet);
    pendingTasklets.addLast(tasklet);
  }

  putDelegate(tasklets, vortexAggregateFuture);
  return vortexAggregateFuture;
}
 
Example #17
Source File: ResourceEventImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
private ResourceEventImpl(final Builder builder) {
  this.identifier = BuilderUtils.notNull(builder.identifier);
  this.resourceMemory = builder.recovery ? builder.resourceMemory : BuilderUtils.notNull(builder.resourceMemory);
  this.nodeId = builder.recovery ? builder.nodeId : BuilderUtils.notNull(builder.nodeId);
  this.virtualCores = Optional.ofNullable(builder.virtualCores);
  this.rackName = Optional.ofNullable(builder.rackName);
  this.runtimeName = BuilderUtils.notNull(builder.runtimeName);
}
 
Example #18
Source File: RandomSchedulingPolicy.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @param tasklet to schedule
 * @return a random worker
 */
@Override
public Optional<String> trySchedule(final Tasklet tasklet) {
  if (idList.isEmpty()) {
    return Optional.empty();
  } else {
    final int index = rand.nextInt(idList.size());
    return Optional.of(idList.get(index));
  }
}
 
Example #19
Source File: AzureBatchEvaluatorShimManager.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * This method is invoked when the Azure Batch runtime is notified that a pending resource request has been
 * fulfilled. It could happen because of two reasons:
 *    1. The driver receives a message from the evaluator shim indicating it has successfully started.
 *    2. {@link AzureBatchTaskStatusAlarmHandler} detects that the evaluator shim failed before sending the status
 *       message.
 *
 * @param containerId id of the container.
 * @param remoteId remote address for the allocated container.
 * @param cloudTask Azure Batch task which corresponds to the container.
 */
public void onResourceAllocated(final String containerId,
                                final String remoteId,
                                final Optional<CloudTask> cloudTask) {
  ResourceRequestEvent resourceRequestEvent = this.outstandingResourceRequests.remove(containerId);

  if (resourceRequestEvent == null) {
    LOG.log(Level.WARNING, "No outstanding resource request found for container id = {0}.", containerId);
  } else {
    this.outstandingResourceRequestCount.decrementAndGet();

    // We would expect the Azure Batch task to be in 'RUNNING' state. If it is in
    // 'COMPLETED' state, it cannot receiver instructions and thus by definition
    // has failed.
    if (cloudTask.isPresent() && TaskState.COMPLETED.equals(cloudTask.get().state())) {
      this.failedResources.put(containerId, cloudTask.get());
    }

    LOG.log(Level.FINEST, "Notifying REEF of a new node: {0}", remoteId);
    this.reefEventHandlers.onNodeDescriptor(NodeDescriptorEventImpl.newBuilder()
        .setIdentifier(RemoteIdentifierParser.parseNodeId(remoteId))
        .setHostName(RemoteIdentifierParser.parseIp(remoteId))
        .setPort(RemoteIdentifierParser.parsePort(remoteId))
        .setMemorySize(resourceRequestEvent.getMemorySize().get())
        .build());

    LOG.log(Level.FINEST, "Triggering a new ResourceAllocationEvent for remoteId = {0}.", remoteId);
    this.reefEventHandlers.onResourceAllocation(
        ResourceEventImpl.newAllocationBuilder()
            .setIdentifier(containerId)
            .setNodeId(RemoteIdentifierParser.parseNodeId(remoteId))
            .setResourceMemory(resourceRequestEvent.getMemorySize().get())
            .setVirtualCores(resourceRequestEvent.getVirtualCores().get())
            .setRuntimeName(RuntimeIdentifier.RUNTIME_NAME)
            .build());
  }

  this.updateRuntimeStatus();
}
 
Example #20
Source File: WatcherAvroUtil.java    From reef with Apache License 2.0 5 votes vote down vote up
private static ByteBuffer unwrapOptionalByteArray(final Optional<byte[]> optionalByteArray) {
  if (optionalByteArray.isPresent()) {
    return ByteBuffer.wrap(optionalByteArray.get());
  }

  return null;
}
 
Example #21
Source File: DriverStatusManager.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @param exception the exception that ended the Driver, if any.
 * @return message to be sent to the client at the end of the job.
 */
private ReefServiceProtos.JobStatusProto getJobEndingMessage(final Optional<Throwable> exception) {
  if (exception.isPresent()) {
    return ReefServiceProtos.JobStatusProto.newBuilder()
        .setIdentifier(this.jobIdentifier)
        .setState(ReefServiceProtos.State.FAILED)
        .setException(ByteString.copyFrom(this.exceptionCodec.toBytes(exception.get())))
        .build();
  } else {
    return ReefServiceProtos.JobStatusProto.newBuilder()
        .setIdentifier(this.jobIdentifier)
        .setState(ReefServiceProtos.State.DONE)
        .build();
  }
}
 
Example #22
Source File: GRPCDriverClientService.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public void driverRestartFailedEvaluatorHandler(
    final EvaluatorInfo request,
    final StreamObserver<Void> responseObserver) {
  try (ObserverCleanup cleanup = ObserverCleanup.of(responseObserver)) {
    this.clientDriverDispatcher.get().dispatchRestart(new FailedEvaluatorBridge(
        request.getEvaluatorId(),
        new EvaluatorException(request.getFailure() != null ?
            request.getFailure().getMessage() : "restart failed"),
        Lists.<FailedContext>newArrayList(),
        Optional.<FailedTask>empty()));
  }
}
 
Example #23
Source File: LoggingScopeImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * A constructor of ReefLoggingScope. It starts the timer and logs the msg
 *
 * @param logger
 * @param msg
 * @param params
 */
LoggingScopeImpl(final Logger logger, final Level logLevel, final String msg, final Object[] params) {
  this.logger = logger;
  this.logLevel = logLevel;
  this.msg = msg;
  this.params = params;
  stopWatch.start();
  this.optionalParams = Optional.ofNullable(params);

  if (logger.isLoggable(logLevel)) {
    final StringBuilder sb = new StringBuilder();
    log(sb.append(START_PREFIX).append(msg).toString());
  }
}
 
Example #24
Source File: FailedContextImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<String> getParentId() {
  if (this.getParentContext().isPresent()) {
    return Optional.of(this.getParentContext().get().getId());
  } else {
    return Optional.empty();
  }
}
 
Example #25
Source File: ContextManager.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @return the TaskStatusProto of the currently running task, if there is any
 */
public Optional<ReefServiceProtos.TaskStatusProto> getTaskStatus() {
  synchronized (this.contextStack) {
    if (this.contextStack.isEmpty()) {
      throw new RuntimeException(
          "Asked for a Task status while there isn't even a context running.");
    }
    return this.contextStack.peek().getTaskStatus();
  }
}
 
Example #26
Source File: RootContextLauncher.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
RootContextLauncher(@Parameter(RootContextConfiguration.class) final String rootContextConfiguration,
                    final Injector injector, final ConfigurationSerializer configurationSerializer)
    throws IOException, BindException {
  this.injector = injector;
  this.configurationSerializer = configurationSerializer;
  this.rootContextConfiguration = this.configurationSerializer.fromString(rootContextConfiguration);
  this.rootServiceConfiguration = Optional.empty();
  this.initialTaskConfiguration = Optional.empty();
}
 
Example #27
Source File: FailedEvaluatorImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
FailedEvaluatorImpl(final EvaluatorException ex,
                    final List<FailedContext> ctx,
                    final Optional<FailedTask> task,
                    final String id) {
  this.ex = ex;
  this.ctx = ctx;
  this.task = task;
  this.id = id;
}
 
Example #28
Source File: LocalClasspathProvider.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @return the path to "JAVA_HOME", if that is set. Optional.empty(), else.
 */
private static Optional<Path> getJavaHome() {
  final Optional<String> javaHome = getEnv("JAVA_HOME");

  if (javaHome.isPresent()) {
    final File javaHomeFile = new File(javaHome.get());
    if (javaHomeFile.exists()) {
      return Optional.of(javaHomeFile.toPath());
    }
  }
  return Optional.empty();
}
 
Example #29
Source File: JobLauncher.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
public static void shutdown() {
  // Trigger driver shutdown afterwards
  driverRPCServer.send(ControlMessage.ClientToDriverMessage.newBuilder()
    .setType(ControlMessage.ClientToDriverMessageType.DriverShutdown).build());
  // Wait for driver to naturally finish
  synchronized (driverLauncher) {
    while (!driverLauncher.getStatus().isDone()) {
      try {
        LOG.info("Wait for the driver to finish");
        driverLauncher.wait();
      } catch (final InterruptedException e) {
        LOG.warn(INTERRUPTED, e);
        // clean up state...
        Thread.currentThread().interrupt();
      }
    }
    LOG.info("Driver terminated");
  }

  // Close everything that's left
  driverRPCServer.shutdown();
  driverLauncher.close();
  isSetUp = false;
  final Optional<Throwable> possibleError = driverLauncher.getStatus().getError();
  if (possibleError.isPresent()) {
    throw new RuntimeException(possibleError.get());
  } else if (jobDoneLatch.getCount() > 0) {
    LOG.info("Job cancelled");
  } else {
    LOG.info("Job successfully completed");
  }
}
 
Example #30
Source File: FailedContextBridge.java    From reef with Apache License 2.0 5 votes vote down vote up
public FailedContextBridge(
    final String contextId,
    final String evaluatorId,
    final String message,
    final EvaluatorDescriptor evaluatorDescriptor,
    final Optional<ActiveContext> parentContext,
    final Optional<Throwable> reason) {
  this.contextId = contextId;
  this.evaluatorId = evaluatorId;
  this.message = message;
  this.evaluatorDescriptor = evaluatorDescriptor;
  this.parentContext = parentContext;
  this.reason = reason;
}