Search in sources :

Example 16 with IRODSFileFactory

use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.

the class FileOperationServiceImpl method deleteDataObject.

@Override
public boolean deleteDataObject(String dataObjectPath, boolean forceFlag) throws DataGridException {
    boolean dataObjDeleted = false;
    try {
        IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        IRODSFile fileToBeRemoved = irodsFileFactory.instanceIRODSFile(dataObjectPath);
        if (forceFlag) {
            irodsFileSystemAO.fileDeleteForce(fileToBeRemoved);
        } else {
            irodsFileSystemAO.fileDeleteNoForce(fileToBeRemoved);
        }
        dataObjDeleted = true;
    } catch (JargonException e) {
        logger.error("Could not delete data object: {}", e.getMessage());
    }
    return dataObjDeleted;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 17 with IRODSFileFactory

use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.

the class SpecQueryServiceImplTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TestingPropertiesHelper testingPropertiesLoader = new TestingPropertiesHelper();
    testingProperties = testingPropertiesLoader.getTestProperties();
    scratchFileUtils = new ScratchFileUtils(testingProperties);
    scratchFileUtils.clearAndReinitializeScratchDirectory(IRODS_TEST_SUBDIR_PATH);
    irodsTestSetupUtilities = new IRODSTestSetupUtilities();
    irodsTestSetupUtilities.initializeIrodsScratchDirectory();
    irodsTestSetupUtilities.initializeDirectoryForTest(IRODS_TEST_SUBDIR_PATH);
    irodsFileSystem = IRODSFileSystem.instance();
    // set up test structure
    String rootCollection = "SpecQueryServiceImplTestRoot";
    String localCollectionAbsolutePath = scratchFileUtils.createAndReturnAbsoluteScratchPath(IRODS_TEST_SUBDIR_PATH + '/' + rootCollection);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
    String irodsCollectionRootAbsolutePath = (MiscIRODSUtils.computeHomeDirectoryForIRODSAccount(irodsAccount) + '/' + rootCollection);
    rootCollPathInIrods = irodsCollectionRootAbsolutePath;
    FileGenerator.generateManyFilesAndCollectionsInParentCollectionByAbsolutePath(localCollectionAbsolutePath, "specQueryTset", 1, 2, 3, "testFile", ".txt", 4, 3, 2, 30000);
    IRODSFileFactory irodsFileFactory = irodsFileSystem.getIRODSFileFactory(irodsAccount);
    IRODSFile destFile = irodsFileFactory.instanceIRODSFile(irodsCollectionRootAbsolutePath);
    destFile.deleteWithForceOption();
    destFile.mkdirs();
    DataTransferOperations dataTransferOperationsAO = irodsFileSystem.getIRODSAccessObjectFactory().getDataTransferOperations(irodsAccount);
    DataObjectAO dataObjectAO = irodsFileSystem.getIRODSAccessObjectFactory().getDataObjectAO(irodsAccount);
    CollectionAO collectionAO = irodsFileSystem.getIRODSAccessObjectFactory().getCollectionAO(irodsAccount);
    File localFile = new File(localCollectionAbsolutePath);
    dataTransferOperationsAO.putOperation(localFile, destFile, null, null);
    // Decorate with various AVUs to use in tests
    decorateChildren(destFile, collectionAO, dataObjectAO);
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) IRODSTestSetupUtilities(org.irods.jargon.testutils.IRODSTestSetupUtilities) CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataTransferOperations(org.irods.jargon.core.pub.DataTransferOperations) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) File(java.io.File) TestingPropertiesHelper(org.irods.jargon.testutils.TestingPropertiesHelper) ScratchFileUtils(org.irods.jargon.testutils.filemanip.ScratchFileUtils) BeforeClass(org.junit.BeforeClass)

Example 18 with IRODSFileFactory

use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.

