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