use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method getTotalNumberOfReplsForDataObject.
@Override
public int getTotalNumberOfReplsForDataObject(String path) throws DataGridException {
logger.info("getTotalNumberOfReplsForDataObject()");
int totalNumberOfRepls = 0;
if (path == null || path.isEmpty()) {
return 0;
}
String parentPath = path.substring(0, path.lastIndexOf(IRODS_PATH_SEPARATOR));
String dataObjectName = path.substring(path.lastIndexOf(IRODS_PATH_SEPARATOR), path.length());
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
// getting total number of replicas
try {
totalNumberOfRepls = dataObjectAO.getTotalNumberOfReplsForDataObject(parentPath, dataObjectName);
} catch (JargonException e) {
logger.error("Could not get number of replicas of a data obj: {}", e.getMessage());
throw new DataGridException(e.getMessage());
}
return totalNumberOfRepls;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method getCollectionDataProfile.
@SuppressWarnings("unchecked")
@Override
public DataProfile<IRODSDomainObject> getCollectionDataProfile(String path) throws DataGridException {
IRODSAccount irodsAccount = irodsServices.getUserAO().getIRODSAccount();
logger.info("*****************path **************" + path);
logger.debug("got irodsAccount:{}", irodsAccount);
DataProfilerService dataProfilerService = dataProfilerFactory.instanceDataProfilerService(irodsAccount);
logger.debug("got the dataProfilerService");
// TODO: allow clone()
try {
@SuppressWarnings("rawtypes") DataProfile dataProfile = dataProfilerService.retrieveDataProfile(path);
logger.info("------CollectionInfoController getTestCollectionInfo() ends !!");
logger.info("data profile retrieved:{}", dataProfile);
/*
* TODO: after this do an if test and send to right view with the DataProfile in
* the model
*/
return dataProfile;
} catch (JargonException e) {
logger.error("Could not retrieve collection/dataobject from path: {}", path, e);
throw new DataGridException(e.getMessage());
}
}
use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class UploadController method upload.
@RequestMapping(value = "/", method = RequestMethod.POST, produces = { "text/plain" })
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<?> upload(final HttpServletRequest request) throws DataGridException {
logger.info("upload()");
String uploadMessage = "File Uploaded. ";
String errorType = "";
if (!(request instanceof MultipartHttpServletRequest)) {
logger.warn("Request is not a multipart request.");
uploadMessage = "Request is not a multipart request.";
errorType = FATAL;
return getUploadResponse(uploadMessage, errorType);
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile multipartFile = multipartRequest.getFile("file");
logger.info("multipartFile:{}", multipartFile);
boolean isRuleDeployment = Boolean.parseBoolean(multipartRequest.getParameter("ruleDeployment"));
boolean checksum = Boolean.parseBoolean(multipartRequest.getParameter("checksum"));
boolean replica = Boolean.parseBoolean(multipartRequest.getParameter("replica"));
boolean overwrite = Boolean.parseBoolean(multipartRequest.getParameter("overwriteDuplicateFiles"));
String resources = multipartRequest.getParameter("resources");
String resourcesToUpload = multipartRequest.getParameter("resourcesToUpload");
String destPath = multipartRequest.getParameter("uploadDestinationPath");
logger.info("parsed parameters...");
try {
if (isRuleDeployment) {
ruleDeploymentService.deployRule(multipartFile);
} else {
us.upload(multipartFile, destPath, checksum, replica, resources, resourcesToUpload, overwrite);
}
} catch (DataGridReplicateException e) {
uploadMessage += e.getMessage();
errorType = WARNING;
logger.warn("DataGridReplicateException during upload, will pass back as a warning", e);
} catch (DataGridRuleException e) {
uploadMessage += METADATA_EXTRACTION_FAILED_MSG;
errorType = WARNING;
logger.warn("DataGridRule exception extracting metadata, will pass back as warning", e);
} catch (DataGridException e) {
uploadMessage = e.getMessage();
errorType = FATAL;
logger.error("DataGridException uploading file", e);
logger.warn("DataGridException uplaoding file, will pass back as warning", e);
// throw e;
} catch (JargonException e) {
uploadMessage = e.getMessage();
errorType = FATAL;
logger.error("JargonException uploading file", e);
logger.warn("JargonException uplaoding file, will pass back as warning", e);
} catch (Throwable t) {
logger.error("unexpected exception in upload", t);
errorType = FATAL;
throw t;
}
return getUploadResponse(uploadMessage, errorType);
}
use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class UploadServiceImpl method upload.
@Override
public boolean upload(MultipartFile file, String targetPath, boolean computeCheckSum, boolean replicateFile, String replicationResc, String destResc, boolean overwrite) throws DataGridException {
logger.info("upload()");
if (file == null || file.isEmpty() || "".equals(targetPath) || targetPath == null || "".equals(destResc) || destResc == null) {
logger.error("File could not be sent to the data grid.");
return false;
}
logger.info("file:{}", file);
logger.info("targetPath:{}", targetPath);
logger.info("computeCheckSum:{}", computeCheckSum);
logger.info("replicateFile:{}", replicateFile);
logger.info("replicationResc:{}", replicationResc);
logger.info("destResc:{}", destResc);
logger.info("overwrite:{}", overwrite);
InputStream inputStream;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
logger.error("Could not get input stream from file: ", e.getMessage());
throw new DataGridException("Could not get input stream from file.");
}
String defaultStorageResource = is.getDefaultStorageResource();
logger.info("Setting default resource to {}", destResc);
// Setting temporarily the defaultStorageResource for the logged user
is.setDefaultStorageResource(destResc);
boolean isFileUploaded;
// Getting DataObjectAO in order to create the new file
IRODSFileFactory irodsFileFactory = is.getIRODSFileFactory();
Stream2StreamAO stream2StreamA0 = is.getStream2StreamAO();
IRODSFile targetFile = null;
try {
String fileName = file.getOriginalFilename();
if (fileName.isEmpty())
fileName = file.getName();
targetFile = irodsFileFactory.instanceIRODSFile(targetPath, fileName);
logger.info("targetFile:{}", targetFile);
// aborted.
if (targetFile.exists() && !overwrite) {
String msg = "File already exists. Not overwriting it.";
logger.info(msg);
throw new DataGridFileAlreadyExistsException(msg);
}
// Transfering file to iRODS filesystem
stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
logger.info("transfer complete, compute checksum if required");
// Computing a check sum for this file just uploaded to iRODS
if (computeCheckSum)
fos.computeChecksum(targetPath, fileName);
// Replicating file into desired resource
if (replicateFile)
fos.replicateDataObject(targetFile.getPath(), replicationResc, false);
if (configService.isUploadRulesEnabled()) {
logger.info("applying upload rules");
processUploadRules(targetPath, destResc, targetFile);
}
isFileUploaded = true;
} catch (JargonException e) {
fos.deleteDataObject(targetFile.getPath(), true);
logger.error("Upload stream failed from Metalnx to the data grid. {}", e.getMessage());
throw new DataGridException("Upload failed. Resource(s) might be full.");
} catch (DataGridFileAlreadyExistsException e) {
logger.warn("File already exists..will rethrow.");
throw e;
} catch (Throwable e) {
logger.error("Exception in upload processing", e);
throw new DataGridException("Could not upload due to system exception");
} finally {
try {
// Closing streams opened
inputStream.close();
} catch (IOException e) {
logger.error("Could close stream: ", e.getMessage());
}
}
// Setting the default resource back to the original one.
is.setDefaultStorageResource(defaultStorageResource);
return isFileUploaded;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.
the class BrowseController method getFileInfo.
/**
* Gets checksum, total number of replicas and where each replica lives in the
* data grid for a specific data object
*
* @param model
* @param path
* path to the data object to get checksum and replica information
* @return the template that shows the data object information
* @throws DataGridException
* @throws FileNotFoundException
*/
@RequestMapping(value = "/info/", method = RequestMethod.POST)
public String getFileInfo(final Model model, final String path) throws DataGridException, FileNotFoundException {
logger.info("CollectionController getInfoFile() starts :: " + path);
DataGridCollectionAndDataObject dataGridObj = null;
Map<DataGridCollectionAndDataObject, DataGridResource> replicasMap = null;
try {
dataGridObj = cs.findByName(path);
if (dataGridObj != null && !dataGridObj.isCollection()) {
replicasMap = cs.listReplicasByResource(path);
dataGridObj.setChecksum(cs.getChecksum(path));
dataGridObj.setNumberOfReplicas(cs.getTotalNumberOfReplsForDataObject(path));
dataGridObj.setReplicaNumber(String.valueOf(cs.getReplicationNumber(path)));
permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, loggedUserUtils.getLoggedDataGridUser());
}
} catch (DataGridConnectionRefusedException e) {
logger.error("Could not connect to the data grid", e);
throw e;
} catch (DataGridException e) {
logger.error("Could not get file info for {}", path, e);
throw e;
} catch (FileNotFoundException e) {
logger.error("file does not exist for:{}", path, e);
throw e;
}
model.addAttribute("collectionAndDataObject", dataGridObj);
model.addAttribute("currentCollection", dataGridObj);
model.addAttribute("replicasMap", replicasMap);
model.addAttribute("infoFlag", true);
logger.info("CollectionController getInfoFile() ends !!");
return "collections/info :: infoView";
// return "collections/info";
}
Aggregations