Search in sources :

Example 11 with ResourceSpec

use of com.mesosphere.sdk.specification.ResourceSpec 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 12 with ResourceSpec

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

the class ExecutorResourceMapper method getEvaluationStagesInternal.

private List<OfferEvaluationStage> getEvaluationStagesInternal() {
    List<ResourceSpec> remainingResourceSpecs = new ArrayList<>();
    remainingResourceSpecs.addAll(volumeSpecs);
    if (useDefaultExecutor) {
        remainingResourceSpecs.addAll(resourceSpecs);
    }
    List<ResourceLabels> matchingResources = new ArrayList<>();
    for (Protos.Resource resource : executorResources) {
        Optional<ResourceLabels> matchingResource;
        if (resource.getName().equals(Constants.DISK_RESOURCE_TYPE) && resource.hasDisk()) {
            matchingResource = findMatchingDiskSpec(resource, remainingResourceSpecs);
        } else {
            matchingResource = findMatchingResourceSpec(resource, remainingResourceSpecs);
        }
        if (matchingResource.isPresent()) {
            if (!remainingResourceSpecs.remove(matchingResource.get().getOriginal())) {
                throw new IllegalStateException(String.format("Didn't find %s in %s", matchingResource.get().getOriginal(), remainingResourceSpecs));
            }
            matchingResources.add(matchingResource.get());
        } else {
            logger.warn("Failed to find match for resource: {}", TextFormat.shortDebugString(resource));
            if (resource.hasDisk()) {
                orphanedResources.add(resource);
            }
        }
    }
    List<OfferEvaluationStage> stages = new ArrayList<>();
    if (!orphanedResources.isEmpty()) {
        logger.info("Orphaned executor resources no longer in executor: {}", orphanedResources.stream().map(r -> TextFormat.shortDebugString(r)).collect(Collectors.toList()));
    }
    if (!matchingResources.isEmpty()) {
        logger.info("Matching executor resources: {}", matchingResources);
        for (ResourceLabels resourceLabels : matchingResources) {
            stages.add(newUpdateEvaluationStage(resourceLabels));
        }
    }
    if (!remainingResourceSpecs.isEmpty()) {
        logger.info("Missing resources not found in executor: {}", remainingResourceSpecs);
        for (ResourceSpec missingResource : remainingResourceSpecs) {
            stages.add(newCreateEvaluationStage(missingResource));
        }
    }
    return stages;
}
Also used : Protos(org.apache.mesos.Protos) ResourceSpec(com.mesosphere.sdk.specification.ResourceSpec)

Example 13 with ResourceSpec

use of com.mesosphere.sdk.specification.ResourceSpec 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

ResourceSpec (com.mesosphere.sdk.specification.ResourceSpec)13 Protos (org.apache.mesos.Protos)10 DefaultResourceSpec (com.mesosphere.sdk.specification.DefaultResourceSpec)8 ReserveEvaluationOutcome (com.mesosphere.sdk.offer.evaluate.OfferEvaluationUtils.ReserveEvaluationOutcome)4 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)3 ReserveOfferRecommendation (com.mesosphere.sdk.offer.ReserveOfferRecommendation)3 UnreserveOfferRecommendation (com.mesosphere.sdk.offer.UnreserveOfferRecommendation)3 VolumeSpec (com.mesosphere.sdk.specification.VolumeSpec)3 TaskSpec (com.mesosphere.sdk.specification.TaskSpec)2 Collectors (java.util.stream.Collectors)2 TextFormat (com.google.protobuf.TextFormat)1 DcosConstants (com.mesosphere.sdk.dcos.DcosConstants)1 ResourceRefinementCapabilityContext (com.mesosphere.sdk.dcos.ResourceRefinementCapabilityContext)1 com.mesosphere.sdk.offer (com.mesosphere.sdk.offer)1 Constants (com.mesosphere.sdk.offer.Constants)1 com.mesosphere.sdk.offer.taskdata (com.mesosphere.sdk.offer.taskdata)1 PodSpec (com.mesosphere.sdk.specification.PodSpec)1 PortSpec (com.mesosphere.sdk.specification.PortSpec)1 TestConstants (com.mesosphere.sdk.testutils.TestConstants)1 java.util (java.util)1