use of io.hops.hopsworks.exceptions.ExperimentsException 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.ExperimentsException in project hopsworks by logicalclocks.
the class ExperimentResultsBuilder method build.
public ExperimentResultSummaryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Project project, String mlId) throws ExperimentsException {
ExperimentResultSummaryDTO dto = new ExperimentResultSummaryDTO();
uri(dto, uriInfo, project, mlId);
expand(dto, resourceRequest);
dto.setCount(0l);
if (dto.isExpand()) {
DistributedFileSystemOps dfso = null;
try {
dfso = dfs.getDfsOps();
String summaryPath = Utils.getProjectPath(project.getName()) + Settings.HOPS_EXPERIMENTS_DATASET + "/" + mlId + "/.summary.json";
if (dfso.exists(summaryPath)) {
String summaryJson = dfso.cat(new Path(summaryPath));
if (!Strings.isNullOrEmpty(summaryJson)) {
ExperimentResultsDTO[] results = experimentConverter.unmarshalResults(summaryJson).getCombinations();
if (results != null) {
dto.setCount((long) results.length);
results = apply(results, resourceRequest);
dto.setCombinations(results);
}
}
}
} catch (Exception e) {
throw new ExperimentsException(RESTCodes.ExperimentsErrorCode.RESULTS_RETRIEVAL_ERROR, Level.SEVERE, "Unable to get results for experiment", e.getMessage(), e);
} finally {
if (dfso != null) {
dfs.closeDfsClient(dfso);
}
}
}
return dto;
}
use of io.hops.hopsworks.exceptions.ExperimentsException in project hopsworks by logicalclocks.
the class ExperimentConverter method createMarshaller.
private Marshaller createMarshaller() throws ExperimentsException {
try {
Marshaller marshaller = jaxbExperimentContext.createMarshaller();
marshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
marshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
return marshaller;
} catch (JAXBException e) {
throw new ExperimentsException(RESTCodes.ExperimentsErrorCode.EXPERIMENT_MARSHALLING_FAILED, Level.INFO, "Failed to unmarshal", "Error occurred during unmarshalling setup", e);
}
}
use of io.hops.hopsworks.exceptions.ExperimentsException in project hopsworks by logicalclocks.
the class ExperimentConverter method createUnmarshaller.
private Unmarshaller createUnmarshaller() throws ExperimentsException {
try {
Unmarshaller unmarshaller = jaxbExperimentContext.createUnmarshaller();
unmarshaller.setProperty(MarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
return unmarshaller;
} catch (JAXBException e) {
throw new ExperimentsException(RESTCodes.ExperimentsErrorCode.EXPERIMENT_MARSHALLING_FAILED, Level.INFO, "Failed to unmarshal", "Error occurred during unmarshalling setup", e);
}
}
use of io.hops.hopsworks.exceptions.ExperimentsException in project hopsworks by logicalclocks.
the class ExperimentResultsResource method getResults.
@ApiOperation(value = "Get results information", response = ExperimentResultSummaryDTO.class)
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getResults(@Context UriInfo uriInfo, @BeanParam Pagination pagination, @BeanParam ExperimentResultsBeanParam experimentResultsBeanParam, @Context SecurityContext sc) throws ExperimentsException {
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RESULTS);
resourceRequest.setOffset(pagination.getOffset());
resourceRequest.setLimit(pagination.getLimit());
resourceRequest.setSort(experimentResultsBeanParam.getSortBySet());
ExperimentResultSummaryDTO dto = experimentResultsBuilder.build(uriInfo, resourceRequest, project, experimentId);
if (dto == null) {
throw new ExperimentsException(RESTCodes.ExperimentsErrorCode.RESULTS_NOT_FOUND, Level.FINE);
}
return Response.ok().entity(dto).build();
}
Aggregations