use of com.mesosphere.sdk.specification.VolumeSpec in project dcos-commons by mesosphere.
the class SendOffer method getOfferForPod.
private Protos.Offer getOfferForPod(ClusterState state) {
Optional<PodSpec> matchingSpec = state.getServiceSpec().getPods().stream().filter(podSpec -> podType.equals(podSpec.getType())).findAny();
if (!matchingSpec.isPresent()) {
throw new IllegalArgumentException(String.format("No PodSpec found with type=%s: types=%s", podType, state.getServiceSpec().getPods().stream().map(podSpec -> podSpec.getType()).collect(Collectors.toList())));
}
PodSpec podSpec = matchingSpec.get();
Protos.Offer.Builder offerBuilder = Protos.Offer.newBuilder().setFrameworkId(TestConstants.FRAMEWORK_ID).setSlaveId(TestConstants.AGENT_ID).setHostname(hostname);
offerBuilder.getIdBuilder().setValue(UUID.randomUUID().toString());
// Include pod/executor-level volumes:
for (VolumeSpec volumeSpec : podSpec.getVolumes()) {
offerBuilder.addResources(toUnreservedResource(volumeSpec));
}
// Include task-level resources (note: resources are not merged, e.g. 1.5cpu+1.0 cpu instead of 2.5cpu):
for (TaskSpec taskSpec : podSpec.getTasks()) {
if (podToReuse.isPresent()) {
// Copy executor id and resources from prior pod launch:
LaunchedPod pod = state.getLastLaunchedPod(podToReuse.get());
offerBuilder.addExecutorIds(pod.getExecutor().getExecutorId()).addAllResources(pod.getExecutor().getResourcesList());
for (Protos.TaskInfo task : pod.getTasks()) {
offerBuilder.addAllResources(task.getResourcesList());
}
} else {
// Create new unreserved resources:
for (ResourceSpec resourceSpec : taskSpec.getResourceSet().getResources()) {
offerBuilder.addResources(toUnreservedResource(resourceSpec));
}
for (VolumeSpec volumeSpec : taskSpec.getResourceSet().getVolumes()) {
offerBuilder.addResources(toUnreservedResource(volumeSpec));
}
}
}
// just ignored.
if (!podToReuse.isPresent()) {
offerBuilder.addAllResources(DEFAULT_EXECUTOR_RESOURCES);
}
return offerBuilder.build();
}
use of com.mesosphere.sdk.specification.VolumeSpec in project dcos-commons by mesosphere.
the class ExecutorResourceMapper method findMatchingDiskSpec.
private Optional<ResourceLabels> findMatchingDiskSpec(Protos.Resource executorResource, Collection<ResourceSpec> resourceSpecs) {
for (ResourceSpec resourceSpec : resourceSpecs) {
if (!(resourceSpec instanceof VolumeSpec)) {
continue;
}
if (executorResource.getDisk().getVolume().getContainerPath().equals(((VolumeSpec) resourceSpec).getContainerPath())) {
Optional<String> resourceId = ResourceUtils.getResourceId(executorResource);
if (!resourceId.isPresent()) {
logger.error("Failed to find resource ID for resource: {}", executorResource);
continue;
}
double diskSize = executorResource.getScalar().getValue();
VolumeSpec updatedSpec = OfferEvaluationUtils.updateVolumeSpec((VolumeSpec) resourceSpec, diskSize);
return Optional.of(new ResourceLabels(resourceSpec, updatedSpec, resourceId.get(), Optional.of(executorResource.getDisk().getPersistence().getId()), ResourceUtils.getSourceRoot(executorResource)));
}
}
return Optional.empty();
}
use of com.mesosphere.sdk.specification.VolumeSpec in project dcos-commons by mesosphere.
the class ExecutorResourceMapper method newUpdateEvaluationStage.
private OfferEvaluationStage newUpdateEvaluationStage(ResourceLabels resourceLabels) {
ResourceSpec resourceSpec = resourceLabels.getUpdated();
Optional<String> resourceId = Optional.of(resourceLabels.getResourceId());
if (resourceSpec instanceof VolumeSpec) {
return VolumeEvaluationStage.getExisting((VolumeSpec) resourceSpec, Optional.empty(), resourceId, resourceNamespace, resourceLabels.getPersistenceId(), resourceLabels.getSourceRoot(), useDefaultExecutor);
} else {
return new ResourceEvaluationStage(resourceSpec, Optional.empty(), resourceId, resourceNamespace);
}
}
use of com.mesosphere.sdk.specification.VolumeSpec in project dcos-commons by mesosphere.
the class ResourceBuilderTest method testExistingFromMountVolumeSpec.
private static void testExistingFromMountVolumeSpec(Optional<String> namespace) {
VolumeSpec volumeSpec = new DefaultVolumeSpec(10, VolumeSpec.Type.MOUNT, TestConstants.CONTAINER_PATH, TestConstants.ROLE, Constants.ANY_ROLE, TestConstants.PRINCIPAL);
Optional<String> resourceId = Optional.of(UUID.randomUUID().toString());
Optional<String> persistenceId = Optional.of(UUID.randomUUID().toString());
ResourceBuilder resourceBuilder = ResourceBuilder.fromSpec(volumeSpec, resourceId, namespace, persistenceId, Optional.of(TestConstants.MOUNT_SOURCE_ROOT));
Protos.Resource resource = resourceBuilder.build();
validateDisk(resource, resourceId, namespace);
Protos.Resource.DiskInfo diskInfo = resource.getDisk();
Assert.assertTrue(diskInfo.hasSource());
Protos.Resource.DiskInfo.Source source = diskInfo.getSource();
Assert.assertEquals("MOUNT", source.getType().toString());
Assert.assertTrue(source.hasMount());
Assert.assertEquals(TestConstants.MOUNT_SOURCE_ROOT, source.getMount().getRoot());
Assert.assertEquals(persistenceId.get(), resource.getDisk().getPersistence().getId());
}
Aggregations