Search in sources :

Example 1 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger 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 IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger 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 3 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger 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)

Example 4 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.

the class DeployImageJob method stubDeploymentConfig.

protected IResource stubDeploymentConfig(IResourceFactory factory, final String name, DockerImageURI imageUri, IImageStream is) {
    IDeploymentConfig dc = factory.stub(ResourceKind.DEPLOYMENT_CONFIG, name, parameters.getProject().getName());
    dc.addLabel(SELECTOR_KEY, name);
    dc.addTemplateLabel(SELECTOR_KEY, name);
    for (Label label : parameters.getLabels()) {
        dc.addTemplateLabel(label.getName(), label.getValue());
    }
    dc.setReplicas(parameters.getReplicas());
    dc.setReplicaSelector(SELECTOR_KEY, name);
    Map<String, String> envs = getModifiedEnvVars(parameters.getEnvironmentVariables(), parameters.getImageEnvVars());
    dc.addContainer(dc.getName(), imageUri, new HashSet<>(parameters.getPortSpecs()), envs, parameters.getVolumes());
    dc.addTrigger(DeploymentTriggerType.CONFIG_CHANGE);
    if (is != null) {
        IDeploymentImageChangeTrigger imageChangeTrigger = (IDeploymentImageChangeTrigger) dc.addTrigger(DeploymentTriggerType.IMAGE_CHANGE);
        imageChangeTrigger.setAutomatic(true);
        imageChangeTrigger.setContainerName(name);
        imageChangeTrigger.setFrom(new DockerImageURI(null, null, is.getName(), imageUri.getTag()));
        imageChangeTrigger.setKind(ResourceKind.IMAGE_STREAM_TAG);
        imageChangeTrigger.setNamespace(is.getNamespaceName());
    }
    return dc;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) Label(org.jboss.tools.openshift.internal.ui.wizard.common.IResourceLabelsPageModel.Label) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)

Example 5 with IDeploymentImageChangeTrigger

use of com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger in project jbosstools-openshift by jbosstools.

the class DockerImageLabelsTest method setup.

@Before
public void setup() throws IOException {
    this.connection = createConnection("https://localhost:8181", "aUser");
    this.labelsThatFailsToLoad = spy(new TestableDockerImageLabels(null, connection));
    this.dc = ResourceMocks.createDeploymentConfig("aDeploymentConfig", ResourceMocks.createProject("aProject"), null, null);
    IDeploymentImageChangeTrigger trigger = ResourceMocks.createDeploymentImageChangeTrigger(DeploymentTriggerType.IMAGE_CHANGE, "nodejs:latest");
    ResourceMocks.mockGetTriggers(Collections.singletonList(trigger), dc);
    IResource imageStreamTag = mockImageStreamTag(NODEJS_IMAGESTREAM_TAG_URL);
    doReturn(imageStreamTag).when(connection).getResource(eq(ResourceKind.IMAGE_STREAM_TAG), anyString(), anyString());
    this.labels = spy(new TestableDockerImageLabels(dc, connection));
}
Also used : IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IResource(com.openshift.restclient.model.IResource) Before(org.junit.Before)

Aggregations

IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)9 DockerImageURI (com.openshift.restclient.images.DockerImageURI)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)5 IResource (com.openshift.restclient.model.IResource)4 Collection (java.util.Collection)3 Test (org.junit.Test)3 IResourceFactory (com.openshift.restclient.IResourceFactory)2 ResourceKind (com.openshift.restclient.ResourceKind)2 IImageStream (com.openshift.restclient.model.IImageStream)2 IProject (com.openshift.restclient.model.IProject)2 DeploymentTriggerType (com.openshift.restclient.model.deploy.DeploymentTriggerType)2 IDeploymentTrigger (com.openshift.restclient.model.deploy.IDeploymentTrigger)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 ICommonAttributes (org.jboss.tools.openshift.core.ICommonAttributes)2 Connection (org.jboss.tools.openshift.core.connection.Connection)2