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);
}
}
}
}
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;
}
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);
}
}
}
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);
}
}
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);
}
}
}
}
Aggregations