Search in sources :

Example 26 with DelaException

use of io.hops.hopsworks.exceptions.DelaException in project hopsworks by logicalclocks.

the class DelaHdfsController method write.

public void write(Project project, Users user, Path filePath, byte[] fileContent) throws DelaException {
    String hdfsUser = hdfsUsersBean.getHdfsUserName(project, user);
    DistributedFileSystemOps dfso = dfs.getDfsOps(hdfsUser);
    try {
        if (dfso.exists(filePath)) {
            throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.FINE, DelaException.Source.HDFS, "file exists");
        }
    } catch (IOException ex) {
        throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.SEVERE, DelaException.Source.HDFS, "cannot read", ex.getMessage(), ex);
    }
    FSDataOutputStream out = null;
    try {
        out = dfso.create(filePath);
        out.write(fileContent);
        out.flush();
    } catch (IOException ex) {
        throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.SEVERE, DelaException.Source.HDFS, "cannot write", ex.getMessage(), ex);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException ex) {
                throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.SEVERE, DelaException.Source.HDFS, "cannot close", ex.getMessage(), ex);
            }
        }
    }
}
Also used : DistributedFileSystemOps(io.hops.hopsworks.common.hdfs.DistributedFileSystemOps) IOException(java.io.IOException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) DelaException(io.hops.hopsworks.exceptions.DelaException)

Example 27 with DelaException

use of io.hops.hopsworks.exceptions.DelaException in project hopsworks by logicalclocks.

the class DelaDatasetController method download.

public Dataset download(Project project, Users user, String publicDSId, String name) throws DelaException, ProvenanceException {
    Dataset dataset;
    try {
        dataset = createDataset(user, project, name, "");
    } catch (DatasetException | HopsSecurityException e) {
        throw new DelaException(RESTCodes.DelaErrorCode.THIRD_PARTY_ERROR, Level.SEVERE, DelaException.Source.LOCAL, null, e.getMessage(), e);
    }
    dataset.setPublicDsState(SharedState.HOPS);
    dataset.setPublicDsId(publicDSId);
    // datasetController.setPermissions();
    // dataset.setEditable(DatasetPermissions.OWNER_ONLY);
    datasetFacade.merge(dataset);
    datasetCtrl.logDataset(project, dataset, OperationType.Update);
    return dataset;
}
Also used : Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) DelaException(io.hops.hopsworks.exceptions.DelaException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException)

Example 28 with DelaException

use of io.hops.hopsworks.exceptions.DelaException in project hopsworks by logicalclocks.

the class DelaSetupWorker method delaContact.

private void delaContact(Timer timer) {
    LOGGER.log(Level.INFO, "{0} - state:{1}", new Object[] { DelaException.Source.HOPS_SITE, state });
    AddressJSON delaTransferEndpoint;
    try {
        delaTransferEndpoint = SettingsHelper.delaTransferEndpoint(settings);
    } catch (DelaException tpe) {
        try {
            delaTransferEndpoint = getDelaTransferEndpoint(delaVersion);
            delaStateCtrl.transferDelaContacted();
            settings.setDELA_PUBLIC_ENDPOINT(delaTransferEndpoint);
            timer = resetToRegister(timer);
            hopsSiteRegister(timer, delaTransferEndpoint);
        } catch (DelaException tpe2) {
            LOGGER.log(Level.WARNING, "{0} - source:<{1}>:{2}", new Object[] { DelaException.Source.HOPS_SITE, tpe2.getSource(), tpe2.getMessage() });
            timer = tryAgainLater(timer);
        }
    }
}
Also used : AddressJSON(io.hops.hopsworks.common.dela.AddressJSON) DelaException(io.hops.hopsworks.exceptions.DelaException)

Example 29 with DelaException

use of io.hops.hopsworks.exceptions.DelaException in project hopsworks by logicalclocks.

the class DelaSetupWorker method hopsSiteRegister.

private void hopsSiteRegister(Timer timer) {
    LOGGER.log(Level.INFO, "{0} - state:{1}", new Object[] { DelaException.Source.HOPS_SITE, state });
    AddressJSON delaTransferEndpoint;
    try {
        delaTransferEndpoint = SettingsHelper.delaTransferEndpoint(settings);
    } catch (DelaException ex) {
        timer = resetToDelaContact(timer);
        return;
    }
    try {
        hopsSiteRegister(timer, delaTransferEndpoint);
    } catch (DelaException tpe) {
        LOGGER.log(Level.WARNING, "{0} - source:<{1}>:{2}", new Object[] { DelaException.Source.HOPS_SITE, tpe.getSource(), tpe.getMessage() });
        timer = tryAgainLater(timer);
    }
}
Also used : AddressJSON(io.hops.hopsworks.common.dela.AddressJSON) DelaException(io.hops.hopsworks.exceptions.DelaException)

Example 30 with DelaException

use of io.hops.hopsworks.exceptions.DelaException in project hopsworks by logicalclocks.

the class DelaHdfsController method read.

public byte[] read(DistributedFileSystemOps dfso, Path filePath) throws DelaException {
    try {
        if (!dfso.exists(filePath)) {
            throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.FINE, DelaException.Source.HDFS, "file does not exist");
        }
    } catch (IOException ex) {
        throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.SEVERE, DelaException.Source.HDFS, "cannot read", ex.getMessage(), ex);
    }
    FSDataInputStream fdi = null;
    try {
        fdi = dfso.open(filePath);
        long fileLength = dfso.getLength(filePath);
        byte[] fileContent = new byte[(int) fileLength];
        fdi.readFully(fileContent);
        return fileContent;
    } catch (IOException ex) {
        throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.SEVERE, DelaException.Source.HDFS, "cannot read", ex.getMessage(), ex);
    } finally {
        if (fdi != null) {
            try {
                fdi.close();
            } catch (IOException ex) {
                throw new DelaException(RESTCodes.DelaErrorCode.ACCESS_ERROR, Level.SEVERE, DelaException.Source.HDFS, "cannot close", ex.getMessage(), ex);
            }
        }
    }
}
Also used : FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException) DelaException(io.hops.hopsworks.exceptions.DelaException)

Aggregations

DelaException (io.hops.hopsworks.exceptions.DelaException)62 ClientWrapper (io.hops.hopsworks.common.util.ClientWrapper)31 Users (io.hops.hopsworks.persistence.entity.user.Users)8 Path (javax.ws.rs.Path)8 Gson (com.google.gson.Gson)7 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)7 IOException (java.io.IOException)6 HopsSite (io.hops.hopsworks.dela.hopssite.HopsSite)5 ManifestJSON (io.hops.hopsworks.dela.old_dto.ManifestJSON)5 SuccessJSON (io.hops.hopsworks.dela.old_dto.SuccessJSON)5 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)5 Produces (javax.ws.rs.Produces)5 AddressJSON (io.hops.hopsworks.common.dela.AddressJSON)4 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)4 TorrentId (io.hops.hopsworks.dela.old_dto.TorrentId)4 LinkedList (java.util.LinkedList)4 GET (javax.ws.rs.GET)4 POST (javax.ws.rs.POST)4 UserDTO (io.hops.hopsworks.dela.dto.common.UserDTO)3 SearchServiceDTO (io.hops.hopsworks.dela.dto.hopssite.SearchServiceDTO)3