use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesInternalRuntimeTest method shouldReturnCommandsAfterRuntimeStart.
@Test
public void shouldReturnCommandsAfterRuntimeStart() throws Exception {
// given
CommandImpl commandToProvision = new CommandImpl("provisioned-command", "build", "env");
doAnswer((Answer<Void>) invocationOnMock -> {
k8sEnv.getCommands().add(commandToProvision);
return null;
}).when(internalEnvironmentProvisioner).provision(any(), any());
internalRuntime.start(emptyMap());
// when
List<? extends Command> commands = internalRuntime.getCommands();
// then
assertEquals(commands.size(), 2);
Optional<? extends Command> envCommandOpt = commands.stream().filter(c -> "envCommand".equals(c.getName())).findAny();
assertTrue(envCommandOpt.isPresent());
Command envCommand = envCommandOpt.get();
assertEquals(envCommand.getCommandLine(), envCommand.getCommandLine());
assertEquals(envCommand.getType(), envCommand.getType());
Optional<? extends Command> provisionedCommandOpt = commands.stream().filter(c -> "provisioned-command".equals(c.getName())).findAny();
assertTrue(provisionedCommandOpt.isPresent());
Command provisionedCommand = provisionedCommandOpt.get();
assertEquals(provisionedCommand.getCommandLine(), provisionedCommand.getCommandLine());
assertEquals(provisionedCommand.getType(), provisionedCommand.getType());
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
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);
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesRuntimeStateCacheTest method shouldUpdateCommandsAndDeleteRuntime.
// Ensure that we are not affected https://bugs.eclipse.org/bugs/show_bug.cgi?id=474203 Orphan
// Removal not working
// when, object is added to collection and then same object is removed from collection in same
// transaction.
//
// Probable reason - two different transactions was used.
@Test(dependsOnMethods = "shouldReturnCommands")
public void shouldUpdateCommandsAndDeleteRuntime() {
// given
List<CommandImpl> newCommands = new ArrayList<>();
CommandImpl newCommand = new CommandImpl("new", "build", "custom");
newCommands.add(newCommand);
// when
try {
runtimesStatesCache.updateCommands(runtimesStates[0].getRuntimeId(), newCommands);
runtimesStatesCache.remove(runtimesStates[0].getRuntimeId());
} catch (InfrastructureException e) {
fail("No exception expected here, got " + e.getLocalizedMessage());
}
// then
// if no exception happened during remove operation that means test passed correctly.
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class PreviewUrlLinksVariableGeneratorTest method variableNamesForTwoCommandsWithSimilarNameMustBeDifferent.
@Test
public void variableNamesForTwoCommandsWithSimilarNameMustBeDifferent() {
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);
CommandImpl command2 = new CommandImpl(command);
command2.setName("runcommand");
WorkspaceImpl w = createWorkspaceWithCommands(Arrays.asList(command, command2));
Map<String, String> linkMap = generator.genLinksMapAndUpdateCommands(w, uriBuilder);
assertEquals(linkMap.size(), 2);
List<? extends Command> commandsAfter = w.getRuntime().getCommands();
assertNotEquals(commandsAfter.get(1).getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE), commandsAfter.get(0).getAttributes().get(Command.PREVIEW_URL_ATTRIBUTE));
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
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");
}
Aggregations