@Override public int hashCode() { return Objects.hash(id, getRecipe(), getMachines()); }
@Override public DockerImageEnvironment create(Environment sourceEnv) throws InfrastructureException, ValidationException { checkNotNull( sourceEnv, "Null environment is not supported by docker image environment factory"); if (sourceEnv.getRecipe().getLocation() != null) { // move image from location to content EnvironmentImpl envCopy = new EnvironmentImpl(sourceEnv); envCopy.getRecipe().setContent(sourceEnv.getRecipe().getLocation()); envCopy.getRecipe().setLocation(null); return super.create(envCopy); } return super.create(sourceEnv); }
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); }
environment = copyEnv(workspace, envName); requireNonNull(environment, "Environment should not be null " + workspaceId); requireNonNull(environment.getRecipe(), "Recipe should not be null " + workspaceId); requireNonNull( environment.getRecipe().getType(), "Recipe type should not be null " + workspaceId);
public WorkspaceConfigImpl( String name, String description, String defaultEnv, List<? extends Command> commands, List<? extends ProjectConfig> projects, Map<String, ? extends Environment> environments, Map<String, String> attributes) { this.name = name; this.defaultEnv = defaultEnv; this.description = description; if (environments != null) { this.environments = environments .entrySet() .stream() .collect(toMap(Map.Entry::getKey, entry -> new EnvironmentImpl(entry.getValue()))); } if (commands != null) { this.commands = commands.stream().map(CommandImpl::new).collect(toList()); } if (projects != null) { this.projects = projects.stream().map(ProjectConfigImpl::new).collect(toList()); } if (attributes != null) { this.attributes = new HashMap<>(attributes); } }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof EnvironmentImpl)) return false; EnvironmentImpl that = (EnvironmentImpl) o; return Objects.equals(id, that.id) && Objects.equals(getRecipe(), that.getRecipe()) && Objects.equals(getMachines(), that.getMachines()); }
@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)); }
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id); EnvironmentImpl previous = workspace.getConfig().getEnvironments().put(envName, new EnvironmentImpl(update)); if (previous == null) { throw new NotFoundException(