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;
}
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);
}
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());
}
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()));
}
Aggregations