use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticFeaturestoreBuilder method setFeatureNameHighlights.
private void setFeatureNameHighlights(SearchHit hitAux, ElasticFeaturestoreDTO result, DatasetAccessController.DatasetAccessCtrl accessCtrl) throws ElasticException, GenericException {
ElasticFeaturestoreHit hit = ElasticFeaturestoreHit.instance(hitAux);
Map<String, HighlightField> highlightFields = hitAux.getHighlightFields();
String featureNameField = FeaturestoreXAttrsConstants.getFeaturestoreElasticKey(FeaturestoreXAttrsConstants.FG_FEATURES, FeaturestoreXAttrsConstants.NAME);
// <highlighted text, name, description>
Function<Triplet<String, String, String>, Boolean> matcher = (state) -> {
// check if highlighted name equals feature name
return removeHighlightTags(state.getValue0()).equals(state.getValue1());
};
BiConsumer<ElasticFeaturestoreItemDTO.Highlights, String> highlighter = ElasticFeaturestoreItemDTO.Highlights::setName;
setFeatureHighlights(highlightFields.get(featureNameField), hit, matcher, highlighter, result, accessCtrl);
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticFeaturestoreBuilder method build.
public ElasticFeaturestoreDTO build(ElasticFeaturestoreRequest req, Integer projectId) throws ElasticException, ServiceException, GenericException {
checkRequest(req);
Project project = projectFacade.find(projectId);
Map<FeaturestoreDocType, Set<Integer>> searchProjects = datasetAccessCtrl.featurestoreSearchContext(project, req.getDocType());
Map<FeaturestoreDocType, SearchResponse> response = elasticCtrl.featurestoreSearch(req.getTerm(), searchProjects, req.getFrom(), req.getSize());
DatasetAccessController.DatasetAccessCtrl localProjectOnly = (datasetDetails, projectsCollector) -> projectsCollector.addAccessProject(project);
ElasticFeaturestoreDTO result = parseResult(response, localProjectOnly);
result.setFeaturegroupsFrom(req.getFrom());
result.setTrainingdatasetsFrom(req.getFrom());
result.setFeaturesFrom(req.getFrom());
return result;
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ProjectService method example.
@POST
@Path("starterProject/{type}")
@Produces(MediaType.APPLICATION_JSON)
public Response example(@PathParam("type") String type, @Context HttpServletRequest req, @Context SecurityContext sc) throws DatasetException, GenericException, KafkaException, ProjectException, UserException, ServiceException, HopsSecurityException, FeaturestoreException, JobException, IOException, ElasticException, SchemaException, ProvenanceException {
TourProjectType demoType;
try {
demoType = TourProjectType.fromString(type);
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Type must be one of: " + Arrays.toString(TourProjectType.values()));
}
ProjectDTO projectDTO = new ProjectDTO();
Project project = null;
projectDTO.setDescription("A demo project for getting started with " + demoType.getDescription());
Users user = jWTHelper.getUserPrincipal(sc);
String username = user.getUsername();
List<String> projectServices = new ArrayList<>();
// save the project
String readMeMessage = null;
switch(demoType) {
case KAFKA:
// It's a Kafka guide
projectDTO.setProjectName("demo_" + TourProjectType.KAFKA.getTourName() + "_" + username);
populateActiveServices(projectServices, TourProjectType.KAFKA);
readMeMessage = "jar file to demonstrate Kafka streaming";
break;
case SPARK:
// It's a Spark guide
projectDTO.setProjectName("demo_" + TourProjectType.SPARK.getTourName() + "_" + username);
populateActiveServices(projectServices, TourProjectType.SPARK);
readMeMessage = "jar file to demonstrate the creation of a spark batch job";
break;
case FS:
// It's a Featurestore guide
projectDTO.setProjectName("demo_" + TourProjectType.FS.getTourName() + "_" + username);
populateActiveServices(projectServices, TourProjectType.FS);
readMeMessage = "Dataset containing a jar file and data that can be used to run a sample spark-job for " + "inserting data in the feature store.";
break;
case ML:
// It's a TensorFlow guide
projectDTO.setProjectName("demo_" + TourProjectType.ML.getTourName() + "_" + username);
populateActiveServices(projectServices, TourProjectType.ML);
readMeMessage = "Jupyter notebooks and training data for demonstrating how to run Deep Learning";
break;
default:
throw new IllegalArgumentException("Type must be one of: " + Arrays.toString(TourProjectType.values()));
}
projectDTO.setServices(projectServices);
DistributedFileSystemOps dfso = null;
DistributedFileSystemOps udfso = null;
try {
project = projectController.createProject(projectDTO, user, req.getSession().getId());
dfso = dfs.getDfsOps();
username = hdfsUsersBean.getHdfsUserName(project, user);
udfso = dfs.getDfsOps(username);
ProvTypeDTO projectMetaStatus = fsProvenanceController.getProjectProvType(user, project);
String tourFilesDataset = projectController.addTourFilesToProject(user.getEmail(), project, dfso, dfso, demoType, projectMetaStatus);
// TestJob dataset
datasetController.generateReadme(udfso, tourFilesDataset, readMeMessage, project.getName());
} catch (Exception ex) {
projectController.cleanup(project, req.getSession().getId());
throw ex;
} finally {
if (dfso != null) {
dfso.close();
}
if (udfso != null) {
dfs.closeDfsClient(udfso);
}
}
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.CREATED).entity(project).build();
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticFeaturestoreHit method instance.
public static ElasticFeaturestoreHit instance(SearchHit hit) throws ElasticException {
ElasticFeaturestoreHit feHit = new ElasticFeaturestoreHit();
feHit.id = hit.getId();
// the source of the retrieved record (i.e. all the indexed information)
feHit.score = hit.getScore();
try {
for (Map.Entry<String, Object> entry : hit.getSourceAsMap().entrySet()) {
// set the name explicitly so that it's easily accessible in the frontend
if (entry.getKey().equals("doc_type")) {
feHit.docType = entry.getValue().toString();
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.NAME)) {
feHit.name = entry.getValue().toString();
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.VERSION)) {
feHit.version = Integer.parseInt(entry.getValue().toString());
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.PROJECT_ID)) {
feHit.projectId = Integer.parseInt(entry.getValue().toString());
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.PROJECT_NAME)) {
feHit.projectName = entry.getValue().toString();
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.DATASET_INODE_ID)) {
feHit.datasetIId = Long.parseLong(entry.getValue().toString());
} else if (entry.getKey().equals(FeaturestoreXAttrsConstants.ELASTIC_XATTR)) {
feHit.xattrs = (Map) entry.getValue();
}
}
} catch (NumberFormatException e) {
String userMsg = "Internal error during query";
String devMsg = "Hopsworks and Elastic types do not match - parsing problem";
throw new ElasticException(RESTCodes.ElasticErrorCode.ELASTIC_INTERNAL_REQ_ERROR, Level.WARNING, userMsg, devMsg, e);
}
return feHit;
}
use of io.hops.hopsworks.exceptions.ElasticException in project hopsworks by logicalclocks.
the class ElasticJWTController method createTokenForELK.
private String createTokenForELK(String project, Optional<Long> projectInodeId, String userRole) throws ElasticException {
SignatureAlgorithm alg = SignatureAlgorithm.valueOf(settings.getJWTSignatureAlg());
Date expiresAt = new Date(System.currentTimeMillis() + settings.getElasicJwtExpMs());
try {
Map<String, Object> claims = new HashMap<>();
claims.put(Constants.ROLES, userRole);
claims.put(Constants.ELK_VALID_PROJECT_NAME, ElasticUtils.getProjectNameWithNoSpecialCharacters(project));
if (projectInodeId.isPresent()) {
claims.put(Constants.ELK_PROJECT_INODE_ID, projectInodeId.get());
}
return jwtController.createTokenForELK(project, settings.getJWTIssuer(), claims, expiresAt, alg);
} catch (DuplicateSigningKeyException | NoSuchAlgorithmException | SigningKeyNotFoundException e) {
throw new ElasticException(RESTCodes.ElasticErrorCode.JWT_NOT_CREATED, Level.SEVERE, "Failed to create jwt token for elk", e.getMessage(), e);
}
}
Aggregations