use of io.hops.hopsworks.exceptions.ServiceException in project hopsworks by logicalclocks.
the class EnvironmentController method updateInstalledDependencies.
public Project updateInstalledDependencies(Project project) throws ServiceException, IOException {
try {
String condaListOutput = libraryController.condaList(projectUtils.getFullDockerImageName(project, false));
Collection<PythonDep> projectDeps = libraryController.parseCondaList(condaListOutput);
projectDeps = libraryController.persistAndMarkImmutable(projectDeps);
project = libraryController.syncProjectPythonDepsWithEnv(project, projectDeps);
project = libraryController.addOngoingOperations(project);
return project;
} catch (ServiceDiscoveryException e) {
throw new ServiceException(RESTCodes.ServiceErrorCode.SERVICE_DISCOVERY_ERROR, Level.SEVERE, null, e.getMessage(), e);
}
}
use of io.hops.hopsworks.exceptions.ServiceException in project hopsworks by logicalclocks.
the class LibraryController method pipList.
/**
* @param <R> parsed elastic item
* @param <S1> intermediate result wrapped in Try
* @param <S2> final result
* @return
* @throws ProvenanceException
*/
private <R, S1, S2> S2 pipList(String query, Integer offset, Integer limit, LibraryController.HandlerFactory<R, S1, S2> handlerFactory, String index) throws ServiceException {
Pair<Long, Try<S1>> searchResult;
try {
CheckedSupplier<SearchRequest, ProvenanceException> srF = ElasticHelper.baseSearchRequest(index, settings.getElasticDefaultScrollPageSize()).andThen(ElasticHelper.withPagination(offset, limit, settings.getElasticDefaultScrollPageSize()));
SearchRequest request = srF.get();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(ElasticHelper.fullTextSearch("library", query));
request.source(sourceBuilder);
searchResult = provElasticController.search(request, handlerFactory.getHandler());
} catch (ElasticException | ProvenanceException pe) {
throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_LIST_LIB_ERROR, Level.FINE, "Unable to list python libraries", pe.getMessage(), pe);
}
return handlerFactory.checkedResult(searchResult);
}
use of io.hops.hopsworks.exceptions.ServiceException in project hopsworks by logicalclocks.
the class VariablesService method getVar.
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.PROJECT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getVar(@Context SecurityContext sc, @PathParam("id") String id) throws ServiceException, HopsSecurityException {
Variables variable = settings.findById(id).orElseThrow(() -> new ServiceException(RESTCodes.ServiceErrorCode.VARIABLE_NOT_FOUND, Level.FINE, "Variable: " + id + "not found"));
if (variable.getVisibility() == VariablesVisibility.ADMIN && !sc.isUserInRole("HOPS_ADMIN")) {
throw new HopsSecurityException(RESTCodes.SecurityErrorCode.REST_ACCESS_CONTROL, Level.FINE, "The requested variable requires admin privileges");
}
RESTApiJsonResponse json = new RESTApiJsonResponse();
json.setSuccessMessage(variable.getValue());
return Response.ok().entity(json).build();
}
use of io.hops.hopsworks.exceptions.ServiceException in project hopsworks by logicalclocks.
the class UserProfileBuilder method rejectUsers.
public UserProfileDTO rejectUsers(List<Integer> ids, HttpServletRequest req) throws UserException {
UserProfileDTO userProfileDTO = new UserProfileDTO();
Users target = null;
if (ids != null && ids.size() > 0) {
for (Integer id : ids) {
try {
target = reject(id);
userProfileDTO.addItem(new UserProfileDTO(target));
} catch (UserException | ServiceException e) {
LOGGER.log(Level.WARNING, "Failed to reject user with id: {0}", id);
}
}
if (userProfileDTO.getItems() != null) {
userProfileDTO.setCount((long) userProfileDTO.getItems().size());
} else {
userProfileDTO.setCount(0L);
}
if (userProfileDTO.getCount() < 1) {
throw new UserException(RESTCodes.UserErrorCode.ACCOUNT_REJECTION_FAILED, Level.FINE, "Failed to reject users");
}
}
return userProfileDTO;
}
use of io.hops.hopsworks.exceptions.ServiceException in project hopsworks by logicalclocks.
the class UserProfileBuilder method acceptUsers.
public UserProfileDTO acceptUsers(List<Integer> ids, HttpServletRequest req) throws UserException {
UserProfileDTO userProfileDTO = new UserProfileDTO();
Users target = null;
if (ids != null && ids.size() > 0) {
for (Integer id : ids) {
try {
target = accept(id, null);
userProfileDTO.addItem(new UserProfileDTO(target));
} catch (UserException | ServiceException e) {
LOGGER.log(Level.WARNING, "Failed to accept user with id: {0}", id);
}
}
if (userProfileDTO.getItems() != null) {
userProfileDTO.setCount((long) userProfileDTO.getItems().size());
} else {
userProfileDTO.setCount(0L);
}
if (userProfileDTO.getCount() < 1) {
throw new UserException(RESTCodes.UserErrorCode.ACCOUNT_ACTIVATION_FAILED, Level.FINE, "Failed to activate " + "users");
}
}
return userProfileDTO;
}
Aggregations