private static EnvironmentImpl copyEnv(Workspace workspace, String envName) { requireNonNull(workspace, "Workspace should not be null."); requireNonNull(envName, "Environment name should not be null."); final Environment environment = workspace.getConfig().getEnvironments().get(envName); if (environment == null) { throw new IllegalArgumentException( format("Workspace '%s' doesn't contain environment '%s'", workspace.getId(), envName)); } return new EnvironmentImpl(environment); }
@VisibleForTesting void checkMaxEnvironmentRam(WorkspaceConfig config) throws ServerException { if (maxRamPerEnvMB < 0) { return; } if (config.getEnvironments().isEmpty()) { return; } for (Map.Entry<String, ? extends Environment> envEntry : config.getEnvironments().entrySet()) { Environment env = envEntry.getValue(); final long workspaceRam = environmentRamCalculator.calculate(env); if (workspaceRam > maxRamPerEnvMB) { throw new LimitExceededException( format("You are only allowed to use %d mb. RAM per workspace.", maxRamPerEnvMB), ImmutableMap.of( "environment_max_ram", Long.toString(maxRamPerEnvMB), "environment_max_ram_unit", "mb", "environment_ram", Long.toString(workspaceRam), "environment_ram_unit", "mb")); } } }
/** * Check that workspace has either plugins defined in attributes (Che 7) or installers defined in * machines (Che 6). * * @throws ValidationException if workspace config contains both installers section and nonempty * plugins or editor field in attributes. */ private void validatePlugins(WorkspaceConfig config) throws ValidationException { Optional<String> installers = config .getEnvironments() .values() .stream() .flatMap(env -> env.getMachines().values().stream()) .flatMap(machine -> machine.getInstallers().stream()) .findAny(); Map<String, String> attributes = config.getAttributes(); if (isSidecarBasedWorkspace(attributes) && installers.isPresent()) { throw new ValidationException("Workspace config cannot have both plugins and installers."); } }
private void validateEnvironments(WorkspaceConfig config) throws ValidationException { boolean environmentIsNotSet = (config.getEnvironments() == null || config.getEnvironments().isEmpty()) && isNullOrEmpty(config.getDefaultEnv()); boolean isSidecarWorkspace = isSidecarBasedWorkspace(config.getAttributes()); if (environmentIsNotSet && isSidecarWorkspace) { // sidecar based workspaces allowed not to have environment return; } check(!isNullOrEmpty(config.getDefaultEnv()), "Workspace default environment name required"); checkNotNull(config.getEnvironments(), "Workspace must contain at least one environment"); check( config.getEnvironments().containsKey(config.getDefaultEnv()), "Workspace default environment configuration required"); for (Environment environment : config.getEnvironments().values()) { checkNotNull(environment, "Environment must not be null"); Recipe recipe = environment.getRecipe(); checkNotNull(recipe, "Environment recipe must not be null"); checkNotNull(recipe.getType(), "Environment recipe type must not be null"); for (Entry<String, ? extends MachineConfig> machineEntry : environment.getMachines().entrySet()) { validateMachine(machineEntry.getKey(), machineEntry.getValue()); } } }
/** Converts {@link WorkspaceConfig} to {@link WorkspaceConfigDto}. */ public static WorkspaceConfigDto asDto(WorkspaceConfig workspace) { List<CommandDto> commands = workspace.getCommands().stream().map(DtoConverter::asDto).collect(toList()); List<ProjectConfigDto> projects = workspace.getProjects().stream().map(DtoConverter::asDto).collect(toList()); Map<String, EnvironmentDto> environments = workspace .getEnvironments() .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> asDto(entry.getValue()))); return newDto(WorkspaceConfigDto.class) .withName(workspace.getName()) .withDefaultEnv(workspace.getDefaultEnv()) .withCommands(commands) .withProjects(projects) .withEnvironments(environments) .withAttributes(workspace.getAttributes()) .withDescription(workspace.getDescription()); }
public WorkspaceConfigImplBuilder fromConfig(WorkspaceConfig workspaceConfig) { this.name = workspaceConfig.getName(); this.description = workspaceConfig.getDescription(); this.defaultEnvName = workspaceConfig.getDefaultEnv(); this.projects = workspaceConfig.getProjects(); this.commands = workspaceConfig.getCommands(); this.environments = workspaceConfig.getEnvironments(); return this; }
public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) { this( workspaceConfig.getName(), workspaceConfig.getDescription(), workspaceConfig.getDefaultEnv(), workspaceConfig.getCommands(), workspaceConfig.getProjects(), workspaceConfig.getEnvironments(), workspaceConfig.getAttributes()); }
throws NotFoundException, ServerException, ConflictException { if (config.getEnvironments().isEmpty()) { return; config.getEnvironments().get(firstNonNull(envName, config.getDefaultEnv())); final ResourceImpl ramToUse = new ResourceImpl(
public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) { this( workspaceConfig.getName(), workspaceConfig.getDescription(), workspaceConfig.getDefaultEnv(), workspaceConfig.getCommands(), workspaceConfig.getProjects(), workspaceConfig.getEnvironments(), workspaceConfig.getAttributes()); }
WorkspaceConfig workspaceConfig = workspace.getConfig(); if (identity.getEnvName() != null) { environment = workspaceConfig.getEnvironments().get(identity.getEnvName()); if (environment == null) { throw new ServerException(