use of org.eclipse.che.plugin.docker.client.json.ContainerListEntry in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToParseResponseStreamAsEmptyListOfContainersAndClose.
@Test
public void shouldBeAbleToParseResponseStreamAsEmptyListOfContainersAndClose() throws IOException, JsonParseException {
String response = "[]";
List<ContainerListEntry> containers = dockerConnector.parseResponseStreamAndClose(new ByteArrayInputStream(response.getBytes()), new TypeToken<List<ContainerListEntry>>() {
});
assertEquals(containers.size(), 0);
}
use of org.eclipse.che.plugin.docker.client.json.ContainerListEntry in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToGetListContainersByFiltersInTheListContainersParams.
@Test
public void shouldBeAbleToGetListContainersByFiltersInTheListContainersParams() throws IOException, JsonParseException {
Filters filters = new Filters().withFilter("testKey", "testValue");
ListContainersParams listContainersParams = ListContainersParams.create().withFilters(filters);
ContainerListEntry containerListEntry = mock(ContainerListEntry.class);
List<ContainerListEntry> expectedListContainers = singletonList(containerListEntry);
doReturn(expectedListContainers).when(dockerConnector).parseResponseStreamAndClose(eq(inputStream), Matchers.<TypeToken<List<ContainerListEntry>>>any());
List<ContainerListEntry> containers = dockerConnector.listContainers(listContainersParams);
verify(dockerConnection).query(eq("filters"), anyObject());
assertEquals(containers, expectedListContainers);
}
use of org.eclipse.che.plugin.docker.client.json.ContainerListEntry in project che by eclipse.
the class DockerAbandonedResourcesCleaner method cleanContainers.
/**
* Cleans up CHE docker containers which don't tracked by API any more.
*/
@VisibleForTesting
void cleanContainers() {
List<String> activeContainers = new ArrayList<>();
try {
for (ContainerListEntry container : dockerConnector.listContainers()) {
String containerName = container.getNames()[0];
Optional<ContainerNameInfo> optional = nameGenerator.parse(containerName);
if (optional.isPresent()) {
try {
// container is orphaned if not found exception is thrown
environmentEngine.getMachine(optional.get().getWorkspaceId(), optional.get().getMachineId());
activeContainers.add(containerName);
} catch (NotFoundException e) {
cleanUpContainer(container);
} catch (Exception e) {
LOG.error(format("Failed to check activity for container with name '%s'. Cause: %s", containerName, e.getLocalizedMessage()), e);
}
}
}
} catch (IOException e) {
LOG.error("Failed to get list docker containers", e);
} catch (Exception e) {
LOG.error("Failed to clean up inactive containers", e);
}
LOG.info("List containers registered in the api: " + activeContainers);
}
use of org.eclipse.che.plugin.docker.client.json.ContainerListEntry in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToParseResponseStreamAsListOfContainersAndClose.
@Test
public void shouldBeAbleToParseResponseStreamAsListOfContainersAndClose() throws IOException, JsonParseException {
String response = " [\n" + " {\n" + " \"Id\": \"8dfafdbc3a40\",\n" + " \"Image\": \"ubuntu:latest\",\n" + " \"Command\": \"echo 1\",\n" + " \"Created\": 1367854155,\n" + " \"Status\": \"Exit 0\",\n" + " \"SizeRw\": 12288,\n" + " \"SizeRootFs\": 0\n" + " }" + "]\n";
List<ContainerListEntry> containers = dockerConnector.parseResponseStreamAndClose(new ByteArrayInputStream(response.getBytes()), new TypeToken<List<ContainerListEntry>>() {
});
assertEquals(containers.size(), 1);
ContainerListEntry actualContainer1 = containers.get(0);
assertEquals(actualContainer1.getId(), "8dfafdbc3a40");
assertEquals(actualContainer1.getImage(), "ubuntu:latest");
assertEquals(actualContainer1.getCommand(), "echo 1");
assertEquals(actualContainer1.getCreated(), 1367854155);
assertEquals(actualContainer1.getStatus(), "Exit 0");
assertEquals(actualContainer1.getSizeRw(), 12288);
assertEquals(actualContainer1.getSizeRootFs(), 0);
}
use of org.eclipse.che.plugin.docker.client.json.ContainerListEntry in project che by eclipse.
the class DockerConnectorTest method shouldCallListContainersWithParametersObject.
@Test
public void shouldCallListContainersWithParametersObject() throws IOException {
ListContainersParams listContainersParams = ListContainersParams.create().withAll(true);
ContainerListEntry containerListEntry = mock(ContainerListEntry.class);
List<ContainerListEntry> expectedListContainers = singletonList(containerListEntry);
doReturn(expectedListContainers).when(dockerConnector).listContainers(listContainersParams);
List<ContainerListEntry> result = dockerConnector.listContainers();
ArgumentCaptor<ListContainersParams> listContainersParamsArgumentCaptor = ArgumentCaptor.forClass(ListContainersParams.class);
verify(dockerConnector).listContainers(listContainersParamsArgumentCaptor.capture());
assertEquals(result, expectedListContainers);
assertEquals(listContainersParamsArgumentCaptor.getValue(), listContainersParams);
}
Aggregations