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

The following examples show how to use org.apache.mesos.v1.Protos#Resource . 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: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
public static Protos.Resource mesosRange(
    ResourceType type,
    Optional<String> role,
    Integer... values) {

  return resourceBuilder(type, role, false)
      .setRanges(Protos.Value.Ranges.newBuilder().addAllRange(
          Iterables.transform(
              Numbers.toRanges(ImmutableSet.copyOf(values)),
              Numbers.RANGE_TRANSFORM)))
      .build();
}
 
Example 2
Source File: AcceptedOfferTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test
public void testReservedPredicates() {
  Protos.Resource withRole = mesosScalar(CPUS, TEST_ROLE, false, 1.0);
  assertTrue(AcceptedOffer.RESERVED.test(withRole));
  assertFalse(AcceptedOffer.RESERVED.negate().test(withRole));
  Protos.Resource absentRole = mesosScalar(CPUS, ABSENT_ROLE, false, 1.0);
  assertFalse(AcceptedOffer.RESERVED.test(absentRole));
  assertTrue(AcceptedOffer.RESERVED.negate().test(absentRole));
}
 
Example 3
Source File: ResourceManagerTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test
public void testBagFromMesosResourcesUnsupportedResources() {
  Protos.Resource unsupported = Protos.Resource.newBuilder()
      .setName("unknown")
      .setType(SCALAR)
      .setScalar(Scalar.newBuilder().setValue(1.0).build()).build();
  assertEquals(
      new ResourceBag(ImmutableMap.of(CPUS, 3.0)),
      ResourceManager.bagFromMesosResources(
          ImmutableSet.of(mesosScalar(CPUS, 3.0), unsupported)));
}
 
Example 4
Source File: ResourceManagerTest.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@Test
public void testMesosResourceQuantity() {
  Set<Protos.Resource> resources = ImmutableSet.of(
      mesosScalar(CPUS, 3.0),
      mesosScalar(CPUS, 4.0),
      mesosScalar(RAM_MB, 64),
      mesosRange(PORTS, 1, 3));

  assertEquals(7.0, ResourceManager.quantityOfMesosResource(resources, CPUS), 0.0);
  assertEquals(64, ResourceManager.quantityOfMesosResource(resources, RAM_MB), 0.0);
  assertEquals(0.0, ResourceManager.quantityOfMesosResource(resources, DISK_MB), 0.0);
  assertEquals(2, ResourceManager.quantityOfMesosResource(resources, PORTS), 0.0);
}
 
Example 5
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
public static Protos.Offer offer(String agentId, Protos.Resource... resources) {
  return Protos.Offer.newBuilder()
      .setId(Protos.OfferID.newBuilder().setValue("offer-id-" + agentId))
      .setFrameworkId(Protos.FrameworkID.newBuilder().setValue("framework-id"))
      .setAgentId(Protos.AgentID.newBuilder().setValue(agentId))
      .setHostname("hostname")
      .addAllResources(ImmutableSet.copyOf(resources)).build();
}
 
Example 6
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
public static Protos.Resource mesosRange(
    ResourceType type,
    Optional<String> role,
    Iterable<Integer> values) {

  return resourceBuilder(type, role, false)
      .setRanges(Protos.Value.Ranges.newBuilder().addAllRange(
          Iterables.transform(Numbers.toRanges(values), Numbers.RANGE_TRANSFORM)))
      .build();
}
 
Example 7
Source File: Resources.java    From Juice with GNU General Public License v3.0 5 votes vote down vote up
private
@NotNull
Protos.Resource addResource(@NotNull String name, @NotNull double value) {
    return Protos.Resource.newBuilder()
            .setName(name)
            .setRole(role)
            .setType(Protos.Value.Type.SCALAR)
            .setScalar(Protos.Value.Scalar.newBuilder().setValue(value).build())
            .build();
}
 
Example 8
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
public static Protos.Resource mesosScalar(
    ResourceType type,
    Optional<String> role,
    boolean revocable,
    double value) {

  return resourceBuilder(type, role, revocable)
      .setScalar(Protos.Value.Scalar.newBuilder().setValue(value).build())
      .build();
}
 
Example 9
Source File: Offers.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private static Protos.Resource makeRange(ResourceType type, Iterable<Integer> values) {
  return Protos.Resource.newBuilder()
      .setType(Protos.Value.Type.RANGES)
      .setName(type.getMesosName())
      .setRanges(Protos.Value.Ranges.newBuilder().addAllRange(
          Iterables.transform(Numbers.toRanges(values), Numbers.RANGE_TRANSFORM)))
      .build();
}
 
Example 10
Source File: Offers.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
private static Protos.Resource makeScalar(ResourceType type, double value) {
  return Protos.Resource.newBuilder()
      .setType(Protos.Value.Type.SCALAR)
      .setName(type.getMesosName())
      .setScalar(Protos.Value.Scalar.newBuilder().setValue(value).build())
      .build();
}
 
