use of org.eclipse.che.plugin.docker.client.json.Filters 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.Filters in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToGetNetworksWithParams.
@Test
public void shouldBeAbleToGetNetworksWithParams() throws Exception {
// given
Network network = createNetwork();
List<Network> originNetworks = singletonList(network);
ByteArrayInputStream inputStream = new ByteArrayInputStream(GSON.toJson(originNetworks).getBytes());
doReturn(inputStream).when(dockerResponse).getInputStream();
GetNetworksParams getNetworksParams = GetNetworksParams.create().withFilters(new Filters().withFilter("key", "value1", "value2"));
// when
List<Network> actual = dockerConnector.getNetworks(getNetworksParams);
// then
assertEquals(actual, originNetworks);
verify(dockerConnectionFactory).openConnection(any(URI.class));
verify(dockerConnection).method(REQUEST_METHOD_GET);
verify(dockerConnection).path("/networks");
verify(dockerConnection).query(eq("filters"), anyObject());
verify(dockerConnection).request();
verify(dockerResponse).getStatus();
verify(dockerResponse).getInputStream();
}
use of org.eclipse.che.plugin.docker.client.json.Filters in project che by eclipse.
the class OpenShiftConnector method getNetworks.
/**
* In OpenShift, there is only one network in the Docker sense, and it is similar
* to the default bridge network. Rather than implementing all of the filters
* available in the Docker API, we only implement {@code type=["custom"|"builtin"]}.
*
* <p> If type is "custom", null is returned. Otherwise, the default network is returned,
* and the result is effectively the same as {@link DockerConnector#inspectNetwork(String)}
* where the network is "bridge".
*
* @see DockerConnector#getNetworks()
*/
@Override
public List<Network> getNetworks(GetNetworksParams params) throws IOException {
Filters filters = params.getFilters();
List<Network> networks = new ArrayList<>();
List<String> typeFilters = filters.getFilter("type");
if (typeFilters == null || !typeFilters.contains("custom")) {
Network network = inspectNetwork("openshift");
networks.add(network);
}
return networks;
}
use of org.eclipse.che.plugin.docker.client.json.Filters in project che by eclipse.
the class DockerConnector method listContainers.
/**
* Method returns list of docker containers which was filtered by {@link ListContainersParams}
*
* @throws IOException
* when problems occurs with docker api calls
*/
public List<ContainerListEntry> listContainers(ListContainersParams params) throws IOException {
final Filters filters = params.getFilters();
try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("GET").path(apiVersionPathPrefix + "/containers/json")) {
addQueryParamIfNotNull(connection, "all", params.isAll());
addQueryParamIfNotNull(connection, "size", params.isSize());
addQueryParamIfNotNull(connection, "limit", params.getLimit());
addQueryParamIfNotNull(connection, "since", params.getSince());
addQueryParamIfNotNull(connection, "before", params.getBefore());
if (filters != null) {
connection.query("filters", urlPathSegmentEscaper().escape(toJson(filters.getFilters())));
}
DockerResponse response = connection.request();
final int status = response.getStatus();
if (OK.getStatusCode() != status) {
throw getDockerException(response);
}
return parseResponseStreamAndClose(response.getInputStream(), new TypeToken<List<ContainerListEntry>>() {
});
}
}
use of org.eclipse.che.plugin.docker.client.json.Filters in project che by eclipse.
the class DockerConnector method getEvents.
/**
* Get docker events.
* Parameter {@code untilSecond} does nothing if {@code sinceSecond} is 0.<br>
* If {@code untilSecond} and {@code sinceSecond} are 0 method gets new events only (streaming mode).<br>
* If {@code untilSecond} and {@code sinceSecond} are not 0 (but less that current date)
* methods get events that were generated between specified dates.<br>
* If {@code untilSecond} is 0 but {@code sinceSecond} is not method gets old events and streams new ones.<br>
* If {@code sinceSecond} is 0 no old events will be got.<br>
* With some connection implementations method can fail due to connection timeout in streaming mode.
*
* @param messageProcessor
* processor of all found events that satisfy specified parameters
* @throws IOException
* when a problem occurs with docker api calls
*/
public void getEvents(final GetEventsParams params, MessageProcessor<Event> messageProcessor) throws IOException {
final Filters filters = params.getFilters();
try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri).method("GET").path(apiVersionPathPrefix + "/events")) {
addQueryParamIfNotNull(connection, "since", params.getSinceSecond());
addQueryParamIfNotNull(connection, "until", params.getUntilSecond());
if (filters != null) {
connection.query("filters", urlPathSegmentEscaper().escape(toJson(filters.getFilters())));
}
final DockerResponse response = connection.request();
if (OK.getStatusCode() != response.getStatus()) {
throw getDockerException(response);
}
try (InputStream responseStream = response.getInputStream()) {
new MessagePumper<>(new JsonMessageReader<>(responseStream, Event.class), messageProcessor).start();
}
}
}
Aggregations