Search in sources :

Example 1 with DockerImageURI

use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.

the class DockerImageLabels method load.

/**
 * Loads the docker image meta data for a given resource. The given resource is
 * used to infer a deployment config which then is used to determined the docker
 * image being used. The meta data of this docker image is then loaded.
 *
 * @param reosurce
 *            the openshift resource to load the image metadata for
 * @return
 */
protected String load(IResource resource) {
    IDeploymentConfig dc = ResourceUtils.getDeploymentConfigFor(resource, connection);
    if (dc == null) {
        return null;
    }
    IDeploymentImageChangeTrigger trigger = getImageChangeTrigger(dc.getTriggers());
    if (trigger == null) {
        return null;
    }
    DockerImageURI uri = trigger.getFrom();
    return getImageStreamTag(uri, resource.getNamespaceName());
// String imageRef = getImageRef(dc, connection);
// int imageDigestIndex = imageRef.indexOf(DOCKER_IMAGE_DIGEST_IDENTIFIER);
// if (imageDigestIndex > 0) {
// String imageDigest = imageRef.substring(imageDigestIndex);
// return getImageStreamTag(imageDigest, imageRef, project.getName(), connection);
// } else {
// IImageStream imageStream = connection.getResource(ResourceKind.IMAGE_STREAM, project.getName(), imageRef);
// if (	imageStream != null) {
// //				DockerImageURI uri = imageStream.getDockerImageRepository();
// //				return importImageStream(uri.getAbsoluteUri(), project);
// IDockerImageMetadata metadata = DockerImageUtils.lookupImageMetadata(project, uri);
// return metadata.toString();
// } else {
// return importImageStream(imageRef, project);
// }
// }
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Example 2 with DockerImageURI

use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.

the class OpenshiftEapProfileDetectorTest method createBuildConfig.

@SuppressWarnings("deprecation")
private IBuildConfig createBuildConfig(Class<? extends IBuildStrategy> clazz, String name) {
    IBuildConfig bc = mock(IBuildConfig.class);
    DockerImageURI image = mock(DockerImageURI.class);
    when(image.getName()).thenReturn(name);
    IBuildStrategy strategy = null;
    if (clazz == null) {
        strategy = mock(ISourceBuildStrategy.class);
    } else if (IDockerBuildStrategy.class.isAssignableFrom(clazz)) {
        IDockerBuildStrategy dbs = mock(IDockerBuildStrategy.class);
        when(dbs.getBaseImage()).thenReturn(image);
        strategy = dbs;
    } else if (ICustomBuildStrategy.class.isAssignableFrom(clazz)) {
        ICustomBuildStrategy cbs = mock(ICustomBuildStrategy.class);
        when(cbs.getImage()).thenReturn(image);
        strategy = cbs;
    } else if (ISTIBuildStrategy.class.isAssignableFrom(clazz)) {
        ISTIBuildStrategy sts = mock(ISTIBuildStrategy.class);
        when(sts.getImage()).thenReturn(image);
        strategy = sts;
    } else if (ISourceBuildStrategy.class.isAssignableFrom(clazz)) {
        ISourceBuildStrategy sbs = mock(ISourceBuildStrategy.class);
        when(sbs.getImage()).thenReturn(image);
        strategy = sbs;
    }
    when(bc.getBuildStrategy()).thenReturn(strategy);
    Map<String, String> labels = Collections.singletonMap("template", name);
    when(bc.getLabels()).thenReturn(labels);
    return bc;
}
Also used : ISourceBuildStrategy(com.openshift.restclient.model.build.ISourceBuildStrategy) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IBuildConfig(com.openshift.restclient.model.IBuildConfig) IDockerBuildStrategy(com.openshift.restclient.model.build.IDockerBuildStrategy) IBuildStrategy(com.openshift.restclient.model.build.IBuildStrategy) ISTIBuildStrategy(com.openshift.restclient.model.build.ISTIBuildStrategy) ISTIBuildStrategy(com.openshift.restclient.model.build.ISTIBuildStrategy) ICustomBuildStrategy(com.openshift.restclient.model.build.ICustomBuildStrategy)

Example 3 with DockerImageURI

use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.

the class ResourceMocks method createSourceBuildStrategy.

public static IBuildStrategy createSourceBuildStrategy(String uri) {
    DockerImageURI dockerUri = mock(DockerImageURI.class);
    doReturn(uri).when(dockerUri).getAbsoluteUri();
    ISourceBuildStrategy strategy = mock(ISourceBuildStrategy.class);
    doReturn(BuildStrategyType.SOURCE).when(strategy).getType();
    doReturn(dockerUri).when(strategy).getImage();
    return strategy;
}
Also used : ISourceBuildStrategy(com.openshift.restclient.model.build.ISourceBuildStrategy) DockerImageURI(com.openshift.restclient.images.DockerImageURI)

Example 4 with DockerImageURI

use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.

the class ResourceMocks method createDeploymentImageChangeTrigger.

/**
 * Returns a mock of a {@link IDeploymentImageChangeTrigger} of the given type and with the given (from-) uri.
 * @param type
 * @param uri
 * @return
 *
 * @see #mockGetTriggers(List, IDeploymentConfig)
 */
public static IDeploymentImageChangeTrigger createDeploymentImageChangeTrigger(String type, String uri) {
    IDeploymentImageChangeTrigger trigger = mock(IDeploymentImageChangeTrigger.class);
    doReturn(new DockerImageURI(uri)).when(trigger).getFrom();
    doReturn(type).when(trigger).getType();
    return trigger;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Example 5 with DockerImageURI

use of com.openshift.restclient.images.DockerImageURI in project jbosstools-openshift by jbosstools.

the class DeployImageJob method updateTriggerIfUpdate.

protected boolean updateTriggerIfUpdate(Connection connection, String project, String name) {
    try {
        IDeploymentConfig dc = connection.getResource(ResourceKind.DEPLOYMENT_CONFIG, project, name);
        IDeploymentImageChangeTrigger trigger = (IDeploymentImageChangeTrigger) dc.getTriggers().stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst().orElse(null);
        if (trigger == null || !ResourceKind.IMAGE_STREAM_TAG.equals(trigger.getKind()) || StringUtils.isBlank(trigger.getNamespace()) || connection.getResource(ResourceKind.IMAGE_STREAM, trigger.getNamespace(), trigger.getFrom().getName()) == null) {
            return false;
        }
        DockerImageURI sourceImage = getSourceImage();
        if (sourceImage.getName().equals(trigger.getFrom().getName()) && !sourceImage.getTag().equals(trigger.getFrom().getTag())) {
            trigger.setFrom(new DockerImageURI(null, null, sourceImage.getName(), sourceImage.getTag()));
            connection.updateResource(dc);
        }
        return true;
    } catch (NotFoundException e) {
        return false;
    } catch (OpenShiftException e) {
        if (e.getStatus() != null && e.getStatus().getCode() == IHttpConstants.STATUS_NOT_FOUND) {
            return false;
        }
        throw e;
    }
}
Also used : ResourceCreationJobUtils.findExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.findExistingResources) StringUtils(org.apache.commons.lang.StringUtils) IImageStream(com.openshift.restclient.model.IImageStream) HashMap(java.util.HashMap) AbstractDelegatingMonitorJob(org.jboss.tools.openshift.internal.common.core.job.AbstractDelegatingMonitorJob) DockerImageUtils(org.jboss.tools.openshift.internal.core.docker.DockerImageUtils) OpenShiftException(com.openshift.restclient.OpenShiftException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ITargetPort(com.openshift.restclient.model.route.ITargetPort) IStatus(org.eclipse.core.runtime.IStatus) Map(java.util.Map) NotFoundException(com.openshift.restclient.NotFoundException) IResourceFactory(com.openshift.restclient.IResourceFactory) Trace(org.jboss.tools.openshift.internal.core.Trace) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IService(com.openshift.restclient.model.IService) ResourceCreationJobUtils.createErrorStatusForExistingResources(org.jboss.tools.openshift.internal.ui.job.ResourceCreationJobUtils.createErrorStatusForExistingResources) IHttpConstants(com.openshift.restclient.http.IHttpConstants) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IServicePort(com.openshift.restclient.model.IServicePort) IRoute(com.openshift.restclient.model.route.IRoute) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) DockerImageURI(com.openshift.restclient.images.DockerImageURI) OpenShiftException(com.openshift.restclient.OpenShiftException) NotFoundException(com.openshift.restclient.NotFoundException) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Aggregations

DockerImageURI (com.openshift.restclient.images.DockerImageURI)39 Test (org.junit.Test)23 IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)9 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)6 IImageStream (com.openshift.restclient.model.IImageStream)5 ISourceBuildStrategy (com.openshift.restclient.model.build.ISourceBuildStrategy)5 IImageStreamImportCapability (com.openshift.restclient.capability.resources.IImageStreamImportCapability)4 IResource (com.openshift.restclient.model.IResource)4 IImageStreamImport (com.openshift.restclient.model.image.IImageStreamImport)4 HashMap (java.util.HashMap)4 IResourceFactory (com.openshift.restclient.IResourceFactory)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)3 IProject (com.openshift.restclient.model.IProject)3 IStatus (com.openshift.restclient.model.IStatus)3 ICustomBuildStrategy (com.openshift.restclient.model.build.ICustomBuildStrategy)3 IDockerBuildStrategy (com.openshift.restclient.model.build.IDockerBuildStrategy)3 Collection (java.util.Collection)3 EnvironmentVariable (org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable)3 ResourceKind (com.openshift.restclient.ResourceKind)2 IBuildStrategy (com.openshift.restclient.model.build.IBuildStrategy)2