protected OAuthAuthenticator getAuthenticator(String oauthProviderName) throws NotFoundException { OAuthAuthenticator oauth = providers.getAuthenticator(oauthProviderName); if (oauth == null) { LOG.warn("Unsupported OAuth provider {} ", oauthProviderName); throw new NotFoundException("Unsupported OAuth provider " + oauthProviderName); } return oauth; } }
@Override public Map<String, VcsStatus> getStatus(String wsPath, List<String> paths) throws ServerException { Map<String, VcsStatus> result = new HashMap<>(); try { ProjectConfig project = projectManager .getClosest(absolutize(wsPath)) .orElseThrow(() -> new NotFoundException("Can't find project")); Status status = getStatus( project.getName(), pathTransformer.transform(project.getPath()).toString(), paths); paths.forEach( path -> { String itemWsPath = resolve(project.getPath(), path); if (status.getUntracked().contains(path)) { result.put(itemWsPath, UNTRACKED); } else if (status.getAdded().contains(path)) { result.put(itemWsPath, ADDED); } else if (status.getModified().contains(path) || status.getChanged().contains(path)) { result.put(itemWsPath, MODIFIED); } else { result.put(itemWsPath, NOT_MODIFIED); } }); } catch (NotFoundException e) { throw new ServerException(e.getMessage()); } return result; }
@Override public void update(Installer installer) throws InstallerException { checkConfiguration(); try { requestFactory .fromUrl( UriBuilder.fromUri(registryServiceUrl) .path(InstallerRegistryService.class, "update") .build() .toString()) .setBody(asDto(installer)) .usePutMethod() .request(); } catch (NotFoundException e) { throw new InstallerNotFoundException(e.getMessage(), e); } catch (IOException | ApiException e) { throw new InstallerException(e.getMessage(), e); } }
@Override public List<String> getVersions(String id) throws InstallerException { checkConfiguration(); try { @SuppressWarnings("unchecked") List<String> result = requestFactory .fromUrl( UriBuilder.fromUri(registryServiceUrl) .path(InstallerRegistryService.class, "getVersions") .build(id) .toString()) .useGetMethod() .request() .as(List.class, new TypeToken<List<String>>() {}.getType()); return result; } catch (NotFoundException e) { throw new InstallerNotFoundException(e.getMessage(), e); } catch (IOException | ApiException e) { throw new InstallerException(e.getMessage(), e); } }
/** * Gets a logger, if checkLevel is true and if logger has no level defined it will return a * NameNotFound exception */ protected Logger getLogger(String name, boolean checkLevel) throws NotFoundException { LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); Logger log = loggerContext.getLogger(name); if (checkLevel && log.getLevel() == null) { throw new NotFoundException("The logger with name " + name + " is not existing."); } return log; } }
@Override public Installer getInstaller(String installerKey) throws InstallerException { checkConfiguration(); try { return requestFactory .fromUrl( UriBuilder.fromUri(registryServiceUrl) .path(InstallerRegistryService.class, "getInstaller") .build(installerKey) .toString()) .useGetMethod() .request() .asDto(InstallerDto.class); } catch (NotFoundException e) { throw new InstallerNotFoundException(e.getMessage(), e); } catch (BadRequestException e) { throw new IllegalInstallerKeyException(e.getMessage(), e); } catch (IOException | ApiException e) { throw new InstallerException(e.getMessage(), e); } }
@Transactional protected void doRemove(String owner, String service, String name) throws NotFoundException { EntityManager manager = managerProvider.get(); SshPairImpl entity = manager.find(SshPairImpl.class, new SshPairPrimaryKey(owner, service, name)); if (entity == null) { throw new NotFoundException( format("Ssh pair with service '%s' and name '%s' was not found.", service, name)); } manager.remove(entity); manager.flush(); }
@Override public List<Installer> getOrderedInstallers(List<String> installerKeys) throws InstallerException { checkConfiguration(); try { return new ArrayList<>( requestFactory .fromUrl( UriBuilder.fromUri(registryServiceUrl) .path(InstallerRegistryService.class, "getOrderedInstallers") .build() .toString()) .usePostMethod() .setBody(installerKeys) .request() .asList(InstallerDto.class)); } catch (NotFoundException e) { throw new InstallerNotFoundException(e.getMessage(), e); } catch (BadRequestException e) { throw new IllegalInstallerKeyException(e.getMessage(), e); } catch (IOException | ApiException e) { throw new InstallerException(e.getMessage(), e); } }
@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); } }
private InternalEnvironment getInternalEnvironment(Environment environment) throws InfrastructureException, ValidationException, NotFoundException { final String recipeType = environment.getRecipe().getType(); final InternalEnvironmentFactory factory = environmentFactories.get(recipeType); if (factory == null) { throw new NotFoundException( format("InternalEnvironmentFactory is not configured for recipe type: '%s'", recipeType)); } return factory.create(environment); } }
@Override @Transactional public SignatureKeyPairImpl get(String workspaceId) throws NotFoundException, ServerException { final EntityManager manager = managerProvider.get(); try { return new SignatureKeyPairImpl( manager .createNamedQuery("SignKeyPair.getAll", SignatureKeyPairImpl.class) .setParameter("workspaceId", workspaceId) .getSingleResult()); } catch (NoResultException x) { throw new NotFoundException( format("Signature key pair for workspace '%s' doesn't exist", workspaceId)); } catch (RuntimeException ex) { throw new ServerException(ex.getMessage(), ex); } }
@Override @Transactional public StackImpl getById(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final StackImpl stack = managerProvider.get().find(StackImpl.class, id); if (stack == null) { throw new NotFoundException(format("Stack with id '%s' doesn't exist", id)); } return new StackImpl(stack); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
public void validate(Environment environment) throws NotFoundException, InfrastructureException, ValidationException { String type = environment.getRecipe().getType(); if (!infrastructure.getRecipeTypes().contains(type)) { throw new NotFoundException("Infrastructure not found for type: " + type); } // try to create internal environment to check if the specified environment is valid createInternalEnvironment(environment, emptyMap(), emptyList()); }
@GET @Path("/{id}/icon") @Produces("image/*") @GenerateLink(rel = LINK_REL_GET_ICON) @ApiOperation( value = "Get icon by stack id", notes = "This operation can be performed only by authorized user", response = byte[].class) @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested image entity"), @ApiResponse(code = 403, message = "The user does not have access to get image entity"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public Response getIcon(@ApiParam("The stack id") @PathParam("id") final String id) throws NotFoundException, ServerException, BadRequestException { StackImpl stack = stackDao.getById(id); if (stack == null) { throw new NotFoundException("Stack with id '" + id + "' was not found."); } StackIcon image = stack.getStackIcon(); if (image == null) { throw new NotFoundException("Image for stack with id '" + id + "' was not found."); } return Response.ok(image.getData(), image.getMediaType()).build(); }
@Override @Transactional public WorkspaceImpl get(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id); if (workspace == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", id)); } return new WorkspaceImpl(workspace); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override @Transactional public StackImpl getById(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final StackImpl stack = managerProvider.get().find(StackImpl.class, id); if (stack == null) { throw new NotFoundException(format("Stack with id '%s' doesn't exist", id)); } return new StackImpl(stack); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Transactional protected StackImpl doUpdate(StackImpl update) throws NotFoundException { final EntityManager manager = managerProvider.get(); if (manager.find(StackImpl.class, update.getId()) == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId())); } if (update.getWorkspaceConfig() != null) { update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes); } StackImpl merged = manager.merge(update); manager.flush(); return merged; } }
@Override @Transactional public WorkspaceImpl get(String id) throws NotFoundException, ServerException { requireNonNull(id, "Required non-null id"); try { final WorkspaceImpl workspace = managerProvider.get().find(WorkspaceImpl.class, id); if (workspace == null) { throw new NotFoundException(format("Workspace with id '%s' doesn't exist", id)); } return new WorkspaceImpl(workspace); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }
@Override @Transactional public WorkspaceImpl get(String name, String namespace) throws NotFoundException, ServerException { requireNonNull(name, "Required non-null name"); requireNonNull(namespace, "Required non-null namespace"); try { return new WorkspaceImpl( managerProvider .get() .createNamedQuery("Workspace.getByName", WorkspaceImpl.class) .setParameter("namespace", namespace) .setParameter("name", name) .getSingleResult()); } catch (NoResultException noResEx) { throw new NotFoundException( format("Workspace with name '%s' in namespace '%s' doesn't exist", name, namespace)); } catch (RuntimeException x) { throw new ServerException(x.getLocalizedMessage(), x); } }