use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithOneContainer.
@Test(dependsOnMethods = "shouldFilterRecipeWithGivenSelectors", enabled = false)
public void shouldSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithOneContainer() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
final Map<String, String> selector = singletonMap("app.kubernetes.io/component", "webapp");
ComponentImpl component = new ComponentImpl();
component.setType(OPENSHIFT_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setSelector(selector);
CommandImpl command = new CommandImpl();
command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, COMPONENT_NAME);
workspaceConfig.getCommands().add(command);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
CommandImpl actualCommand = workspaceConfig.getCommands().get(0);
assertEquals(actualCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE), "petclinic/server");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl 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 + "}");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class PreviewUrlLinksVariableGeneratorTest method shouldAppendPathWithQueryParamsWhenDefinedInPreviewUrl.
@Test
public void shouldAppendPathWithQueryParamsWhenDefinedInPreviewUrl() {
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, "/hello?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 + "}/hello?a=b");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesPreviewUrlCommandProvisionerTest method shouldUpdateCommandWhenServiceAndIngressFound.
@Test
public void shouldUpdateCommandWhenServiceAndIngressFound() throws InfrastructureException {
final int PORT = 8080;
final String SERVICE_PORT_NAME = "service-" + PORT;
List<CommandImpl> commands = Collections.singletonList(new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap()));
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(new ArrayList<>(commands)).build();
Mockito.when(mockNamespace.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, SERVICE_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
service.setSpec(spec);
Mockito.when(mockServices.get()).thenReturn(Collections.singletonList(service));
Ingress ingress = new Ingress();
IngressSpec ingressSpec = new IngressSpec();
IngressRule rule = new IngressRule("testhost", new HTTPIngressRuleValue(Collections.singletonList(new HTTPIngressPath(new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVICE_PORT_NAME, PORT))), null, null))));
ingressSpec.setRules(Collections.singletonList(rule));
ingress.setSpec(ingressSpec);
Mockito.when(mockNamespace.ingresses()).thenReturn(mockIngresses);
Mockito.when(mockIngresses.get()).thenReturn(Collections.singletonList(ingress));
previewUrlCommandProvisioner.provision(env, mockNamespace);
assertTrue(env.getCommands().get(0).getAttributes().containsKey("previewUrl"));
assertEquals(env.getCommands().get(0).getAttributes().get("previewUrl"), "testhost");
assertTrue(env.getWarnings().isEmpty());
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class PreviewUrlExposerTest method shouldNotProvisionWhenServiceAndIngressFound.
@Test
public void shouldNotProvisionWhenServiceAndIngressFound() 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);
Ingress ingress = new Ingress();
ObjectMeta ingressMeta = new ObjectMeta();
ingressMeta.setName("ingressname");
ingress.setMetadata(ingressMeta);
IngressSpec ingressSpec = new IngressSpec();
IngressRule ingressRule = new IngressRule();
ingressRule.setHost("ingresshost");
IngressBackend ingressBackend = new IngressBackend(null, new IngressServiceBackend("servicename", new ServiceBackendPort(SERVER_PORT_NAME, PORT)));
ingressRule.setHttp(new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null, null))));
ingressSpec.setRules(singletonList(ingressRule));
ingress.setSpec(ingressSpec);
Map<String, Service> services = new HashMap<>();
services.put("servicename", service);
Map<String, Ingress> ingresses = new HashMap<>();
ingresses.put("ingressname", ingress);
KubernetesEnvironment env = KubernetesEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setServices(services).setIngresses(ingresses).build();
assertEquals(env.getIngresses().size(), 1);
previewUrlExposer.expose(env);
assertEquals(env.getIngresses().size(), 1);
}
Aggregations