Search in sources :

Example 1 with FilePreviewDTO

use of io.hops.hopsworks.common.dataset.FilePreviewDTO in project hopsworks by logicalclocks.

the class RemoteDelaService method readme.

@GET
@Path("/datasets/{publicDSId}/readme")
@Produces(MediaType.APPLICATION_JSON)
public Response readme(@PathParam("publicDSId") String publicDSId, @Context SecurityContext sc) throws DelaException {
    LOGGER.log(Settings.DELA_DEBUG, "remote:dela:readme {0}", publicDSId);
    Optional<Dataset> dataset = datasetFacade.findByPublicDsId(publicDSId);
    if (!dataset.isPresent() || !dataset.get().isPublicDs()) {
        throw new DelaException(RESTCodes.DelaErrorCode.DATASET_DOES_NOT_EXIST, Level.FINE, DelaException.Source.REMOTE_DELA);
    }
    FilePreviewDTO result = hdfsDelaCtrl.getPublicReadme(dataset.get());
    LOGGER.log(Settings.DELA_DEBUG, "remote:dela:readme - done {0}", publicDSId);
    return success(result);
}
Also used : Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) FilePreviewDTO(io.hops.hopsworks.common.dataset.FilePreviewDTO) DelaException(io.hops.hopsworks.exceptions.DelaException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with FilePreviewDTO

use of io.hops.hopsworks.common.dataset.FilePreviewDTO in project hopsworks by logicalclocks.

the class DelaHdfsController method getPublicReadme.

public FilePreviewDTO getPublicReadme(Dataset dataset) throws DelaException {
    LOGGER.log(Settings.DELA_DEBUG, "dela:hdfs:readme");
    DistributedFileSystemOps dfso = dfs.getDfsOps();
    FilePreviewDTO result = new FilePreviewDTO("text", "md", new String(read(dfso, readmePath(dataset))));
    LOGGER.log(Settings.DELA_DEBUG, "dela:hdfs:readme");
    return result;
}
Also used : FilePreviewDTO(io.hops.hopsworks.common.dataset.FilePreviewDTO) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)

Example 3 with FilePreviewDTO

use of io.hops.hopsworks.common.dataset.FilePreviewDTO in project hopsworks by logicalclocks.

the class RemoteDelaController method readme.

// ********************************************************************************************************************
public FilePreviewDTO readme(String publicDSId, ClusterAddressDTO source) throws DelaException {
    checkReady();
    try {
        ClientWrapper client = getClient(source.getDelaClusterAddress(), Path.readme(publicDSId), FilePreviewDTO.class);
        LOGGER.log(Settings.DELA_DEBUG, "dela:cross:readme {0}", client.getFullPath());
        FilePreviewDTO result = (FilePreviewDTO) client.doGet();
        LOGGER.log(Settings.DELA_DEBUG, "dela:cross:readme:done {0}", client.getFullPath());
        return result;
    } catch (IllegalStateException ex) {
        throw new DelaException(RESTCodes.DelaErrorCode.COMMUNICATION_FAILURE, Level.SEVERE, DelaException.Source.REMOTE_DELA, null, ex.getMessage(), ex);
    }
}
Also used : FilePreviewDTO(io.hops.hopsworks.common.dataset.FilePreviewDTO) DelaException(io.hops.hopsworks.exceptions.DelaException) ClientWrapper(io.hops.hopsworks.common.util.ClientWrapper)

Example 4 with FilePreviewDTO

use of io.hops.hopsworks.common.dataset.FilePreviewDTO in project hopsworks by logicalclocks.

the class ProjectService method getReadmeByInodeId.

@GET
@Path("/readme/byInodeId/{inodeId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getReadmeByInodeId(@PathParam("inodeId") Long inodeId, @Context SecurityContext sc) throws DatasetException {
    if (inodeId == null) {
        throw new IllegalArgumentException("No inodeId provided.");
    }
    Inode inode = inodes.findById(inodeId);
    Inode parent = inodes.findParent(inode);
    Project proj = projectFacade.findByName(parent.getInodePK().getName());
    Dataset ds = datasetFacade.findByProjectAndInode(proj, inode);
    if (ds != null && !ds.isSearchable()) {
        throw new DatasetException(RESTCodes.DatasetErrorCode.README_NOT_ACCESSIBLE, Level.FINE);
    }
    DistributedFileSystemOps dfso = dfs.getDfsOps();
    FilePreviewDTO filePreviewDTO;
    String path = inodeController.getPath(inode);
    try {
        filePreviewDTO = datasetController.getReadme(path + "/README.md", dfso);
    } catch (IOException ex) {
        filePreviewDTO = new FilePreviewDTO();
        filePreviewDTO.setContent("No README file found for this dataset.");
        return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(filePreviewDTO).build();
    }
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(filePreviewDTO).build();
}
Also used : Project(io.hops.hopsworks.persistence.entity.project.Project) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) FilePreviewDTO(io.hops.hopsworks.common.dataset.FilePreviewDTO) DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) IOException(java.io.IOException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

FilePreviewDTO (io.hops.hopsworks.common.dataset.FilePreviewDTO)4 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)2 DelaException (io.hops.hopsworks.exceptions.DelaException)2 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ClientWrapper (io.hops.hopsworks.common.util.ClientWrapper)1 DatasetException (io.hops.hopsworks.exceptions.DatasetException)1 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 IOException (java.io.IOException)1