Search in sources :

Example 26 with PreviewUrlImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project che-server by eclipse-che.

the class PreviewUrlLinksVariableGeneratorTest method shouldDoNothingWhenNoCommandWithPreviewurlAttribute.

@Test
public void shouldDoNothingWhenNoCommandWithPreviewurlAttribute() {
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(123, null), Collections.emptyMap());
    WorkspaceImpl w = createWorkspaceWithCommands(singletonList(command));
    assertTrue(generator.genLinksMapAndUpdateCommands(w, uriBuilder).isEmpty());
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) Test(org.testng.annotations.Test)

Example 27 with PreviewUrlImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project che-server by eclipse-che.

the class PreviewUrlLinksVariableGeneratorTest method shouldGetHttpsWhenUriBuilderHasHttps.

@Test
public void shouldGetHttpsWhenUriBuilderHasHttps() {
    UriBuilder httpsUriBuilder = UriBuilder.fromUri("https://host/path");
    Map<String, String> commandAttrs = new HashMap<>();
    commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host");
    CommandImpl command = new CommandImpl("run command", "a", "a", new PreviewUrlImpl(123, null), commandAttrs);
    Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(createWorkspaceWithCommands(singletonList(command)), httpsUriBuilder);
    assertTrue(linkMap.values().iterator().next().startsWith("https://"));
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) HashMap(java.util.HashMap) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) UriBuilder(jakarta.ws.rs.core.UriBuilder) Test(org.testng.annotations.Test)

Example 28 with PreviewUrlImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl in project che-server by eclipse-che.

the class OpenShiftPreviewUrlCommandProvisionerTest method shouldUpdateCommandWhenServiceAndIngressFound.

@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() 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();
    ObjectMeta metadata = new ObjectMeta();
    metadata.setName("servicename");
    service.setMetadata(metadata);
    ServiceSpec spec = new ServiceSpec();
    spec.setPorts(Collections.singletonList(new ServicePort(null, "8080", null, port, "TCP", new IntOrString(port))));
    service.setSpec(spec);
    Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
    Route route = new Route();
    RouteSpec routeSpec = new RouteSpec();
    routeSpec.setPort(new RoutePort(new IntOrString("8080")));
    routeSpec.setTo(new RouteTargetReference("a", "servicename", 1));
    routeSpec.setHost("testhost");
    route.setSpec(routeSpec);
    Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
    Mockito.when(mockRoutes.get()).thenReturn(Collections.singletonList(route));
    previewUrlCommandProvisioner.provision(env, mockProject);
    assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl"));
    assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost");
    assertTrue(env.getWarnings().isEmpty());
}
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) 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) 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)

Example 29 with PreviewUrlImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl 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 30 with PreviewUrlImpl

use of org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl 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)

Aggregations

CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)40 PreviewUrlImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl)40 Test (org.testng.annotations.Test)40 HashMap (java.util.HashMap)26 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)20 Service (io.fabric8.kubernetes.api.model.Service)20 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)20 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)16 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)14 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)12 ArrayList (java.util.ArrayList)12 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)12 OpenShiftEnvironment (org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment)12 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)8 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)8 Route (io.fabric8.openshift.api.model.Route)8 HTTPIngressPath (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressPath)4 HTTPIngressRuleValue (io.fabric8.kubernetes.api.model.networking.v1.HTTPIngressRuleValue)4 IngressRule (io.fabric8.kubernetes.api.model.networking.v1.IngressRule)4 IngressServiceBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressServiceBackend)4