Search in sources :

Example 16 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftPreviewUrlCommandProvisionerTest method shouldDoNothingWhenCantFindRouteForPreviewUrl.

@Test
public void shouldDoNothingWhenCantFindRouteForPreviewUrl() throws InfrastructureException {
    int port = 8080;
    List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(port, null), Collections.emptyMap()));
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
    Mockito.when(mockProject.services()).thenReturn(mockServices);
    Service service = new Service();
    ServiceSpec spec = new ServiceSpec();
    spec.setPorts(Collections.singletonList(new ServicePort(null, "a", null, port, "TCP", new IntOrString(port))));
    service.setSpec(spec);
    Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
    Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
    Mockito.when(mockRoutes.get()).thenReturn(Collections.emptyList());
    previewUrlCommandProvisioner.provision(env, mockProject);
    assertTrue(commands.containsAll(env.getCommands()));
    assertTrue(env.getCommands().containsAll(commands));
    assertEquals(env.getWarnings().get(0).getCode(), Warnings.NOT_ABLE_TO_PROVISION_OBJECTS_FOR_PREVIEW_URL);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArrayList(java.util.ArrayList) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) Test(org.testng.annotations.Test)

Example 17 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftExternalServerExposerTest method shouldAddRouteToEnvForExposingSpecifiedServer.

@Test
public void shouldAddRouteToEnvForExposingSpecifiedServer() {
    // given
    OpenShiftEnvironment osEnv = OpenShiftEnvironment.builder().build();
    Map<String, ServerConfig> servers = new HashMap<>();
    servers.put("server", new ServerConfigImpl());
    // when
    osExternalServerExposer.expose(osEnv, "machine123", "service123", null, new ServicePort(null, "servicePort", null, null, "TCP", null), servers);
    // then
    assertEquals(1, osEnv.getRoutes().size());
    Route route = osEnv.getRoutes().values().iterator().next();
    assertNotNull(route);
    assertEquals(route.getSpec().getTo().getName(), "service123");
    assertEquals(route.getSpec().getPort().getTargetPort().getStrVal(), "servicePort");
    Deserializer annotations = Annotations.newDeserializer(route.getMetadata().getAnnotations());
    assertEquals(annotations.machineName(), "machine123");
    assertEquals(annotations.servers(), servers);
    assertEquals(route.getMetadata().getLabels().get("foo"), "bar");
    assertNull(route.getSpec().getHost());
}
Also used : OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) HashMap(java.util.HashMap) Deserializer(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations.Deserializer) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 18 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftPreviewUrlExposerTest method shouldDoNothingWhenNoCommandsDefined.

@Test
public void shouldDoNothingWhenNoCommandsDefined() throws InternalInfrastructureException {
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().build();
    previewUrlEndpointsProvisioner.expose(env);
    assertTrue(env.getCommands().isEmpty());
    assertTrue(env.getServices().isEmpty());
    assertTrue(env.getRoutes().isEmpty());
}
Also used : OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) Test(org.testng.annotations.Test)

Example 19 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftPreviewUrlExposerTest method shouldProvisionServiceAndRouteWhenNotFound.

@Test
public void shouldProvisionServiceAndRouteWhenNotFound() throws InternalInfrastructureException {
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setRoutes(new HashMap<>()).setServices(new HashMap<>()).build();
    previewUrlEndpointsProvisioner.expose(env);
    assertEquals(env.getRoutes().size(), 1);
    assertEquals(env.getServices().size(), 1);
    Service provisionedService = env.getServices().values().iterator().next();
    ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0);
    assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME);
    assertEquals(provisionedServicePort.getPort().intValue(), PORT);
    Route provisionedRoute = env.getRoutes().values().iterator().next();
    assertEquals(provisionedRoute.getSpec().getTo().getName(), provisionedService.getMetadata().getName());
    assertEquals(provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 20 with OpenShiftEnvironment

use of org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment in project che-server by eclipse-che.

the class OpenShiftPreviewUrlExposerTest method shouldNotProvisionWhenServiceAndRouteFound.

@Test
public void shouldNotProvisionWhenServiceAndRouteFound() throws InternalInfrastructureException {
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    Service service = new Service();
    ObjectMeta serviceMeta = new ObjectMeta();
    serviceMeta.setName("servicename");
    service.setMetadata(serviceMeta);
    ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(singletonList(new ServicePort(null, SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
    service.setSpec(serviceSpec);
    Route route = new Route();
    RouteSpec routeSpec = new RouteSpec();
    routeSpec.setPort(new RoutePort(new IntOrString(SERVER_PORT_NAME)));
    routeSpec.setTo(new RouteTargetReference("routekind", "servicename", 1));
    route.setSpec(routeSpec);
    Map<String, Service> services = new HashMap<>();
    services.put("servicename", service);
    Map<String, Route> routes = new HashMap<>();
    routes.put("routename", route);
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setRoutes(routes).build();
    assertEquals(env.getRoutes().size(), 1);
    previewUrlEndpointsProvisioner.expose(env);
    assertEquals(env.getRoutes().size(), 1);
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) RouteTargetReference(io.fabric8.openshift.api.model.RouteTargetReference) RoutePort(io.fabric8.openshift.api.model.RoutePort) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceSpec(io.fabric8.kubernetes.api.model.ServiceSpec) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) RouteSpec(io.fabric8.openshift.api.model.RouteSpec) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Aggregations

OpenShiftEnvironment (org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment)28 Test (org.testng.annotations.Test)22 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)16 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)14 Route (io.fabric8.openshift.api.model.Route)14 Service (io.fabric8.kubernetes.api.model.Service)12 PreviewUrlImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl)12 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)10 HashMap (java.util.HashMap)10 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)8 ArrayList (java.util.ArrayList)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)6 TypeLiteral (com.google.inject.TypeLiteral)4 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)4 RoutePort (io.fabric8.openshift.api.model.RoutePort)4 RouteSpec (io.fabric8.openshift.api.model.RouteSpec)4 RouteTargetReference (io.fabric8.openshift.api.model.RouteTargetReference)4 ServerConfig (org.eclipse.che.api.core.model.workspace.config.ServerConfig)4 ServerConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2