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);
}
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);
}
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();
}
}
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);
}
Aggregations