Search in sources :

Example 1 with IImageStream

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

the class DeployImageJob method generateResources.

private Map<String, IResource> generateResources(final Connection connection, final String name) {
    final IResourceFactory factory = connection.getResourceFactory();
    final IProject project = parameters.getProject();
    DockerImageURI sourceImage = getSourceImage();
    Map<String, IResource> resources = new HashMap<>(4);
    IImageStream is = stubImageStream(factory, name, project, sourceImage);
    if (is != null && StringUtils.isBlank(is.getResourceVersion())) {
        resources.put(ResourceKind.IMAGE_STREAM, is);
    }
    resources.put(ResourceKind.SERVICE, stubService(factory, name, SELECTOR_KEY, name));
    if (parameters.isAddRoute()) {
        resources.put(ResourceKind.ROUTE, stubRoute(factory, name, resources.get(ResourceKind.SERVICE).getName()));
    }
    resources.put(ResourceKind.DEPLOYMENT_CONFIG, stubDeploymentConfig(factory, name, sourceImage, is));
    addToGeneratedResources(resources, connection, name, project);
    for (IResource resource : resources.values()) {
        addLabelsToResource(resource);
        resource.setAnnotation(OpenShiftAPIAnnotations.GENERATED_BY, JBOSSTOOLS_OPENSHIFT);
    }
    return resources;
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) HashMap(java.util.HashMap) IImageStream(com.openshift.restclient.model.IImageStream) IResourceFactory(com.openshift.restclient.IResourceFactory) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 2 with IImageStream

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

the class DeployImageJob method stubImageStream.

protected IImageStream stubImageStream(IResourceFactory factory, String name, IProject project, DockerImageURI imageUri) {
    // get project is - check
    IImageStream is = findImageStreamFor(project.getName(), imageUri);
    if (is == null) {
        // get openshift is - check
        if (StringUtils.isNotBlank(getParameters().getConnection().getClusterNamespace())) {
            is = findImageStreamFor((String) getParameters().getConnection().getClusterNamespace(), imageUri);
        }
        // check if cluster will be able to pull image
        if (is == null && isImageVisibleByOpenShift(project, imageUri)) {
            is = factory.stub(ResourceKind.IMAGE_STREAM, name, project.getName());
            is.addTag(imageUri.getTag(), "DockerImage", imageUri.toString());
        }
    }
    if (is == null) {
        summaryMessage = NLS.bind(MSG_NO_IMAGESTREAM, summaryMessage, parameters.getImageName());
    }
    return is;
}
Also used : IImageStream(com.openshift.restclient.model.IImageStream)

Example 3 with IImageStream

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

the class DeployImageJobTest method testStubImageStreamWhereOneAlreadyExistsInTheProject.

@Test
public void testStubImageStreamWhereOneAlreadyExistsInTheProject() {
    givenAnImageStreamTo(project.getName(), DOCKER_TAG);
    IImageStream is = whenStubbingTheImageStream();
    assertNotNull("Exp. an IS to be returned", is);
    assertEquals(IMAGE_STREAM_NAME, is.getName());
    assertEquals(project.getName(), is.getNamespaceName());
    assertEquals(DOCKER_TAG, is.getDockerImageRepository());
}
Also used : IImageStream(com.openshift.restclient.model.IImageStream) Test(org.junit.Test)

Example 4 with IImageStream

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

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

Aggregations

IImageStream (com.openshift.restclient.model.IImageStream)13 Test (org.junit.Test)8 DockerImageURI (com.openshift.restclient.images.DockerImageURI)4 IProject (com.openshift.restclient.model.IProject)3 IResource (com.openshift.restclient.model.IResource)3 Connection (org.jboss.tools.openshift.core.connection.Connection)3 IResourceFactory (com.openshift.restclient.IResourceFactory)2 ResourceKind (com.openshift.restclient.ResourceKind)2 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)2 IDeploymentImageChangeTrigger (com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 ICommonAttributes (org.jboss.tools.openshift.core.ICommonAttributes)2 ResourceMocks.createConnection (org.jboss.tools.openshift.test.util.ResourceMocks.createConnection)2 ResourceFactory (com.openshift.internal.restclient.ResourceFactory)1 IClient (com.openshift.restclient.IClient)1 OpenShiftException (com.openshift.restclient.OpenShiftException)1