Skip to content

Commit

Permalink
Implemented AGENT_ADDED and AGENT_REMOVED events.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhitaoli authored and hatred committed Oct 7, 2016
1 parent c9c7f33 commit a68671a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/common/protobuf_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,31 @@ mesos::master::Response::GetAgents::Agent createAgentResponse(
return agent;
}


mesos::master::Event createAgentAdded(
const mesos::internal::master::Slave& slave)
{
mesos::master::Event event;
event.set_type(mesos::master::Event::AGENT_ADDED);

event.mutable_agent_added()->mutable_agent()->CopyFrom(
createAgentResponse(slave));

return event;
}


mesos::master::Event createAgentRemoved(const SlaveID& slaveId)
{
mesos::master::Event event;
event.set_type(mesos::master::Event::AGENT_REMOVED);

event.mutable_agent_removed()->mutable_agent_id()->CopyFrom(
slaveId);

return event;
}

} // namespace event {
} // namespace master {

Expand Down
9 changes: 9 additions & 0 deletions src/common/protobuf_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ mesos::master::Event createTaskAdded(const Task& task);
mesos::master::Response::GetAgents::Agent createAgentResponse(
const mesos::internal::master::Slave& slave);


// Helper for creating an `AGENT_ADDED` event from a `Slave`.
mesos::master::Event createAgentAdded(
const mesos::internal::master::Slave& slave);


// Helper for creating an `AGENT_REMOVED` event from a `SlaveID`.
mesos::master::Event createAgentRemoved(const SlaveID& slaveId);

} // namespace event {
} // namespace master {

Expand Down
8 changes: 8 additions & 0 deletions src/master/master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7341,6 +7341,10 @@ void Master::addSlave(
unavailability,
slave->totalResources,
slave->usedResources);

if (!subscribers.subscribed.empty()) {
subscribers.send(protobuf::master::event::createAgentAdded(*slave));
}
}


Expand Down Expand Up @@ -7507,6 +7511,10 @@ void Master::_removeSlave(

sendSlaveLost(slave->info);

if (!subscribers.subscribed.empty()) {
subscribers.send(protobuf::master::event::createAgentRemoved(slave->id));
}

delete slave;
}

Expand Down

0 comments on commit a68671a

Please sign in to comment.