Search in sources :

Example 16 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class WsAgentLauncher method launch.

@Override
public void launch(Instance machine, Agent agent) throws ServerException {
    final HttpJsonRequest wsAgentPingRequest;
    try {
        wsAgentPingRequest = createPingRequest(machine);
    } catch (ServerException e) {
        throw new MachineException(e.getServiceError());
    }
    String script = agent.getScript() + "\n" + firstNonNull(wsAgentRunCommand, DEFAULT_WS_AGENT_RUN_COMMAND);
    final String wsAgentPingUrl = wsAgentPingRequest.getUrl();
    try {
        // for server side type of command mean nothing
        // but we will use it as marker on
        // client side for track this command
        CommandImpl command = new CommandImpl(getAgentId(), script, WS_AGENT_PROCESS_NAME);
        machineProcessManagerProvider.get().exec(machine.getWorkspaceId(), machine.getId(), command, getWsAgentProcessOutputChannel(machine.getWorkspaceId()));
        final long pingStartTimestamp = System.currentTimeMillis();
        LOG.debug("Starts pinging ws agent. Workspace ID:{}. Url:{}. Timestamp:{}", machine.getWorkspaceId(), wsAgentPingUrl, pingStartTimestamp);
        while (System.currentTimeMillis() - pingStartTimestamp < wsAgentMaxStartTimeMs) {
            if (pingWsAgent(wsAgentPingRequest)) {
                return;
            } else {
                Thread.sleep(wsAgentPingDelayMs);
            }
        }
    } catch (BadRequestException | ServerException | NotFoundException e) {
        throw new ServerException(e.getServiceError());
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new ServerException("Ws agent pinging is interrupted");
    }
    LOG.error("Fail pinging ws agent. Workspace ID:{}. Url:{}. Timestamp:{}", machine.getWorkspaceId(), wsAgentPingUrl);
    throw new ServerException(pingTimedOutErrorMessage);
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ServerException(org.eclipse.che.api.core.ServerException) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) BadRequestException(org.eclipse.che.api.core.BadRequestException) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 17 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class OAuthAuthenticationService method invalidate.

@DELETE
@Path("token")
public void invalidate(@Required @QueryParam("oauth_provider") String oauthProvider) throws BadRequestException, NotFoundException, ServerException, ForbiddenException {
    OAuthAuthenticator oauth = getAuthenticator(oauthProvider);
    final Subject subject = EnvironmentContext.getCurrent().getSubject();
    try {
        if (!oauth.invalidateToken(subject.getUserId())) {
            throw new NotFoundException("OAuth token for user " + subject.getUserId() + " was not found");
        }
    } catch (IOException e) {
        throw new ServerException(e.getMessage());
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) Subject(org.eclipse.che.commons.subject.Subject) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 18 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class JpaAccountDao method doUpdate.

@Transactional
protected void doUpdate(AccountImpl update) throws NotFoundException {
    final EntityManager manager = managerProvider.get();
    final AccountImpl account = manager.find(AccountImpl.class, update.getId());
    if (account == null) {
        throw new NotFoundException(format("Couldn't update account with id '%s' because it doesn't exist", update.getId()));
    }
    manager.merge(update);
    manager.flush();
}
Also used : EntityManager(javax.persistence.EntityManager) AccountImpl(org.eclipse.che.account.spi.AccountImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Transactional(com.google.inject.persist.Transactional)

Example 19 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class JpaAccountDao method getByName.

@Override
@Transactional
public AccountImpl getByName(String name) throws ServerException, NotFoundException {
    requireNonNull(name, "Required non-null account name");
    final EntityManager manager = managerProvider.get();
    try {
        return manager.createNamedQuery("Account.getByName", AccountImpl.class).setParameter("name", name).getSingleResult();
    } catch (NoResultException e) {
        throw new NotFoundException(String.format("Account with name '%s' was not found", name));
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Example 20 with NotFoundException

use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.

the class FactoryService method processDefaults.

/**
     * Checks the current user if it is not temporary then
     * adds to the factory creator information and time of creation
     */
private void processDefaults(FactoryDto factory) throws ForbiddenException {
    try {
        final String userId = EnvironmentContext.getCurrent().getSubject().getUserId();
        final User user = userManager.getById(userId);
        if (user == null || parseBoolean(preferenceManager.find(userId).get("temporary"))) {
            throw new ForbiddenException("Current user is not allowed to use this method.");
        }
        factory.setCreator(DtoFactory.newDto(AuthorDto.class).withUserId(userId).withName(user.getName()).withEmail(user.getEmail()).withCreated(System.currentTimeMillis()));
    } catch (NotFoundException | ServerException ex) {
        throw new ForbiddenException("Current user is not allowed to use this method");
    }
}
Also used : AuthorDto(org.eclipse.che.api.factory.shared.dto.AuthorDto) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) User(org.eclipse.che.api.core.model.user.User) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Aggregations

NotFoundException (org.eclipse.che.api.core.NotFoundException)72 ServerException (org.eclipse.che.api.core.ServerException)29 ConflictException (org.eclipse.che.api.core.ConflictException)19 Transactional (com.google.inject.persist.Transactional)16 IOException (java.io.IOException)13 EntityManager (javax.persistence.EntityManager)13 Path (javax.ws.rs.Path)13 Test (org.testng.annotations.Test)12 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)11 Produces (javax.ws.rs.Produces)10 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 ArrayList (java.util.ArrayList)9 BadRequestException (org.eclipse.che.api.core.BadRequestException)9 Instance (org.eclipse.che.api.machine.server.spi.Instance)9 GET (javax.ws.rs.GET)7 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)7 SourceNotFoundException (org.eclipse.che.api.machine.server.exception.SourceNotFoundException)6 MachineImpl (org.eclipse.che.api.machine.server.model.impl.MachineImpl)6 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)6