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);
}
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());
}
}
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();
}
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);
}
}
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");
}
}
Aggregations