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