Example 11
Source File: SingularityMesosTaskBuilderTest.java    From Singularity with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetPortByIndex() throws Exception {
  taskResources = new Resources(1, 1, 4, 0);

  final Protos.Resource portsResource = Protos
    .Resource.newBuilder()
    .setName("ports")
    .setType(Protos.Value.Type.RANGES)
    .setRanges(
      Protos
        .Value.Ranges.newBuilder()
        .addRange(Protos.Value.Range.newBuilder().setBegin(31003).setEnd(31006).build())
        .build()
    )
    .build();

  final SingularityRequest request = new SingularityRequestBuilder(
    "test",
    RequestType.WORKER
  )
  .build();
  final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1")
    .setCommand(Optional.of("/bin/echo"))
    .setArguments(Optional.of(Collections.singletonList("wat")))
    .build();
  final SingularityTaskRequest taskRequest = new SingularityTaskRequest(
    request,
    deploy,
    pendingTask
  );
  final SingularityMesosTaskHolder task = builder.buildTask(
    offerHolder,
    Collections.singletonList(portsResource),
    taskRequest,
    taskResources,
    executorResources
  );
  assertEquals(31005L, task.getTask().getPortByIndex(2).get().longValue());
}
 
Example 12
Source File: Resources.java    From Juice with GNU General Public License v3.0 5 votes vote down vote up
public
@NotNull
List<Protos.Resource> protos() {
    List<Protos.Resource> resources = new ArrayList<>();
    resources.add(addResource(CPUS, cpu));
    resources.add(addResource(MEMS, mem));
    return resources;
}
 
Example 13
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public static Protos.Resource mesosRange(ResourceType type, Integer... values) {
  return mesosRange(type, Optional.empty(), values);
}
 
Example 14
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public static Protos.Resource mesosScalar(ResourceType type, double value, boolean revocable) {
  return mesosScalar(type, Optional.empty(), revocable, value);
}
 
Example 15
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public static Protos.Resource mesosScalar(ResourceType type, double value) {
  return mesosScalar(type, Optional.empty(), false, value);
}
 
Example 16
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public static Iterable<Protos.Resource> mesosScalarFromBag(ResourceBag bag) {
  return bag.streamResourceVectors()
      .map(entry -> mesosScalar(entry.getKey(), entry.getValue()))
      .collect(Collectors.toSet());
}
 
Example 17
Source File: ResourceTestUtil.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
public static Protos.Offer offer(Protos.Resource... resources) {
  return offer("slave-id", resources);
}
 
Example 18
Source File: ResourceManagerTest.java    From attic-aurora with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetOfferResources() {
  ResourceType.initializeEmptyCliArgsForTest();
  Protos.Resource resource1 = Protos.Resource.newBuilder()
      .setType(SCALAR)
      .setName(CPUS.getMesosName())
      .setScalar(Scalar.newBuilder().setValue(2.0).build())
      .build();

  Protos.Resource resource2 = Protos.Resource.newBuilder()
      .setType(SCALAR)
      .setName(CPUS.getMesosName())
      .setRevocable(Protos.Resource.RevocableInfo.getDefaultInstance())
      .setScalar(Scalar.newBuilder().setValue(1.0).build())
      .build();

  Protos.Resource resource3 = Protos.Resource.newBuilder()
      .setType(SCALAR)
      .setName(RAM_MB.getMesosName())
      .setScalar(Scalar.newBuilder().setValue(64).build())
      .build();

  Offer offer = Offer.newBuilder()
      .setId(Protos.OfferID.newBuilder().setValue("offer-id"))
      .setFrameworkId(Protos.FrameworkID.newBuilder().setValue("framework-id"))
      .setAgentId(Protos.AgentID.newBuilder().setValue("slave-id"))
      .setHostname("hostname")
      .addAllResources(ImmutableSet.of(resource1, resource2, resource3)).build();

  assertEquals(
      ImmutableSet.of(resource1, resource2),
      ImmutableSet.copyOf(ResourceManager.getOfferResources(offer, CPUS)));
  assertEquals(
      resource3,
      Iterables.getOnlyElement(ResourceManager.getOfferResources(offer, RAM_MB)));
  assertEquals(
      ImmutableSet.of(resource1, resource3),
      ImmutableSet.copyOf(ResourceManager.getNonRevocableOfferResources(offer)));
  assertEquals(
      ImmutableSet.of(resource2, resource3),
      ImmutableSet.copyOf(ResourceManager.getRevocableOfferResources(offer)));
  assertEquals(
      ImmutableSet.of(resource1, resource3),
      ImmutableSet.copyOf(ResourceManager.getOfferResources(offer, false)));
  assertEquals(
      ImmutableSet.of(resource2, resource3),
      ImmutableSet.copyOf(ResourceManager.getOfferResources(offer, true)));
}