use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.
the class XAttrsResource method get.
@ApiOperation(value = "Get extended attributes attached to a path.", response = XAttrDTO.class)
@GET
@Path("{path: .+}")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@Context SecurityContext sc, @Context UriInfo uriInfo, @PathParam("path") String path, @QueryParam("pathType") @DefaultValue("DATASET") DatasetType pathType, @QueryParam("name") String xattrName) throws DatasetException, MetadataException {
Users user = jWTHelper.getUserPrincipal(sc);
Map<String, String> result = new HashMap<>();
DistributedFileSystemOps udfso = dfs.getDfsOps(hdfsUsersController.getHdfsUserName(project, user));
String inodePath = datasetHelper.getDatasetPathIfFileExist(project, path, pathType).getFullPath().toString();
try {
if (xattrName != null) {
String xattr = xattrsController.getXAttr(inodePath, xattrName, udfso);
if (Strings.isNullOrEmpty(xattr)) {
throw new MetadataException(RESTCodes.MetadataErrorCode.METADATA_MISSING_FIELD, Level.FINE);
}
result.put(xattrName, xattr);
} else {
result.putAll(xattrsController.getXAttrs(inodePath, udfso));
}
} finally {
dfs.closeDfsClient(udfso);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.XATTRS);
XAttrDTO dto = xattrsBuilder.build(uriInfo, resourceRequest, project, inodePath, result);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.
the class ModelRegistryBuilder method build.
// Build collection
public ModelRegistryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project project) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
ModelRegistryDTO dto = new ModelRegistryDTO();
uri(dto, uriInfo, project);
expand(dto, resourceRequest);
Collection<Dataset> dsInProject = project.getDatasetCollection();
// Add all datasets shared with the project
dsInProject.addAll(project.getDatasetSharedWithCollection().stream().filter(DatasetSharedWith::getAccepted).map(DatasetSharedWith::getDataset).collect(Collectors.toList()));
Collection<Dataset> modelsDatasets = dsInProject.stream().filter(ds -> ds.getName().equals(Settings.HOPS_MODELS_DATASET)).collect(Collectors.toList());
dto.setCount((long) modelsDatasets.size());
for (Dataset ds : modelsDatasets) {
ModelRegistryDTO modelRegistryDTO = build(uriInfo, resourceRequest, user, project, ds.getProject());
if (modelRegistryDTO != null) {
dto.addItem(modelRegistryDTO);
}
}
return dto;
}
use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.
the class ExperimentsResource method post.
@ApiOperation(value = "Create or update an experiment", response = ExperimentDTO.class)
@PUT
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response post(@PathParam("id") String id, ExperimentDTO experimentDTO, @QueryParam("type") ExperimentOperationType type, @Context HttpServletRequest req, @Context UriInfo uriInfo, @Context SecurityContext sc) throws DatasetException, ProvenanceException, PythonException, MetadataException, ProjectException, GenericException, ExperimentsException {
if (experimentDTO == null) {
throw new IllegalArgumentException("No Experiment configuration was provided");
}
Users user = jwtHelper.getUserPrincipal(sc);
Project experimentProject = project;
switch(type) {
case INIT:
{
String experimentPath = Utils.getProjectPath(project.getName()) + Settings.HOPS_EXPERIMENTS_DATASET + "/" + id + "/" + Settings.ENVIRONMENT_FILE;
experimentDTO.setEnvironment(environmentController.exportEnv(experimentProject, user, experimentPath));
try {
String program = experimentsController.versionProgram(experimentProject, user, experimentDTO.getJobName(), experimentDTO.getKernelId(), id);
experimentDTO.setProgram(program);
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Could not version notebook " + e.getMessage());
}
}
break;
case MODEL_UPDATE:
{
Project modelProject = getModelsProjectAndCheckAccess(experimentDTO);
experimentsController.attachModel(user, experimentProject, id, modelProject, experimentDTO.getModel());
}
break;
case FULL_UPDATE:
{
// no need to update the summary in any way
}
break;
default:
{
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "unhandled experiment summary operation type:" + type);
}
}
experimentsController.attachExperiment(user, experimentProject, id, experimentDTO);
UriBuilder builder = uriInfo.getAbsolutePathBuilder().path(id);
switch(type) {
case INIT:
return Response.created(builder.build()).entity(experimentDTO).build();
case MODEL_UPDATE:
case FULL_UPDATE:
return Response.ok(builder.build()).entity(experimentDTO).build();
default:
{
throw new GenericException(RESTCodes.GenericErrorCode.ILLEGAL_ARGUMENT, Level.INFO, "unhandled experiment summary operation type:" + type);
}
}
}
use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.
the class XAttrsController method addXAttr.
public boolean addXAttr(Project project, Users user, String inodePath, String name, String metaObj) throws DatasetException, MetadataException {
if (name == null || name.isEmpty()) {
throw new MetadataException(RESTCodes.MetadataErrorCode.METADATA_MISSING_FIELD, Level.FINE);
}
JSONObject metaJSON = null;
Object json = new JSONTokener(metaObj).nextValue();
if (json instanceof JSONObject) {
metaJSON = (JSONObject) json;
} else if (json instanceof JSONArray) {
metaJSON = new JSONObject();
metaJSON.put(name, json.toString());
}
if (!metaJSON.has(name)) {
throw new MetadataException(RESTCodes.MetadataErrorCode.METADATA_MISSING_FIELD, Level.FINE);
}
String metadata = metaJSON.getString(name);
boolean created = getXAttr(project, user, inodePath, XATTR_USER_NAMESPACE, name) == null;
addXAttrInt(project, user, inodePath, name, metadata);
return created;
}
use of io.hops.hopsworks.exceptions.MetadataException in project hopsworks by logicalclocks.
the class HopsFSProvenanceController method setProvCoreXAttr.
private void setProvCoreXAttr(String path, ProvCoreDTO provCore, DistributedFileSystemOps udfso) throws ProvenanceException {
try {
String provType = converter.marshal(provCore);
xattrCtrl.upsertProvXAttr(udfso, path, ProvXAttrs.PROV_XATTR_CORE_VAL, provType.getBytes());
} catch (GenericException | DatasetException | MetadataException e) {
throw new ProvenanceException(RESTCodes.ProvenanceErrorCode.FS_ERROR, Level.WARNING, "hopsfs - set xattr - prov core - error", "hopsfs - set xattr - prov core - error", e);
}
}
Aggregations