use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityAgentAndRackManager method agentLost.
void agentLost(AgentID agentIdObj) {
final String agentId = agentIdObj.getValue();
Optional<SingularityAgent> agent = agentManager.getObject(agentId);
if (agent.isPresent()) {
MachineState previousState = agent.get().getCurrentState().getState();
agentManager.changeState(agent.get(), MachineState.DEAD, Optional.empty(), Optional.empty());
if (configuration.getDisasterDetection().isEnabled()) {
updateDisasterCounter(previousState);
}
checkRackAfterAgentLoss(agent.get());
} else {
LOG.warn("Lost a agent {}, but didn't know about it", agentId);
}
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityAgentAndRackManager method loadAgentsAndRacksFromMaster.
public void loadAgentsAndRacksFromMaster(MesosMasterStateObject state, boolean isStartup) {
Map<String, SingularityAgent> activeAgentsById = agentManager.getObjectsByIdForState(MachineState.ACTIVE);
Map<String, SingularityRack> activeRacksById = rackManager.getObjectsByIdForState(MachineState.ACTIVE);
Map<String, SingularityRack> remainingActiveRacks = Maps.newHashMap(activeRacksById);
int agents = 0;
int racks = 0;
for (MesosMasterAgentObject agentJsonObject : state.getAgents()) {
String agentId = agentJsonObject.getId();
String rackId = agentAndRackHelper.getRackId(agentJsonObject.getAttributes());
Map<String, String> textAttributes = agentAndRackHelper.getTextAttributes(agentJsonObject.getAttributes());
String host = agentAndRackHelper.getMaybeTruncatedHost(agentJsonObject.getHostname());
if (activeAgentsById.containsKey(agentId)) {
SingularityAgent agent = activeAgentsById.get(agentId);
if (agent != null && (!agent.getResources().isPresent() || !agent.getResources().get().equals(agentJsonObject.getResources()))) {
LOG.trace("Found updated resources ({}) for agent {}", agentJsonObject.getResources(), agent);
agentManager.saveObject(agent.withResources(agentJsonObject.getResources()));
}
activeAgentsById.remove(agentId);
} else {
SingularityAgent newAgent = new SingularityAgent(agentId, host, rackId, textAttributes, Optional.of(agentJsonObject.getResources()));
if (check(newAgent, agentManager) == CheckResult.NEW) {
agents++;
}
}
if (activeRacksById.containsKey(rackId)) {
remainingActiveRacks.remove(rackId);
} else {
SingularityRack rack = new SingularityRack(rackId);
if (check(rack, rackManager) == CheckResult.NEW) {
racks++;
}
}
}
for (SingularityAgent leftOverAgent : activeAgentsById.values()) {
agentManager.changeState(leftOverAgent, isStartup ? MachineState.MISSING_ON_STARTUP : MachineState.DEAD, Optional.empty(), Optional.empty());
}
for (SingularityRack leftOverRack : remainingActiveRacks.values()) {
rackManager.changeState(leftOverRack, isStartup ? MachineState.MISSING_ON_STARTUP : MachineState.DEAD, Optional.empty(), Optional.empty());
}
LOG.info("Found {} new racks ({} missing) and {} new agents ({} missing)", racks, remainingActiveRacks.size(), agents, activeAgentsById.size());
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityAgentAndRackManager method checkOffer.
public CheckResult checkOffer(Offer offer) {
final String agentId = offer.getAgentId().getValue();
final String rackId = agentAndRackHelper.getRackIdOrDefault(offer);
final String host = agentAndRackHelper.getMaybeTruncatedHost(offer);
final Map<String, String> textAttributes = agentAndRackHelper.getTextAttributes(offer);
final SingularityAgent agent = new SingularityAgent(agentId, host, rackId, textAttributes, Optional.empty());
CheckResult result = check(agent, agentManager);
if (result == CheckResult.NEW) {
if (inactiveAgentManager.isInactive(agent.getHost())) {
LOG.info("Agent {} on inactive host {} attempted to rejoin. Marking as decommissioned.", agent, host);
agentManager.changeState(agent, MachineState.STARTING_DECOMMISSION, Optional.of(String.format("Agent %s on inactive host %s attempted to rejoin cluster.", agentId, host)), Optional.empty());
} else {
LOG.info("Offer revealed a new agent {}", agent);
}
}
final SingularityRack rack = new SingularityRack(rackId);
if (check(rack, rackManager) == CheckResult.NEW) {
LOG.info("Offer revealed a new rack {}", rack);
}
return result;
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityMachinesTest method testReconcileSlavesOnStartup.
@Test
public void testReconcileSlavesOnStartup() {
// Load 3 agents on startup
MesosMasterStateObject state = getMasterState(3);
singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(state, true);
// Load 2 agents on startup
// 2 agents, third has died
MesosMasterStateObject newState = getMasterState(2);
singularityAgentAndRackManager.loadAgentsAndRacksFromMaster(newState, true);
List<SingularityAgent> agents = agentManager.getObjects();
Assertions.assertEquals(3, agents.size());
for (SingularityAgent agent : agents) {
if (agent.getId().equals("2")) {
Assertions.assertEquals(MachineState.MISSING_ON_STARTUP, agent.getCurrentState().getState());
} else {
Assertions.assertEquals(MachineState.ACTIVE, agent.getCurrentState().getState());
}
}
}
use of com.hubspot.singularity.SingularityAgent in project Singularity by HubSpot.
the class SingularityMachinesTest method testBadExpiringStateTransition.
@Test
public void testBadExpiringStateTransition() {
SingularityAgent agent = getSingleSlave();
Assertions.assertThrows(WebApplicationException.class, () -> agentResource.decommissionAgent(singularityUser, agent.getId(), new SingularityMachineChangeRequest(Optional.of(1L), Optional.empty(), Optional.empty(), Optional.of(MachineState.FROZEN), Optional.empty())));
}
Aggregations