Search in sources :

Example 1 with ExperimentsException

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);
            }
    }
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) UriBuilder(javax.ws.rs.core.UriBuilder) GenericException(io.hops.hopsworks.exceptions.GenericException) ProjectException(io.hops.hopsworks.exceptions.ProjectException) ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) GenericException(io.hops.hopsworks.exceptions.GenericException) PythonException(io.hops.hopsworks.exceptions.PythonException) MetadataException(io.hops.hopsworks.exceptions.MetadataException) ProvenanceException(io.hops.hopsworks.exceptions.ProvenanceException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 2 with ExperimentsException

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;
}
Also used : Path(org.apache.hadoop.fs.Path) ExperimentResultsDTO(io.hops.hopsworks.api.experiments.dto.results.ExperimentResultsDTO) ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) ExperimentResultSummaryDTO(io.hops.hopsworks.api.experiments.dto.results.ExperimentResultSummaryDTO)

Example 3 with ExperimentsException

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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) JAXBException(javax.xml.bind.JAXBException)

Example 4 with ExperimentsException

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);
    }
}
Also used : ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) JAXBException(javax.xml.bind.JAXBException) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 5 with ExperimentsException

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();
}
Also used : ExperimentsException(io.hops.hopsworks.exceptions.ExperimentsException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ExperimentResultSummaryDTO(io.hops.hopsworks.api.experiments.dto.results.ExperimentResultSummaryDTO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

ExperimentsException (io.hops.hopsworks.exceptions.ExperimentsException)7 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)3 GenericException (io.hops.hopsworks.exceptions.GenericException)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)3 ApiOperation (io.swagger.annotations.ApiOperation)3 Produces (javax.ws.rs.Produces)3 ExperimentDTO (io.hops.hopsworks.api.experiments.dto.ExperimentDTO)2 ExperimentResultSummaryDTO (io.hops.hopsworks.api.experiments.dto.results.ExperimentResultSummaryDTO)2 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)2 ProvStateDTO (io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO)2 DatasetException (io.hops.hopsworks.exceptions.DatasetException)2 MetadataException (io.hops.hopsworks.exceptions.MetadataException)2 ProvenanceException (io.hops.hopsworks.exceptions.ProvenanceException)2 Users (io.hops.hopsworks.persistence.entity.user.Users)2 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 JAXBException (javax.xml.bind.JAXBException)2 ExperimentsEndpointDTO (io.hops.hopsworks.api.experiments.dto.ExperimentsEndpointDTO)1 ExperimentResultsDTO (io.hops.hopsworks.api.experiments.dto.results.ExperimentResultsDTO)1