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