Search in sources :

Example 6 with VolumeSpec

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();
}
Also used : Protos(org.apache.mesos.Protos) Arrays(java.util.Arrays) SchedulerDriver(org.apache.mesos.SchedulerDriver) TestConstants(com.mesosphere.sdk.testutils.TestConstants) TaskSpec(com.mesosphere.sdk.specification.TaskSpec) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PodSpec(com.mesosphere.sdk.specification.PodSpec) List(java.util.List) VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) Scheduler(org.apache.mesos.Scheduler) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec) Optional(java.util.Optional) Constants(com.mesosphere.sdk.offer.Constants) VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) PodSpec(com.mesosphere.sdk.specification.PodSpec) Protos(org.apache.mesos.Protos) TaskSpec(com.mesosphere.sdk.specification.TaskSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Example 7 with VolumeSpec

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();
}
Also used : VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Example 8 with VolumeSpec

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);
    }
}
Also used : VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Example 9 with VolumeSpec

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());
}
Also used : DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec) VolumeSpec(com.mesosphere.sdk.specification.VolumeSpec) Protos(org.apache.mesos.Protos) DefaultVolumeSpec(com.mesosphere.sdk.specification.DefaultVolumeSpec)

Aggregations

VolumeSpec (com.mesosphere.sdk.specification.VolumeSpec)9 Protos (org.apache.mesos.Protos)7 DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)6 ResourceSpec (com.mesosphere.sdk.specification.ResourceSpec)3 Constants (com.mesosphere.sdk.offer.Constants)1 PodSpec (com.mesosphere.sdk.specification.PodSpec)1 TaskSpec (com.mesosphere.sdk.specification.TaskSpec)1 TestConstants (com.mesosphere.sdk.testutils.TestConstants)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Scheduler (org.apache.mesos.Scheduler)1 SchedulerDriver (org.apache.mesos.SchedulerDriver)1