use of com.hubspot.mesos.json.MesosMasterAgentObject in project Singularity by HubSpot.
the class SingularityMachinesTest method getMasterState.
private MesosMasterStateObject getMasterState(int numSlaves) {
long now = System.currentTimeMillis();
Map<String, Object> resources = new HashMap<>();
resources.put("cpus", 10);
resources.put("mem", 2000);
Map<String, String> attributes = new HashMap<>();
attributes.put("testKey", "testValue");
List<MesosMasterAgentObject> agents = new ArrayList<>();
for (Integer i = 0; i < numSlaves; i++) {
agents.add(new MesosMasterAgentObject(i.toString(), i.toString(), String.format("localhost:505%s", i), now, new MesosResourcesObject(resources), attributes, new MesosResourcesObject(resources), new MesosResourcesObject(resources), new MesosResourcesObject(resources), new MesosResourcesObject(resources), "", true));
}
MesosFrameworkObject framework = new MesosFrameworkObject("", "", "", "", "", "", "", now, now, now, true, true, new MesosResourcesObject(resources), new MesosResourcesObject(resources), new MesosResourcesObject(resources), Collections.emptyList());
return new MesosMasterStateObject("", "", "", "", now, "", now, now, "", "", "", 0, 0, "", "", "", Collections.emptyMap(), agents, Collections.singletonList(framework));
}
use of com.hubspot.mesos.json.MesosMasterAgentObject in project Singularity by HubSpot.
the class SingularityAgentAndRackManager method checkDecommissionedAgentsFromMaster.
public void checkDecommissionedAgentsFromMaster(MesosMasterStateObject state, boolean isStartup) {
Map<String, SingularityAgent> agentsById = agentManager.getObjectsByIdForState(MachineState.DECOMMISSIONED);
for (MesosMasterAgentObject agentJsonObject : state.getAgents()) {
String agentId = agentJsonObject.getId();
agentsById.remove(agentId);
}
for (SingularityAgent leftOverAgent : agentsById.values()) {
MachineState newState = isStartup ? MachineState.MISSING_ON_STARTUP : MachineState.DEAD;
LOG.info("Marking decommissioned agent without mesos resources as {}", newState);
agentManager.changeState(leftOverAgent, newState, Optional.empty(), Optional.empty());
}
}
use of com.hubspot.mesos.json.MesosMasterAgentObject 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());
}
Aggregations