Search in sources :

Example 36 with EnvironmentImpl

use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.

the class EnvironmentParserTest method getEntryForComposeEnv.

private static List<Object> getEntryForComposeEnv(Map<String, ServerConf2Impl> servers, List<String> composeExpose, Map<String, String> composeLabels, List<String> expectedExpose, Map<String, String> expectedLabels) {
    CheServicesEnvironmentImpl cheComposeEnv = createCheServicesEnv(new HashMap<>(composeLabels), new ArrayList<>(composeExpose));
    CheServicesEnvironmentImpl expectedEnv = createCheServicesEnv(expectedLabels, expectedExpose);
    EnvironmentImpl environmentConfig = createCompose1MachineEnvConfig();
    ExtendedMachineImpl extendedMachine = getMachine(environmentConfig);
    extendedMachine.setServers(new HashMap<>(servers));
    return asList(environmentConfig, expectedEnv, cheComposeEnv);
}
Also used : ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)

Example 37 with EnvironmentImpl

use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.

the class EnvironmentParserTest method shouldThrowExceptionInCaseFailedParseMemoryLimit.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Value of attribute 'memoryLimitBytes' of machine 'machine1' is illegal")
public void shouldThrowExceptionInCaseFailedParseMemoryLimit() throws ServerException {
    HashMap<String, ExtendedMachineImpl> machines = new HashMap<>();
    machines.put("machine1", new ExtendedMachineImpl(emptyList(), emptyMap(), singletonMap("memoryLimitBytes", "here should be memory size number")));
    EnvironmentImpl environment = new EnvironmentImpl(new EnvironmentRecipeImpl("compose", "application/x-yaml", "content", null), machines);
    CheServicesEnvironmentImpl cheEnv = new CheServicesEnvironmentImpl();
    cheEnv.getServices().put("machine1", new CheServiceImpl());
    when(envParser.parse(environment)).thenReturn(cheEnv);
    // when
    parser.parse(environment);
}
Also used : HashMap(java.util.HashMap) CheServiceImpl(org.eclipse.che.api.environment.server.model.CheServiceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) CheServicesEnvironmentImpl(org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl) EnvironmentRecipeImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl) Test(org.testng.annotations.Test)

Example 38 with EnvironmentImpl

use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.

the class WorkspaceService method addEnvironment.

@POST
@Path("/{id}/environment")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Add a new environment to the workspace", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The workspace successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to add the environment"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 409, message = "Environment with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto addEnvironment(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam(value = "The new environment", required = true) EnvironmentDto newEnvironment, @ApiParam(value = "The name of the environment", required = true) @QueryParam("name") String envName) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
    requiredNotNull(newEnvironment, "New environment");
    requiredNotNull(envName, "New environment name");
    relativizeRecipeLinks(newEnvironment);
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
    workspace.getConfig().getEnvironments().put(envName, new EnvironmentImpl(newEnvironment));
    validator.validateConfig(workspace.getConfig());
    return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(id, workspace)), getServiceContext());
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 39 with EnvironmentImpl

use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.

the class StackServiceTest method setUp.

