Search in sources :

Example 6 with IDeploymentConfig

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

use of com.openshift.restclient.model.IDeploymentConfig 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 8 with IDeploymentConfig

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

the class DeployImageJobTest method testStubDeploymentConfig.

@Test
public void testStubDeploymentConfig() {
    IImageStream is = givenAnImageStreamTo(project.getName(), DOCKER_TAG);
    IResource resource = job.stubDeploymentConfig(factory, RESOURCE_NAME, DOCKER_TAG, is);
    assertTrue(resource instanceof IDeploymentConfig);
    IDeploymentConfig dc = (IDeploymentConfig) resource;
    assertEquals("Exp. replicas to match incoming params", parameters.getReplicas(), dc.getReplicas());
    assertEquals("Exp. the selector key to be the resourceName", RESOURCE_NAME, dc.getReplicaSelector().get(DeployImageJob.SELECTOR_KEY));
    IContainer container = dc.getContainer(RESOURCE_NAME);
    assertNotNull("Exp. to find a container with the resource name", container);
    Collection<IDeploymentTrigger> triggers = dc.getTriggers();
    assertTrue("Exp. a config change trigger", triggers.stream().filter(t -> DeploymentTriggerType.CONFIG_CHANGE.equals(t.getType())).findFirst().isPresent());
    // assert ict matches container spec
    Optional<IDeploymentTrigger> icTrigger = triggers.stream().filter(t -> DeploymentTriggerType.IMAGE_CHANGE.equals(t.getType())).findFirst();
    assertTrue(icTrigger.isPresent());
    IDeploymentImageChangeTrigger imageChangeTrigger = (IDeploymentImageChangeTrigger) icTrigger.get();
    Collection<String> names = imageChangeTrigger.getContainerNames();
    assertEquals(1, names.size());
    assertEquals("Exp. the container and trigger names to match", container.getName(), names.iterator().next());
    assertTrue(imageChangeTrigger.isAutomatic());
    assertEquals(ResourceKind.IMAGE_STREAM_TAG, imageChangeTrigger.getKind());
    assertEquals("Exp. the trigger to point to the imagestream name", new DockerImageURI(null, null, is.getName(), DOCKER_TAG.getTag()), imageChangeTrigger.getFrom());
    assertEquals("Exp. the trigger to point to the imagestream name", is.getNamespaceName(), imageChangeTrigger.getNamespace());
}
Also used : Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IStatus(org.eclipse.core.runtime.IStatus) DeployImageJob(org.jboss.tools.openshift.internal.ui.job.DeployImageJob) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.eq(org.mockito.Matchers.eq) IResourceVisitor(org.jboss.tools.openshift.test.util.ResourceMocks.IResourceVisitor) Mockito.doReturn(org.mockito.Mockito.doReturn) ResourceKind(com.openshift.restclient.ResourceKind) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Matchers.any(org.mockito.Matchers.any) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) ResourceMocks.createResource(org.jboss.tools.openshift.test.util.ResourceMocks.createResource) Mockito.mock(org.mockito.Mockito.mock) ResourceFactory(com.openshift.internal.restclient.ResourceFactory) Mock(org.mockito.Mock) IImageStream(com.openshift.restclient.model.IImageStream) RunWith(org.junit.runner.RunWith) Mockito.spy(org.mockito.Mockito.spy) Matchers.anyString(org.mockito.Matchers.anyString) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) ResourceMocks.createConnection(org.jboss.tools.openshift.test.util.ResourceMocks.createConnection) IResourceFactory(com.openshift.restclient.IResourceFactory) Before(org.junit.Before) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IResource(com.openshift.restclient.model.IResource) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Connection(org.jboss.tools.openshift.core.connection.Connection) Mockito.verify(org.mockito.Mockito.verify) IDeployImageParameters(org.jboss.tools.openshift.internal.ui.wizard.deployimage.IDeployImageParameters) Assert.assertNull(org.junit.Assert.assertNull) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) IClient(com.openshift.restclient.IClient) DeploymentTriggerType(com.openshift.restclient.model.deploy.DeploymentTriggerType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IContainer(com.openshift.restclient.model.IContainer) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStream(com.openshift.restclient.model.IImageStream) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentTrigger(com.openshift.restclient.model.deploy.IDeploymentTrigger) Matchers.anyString(org.mockito.Matchers.anyString) IContainer(com.openshift.restclient.model.IContainer) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 9 with IDeploymentConfig

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

the class CreateApplicationFromImageJobTest method testStubDeploymentConfig.

@SuppressWarnings("unchecked")
@Test
public void testStubDeploymentConfig() {
    IImageStream is = mock(IImageStream.class);
    when(is.getName()).thenReturn("aISname");
    when(is.getNamespaceName()).thenReturn("anamespace");
    IDeploymentConfig stub = mock(IDeploymentConfig.class);
    when(stub.getName()).thenReturn(APP_NAME);
    when(stub.addTrigger(anyString())).thenReturn(mock(IDeploymentImageChangeTrigger.class));
    when(factory.stub(anyString(), anyString(), anyString())).thenReturn(stub);
    when(deployImageModel.getProject()).thenReturn(project);
    when(deployImageModel.getLabels()).thenReturn(Collections.emptyList());
    when(deployImageModel.getVolumes()).thenReturn(Collections.emptyList());
    when(deployImageModel.getPortSpecs()).thenReturn(Collections.emptyList());
    when(deployImageModel.getReplicas()).thenReturn(1);
    when(deployImageModel.getEnvironmentVariables()).thenReturn(Collections.emptyList());
    job.stubDeploymentConfig(factory, APP_NAME, new DockerImageURI("foo:bar"), is);
    verify(stub).addContainer(eq(APP_NAME), eq(new DockerImageURI(APP_NAME)), anySet(), anyMap(), anyList());
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStream(com.openshift.restclient.model.IImageStream) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) Test(org.junit.Test)

Example 10 with IDeploymentConfig

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

the class OpenShiftExplorerLabelProviderTest method getStyledTextForADeploymentConfigWithLongNames.

@Test
public void getStyledTextForADeploymentConfigWithLongNames() {
    provider.setLabelLimit(120);
    IDeploymentConfig config = givenAResource(IDeploymentConfig.class, ResourceKind.DEPLOYMENT_CONFIG);
    Map<String, String> selector = new HashMap<>();
    String name = "foo01234567890123456789012345678901234567890123456789";
    selector.put("name", name);
    String deployment = "bar01234567890123456789012345678901234567890123456789";
    selector.put("deployment", deployment);
    when(config.getReplicaSelector()).thenReturn(selector);
    assertEquals("someName selector: deployment=bar0123456789012345678901234567890...=foo01234567890123456789012345678901234567890123456789", provider.getStyledText(config).getString());
    // test description
    assertEquals("someName selector: deployment=" + deployment + ",name=" + name, provider.getDescription(config));
}
Also used : HashMap(java.util.HashMap) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) StyledString(org.eclipse.jface.viewers.StyledString) Test(org.junit.Test)

Aggregations

IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)24 Test (org.junit.Test)11 Connection (org.jboss.tools.openshift.core.connection.Connection)9 IResource (com.openshift.restclient.model.IResource)8 IService (com.openshift.restclient.model.IService)7 IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)7 DockerImageURI (com.openshift.restclient.images.DockerImageURI)6 IProject (com.openshift.restclient.model.IProject)5 Collection (java.util.Collection)4 ResourceKind (com.openshift.restclient.ResourceKind)3 IImageStream (com.openshift.restclient.model.IImageStream)3 IReplicationController (com.openshift.restclient.model.IReplicationController)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 List (java.util.List)3 IServiceWrapper (org.jboss.tools.openshift.internal.ui.models.IServiceWrapper)3 IClient (com.openshift.restclient.IClient)2 IResourceFactory (com.openshift.restclient.IResourceFactory)2 IPod (com.openshift.restclient.model.IPod)2