Java Code Examples for org.apache.mesos.Protos.Resource#Builder

The following examples show how to use org.apache.mesos.Protos.Resource#Builder . 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: MesosResourcePool.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void freeAtomicResource(MesosResource mesosResource) {
  Resource.Builder resBuilder = Resource.newBuilder(mesosResource.getResource());
  resBuilder.clearReservation();
  resBuilder.setRole(Constants.ANY_ROLE);

  if (resBuilder.hasDisk()) {
    Resource.DiskInfo.Builder diskBuilder = Resource.DiskInfo.newBuilder(resBuilder.getDisk());
    diskBuilder.clearPersistence();
    diskBuilder.clearVolume();
    resBuilder.setDisk(diskBuilder.build());
  }

  Resource releasedResource = resBuilder.build();

  List<MesosResource> resList = unreservedAtomicPool.get(mesosResource.getName());
  if (resList == null) {
    resList = new ArrayList<>();
  }

  resList.add(new MesosResource(releasedResource));
  unreservedAtomicPool.put(mesosResource.getName(), resList);
}
 
Example 2
Source File: UnreserveOfferRecommendation.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
public UnreserveOfferRecommendation(Offer offer, Resource resource) {
  this.offer = offer;
  Resource.Builder resourceBuilder = resource.toBuilder();

  Resource resourceR;
  // If non-root disk resource, we want to clear ALL fields except for the field indicating the disk source.
  if (resource.hasDisk() && resource.getDisk().hasSource()) {
    resourceR = resourceBuilder
        .setDisk(Resource.DiskInfo.newBuilder().setSource(resource.getDisk().getSource()))
        .build();
  } else {
    resourceR = resourceBuilder.clearDisk().clearRevocable().build();
  }

  this.operation = Operation.newBuilder()
      .setType(Operation.Type.UNRESERVE)
      .setUnreserve(
          Operation.Unreserve.newBuilder().addAllResources(Collections.singletonList(resourceR))
      )
      .build();
  this.resource = resourceR;
}
 
Example 3
Source File: MesosNimbus.java    From storm with Apache License 2.0 6 votes vote down vote up
private List<Resource> createMesosScalarResourceList(ResourceType resourceType, List<ResourceEntry> scalarResourceEntryList) {
  List<Resource> retVal = new ArrayList<>();
  ScalarResourceEntry scalarResourceEntry = null;

  for (ResourceEntry resourceEntry : scalarResourceEntryList) {
    scalarResourceEntry = (ScalarResourceEntry) resourceEntry;
    Resource.Builder resourceBuilder = Resource.newBuilder()
                                               .setName(resourceType.toString())
                                               .setType(Protos.Value.Type.SCALAR)
                                               .setScalar(Scalar.newBuilder().setValue(scalarResourceEntry.getValue()));
    if (resourceEntry.getReservationType() != null && resourceEntry.getReservationType().equals(ReservationType.STATIC)) {
      resourceBuilder.setRole(MesosCommon.getRole(mesosStormConf));
    }
    retVal.add(resourceBuilder.build());
  }
  return retVal;
}
 
Example 4
Source File: MesosNimbus.java    From storm with Apache License 2.0 6 votes vote down vote up
private Resource createMesosRangeResource(ResourceType resourceType, RangeResourceEntry rangeResourceEntry) {
  Ranges.Builder rangesBuilder = Ranges.newBuilder();
  Range rangeBuilder = Range.newBuilder()
                            .setBegin(rangeResourceEntry.getBegin())
                            .setEnd(rangeResourceEntry.getEnd()).build();
  rangesBuilder.addRange(rangeBuilder);

  Resource.Builder resourceBuilder = Resource.newBuilder()
                                             .setName(resourceType.toString())
                                             .setType(Protos.Value.Type.RANGES)
                                             .setRanges(rangesBuilder.build());
  if (rangeResourceEntry.getReservationType() != null && rangeResourceEntry.getReservationType().equals(ReservationType.STATIC)) {
    resourceBuilder.setRole(MesosCommon.getRole(mesosStormConf));
  }
  return resourceBuilder.build();
}
 
Example 5
Source File: OfferTestUtils.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Minimum to keep required field errors away.
 */
public static void addResource(Offer.Builder o, String name, String role) {
    Resource.Builder b = o.addResourcesBuilder().setType(Value.Type.RANGES).setName(name);
    if (role != null) {
        b.setRole(role);
    }
}
 
Example 6
Source File: MesosResourcePool.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
public Optional<MesosResource> consumeReservableMerged(
    String name,
    Value desiredValue,
    String preReservedRole)
{
  Map<String, Value> pool = reservableMergedPoolByRole.get(preReservedRole);
  if (pool == null) {
    LOGGER.info("No unreserved resources available for role '{}'. Reservable roles are: {}",
        preReservedRole, reservableMergedPoolByRole.keySet());
    return Optional.empty();
  }

  Value availableValue = pool.get(name);

  if (sufficientValue(desiredValue, availableValue)) {
    pool.put(name, ValueUtils.subtract(availableValue, desiredValue));
    reservableMergedPoolByRole.put(preReservedRole, pool);

    Resource.Builder builder =
        ResourceBuilder.fromUnreservedValue(name, desiredValue).build().toBuilder();
    if (Capabilities.getInstance().supportsPreReservedResources() &&
        !preReservedRole.equals(Constants.ANY_ROLE))
    {
      builder.addReservations(
          Resource.ReservationInfo.newBuilder()
              .setRole(preReservedRole)
              .setType(Resource.ReservationInfo.Type.STATIC));
    }

    return Optional.of(new MesosResource(builder.build()));
  } else {
    if (availableValue == null) {
      LOGGER.info("Offer lacks any unreserved {} resources for role {}", name, preReservedRole);
    } else {
      LOGGER.info("Offered quantity of {} for role {} is insufficient: desired {}, offered {}",
          name,
          preReservedRole,
          TextFormat.shortDebugString(desiredValue),
          TextFormat.shortDebugString(availableValue));
    }
    return Optional.empty();
  }
}