@BeforeMethod
public void setUp() throws NoSuchFieldException, IllegalAccessException {
    byte[] fileContent = STACK_ID.getBytes();
    stackIcon = new StackIcon(ICON_MEDIA_TYPE, "image/svg+xml", fileContent);
    componentsImpl = singletonList(new StackComponentImpl(COMPONENT_NAME, COMPONENT_VERSION));
    stackSourceImpl = new StackSourceImpl(SOURCE_TYPE, SOURCE_ORIGIN);
    CommandImpl command = new CommandImpl(COMMAND_NAME, COMMAND_LINE, COMMAND_TYPE);
    EnvironmentImpl environment = new EnvironmentImpl(null, null);
    WorkspaceConfigImpl workspaceConfig = WorkspaceConfigImpl.builder().setName(WORKSPACE_CONFIG_NAME).setDefaultEnv(DEF_ENVIRONMENT_NAME).setCommands(singletonList(command)).setEnvironments(singletonMap(ENVIRONMENT_NAME, environment)).build();
    stackSourceDto = newDto(StackSourceDto.class).withType(SOURCE_TYPE).withOrigin(SOURCE_ORIGIN);
    StackComponentDto stackComponentDto = newDto(StackComponentDto.class).withName(COMPONENT_NAME).withVersion(COMPONENT_VERSION);
    componentsDto = singletonList(stackComponentDto);
    stackDto = DtoFactory.getInstance().createDto(StackDto.class).withId(STACK_ID).withName(NAME).withDescription(DESCRIPTION).withScope(SCOPE).withCreator(CREATOR).withTags(tags).withSource(stackSourceDto).withComponents(componentsDto);
    stackImpl = StackImpl.builder().setId(STACK_ID).setName(NAME).setDescription(DESCRIPTION).setScope(SCOPE).setCreator(CREATOR).setTags(tags).setSource(stackSourceImpl).setComponents(componentsImpl).setWorkspaceConfig(workspaceConfig).setStackIcon(stackIcon).build();
    foreignStack = StackImpl.builder().setId(STACK_ID).setName(NAME).setDescription(DESCRIPTION).setScope(SCOPE).setCreator(FOREIGN_CREATOR).setTags(tags).setSource(stackSourceImpl).setComponents(componentsImpl).setWorkspaceConfig(workspaceConfig).setStackIcon(stackIcon).build();
    when(uriInfo.getBaseUriBuilder()).thenReturn(new UriBuilderImpl());
    final Field uriField = service.getClass().getSuperclass().getDeclaredField("uriInfo");
    uriField.setAccessible(true);
    uriField.set(service, uriInfo);
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) Field(java.lang.reflect.Field) StackComponentImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackComponentImpl) StackComponentDto(org.eclipse.che.api.workspace.shared.dto.stack.StackComponentDto) StackDto(org.eclipse.che.api.workspace.shared.dto.stack.StackDto) StackIcon(org.eclipse.che.api.workspace.server.stack.image.StackIcon) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) StackSourceImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackSourceImpl) StackSourceDto(org.eclipse.che.api.workspace.shared.dto.stack.StackSourceDto) UriBuilderImpl(org.everrest.core.impl.uri.UriBuilderImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 40 with EnvironmentImpl

use of org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl in project che by eclipse.

the class WorkspaceServiceTest method testWorkspaceLinks.

@Test
public void testWorkspaceLinks() throws Exception {
    // given
    final WorkspaceImpl workspace = createWorkspace(createConfigDto());
    EnvironmentImpl environment = workspace.getConfig().getEnvironments().get(workspace.getConfig().getDefaultEnv());
    assertNotNull(environment);
    final WorkspaceRuntimeImpl runtime = new WorkspaceRuntimeImpl(workspace.getConfig().getDefaultEnv(), null);
    MachineConfigImpl devMachineConfig = MachineConfigImpl.builder().setDev(true).setEnvVariables(emptyMap()).setServers(emptyList()).setLimits(new MachineLimitsImpl(1024)).setSource(new MachineSourceImpl("type").setContent("content")).setName(environment.getMachines().keySet().iterator().next()).setType("type").build();
    runtime.setDevMachine(new MachineImpl(devMachineConfig, "machine123", workspace.getId(), workspace.getConfig().getDefaultEnv(), USER_ID, MachineStatus.RUNNING, new MachineRuntimeInfoImpl(emptyMap(), emptyMap(), singletonMap("8080/https", new ServerImpl("wsagent", "https", "address", "url", new ServerPropertiesImpl("path", "internaladdress", "internalurl"))))));
    runtime.getMachines().add(runtime.getDevMachine());
    workspace.setStatus(RUNNING);
    workspace.setRuntime(runtime);
    when(wsManager.getWorkspace(workspace.getId())).thenReturn(workspace);
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/workspace/" + workspace.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    final WorkspaceDto workspaceDto = unwrapDto(response, WorkspaceDto.class);
    final Set<String> actualRels = workspaceDto.getLinks().stream().map(Link::getRel).collect(toSet());
    final Set<String> expectedRels = new HashSet<>(asList(LINK_REL_START_WORKSPACE, LINK_REL_REMOVE_WORKSPACE, GET_ALL_USER_WORKSPACES, LINK_REL_GET_SNAPSHOT, LINK_REL_GET_WORKSPACE_EVENTS_CHANNEL, LINK_REL_IDE_URL, LINK_REL_SELF, LINK_REL_ENVIRONMENT_OUTPUT_CHANNEL, LINK_REL_ENVIRONMENT_STATUS_CHANNEL));
    assertTrue(actualRels.equals(expectedRels), format("Links difference: '%s'. \n" + "Returned links: '%s', \n" + "Expected links: '%s'.", Sets.symmetricDifference(actualRels, expectedRels), actualRels.toString(), expectedRels.toString()));
    assertNotNull(workspaceDto.getRuntime().getLink(LINK_REL_STOP_WORKSPACE), "Runtime doesn't contain stop link");
    assertNotNull(workspaceDto.getRuntime().getLink(WSAGENT_REFERENCE), "Runtime doesn't contain wsagent link");
    assertNotNull(workspaceDto.getRuntime().getLink(WSAGENT_WEBSOCKET_REFERENCE), "Runtime doesn't contain wsagent.websocket link");
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ExtendedMachineImpl(org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) MachineSourceImpl(org.eclipse.che.api.machine.server.model.impl.MachineSourceImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) WorkspaceRuntimeImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceRuntimeImpl) MachineLimitsImpl(org.eclipse.che.api.machine.server.model.impl.MachineLimitsImpl) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) Matchers.anyString(org.mockito.Matchers.anyString) MachineRuntimeInfoImpl(org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl) Response(com.jayway.restassured.response.Response) MachineConfigImpl(org.eclipse.che.api.machine.server.model.impl.MachineConfigImpl) ServerImpl(org.eclipse.che.api.machine.server.model.impl.ServerImpl) ServerPropertiesImpl(org.eclipse.che.api.machine.server.model.impl.ServerPropertiesImpl) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

EnvironmentImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl)40 CheServicesEnvironmentImpl (org.eclipse.che.api.environment.server.model.CheServicesEnvironmentImpl)27 Test (org.testng.annotations.Test)23 ExtendedMachineImpl (org.eclipse.che.api.workspace.server.model.impl.ExtendedMachineImpl)17 CheServiceImpl (org.eclipse.che.api.environment.server.model.CheServiceImpl)15 Matchers.anyString (org.mockito.Matchers.anyString)14 EnvironmentRecipeImpl (org.eclipse.che.api.workspace.server.model.impl.EnvironmentRecipeImpl)10 LineConsumer (org.eclipse.che.api.core.util.LineConsumer)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 ServerConf2Impl (org.eclipse.che.api.workspace.server.model.impl.ServerConf2Impl)7 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)6 Instance (org.eclipse.che.api.machine.server.spi.Instance)5 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)5 CheServiceBuildContextImpl (org.eclipse.che.api.environment.server.model.CheServiceBuildContextImpl)4 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)4 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 ServerException (org.eclipse.che.api.core.ServerException)3 Machine (org.eclipse.che.api.core.model.machine.Machine)3 ExtendedMachine (org.eclipse.che.api.core.model.workspace.ExtendedMachine)3