Search in sources :

Example 1 with Command

use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.

the class CommandConverterTest method shouldAcceptActionWithReference.

@Test
public void shouldAcceptActionWithReference() throws Exception {
    // given
    CommandImpl devfileCommand = new CommandImpl();
    devfileCommand.setName("build");
    ActionImpl action = new ActionImpl();
    action.setType("exec");
    action.setReference("blah");
    devfileCommand.getActions().add(action);
    // when
    Command command = commandConverter.toWorkspaceCommand(devfileCommand, fileURL -> "content");
    // then
    assertNull(command.getCommandLine());
    assertEquals("blah", command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_ATTRIBUTE));
    assertEquals("content", command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_CONTENT_ATTRIBUTE));
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) Test(org.testng.annotations.Test)

Example 2 with Command

use of org.eclipse.che.api.core.model.workspace.config.Command 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 + "}");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) HashMap(java.util.HashMap) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) Test(org.testng.annotations.Test)

Example 3 with Command

use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.

the class CommandConverterTest method shouldAcceptActionWithCommand.

@Test
public void shouldAcceptActionWithCommand() throws Exception {
    // given
    CommandImpl devfileCommand = new CommandImpl();
    devfileCommand.setName("build");
    ActionImpl action = new ActionImpl();
    action.setType("exec");
    action.setCommand("blah");
    devfileCommand.getActions().add(action);
    // when
    Command command = commandConverter.toWorkspaceCommand(devfileCommand, null);
    // then
    assertEquals(command.getCommandLine(), "blah");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) ActionImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl) Test(org.testng.annotations.Test)

Example 4 with Command

use of org.eclipse.che.api.core.model.workspace.config.Command 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 + "}");
}
Also used : CommandImpl(org.eclipse.che.api.workspace.server.model.impl.CommandImpl) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) HashMap(java.util.HashMap) PreviewUrlImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.PreviewUrlImpl) Command(org.eclipse.che.api.core.model.workspace.config.Command) Test(org.testng.annotations.Test)

Example 5 with Command

use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.

the class WorkspaceValidator method validateConfig.

/**
 * Checks whether given workspace configuration object is in application valid state, so it
 * provides enough data to be processed by internal components, and the data it provides is valid
 * so consistency is not violated.
 *
 * @param config configuration to validate
 * @throws ValidationException if any of validation constraints is violated
 * @throws ServerException when any other error occurs during environment validation
 */
public void validateConfig(WorkspaceConfig config) throws ValidationException, ServerException {
    // configuration object properties
    checkNotNull(config.getName(), "Workspace name required");
    check(WS_NAME.matcher(config.getName()).matches(), "Incorrect workspace name, it must be between 3 and 100 characters and may contain digits, " + "latin letters, underscores, dots, dashes and must start and end only with digits, " + "latin letters or underscores");
    validateEnvironments(config);
    // commands
    for (Command command : config.getCommands()) {
        check(!isNullOrEmpty(command.getName()), "Workspace %s contains command with null or empty name", config.getName());
        check(!isNullOrEmpty(command.getCommandLine()) || !isNullOrEmpty(command.getAttributes().get(Command.COMMAND_ACTION_REFERENCE_CONTENT_ATTRIBUTE)), "Command line or content required for command '%s' in workspace '%s'.", command.getName(), config.getName());
    }
}
Also used : Command(org.eclipse.che.api.core.model.workspace.config.Command)

Aggregations

Command (org.eclipse.che.api.core.model.workspace.config.Command)14 Test (org.testng.annotations.Test)10 HashMap (java.util.HashMap)6 ActionImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.ActionImpl)6 CommandImpl (org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl)6 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)2 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 IntOrStringBuilder (io.fabric8.kubernetes.api.model.IntOrStringBuilder)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 Secret (io.fabric8.kubernetes.api.model.Secret)2