Search in sources :

Example 26 with GenericException

use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.

the class ModelUtils method getModelsProjectAndCheckAccess.

public Project getModelsProjectAndCheckAccess(ModelDTO modelDTO, Project project) throws ProjectException, GenericException, DatasetException {
    Project modelProject;
    if (modelDTO.getProjectName() == null) {
        modelProject = project;
    } else {
        modelProject = projectFacade.findByName(modelDTO.getProjectName());
        if (modelProject == null) {
            throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_NOT_FOUND, Level.INFO, "model project not found");
        }
    }
    Dataset modelDataset = datasetCtrl.getByName(modelProject, Settings.HOPS_MODELS_DATASET);
    if (!accessCtrl.hasAccess(project, modelDataset)) {
        throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.INFO, "models endpoint");
    }
    return modelProject;
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) Project(io.hops.hopsworks.persistence.entity.project.Project) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) GenericException(io.hops.hopsworks.exceptions.GenericException)

Example 27 with GenericException

use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.

the class VariablesService method getFileNameValidatorRegex.

@GET
@Path("filename-regex")
@Produces(MediaType.APPLICATION_JSON)
@JWTNotRequired
public Response getFileNameValidatorRegex(@QueryParam("type") String type) throws GenericException {
    FileNameRegexDTO fileNameRegexDTO = new FileNameRegexDTO();
    if (type == null || type.equals("project")) {
        fileNameRegexDTO.setRegex(FolderNameValidator.getProjectNameRegexStr(settings.getReservedProjectNames()));
        fileNameRegexDTO.setReservedWords(settings.getProjectNameReservedWords().toUpperCase());
    } else if (type.equals("dataset")) {
        fileNameRegexDTO.setRegex(FolderNameValidator.getDatasetNameRegexStr());
    } else {
        throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "Type QueryParam should be:" + "project|dataset|subdir");
    }
    return Response.ok(fileNameRegexDTO).build();
}
Also used : GenericException(io.hops.hopsworks.exceptions.GenericException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTNotRequired(io.hops.hopsworks.api.filter.JWTNotRequired)

Example 28 with GenericException

use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.

the class SparkController method createSparkJob.

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private SparkJob createSparkJob(String username, Jobs job, Users user) throws JobException, GenericException, ServiceException {
    SparkJob sparkjob = null;
    try {
        // Set Hopsworks consul service domain, don't use the address, use the name
        String hopsworksRestEndpoint = "https://" + serviceDiscoveryController.constructServiceFQDNWithPort(ServiceDiscoveryController.HopsworksService.HOPSWORKS_APP);
        UserGroupInformation proxyUser = ugiService.getProxyUser(username);
        try {
            sparkjob = proxyUser.doAs((PrivilegedExceptionAction<SparkJob>) () -> new SparkJob(job, submitter, user, settings.getHadoopSymbolicLinkDir(), hdfsUsersBean.getHdfsUserName(job.getProject(), user), settings, kafkaBrokers.getKafkaBrokersString(), hopsworksRestEndpoint, servingConfig, serviceDiscoveryController));
        } catch (InterruptedException ex) {
            LOGGER.log(Level.SEVERE, null, ex);
        }
    } catch (IOException ex) {
        throw new JobException(RESTCodes.JobErrorCode.PROXY_ERROR, Level.SEVERE, "job: " + job.getId() + ", user:" + user.getUsername(), ex.getMessage(), ex);
    } catch (ServiceDiscoveryException ex) {
        throw new ServiceException(RESTCodes.ServiceErrorCode.SERVICE_NOT_FOUND, Level.SEVERE, "job: " + job.getId() + ", user:" + user.getUsername(), ex.getMessage(), ex);
    }
    if (sparkjob == null) {
        throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.WARNING, "Could not instantiate job with name: " + job.getName() + " and id: " + job.getId(), "sparkjob object was null");
    }
    return sparkjob;
}
Also used : JobException(io.hops.hopsworks.exceptions.JobException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) GenericException(io.hops.hopsworks.exceptions.GenericException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) TransactionAttribute(javax.ejb.TransactionAttribute)

