Search in sources :

Example 1 with RepositoryTag

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());
}
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) GenericType(javax.ws.rs.core.GenericType) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) WebTarget(javax.ws.rs.client.WebTarget) Map(java.util.Map)

Example 2 with RepositoryTag

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);
    }
}
Also used : IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) TableViewer(org.eclipse.jface.viewers.TableViewer) Activator(org.eclipse.linuxtools.docker.ui.Activator) TableColumn(org.eclipse.swt.widgets.TableColumn) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Table(org.eclipse.swt.widgets.Table) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) Composite(org.eclipse.swt.widgets.Composite) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IconColumnLabelProvider(org.eclipse.linuxtools.internal.docker.ui.wizards.ImageSearchPage.IconColumnLabelProvider) WizardPage(org.eclipse.jface.wizard.WizardPage) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) ViewerProperties(org.eclipse.jface.databinding.viewers.ViewerProperties) BlockingQueue(java.util.concurrent.BlockingQueue) IRegistry(org.eclipse.linuxtools.docker.core.IRegistry) Display(org.eclipse.swt.widgets.Display) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) TimeUnit(java.util.concurrent.TimeUnit) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) List(java.util.List) SWTImagesFactory(org.eclipse.linuxtools.internal.docker.ui.SWTImagesFactory) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) RepositoryTagV2(org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2) Collections(java.util.Collections) IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) DockerException(org.eclipse.linuxtools.docker.core.DockerException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) RepositoryTag(org.eclipse.linuxtools.internal.docker.core.RepositoryTag) IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) ArrayList(java.util.ArrayList) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 RepositoryTag (org.eclipse.linuxtools.internal.docker.core.RepositoryTag)2 RepositoryTagV2 (org.eclipse.linuxtools.internal.docker.core.RepositoryTagV2)2 ObjectMapperProvider (com.spotify.docker.client.ObjectMapperProvider)1 ImageSearchResult (com.spotify.docker.client.messages.ImageSearchResult)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collections (java.util.Collections)1 Map (java.util.Map)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)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