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); }
/** 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; }
/** * Updates an existing workspace with a new configuration. * * <p> * * <p>Replace strategy is used for workspace update, it means that existing workspace data will be * replaced with given {@code update}. * * @param update workspace update * @return updated instance of the workspace * @throws NullPointerException when either {@code workspaceId} or {@code update} is null * @throws NotFoundException when workspace with given id doesn't exist * @throws ConflictException when any conflict occurs (e.g Workspace with such name already exists * in {@code namespace}) * @throws ServerException when any other error occurs */ public WorkspaceImpl updateWorkspace(String id, Workspace update) throws ConflictException, ServerException, NotFoundException, ValidationException { requireNonNull(id, "Required non-null workspace id"); requireNonNull(update, "Required non-null workspace update"); requireNonNull(update.getConfig(), "Required non-null workspace configuration update"); validator.validateConfig(update.getConfig()); validator.validateAttributes(update.getAttributes()); WorkspaceImpl workspace = workspaceDao.get(id); workspace.setConfig(new WorkspaceConfigImpl(update.getConfig())); workspace.setAttributes(update.getAttributes()); workspace.getAttributes().put(UPDATED_ATTRIBUTE_NAME, Long.toString(currentTimeMillis())); workspace.setTemporary(update.isTemporary()); return normalizeState(workspaceDao.update(workspace), true); }
public WorkspaceImpl(Workspace workspace, Account account) { this( workspace.getId(), account, workspace.getConfig(), workspace.getRuntime(), workspace.getAttributes(), workspace.isTemporary(), workspace.getStatus()); }
@Override public WorkspaceImpl updateWorkspace(String id, Workspace update) throws ConflictException, ServerException, NotFoundException, ValidationException { checkMaxEnvironmentRam(update.getConfig()); WorkspaceImpl workspace = this.getWorkspace(id); String accountId = workspace.getAccount().getId(); // Workspace must not be updated while the manager checks it's resources to allow start try (@SuppressWarnings("unused") Unlocker u = resourcesLocks.lock(accountId)) { return super.updateWorkspace(id, update); } }
"Workspace '{}/{}' with id '{}' is stopped by user '{}'", workspace.getNamespace(), workspace.getConfig().getName(), workspaceId, stoppedBy);
"Workspace '{}/{}' with id '{}' is stopping by user '{}'", workspace.getNamespace(), workspace.getConfig().getName(), workspace.getId(), stoppedBy);
WorkspaceConfig workspaceConfig = workspace.getConfig(); if (identity.getEnvName() != null) { environment = workspaceConfig.getEnvironments().get(identity.getEnvName());
WorkspaceConfig workspaceConfig = workspace.getConfig(); if (isStartRefused.get()) { throw new ConflictException(
/** Converts {@link Workspace} to {@link WorkspaceDto}. */ public static WorkspaceDto asDto(Workspace workspace) { WorkspaceDto workspaceDto = newDto(WorkspaceDto.class) .withId(workspace.getId()) .withStatus(workspace.getStatus()) .withNamespace(workspace.getNamespace()) .withTemporary(workspace.isTemporary()) .withAttributes(workspace.getAttributes()) .withConfig(asDto(workspace.getConfig())); if (workspace.getRuntime() != null) { RuntimeDto runtime = asDto(workspace.getRuntime()); workspaceDto.setRuntime(runtime); } return workspaceDto; }