use of org.eclipse.linuxtools.internal.docker.core.DockerImageSearchResult 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;
}
Aggregations