use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method shouldFillInWarningIfChePluginDoesNotHaveAnyContainersButThereAreRelatedCommands.
@Test
public void shouldFillInWarningIfChePluginDoesNotHaveAnyContainersButThereAreRelatedCommands() throws Exception {
// given
ChePlugin chePlugin = createChePlugin("somePublisher/custom-name/0.0.3");
String pluginRef = chePlugin.getId();
CommandImpl pluginCommand = new CommandImpl("test-command", "echo Hello World!", "custom");
pluginCommand.getAttributes().put("plugin", pluginRef);
internalEnvironment.getCommands().add(pluginCommand);
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
// then
List<Warning> envWarnings = internalEnvironment.getWarnings();
assertEquals(envWarnings.size(), 1);
Warning warning = envWarnings.get(0);
assertEquals(warning.getCode(), Warnings.COMMAND_IS_CONFIGURED_IN_PLUGIN_WITHOUT_CONTAINERS_WARNING_CODE);
assertEquals(warning.getMessage(), "There are configured commands for plugin 'somePublisher/custom-name/0.0.3' that doesn't have any containers");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method shouldProvisionPluginsCommandsToEnvironment.
@Test
public void shouldProvisionPluginsCommandsToEnvironment() throws Exception {
// given
Command pluginCommand = new Command().name("test-command").workingDir("~").command(Arrays.asList("./build.sh", "--no-pull"));
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(createChePlugin(createContainer("container", pluginCommand))));
// then
List<CommandImpl> envCommands = internalEnvironment.getCommands();
assertEquals(envCommands.size(), 1);
CommandImpl envCommand = envCommands.get(0);
assertEquals(envCommand.getName(), pluginCommand.getName());
assertEquals(envCommand.getCommandLine(), String.join(" ", pluginCommand.getCommand()));
assertEquals(envCommand.getType(), "custom");
assertEquals(envCommand.getAttributes().get(WORKING_DIRECTORY_ATTRIBUTE), pluginCommand.getWorkingDir());
validateContainerNameName(envCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE), "container");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesPluginsToolingApplierTest method shouldFillInWarningIfChePluginHasMultiplyContainersButThereAreRelatedCommands.
@Test
public void shouldFillInWarningIfChePluginHasMultiplyContainersButThereAreRelatedCommands() throws Exception {
// given
ChePlugin chePlugin = createChePlugin(createContainer(), createContainer());
String pluginRef = chePlugin.getId();
CommandImpl pluginCommand = new CommandImpl("test-command", "echo Hello World!", "custom");
pluginCommand.getAttributes().put("plugin", pluginRef);
internalEnvironment.getCommands().add(pluginCommand);
// when
applier.apply(runtimeIdentity, internalEnvironment, singletonList(chePlugin));
// then
List<Warning> envWarnings = internalEnvironment.getWarnings();
assertEquals(envWarnings.size(), 1);
Warning warning = envWarnings.get(0);
assertEquals(warning.getCode(), Warnings.COMMAND_IS_CONFIGURED_IN_PLUGIN_WITH_MULTIPLY_CONTAINERS_WARNING_CODE);
assertEquals(warning.getMessage(), "There are configured commands for plugin '" + pluginRef + "' that has multiply containers. Commands will be configured to be run in first container");
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class WorkspaceRuntimes method createInternalEnvironment.
@VisibleForTesting
InternalEnvironment createInternalEnvironment(@Nullable Environment environment, Map<String, String> workspaceConfigAttributes, List<? extends Command> commands, DevfileImpl devfile) throws InfrastructureException, ValidationException, NotFoundException {
String recipeType;
if (environment == null) {
recipeType = Constants.NO_ENVIRONMENT_RECIPE_TYPE;
} else {
recipeType = environment.getRecipe().getType();
}
InternalEnvironmentFactory factory = environmentFactories.get(recipeType);
if (factory == null) {
throw new NotFoundException(format("InternalEnvironmentFactory is not configured for recipe type: '%s'", recipeType));
}
InternalEnvironment internalEnvironment = factory.create(environment);
internalEnvironment.setAttributes(new HashMap<>(workspaceConfigAttributes));
internalEnvironment.setCommands(commands.stream().map(CommandImpl::new).collect(toList()));
internalEnvironment.setDevfile(devfile);
return internalEnvironment;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class PluginComponentToWorkspaceApplier method apply.
/**
* Applies changes on workspace config according to the specified plugin component.
*
* @param workspaceConfig workspace config on which changes should be applied
* @param pluginComponent plugin component that should be applied
* @param contentProvider optional content provider that may be used for external component
* resource fetching
* @throws IllegalArgumentException if specified workspace config or plugin component is null
* @throws IllegalArgumentException if specified component has type different from chePlugin
*/
@Override
public void apply(WorkspaceConfigImpl workspaceConfig, ComponentImpl pluginComponent, @Nullable FileContentProvider contentProvider) throws DevfileException {
checkArgument(workspaceConfig != null, "Workspace config must not be null");
checkArgument(pluginComponent != null, "Component must not be null");
checkArgument(PLUGIN_COMPONENT_TYPE.equals(pluginComponent.getType()), format("Plugin must have `%s` type", PLUGIN_COMPONENT_TYPE));
String workspacePluginsAttribute = workspaceConfig.getAttributes().get(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE);
final String pluginId = pluginComponent.getId();
final String registryUrl = pluginComponent.getRegistryUrl();
final ExtendedPluginFQN fqn = componentFQNParser.evaluateFQN(pluginComponent, contentProvider);
if (!isNullOrEmpty(fqn.getReference())) {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append(workspacePluginsAttribute, fqn.getReference()));
} else {
workspaceConfig.getAttributes().put(WORKSPACE_TOOLING_PLUGINS_ATTRIBUTE, append(workspacePluginsAttribute, componentFQNParser.getCompositeId(registryUrl, pluginId)));
}
for (CommandImpl command : workspaceConfig.getCommands()) {
String commandComponent = command.getAttributes().get(COMPONENT_ALIAS_COMMAND_ATTRIBUTE);
if (commandComponent == null) {
// command does not have component information
continue;
}
if (!commandComponent.equals(pluginComponent.getAlias())) {
continue;
}
command.getAttributes().put(PLUGIN_ATTRIBUTE, fqn.getId());
}
// make sure id is set to be able to match component with plugin broker result
// when referenceContent is used
pluginComponent.setId(fqn.getId());
}
Aggregations