Search in sources :

Example 1 with CheContainerPort

use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method throwsExceptionOnAddingChePluginEndpointServiceIfServiceExists.

@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Applying of sidecar tooling failed. Kubernetes service with name '" + CHE_PLUGIN_ENDPOINT_NAME + "' already exists in the workspace environment.")
public void throwsExceptionOnAddingChePluginEndpointServiceIfServiceExists() throws Exception {
    // given
    ChePluginEndpoint endpoint1 = new ChePluginEndpoint().name(CHE_PLUGIN_ENDPOINT_NAME).targetPort(101010).setPublic(true);
    CheContainerPort cheContainerPort1 = new CheContainerPort().exposedPort(101010);
    ChePlugin chePlugin = createChePlugin();
    chePlugin.setEndpoints(singletonList(endpoint1));
    chePlugin.getContainers().get(0).setPorts(singletonList(cheContainerPort1));
    // make collision of service names
    internalEnvironment.getServices().put(CHE_PLUGIN_ENDPOINT_NAME, new Service());
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort) Service(io.fabric8.kubernetes.api.model.Service) Test(org.testng.annotations.Test)

Example 2 with CheContainerPort

use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method shouldNotExposeChePluginPortIfThereIsNoEndpoint.

@Test
public void shouldNotExposeChePluginPortIfThereIsNoEndpoint() throws Exception {
    // given
    ChePluginEndpoint endpoint1 = new ChePluginEndpoint().name(CHE_PLUGIN_ENDPOINT_NAME).targetPort(101010).setPublic(true);
    CheContainerPort cheContainerPort1 = new CheContainerPort().exposedPort(101010);
    CheContainerPort cheContainerPort2 = new CheContainerPort().exposedPort(2020);
    ChePlugin chePlugin = createChePlugin();
    chePlugin.setEndpoints(singletonList(endpoint1));
    chePlugin.getContainers().get(0).setPorts(asList(cheContainerPort1, cheContainerPort2));
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    Container container = getOneAndOnlyNonUserContainer(internalEnvironment);
    verifyPortsExposed(container, 101010);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort) Test(org.testng.annotations.Test)

Example 3 with CheContainerPort

use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method addPortToSingleContainerPlugin.

private void addPortToSingleContainerPlugin(ChePlugin plugin, int port, String portName, Map<String, String> attributes, boolean isPublic) {
    assertEquals(plugin.getContainers().size(), 1);
    ChePluginEndpoint endpoint = new ChePluginEndpoint().attributes(attributes).name(portName).setPublic(isPublic).targetPort(port);
    plugin.getEndpoints().add(endpoint);
    List<CheContainerPort> ports = plugin.getContainers().get(0).getPorts();
    if (ports.stream().map(CheContainerPort::getExposedPort).noneMatch(integer -> integer == port)) {
        ports.add(new CheContainerPort().exposedPort(port));
    }
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort)

Example 4 with CheContainerPort

use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort in project che-server by eclipse-che.

the class K8sContainerResolverBuilderTest method shouldPassOnlyParticularContainerEndpoints.

@Test
public void shouldPassOnlyParticularContainerEndpoints() {
    // given
    K8sContainerResolverBuilder builder = new K8sContainerResolverBuilder();
    builder.setContainer(new CheContainer().ports(asList(new CheContainerPort().exposedPort(9014), new CheContainerPort().exposedPort(4040))));
    builder.setPluginEndpoints(asList(new ChePluginEndpoint().targetPort(9014), new ChePluginEndpoint().targetPort(9013), new ChePluginEndpoint().targetPort(8080), new ChePluginEndpoint().targetPort(4040)));
    K8sContainerResolver resolver = builder.build();
    ArrayList<ChePluginEndpoint> expected = new ArrayList<>();
    expected.add(new ChePluginEndpoint().targetPort(9014));
    expected.add(new ChePluginEndpoint().targetPort(4040));
    // when
    List<ChePluginEndpoint> actualEndpoints = resolver.getEndpoints();
    // then
    assertEqualsNoOrder(actualEndpoints.toArray(), expected.toArray());
}
Also used : CheContainer(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer) ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) ArrayList(java.util.ArrayList) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort) Test(org.testng.annotations.Test)

Example 5 with CheContainerPort

use of org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort in project che-server by eclipse-che.

the class KubernetesPluginsToolingApplierTest method shouldAddK8sServicesForChePluginEndpoints.

@Test
public void shouldAddK8sServicesForChePluginEndpoints() throws Exception {
    // given
    ChePluginEndpoint endpoint1 = new ChePluginEndpoint().name(CHE_PLUGIN_ENDPOINT_NAME).targetPort(101010).setPublic(true);
    ChePluginEndpoint endpoint2 = new ChePluginEndpoint().name("test-endpoint-2").targetPort(2020).setPublic(false);
    CheContainerPort cheContainerPort1 = new CheContainerPort().exposedPort(101010);
    CheContainerPort cheContainerPort2 = new CheContainerPort().exposedPort(2020);
    ChePlugin chePlugin = createChePlugin();
    chePlugin.setEndpoints(asList(endpoint1, endpoint2));
    chePlugin.getContainers().get(0).setPorts(asList(cheContainerPort1, cheContainerPort2));
    // when
    applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
    // then
    verifyK8sServices(internalEnvironment, endpoint1, endpoint2);
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) CheContainerPort(org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort) Test(org.testng.annotations.Test)

Aggregations

CheContainerPort (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort)12 ChePluginEndpoint (org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint)12 Test (org.testng.annotations.Test)10 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)8 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)6 Container (io.fabric8.kubernetes.api.model.Container)4 Service (io.fabric8.kubernetes.api.model.Service)2 ArrayList (java.util.ArrayList)2