Skip to content

Commit

Permalink
Updated declineOffer use Call::DECLINE to decline offer.
Browse files Browse the repository at this point in the history
  • Loading branch information
gyliu513 authored and vinodkone committed Nov 3, 2015
1 parent 82b6112 commit 0de0a19
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
40 changes: 37 additions & 3 deletions src/sched/sched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,29 @@ class SchedulerProcess : public ProtobufProcess<SchedulerProcess>
send(master.get().pid(), call);
}

void declineOffer(
const OfferID& offerId,
const Filters& filters)
{
if (!connected) {
VLOG(1) << "Ignoring decline offer message as master is disconnected";
return;
}

Call call;

CHECK(framework.has_id());
call.mutable_framework_id()->CopyFrom(framework.id());
call.set_type(Call::DECLINE);

Call::Decline* decline = call.mutable_decline();
decline->add_offer_ids()->CopyFrom(offerId);
decline->mutable_filters()->CopyFrom(filters);

CHECK_SOME(master);
send(master.get().pid(), call);
}

void reviveOffers()
{
if (!connected) {
Expand Down Expand Up @@ -1938,10 +1961,21 @@ Status MesosSchedulerDriver::declineOffer(
const OfferID& offerId,
const Filters& filters)
{
vector<OfferID> offerIds;
offerIds.push_back(offerId);
synchronized (mutex) {
if (status != DRIVER_RUNNING) {
return status;
}

return launchTasks(offerIds, vector<TaskInfo>(), filters);
CHECK(process != NULL);

dispatch(
process,
&SchedulerProcess::declineOffer,
offerId,
filters);

return status;
}
}


Expand Down
6 changes: 3 additions & 3 deletions src/tests/master_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2635,8 +2635,8 @@ TEST_F(MasterTest, OfferNotRescindedOnceDeclined)
EXPECT_CALL(sched, resourceOffers(_, _))
.WillRepeatedly(DeclineOffers()); // Decline all offers.

Future<mesos::scheduler::Call> acceptCall = FUTURE_CALL(
mesos::scheduler::Call(), mesos::scheduler::Call::ACCEPT, _, _);
Future<mesos::scheduler::Call> declineCall = FUTURE_CALL(
mesos::scheduler::Call(), mesos::scheduler::Call::DECLINE, _, _);

EXPECT_CALL(sched, offerRescinded(&driver, _))
.Times(0);
Expand All @@ -2645,7 +2645,7 @@ TEST_F(MasterTest, OfferNotRescindedOnceDeclined)
AWAIT_READY(registered);

// Wait for the framework to decline the offers.
AWAIT_READY(acceptCall);
AWAIT_READY(declineCall);

// Now advance to the offer timeout, we need to settle the clock to
// ensure that the offer rescind timeout would be processed
Expand Down

0 comments on commit 0de0a19

Please sign in to comment.