Java源码示例:com.containersol.minimesos.state.State
示例1
@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());
}
示例2
@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());
}
}
}
示例3
@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());
}
示例4
@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);
}
}
示例5
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);
}
});
}
示例6
@Test
public void mesosClusterCanBeStarted() throws Exception {
MesosMaster master = CLUSTER.getMaster();
State state = master.getState();
Assert.assertEquals(3, state.getActivatedAgents());
}
示例7
@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);
}
示例8
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;
}
示例9
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;
}
示例10
@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);
}
示例11
public State getStateInfo(MesosCluster cluster) throws UnirestException, JsonParseException, JsonMappingException {
return State.fromJSON(cluster.getClusterStateInfo().toString(2));
}
示例12
/**
* Retrieve state of the Master or Agent.
*
* @return state object with frameworks and tasks
*/
State getState();