Search in sources :

Example 1 with MesosMasterAgentObject

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));
}
Also used : MesosResourcesObject(com.hubspot.mesos.json.MesosResourcesObject) HashMap(java.util.HashMap) MesosFrameworkObject(com.hubspot.mesos.json.MesosFrameworkObject) ArrayList(java.util.ArrayList) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) MesosResourcesObject(com.hubspot.mesos.json.MesosResourcesObject) MesosMasterAgentObject(com.hubspot.mesos.json.MesosMasterAgentObject) MesosFrameworkObject(com.hubspot.mesos.json.MesosFrameworkObject) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) MesosMasterAgentObject(com.hubspot.mesos.json.MesosMasterAgentObject)

Example 2 with MesosMasterAgentObject

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());
    }
}
Also used : SingularityAgent(com.hubspot.singularity.SingularityAgent) MesosMasterAgentObject(com.hubspot.mesos.json.MesosMasterAgentObject) MachineState(com.hubspot.singularity.MachineState)

Example 3 with MesosMasterAgentObject

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());
}
Also used : SingularityRack(com.hubspot.singularity.SingularityRack) SingularityAgent(com.hubspot.singularity.SingularityAgent) MesosMasterAgentObject(com.hubspot.mesos.json.MesosMasterAgentObject)

Aggregations

MesosMasterAgentObject (com.hubspot.mesos.json.MesosMasterAgentObject)3 SingularityAgent (com.hubspot.singularity.SingularityAgent)2 MesosFrameworkObject (com.hubspot.mesos.json.MesosFrameworkObject)1 MesosMasterStateObject (com.hubspot.mesos.json.MesosMasterStateObject)1 MesosResourcesObject (com.hubspot.mesos.json.MesosResourcesObject)1 MachineState (com.hubspot.singularity.MachineState)1 SingularityRack (com.hubspot.singularity.SingularityRack)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1