org.apache.reef.util.Optional.orElse()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中org.apache.reef.util.Optional.orElse()方法的一些代码示例,展示了Optional.orElse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.orElse()方法的具体详情如下:
包路径:org.apache.reef.util.Optional
类名称:Optional
方法名:orElse

Optional.orElse介绍

暂无

代码示例

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

/**
 * Extract the information on whether or not the job should preserve evaluators across job driver restarts.
 */
private Boolean getPreserveEvaluators(final JobSubmissionEvent jobSubmissionEvent) {
 return jobSubmissionEvent.getPreserveEvaluators().orElse(false);
}

代码示例来源:origin: org.apache.reef/reef-common

@Override
 public void onNext(final FailedTask failedTask) {
  throw new RuntimeException("No handler bound for FailedTask: " + failedTask, failedTask.getReason().orElse(null));
 }
}

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

/**
 * Extract the number of maximum application attempts on the job.
 */
private Integer getMaxApplicationSubmissions(final JobSubmissionEvent jobSubmissionEvent) {
 return jobSubmissionEvent.getMaxApplicationSubmissions().orElse(1);
}

代码示例来源:origin: org.apache.reef/reef-common

public static LauncherStatus failed(final Optional<Throwable> ex) {
 return new LauncherStatus(State.FAILED, ex.orElse(null));
}

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

private static int getPriority(final JobSubmissionEvent jobSubmissionEvent) {
 return jobSubmissionEvent.getPriority().orElse(0);
}

代码示例来源:origin: org.apache.reef/reef-common

@Override
public String toString() {
 // Replace with String.join() after migration to Java 1.8
 final StringBuilder allocatedContainers = new StringBuilder();
 for (String container : this.containerAllocationList) {
  if (allocatedContainers.length() > 0) {
   allocatedContainers.append(',');
  }
  allocatedContainers.append(container);
 }
 return String.format(
   "RuntimeStatusEventImpl:{name:%s, state:%s, allocated:[%s], outstanding:%d, error:%s}",
   this.name, this.state, allocatedContainers, this.outstandingContainerRequests.orElse(0),
   this.error.isPresent());
}

代码示例来源:origin: org.apache.reef/reef-common

@Override
 public void onNext(final FailedJob job) {
  throw new RuntimeException("REEF job failed: " + job.getId(), job.getReason().orElse(null));
 }
}

代码示例来源:origin: org.apache.reef/reef-common

/**
 * Create a builder from an existing ResourceRequestEvent.
 */
public Builder mergeFrom(final ResourceRequestEvent resourceRequestEvent) {
 this.resourceCount = resourceRequestEvent.getResourceCount();
 this.nodeNameList = resourceRequestEvent.getNodeNameList();
 this.rackNameList = resourceRequestEvent.getRackNameList();
 this.memorySize = resourceRequestEvent.getMemorySize().orElse(null);
 this.priority = resourceRequestEvent.getPriority().orElse(null);
 this.virtualCores = resourceRequestEvent.getVirtualCores().orElse(null);
 this.relaxLocality = resourceRequestEvent.getRelaxLocality().orElse(null);
 this.runtimeName = resourceRequestEvent.getRuntimeName();
 return this;
}

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

private synchronized Priority getPriority(final ResourceRequestEvent resourceRequestEvent) {
 final Priority pri = Records.newRecord(Priority.class);
 pri.setPriority(resourceRequestEvent.getPriority().orElse(1));
 return pri;
}

代码示例来源:origin: org.apache.reef/reef-runtime-local

@Override
 public void onNext(final RemoteMessage<ReefServiceProtos.RuntimeErrorProto> value) {
  final FailedRuntime error = new FailedRuntime(value.getMessage());
  LOG.log(Level.SEVERE, "FailedRuntime: " + error, error.getReason().orElse(null));
  release(error.getId());
 }
});

代码示例来源:origin: org.apache.reef/reef-common

public synchronized void handle(final NodeDescriptorEvent node) {
  final String rackName = node.getRackName().orElse(DEFAULT_RACK);

  LOG.log(Level.FINEST, "Catalog new node: id[{0}], rack[{1}], host[{2}], port[{3}], memory[{4}]",
    new Object[]{node.getIdentifier(), rackName, node.getHostName(), node.getPort(),
      node.getMemorySize()}
  );

  if (!this.racks.containsKey(rackName)) {
   final RackDescriptorImpl rack = new RackDescriptorImpl(rackName);
   this.racks.put(rackName, rack);
  }
  final RackDescriptorImpl rack = this.racks.get(rackName);
  final InetSocketAddress address = new InetSocketAddress(node.getHostName(), node.getPort());
  final NodeDescriptorImpl nodeDescriptor = new NodeDescriptorImpl(node.getIdentifier(), address, rack,
    node.getMemorySize());
  this.nodes.put(nodeDescriptor.getId(), nodeDescriptor);
 }
}

代码示例来源:origin: org.apache.reef/reef-common

