Search in sources :

Example 1 with DefaultResourceSpec

use of com.mesosphere.sdk.specification.DefaultResourceSpec in project dcos-commons by mesosphere.

the class ResourceBuilderTest method testExistingFromResourceSpec.

private static void testExistingFromResourceSpec(Optional<String> namespace) {
    Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
    ResourceSpec resourceSpec = new DefaultResourceSpec("cpus", VALUE, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL);
    validateScalarResource(ResourceBuilder.fromSpec(resourceSpec, resourceId, namespace).build(), resourceId, namespace);
}
Also used : DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Example 2 with DefaultResourceSpec

use of com.mesosphere.sdk.specification.DefaultResourceSpec in project dcos-commons by mesosphere.

the class ResourceBuilderTest method testNewFromResourceSpec.

private static void testNewFromResourceSpec(Optional<String> namespace) {
    ResourceSpec resourceSpec = new DefaultResourceSpec("cpus", VALUE, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL);
    ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(resourceSpec, Optional.empty(), namespace);
    Protos.Resource resource = resourceBuilder.build();
    validateScalarResource(resource, Optional.empty(), namespace);
}
Also used : Protos(org.apache.mesos.Protos) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Example 3 with DefaultResourceSpec

use of com.mesosphere.sdk.specification.DefaultResourceSpec in project dcos-commons by mesosphere.

the class ResourceBuilderTest method testRefineStaticResource.

/*
        name: "cpus"
        type: SCALAR
        scalar {
          value: 1.0
        }
        reservations {
          role: "base-role"
          type: STATIC
        }
        reservations {
          principal: "test-principal"
          labels {
            labels {
              key: "resource_id"
              value: "a395f14b-3cc8-4009-9dc4-51838b423aed"
            }
          }
          role: "test-role"
          type: DYNAMIC
        }
    */
private static void testRefineStaticResource(Optional<String> namespace) {
    ResourceRefinementCapabilityContext context = new ResourceRefinementCapabilityContext(Capabilities.getInstance());
    try {
        ResourceSpec resourceSpec = new DefaultResourceSpec("cpus", VALUE, TestConstants.ROLE, TestConstants.PRE_RESERVED_ROLE, TestConstants.PRINCIPAL);
        ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(resourceSpec, Optional.empty(), namespace);
        Protos.Resource resource = resourceBuilder.build();
        Assert.assertEquals(2, resource.getReservationsCount());
        validateScalarResourceRefined(resource, Optional.empty(), namespace);
        Assert.assertEquals(Protos.Resource.ReservationInfo.Type.STATIC, resource.getReservations(0).getType());
        Assert.assertEquals(TestConstants.PRE_RESERVED_ROLE, resource.getReservations(0).getRole());
    } finally {
        context.reset();
    }
}
Also used : Protos(org.apache.mesos.Protos) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec) ResourceRefinementCapabilityContext(com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext)

Example 4 with DefaultResourceSpec

use of com.mesosphere.sdk.specification.DefaultResourceSpec in project dcos-commons by mesosphere.

the class ResourceBuilderTest method testFromExistingScalarResource.

private static void testFromExistingScalarResource(Optional<String> namespace) {
    ResourceSpec resourceSpec = new DefaultResourceSpec("cpus", VALUE, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL);
    Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
    Protos.Resource originalResource = ResourceBuilder.fromSpec(resourceSpec, resourceId, namespace).build();
    Protos.Resource reconstructedResource = ResourceBuilder.fromExistingResource(originalResource).build();
    Assert.assertEquals(originalResource, reconstructedResource);
}
Also used : Protos(org.apache.mesos.Protos) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) DefaultResourceSpec(com.mesosphere.sdk.specification.DefaultResourceSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Aggregations

DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)4 ResourceSpec (com.mesosphere.sdk.specification.ResourceSpec)4 Protos (org.apache.mesos.Protos)3 ResourceRefinementCapabilityContext (com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext)1