use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class DevfileConverter method devFileToWorkspaceConfig.
/**
* Converts given {@link Devfile} into {@link WorkspaceConfigImpl workspace config}.
*
* @param devfile initial devfile
* @param contentProvider content provider for recipe-type component or plugin references
* @return constructed workspace config
* @throws DevfileException when general devfile error occurs
* @throws DevfileException when devfile requires additional files content but the specified
* content provider does not support it
* @throws DevfileFormatException when devfile format is invalid
* @throws DevfileRecipeFormatException when content of the file specified in recipe type
* component is empty or its format is invalid
*/
public WorkspaceConfigImpl devFileToWorkspaceConfig(DevfileImpl devfile, FileContentProvider contentProvider) throws DevfileException {
checkArgument(devfile != null, "Devfile must not be null");
checkArgument(contentProvider != null, "Content provider must not be null");
// make copy to avoid modification of original devfile
devfile = new DevfileImpl(devfile);
validateCurrentVersion(devfile);
defaultEditorProvisioner.apply(devfile, contentProvider);
WorkspaceConfigImpl config = new WorkspaceConfigImpl();
config.setName(devfile.getName());
for (Command command : devfile.getCommands()) {
CommandImpl com = commandConverter.toWorkspaceCommand(command, contentProvider);
if (com != null) {
config.getCommands().add(com);
}
}
// so, commands should be already converted
for (ComponentImpl component : devfile.getComponents()) {
ComponentToWorkspaceApplier applier = componentTypeToApplier.get(component.getType());
if (applier == null) {
throw new DevfileException(String.format("Devfile contains component `%s` with type `%s` that can not be converted to workspace", getIdentifiableComponentName(component), component.getType()));
}
applier.apply(config, component, contentProvider);
}
for (ProjectImpl project : devfile.getProjects()) {
ProjectConfigImpl projectConfig = projectConverter.toWorkspaceProject(project);
config.getProjects().add(projectConfig);
}
config.getAttributes().putAll(devfile.getAttributes());
config.setDevfile(devfile);
return config;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class WorkspaceActivityDaoTest method createWorkspaceConfig.
private static WorkspaceConfigImpl createWorkspaceConfig(String name) {
// Project Sources configuration
final SourceStorageImpl source1 = new SourceStorageImpl();
source1.setType("type1");
source1.setLocation("location1");
// Project Configuration
final ProjectConfigImpl pCfg1 = new ProjectConfigImpl();
pCfg1.setPath("/path1");
pCfg1.setType("type1");
pCfg1.setName("project1");
pCfg1.setDescription("description1");
pCfg1.getMixins().addAll(asList("mixin1", "mixin2"));
pCfg1.setSource(source1);
final List<ProjectConfigImpl> projects = new ArrayList<>(singletonList(pCfg1));
// Commands
final CommandImpl cmd1 = new CommandImpl("name1", "cmd1", "type1");
final List<CommandImpl> commands = new ArrayList<>(singletonList(cmd1));
// OldMachine configs
final MachineConfigImpl exMachine1 = new MachineConfigImpl();
final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "path1", singletonMap("key", "value"));
exMachine1.setServers(ImmutableMap.of("ref1", serverConf1));
exMachine1.setAttributes(singletonMap("att1", "val"));
exMachine1.setEnv(ImmutableMap.of("CHE_ENV1", "value", "CHE_ENV2", "value"));
exMachine1.setVolumes(ImmutableMap.of("vol1", new VolumeImpl().withPath("/path/1")));
// Environments
final RecipeImpl recipe1 = new RecipeImpl();
recipe1.setLocation("https://eclipse.che/Dockerfile");
recipe1.setType("dockerfile");
recipe1.setContentType("text/x-dockerfile");
recipe1.setContent("content");
final EnvironmentImpl env1 = new EnvironmentImpl();
env1.setMachines(new HashMap<>(ImmutableMap.of("machine1", exMachine1)));
env1.setRecipe(recipe1);
final RecipeImpl recipe2 = new RecipeImpl();
recipe2.setLocation("https://eclipse.che/Dockerfile");
recipe2.setType("dockerfile");
recipe2.setContentType("text/x-dockerfile");
recipe2.setContent("content");
final Map<String, EnvironmentImpl> environments = ImmutableMap.of("env1", env1);
// Workspace configuration
final WorkspaceConfigImpl wCfg = new WorkspaceConfigImpl();
wCfg.setDefaultEnv("env1");
wCfg.setName(name);
wCfg.setDescription("description");
wCfg.setCommands(commands);
wCfg.setProjects(projects);
wCfg.setEnvironments(new HashMap<>(environments));
return wCfg;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesRuntimeStateCacheTest method shouldUpdateCommands.
@Test(dependsOnMethods = "shouldReturnCommands")
public void shouldUpdateCommands() throws Exception {
// given
List<CommandImpl> newCommands = new ArrayList<>();
CommandImpl newCommand = new CommandImpl("new", "build", "custom");
newCommands.add(newCommand);
// when
runtimesStatesCache.updateCommands(runtimesStates[0].getRuntimeId(), newCommands);
// then
List<? extends Command> updatedCommands = runtimesStatesCache.getCommands(runtimesStates[0].getRuntimeId());
assertEquals(updatedCommands.size(), 1);
assertEquals(new CommandImpl(updatedCommands.get(0)), newCommand);
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class TestObjects method createCommand.
public static CommandImpl createCommand() {
CommandImpl cmd = new CommandImpl(generate("command", 5), "echo " + generate("command", 5), "CUSTOM");
cmd.getAttributes().put("attr1", "val1");
cmd.getAttributes().put("attr2", "val2");
return cmd;
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldNotSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithMultipleContainers.
@Test
public void shouldNotSetMachineNameAttributeToCommandConfiguredInOpenShiftComponentWithMultipleContainers() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(OPENSHIFT_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
CommandImpl command = new CommandImpl();
command.getAttributes().put(COMPONENT_ALIAS_COMMAND_ATTRIBUTE, COMPONENT_NAME);
workspaceConfig.getCommands().add(command);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
CommandImpl actualCommand = workspaceConfig.getCommands().get(0);
assertNull(actualCommand.getAttributes().get(MACHINE_NAME_ATTRIBUTE));
}
Aggregations