public EnvironmentDtoImpl(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto origin) { java.util.Map<java.lang.String, org.eclipse.che.api.workspace.shared.dto.MachineConfigDto> machinesIn = origin.getMachines(); if (machinesIn != null) { java.util.Map<java.lang.String, org.eclipse.che.api.workspace.shared.dto.MachineConfigDto> machinesOut = new java.util.HashMap<java.lang.String, org.eclipse.che.api.workspace.shared.dto.MachineConfigDto>(); for (java.util.Map.Entry<String, org.eclipse.che.api.workspace.shared.dto.MachineConfigDto> entry0 : machinesIn.entrySet()) { org.eclipse.che.api.workspace.shared.dto.MachineConfigDto machinesIn_ = entry0.getValue(); machinesOut.put(entry0.getKey(), machinesIn_ == null ? null : new MachineConfigDtoImpl(machinesIn_)); } this.machines = machinesOut; } org.eclipse.che.api.workspace.shared.dto.RecipeDto recipeIn = origin.getRecipe(); this.recipe = recipeIn == null ? null : new RecipeDtoImpl(recipeIn); }
private void relativizeRecipeLinks(EnvironmentDto environment) { if (environment != null) { RecipeDto recipe = environment.getRecipe(); if (recipe != null) { if ("dockerfile".equals(recipe.getType())) { String location = recipe.getLocation(); if (location != null && location.startsWith(apiEndpoint)) { recipe.setLocation(location.substring(apiEndpoint.length())); } } } } }
@Override public Workspace createWorkspace( String workspaceName, int memory, MemoryMeasure memoryUnit, WorkspaceConfigDto workspace) throws Exception { EnvironmentDto environment = workspace.getEnvironments().get("replaced_name"); environment .getMachines() .values() .stream() .filter(WsAgentMachineFinderUtil::containsWsAgentServerOrInstaller) .forEach( m -> m.getAttributes() .put(MEMORY_LIMIT_ATTRIBUTE, Long.toString(convertToByte(memory, memoryUnit)))); workspace.getEnvironments().remove("replaced_name"); workspace.getEnvironments().put(workspaceName, environment); workspace.setName(workspaceName); workspace.setDefaultEnv(workspaceName); WorkspaceDto workspaceDto = requestFactory .fromUrl(getBaseUrl()) .usePostMethod() .setBody(workspace) .request() .asDto(WorkspaceDto.class); LOG.info("Workspace name='{}' and id='{}' created", workspaceName, workspaceDto.getId()); return workspaceDto; }
/** Converts {@link Environment} to {@link EnvironmentDto}. */ public static EnvironmentDto asDto(Environment env) { final EnvironmentDto envDto = newDto(EnvironmentDto.class); if (env.getMachines() != null) { envDto.withMachines( env.getMachines() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue())))); } if (env.getRecipe() != null) { envDto.withRecipe( newDto(RecipeDto.class) .withType(env.getRecipe().getType()) .withContentType(env.getRecipe().getContentType()) .withLocation(env.getRecipe().getLocation()) .withContent(env.getRecipe().getContent())); } return envDto; }