com.containersol.minimesos.state.State Java Examples

The following examples show how to use com.containersol.minimesos.state.State. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParseStateJSONTest.java    From minimesos with Apache License 2.0 6 votes vote down vote up
@Test
public void exampleStateJSONIsParsedCorrectly() throws JsonParseException, JsonMappingException {
    State parsedState = State.fromJSON(EXAMPLE_STATE_JSON);
    assertEquals("20150907-122934-3858764204-5050-23", parsedState.getId());
    assertEquals(1, parsedState.getFrameworks().size());
    Framework framework = parsedState.getFramework("elasticsearch");
    assertNotNull(framework);
    assertEquals("elasticsearch", framework.getName());
    assertEquals(true, framework.isActive());
    assertEquals(true, framework.isCheckpoint());
    assertEquals(2592000, framework.getFailoverTimeout());
    assertEquals("0f43d2f7606a", framework.getHostname());
    assertEquals("20150907-122934-3858764204-5050-23-0000", framework.getId());
    assertEquals("elasticsearch", framework.getName());
    assertEquals("*", framework.getRole());
    assertEquals("0.22.1", parsedState.getVersion());
    assertEquals(0, framework.getExecutors().size());
    assertEquals("29deeca9-0f28-4df7-af1d-14ae790044f6", framework.getTasks().get(0).getExecutorId());
    assertEquals("20150907-122934-3858764204-5050-23-0000", framework.getTasks().get(0).getFrameworkId());
}
 
Example #2
Source File: CommandPs.java    From minimesos with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() {
    MesosCluster cluster = repository.loadCluster(new MesosClusterContainersFactory());

    if (cluster == null) {
        output.println("Minimesos cluster is not running");
        return;
    }

    output.printf(FORMAT, COLUMNS);
    State state = cluster.getMaster().getState();
    for (Framework framework : state.getFrameworks()) {
        for (Task task : framework.getTasks()) {
            output.printf(FORMAT, framework.getName(), task.getName(), task.getState(), task.getDiscovery().getPorts().getPorts().get(0).getNumber());
        }
    }
}
 
Example #3
Source File: DeploymentSystemTest.java    From logstash with Apache License 2.0 6 votes vote down vote up
@Test
public void willAddExecutorOnNewNodes() throws JsonParseException, UnirestException, JsonMappingException {
    deployScheduler(null, null, true, null, false);

    IntStream.range(0, 2).forEach(value -> cluster.addAndStartContainer(new LogstashMesosSlave(dockerClient, cluster.getZkContainer())));

    await().atMost(1, TimeUnit.MINUTES).pollInterval(1, SECONDS).until(
            () -> State.fromJSON(cluster.getClusterStateInfo().toString()).getFramework("logstash").getTasks().stream().filter(task -> task.getState().equals("TASK_RUNNING")).count() == 3
    );

    // TODO use com.containersol.minimesos.state.Task when it exposes the slave_id property https://github.com/ContainerSolutions/minimesos/issues/168
    JSONArray tasks = cluster.getClusterStateInfo().getJSONArray("frameworks").getJSONObject(0).getJSONArray("tasks");
    Set<String> slaveIds = new TreeSet<>();
    for (int i = 0; i < tasks.length(); i++) {
        slaveIds.add(tasks.getJSONObject(i).getString("slave_id"));
    }
    assertEquals(3, slaveIds.size());
}
 
Example #4
Source File: MesosContainerImpl.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Override
public State getState() {
    try {
        return State.fromJSON(getStateInfoJSON().toString());
    } catch (JsonParseException | JsonMappingException | UnirestException e) {
        throw new MinimesosException("Could not retrieve state from Mesos container: " + getName(), e);
    }
}
 
Example #5
Source File: MesosCluster.java    From minimesos with Apache License 2.0 5 votes vote down vote up
public void waitForState(final Predicate<State> predicate) {
    await("Mesos master startup" + clusterConfig.getTimeout()).atMost(clusterConfig.getTimeout(), TimeUnit.SECONDS).until(() -> {
        try {
            assertTrue(predicate.test(State.fromJSON(getMaster().getStateInfoJSON().toString())));
        } catch (InternalServerErrorException | JsonParseException | UnirestException | JsonMappingException e) { //NOSONAR
            throw new AssertionError("Mesos master did not start after " + clusterConfig.getTimeout(), e);
        }
    });
}
 
