public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) { this( workspaceConfig.getName(), workspaceConfig.getDescription(), workspaceConfig.getDefaultEnv(), workspaceConfig.getCommands(), workspaceConfig.getProjects(), workspaceConfig.getEnvironments(), workspaceConfig.getAttributes()); }
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()); } } }
throws NotFoundException, ServerException, ConflictException { if (config.getEnvironments().isEmpty()) { return; config.getEnvironments().get(firstNonNull(envName, config.getDefaultEnv())); final ResourceImpl ramToUse = new ResourceImpl( + "The workspace can't be start. Stop other workspaces or grant more resources.", namespace, config.getName(), printResourceInfo(requiredRam), printResourceInfo(availableRam),
WorkspaceConfig workspaceConfig = workspace.getConfig(); if (identity.getEnvName() != null) { environment = workspaceConfig.getEnvironments().get(identity.getEnvName()); if (environment == null) { throw new ServerException( InternalEnvironment internalEnv = createInternalEnvironment( environment, workspaceConfig.getAttributes(), workspaceConfig.getCommands()); runtime = infra.prepare(identity, internalEnv).getRuntime(); WorkspaceStatus runtimeStatus = runtime.getStatus();
"Start of the workspace '%s' is rejected by the system, " + "no more workspaces are allowed to start", workspaceConfig.getName())); InternalEnvironment internalEnv = createInternalEnvironment( environment, workspaceConfig.getAttributes(), workspaceConfig.getCommands()); RuntimeContext runtimeContext = infrastructure.prepare(runtimeId, internalEnv); InternalRuntime runtime = runtimeContext.getRuntime(); "Starting workspace '{}/{}' with id '{}' by user '{}'", workspace.getNamespace(), workspaceConfig.getName(), workspace.getId(), sessionUserNameOr("undefined"));
/** * 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."); } }
checkNotNull(config.getName(), "Workspace name required"); check( WS_NAME.matcher(config.getName()).matches(), "Incorrect workspace name, it must be between 3 and 100 characters and may contain digits, " + "latin letters, underscores, dots, dashes and must start and end only with digits, " for (Command command : config.getCommands()) { check( !isNullOrEmpty(command.getName()), "Workspace %s contains command with null or empty name", config.getName()); check( !isNullOrEmpty(command.getCommandLine()), "Command line required for command '%s' in workspace '%s'", command.getName(), config.getName());
/** Returns 'rel -> url' map of links for the given workspace. */ public Map<String, String> genLinks(Workspace workspace, ServiceContext serviceContext) throws ServerException { final UriBuilder uriBuilder = serviceContext.getServiceUriBuilder(); final LinkedHashMap<String, String> links = new LinkedHashMap<>(); links.put( LINK_REL_SELF, uriBuilder .clone() .path(WorkspaceService.class, "getByKey") .build(workspace.getId()) .toString()); links.put( LINK_REL_IDE_URL, uriBuilder .clone() .replacePath("") .path(workspace.getNamespace()) .path(workspace.getConfig().getName()) .build() .toString()); if (workspace.getStatus() != WorkspaceStatus.STOPPED) { addRuntimeLinks(links, workspace.getId(), serviceContext); } return links; }
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")); } } }
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; }
"Workspace '{}/{}' with id '{}' is stopped by user '{}'", workspace.getNamespace(), workspace.getConfig().getName(), workspaceId, stoppedBy);
public WorkspaceConfigImpl(WorkspaceConfig workspaceConfig) { this( workspaceConfig.getName(), workspaceConfig.getDescription(), workspaceConfig.getDefaultEnv(), workspaceConfig.getCommands(), workspaceConfig.getProjects(), workspaceConfig.getEnvironments(), workspaceConfig.getAttributes()); }
"Workspace '{}/{}' with id '{}' is stopping by user '{}'", workspace.getNamespace(), workspace.getConfig().getName(), workspace.getId(), stoppedBy);
/** 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()); }