@Override
public void onNext(final RuntimeStatusEvent runtimeStatusEvent) {
 final State newState = runtimeStatusEvent.getState();
 LOG.log(Level.FINEST, "Runtime status: {0}", runtimeStatusEvent);
 synchronized(this) {
  this.outstandingContainerRequests = runtimeStatusEvent.getOutstandingContainerRequests().orElse(0);
  this.containerAllocationCount = runtimeStatusEvent.getContainerAllocationList().size();
  this.setState(newState);
 }
 switch (newState) {
 case FAILED:
  this.onRMFailure(runtimeStatusEvent);
  break;
 case DONE:
  this.onRMDone(runtimeStatusEvent);
  break;
 case RUNNING:
  this.onRMRunning(runtimeStatusEvent);
  break;
 case INIT:
 case SUSPEND:
 case KILLED:
  break;
 default:
  throw new RuntimeException("Unknown state: " + newState);
 }
}

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

@Override
public void onNext(final JobSubmissionEvent jobSubmissionEvent) {
 final String jobId = jobSubmissionEvent.getIdentifier();
 LOG.log(Level.FINEST, "Submitting UNMANAGED AM job: {0}", jobSubmissionEvent);
 try {
  this.driverFiles.copyGlobalsFrom(jobSubmissionEvent);
  this.submissionHelper
    .setApplicationName(jobId)
    .setPriority(jobSubmissionEvent.getPriority().orElse(0))
    .setQueue(getQueue(jobSubmissionEvent))
    .submit();
  this.applicationId = this.submissionHelper.getStringApplicationId();
  LOG.log(Level.FINER, "Submitted UNMANAGED AM job with ID {0} :: {1}", new String[] {jobId, this.applicationId});
 } catch (final IOException | YarnException ex) {
  throw new RuntimeException("Unable to submit UNMANAGED Driver to YARN: " + jobId, ex);
 }
}

代码示例来源:origin: org.apache.reef/reef-runtime-yarn

@Override
public synchronized void onNext(final ResourceRequestEvent resourceRequestEvent) {
 LOG.log(Level.FINEST, "Got ResourceRequestEvent in YarnResourceRequestHandler: memory = {0}, cores = {1}.",
   new Object[]{resourceRequestEvent.getMemorySize(), resourceRequestEvent.getVirtualCores()});
 final String[] nodes = resourceRequestEvent.getNodeNameList().size() == 0 ? null :
   resourceRequestEvent.getNodeNameList().toArray(new String[resourceRequestEvent.getNodeNameList().size()]);
 final String[] racks = resourceRequestEvent.getRackNameList().size() == 0 ? null :
   resourceRequestEvent.getRackNameList().toArray(new String[resourceRequestEvent.getRackNameList().size()]);
 // set the priority for the request
 final Priority pri = getPriority(resourceRequestEvent);
 final Resource resource = getResource(resourceRequestEvent);
 final boolean relaxLocality = resourceRequestEvent.getRelaxLocality().orElse(true);
 final AMRMClient.ContainerRequest[] containerRequests =
   new AMRMClient.ContainerRequest[resourceRequestEvent.getResourceCount()];
 for (int i = 0; i < resourceRequestEvent.getResourceCount(); i++) {
  containerRequests[i] = new AMRMClient.ContainerRequest(resource, nodes, racks, pri, relaxLocality);
 }
 this.yarnContainerRequestHandler.onContainerRequest(containerRequests);
}

代码示例来源:origin: org.apache.reef/reef-runtime-local

/**
 * Allocates a container based on a request event. First it tries to match a
 * given node, if it cannot, it tries to get a spot in a rack.
 * @param requestEvent resource request event.
 * @return an optional with the container if allocated.
 */
Optional<Container> allocateContainer(final ResourceRequestEvent requestEvent) {
 Container container = null;
 final Optional<String> nodeName = getPreferredNode(requestEvent.getNodeNameList());
 if (nodeName.isPresent()) {
  container = allocateBasedOnNode(
    requestEvent.getMemorySize().orElse(this.defaultMemorySize),
    requestEvent.getVirtualCores().orElse(this.defaultNumberOfCores),
    nodeName.get());
 } else {
  final Optional<String> rackName = getPreferredRack(requestEvent.getRackNameList());
  if (rackName.isPresent()) {
   container = allocateBasedOnRack(
     requestEvent.getMemorySize().orElse(this.defaultMemorySize),
     requestEvent.getVirtualCores().orElse(this.defaultNumberOfCores),
     rackName.get());
  }
 }
 return Optional.ofNullable(container);
}

代码示例来源:origin: org.apache.reef/reef-io

public static AvroContextBase toAvroContextBase(final ContextBase contextBase) {
 return AvroContextBase.newBuilder()
   .setEvaluatorDescriptor(null)
   .setEvaluatorId(contextBase.getEvaluatorId())
   .setId(contextBase.getId())
   .setParentId(contextBase.getParentId().orElse(null))
   .build();
}

代码示例来源:origin: org.apache.reef/reef-io

public static AvroFailure toAvroFailure(final Failure failure) {
 final String reason;
 if (failure.getReason().isPresent()) {
  reason = convertThrowableToString(failure.getReason().get());
 } else {
  reason = null;
 }
 return AvroFailure.newBuilder()
   .setAsError(convertThrowableToString(failure.asError()))
   .setData(unwrapOptionalByteArray(failure.getData()))
   .setDescription(failure.getDescription().orElse(null))
   .setId(failure.getId())
   .setMessage(failure.getMessage())
   .setReason(reason)
   .build();
}

相关文章