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;
}
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();
}
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;
}
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);
}
}
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);
}
}
Aggregations