Search in sources :

Example 1 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 shouldDoNothingWhenCantFindServiceForPreviewurl.

@Test
public void shouldDoNothingWhenCantFindServiceForPreviewurl() throws InfrastructureException {
    List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(8080, null), Collections.emptyMap()));
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
    Mockito.when(mockProject.routes()).thenReturn(mockRoutes);
    Mockito.when(mockProject.services()).thenReturn(mockServices);
    Mockito.when(mockServices.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) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 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 shouldProvisionRouteWhenNotFound.

@Test
public void shouldProvisionRouteWhenNotFound() throws InternalInfrastructureException {
    final int PORT = 8080;
    final String SERVER_PORT_NAME = "server-" + PORT;
    final String SERVICE_NAME = "servicename";
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
    Service service = new Service();
    ObjectMeta serviceMeta = new ObjectMeta();
    serviceMeta.setName(SERVICE_NAME);
    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);
    Map<String, Service> services = new HashMap<>();
    services.put(SERVICE_NAME, service);
    OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setRoutes(new HashMap<>()).build();
    previewUrlEndpointsProvisioner.expose(env);
    assertEquals(env.getRoutes().size(), 1);
    Route provisionedRoute = env.getRoutes().values().iterator().next();
    assertEquals(provisionedRoute.getSpec().getTo().getName(), SERVICE_NAME);
    assertEquals(provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
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) 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) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) Route(io.fabric8.openshift.api.model.Route) Test(org.testng.annotations.Test)

Example 3 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 shouldAppendQueryParamsWhenDefinedInPreviewUrl.

@Test
public void shouldAppendQueryParamsWhenDefinedInPreviewUrl() {
    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, "?a=b"), commandAttrs);
    WorkspaceImpl workspace = createWorkspaceWithCommands(singletonList(command));
    Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(workspace, uriBuilder);
    assertTrue(linkMap.values().iterator().next().endsWith("preview_url_host"));
    String linkKey = linkMap.keySet().iterator().next();
    assertEquals(workspace.getRuntime().getCommands().get(0).getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), "${" + linkKey + "}?a=b");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) HashMap(java.util.HashMap) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) Test(org.testng.annotations.Test)

Example 4 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 shouldAppendPathWhenDefinedInPreviewUrl.

@Test
public void shouldAppendPathWhenDefinedInPreviewUrl() {
    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, "testpath"), commandAttrs);
    WorkspaceImpl workspace = createWorkspaceWithCommands(singletonList(command));
    Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(workspace, uriBuilder);
    assertTrue(linkMap.values().iterator().next().endsWith("preview_url_host"));
    String linkKey = linkMap.keySet().iterator().next();
    assertEquals(workspace.getRuntime().getCommands().get(0).getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), "${" + linkKey + "}testpath");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) HashMap(java.util.HashMap) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) Test(org.testng.annotations.Test)

Example 5 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 shouldUpdateCommandAndReturnLinkMapWhenPreviewUrlFound.

@Test
public void shouldUpdateCommandAndReturnLinkMapWhenPreviewUrlFound() {
    Map<String, String> commandAttrs = new HashMap<>();
    commandAttrs.put(Command.PREVIEW_URL_ATTRIBUTE, "preview_url_host");
    CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(123, null), commandAttrs);
    WorkspaceImpl w = createWorkspaceWithCommands(Arrays.asList(command, new CommandImpl("b", "b", "b")));
    Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(w, uriBuilder);
    assertEquals(linkMap.size(), 1);
    assertEquals(linkMap.values().iterator().next(), "http://preview_url_host");
    String varKey = linkMap.keySet().iterator().next();
    assertTrue(varKey.startsWith("previewurl/"));
    Command aCommand = w.getRuntime().getCommands().stream().filter(c -> c.getName().equals("a")).findFirst().get();
    assertTrue(aCommand.getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE).contains(varKey));
    assertEquals(aCommand.getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), "${" + varKey + "}");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) HashMap(java.util.HashMap) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) 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