Example #6
Source File: MesosClusterTest.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Test
public void mesosClusterCanBeStarted() throws Exception {
    MesosMaster master = CLUSTER.getMaster();
    State state = master.getState();

    Assert.assertEquals(3, state.getActivatedAgents());
}
 
Example #7
Source File: CommandLogs.java    From minimesos with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() {
    MesosCluster cluster = repository.loadCluster(new MesosClusterContainersFactory());
    if (cluster == null) {
        output.println("Minimesos cluster is not running");
        return;
    }

    State masterState = cluster.getMaster().getState();
    Task task = findTask(masterState, taskId);
    if (task == null) {
        output.println(String.format("Cannot find task: '%s'", taskId));
        return;
    }

    MesosAgent agent = findAgent(cluster, task.getSlaveId());
    if (agent == null) {
        output.println(String.format("Cannot find agent: '%s'", task.getSlaveId()));
        return;
    }


    String filename = stderr ? "stderr" : "stdout";
    output.println(String.format("[minimesos] Fetching '%s' of task '%s'\n", filename, task.getId()));
    URI fileUrl = getFileUrl(agent, task, filename);
    String content = downloader.getFileContentAsString(fileUrl.toString());
    output.println(content);
}
 
Example #8
Source File: CommandLogs.java    From minimesos with Apache License 2.0 5 votes vote down vote up
private Task findTask(State state, String taskId) {
    for (Framework framework : state.getFrameworks()) {
        for (Task task: framework.getTasks()) {
            if (task.getId().contains(taskId)) {
                return task;
            }
        }
    }
    return null;
}
 
Example #9
Source File: CommandLogs.java    From minimesos with Apache License 2.0 5 votes vote down vote up
private MesosAgent findAgent(MesosCluster cluster, String slaveId) {
    for (MesosAgent agent : cluster.getAgents()) {
        State agentState = agent.getState();
        if (agentState.getId().equals(slaveId)) {
            return agent;
        }
    }
    return null;
}
 
Example #10
Source File: CommandPsTest.java    From minimesos with Apache License 2.0 4 votes vote down vote up
@Test
public void execute() throws UnsupportedEncodingException {
    State state = new State();
    Framework marathon = new Framework();
    marathon.setName("marathon");

    Task task = new Task();
    task.setName("weave-scope");
    task.setState("TASK_RUNNING");

    Port port = new Port();
    port.setNumber(4040);

    Ports ports = new Ports();
    ports.setPorts(singletonList(port));

    Discovery discovery = new Discovery();
    discovery.setPorts(ports);

    task.setDiscovery(discovery);

    ArrayList<Task> tasks = new ArrayList<>();
    tasks.add(task);

    marathon.setTasks(tasks);

    ArrayList<Framework> frameworks = new ArrayList<>();
    frameworks.add(marathon);
    state.setFrameworks(frameworks);

    MesosMasterContainer master = mock(MesosMasterContainer.class);
    when(master.getState()).thenReturn(state);

    MesosCluster mesosCluster = mock(MesosCluster.class);
    when(mesosCluster.getMaster()).thenReturn(master);

    ClusterRepository repository = mock(ClusterRepository.class);
    when(repository.loadCluster(any(MesosClusterFactory.class))).thenReturn(mesosCluster);

    CommandPs commandPs = new CommandPs(ps);
    commandPs.setRepository(repository);

    commandPs.execute();

    String result = outputStream.toString("UTF-8");
    assertEquals(String.format(FORMAT, COLUMNS) + String.format(FORMAT, VALUES), result);
}
 
Example #11
Source File: FrameworkRoleSystemTest.java    From elasticsearch with Apache License 2.0 4 votes vote down vote up
public State getStateInfo(MesosCluster cluster) throws UnirestException, JsonParseException, JsonMappingException {
    return State.fromJSON(cluster.getClusterStateInfo().toString(2));
}
 
Example #12
Source File: MesosContainer.java    From minimesos with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve state of the Master or Agent.
 *
 * @return state object with frameworks and tasks
 */
State getState();