@Override public void update(ProfileImpl profile) throws NotFoundException, ServerException { throw new ServerException("Given operation doesn't supported on current configured storage."); }
/** Removes key pair from cache and DB. */ @VisibleForTesting void removeKeyPair(String workspaceId) { try { signatureKeyDao.remove(workspaceId); LOG.debug("Removed signature key pair for ws id {}.", workspaceId); } catch (ServerException e) { LOG.error( "Unable to cleanup machine token signature keypairs for ws {}. Cause: {}", workspaceId, e.getMessage()); } }
@Override public void create(ProfileImpl profile) throws ServerException, ConflictException { throw new ServerException("Given operation doesn't supported on current configured storage."); }
@PostConstruct void initialize() { try { removeTemporaryWs(); } catch (ServerException e) { LOG.warn("Unable to cleanup temporary workspaces on startup: " + e.getMessage(), e); } }
@Override public void remove(String userId) throws ServerException { throw new ServerException("Given operation doesn't supported on current configured storage."); }
void shutdown() { try { removeTemporaryWs(); } catch (ServerException e) { LOG.warn("Unable to cleanup temporary workspaces on shutdown: " + e.getMessage(), e); } }
@Override public void removeWorker(String workspaceId, String userId) throws ServerException { try { super.remove(userId, workspaceId); } catch (NotFoundException e) { throw new ServerException(e); } }
@VisibleForTesting void removeTemporaryWs() throws ServerException { for (WorkspaceImpl workspace : Pages.iterate( (maxItems, skipCount) -> workspaceDao.getWorkspaces(true, maxItems, skipCount))) { WorkspaceStatus status = runtimes.getStatus(workspace.getId()); if (status == WorkspaceStatus.STOPPED) { try { workspaceDao.remove(workspace.getId()); } catch (ServerException e) { LOG.error( "Unable to cleanup temporary workspace {}. Reason is {}", workspace.getId(), e.getMessage()); } } } } }
@Override public void remove(String owner, String service, String name) throws ServerException, NotFoundException { requireNonNull(owner); requireNonNull(service); requireNonNull(name); try { doRemove(owner, service, name); } catch (RuntimeException e) { throw new ServerException(e); } }
@Override public void remove(String workspaceId) throws ServerException { requireNonNull(workspaceId, "Required non-null workspace Id"); try { doRemove(workspaceId); } catch (RuntimeException ex) { throw new ServerException(ex.getMessage(), ex); } }
@Override public void store(FreeResourcesLimitImpl resourcesLimit) throws ServerException { requireNonNull(resourcesLimit, "Required non-null resource limit"); try { doStore(resourcesLimit); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
@Override @Transactional public List<SshPairImpl> get(String owner) throws ServerException { requireNonNull(owner, "Required non-null owner"); try { return managerProvider .get() .createNamedQuery("SshKeyPair.getByOwner", SshPairImpl.class) .setParameter("owner", owner) .getResultList(); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override protected WorkerImpl getEntity(String userId, String instanceId) throws NotFoundException, ServerException { try { return doGet(userId, instanceId); } catch (NoResultException e) { throw new NotFoundException( format("Worker of workspace '%s' with id '%s' was not found.", instanceId, userId)); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
@Override protected StackPermissionsImpl getEntity(String userId, String instanceId) throws NotFoundException, ServerException { try { return doGet(userId, instanceId); } catch (NoResultException e) { throw new NotFoundException( format("Permissions on stack '%s' of user '%s' was not found.", instanceId, userId)); } catch (RuntimeException e) { throw new ServerException(e.getMessage(), e); } }
@Override public void remove(String id) throws ServerException { requireNonNull(id, "Required non-null id"); try { doRemove(id); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override public void remove(String id) throws ServerException { requireNonNull(id, "Required non-null id"); try { doRemove(id); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override @Transactional public List<SshPairImpl> get(String owner, String service) throws ServerException { requireNonNull(owner); requireNonNull(service); try { return managerProvider .get() .createNamedQuery("SshKeyPair.getByOwnerAndService", SshPairImpl.class) .setParameter("owner", owner) .setParameter("service", service) .getResultList(); } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
@Transactional protected List<WorkerImpl> doGetByUser(@Nullable String userId) throws ServerException { try { return managerProvider .get() .createNamedQuery("Worker.getByUserId", WorkerImpl.class) .setParameter("userId", userId) .getResultList(); } catch (RuntimeException e) { throw new ServerException(e.getLocalizedMessage(), e); } }
@POST @Path("/github") @Consumes(MediaType.APPLICATION_JSON) public void setGitHubToken(OAuthToken token) throws ServerException { if (token == null) { throw new ServerException("No token provided"); } OAuthAuthenticator provider = providers.getAuthenticator(GIT_HUB_OAUTH_PROVIDER); if (provider == null) { throw new ServerException("\"" + GIT_HUB_OAUTH_PROVIDER + "\" oauth provider not registered"); } else if (!(provider instanceof OpenShiftGitHubOAuthAuthenticator)) { throw new ServerException( "'setToken' API is not supported by the original 'GitHubOAuthAuthenticator', 'OpenShiftGitHubOAuthAuthenticator' should be configured instead"); } String userId = EnvironmentContext.getCurrent().getSubject().getUserId(); try { ((OpenShiftGitHubOAuthAuthenticator) provider).setToken(userId, token); } catch (IOException e) { throw new ServerException(e.getMessage()); } }
@Override public void onCreateProject( String projectWsPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException, NotFoundException { try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(RESOURCE_NAME)) { fsManager.createDir(projectWsPath); String wsPath = resolve(projectWsPath, FILE_NAME); fsManager.createFile(wsPath, inputStream); } catch (IOException e) { throw new ServerException(e); } }