Java Code Examples for org.apache.mesos.Protos#ResourceProviderID

The following examples show how to use org.apache.mesos.Protos#ResourceProviderID . 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: ResourceLabels.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
/**
 * ResourceLabels are used to map {@link com.mesosphere.sdk.specification.ServiceSpec} entities to resources which
 * have actually been consumed.  Generally speaking there should be no difference between the resources from a Mesos
 * perspective and the resources from a {@link com.mesosphere.sdk.specification.ServiceSpec} perspective.
 * <p>
 * There is one special case in which they differ, MOUNT volume resources.  In this case the {@link ResourceSpec}
 * and actually consumed resources differ in value.  Because MOUNT volumes are atomic if the {@link ResourceSpec}
 * indicates a need for 25 GB of disk and 50 GB of disk are actually offered, then 50 GB must be consumed.
 * <p>
 * To capture this change the concept of an "updated" ResourceSpec is needed.  We modify the ResourceSpec in this
 * scenario to match the actually consumed resources to facilitate consistent protobuf construction.
 */
ResourceLabels(
    ResourceSpec original,
    ResourceSpec updated,
    String resourceId,
    Optional<String> resourceNamespace,
    Optional<String> persistenceId,
    Optional<Protos.ResourceProviderID> providerId,
    Optional<Protos.Resource.DiskInfo.Source> diskSource,
    Optional<String> frameworkId)
{
  this.original = original;
  this.updated = updated;
  this.resourceId = resourceId;
  this.resourceNamespace = resourceNamespace;
  this.persistenceId = persistenceId;
  this.providerId = providerId;
  this.diskSource = diskSource;
  this.frameworkId = frameworkId;
}
 
Example 2
Source File: PodInfoBuilder.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
public static Protos.Resource getExistingExecutorVolume(
    VolumeSpec volumeSpec,
    Optional<String> resourceId,
    Optional<String> resourceNamespace,
    Optional<String> persistenceId,
    Optional<Protos.ResourceProviderID> providerId,
    Optional<Protos.Resource.DiskInfo.Source> diskSource,
    Optional<String> frameworkId)
{

  Protos.Resource.Builder builder = ResourceBuilder
      .fromSpec(volumeSpec, resourceId, resourceNamespace, persistenceId, providerId, diskSource, frameworkId)
      .build()
      .toBuilder();

  return builder.build();
}
 
Example 3
Source File: VolumeEvaluationStage.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
public static VolumeEvaluationStage getExisting(
    VolumeSpec volumeSpec,
    Collection<String> taskNames,
    Optional<String> resourceId,
    Optional<String> resourceNamespace,
    Optional<String> persistenceId,
    Optional<Protos.ResourceProviderID> providerId,
    Optional<Protos.Resource.DiskInfo.Source> diskSource,
    Optional<String> frameworkId)
{
  return new VolumeEvaluationStage(
      volumeSpec,
      taskNames,
      resourceId,
      resourceNamespace,
      persistenceId,
      providerId,
      diskSource,
      frameworkId);
}
 
Example 4
Source File: VolumeEvaluationStage.java    From dcos-commons with Apache License 2.0 6 votes vote down vote up
private VolumeEvaluationStage(
    VolumeSpec volumeSpec,
    Collection<String> taskNames,
    Optional<String> resourceId,
    Optional<String> resourceNamespace,
    Optional<String> persistenceId,
    Optional<Protos.ResourceProviderID> providerId,
    Optional<Protos.Resource.DiskInfo.Source> diskSource,
    Optional<String> frameworkId)
{
  this.logger = LoggingUtils.getLogger(getClass(), resourceNamespace);
  this.volumeSpec = volumeSpec;
  this.taskNames = taskNames;
  this.resourceId = resourceId;
  this.resourceNamespace = resourceNamespace;
  this.persistenceId = persistenceId;
  this.providerId = providerId;
  this.diskSource = diskSource;
  this.frameworkId = frameworkId;
}
 
Example 5
Source File: ResourceBuilder.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
public static ResourceBuilder fromSpec(
    VolumeSpec spec,
    Optional<String> resourceId,
    Optional<String> resourceNamespace,
    Optional<String> persistenceId,
    Optional<Protos.ResourceProviderID> providerId,
    Optional<Protos.Resource.DiskInfo.Source> diskSource,
    Optional<String> frameworkId)
{
  ResourceBuilder resourceBuilder = fromSpec(spec, resourceId, resourceNamespace, frameworkId);

  providerId.ifPresent(resourceBuilder::setProviderId);

  switch (spec.getType()) {
    case ROOT:
      if (diskSource.isPresent()) {
        throw new IllegalStateException("Source must not be set on a ROOT volume");
      }
      return resourceBuilder.setRootVolume(spec.getContainerPath(), persistenceId);
    case MOUNT:
      if (!diskSource.isPresent()) {
        throw new IllegalStateException("Source must be set on a MOUNT volume");
      }
      return resourceBuilder
          .setMountVolume(spec.getContainerPath(), persistenceId, diskSource.get());
    default:
      throw new IllegalStateException(String.format("Unexpected disk type: %s", spec.getType()));
  }
}
 
Example 6
Source File: ResourceUtils.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
public static Optional<Protos.ResourceProviderID> getProviderId(Protos.Resource resource) {
  if (resource.hasProviderId()) {
    return Optional.of(resource.getProviderId());
  }

  return Optional.empty();
}
 
Example 7
Source File: TaskResourceMapper.java    From dcos-commons with Apache License 2.0 5 votes vote down vote up
private static OfferEvaluationStage toEvaluationStage(
    Collection<String> taskSpecNames,
    ResourceSpec resourceSpec,
    Optional<String> resourceId,
    Optional<String> resourceNamespace,
    Optional<String> persistenceId,
    Optional<Protos.ResourceProviderID> providerId,
    Optional<Protos.Resource.DiskInfo.Source> diskSource,
    Optional<String> frameworkId)
{
  if (resourceSpec instanceof NamedVIPSpec) {
    return new NamedVIPEvaluationStage(
        (NamedVIPSpec) resourceSpec, taskSpecNames, resourceId, resourceNamespace, frameworkId);
  } else if (resourceSpec instanceof PortSpec) {
    return new PortEvaluationStage(
        (PortSpec) resourceSpec,
        taskSpecNames,
        resourceId,
        resourceNamespace,
        frameworkId);
  } else if (resourceSpec instanceof VolumeSpec) {
    return VolumeEvaluationStage.getExisting(
        (VolumeSpec) resourceSpec,
        taskSpecNames,
        resourceId,
        resourceNamespace,
        persistenceId,
        providerId,
        diskSource,
        frameworkId);
  } else {
    return new ResourceEvaluationStage(
        resourceSpec,
        taskSpecNames,
        resourceId,
        resourceNamespace,
        frameworkId);
  }
}
 
Example 8
Source File: ResourceBuilder.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Assigns the resource provider id to the provided value.
 */
private ResourceBuilder setProviderId(Protos.ResourceProviderID providerId) {
  this.providerId = Optional.of(providerId);
  return this;
}
 
Example 9
Source File: ResourceLabels.java    From dcos-commons with Apache License 2.0 4 votes vote down vote up
public Optional<Protos.ResourceProviderID> getProviderId() {
  return providerId;
}