diff --git a/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/Connection.java b/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/Connection.java index 1b6f24f761..70a4126b38 100644 --- a/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/Connection.java +++ b/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/Connection.java @@ -369,6 +369,17 @@ public List getResources(String kind, String namespace) } } + @Override + public T getResource(String kind, String namespace, String name) { + try { + if(client.getAuthorizationStrategy() == null) { + client.setAuthorizationStrategy(getAuthorizationStrategy()); + } + return client.get(kind, name, namespace); + } catch (UnauthorizedException e) { + return retryGet("Unauthorized. Trying to reauthenticate", e, kind, name, namespace); + } + } /** * Get or refresh a resource * @@ -382,16 +393,16 @@ public T getResource(IResource resource) { } return client.get(resource.getKind(), resource.getName(), resource.getNamespace()); } catch (UnauthorizedException e) { - return retryGet("Unauthorized. Trying to reauthenticate", e, resource); + return retryGet("Unauthorized. Trying to reauthenticate", e, resource.getKind(), resource.getName(), resource.getNamespace()); } } - private T retryGet(String message, OpenShiftException e, IResource resource){ + private T retryGet(String message, OpenShiftException e, String kind, String name, String namespace){ OpenShiftCoreActivator.pluginLog().logInfo(message); setToken(null);// token must be invalid, make sure not to try with // cache if (connect()) { - return client.get(resource.getKind(), resource.getName(), resource.getNamespace()); + return client.get(kind, name, namespace); } throw e; } diff --git a/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/IOpenShiftConnection.java b/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/IOpenShiftConnection.java index 8d88ebecdd..0cf3ed3feb 100644 --- a/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/IOpenShiftConnection.java +++ b/plugins/org.jboss.tools.openshift.core/src/org/jboss/tools/openshift/core/connection/IOpenShiftConnection.java @@ -31,6 +31,15 @@ public interface IOpenShiftConnection { List getResources(String kind); List getResources(String kind, String namespace); + + /** + * Retrieve a resource by name + * @param kind + * @param namespace + * @param name + * @return + */ + T getResource(String kind, String namespace, String name); String getUsername(); } diff --git a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/DeploymentResourceMapper.java b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/DeploymentResourceMapper.java index 44f6533309..98df6c43b3 100644 --- a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/DeploymentResourceMapper.java +++ b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/DeploymentResourceMapper.java @@ -15,9 +15,11 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; +import java.util.stream.Collectors; import org.jboss.tools.common.databinding.ObservablePojo; import org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter; @@ -29,9 +31,11 @@ import org.jboss.tools.openshift.core.connection.IOpenShiftConnection; import org.jboss.tools.openshift.internal.core.Trace; import org.jboss.tools.openshift.internal.core.WatchManager; +import org.jboss.tools.openshift.internal.core.util.ResourceUtils; import org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator; import com.openshift.restclient.ResourceKind; +import com.openshift.restclient.model.IBuildConfig; import com.openshift.restclient.model.IProject; import com.openshift.restclient.model.IResource; import com.openshift.restclient.model.IService; @@ -73,6 +77,23 @@ public synchronized void refresh() { buildDeployments(); } + + @Override + public Collection getImageStreamTagsFor(IService service) { + Optional deployment = deployments.stream().filter(d->service.equals(d.getService())).findFirst(); + if(deployment.isPresent()) { + Set imageRefs = deployment.get() + .getBuildConfigs() + .stream() + .map(bc->ResourceUtils.imageRef((IBuildConfig) bc.getResource())).collect(Collectors.toSet()); + final String projectName = service.getNamespace(); + return imageRefs.stream() + .map(ref->conn.getResource(ResourceKind.IMAGE_STREAM_TAG, projectName, ref)) + .collect(Collectors.toSet()); + } + return Collections.emptySet(); + } + @Override public Collection getDeployments() { buildDeployments(); diff --git a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/IDeploymentResourceMapper.java b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/IDeploymentResourceMapper.java index 7aab92af4c..19690f09ac 100644 --- a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/IDeploymentResourceMapper.java +++ b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/IDeploymentResourceMapper.java @@ -15,7 +15,20 @@ import org.jboss.tools.common.databinding.IObservablePojo; import org.jboss.tools.openshift.common.core.IRefreshable; +import com.openshift.restclient.model.IResource; +import com.openshift.restclient.model.IService; + public interface IDeploymentResourceMapper extends IObservablePojo, IRefreshable { Collection getDeployments(); + + /** + * Retrieve the ImageStreamTags associated with the given + * service. This will most likely trigger a call to the + * server since ImageStreamTags are not a watchable resource + * + * @param service + * @return The collection of imagestreamtags or an empty collection + */ + Collection getImageStreamTagsFor(IService service); } diff --git a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/ResourcesUIModel.java b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/ResourcesUIModel.java index d4eaaccab4..404e7d80ba 100644 --- a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/ResourcesUIModel.java +++ b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/models/ResourcesUIModel.java @@ -88,22 +88,6 @@ public void setDeploymentConfigResources(Collection dcs) { firePropertyChange(PROP_DEPLOYMENT_CONFIGS, resources.get(ResourceKind.DEPLOYMENT_CONFIG), resources.put(ResourceKind.DEPLOYMENT_CONFIG, init(dcs))); } - public Collection getImageStreamTags() { - return resources.get(ResourceKind.IMAGE_STREAM_TAG); - } - - public void setImageStreamTags(Collection models) { - firePropertyChange(PROP_IMAGE_STREAM_TAGS, - resources.get(ResourceKind.IMAGE_STREAM_TAG), - resources.put(ResourceKind.IMAGE_STREAM_TAG, new ArrayList<>(models))); - } - - public void setImageStreamTagResources(Collection istags) { - firePropertyChange(PROP_IMAGE_STREAM_TAGS, - resources.get(ResourceKind.IMAGE_STREAM_TAG), - resources.put(ResourceKind.IMAGE_STREAM_TAG, init(istags))); - } - @Override public Collection getBuilds() { return resources.get(ResourceKind.BUILD); diff --git a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/server/ServerSettingsViewModel.java b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/server/ServerSettingsViewModel.java index b4b1c93a02..766ddbcd9a 100644 --- a/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/server/ServerSettingsViewModel.java +++ b/plugins/org.jboss.tools.openshift.ui/src/org/jboss/tools/openshift/internal/ui/server/ServerSettingsViewModel.java @@ -20,10 +20,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.eclipse.wst.server.core.IServerWorkingCopy; import org.jboss.tools.openshift.common.core.connection.ConnectionURL; @@ -136,10 +134,9 @@ private String getDeploymentDirectory(IService service, Map istags = getImageStreamTags(service, deploymentMapper); + Collection istags = deploymentMapper.getImageStreamTagsFor(service); Iterator istagsIterator = istags.iterator(); if (istagsIterator.hasNext()) { IResource imageStreamTag = istagsIterator.next(); @@ -171,16 +168,6 @@ private String matchFirstGroup(String imageStreamTag, Pattern pattern) { } - private Collection getImageStreamTags(IService service, IDeploymentResourceMapper deploymentMapper) { - Optional deployment = deploymentMapper.getDeployments().stream().filter(d->service.equals(d.getService())).findFirst(); - if(deployment.isPresent()) { - Collection istags = deployment.get().getImageStreamTags().stream().map(m->m.getResource()).collect(Collectors.toList()); - // need to refresh to get full resource WITH labels - return getVerboseResources(istags, getConnection()); - } - return Collections.emptyList(); - } - public void setDeployProject(org.eclipse.core.resources.IProject project) { update(getConnection(), getConnections(), project, this.projects, this.sourcePath, this.podPath, this.deploymentMapperByProjectName, getService(), getServiceItems()); @@ -264,23 +251,6 @@ private Map loadImageStreamTags() { return deploymentMapperByProjectName; } - /** - * Returns the verbose version of the resources by requesting them individually. - * When listing all resources you only get a compact short version. - * To get the full-blown resource WITH labels etc you have to query them individually. - * - * @param resources - * @param connection - * @return - */ - private List getVerboseResources(Collection resources, Connection connection) { - if (resources == null - || resources.isEmpty()) { - return Collections.emptyList(); - } - return resources.stream().map(r -> (IResource) connection.getResource(r)).collect(Collectors.toList()); - } - protected List loadProjects() { return ProjectUtils.getAllAccessibleProjects(); }