use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class OpenShiftPreviewUrlExposerTest method shouldProvisionServiceAndRouteWhenNotFound.
@Test
public void shouldProvisionServiceAndRouteWhenNotFound() throws InternalInfrastructureException {
final int PORT = 8080;
final String SERVER_PORT_NAME = "server-" + PORT;
CommandImpl command = new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).setRoutes(new HashMap<>()).setServices(new HashMap<>()).build();
previewUrlEndpointsProvisioner.expose(env);
assertEquals(env.getRoutes().size(), 1);
assertEquals(env.getServices().size(), 1);
Service provisionedService = env.getServices().values().iterator().next();
ServicePort provisionedServicePort = provisionedService.getSpec().getPorts().get(0);
assertEquals(provisionedServicePort.getName(), SERVER_PORT_NAME);
assertEquals(provisionedServicePort.getPort().intValue(), PORT);
Route provisionedRoute = env.getRoutes().values().iterator().next();
assertEquals(provisionedRoute.getSpec().getTo().getName(), provisionedService.getMetadata().getName());
assertEquals(provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class OpenShiftPreviewUrlExposerTest method shouldDoNothingWhenNoCommandWithPreviewUrlDefined.
@Test
public void shouldDoNothingWhenNoCommandWithPreviewUrlDefined() throws InternalInfrastructureException {
CommandImpl command = new CommandImpl("a", "a", "a");
OpenShiftEnvironment env = OpenShiftEnvironment.builder().setCommands(singletonList(new CommandImpl(command))).build();
previewUrlEndpointsProvisioner.expose(env);
assertEquals(env.getCommands().get(0), command);
assertTrue(env.getServices().isEmpty());
assertTrue(env.getRoutes().isEmpty());
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
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 devspaces-images by redhat-developer.
the class WorkspaceDaoTest method shouldUpdateWorkspaceWithConfig.
@Test(dependsOnMethods = "shouldGetWorkspaceById")
public void shouldUpdateWorkspaceWithConfig() throws Exception {
final WorkspaceImpl workspace = new WorkspaceImpl(workspaces[0], workspaces[0].getAccount());
// Remove an existing project configuration from workspace
workspace.getConfig().getProjects().remove(1);
// Add new project to the workspace configuration
final SourceStorageImpl source3 = new SourceStorageImpl();
source3.setType("type3");
source3.setLocation("location3");
source3.setParameters(new HashMap<>(ImmutableMap.of("param1", "value1", "param2", "value2", "param3", "value3")));
final ProjectConfigImpl newProjectCfg = new ProjectConfigImpl();
newProjectCfg.setPath("/path3");
newProjectCfg.setType("type3");
newProjectCfg.setName("project3");
newProjectCfg.setDescription("description3");
newProjectCfg.getMixins().addAll(asList("mixin3", "mixin4"));
newProjectCfg.setSource(source3);
newProjectCfg.getAttributes().put("new-key", asList("1", "2"));
workspace.getConfig().getProjects().add(newProjectCfg);
// Update an existing project configuration
final ProjectConfigImpl projectCfg = workspace.getConfig().getProjects().get(0);
projectCfg.getAttributes().clear();
projectCfg.getSource().setLocation("new-location");
projectCfg.getSource().setType("new-type");
projectCfg.getSource().getParameters().put("new-param", "new-param-value");
projectCfg.getMixins().add("new-mixin");
projectCfg.setPath("/new-path");
projectCfg.setDescription("new project description");
// Remove an existing command
workspace.getConfig().getCommands().remove(1);
// Add a new command
final CommandImpl newCmd = new CommandImpl();
newCmd.setName("name3");
newCmd.setType("type3");
newCmd.setCommandLine("cmd3");
newCmd.getAttributes().putAll(ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3"));
workspace.getConfig().getCommands().add(newCmd);
// Update an existing command
final CommandImpl command = workspace.getConfig().getCommands().get(0);
command.setName("new-name");
command.setType("new-type");
command.setCommandLine("new-command-line");
command.getAttributes().clear();
// Add a new environment
final RecipeImpl newRecipe = new RecipeImpl();
newRecipe.setLocation("new-location");
newRecipe.setType("new-type");
newRecipe.setContentType("new-content-type");
newRecipe.setContent("new-content");
final MachineConfigImpl newMachine = new MachineConfigImpl();
final ServerConfigImpl serverConf1 = new ServerConfigImpl("2265", "http", "path1", singletonMap("key", "value"));
final ServerConfigImpl serverConf2 = new ServerConfigImpl("2266", "ftp", "path2", singletonMap("key", "value"));
newMachine.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
newMachine.setAttributes(singletonMap("att1", "val"));
newMachine.setAttributes(singletonMap("CHE_ENV", "value"));
final EnvironmentImpl newEnv = new EnvironmentImpl();
newEnv.setMachines(ImmutableMap.of("new-machine", newMachine));
newEnv.setRecipe(newRecipe);
workspace.getConfig().getEnvironments().put("new-env", newEnv);
// Update an existing environment
final EnvironmentImpl defaultEnv = workspace.getConfig().getEnvironments().get(workspace.getConfig().getDefaultEnv());
// Remove an existing machine config
final List<String> machineNames = new ArrayList<>(defaultEnv.getMachines().keySet());
// Update an existing machine
final MachineConfigImpl existingMachine = defaultEnv.getMachines().get(machineNames.get(1));
existingMachine.setAttributes(ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3"));
existingMachine.getServers().clear();
existingMachine.getServers().put("new-ref", new ServerConfigImpl("new-port", "new-protocol", "new-path", singletonMap("key", "value")));
defaultEnv.getMachines().remove(machineNames.get(0));
defaultEnv.getRecipe().setContent("updated-content");
defaultEnv.getRecipe().setContentType("updated-content-type");
defaultEnv.getRecipe().setLocation("updated-location");
defaultEnv.getRecipe().setType("updated-type");
// Remove an existing environment
final Optional<String> nonDefaultEnv = workspace.getConfig().getEnvironments().keySet().stream().filter(key -> !key.equals(workspace.getConfig().getDefaultEnv())).findAny();
assertTrue(nonDefaultEnv.isPresent());
workspace.getConfig().getEnvironments().remove(nonDefaultEnv.get());
// Update workspace configuration
final WorkspaceConfigImpl wCfg = workspace.getConfig();
wCfg.setDefaultEnv("new-env");
wCfg.setName("new-name");
wCfg.setDescription("This is a new description");
// Update workspace object
workspace.setAccount(new AccountImpl("accId", "new-namespace", "test"));
workspace.getAttributes().clear();
workspaceDao.update(workspace);
assertEquals(workspaceDao.get(workspace.getId()), new WorkspaceImpl(workspace, workspace.getAccount()));
}
use of org.eclipse.che.api.workspace.server.model.impl.CommandImpl in project devspaces-images by redhat-developer.
the class TestObjectsFactory 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;
}
Aggregations