org.eclipse.che.api.core.ServerException Java Examples
The following examples show how to use
org.eclipse.che.api.core.ServerException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MachineInnerRsyncAgentLauncherImpl.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Override public void launch(Instance machine, Agent agent) throws ServerException, AgentStartException { super.launch(machine, agent); DockerNode node = (DockerNode) machine.getNode(); DockerInstance dockerMachine = (DockerInstance) machine; try { node.bindWorkspace(); } catch (EnvironmentException e) { throw new AgentStartException( format( "Agent '%s' start failed because of an error with underlying environment. Error: %s", agent.getId(), e.getLocalizedMessage())); } LOG.info( "Docker machine has been deployed. " + "ID '{}'. Workspace ID '{}'. " + "Container ID '{}'. RAM '{}'. Node host '{}'. Node IP '{}'", machine.getId(), machine.getWorkspaceId(), dockerMachine.getContainer(), dockerMachine.getConfig().getLimits().getRam(), node.getHost(), node.getIp()); }
Example #2
Source File: BitbucketConnectionImpl.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Override public List<BitbucketRepository> getRepositoryForks(String owner, String repositorySlug) throws IOException, BitbucketException, ServerException { final List<BitbucketRepository> repositories = new ArrayList<>(); BitbucketRepositoriesPage repositoryPage = newDto(BitbucketRepositoriesPage.class); do { final String nextPageUrl = repositoryPage.getNext(); final String url = nextPageUrl == null ? urlTemplates.forksUrl(owner, repositorySlug) : nextPageUrl; repositoryPage = getBitbucketPage(this, url, BitbucketRepositoriesPage.class); repositories.addAll(repositoryPage.getValues()); } while (repositoryPage.getNext() != null); return repositories; }
Example #3
Source File: DockerEnvironmentBackupManagerTest.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Test( expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Sync port is not exposed in ws-machine. Workspace projects syncing is not possible" ) public void backupShouldThrowErrorIfMachineDoesNotContainServerWithSshPort() throws Exception { // given when(machineRuntimeInfo.getServers()) .thenReturn( singletonMap( "23/tcp", new ServerImpl("ref", "proto", "127.0.0.1:" + PUBLISHED_SSH_PORT, null, null))); backupManager.backupWorkspace(WORKSPACE_ID); // when backupManager.backupWorkspace(WORKSPACE_ID); }
Example #4
Source File: HostedMachineProviderImpl.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Override protected void checkContainerIsRunning(String container) throws IOException, ServerException { // Sometimes Swarm doesn't see newly created containers for several seconds. // Here we retry operation to ensure that such behavior of Swarm doesn't affect the product. try { super.checkContainerIsRunning(container); } catch (ContainerNotFoundException e) { try { Thread.sleep(SWARM_WAIT_BEFORE_REPEAT_WORKAROUND_TIME_MS); super.checkContainerIsRunning(container); } catch (InterruptedException ignored) { // throw original error throw e; } } }
Example #5
Source File: BitbucketConnectionImpl.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Override public List<BitbucketPullRequest> getRepositoryPullRequests(String owner, String repositorySlug) throws ServerException, IOException, BitbucketException { final List<BitbucketPullRequest> pullRequests = new ArrayList<>(); BitbucketPullRequestsPage pullRequestsPage = newDto(BitbucketPullRequestsPage.class); do { final String nextPageUrl = pullRequestsPage.getNext(); final String url = nextPageUrl == null ? urlTemplates.pullRequestUrl(owner, repositorySlug) : nextPageUrl; pullRequestsPage = getBitbucketPage(this, url, BitbucketPullRequestsPage.class); pullRequests.addAll(pullRequestsPage.getValues()); } while (pullRequestsPage.getNext() != null); return pullRequests; }
Example #6
Source File: HostedMachineProviderImplTest.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Test(expectedExceptions = ServerException.class) public void shouldNotRepeatContainerInspectionOnCheckContainerStatusIfInspectionExceptionDiffers() throws Exception { // given when(dockerConnector.inspectContainer(anyString())) .thenThrow(new DockerException("test exception", 500)) .thenReturn(containerInfo); // when try { createInstanceFromRecipe(); } finally { // then verify(dockerConnector).inspectContainer(anyString()); } }
Example #7
Source File: WorkspaceFilesCleanUpScriptExecutor.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Execute workspace cleanUp script. * * @param workspace to cleanUp files. * @throws IOException in case I/O error. * @throws ServerException in case internal server error. */ @Override public void clear(Workspace workspace) throws IOException, ServerException { File wsFolder = workspaceIdHashLocationFinder.calculateDirPath(backupsRootDir, workspace.getId()); CommandLine commandLine = new CommandLine(workspaceCleanUpScript, wsFolder.getAbsolutePath()); try { execute(commandLine.asArray(), cleanUpTimeOut); } catch (InterruptedException | TimeoutException e) { throw new ServerException( format( "Failed to delete workspace files by path: '%s' for workspace with id: '%s'", wsFolder.getAbsolutePath(), workspace.getId()), e); } }
Example #8
Source File: MicrosoftVstsService.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@PUT @Path("/pullrequests/{account}/{collection}/{project}/{repository}/{pullRequest}") @Consumes(APPLICATION_JSON) public MicrosoftPullRequest updatePullRequest( @PathParam("account") String account, @PathParam("collection") String collection, @PathParam("project") String project, @PathParam("repository") String repository, @PathParam("pullRequest") String pullRequestId, MicrosoftPullRequest pullRequest) throws IOException, ServerException, UnauthorizedException { final String repositoryId = microsoftVstsRestClient.getRepository(account, collection, project, repository).getId(); return microsoftVstsRestClient.updatePullRequests( account, collection, repositoryId, pullRequestId, pullRequest); }
Example #9
Source File: FactoryConnection.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Update a given factory * * @param factory the factory to update * @return the updated factory or null if an error occurred during the call to 'updateFactory' * @throws ServerException */ public FactoryDto updateFactory(final FactoryDto factory) throws ServerException { final String factoryId = factory.getId(); final String url = fromUri(baseUrl) .path(FactoryService.class) .path(FactoryService.class, "updateFactory") .build(factoryId) .toString(); FactoryDto newFactory; HttpJsonRequest httpJsonRequest = httpJsonRequestFactory.fromUrl(url).usePutMethod().setBody(factory); try { HttpJsonResponse response = httpJsonRequest.request(); newFactory = response.asDto(FactoryDto.class); } catch (IOException | ApiException e) { LOG.error(e.getLocalizedMessage(), e); throw new ServerException(e.getLocalizedMessage()); } return newFactory; }
Example #10
Source File: EmailInviteSender.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Override public void onEvent(InviteCreatedEvent event) { if (event.getInitiatorId() != null) { Invite invite = event.getInvite(); try { sendEmail(event.getInitiatorId(), invite); } catch (ServerException e) { LOG.warn( "Error while processing email invite to {} with id {} for user. Cause: {}", invite.getDomainId(), invite.getInstanceId(), invite.getEmail(), e.getLocalizedMessage()); } } }
Example #11
Source File: DockerEnvironmentBackupManagerTest.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Test( expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Sync port is not exposed in ws-machine. Workspace projects syncing is not possible" ) public void restoreShouldThrowErrorIfSshPortIsNotPublishedInContainer() throws Exception { // given NetworkSettings networkSettings = new NetworkSettings(); networkSettings.setPorts( singletonMap("23/tcp", singletonList(new PortBinding().withHostPort(PUBLISHED_SSH_PORT)))); ContainerInfo containerInfo = new ContainerInfo(); containerInfo.setNetworkSettings(networkSettings); ContainerState containerState = new ContainerState(); containerState.setRunning(true); containerInfo.setState(containerState); when(docker.inspectContainer(eq(CONTAINER_ID))).thenReturn(containerInfo); // when backupManager.restoreWorkspaceBackup(WORKSPACE_ID, CONTAINER_ID, NODE_HOST); }
Example #12
Source File: InviteService.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@POST @Consumes(APPLICATION_JSON) @ApiOperation( value = "Invite unregistered user by email " + "or update permissions for already invited user", notes = "Invited user will receive email notification only on invitation creation" ) @ApiResponses({ @ApiResponse(code = 204, message = "The invitation successfully created/updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 409, message = "User with specified email is already registered"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void invite(@ApiParam(value = "The invite to store", required = true) InviteDto inviteDto) throws BadRequestException, NotFoundException, ConflictException, ServerException { checkArgument(inviteDto != null, "Invite required"); checkArgument(!isNullOrEmpty(inviteDto.getEmail()), "Email required"); checkArgument(!isNullOrEmpty(inviteDto.getDomainId()), "Domain id required"); checkArgument(!isNullOrEmpty(inviteDto.getInstanceId()), "Instance id required"); checkArgument(!inviteDto.getActions().isEmpty(), "One or more actions required"); emailValidator.validateUserMail(inviteDto.getEmail()); inviteManager.store(inviteDto); }
Example #13
Source File: MicrosoftVstsRestClient.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Returns the list of active pull request in given repository. Generates html url for each pull * requests * * @param repositoryId the id of the repository * @throws IOException when any io error occurs * @throws ServerException when server responds with unexpected code * @throws UnauthorizedException when user in not authorized to call this method */ public List<MicrosoftPullRequest> getPullRequests( String account, String collection, String project, String repository, String repositoryId) throws IOException, ServerException, UnauthorizedException { return doGet( templates.pullRequestsUrl(account, collection, repositoryId), MicrosoftPullRequestList.class) .getValue() .stream() .peek( pr -> pr.setHtmlUrl( templates.pullRequestHtmlUrl( account, collection, project, repository, String.valueOf(pr.getPullRequestId())))) .collect(Collectors.toList()); }
Example #14
Source File: VSTSWebhookService.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Get configured 'work item created' webhook for given account, host and collection * * @param host the VSTS host * @param account the VSTS account * @param collection the VSTS collection * @return the webhook configured for given account, host and collection or null if no webhook is * configured * @throws ServerException */ private Optional<WorkItemCreatedWebhook> getWorkItemCreatedWebhook( final String host, final String account, final String collection) throws ServerException { final List webhooks = getVSTSWebhooks(WORK_ITEM_CREATED_WEBHOOK); WorkItemCreatedWebhook webhook = null; for (Object o : webhooks) { final WorkItemCreatedWebhook w = (WorkItemCreatedWebhook) o; final String webhookHost = w.getHost(); final String webhookAccount = w.getAccount(); final String webhookCollection = w.getCollection(); if (host.equals(webhookHost) && account.equals(webhookAccount) && collection.equals(webhookCollection)) { webhook = w; break; } } return Optional.ofNullable(webhook); }
Example #15
Source File: BitbucketServerConnectionImpl.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Override public List<BitbucketPullRequest> getRepositoryPullRequests(String owner, String repositorySlug) throws ServerException, IOException, BitbucketException { final List<BitbucketPullRequest> pullRequests = new ArrayList<>(); BitbucketServerPullRequestsPage pullRequestsPage = null; do { final String url = urlTemplates.pullRequestUrl(owner, repositorySlug) + (pullRequestsPage != null ? "?start=" + valueOf(pullRequestsPage.getNextPageStart()) : ""); pullRequestsPage = getBitbucketPage(this, url, BitbucketServerPullRequestsPage.class); pullRequests.addAll( pullRequestsPage .getValues() .stream() .map(BitbucketServerDTOConverter::convertToBitbucketPullRequest) .collect(Collectors.toList())); } while (!pullRequestsPage.isIsLastPage()); return pullRequests; }
Example #16
Source File: PasswordServiceTest.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Test public void shouldRespond500IfOtherErrorOccursOnSetupPass() throws Exception { when(recoveryStorage.isValid(UUID)).thenReturn(true); when(recoveryStorage.get(UUID)).thenReturn(USER_EMAIL); when(userManager.getByEmail(USER_EMAIL)).thenReturn(user); doThrow(new ServerException("test")).when(userManager).update(any(User.class)); Response response = given() .formParam("uuid", UUID) .formParam("password", NEW_PASSWORD) .when() .post(SERVICE_PATH + "/setup"); assertEquals(response.statusCode(), 500); assertEquals( unwrapDto(response, ServiceError.class).getMessage(), "Unable to setup password. Please contact support."); verify(recoveryStorage, times(1)).remove(UUID); verify(userManager).update(any(User.class)); }
Example #17
Source File: JenkinsWebhookManager.java From codenvy with Eclipse Public License 1.0 | 6 votes |
private Factory createFailedFactory(String factoryId, String repositoryUrl, String commitId) throws ConflictException, ServerException, NotFoundException { FactoryImpl factory = (FactoryImpl) factoryManager.getById(factoryId); factory.setName(factory.getName() + "_" + commitId); factory .getWorkspace() .getProjects() .stream() .filter(project -> project.getSource().getLocation().equals(repositoryUrl)) .forEach( project -> { Map<String, String> parameters = project.getSource().getParameters(); parameters.remove("branch"); parameters.put("commitId", commitId); }); return factoryManager.saveFactory(factory); }
Example #18
Source File: HostedWorkspaceActivityManager.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Override protected long getIdleTimeout(String workspaceId) throws NotFoundException, ServerException { WorkspaceImpl workspace = workspaceManager.getWorkspace(workspaceId); Account account = accountManager.getByName(workspace.getNamespace()); List<? extends Resource> availableResources = resourceUsageManager.getAvailableResources(account.getId()); Optional<? extends Resource> timeoutOpt = availableResources .stream() .filter(resource -> TimeoutResourceType.ID.equals(resource.getType())) .findAny(); if (timeoutOpt.isPresent()) { return timeoutOpt.get().getAmount() * 60 * 1000; } else { return -1; } }
Example #19
Source File: SystemRamCheckingWorkspaceManager.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * One of the checks in {@link #checkSystemRamLimitAndPropagateStart(WorkspaceCallback)} is needed * to deny starting workspace, if system RAM limit exceeded. This check may be slow because it is * based on request to swarm for memory amount allocated on all nodes, but it can't be performed * more than specified times at the same time, and the semaphore is used to control that. The * semaphore is a trade off between speed and risk to exceed system RAM limit. In the worst case * specified number of permits to start workspace can happen at the same time after the actually * system limit allows to start only one workspace, all permits will be allowed to start * workspace. If more than specified number of permits to start workspace happens, they will wait * in a queue. limits.workspace.start.throughput property configures how many permits can be * handled at the same time. */ @VisibleForTesting <T extends WorkspaceImpl> T checkSystemRamLimitAndPropagateLimitedThroughputStart( WorkspaceCallback<T> callback) throws ServerException, NotFoundException, ConflictException { if (startSemaphore == null) { return checkSystemRamLimitAndPropagateStart(callback); } else { try { startSemaphore.acquire(); return checkSystemRamLimitAndPropagateStart(callback); } catch (InterruptedException e) { currentThread().interrupt(); throw new ServerException(e.getMessage(), e); } finally { startSemaphore.release(); } } }
Example #20
Source File: FactoryConnection.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Find a factory * * @param factoryName the name of the factory * @param userId the id of the user that owns the factory * @return the expected factory or null if an error occurred during the call to 'getFactory' * @throws ServerException */ public List<FactoryDto> findFactory(final String factoryName, final String userId) throws ServerException { String url = fromUri(baseUrl) .path(FactoryService.class) .path(FactoryService.class, "getFactoryByAttribute") .build() .toString(); List<FactoryDto> factories; HttpJsonRequest httpJsonRequest = httpJsonRequestFactory .fromUrl(url) .useGetMethod() .addQueryParam("name", factoryName) .addQueryParam("creator.userId", userId); try { HttpJsonResponse response = httpJsonRequest.request(); factories = response.asList(FactoryDto.class); } catch (IOException | ApiException e) { LOG.error(e.getLocalizedMessage(), e); throw new ServerException(e.getLocalizedMessage()); } return factories; }
Example #21
Source File: DockerEnvironmentBackupManager.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Returns user id, group id and username in container. This method caches info about users and on * second and subsequent calls cached value will be returned. * * @param workspaceId id of workspace * @param containerId id of container * @return {@code User} object with id, groupId and username filled * @throws IOException if connection to container fails * @throws ServerException if other error occurs */ private User getUserInfo(String workspaceId, String containerId) throws IOException, ServerException { Map<String, User> workspaceMachinesUserInfo = workspacesMachinesUsersInfo.get(workspaceId); if (workspaceMachinesUserInfo == null) { workspaceMachinesUserInfo = new HashMap<>(); workspacesMachinesUsersInfo.put(workspaceId, workspaceMachinesUserInfo); } User user = workspaceMachinesUserInfo.get(containerId); if (user == null) { user = getUserInfoWithinContainer(workspaceId, containerId); workspaceMachinesUserInfo.put(containerId, user); } return user; }
Example #22
Source File: DockerEnvironmentBackupManager.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Copy files of workspace into backup storage and cleanup them in container. * * @param workspaceId id of workspace to backup * @param containerId id of container that contains data * @param nodeHost host of a node where container is running * @throws EnvironmentException if backup failed due to abnormal state of machines in environment * @throws ServerException if any other error occurs */ public void backupWorkspaceAndCleanup(String workspaceId, String containerId, String nodeHost) throws ServerException, EnvironmentException { try { String destPath = workspaceIdHashLocationFinder.calculateDirPath(backupsRootDir, workspaceId).toString(); // if sync agent is not in machine port parameter is not used int syncPort = getSyncPort(containerId); String srcUserName = getUserInfo(workspaceId, containerId).name; backupAndCleanupInsideLock( workspaceId, projectFolderPath, nodeHost, syncPort, srcUserName, destPath); } catch (IOException e) { throw new ServerException(e.getLocalizedMessage(), e); } finally { // remove lock in case exception prevent removing it in regular place to prevent resources // leak // and blocking further WS start workspacesBackupLocks.remove(workspaceId); // clear user info cache workspacesMachinesUsersInfo.remove(workspaceId); } }
Example #23
Source File: JenkinsWebhookManager.java From codenvy with Eclipse Public License 1.0 | 6 votes |
private Optional<Factory> findExistingFailedFactory(String repositoryUrl, String commitId) throws NotFoundException, ServerException { return getUserFactories() .stream() .filter( f -> f.getWorkspace() .getProjects() .stream() .anyMatch( project -> repositoryUrl.equals(project.getSource().getLocation()) && commitId.equals( project.getSource().getParameters().get("commitId")))) .findAny(); }
Example #24
Source File: JpaInviteDao.java From codenvy with Eclipse Public License 1.0 | 6 votes |
@Transactional protected Optional<InviteImpl> doCreate(InviteImpl invite) throws ServerException { EntityManager manager = managerProvider.get(); InviteImpl existing = null; try { final InviteImpl result = getEntity(invite.getDomainId(), invite.getInstanceId(), invite.getEmail()); existing = new InviteImpl(result); result.getActions().clear(); result.getActions().addAll(invite.getActions()); } catch (NotFoundException n) { manager.persist(invite); } manager.flush(); return Optional.ofNullable(existing); }
Example #25
Source File: InviteManager.java From codenvy with Eclipse Public License 1.0 | 6 votes |
/** * Stores (create or updates) invite. * * <p>It also send email invite on initial invite creation. * * @param invite invite to store * @throws ConflictException when user is specified email is already registered * @throws ServerException when any other error occurs during invite storing */ @Transactional(rollbackOn = {RuntimeException.class, ServerException.class}) public void store(Invite invite) throws NotFoundException, ConflictException, ServerException { requireNonNull(invite, "Required non-null invite"); String domainId = invite.getDomainId(); if (!OrganizationDomain.DOMAIN_ID.equals(domainId) && !WorkspaceDomain.DOMAIN_ID.equals(domainId)) { throw new ConflictException("Invitations for specified domain are not supported"); } permissionsManager.checkActionsSupporting(domainId, invite.getActions()); try { userManager.getByEmail(invite.getEmail()); throw new ConflictException("User with specified id is already registered"); } catch (NotFoundException ignored) { } Optional<InviteImpl> existingInvite = inviteDao.store(new InviteImpl(invite)); if (!existingInvite.isPresent()) { Subject currentSubject = EnvironmentContext.getCurrent().getSubject(); eventService.publish( new InviteCreatedEvent( currentSubject.isAnonymous() ? null : currentSubject.getUserId(), invite)); } }
Example #26
Source File: JenkinsConnector.java From codenvy with Eclipse Public License 1.0 | 5 votes |
/** Returns related factory Id, configured for current connector by connector properties. */ String getFactoryId() throws ServerException { Optional<String> propertyPrefixOptional = getJenkinsConnectorPropertyPrefix(); if (propertyPrefixOptional.isPresent()) { Map<String, String> properties = configurationProperties.getProperties(JENKINS_CONNECTOR_PREFIX_PATTERN); return properties.get(propertyPrefixOptional.get() + JENKINS_CONNECTOR_FACTORY_ID_SUFFIX); } else { throw new ServerException(String.format(PROPERTY_NOT_FOUND_ERROR_MESSAGE, url, jobName)); } }
Example #27
Source File: BitbucketConnectionImpl.java From codenvy with Eclipse Public License 1.0 | 5 votes |
@Override public BitbucketPullRequest openPullRequest( String owner, String repositorySlug, BitbucketPullRequest pullRequest) throws ServerException, IOException, BitbucketException { final String url = urlTemplates.pullRequestUrl(owner, repositorySlug); final String response = postJson(this, url, toJson(pullRequest, CAMEL_UNDERSCORE)); return parseJsonResponse(response, BitbucketPullRequest.class); }
Example #28
Source File: UserInfoPrinter.java From codenvy with Eclipse Public License 1.0 | 5 votes |
private void printUserWorkspaceInfo(WorkspaceImpl workspace) throws ServerException { printRow( " └ " + workspace.getConfig().getName() + ", is owner: " + workspace.getNamespace().equals(user.getName()) + ", permissions: "); AbstractPermissions permissions = wsPermissions.get(workspace.getId()); if (permissions != null) { printRow(permissions.getActions().toString() + "\n"); } else { printRow("[]\n"); } }
Example #29
Source File: BearerTokenAuthenticationHandler.java From codenvy with Eclipse Public License 1.0 | 5 votes |
private Optional<User> getUserByName(String name) throws ServerException { try { User user = userManager.getByName(name); return Optional.of(user); } catch (NotFoundException e) { return Optional.empty(); } }
Example #30
Source File: Printer.java From codenvy with Eclipse Public License 1.0 | 5 votes |
protected void printRow(String row) throws ServerException { try { append(row, auditReport.toFile(), Charset.defaultCharset()); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new ServerException("Failed to generate audit report. " + e.getMessage(), e); } }