Search in sources :

Example 21 with WorkspaceImpl

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()));
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) BeforeWorkspaceRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent) Mockito.doCallRealMethod(org.mockito.Mockito.doCallRealMethod) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) Arrays(java.util.Arrays) Listeners(org.testng.annotations.Listeners) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) TckRepository(org.eclipse.che.commons.test.tck.repository.TckRepository) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) AccountImpl(org.eclipse.che.account.spi.AccountImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) TckRepositoryException(org.eclipse.che.commons.test.tck.repository.TckRepositoryException) AfterMethod(org.testng.annotations.AfterMethod) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) CascadeEvent(org.eclipse.che.core.db.cascade.event.CascadeEvent) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Mockito.doThrow(org.mockito.Mockito.doThrow) ImmutableList(com.google.common.collect.ImmutableList) CascadeEventSubscriber(org.eclipse.che.core.db.cascade.CascadeEventSubscriber) WorkspaceRemovedEvent(org.eclipse.che.api.workspace.server.event.WorkspaceRemovedEvent) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConflictException(org.eclipse.che.api.core.ConflictException) Collections.singletonMap(java.util.Collections.singletonMap) WorkspaceDao(org.eclipse.che.api.workspace.server.spi.WorkspaceDao) EventService(org.eclipse.che.api.core.notification.EventService) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.fail(org.testng.Assert.fail) BeforeMethod(org.testng.annotations.BeforeMethod) NotFoundException(org.eclipse.che.api.core.NotFoundException) Matchers.any(org.mockito.Matchers.any) TckListener(org.eclipse.che.commons.test.tck.TckListener) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) ServerException(org.eclipse.che.api.core.ServerException) CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Mockito.mock(org.mockito.Mockito.mock) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ArrayList(java.util.ArrayList) AccountImpl(org.eclipse.che.account.spi.AccountImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) SourceStorageImpl(org.eclipse.che.api.workspace.server.model.impl.SourceStorageImpl) ServerConf2Impl(org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Test(org.testng.annotations.Test)

Example 22 with WorkspaceImpl

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());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) Test(org.testng.annotations.Test)

Example 23 with WorkspaceImpl

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));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) Test(org.testng.annotations.Test)

Example 24 with WorkspaceImpl

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));
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) Test(org.testng.annotations.Test)

Example 25 with WorkspaceImpl

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);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) Test(org.testng.annotations.Test)

Aggregations

WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)165 Test (org.testng.annotations.Test)130 Response (com.jayway.restassured.response.Response)34 WorkspaceRuntimeImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl)15 ServerException (org.eclipse.che.api.core.ServerException)14 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)12 ApiOperation (io.swagger.annotations.ApiOperation)11 ApiResponses (io.swagger.annotations.ApiResponses)11 AccountImpl (org.eclipse.che.account.spi.AccountImpl)11 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)10 EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)9 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)9 NotFoundException (org.eclipse.che.api.core.NotFoundException)8 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)8 Consumes (javax.ws.rs.Consumes)7 ConflictException (org.eclipse.che.api.core.ConflictException)7 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)7 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)7