the class CollectionServiceImplTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TestingPropertiesHelper testingPropertiesLoader = new TestingPropertiesHelper();
    testingProperties = testingPropertiesLoader.getTestProperties();
    scratchFileUtils = new ScratchFileUtils(testingProperties);
    scratchFileUtils.clearAndReinitializeScratchDirectory(IRODS_TEST_SUBDIR_PATH);
    irodsTestSetupUtilities = new IRODSTestSetupUtilities();
    irodsTestSetupUtilities.initializeIrodsScratchDirectory();
    irodsTestSetupUtilities.initializeDirectoryForTest(IRODS_TEST_SUBDIR_PATH);
    irodsFileSystem = IRODSFileSystem.instance();
    // set up test structure
    String rootCollection = "CollectionServiceImplTestTestRoot";
    String localCollectionAbsolutePath = scratchFileUtils.createAndReturnAbsoluteScratchPath(IRODS_TEST_SUBDIR_PATH + '/' + rootCollection);
    IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
    String irodsCollectionRootAbsolutePath = (MiscIRODSUtils.computeHomeDirectoryForIRODSAccount(irodsAccount) + '/' + rootCollection);
    rootCollPathInIrods = irodsCollectionRootAbsolutePath;
    FileGenerator.generateManyFilesAndCollectionsInParentCollectionByAbsolutePath(localCollectionAbsolutePath, "textSearchQueryTest", 1, 2, 3, "textSearchService", ".txt", 4, 3, 2, 30);
    IRODSFileFactory irodsFileFactory = irodsFileSystem.getIRODSFileFactory(irodsAccount);
    IRODSFile destFile = irodsFileFactory.instanceIRODSFile(irodsCollectionRootAbsolutePath);
    destFile.deleteWithForceOption();
    destFile.mkdirs();
    DataTransferOperations dataTransferOperationsAO = irodsFileSystem.getIRODSAccessObjectFactory().getDataTransferOperations(irodsAccount);
    File localFile = new File(localCollectionAbsolutePath);
    dataTransferOperationsAO.putOperation(localFile, destFile, null, null);
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) IRODSTestSetupUtilities(org.irods.jargon.testutils.IRODSTestSetupUtilities) DataTransferOperations(org.irods.jargon.core.pub.DataTransferOperations) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) File(java.io.File) TestingPropertiesHelper(org.irods.jargon.testutils.TestingPropertiesHelper) ScratchFileUtils(org.irods.jargon.testutils.filemanip.ScratchFileUtils) BeforeClass(org.junit.BeforeClass)

Example 19 with IRODSFileFactory

use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.

the class RuleDeploymentServiceImpl method deployRule.

@Override
public void deployRule(MultipartFile file) throws DataGridException, JargonException {
    logger.info("Deploying rule");
    if (file == null) {
        logger.error("File could not be sent to the data grid. Rule file is null.");
        throw new DataGridException("Rule file is null.");
    }
    if (!ruleCacheExists()) {
        logger.info("Rule cache does not exist. Creating one.");
        createRuleCache();
    }
    InputStream inputStream;
    try {
        inputStream = file.getInputStream();
    } catch (IOException e) {
        logger.error("Could not get input stream from rule file: ", e.getMessage());
        throw new DataGridException("Could not get input stream from ruleFile.");
    }
    // Getting DataObjectAO in order to create the new rule file
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    Stream2StreamAO stream2StreamA0 = irodsServices.getStream2StreamAO();
    IRODSFile targetFile = null;
    try {
        String ruleCacheDirPath = getRuleCachePath();
        String ruleName = file.getOriginalFilename().isEmpty() ? file.getName() : file.getOriginalFilename();
        targetFile = irodsFileFactory.instanceIRODSFile(ruleCacheDirPath, ruleName);
        stream2StreamA0.transferStreamToFileUsingIOStreams(inputStream, (File) targetFile, 0, BUFFER_SIZE);
        String resourceName = irodsServices.getDefaultStorageResource();
        Resource resc = irodsServices.getResourceAO().findByName(resourceName);
        String vaultPath = resc.getVaultPath();
        String host = resc.getLocation();
        String ruleVaultPath = String.format("%s/%s/%s", vaultPath, RULE_CACHE_DIR_NAME, ruleName);
        String ruleNameWithoutExtension = FilenameUtils.removeExtension(ruleName);
        ruleService.execDeploymentRule(host, ruleNameWithoutExtension, ruleVaultPath);
    } catch (JargonException e) {
        if (targetFile != null)
            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.");
    } finally {
        try {
            // Closing streams opened
            inputStream.close();
        } catch (IOException e) {
            logger.error("Could close stream: ", e.getMessage());
        }
    }
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) InputStream(java.io.InputStream) Stream2StreamAO(org.irods.jargon.core.pub.Stream2StreamAO) JargonException(org.irods.jargon.core.exception.JargonException) Resource(org.irods.jargon.core.pub.domain.Resource) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Example 20 with IRODSFileFactory

