Search in sources :

Example 26 with ServiceException

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);
    }
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) PythonDep(io.hops.hopsworks.persistence.entity.python.PythonDep) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)

Example 27 with ServiceException

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);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) ElasticException(io.hops.hopsworks.exceptions.ElasticException) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) Try(com.lambdista.util.Try) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 28 with ServiceException

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();
}
Also used : Variables(io.hops.hopsworks.persistence.entity.util.Variables) ServiceException(io.hops.hopsworks.exceptions.ServiceException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)

Example 29 with ServiceException

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;
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException)

Example 30 with ServiceException

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;
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException)

Aggregations

ServiceException (io.hops.hopsworks.exceptions.ServiceException)53 IOException (java.io.IOException)22 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)16 Users (io.hops.hopsworks.persistence.entity.user.Users)12 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)10 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 GenericException (io.hops.hopsworks.exceptions.GenericException)8 ProjectException (io.hops.hopsworks.exceptions.ProjectException)8 ElasticException (io.hops.hopsworks.exceptions.ElasticException)7 JupyterProject (io.hops.hopsworks.persistence.entity.jupyter.JupyterProject)7 Project (io.hops.hopsworks.persistence.entity.project.Project)7 TransactionAttribute (javax.ejb.TransactionAttribute)7 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)6 JobException (io.hops.hopsworks.exceptions.JobException)6 UserException (io.hops.hopsworks.exceptions.UserException)6 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)6 ProcessDescriptor (io.hops.hopsworks.common.util.ProcessDescriptor)4 ProcessResult (io.hops.hopsworks.common.util.ProcessResult)4 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)4