Search in sources :

Example 11 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class DefaultWorkspaceValidatorTest method createConfig.

private static WorkspaceConfigDto createConfig() {
    final WorkspaceConfigDto workspaceConfigDto = newDto(WorkspaceConfigDto.class).withName("ws-name").withDefaultEnv("dev-env");
    ExtendedMachineDto extendedMachine = newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent")).withServers(singletonMap("ref1", newDto(ServerConf2Dto.class).withPort("8080/tcp").withProtocol("https").withProperties(singletonMap("some", "prop")))).withAttributes(singletonMap("memoryLimitBytes", "1000000"));
    EnvironmentDto env = newDto(EnvironmentDto.class).withMachines(singletonMap("devmachine1", extendedMachine)).withRecipe(newDto(EnvironmentRecipeDto.class).withType("type").withContent("content").withContentType("content type"));
    workspaceConfigDto.setEnvironments(singletonMap("dev-env", env));
    List<CommandDto> commandDtos = new ArrayList<>();
    commandDtos.add(newDto(CommandDto.class).withName("command_name").withType("maven").withCommandLine("mvn clean install").withAttributes(new HashMap<>(singletonMap("cmd-attribute-name", "cmd-attribute-value"))));
    workspaceConfigDto.setCommands(commandDtos);
    return workspaceConfigDto;
}
Also used : HashMap(java.util.HashMap) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) ArrayList(java.util.ArrayList) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)

Example 12 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class WorkspaceRuntimeIntegrationTest method environmentEngineShouldDestroyAllMachinesBeforeRemovalOfEnvironmentRecord.

// Check for https://github.com/codenvy/codenvy/issues/593
@Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "Workspace with id '" + WORKSPACE_ID + "' is not running")
public void environmentEngineShouldDestroyAllMachinesBeforeRemovalOfEnvironmentRecord() throws Exception {
    // given
    EnvironmentDto environment = newDto(EnvironmentDto.class);
    environment.withMachines(singletonMap("service1", newDto(ExtendedMachineDto.class).withAgents(singletonList("org.eclipse.che.ws-agent"))));
    WorkspaceConfigDto config = newDto(WorkspaceConfigDto.class).withDefaultEnv(ENV_NAME).withName("ws1").withEnvironments(singletonMap(ENV_NAME, environment));
    WorkspaceDto workspace = newDto(WorkspaceDto.class).withId(WORKSPACE_ID).withNamespace("namespace").withConfig(config);
    Instance instance = mock(Instance.class);
    MachineConfigImpl machineConfig = new MachineConfigImpl();
    machineConfig.setDev(true);
    machineConfig.setName("service1");
    when(instance.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(instance.getId()).thenReturn("machineId");
    when(instance.getConfig()).thenReturn(machineConfig);
    CheServicesEnvironmentImpl internalEnv = new CheServicesEnvironmentImpl();
    internalEnv.getServices().put("service1", new CheServiceImpl().withId("machineId"));
    when(environmentParser.parse(any(Environment.class))).thenReturn(internalEnv);
    when(instanceProvider.startService(anyString(), anyString(), anyString(), anyString(), anyBoolean(), anyString(), any(CheServiceImpl.class), any(LineConsumer.class))).thenReturn(instance);
    runtimes.startAsync(workspace, ENV_NAME, false);
    verify(sharedPool).submit(taskCaptor.capture());
    taskCaptor.getValue().call();
    WaitingAnswer<Void> waitingAnswer = new WaitingAnswer<>();
    doAnswer(waitingAnswer).when(instance).destroy();
    // when
    executor.execute(() -> {
        try {
            runtimes.stop(WORKSPACE_ID);
        } catch (Exception e) {
            LOG.error(e.getLocalizedMessage(), e);
        }
    });
    waitingAnswer.waitAnswerCall(1, TimeUnit.SECONDS);
    // then
    // no exception - environment and workspace are still running
    runtimes.getRuntime(WORKSPACE_ID);
    // let instance removal proceed
    waitingAnswer.completeAnswer();
    // verify destroying was called
    verify(instance, timeout(1000)).destroy();
    verify(instanceProvider, timeout(1000)).destroyNetwork(anyString());
    // wait to ensure that removal of runtime is finished
    Thread.sleep(500);
    // runtime is removed - now getting of it should throw an exception
    runtimes.getRuntime(WORKSPACE_ID);
}
Also used : WaitingAnswer(org.eclipse.che.commons.test.mockito.answer.WaitingAnswer) Instance(org.eclipse.che.api.machine.server.spi.Instance) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) NotFoundException(org.eclipse.che.api.core.NotFoundException) LineConsumer(org.eclipse.che.api.core.util.LineConsumer) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) Environment(org.eclipse.che.api.core.model.workspace.Environment) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) ExtendedMachineDto(org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto) Test(org.testng.annotations.Test)

Example 13 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class WorkspaceServiceTest method shouldUpdateEnvironment.

@Test
public void shouldUpdateEnvironment() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
    final EnvironmentDto envDto = createEnvDto();
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(envDto).when().put(SECURE_PATH + "/workspace/" + workspace.getId() + "/environment/" + workspace.getConfig().getDefaultEnv());
    assertEquals(response.getStatusCode(), 200);
    assertEquals(workspace.getConfig().getEnvironments().size(), 1);
    verify(validator).validateConfig(workspace.getConfig());
    verify(wsManager).updateWorkspace(any(), any());
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) Test(org.testng.annotations.Test)

Example 14 with EnvironmentDto

use of org.eclipse.che.api.workspace.shared.dto.EnvironmentDto in project che by eclipse.

the class WorkspaceServiceTest method shouldRelativizeLinksOnAddEnvironment.

@Test
public void shouldRelativizeLinksOnAddEnvironment() throws Exception {
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    final String initialLocation = "http://localhost:8080/api/recipe/idrecipe123456789/script";
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    when(wsManager.updateWorkspace(any(), any())).thenReturn(workspace);
    final EnvironmentDto envDto = createEnvDto();
    envDto.getRecipe().withLocation(initialLocation).withType("dockerfile");
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(envDto).when().queryParam("name", "new-env").post(SECURE_PATH + "/workspace/" + workspace.getId() + "/environment");
    assertEquals(response.getStatusCode(), 200);
    String savedLocation = unwrapDto(response, WorkspaceDto.class).getConfig().getEnvironments().get("new-env").getRecipe().getLocation();
    assertEquals(savedLocation, initialLocation.substring(API_ENDPOINT.length()));
}
Also used : Response(com.jayway.restassured.response.Response) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Aggregations

EnvironmentDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentDto)14 WorkspaceConfigDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto)8 HashMap (java.util.HashMap)6 Test (org.testng.annotations.Test)6 ExtendedMachineDto (org.eclipse.che.api.workspace.shared.dto.ExtendedMachineDto)5 MachineConfigDto (org.eclipse.che.api.machine.shared.dto.MachineConfigDto)4 Response (com.jayway.restassured.response.Response)3 CommandDto (org.eclipse.che.api.machine.shared.dto.CommandDto)3 EnvironmentRecipeDto (org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Environment (org.eclipse.che.api.core.model.workspace.Environment)2 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)2 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)2 MachineDto (org.eclipse.che.api.machine.shared.dto.MachineDto)2 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)2 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)2 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)2 WorkspaceRuntimeDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceRuntimeDto)2