use of org.eclipse.che.api.core.model.workspace.config.Command in project che-server by eclipse-che.
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());
}
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.
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.core.model.workspace.config.Command in project devspaces-images by redhat-developer.
the class CommandConverterTest method shouldAcceptActionWithReferenceContent.
@Test
public void shouldAcceptActionWithReferenceContent() throws Exception {
// given
CommandImpl devfileCommand = new CommandImpl();
devfileCommand.setName("build");
ActionImpl action = new ActionImpl();
action.setType("exec");
action.setReference("blah");
action.setReferenceContent("content");
devfileCommand.getActions().add(action);
// when
Command command = commandConverter.toWorkspaceCommand(devfileCommand, null);
// 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));
}
use of org.eclipse.che.api.core.model.workspace.config.Command in project devspaces-images by redhat-developer.
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));
}
Aggregations