Search in sources :

Example 1 with PortSpecAdapter

use of org.jboss.tools.openshift.internal.core.models.PortSpecAdapter in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugModeTest method shouldAddContainerDebugPortGivenNoPortExistsYet.

@Test
public void shouldAddContainerDebugPortGivenNoPortExistsYet() throws CoreException, UnsupportedEncodingException, MalformedURLException {
    // given
    mockGetEnvironmentVariables(asList(createEnvironmentVariable(KEY_DEVMODE, Boolean.FALSE.toString())), dc);
    final IPort existingContainerPort = new PortSpecAdapter("papaSmurf", "transport", 42);
    Set<IPort> ports = singleton(existingContainerPort);
    IContainer container = createContainer("someDc-container1", ports);
    mockGetContainers(asList(container), dc);
    context.setDebugEnabled(true);
    // when
    debugMode.execute(new NullProgressMonitor());
    // then
    verify(container, atLeastOnce()).setPorts(argThat(aSetEqualTo(existingContainerPort, createPort(toInt(VALUE_DEBUGPORT)))));
    // send updated dc
    verify(debugMode, times(1)).send(eq(dc), eq(connection), any(IProgressMonitor.class));
}
Also used : IPort(com.openshift.restclient.model.IPort) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter) IContainer(com.openshift.restclient.model.IContainer) Test(org.junit.Test)

Example 2 with PortSpecAdapter

use of org.jboss.tools.openshift.internal.core.models.PortSpecAdapter in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModel method initExposedPorts.

private void initExposedPorts() {
    List<IPort> portSpecs = Collections.emptyList();
    if (imageMeta != null && !CollectionUtils.isEmpty(imageMeta.exposedPorts())) {
        portSpecs = imageMeta.exposedPorts().stream().map(spec -> new PortSpecAdapter(spec)).collect(Collectors.toList());
    }
    setPortSpecs(portSpecs);
}
Also used : IPort(com.openshift.restclient.model.IPort) PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter)

Example 3 with PortSpecAdapter

use of org.jboss.tools.openshift.internal.core.models.PortSpecAdapter 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 4 with PortSpecAdapter

use of org.jboss.tools.openshift.internal.core.models.PortSpecAdapter in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method checkThatServicePortsAreReset.

@Test
public void checkThatServicePortsAreReset() {
    // assume Docker image is on local
    final IDockerImageInfo dockerImageInfo = Mockito.mock(IDockerImageInfo.class, Mockito.RETURNS_DEEP_STUBS);
    when(dockerConnection.hasImage(WILDFLY_IMAGE, LATEST_TAG)).thenReturn(true);
    when(dockerConnection.getImageInfo(WILDFLY_IMAGE_URI)).thenReturn(dockerImageInfo);
    when(dockerImageInfo.config().env()).thenReturn(Collections.emptyList());
    when(dockerImageInfo.config().exposedPorts()).thenReturn(new HashSet<>(Arrays.asList("8080/tcp", "9990/tcp")));
    when(dockerImageInfo.config().volumes()).thenReturn(Collections.emptySet());
    when(dockerImageInfo.containerConfig()).thenReturn(null);
    mockSingleImage(dockerConnection, WILDFLY_IMAGE, LATEST_TAG);
    // when
    model.setImageName(WILDFLY_IMAGE_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    model.removeServicePort(model.getServicePorts().get(0));
    assertThat(model.getServicePorts()).hasSize(1);
    assertThat(model.getServicePorts()).isEqualTo(Collections.singletonList(new ServicePortAdapter(new PortSpecAdapter("9990-tcp", "TCP", 9990))));
    model.resetServicePorts();
    assertThat(model.getServicePorts()).hasSize(2);
    ServicePortAdapter first = new ServicePortAdapter(new PortSpecAdapter("8080-tcp", "TCP", 8080));
    first.setRoutePort(true);
    assertThat(model.getServicePorts()).isEqualTo(Arrays.asList(first, new ServicePortAdapter(new PortSpecAdapter("9990-tcp", "TCP", 9990))));
}
Also used : ServicePortAdapter(org.jboss.tools.openshift.internal.ui.wizard.deployimage.ServicePortAdapter) PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) Test(org.junit.Test)

Example 5 with PortSpecAdapter

use of org.jboss.tools.openshift.internal.core.models.PortSpecAdapter in project jbosstools-openshift by jbosstools.

the class DeployImageWizardModelTest method shouldInitializeContainerInfoFromLocalDockerImage.

@Test
public void shouldInitializeContainerInfoFromLocalDockerImage() {
    // assume Docker image is on local
    final IDockerImageInfo dockerImageInfo = Mockito.mock(IDockerImageInfo.class, Mockito.RETURNS_DEEP_STUBS);
    when(dockerConnection.hasImage(WILDFLY_IMAGE, LATEST_TAG)).thenReturn(true);
    when(dockerConnection.getImageInfo(WILDFLY_IMAGE_URI)).thenReturn(dockerImageInfo);
    when(dockerImageInfo.config().env()).thenReturn(Arrays.asList("foo1=bar1", "foo2=bar2"));
    when(dockerImageInfo.config().exposedPorts()).thenReturn(new HashSet<>(Arrays.asList("8080/tcp", "9990/tcp")));
    when(dockerImageInfo.config().volumes()).thenReturn(Collections.emptySet());
    when(dockerImageInfo.containerConfig()).thenReturn(null);
    mockSingleImage(dockerConnection, WILDFLY_IMAGE, LATEST_TAG);
    // when
    model.setImageName(WILDFLY_IMAGE_URI);
    final boolean result = model.initializeContainerInfo();
    // then
    assertThat(result).isTrue();
    assertThat(model.getEnvironmentVariables()).contains(new EnvironmentVariable("foo1", "bar1"), new EnvironmentVariable("foo2", "bar2"));
    assertThat(model.getPortSpecs()).contains(new PortSpecAdapter("8080/tcp"), new PortSpecAdapter("9990/tcp"));
}
Also used : PortSpecAdapter(org.jboss.tools.openshift.internal.core.models.PortSpecAdapter) EnvironmentVariable(org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) Test(org.junit.Test)

Aggregations

PortSpecAdapter (org.jboss.tools.openshift.internal.core.models.PortSpecAdapter)9 Test (org.junit.Test)7 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)4 IPort (com.openshift.restclient.model.IPort)3 ServicePortAdapter (org.jboss.tools.openshift.internal.ui.wizard.deployimage.ServicePortAdapter)3 EnvironmentVariable (org.jboss.tools.openshift.internal.ui.wizard.common.EnvironmentVariable)2 IImageStreamImportCapability (com.openshift.restclient.capability.resources.IImageStreamImportCapability)1 DockerImageURI (com.openshift.restclient.images.DockerImageURI)1 IContainer (com.openshift.restclient.model.IContainer)1 IServicePort (com.openshift.restclient.model.IServicePort)1 IStatus (com.openshift.restclient.model.IStatus)1 IImageStreamImport (com.openshift.restclient.model.image.IImageStreamImport)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1