Search in sources :

Example 1 with DataGridException

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;
}
Also used : DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 2 with DataGridException

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());
    }
}
Also used : DataProfile(org.irods.jargon.extensions.dataprofiler.DataProfile) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) JargonException(org.irods.jargon.core.exception.JargonException) DataProfilerService(org.irods.jargon.extensions.dataprofiler.DataProfilerService)

Example 3 with DataGridException

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);
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) DataGridRuleException(com.emc.metalnx.core.domain.exceptions.DataGridRuleException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridReplicateException(com.emc.metalnx.core.domain.exceptions.DataGridReplicateException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with DataGridException

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;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridFileAlreadyExistsException(com.emc.metalnx.core.domain.exceptions.DataGridFileAlreadyExistsException) InputStream(java.io.InputStream) Stream2StreamAO(org.irods.jargon.core.pub.Stream2StreamAO) JargonException(org.irods.jargon.core.exception.JargonException) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 5 with DataGridException

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";
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)19 JargonException (org.irods.jargon.core.exception.JargonException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)5 CollectionAO (org.irods.jargon.core.pub.CollectionAO)4 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)4 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 IOException (java.io.IOException)3 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)3 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)3 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)3 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)2 InputStream (java.io.InputStream)2 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)2 Stream2StreamAO (org.irods.jargon.core.pub.Stream2StreamAO)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)2 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)1 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)1