Search in sources :

Example 1 with ImageSearchResultV2

use of org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2 in project linuxtools by eclipse.

the class AbstractRegistry method getImages.

@Override
public List<IDockerImageSearchResult> getImages(String term) throws DockerException {
    final Client client = ClientBuilder.newClient(DEFAULT_CONFIG);
    List<IDockerImageSearchResult> result = new ArrayList<>();
    WebTarget queryImagesResource;
    if (isVersion2()) {
        final GenericType<ImageSearchResultV2> IMAGE_SEARCH_RESULT_LIST = new GenericType<ImageSearchResultV2>() {
        };
        ImageSearchResultV2 cisr = null;
        queryImagesResource = client.target(getHTTPServerAddress()).path("v2").path(// $NON-NLS-1$ //$NON-NLS-2$
        "_catalog");
        try {
            cisr = queryImagesResource.request(APPLICATION_JSON_TYPE).async().method(GET, IMAGE_SEARCH_RESULT_LIST).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new DockerException(e);
        }
        List<ImageSearchResult> tmp = cisr.getRepositories().stream().filter(e -> e.name().contains(term)).collect(Collectors.toList());
        result.addAll(tmp.stream().map(r -> new DockerImageSearchResult(r.description(), r.official(), r.automated(), r.name(), r.starCount())).collect(Collectors.toList()));
    } else {
        ImageSearchResultV1 pisr = null;
        final GenericType<ImageSearchResultV1> IMAGE_SEARCH_RESULT_LIST = new GenericType<ImageSearchResultV1>() {
        };
        int page = 0;
        try {
            while (pisr == null || pisr.getPage() < pisr.getTotalPages()) {
                page++;
                queryImagesResource = client.target(getHTTPServerAddress()).path("v1").path(// $NON-NLS-1$ //$NON-NLS-2$
                "search").queryParam("q", // $NON-NLS-1$
                term).queryParam("page", // $NON-NLS-1$
                page);
                pisr = queryImagesResource.request(APPLICATION_JSON_TYPE).async().method(GET, IMAGE_SEARCH_RESULT_LIST).get();
                List<ImageSearchResult> tmp = pisr.getResult();
                result.addAll(tmp.stream().map(r -> new DockerImageSearchResult(r.description(), r.official(), r.automated(), r.name(), r.starCount())).collect(Collectors.toList()));
            }
        } catch (InterruptedException | ExecutionException e) {
            throw new DockerException(e);
        }
    }
    return result;
}
Also used : GET(javax.ws.rs.HttpMethod.GET) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) TimeoutException(java.util.concurrent.TimeoutException) ArrayList(java.util.ArrayList) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) ClientBuilder(javax.ws.rs.client.ClientBuilder) ImageSearchResultV1(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1) Map(java.util.Map) Status(javax.ws.rs.core.Response.Status) ObjectMapperProvider(com.spotify.docker.client.ObjectMapperProvider) CancellationException(java.util.concurrent.CancellationException) NLS(org.eclipse.osgi.util.NLS) JacksonFeature(org.glassfish.jersey.jackson.JacksonFeature) Collectors(java.util.stream.Collectors) ImageSearchResultV2(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2) BearerTokenResponse(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils.BearerTokenResponse) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) ImageSearchResult(com.spotify.docker.client.messages.ImageSearchResult) Response(javax.ws.rs.core.Response) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) RepositoryTagV2(org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) WebTarget(javax.ws.rs.client.WebTarget) OAuth2Utils(org.eclipse.linuxtools.internal.docker.core.OAuth2Utils) ImageSearchResultV2(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV2) GenericType(javax.ws.rs.core.GenericType) ImageSearchResultV1(org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1) ArrayList(java.util.ArrayList) ImageSearchResult(com.spotify.docker.client.messages.ImageSearchResult) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) DockerImageSearchResult(org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ObjectMapperProvider (com.spotify.docker.client.ObjectMapperProvider)1 ImageSearchResult (com.spotify.docker.client.messages.ImageSearchResult)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 GET (javax.ws.rs.HttpMethod.GET)1 Client (javax.ws.rs.client.Client)1 ClientBuilder (javax.ws.rs.client.ClientBuilder)1 WebTarget (javax.ws.rs.client.WebTarget)1 GenericType (javax.ws.rs.core.GenericType)1 APPLICATION_JSON_TYPE (javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE)1 Response (javax.ws.rs.core.Response)1 Status (javax.ws.rs.core.Response.Status)1 DockerImageSearchResult (org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult)1 ImageSearchResultV1 (org.eclipse.linuxtools.internal.docker.core.ImageSearchResultV1)1