Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Allow a new lease on single offer mode if there aren't any leases (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
corindwyer authored Jun 5, 2020
1 parent 66ecaca commit 8c82038
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,14 @@ String getCurrVMId() {
boolean addLease(VirtualMachineLease lease) {
if (logger.isDebugEnabled())
logger.debug("{}: adding lease id {}", hostname, lease.getId());
if(singleLeaseMode && firstLeaseAdded)
return false;
if(singleLeaseMode && firstLeaseAdded) {
if (leasesMap.isEmpty()) {
leasesMap.put(lease.getId(), lease);
return true;
} else {
return false;
}
}
if(!Objects.equals(currVMId, lease.getVMID())) {
currVMId = lease.getVMID();
vmIdToHostnameMap.put(lease.getVMID(), hostname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.netflix.fenzo;

import com.netflix.fenzo.functions.Action1;
import org.apache.mesos.Protos;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -150,4 +151,37 @@ public void testInsufficientScalarResourcesWithSingleLeaseMode() {
Assert.assertEquals(VMResource.Other, result.getFailures().values().iterator().next().get(0).getFailures().get(0).getResource());
System.out.println(result.getFailures().values().iterator().next().get(0).getFailures().get(0));
}

@Test
public void testRemovingLeaseAndAddingBackSameLeaseWithSingleLeaseMode() {
final TaskScheduler scheduler = getScheduler(true);

final TaskRequest task = TaskRequestProvider.getTaskRequest(null, 1, 1, 1,
1, 1, null, null, null, Collections.emptyMap());

final VirtualMachineLease lease1 = LeaseProvider.getLeaseOffer("host1", 1.0, 1.0, 1, 1,
Collections.singletonList(new VirtualMachineLease.Range(1, 10)), null, Collections.emptyMap());

final SchedulingResult result1 = scheduler.scheduleOnce(Collections.singletonList(task), Collections.singletonList(lease1));
Assert.assertEquals(0, result1.getFailures().size());
Assert.assertEquals(1, result1.getResultMap().size());

// Expire the leases and run a scheduling loop to make sure they are gone
scheduler.expireAllLeases();
scheduler.scheduleOnce(Collections.emptyList(), Collections.emptyList());

List<VirtualMachineCurrentState> vmCurrentStates1 = scheduler.getVmCurrentStates();
Collection<Protos.Offer> offers1 = vmCurrentStates1.get(0).getAllCurrentOffers();
Assert.assertEquals(0, offers1.size());

// Run another scheduling iteration with the same lease and make sure it can be added back as an offer
final SchedulingResult result2 = scheduler.scheduleOnce(Collections.singletonList(task), Collections.singletonList(lease1));
Assert.assertEquals(0, result2.getFailures().size());
Assert.assertEquals(1, result2.getResultMap().size());

List<VirtualMachineCurrentState> vmCurrentStates2 = scheduler.getVmCurrentStates();
Collection<Protos.Offer> offers2 = vmCurrentStates2.get(0).getAllCurrentOffers();
Assert.assertEquals(1, offers2.size());
System.out.println(vmCurrentStates2.get(0).getAllCurrentOffers());
}
}

0 comments on commit 8c82038

Please sign in to comment.