Search in sources :

Example 1 with IImageStreamImportCapability

use of com.openshift.restclient.capability.resources.IImageStreamImportCapability in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method shouldInitializeContainerInfoFromRemoteDockerImage.

@Test
public void shouldInitializeContainerInfoFromRemoteDockerImage() throws IOException {
    // no Docker image on local
    when(dockerConnection.hasImage(JBOSS_INFINISPAN_SERVER_IMAGE, LATEST_TAG)).thenReturn(false);
    final IImageStreamImportCapability cap = Mockito.mock(IImageStreamImportCapability.class);
    when(project.supports(IImageStreamImportCapability.class)).thenReturn(true);
    when(project.getCapability(IImageStreamImportCapability.class)).thenReturn(cap);
    final IStatus status = Mockito.mock(IStatus.class);
    final IImageStreamImport streamImport = Mockito.mock(IImageStreamImport.class);
    final DockerImageURI dockerImageURI = new DockerImageURI(JBOSS_INFINISPAN_SERVER_URI);
    when(status.isSuccess()).thenReturn(true);
    when(cap.importImageMetadata(dockerImageURI)).thenReturn(streamImport);
    when(streamImport.getImageJsonFor(dockerImageURI.getTag())).thenReturn(getImageStreamImport("/resources/jboss_infinispan-server_ImageStreamImport.json"));
    when(streamImport.getImageStatus()).thenReturn(Arrays.asList(status));
    // when
    model.setImageName(JBOSS_INFINISPAN_SERVER_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    assertThat(model.getEnvironmentVariables()).contains(new EnvironmentVariable("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"), new EnvironmentVariable("JAVA_HOME", "/usr/lib/jvm/java"), new EnvironmentVariable("INFINISPAN_SERVER_HOME", "/opt/jboss/infinispan-server"), new EnvironmentVariable("INFINISPAN_VERSION", "8.2.0.Final"));
    assertThat(model.getPortSpecs()).isEmpty();
    assertThat(model.getVolumes()).isEmpty();
}
Also used : IStatus(com.openshift.restclient.model.IStatus) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) IImageStreamImportCapability(com.openshift.restclient.capability.resources.IImageStreamImportCapability) Test(org.junit.Test)

Example 2 with IImageStreamImportCapability

use of com.openshift.restclient.capability.resources.IImageStreamImportCapability in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method shouldInitializeContainerInfoFromRemoteDockerImageWithVolumes.

@Test
public void shouldInitializeContainerInfoFromRemoteDockerImageWithVolumes() throws IOException {
    // no Docker image on local
    when(dockerConnection.hasImage(JENKINS_IMAGE, LATEST_TAG)).thenReturn(false);
    final IImageStreamImportCapability cap = Mockito.mock(IImageStreamImportCapability.class);
    when(project.supports(IImageStreamImportCapability.class)).thenReturn(true);
    when(project.getCapability(IImageStreamImportCapability.class)).thenReturn(cap);
    final IStatus status = Mockito.mock(IStatus.class);
    final IImageStreamImport streamImport = Mockito.mock(IImageStreamImport.class);
    final DockerImageURI dockerImageURI = new DockerImageURI(JENKINS_IMAGE_URI);
    when(status.isSuccess()).thenReturn(true);
    when(cap.importImageMetadata(dockerImageURI)).thenReturn(streamImport);
    when(streamImport.getImageJsonFor(dockerImageURI.getTag())).thenReturn(getImageStreamImport("/resources/openshift3_jenkins_1_rhel7_ImageStreamImport.json"));
    when(streamImport.getImageStatus()).thenReturn(Arrays.asList(status));
    // when
    model.setImageName(JENKINS_IMAGE_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    assertThat(model.getEnvironmentVariables()).contains(new EnvironmentVariable("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin"), new EnvironmentVariable("JENKINS_VERSION", "1.642"), new EnvironmentVariable("HOME", "/var/lib/jenkins"), new EnvironmentVariable("JENKINS_HOME", "/var/lib/jenkins"));
    assertThat(model.getPortSpecs()).contains(new PortSpecAdapter("50000-tcp", "TCP", 50000), new PortSpecAdapter("8080-tcp", "TCP", 8080));
    assertThat(model.getVolumes()).contains("/var/lib/jenkins");
}
Also used : IStatus(com.openshift.restclient.model.IStatus) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) IImageStreamImportCapability(com.openshift.restclient.capability.resources.IImageStreamImportCapability) Test(org.junit.Test)

Example 3 with IImageStreamImportCapability

use of com.openshift.restclient.capability.resources.IImageStreamImportCapability in project jbosstools-openshift by jbosstools.

the class DockerImageLabels method importImageStream.

private String importImageStream(String imageRef, IProject project) {
    IImageStreamImportCapability imageStreamImportCapability = project.getCapability(IImageStreamImportCapability.class);
    DockerImageURI uri = new DockerImageURI(imageRef);
    IImageStreamImport imageStreamImport = imageStreamImportCapability.importImageMetadata(uri);
    if (!ResourceUtils.isSuccessful(imageStreamImport)) {
        return null;
    }
    return imageStreamImport.getImageJsonFor(uri);
}
Also used : DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) IImageStreamImportCapability(com.openshift.restclient.capability.resources.IImageStreamImportCapability)

Example 4 with IImageStreamImportCapability

use of com.openshift.restclient.capability.resources.IImageStreamImportCapability in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method shouldNotInitializeContainerInfoFromWrongPayload.

@Test
public void shouldNotInitializeContainerInfoFromWrongPayload() throws IOException {
    // no Docker image on local
    when(dockerConnection.hasImage(NON_EXISTANT_IMAGE, LATEST_TAG)).thenReturn(false);
    final IImageStreamImportCapability cap = Mockito.mock(IImageStreamImportCapability.class);
    when(project.supports(IImageStreamImportCapability.class)).thenReturn(true);
    when(project.getCapability(IImageStreamImportCapability.class)).thenReturn(cap);
    final IStatus status = Mockito.mock(IStatus.class);
    final IImageStreamImport streamImport = Mockito.mock(IImageStreamImport.class);
    final DockerImageURI dockerImageURI = new DockerImageURI(NON_EXISTANT_IMAGE_URI);
    when(status.isSuccess()).thenReturn(false);
    when(cap.importImageMetadata(dockerImageURI)).thenReturn(streamImport);
    when(streamImport.getImageJsonFor(dockerImageURI.getTag())).thenReturn(getImageStreamImport("/resources/failed_ImageStreamImport.json"));
    when(streamImport.getImageStatus()).thenReturn(Arrays.asList(status));
    // when
    model.setImageName(NON_EXISTANT_IMAGE_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isFalse();
}
Also used : IStatus(com.openshift.restclient.model.IStatus) DockerImageURI(com.openshift.restclient.images.DockerImageURI) IImageStreamImport(com.openshift.restclient.model.image.IImageStreamImport) IImageStreamImportCapability(com.openshift.restclient.capability.resources.IImageStreamImportCapability) Test(org.junit.Test)

Aggregations

IImageStreamImportCapability (com.openshift.restclient.capability.resources.IImageStreamImportCapability)4 DockerImageURI (com.openshift.restclient.images.DockerImageURI)4 IImageStreamImport (com.openshift.restclient.model.image.IImageStreamImport)4 IStatus (com.openshift.restclient.model.IStatus)3 Test (org.junit.Test)3 EnvironmentVariable (org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable)2 PortSpecAdapter (org.jboss.tools.openshift.internal.core.models.PortSpecAdapter)1