use of org.eclipse.linuxtools.internal.docker.core.RepositoryTag in project linuxtools by eclipse.
the class AbstractRegistry method retrieveTagsFromRegistryV1.
/**
* Retrieves the list of tags for a given repository, assuming that the
* target registry is a registry v2 instance.
*
* @param client
* the client to use
* @param repository
* the repository to look-up
* @return the list of tags for the given repository
* @throws CancellationException
* - if the computation was cancelled
* @throws ExecutionException
* - if the computation threw an exception
* @throws InterruptedException
* - if the current thread was interrupted while waiting
*/
private List<IRepositoryTag> retrieveTagsFromRegistryV1(final Client client, final String repository) throws InterruptedException, ExecutionException {
final GenericType<Map<String, String>> REPOSITORY_TAGS_RESULT_LIST = new GenericType<Map<String, String>>() {
};
final WebTarget queryTagsResource = client.target(getHTTPServerAddress()).path(// $NON-NLS-1$
"v1").path("repositories").path(repository).path(// $NON-NLS-1$ //$NON-NLS-2$
"tags");
return queryTagsResource.request(APPLICATION_JSON_TYPE).async().method(GET, REPOSITORY_TAGS_RESULT_LIST).get().entrySet().stream().map(e -> new RepositoryTag(e.getKey(), e.getValue())).collect(Collectors.toList());
}
use of org.eclipse.linuxtools.internal.docker.core.RepositoryTag in project linuxtools by eclipse.
the class ImageTagSelectionPage method searchTags.
private void searchTags() {
try {
final BlockingQueue<List<DockerImageTagSearchResult>> searchResultQueue = new ArrayBlockingQueue<>(1);
ImageTagSelectionPage.this.getContainer().run(true, true, monitor -> {
monitor.beginTask(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.searchTask"), 2);
final String selectedImageName = ImageTagSelectionPage.this.model.getSelectedImage().getName();
try {
final List<IRepositoryTag> repositoryTags = registry.getTags(selectedImageName);
// we have to convert to list of RepositoryTag which
// can be sorted
final List<RepositoryTag> tags = repositoryTags.stream().map(c -> (RepositoryTag) c).collect(Collectors.toList());
Collections.sort(tags);
monitor.worked(1);
final IDockerConnection connection = model.getSelectedConnection();
final List<DockerImageTagSearchResult> searchResults = repositoryTags.stream().map(t -> new DockerImageTagSearchResult(selectedImageName, t, connection.hasImage(selectedImageName, t.getName()))).collect(Collectors.toList());
monitor.worked(1);
searchResultQueue.offer(searchResults);
} catch (DockerException e) {
} finally {
monitor.done();
}
});
List<DockerImageTagSearchResult> res = searchResultQueue.poll(10, TimeUnit.SECONDS);
final List<DockerImageTagSearchResult> searchResult = (res == null) ? new ArrayList<>() : res;
Display.getCurrent().asyncExec(() -> {
ImageTagSelectionPage.this.model.setImageTagSearchResult(searchResult);
// refresh the wizard buttons
getWizard().getContainer().updateButtons();
});
// display a warning in the title area if the search result is empty
if (searchResult.isEmpty()) {
this.setMessage(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.noTagWarning"), WARNING);
} else if (searchResult.size() == 1) {
this.setMessage(WizardMessages.getString(// $NON-NLS-1$
"ImageTagSelectionPage.oneTagMatched"), INFORMATION);
} else {
this.setMessage(WizardMessages.getFormattedString(// $NON-NLS-1$
"ImageTagSelectionPage.tagsMatched", Integer.toString(searchResult.size())), INFORMATION);
}
} catch (InvocationTargetException | InterruptedException e) {
Activator.log(e);
}
}
Aggregations