Example 29 with GenericException

use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.

the class CAProxy method signCSR.

private CSR signCSR(CSR csr, CA_PATH path) throws HopsSecurityException, GenericException {
    try {
        String csrJSON = objectMapper.writeValueAsString(csr);
        HttpPost httpRequest = new HttpPost(path.path);
        httpRequest.setHeader(HttpHeaders.CONTENT_TYPE, CONTENT_TYPE_JSON);
        client.setAuthorizationHeader(httpRequest);
        httpRequest.setEntity(new StringEntity(csrJSON));
        HttpRetryableAction<CSR> retryableAction = new HttpRetryableAction<CSR>() {

            @Override
            public CSR performAction() throws ClientProtocolException, IOException {
                return client.execute(httpRequest, CA_SIGN_RESPONSE_HANDLER);
            }
        };
        return retryableAction.tryAction();
    } catch (JsonProcessingException ex) {
        throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CSR_ERROR, Level.SEVERE, null, null, ex);
    } catch (ClientProtocolException ex) {
        LOG.log(Level.SEVERE, "Could not sign CSR", ex);
        throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CSR_ERROR, Level.SEVERE, null, null, ex.getCause());
    } catch (IOException ex) {
        LOG.log(Level.SEVERE, "Could not sign CSR", ex);
        throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ERROR, Level.SEVERE, "Generic error while signing CSR", null, ex);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CSR(io.hops.hopsworks.common.security.CSR) HttpRetryableAction(io.hops.hopsworks.common.proxies.client.HttpRetryableAction) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) GenericException(io.hops.hopsworks.exceptions.GenericException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) ClientProtocolException(org.apache.http.client.ClientProtocolException) NotRetryableClientProtocolException(io.hops.hopsworks.common.proxies.client.NotRetryableClientProtocolException)

Example 30 with GenericException

use of io.hops.hopsworks.exceptions.GenericException in project hopsworks by logicalclocks.

the class ProjectService method getProjectByNameAsShared.

@GET
@Path("/asShared/getProjectInfo/{projectName}")
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.PROJECT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@Produces(MediaType.APPLICATION_JSON)
public Response getProjectByNameAsShared(@PathParam("projectName") String projectName, @Context SecurityContext sc) throws ProjectException, GenericException {
    Users user = jWTHelper.getUserPrincipal(sc);
    Project project = projectController.findProjectByName(projectName);
    if (accessCtrl.hasExtendedAccess(user, project)) {
        ProjectDTO proj = projectController.getProjectByID(project.getId());
        return Response.ok().entity(proj).build();
    } else {
        throw new GenericException(RESTCodes.GenericErrorCode.NOT_AUTHORIZED_TO_ACCESS, Level.INFO);
    }
}
Also used : ProjectDTO(io.hops.hopsworks.common.project.ProjectDTO) Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) GenericException(io.hops.hopsworks.exceptions.GenericException) 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)

Aggregations

GenericException (io.hops.hopsworks.exceptions.GenericException)43 Users (io.hops.hopsworks.persistence.entity.user.Users)17 Project (io.hops.hopsworks.persistence.entity.project.Project)16 ProjectException (io.hops.hopsworks.exceptions.ProjectException)13 DatasetException (io.hops.hopsworks.exceptions.DatasetException)12 ServiceException (io.hops.hopsworks.exceptions.ServiceException)12 IOException (java.io.IOException)12 Path (javax.ws.rs.Path)11 ElasticException (io.hops.hopsworks.exceptions.ElasticException)10 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)10 JobException (io.hops.hopsworks.exceptions.JobException)9 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)9 Produces (javax.ws.rs.Produces)9 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)8 ArrayList (java.util.ArrayList)8 TransactionAttribute (javax.ejb.TransactionAttribute)8 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)6 UserException (io.hops.hopsworks.exceptions.UserException)6 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)6 HdfsUsers (io.hops.hopsworks.persistence.entity.hdfs.user.HdfsUsers)6