Search in sources :

Example 71 with CommandImpl

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");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Warning(org.eclipse.che.api.core.model.workspace.Warning) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 72 with CommandImpl

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");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Command(org.eclipse.che.api.workspace.server.wsplugins.model.Command) Test(org.testng.annotations.Test)

Example 73 with CommandImpl

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");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) Warning(org.eclipse.che.api.core.model.workspace.Warning) ChePlugin(org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin) Test(org.testng.annotations.Test)

Example 74 with CommandImpl

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;
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) InternalEnvironment(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironment) NotFoundException(org.eclipse.che.api.core.NotFoundException) InternalEnvironmentFactory(org.eclipse.che.api.workspace.server.spi.environment.InternalEnvironmentFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 75 with CommandImpl

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());
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) ExtendedPluginFQN(org.eclipse.che.api.workspace.server.wsplugins.model.ExtendedPluginFQN)

Aggregations

CommandImpl (org.eclipse.che.api.workspace.server.model.impl.CommandImpl)106 Test (org.testng.annotations.Test)80 PreviewUrlImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl)40 ArrayList (java.util.ArrayList)32 Service (io.fabric8.kubernetes.api.model.Service)30 HashMap (java.util.HashMap)30 KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)26 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)24 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)24 ComponentImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl)20 ServiceSpec (io.fabric8.kubernetes.api.model.ServiceSpec)18 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)18 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)18 OpenShiftEnvironment (org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment)16 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)14 Ingress (io.fabric8.kubernetes.api.model.networking.v1.Ingress)14 List (java.util.List)12 IngressBackend (io.fabric8.kubernetes.api.model.networking.v1.IngressBackend)10 ChePlugin (org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin)10 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)9