Search in sources :

Example 1 with MesosMasterSlaveObject

use of com.hubspot.mesos.json.MesosMasterSlaveObject in project Singularity by HubSpot.

the class SingularitySlaveAndRackManager method loadSlavesAndRacksFromMaster.

public void loadSlavesAndRacksFromMaster(MesosMasterStateObject state, boolean isStartup) {
    Map<String, SingularitySlave> activeSlavesById = slaveManager.getObjectsByIdForState(MachineState.ACTIVE);
    Map<String, SingularityRack> activeRacksById = rackManager.getObjectsByIdForState(MachineState.ACTIVE);
    Map<String, SingularityRack> remainingActiveRacks = Maps.newHashMap(activeRacksById);
    int slaves = 0;
    int racks = 0;
    for (MesosMasterSlaveObject slaveJsonObject : state.getSlaves()) {
        String slaveId = slaveJsonObject.getId();
        String rackId = slaveAndRackHelper.getRackId(slaveJsonObject.getAttributes());
        Map<String, String> textAttributes = slaveAndRackHelper.getTextAttributes(slaveJsonObject.getAttributes());
        String host = slaveAndRackHelper.getMaybeTruncatedHost(slaveJsonObject.getHostname());
        if (activeSlavesById.containsKey(slaveId)) {
            SingularitySlave slave = activeSlavesById.get(slaveId);
            if (slave != null && (!slave.getResources().isPresent() || !slave.getResources().get().equals(slaveJsonObject.getResources()))) {
                LOG.trace("Found updated resources ({}) for slave {}", slaveJsonObject.getResources(), slave);
                slaveManager.saveObject(slave.withResources(slaveJsonObject.getResources()));
            }
            activeSlavesById.remove(slaveId);
        } else {
            SingularitySlave newSlave = new SingularitySlave(slaveId, host, rackId, textAttributes, Optional.of(slaveJsonObject.getResources()));
            if (check(newSlave, slaveManager) == CheckResult.NEW) {
                slaves++;
            }
        }
        if (activeRacksById.containsKey(rackId)) {
            remainingActiveRacks.remove(rackId);
        } else {
            SingularityRack rack = new SingularityRack(rackId);
            if (check(rack, rackManager) == CheckResult.NEW) {
                racks++;
            }
        }
    }
    for (SingularitySlave leftOverSlave : activeSlavesById.values()) {
        slaveManager.changeState(leftOverSlave, isStartup ? MachineState.MISSING_ON_STARTUP : MachineState.DEAD, Optional.absent(), Optional.absent());
    }
    for (SingularityRack leftOverRack : remainingActiveRacks.values()) {
        rackManager.changeState(leftOverRack, isStartup ? MachineState.MISSING_ON_STARTUP : MachineState.DEAD, Optional.absent(), Optional.absent());
    }
    LOG.info("Found {} new racks ({} missing) and {} new slaves ({} missing)", racks, remainingActiveRacks.size(), slaves, activeSlavesById.size());
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) MesosMasterSlaveObject(com.hubspot.mesos.json.MesosMasterSlaveObject) SingularityRack(com.hubspot.singularity.SingularityRack)

Example 2 with MesosMasterSlaveObject

use of com.hubspot.mesos.json.MesosMasterSlaveObject in project Singularity by HubSpot.

the class SingularityMachineStatesTest 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<MesosMasterSlaveObject> slaves = new ArrayList<>();
    for (Integer i = 0; i < numSlaves; i++) {
        slaves.add(new MesosMasterSlaveObject(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(), slaves, Collections.singletonList(framework));
}
Also used : MesosResourcesObject(com.hubspot.mesos.json.MesosResourcesObject) HashMap(java.util.HashMap) MesosFrameworkObject(com.hubspot.mesos.json.MesosFrameworkObject) MesosMasterSlaveObject(com.hubspot.mesos.json.MesosMasterSlaveObject) ArrayList(java.util.ArrayList) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject) MesosResourcesObject(com.hubspot.mesos.json.MesosResourcesObject) MesosMasterSlaveObject(com.hubspot.mesos.json.MesosMasterSlaveObject) MesosFrameworkObject(com.hubspot.mesos.json.MesosFrameworkObject) MesosMasterStateObject(com.hubspot.mesos.json.MesosMasterStateObject)

Aggregations

MesosMasterSlaveObject (com.hubspot.mesos.json.MesosMasterSlaveObject)2 MesosFrameworkObject (com.hubspot.mesos.json.MesosFrameworkObject)1 MesosMasterStateObject (com.hubspot.mesos.json.MesosMasterStateObject)1 MesosResourcesObject (com.hubspot.mesos.json.MesosResourcesObject)1 SingularityRack (com.hubspot.singularity.SingularityRack)1 SingularitySlave (com.hubspot.singularity.SingularitySlave)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1