@Override public int hashCode() { int hash = 7; hash = 31 * hash + Objects.hashCode(id); hash = 31 * hash + Objects.hashCode(name); hash = 31 * hash + Objects.hashCode(description); hash = 31 * hash + Objects.hashCode(defaultEnv); hash = 31 * hash + getCommands().hashCode(); hash = 31 * hash + getProjects().hashCode(); hash = 31 * hash + getEnvironments().hashCode(); hash = 31 * hash + getAttributes().hashCode(); return hash; }
/** Syncs {@link #name} with config name. */ private void syncName() { name = config == null ? null : config.getName(); }
public WorkspaceConfigImpl build() { return new WorkspaceConfigImpl( name, description, defaultEnvName, commands, projects, environments, attributes); }
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; }
@Transactional protected void doCreate(WorkspaceImpl workspace) { if (workspace.getConfig() != null) { workspace.getConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } EntityManager manager = managerProvider.get(); manager.persist(workspace); manager.flush(); }
@DELETE @Path("/{id}/environment/{name}") @ApiOperation( value = "Remove the environment from the workspace", notes = "This operation can be performed only by the workspace owner") @ApiResponses({ @ApiResponse(code = 204, message = "The environment successfully removed"), @ApiResponse(code = 403, message = "The user does not have access remove the environment"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void deleteEnvironment( @ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the environment") @PathParam("name") String envName) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { final WorkspaceImpl workspace = workspaceManager.getWorkspace(id); if (workspace.getConfig().getEnvironments().remove(envName) != null) { doUpdate(id, workspace); } }
@DELETE @Path("/{id}/command/{name}") @ApiOperation( value = "Remove the command from the workspace", notes = "This operation can be performed only by the workspace owner") @ApiResponses({ @ApiResponse(code = 204, message = "The command successfully removed"), @ApiResponse(code = 403, message = "The user does not have access delete the command"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void deleteCommand( @ApiParam("The id of the workspace") @PathParam("id") String id, @ApiParam("The name of the command to remove") @PathParam("name") String commandName) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { WorkspaceImpl workspace = workspaceManager.getWorkspace(id); if (workspace .getConfig() .getCommands() .removeIf(command -> command.getName().equals(commandName))) { doUpdate(id, workspace); } }
/** * 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); }
@Transactional protected void doCreate(WorkspaceImpl workspace) { if (workspace.getConfig() != null) { workspace.getConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } EntityManager manager = managerProvider.get(); manager.persist(workspace); manager.flush(); }
@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); WorkspaceImpl workspace = workspaceManager.getWorkspace(id); workspace.getConfig().getEnvironments().put(envName, new EnvironmentImpl(newEnvironment)); return asDtoWithLinksAndToken(doUpdate(id, workspace)); }
@POST @Path("/{id}/command") @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @ApiOperation( value = "Update the workspace by adding a new command to it", 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 update the workspace"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 409, message = "The command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public WorkspaceDto addCommand( @ApiParam("The workspace id") @PathParam("id") String id, @ApiParam(value = "The new workspace command", required = true) CommandDto newCommand) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { requiredNotNull(newCommand, "Command"); WorkspaceImpl workspace = workspaceManager.getWorkspace(id); workspace.getConfig().getCommands().add(new CommandImpl(newCommand)); return asDtoWithLinksAndToken(doUpdate(id, workspace)); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof WorkspaceConfigImpl)) { return false; } final WorkspaceConfigImpl that = (WorkspaceConfigImpl) obj; return Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(description, that.description) && Objects.equals(defaultEnv, that.defaultEnv) && getCommands().equals(that.getCommands()) && getProjects().equals(that.getProjects()) && getEnvironments().equals(that.getEnvironments()) && getAttributes().equals(that.getAttributes()); }
@DELETE @Path("/{id}/project/{path:.*}") @ApiOperation( value = "Remove the project from the workspace", notes = "This operation can be performed only by the workspace owner") @ApiResponses({ @ApiResponse(code = 204, message = "The project successfully removed"), @ApiResponse(code = 403, message = "The user does not have access remove the project"), @ApiResponse(code = 404, message = "The workspace not found"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void deleteProject( @ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the project to remove") @PathParam("path") String path) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException { final WorkspaceImpl workspace = workspaceManager.getWorkspace(id); final String normalizedPath = path.startsWith("/") ? path : '/' + path; if (workspace .getConfig() .getProjects() .removeIf(project -> project.getPath().equals(normalizedPath))) { doUpdate(id, workspace); } }
@Override public WorkspaceImpl create(WorkspaceImpl workspace) throws ConflictException, ServerException { requireNonNull(workspace, "Required non-null workspace"); try { doCreate(workspace); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with id '%s' or name '%s' in namespace '%s' already exists", workspace.getId(), workspace.getConfig().getName(), workspace.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } return new WorkspaceImpl(workspace); }
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id); EnvironmentImpl previous = workspace.getConfig().getEnvironments().put(envName, new EnvironmentImpl(update)); if (previous == null) { throw new NotFoundException(
this.workspaceConfig = new WorkspaceConfigImpl(workspaceConfig);
requiredNotNull(update, "Command update"); WorkspaceImpl workspace = workspaceManager.getWorkspace(id); List<CommandImpl> commands = workspace.getConfig().getCommands(); if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) { throw new NotFoundException(
@Transactional protected StackImpl doUpdate(StackImpl update) throws NotFoundException { final EntityManager manager = managerProvider.get(); if (manager.find(StackImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getWorkspaceConfig() != null) { update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } StackImpl merged = manager.merge(update); manager.flush(); return merged; } }
@Override public WorkspaceImpl update(WorkspaceImpl update) throws NotFoundException, ConflictException, ServerException { requireNonNull(update, "Required non-null update"); try { return new WorkspaceImpl(doUpdate(update)); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with name '%s' in namespace '%s' already exists", update.getConfig().getName(), update.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } }
activeWorkspace .getConfig() .getEnvironments() .get(activeWorkspace.getRuntime().getActiveEnv()); if (startingEnvironment != null) {