public DestroyOfferRecommendation(Protos.Offer offer, Protos.Resource resource) { this.offer = offer; this.operation = Protos.Offer.Operation.newBuilder() .setType(Protos.Offer.Operation.Type.DESTROY) .setDestroy(Protos.Offer.Operation.Destroy.newBuilder() .addAllVolumes(Arrays.asList(Protos.Resource.newBuilder(resource) .clearRevocable() .build()))) .build(); this.resource = resource; }
public UnreserveOfferRecommendation(Offer offer, Resource resource) { this.offer = offer; Resource.Builder resourceBuilder = resource.toBuilder(); Resource resourceR; // If non-root disk resource, we want to clear ALL fields except for the field indicating the disk source. if (resource.hasDisk() && resource.getDisk().hasSource()) { resourceR = resourceBuilder .setDisk(Resource.DiskInfo.newBuilder().setSource(resource.getDisk().getSource())) .build(); } else { resourceR = resourceBuilder.clearDisk().clearRevocable().build(); } this.operation = Operation.newBuilder() .setType(Operation.Type.UNRESERVE) .setUnreserve( Operation.Unreserve.newBuilder().addAllResources(Collections.singletonList(resourceR)) ) .build(); this.resource = resourceR; }
@Test public void testUnreserveRootDisk() { Protos.Resource resource = ResourceTestUtils.getReservedRootVolume(1); Protos.Offer offer = OfferTestUtils.getOffer(resource); UnreserveOfferRecommendation unreserveOfferRecommendation = new UnreserveOfferRecommendation(offer, resource); Protos.Offer.Operation operation = unreserveOfferRecommendation.getOperation().get(); Assert.assertEquals(1, operation.getUnreserve().getResourcesCount()); Protos.Resource opResource = operation.getUnreserve().getResources(0); Assert.assertFalse(opResource.hasDisk()); Assert.assertFalse(opResource.hasRevocable()); resource = resource.toBuilder().clearDisk().clearRevocable().build(); Assert.assertEquals(resource, opResource); }
/** * The resource passed in is the fully completed Resource which will be launched. This may include volume/disk * information which is not appropriate for the RESERVE operation. It is filtered out here. */ private static Protos.Resource getReservedResource(Protos.Resource resource) { // The resource passed in is the fully completed Resource which will be launched. This may include volume/disk // information which is not appropriate for the RESERVE operation. It is filtered out here. Protos.Resource.Builder resBuilder = Protos.Resource.newBuilder(resource); if (resBuilder.hasDisk() && resBuilder.getDisk().hasSource()) { // Mount volume: Copy disk, but without 'persistence' nor 'volume' fields resBuilder.setDisk(Protos.Resource.DiskInfo.newBuilder(resBuilder.getDisk()) .clearPersistence() .clearVolume()); } else { // Root volume: Clear the disk. resBuilder.clearDisk(); } resBuilder.clearRevocable(); return resBuilder.build(); }