try{ businessService.executeBusinessRule(); }catch (BusinessException e){ // It is better if your BusinessException has some child class to handle if(e.getError() == ErrorEnumeration.VALIDATION_FAILED){ throw new BadRequestException(); }else{ throw new ConflictException(); } }
@Override public void add(Installer installer) throws InstallerException { checkConfiguration(); try { requestFactory .fromUrl( UriBuilder.fromUri(registryServiceUrl) .path(InstallerRegistryService.class, "add") .build() .toString()) .setBody(asDto(installer)) .usePostMethod() .request(); } catch (ConflictException e) { throw new InstallerAlreadyExistsException(e.getMessage(), e); } catch (IOException | ApiException e) { throw new InstallerException(e.getMessage(), e); } }
try { .... } catch (final PersistenceException e) { final Throwable cause = e.getCause(); if (cause instanceof MySQLIntegrityConstraintViolationException) { throw new ConflictException(cause); } throw new ServiceException(e); }
/** * Stops some of the system services preparing system to full shutdown. System status is changed * from {@link SystemStatus#RUNNING} to {@link SystemStatus#PREPARING_TO_SHUTDOWN}. * * @throws ConflictException when system status is different from running */ public void stopServices() throws ConflictException { if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { throw new ConflictException( "System shutdown has been already called, system status: " + statusRef.get()); } ExecutorService exec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("ShutdownSystemServicesPool") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); exec.execute(ThreadLocalPropagateContext.wrap(this::doStopServices)); exec.shutdown(); }
/** * Suspends some of the system services preparing system to lighter shutdown. System status is * changed from {@link SystemStatus#RUNNING} to {@link SystemStatus#PREPARING_TO_SHUTDOWN}. * * @throws ConflictException when system status is different from running */ public void suspendServices() throws ConflictException { if (!statusRef.compareAndSet(RUNNING, PREPARING_TO_SHUTDOWN)) { throw new ConflictException( "System shutdown has been already called, system status: " + statusRef.get()); } ExecutorService exec = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(false) .setNameFormat("SuspendSystemServicesPool") .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()) .build()); exec.execute(ThreadLocalPropagateContext.wrap(this::doSuspendServices)); exec.shutdown(); }
@Override public SignatureKeyPairImpl create(SignatureKeyPairImpl keyPair) throws ConflictException, ServerException { requireNonNull(keyPair, "Required non-null key pair"); try { doCreate(keyPair); } catch (IntegrityConstraintViolationException x) { throw new ConflictException( format( "Unable to create signature key pair because referenced workspace with id '%s' doesn't exist", keyPair.getWorkspaceId())); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format("Signature key pair for workspace '%s' already exists", keyPair.getWorkspaceId())); } catch (RuntimeException ex) { throw new ServerException(ex.getMessage(), ex); } return new SignatureKeyPairImpl(keyPair); }
@Override public void create(StackImpl stack) throws ConflictException, ServerException { requireNonNull(stack, "Required non-null stack"); try { doCreate(stack); } catch (DuplicateKeyException x) { throw new ConflictException( format("Stack with id '%s' or name '%s' already exists", stack.getId(), stack.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override public void create(SshPairImpl sshPair) throws ServerException, ConflictException { requireNonNull(sshPair); try { doCreate(sshPair); } catch (DuplicateKeyException e) { throw new ConflictException( format( "Ssh pair with service '%s' and name '%s' already exists", sshPair.getService(), sshPair.getName())); } catch (RuntimeException e) { throw new ServerException(e); } }
@Override public StackImpl update(StackImpl update) throws NotFoundException, ServerException, ConflictException { requireNonNull(update, "Required non-null update"); try { return new StackImpl(doUpdate(update)); } catch (DuplicateKeyException x) { throw new ConflictException(format("Stack with name '%s' already exists", update.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
/** * Removes workspace with specified identifier. * * <p> * * <p>Does not remove the workspace if it has the runtime, throws {@link ConflictException} in * this case. Won't throw any exception if workspace doesn't exist. * * @param workspaceId workspace id to remove workspace * @throws ConflictException when workspace has runtime * @throws ServerException when any server error occurs * @throws NullPointerException when {@code workspaceId} is null */ @Traced public void removeWorkspace(String workspaceId) throws ConflictException, ServerException { requireNonNull(workspaceId, "Required non-null workspace id"); if (runtimes.hasRuntime(workspaceId)) { throw new ConflictException( format("The workspace '%s' is currently running and cannot be removed.", workspaceId)); } workspaceDao.remove(workspaceId); LOG.info("Workspace '{}' removed by user '{}'", workspaceId, sessionUserNameOrUndefined()); }
@Override public void create(StackImpl stack) throws ConflictException, ServerException { requireNonNull(stack, "Required non-null stack"); try { doCreate(stack); } catch (DuplicateKeyException x) { throw new ConflictException( format("Stack with id '%s' or name '%s' already exists", stack.getId(), stack.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override public StackImpl update(StackImpl update) throws NotFoundException, ServerException, ConflictException { requireNonNull(update, "Required non-null update"); try { return new StackImpl(doUpdate(update)); } catch (DuplicateKeyException x) { throw new ConflictException(format("Stack with name '%s' already exists", update.getName())); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override public WorkspaceImpl update(WorkspaceImpl update) throws NotFoundException, ConflictException, ServerException { requireNonNull(update, "Required non-null update"); try { return new WorkspaceImpl(doUpdate(update)); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with name '%s' in namespace '%s' already exists", update.getConfig().getName(), update.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } }
@Override public WorkspaceImpl update(WorkspaceImpl update) throws NotFoundException, ConflictException, ServerException { requireNonNull(update, "Required non-null update"); try { return new WorkspaceImpl(doUpdate(update)); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with name '%s' in namespace '%s' already exists", update.getConfig().getName(), update.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } }
@Override public WorkspaceImpl create(WorkspaceImpl workspace) throws ConflictException, ServerException { requireNonNull(workspace, "Required non-null workspace"); try { doCreate(workspace); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with id '%s' or name '%s' in namespace '%s' already exists", workspace.getId(), workspace.getConfig().getName(), workspace.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } return new WorkspaceImpl(workspace); }
@Override public WorkspaceImpl create(WorkspaceImpl workspace) throws ConflictException, ServerException { requireNonNull(workspace, "Required non-null workspace"); try { doCreate(workspace); } catch (DuplicateKeyException dkEx) { throw new ConflictException( format( "Workspace with id '%s' or name '%s' in namespace '%s' already exists", workspace.getId(), workspace.getConfig().getName(), workspace.getNamespace())); } catch (RuntimeException x) { throw new ServerException(x.getMessage(), x); } return new WorkspaceImpl(workspace); }
throw new UnauthorizedException(serviceError); } else if (responseCode == Response.Status.CONFLICT.getStatusCode()) { throw new ConflictException(serviceError); } else if (responseCode == Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) { throw new ServerException(serviceError);
throw new UnauthorizedException(serviceError); } else if (responseCode == Response.Status.CONFLICT.getStatusCode()) { throw new ConflictException(serviceError); } else if (responseCode == Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) { throw new ServerException(serviceError);
private void checkWorkspaceIsRunningOrStarting(WorkspaceImpl workspace) throws ConflictException { if (workspace.getStatus() != RUNNING && workspace.getStatus() != STARTING) { throw new ConflictException( format( "Could not stop the workspace '%s/%s' because its status is '%s'.", workspace.getNamespace(), workspace.getConfig().getName(), workspace.getStatus())); } }
throw new ConflictException( format("Could not stop workspace '%s' because its state is '%s'", workspaceId, status)); throw new ConflictException( format( "Could not stop workspace '%s' because its state is '%s'",