use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
the class PreviewUrlLinksVariableGeneratorTest method shouldAppendMultipleQueryParamsWhenDefinedInPreviewUrl.
@Test
public void shouldAppendMultipleQueryParamsWhenDefinedInPreviewUrl() {
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&c=d"), 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&c=d");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
the class TestObjects method createCommand.
public static CommandImpl createCommand() {
CommandImpl cmd = new CommandImpl(generate("command", 5), "echo " + generate("command", 5), "CUSTOM");
cmd.getAttributes().put("attr1", "val1");
cmd.getAttributes().put("attr2", "val2");
return cmd;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class KubernetesPluginsToolingApplier method addSidecar.
/**
* Adds k8s and Che specific configuration of a sidecar into the environment. For example:
* <li>k8s container configuration {@link Container}
* <li>k8s service configuration {@link Service}
* <li>Che machine config {@link InternalMachineConfig}
* <li>Fill in machine name attribute in related commands
*
* @throws InfrastructureException when any error occurs
*/
private void addSidecar(PodData pod, CheContainer container, ChePlugin chePlugin, KubernetesEnvironment k8sEnv, Collection<CommandImpl> sidecarRelatedCommands, Component pluginRelatedComponent, RuntimeIdentity runtimeIdentity) throws InfrastructureException {
K8sContainerResolver k8sContainerResolver = toK8sContainerResolver(container, chePlugin.getEndpoints());
List<ChePluginEndpoint> containerEndpoints = k8sContainerResolver.getEndpoints();
Container k8sContainer = k8sContainerResolver.resolve();
envVars.apply(k8sContainer, pluginRelatedComponent.getEnv());
chePluginsVolumeApplier.applyVolumes(pod, k8sContainer, container.getVolumes(), k8sEnv);
String machineName = k8sContainer.getName();
Names.putMachineName(pod.getMetadata(), k8sContainer.getName(), machineName);
pod.getSpec().getContainers().add(k8sContainer);
MachineResolver machineResolver = new MachineResolverBuilder().setCheContainer(container).setContainer(k8sContainer).setContainerEndpoints(containerEndpoints).setDefaultSidecarMemoryLimitAttribute(defaultSidecarMemoryLimitBytes).setDefaultSidecarMemoryRequestAttribute(defaultSidecarMemoryRequestBytes).setDefaultSidecarCpuLimitAttribute(defaultSidecarCpuLimitCores).setDefaultSidecarCpuRequestAttribute(defaultSidecarCpuRequestCores).setProjectsRootPathEnvVar(projectsRootEnvVariableProvider.get(runtimeIdentity)).setComponent(pluginRelatedComponent).build();
InternalMachineConfig machineConfig = machineResolver.resolve();
machineConfig.getAttributes().put(CONTAINER_SOURCE_ATTRIBUTE, TOOL_CONTAINER_SOURCE);
machineConfig.getAttributes().put(PLUGIN_MACHINE_ATTRIBUTE, chePlugin.getId());
k8sEnv.getMachines().put(machineName, machineConfig);
sidecarRelatedCommands.forEach(c -> c.getAttributes().put(org.eclipse.che.api.core.model.workspace.config.Command.MACHINE_NAME_ATTRIBUTE, machineName));
container.getCommands().stream().map(c -> asCommand(machineName, c)).forEach(c -> k8sEnv.getCommands().add(c));
SidecarServicesProvisioner sidecarServicesProvisioner = new SidecarServicesProvisioner(containerEndpoints, pod.getMetadata().getName());
sidecarServicesProvisioner.provision(k8sEnv);
}
Aggregations