Search in sources :

Example 6 with ChePluginEndpoint

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint 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 7 with ChePluginEndpoint

use of org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint 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)

Example 8 with ChePluginEndpoint

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

the class MachineResolverTest method shouldFailWhenEndpointNameAlreadyExist.

@Test(expectedExceptions = InfrastructureException.class)
public void shouldFailWhenEndpointNameAlreadyExist() throws InfrastructureException {
    // given
    ChePluginEndpoint pluginEndpoint = new ChePluginEndpoint();
    pluginEndpoint.setName("test-endpoint");
    endpoints.add(pluginEndpoint);
    component.setEndpoints(Collections.singletonList(new EndpointImpl("test-endpoint", 8080, Collections.emptyMap())));
    // when -> then exception
    resolver.resolve();
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) EndpointImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.EndpointImpl) Test(org.testng.annotations.Test)

Example 9 with ChePluginEndpoint

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

the class SidecarServicesProvisionerTest method shouldNotDuplicateServicesWhenThereAreConflictingEndpoints.

@Test(expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Applying of sidecar tooling failed. Kubernetes service with name '" + CONFLICTING_SERVICE_NAME + "' already exists in the workspace environment.")
public void shouldNotDuplicateServicesWhenThereAreConflictingEndpoints() throws Exception {
    List<ChePluginEndpoint> actualEndpoints = asList(new ChePluginEndpoint().name(CONFLICTING_SERVICE_NAME).targetPort(8080), new ChePluginEndpoint().name(CONFLICTING_SERVICE_NAME).targetPort(10000));
    endpoints.addAll(actualEndpoints);
    KubernetesEnvironment kubernetesEnvironment = KubernetesEnvironment.builder().build();
    provisioner.provision(kubernetesEnvironment);
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) Test(org.testng.annotations.Test)

Example 10 with ChePluginEndpoint

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

the class SidecarServicesProvisioner method provision.

/**
 * Add k8s Service objects to environment to provide service discovery in sidecar based
 * workspaces.
 */
public void provision(KubernetesEnvironment kubernetesEnvironment) throws InfrastructureException {
    for (ChePluginEndpoint endpoint : endpoints) {
        if (!isDiscoverable(endpoint)) {
            continue;
        }
        String serviceName = endpoint.getName();
        Service service = createService(serviceName, podName, endpoint.getTargetPort());
        Map<String, Service> services = kubernetesEnvironment.getServices();
        if (!services.containsKey(serviceName)) {
            services.put(serviceName, service);
        } else {
            throw new InfrastructureException(format("Applying of sidecar tooling failed. Kubernetes service with name '%s' already exists in the workspace environment.", serviceName));
        }
    }
}
Also used : ChePluginEndpoint(org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint) Service(io.fabric8.kubernetes.api.model.Service) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException)

Aggregations

ChePluginEndpoint (org.eclipse.che.api.workspace.server.wsplugins.model.ChePluginEndpoint)28 Test (org.testng.annotations.Test)20 CheContainerPort (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainerPort)12 Service (io.fabric8.kubernetes.api.model.Service)10 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)10 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)10 CheContainer (org.eclipse.che.api.workspace.server.wsplugins.model.CheContainer)8 Container (io.fabric8.kubernetes.api.model.Container)6 InfrastructureException (org.eclipse.che.api.workspace.server.spi.InfrastructureException)4 Beta (com.google.common.annotations.Beta)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)2 Sets (com.google.common.collect.Sets)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2