use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceDaoTest method shouldUpdateWorkspace.
@Test(dependsOnMethods = "shouldGetWorkspaceById")
public void shouldUpdateWorkspace() 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 EnvironmentRecipeImpl newRecipe = new EnvironmentRecipeImpl();
newRecipe.setLocation("new-location");
newRecipe.setType("new-type");
newRecipe.setContentType("new-content-type");
newRecipe.setContent("new-content");
final ExtendedMachineImpl newMachine = new ExtendedMachineImpl();
final ServerConf2Impl serverConf1 = new ServerConf2Impl("2265", "http", singletonMap("prop1", "val"));
final ServerConf2Impl serverConf2 = new ServerConf2Impl("2266", "ftp", singletonMap("prop1", "val"));
newMachine.setServers(ImmutableMap.of("ref1", serverConf1, "ref2", serverConf2));
newMachine.setAgents(ImmutableList.of("agent5", "agent4"));
newMachine.setAttributes(singletonMap("att1", "val"));
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 ExtendedMachineImpl existingMachine = defaultEnv.getMachines().get(machineNames.get(1));
existingMachine.setAgents(asList("new-agent1", "new-agent2"));
existingMachine.setAttributes(ImmutableMap.of("attr1", "value1", "attr2", "value2", "attr3", "value3"));
existingMachine.getServers().clear();
existingMachine.getServers().put("new-ref", new ServerConf2Impl("new-port", "new-protocol", ImmutableMap.of("prop1", "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.WorkspaceImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldNotCreateSnapshotIfWorkspaceIsTemporaryAndAutoCreateSnapshotDisactivated.
@Test
public void shouldNotCreateSnapshotIfWorkspaceIsTemporaryAndAutoCreateSnapshotDisactivated() throws Exception {
final WorkspaceImpl workspace = createAndMockWorkspace();
workspace.getAttributes().put(Constants.AUTO_CREATE_SNAPSHOT, "false");
mockRuntime(workspace, RUNNING);
SnapshotImpl oldSnapshot = mock(SnapshotImpl.class);
when(snapshotDao.getSnapshot(eq(workspace.getId()), eq(workspace.getConfig().getDefaultEnv()), anyString())).thenReturn(oldSnapshot);
workspace.setTemporary(true);
workspaceManager.stopWorkspace(workspace.getId());
captureRunAsyncCallsAndRunSynchronously();
verify(runtimes, never()).snapshot(workspace.getId());
verify(runtimes).stop(workspace.getId());
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldRecoverWorkspaceWhenRecoverParameterIsTrueAndSnapshotExists.
@Test
public void shouldRecoverWorkspaceWhenRecoverParameterIsTrueAndSnapshotExists() throws Exception {
final WorkspaceImpl workspace = createAndMockWorkspace();
mockStart(workspace);
SnapshotImpl.SnapshotBuilder snapshotBuilder = SnapshotImpl.builder().generateId().setEnvName("env").setDev(true).setMachineName("machine1").setWorkspaceId(workspace.getId()).setType("docker").setMachineSource(new MachineSourceImpl("image"));
SnapshotImpl snapshot1 = snapshotBuilder.build();
SnapshotImpl snapshot2 = snapshotBuilder.generateId().setDev(false).setMachineName("machine2").build();
when(snapshotDao.findSnapshots(workspace.getId())).thenReturn(asList(snapshot1, snapshot2));
workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), true);
verify(runtimes).startAsync(workspace, workspace.getConfig().getDefaultEnv(), true);
assertNotNull(workspace.getAttributes().get(UPDATED_ATTRIBUTE_NAME));
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldNotRecoverWorkspaceWhenRecoverParameterIsFalseAndAutoRestoreAttributeIsSetAndSnapshotExists.
@Test
public void shouldNotRecoverWorkspaceWhenRecoverParameterIsFalseAndAutoRestoreAttributeIsSetAndSnapshotExists() throws Exception {
WorkspaceImpl workspace = createAndMockWorkspace();
workspace.getAttributes().put(AUTO_RESTORE_FROM_SNAPSHOT, "true");
mockStart(workspace);
workspaceManager.startWorkspace(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
verify(runtimes).startAsync(workspace, workspace.getConfig().getDefaultEnv(), false);
assertNotNull(workspace.getAttributes().get(UPDATED_ATTRIBUTE_NAME));
}
use of org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl in project che by eclipse.
the class WorkspaceManagerTest method shouldBeAbleToStartMachineInRunningWs.
@Test
public void shouldBeAbleToStartMachineInRunningWs() throws Exception {
// given
WorkspaceImpl workspace = createAndMockWorkspace();
WorkspaceRuntimeImpl runtime = mockRuntime(workspace, RUNNING);
MachineConfigImpl machineConfig = createMachine(workspace.getId(), runtime.getActiveEnv(), false).getConfig();
// when
workspaceManager.startMachine(machineConfig, workspace.getId());
// then
captureExecuteCallsAndRunSynchronously();
verify(runtimes).startMachine(workspace.getId(), machineConfig);
}
Aggregations