Search in sources :

Example 16 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class OfferEvaluatorVolumesTest method testFailCreateRootVolume.

@Test
public void testFailCreateRootVolume() throws Exception {
    Resource offeredResource = ResourceTestUtils.getUnreservedDisk(1000);
    List<OfferRecommendation> recommendations = evaluator.evaluate(PodInstanceRequirementTestUtils.getRootVolumeRequirement(1.0, 1500), Arrays.asList(OfferTestUtils.getCompleteOffer(offeredResource)));
    Assert.assertEquals(0, recommendations.size());
}
Also used : Resource(org.apache.mesos.Protos.Resource) OfferRecommendation(com.mesosphere.sdk.offer.OfferRecommendation) Test(org.junit.Test)

Example 17 with Resource

use of org.apache.mesos.Protos.Resource in project incubator-myriad by apache.

the class OfferUtilsTest method generateResources.

private List<Resource> generateResources() {
    Resource rOne = Protos.Resource.newBuilder().setName("cpus").setType(Value.Type.SCALAR).setScalar(Scalar.newBuilder().setValue(0.5)).build();
    Resource rTwo = Protos.Resource.newBuilder().setName("mem").setType(Value.Type.SCALAR).setScalar(Scalar.newBuilder().setValue(1.0)).build();
    Resource rThree = Protos.Resource.newBuilder().setName("cpus").setType(Value.Type.SCALAR).setScalar(Scalar.newBuilder().setValue(1.0)).build();
    Resource rFour = Protos.Resource.newBuilder().setName("mem").setType(Value.Type.SCALAR).setScalar(Scalar.newBuilder().setValue(2.0)).build();
    return Lists.newArrayList(rOne, rTwo, rThree, rFour);
}
Also used : Resource(org.apache.mesos.Protos.Resource)

Example 18 with Resource

use of org.apache.mesos.Protos.Resource in project storm-mesos by nathanmarz.

the class MesosNimbus method getResources.

private OfferResources getResources(Offer offer, int cpu, int mem) {
    OfferResources resources = new OfferResources();
    for (Resource r : offer.getResourcesList()) {
        if (r.getName().equals("cpus")) {
            resources.cpuSlots = (int) Math.floor(r.getScalar().getValue() / cpu);
        } else if (r.getName().equals("mem")) {
            resources.memSlots = (int) Math.floor(r.getScalar().getValue() / mem);
        }
    }
    int maxPorts = Math.min(resources.cpuSlots, resources.memSlots);
    for (Resource r : offer.getResourcesList()) {
        if (r.getName().equals("ports")) {
            for (Range range : r.getRanges().getRangeList()) {
                if (resources.ports.size() >= maxPorts) {
                    break;
                } else {
                    int start = (int) range.getBegin();
                    int end = (int) range.getEnd();
                    for (int p = start; p <= end; p++) {
                        resources.ports.add(p);
                        if (resources.ports.size() >= maxPorts) {
                            break;
                        }
                    }
                }
            }
        }
    }
    LOG.debug("Offer: " + offer.toString());
    LOG.debug("Extracted resources: " + resources.toString());
    return resources;
}
Also used : Resource(org.apache.mesos.Protos.Resource) Range(org.apache.mesos.Protos.Value.Range)

Example 19 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class MesosResourcePool method consumeReserved.

public Optional<MesosResource> consumeReserved(String name, Value value, String resourceId) {
    MesosResource mesosResource = dynamicallyReservedPoolByResourceId.get(resourceId);
    if (mesosResource != null) {
        if (mesosResource.isAtomic()) {
            if (sufficientValue(value, mesosResource.getValue())) {
                dynamicallyReservedPoolByResourceId.remove(resourceId);
            } else {
                LOGGER.warn("Reserved atomic quantity of {} is insufficient: desired {}, reserved {}", name, TextFormat.shortDebugString(value), TextFormat.shortDebugString(mesosResource.getValue()));
                return Optional.empty();
            }
        } else {
            Value availableValue = mesosResource.getValue();
            if (ValueUtils.compare(availableValue, value) > 0) {
                // Update the value in pool with the remaining unclaimed resource amount
                Resource remaining = ResourceBuilder.fromExistingResource(mesosResource.getResource()).setValue(ValueUtils.subtract(availableValue, value)).build();
                dynamicallyReservedPoolByResourceId.put(resourceId, new MesosResource(remaining));
            // Return only the claimed resource amount from this reservation
            } else {
                dynamicallyReservedPoolByResourceId.remove(resourceId);
            }
        }
    } else {
        LOGGER.warn("Failed to find reserved {} resource with ID: {}. Reserved resource IDs are: {}", name, resourceId, dynamicallyReservedPoolByResourceId.keySet());
    }
    return Optional.ofNullable(mesosResource);
}
Also used : Value(org.apache.mesos.Protos.Value) Resource(org.apache.mesos.Protos.Resource)

Example 20 with Resource

use of org.apache.mesos.Protos.Resource in project dcos-commons by mesosphere.

the class MesosResourcePool method freeAtomicResource.

@SuppressWarnings("deprecation")
private void freeAtomicResource(MesosResource mesosResource) {
    Resource.Builder resBuilder = Resource.newBuilder(mesosResource.getResource());
    resBuilder.clearReservation();
    resBuilder.setRole(Constants.ANY_ROLE);
    if (resBuilder.hasDisk()) {
        Resource.DiskInfo.Builder diskBuilder = Resource.DiskInfo.newBuilder(resBuilder.getDisk());
        diskBuilder.clearPersistence();
        diskBuilder.clearVolume();
        resBuilder.setDisk(diskBuilder.build());
    }
    Resource releasedResource = resBuilder.build();
    List<MesosResource> resList = unreservedAtomicPool.get(mesosResource.getName());
    if (resList == null) {
        resList = new ArrayList<MesosResource>();
    }
    resList.add(new MesosResource(releasedResource));
    unreservedAtomicPool.put(mesosResource.getName(), resList);
}
Also used : Resource(org.apache.mesos.Protos.Resource)

Aggregations

Resource (org.apache.mesos.Protos.Resource)40 Test (org.junit.Test)35 OfferRecommendation (com.mesosphere.sdk.offer.OfferRecommendation)26 Operation (org.apache.mesos.Protos.Offer.Operation)25 PodInstanceRequirement (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirement)13 Protos (org.apache.mesos.Protos)13 TaskInfo (org.apache.mesos.Protos.TaskInfo)12 Offer (org.apache.mesos.Protos.Offer)9 DefaultResourceSet (com.mesosphere.sdk.specification.DefaultResourceSet)4 DefaultVolumeSpec (com.mesosphere.sdk.specification.DefaultVolumeSpec)4 ResourceSet (com.mesosphere.sdk.specification.ResourceSet)4 DiscoveryInfo (org.apache.mesos.Protos.DiscoveryInfo)4 Label (org.apache.mesos.Protos.Label)4 Port (org.apache.mesos.Protos.Port)4 ResourceUtils (com.mesosphere.sdk.offer.ResourceUtils)3 PodInstanceRequirementTestUtils (com.mesosphere.sdk.scheduler.plan.PodInstanceRequirementTestUtils)3 OfferTestUtils (com.mesosphere.sdk.testutils.OfferTestUtils)3 ResourceTestUtils (com.mesosphere.sdk.testutils.ResourceTestUtils)3 TestConstants (com.mesosphere.sdk.testutils.TestConstants)3 Arrays (java.util.Arrays)3