Search in sources :

Example 16 with DataGridException

use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method createCollection.

@Override
public boolean createCollection(DataGridCollectionAndDataObject collection) throws DataGridException {
    logger.info("createCollection()");
    boolean collCreated;
    try {
        IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        IRODSFile newFile = irodsFileFactory.instanceIRODSFile(collection.getParentPath(), collection.getName());
        irodsFileSystemAO.mkdir(newFile, false);
        // Updating inheritance option on the collection, if needed
        CollectionAO collectionAO = irodsServices.getCollectionAO();
        String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
        // enable inheritance for this collection
        if (collection.isInheritanceOption()) {
            collectionAO.setAccessPermissionInherit(zoneName, collection.getPath(), false);
        } else // disable inheritance for this collection
        if ("own".equals(getPermissionsForPath(collection.getParentPath()))) {
            collectionAO.setAccessPermissionToNotInherit(zoneName, collection.getPath(), false);
        }
        collCreated = true;
    } catch (JargonException e) {
        logger.debug("Could not create a collection in the data grid: {}", e.getMessage());
        throw new DataGridException(e.getMessage());
    }
    return collCreated;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) 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 DataGridException

use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.

the class GroupServiceImpl method updateWritePermissions.

@Override
public boolean updateWritePermissions(DataGridGroup group, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
    DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    try {
        for (String path : addCollectionsToWrite.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.setAccessPermissionWriteAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), addCollectionsToWrite.get(path));
            } else {
                dataObjectAO.setAccessPermissionWriteInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        for (String path : removeCollectionsToWrite.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), removeCollectionsToWrite.get(path));
            } else {
                dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        return true;
    } catch (JargonException | DataGridException e) {
        logger.error("Could not set read permission:", e);
    }
    return false;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 18 with DataGridException

use of com.emc.metalnx.core.domain.exceptions.DataGridException in project metalnx-web by irods-contrib.

the class PermissionsServiceImpl method resolveMostPermissiveAccessForUser.

@Override
public void resolveMostPermissiveAccessForUser(DataGridCollectionAndDataObject obj, DataGridUser user) throws DataGridException {
    if (obj == null || user == null)
        return;
    List<UserGroup> userGroups;
    List<UserFilePermission> acl;
    try {
        userGroups = irodsServices.getGroupAO().findUserGroupsForUser(user.getUsername());
        acl = getFilePermissionListForObject(obj.getPath());
    } catch (JargonException e) {
        throw new DataGridException();
    }
    // Building set containing group names for current user
    Set<String> userGroupsSet = new HashSet<>();
    for (UserGroup g : userGroups) {
        userGroupsSet.add(g.getUserGroupName());
    }
    // Instantiating comparison matrix for permissions
    List<String> permissions = new ArrayList<>();
    permissions.add("NONE");
    permissions.add("READ");
    permissions.add("WRITE");
    permissions.add("OWN");
    String resultingPermission = "NONE";
    for (UserFilePermission perm : acl) {
        String permUserName = perm.getUserName();
        // Checking if current permission is related to logged user
        if (permUserName.compareTo(user.getUsername()) == 0 || userGroupsSet.contains(permUserName)) {
            String permissionName = perm.getFilePermissionEnum().name();
            int userOrGroupPerm = permissions.indexOf(permissionName);
            int currentPermission = permissions.indexOf(resultingPermission);
            if (userOrGroupPerm > currentPermission) {
                resultingPermission = permissionName;
            }
        }
        if (resultingPermission.compareToIgnoreCase("OWN") == 0) {
            break;
        }
    }
    obj.setMostPermissiveAccessForCurrentUser(resultingPermission.toLowerCase());
}
Also used : UserFilePermission(org.irods.jargon.core.pub.domain.UserFilePermission) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) UserGroup(org.irods.jargon.core.pub.domain.UserGroup)

Example 19 with DataGridException

use of com.emc.metalnx.core.domain.exceptions.DataGridException 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)

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