use of org.irods.jargon.core.pub.io.IRODSFileFactory in project metalnx-web by irods-contrib.

the class TicketClientServiceImpl method transferFileToIRODSUsingTicket.

@Override
public void transferFileToIRODSUsingTicket(String ticketString, File localFile, String destPath) throws DataGridTicketUploadException, DataGridTicketInvalidUserException {
    if (ticketString == null || ticketString.isEmpty()) {
        throw new DataGridTicketUploadException("Ticket String not provided");
    } else if (destPath == null || destPath.isEmpty()) {
        throw new DataGridTicketUploadException("Ticket path not provided");
    } else if (localFile == null) {
        throw new DataGridTicketUploadException("File not provided");
    }
    try {
        setUpAccess();
        IRODSFileFactory irodsFileFactory = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount);
        String targetPath = String.format("%s/%s", destPath, localFile.getName());
        IRODSFile targetFile = irodsFileFactory.instanceIRODSFile(targetPath);
        ticketClientOperations.putFileToIRODSUsingTicket(ticketString, localFile, targetFile, null, null);
    } catch (InvalidUserException e) {
        logger.error("Invalid user. Cannot download files as anonymous.");
        throw new DataGridTicketInvalidUserException("Invalid user anonymous");
    } catch (OverwriteException | DuplicateDataException e) {
        logger.error("Could not transfer file to the grid. File already exists: {}", e);
        throw new DataGridTicketUploadException("File already exists");
    } catch (CatNoAccessException e) {
        logger.error("Could not transfer file to the grid. Cat no access: {}", e);
        throw new DataGridTicketUploadException(e.getMessage());
    } catch (DataNotFoundException e) {
        logger.error("Could not transfer file to the grid. File not found: {}", e);
        throw new DataGridTicketUploadException("File not found");
    } catch (JargonException e) {
        logger.error("Could not transfer file to the grid using a ticket: {}", e);
        int code = e.getUnderlyingIRODSExceptionCode();
        String msg = "Transfer failed";
        if (ticketErroCodeMap.containsKey(code)) {
            msg = ticketErroCodeMap.get(code);
        }
        throw new DataGridTicketUploadException(msg);
    } finally {
        closeAccess();
        FileUtils.deleteQuietly(localFile);
    }
}
Also used : DataGridTicketUploadException(com.emc.metalnx.core.domain.exceptions.DataGridTicketUploadException) IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridTicketInvalidUserException(com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridTicketInvalidUserException(com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException)

Aggregations

IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)23 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)23 JargonException (org.irods.jargon.core.exception.JargonException)17 CollectionAO (org.irods.jargon.core.pub.CollectionAO)7 IRODSFileSystemAO (org.irods.jargon.core.pub.IRODSFileSystemAO)7 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)6 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)6 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)4 IOException (java.io.IOException)4 DataTransferOperations (org.irods.jargon.core.pub.DataTransferOperations)4 File (java.io.File)3 DataGridChecksumException (com.emc.metalnx.core.domain.exceptions.DataGridChecksumException)2 DataGridTicketInvalidUserException (com.emc.metalnx.core.domain.exceptions.DataGridTicketInvalidUserException)2 InputStream (java.io.InputStream)2 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)2 Stream2StreamAO (org.irods.jargon.core.pub.Stream2StreamAO)2 IRODSFileInputStream (org.irods.jargon.core.pub.io.IRODSFileInputStream)2 IRODSTestSetupUtilities (org.irods.jargon.testutils.IRODSTestSetupUtilities)2 TestingPropertiesHelper (org.irods.jargon.testutils.TestingPropertiesHelper)2 ScratchFileUtils (org.irods.jargon.testutils.filemanip.ScratchFileUtils)2