/** * Asynchronously starts workspace from the given configuration. * * @param config workspace configuration from which workspace is created and started * @param namespace workspace name is unique in this namespace * @return starting workspace * @throws NullPointerException when {@code workspaceId} is null * @throws NotFoundException when workspace with given {@code workspaceId} doesn't exist * @throws ServerException when any other error occurs during workspace start */ public WorkspaceImpl startWorkspace( WorkspaceConfig config, String namespace, boolean isTemporary, Map<String, String> options) throws ServerException, NotFoundException, ConflictException, ValidationException { requireNonNull(config, "Required non-null configuration"); requireNonNull(namespace, "Required non-null namespace"); validator.validateConfig(config); final WorkspaceImpl workspace = doCreateWorkspace( config, accountManager.getByName(namespace), Collections.emptyMap(), isTemporary); startAsync(workspace, workspace.getConfig().getDefaultEnv(), options); return normalizeState(workspace, true); }
private String getValidatedEnvironmentName(WorkspaceImpl workspace, @Nullable String envName) throws NotFoundException, ServerException { if (envName != null && !workspace.getConfig().getEnvironments().containsKey(envName)) { throw new NotFoundException( format( "Workspace '%s:%s' doesn't contain environment '%s'", workspace.getNamespace(), workspace.getConfig().getName(), envName)); } envName = firstNonNull(envName, workspace.getConfig().getDefaultEnv()); if (envName == null && SidecarToolingWorkspaceUtil.isSidecarBasedWorkspace( workspace.getConfig().getAttributes())) { // Sidecar-based workspaces are allowed not to have any environments return null; } // validate environment in advance if (envName == null) { throw new NotFoundException( format( "Workspace %s:%s can't use null environment", workspace.getNamespace(), workspace.getConfig().getName())); } try { runtimes.validate(workspace.getConfig().getEnvironments().get(envName)); } catch (InfrastructureException | ValidationException e) { throw new ServerException(e); } return envName; }