Search in sources :

Example 1 with NFSShareACL

use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.

the class FileDeviceController method makeNfsAceFromDB.

/**
 * Convert list of NfsACE to list of DB object for ACL
 *
 * @param nfsAcls
 *            list of the NfsACE object
 * @param dbNfsAclTemp
 *            converted DB object List
 */
private void makeNfsAceFromDB(List<NfsACE> nfsAcls, List<NFSShareACL> dbNfsAclTemp) {
    for (NFSShareACL nfsShareACL : dbNfsAclTemp) {
        NfsACE nfsAce = new NfsACE();
        String permission = nfsShareACL.getPermissions();
        if (permission != null && !permission.isEmpty()) {
            nfsAce.setPermissions(permission);
        }
        String domain = nfsShareACL.getDomain();
        if (domain != null && !domain.isEmpty()) {
            nfsAce.setDomain(domain);
        }
        String permissionType = nfsShareACL.getPermissionType();
        nfsAce.setPermissionType(FileControllerConstants.NFS_FILE_PERMISSION_TYPE_ALLOW);
        if (permissionType != null && !permissionType.isEmpty()) {
            nfsAce.setPermissionType(permissionType);
        }
        String type = nfsShareACL.getType();
        if (type != null && !type.isEmpty()) {
            nfsAce.setType(type);
        }
        String user = nfsShareACL.getUser();
        if (user != null && !user.isEmpty()) {
            nfsAce.setUser(user);
        }
        nfsAcls.add(nfsAce);
    }
}
Also used : NfsACE(com.emc.storageos.model.file.NfsACE) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL)

Example 2 with NFSShareACL

use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.

the class FileDeviceController method deleteNFSAcls.

@Override
public void deleteNFSAcls(URI storage, URI fsURI, String subDir, String opId) throws InternalException {
    ControllerUtils.setThreadLocalLogData(fsURI, opId);
    FileObject fsObj = null;
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    FileShare fs = null;
    Snapshot snapshotObj = null;
    boolean isFile = false;
    try {
        StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        args.setSubDirectory(subDir);
        _log.info("FileDeviceController::deleteNFSAcls Recieved Nfs ACL DELETE Operation ");
        // File
        if (URIUtil.isType(fsURI, FileShare.class)) {
            isFile = true;
            fs = _dbClient.queryObject(FileShare.class, fsURI);
            fsObj = fs;
            args.addFSFileObject(fs);
            args.setFileSystemPath(fs.getPath());
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
        } else {
            // Snapshot
            snapshotObj = _dbClient.queryObject(Snapshot.class, fsURI);
            fsObj = snapshotObj;
            fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            args.addFileShare(fs);
            args.setFileSystemPath(fs.getPath());
            args.addSnapshotFileObject(snapshotObj);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
        }
        args.setFileOperation(isFile);
        args.setOpId(opId);
        List<NfsACE> aceDeleteList = new ArrayList<NfsACE>();
        List<NFSShareACL> dbNfsAclTemp = queryAllNfsACLInDB(fs, subDir, args);
        makeNfsAceFromDB(aceDeleteList, dbNfsAclTemp);
        args.setNfsAclsToDelete(aceDeleteList);
        // Do the Operation on device.
        BiosCommandResult result = getDevice(storageObj.getSystemType()).deleteNfsACLs(storageObj, args);
        if (result.isCommandSuccess()) {
            // Update Database
            if (!dbNfsAclTemp.isEmpty()) {
                for (NFSShareACL nfsShareACL : dbNfsAclTemp) {
                    nfsShareACL.setInactive(true);
                }
                _dbClient.updateObject(dbNfsAclTemp);
            }
        }
        if (result.getCommandPending()) {
            return;
        }
        // Audit & Update the task status
        OperationTypeEnum auditType = null;
        auditType = (isFile) ? OperationTypeEnum.DELETE_FILE_SYSTEM_NFS_ACL : OperationTypeEnum.DELETE_FILE_SNAPSHOT_NFS_ACL;
        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
        // Monitoring - Event Processing
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        if (isFile) {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), fs, storageObj);
        } else {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, args.getFileSystemPath(), snapshotObj, fs, storageObj);
        }
        _dbClient.updateObject(fsObj);
    } catch (Exception e) {
        String[] params = { storage.toString(), fsURI.toString() };
        _log.error("Unable to Delete  ACL on  file system or snapshot: storage {}, FS/snapshot URI {}", params, e);
        _log.error("{}, {} ", e.getMessage(), e);
        updateTaskStatus(opId, fsObj, e);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) NfsACE(com.emc.storageos.model.file.NfsACE) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) ArrayList(java.util.ArrayList) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileObject(com.emc.storageos.db.client.model.FileObject) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 3 with NFSShareACL

use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.

the class FileDeviceController method updateNFSACLsInDB.

/**
 * Update the DB object, this method need to be called after the success of
 * back end command
 *
 * @param param
 *            object of NfsACLUpdateParams
 * @param fs
 *            FileShare object
 * @param args
 *            FileDeviceInputOutput object
 */
private void updateNFSACLsInDB(NfsACLUpdateParams param, FileShare fs, FileDeviceInputOutput args) {
    try {
        // Create new Acls
        List<NfsACE> aceAdd = param.getAcesToAdd();
        if (aceAdd != null && !aceAdd.isEmpty()) {
            for (NfsACE ace : aceAdd) {
                NFSShareACL dbNfsAcl = new NFSShareACL();
                dbNfsAcl.setId(URIUtil.createId(NFSShareACL.class));
                copyToPersistNfsACL(ace, dbNfsAcl, fs, args);
                _log.info("Storing new acl in DB: {}", dbNfsAcl);
                _dbClient.createObject(dbNfsAcl);
            }
        }
        // Modify existing acls
        List<NfsACE> aceModify = param.getAcesToModify();
        if (aceModify != null && !aceModify.isEmpty()) {
            for (NfsACE ace : aceModify) {
                NFSShareACL dbNfsAcl = new NFSShareACL();
                copyToPersistNfsACL(ace, dbNfsAcl, fs, args);
                NFSShareACL dbNfsAclTemp = getExistingNfsAclFromDB(dbNfsAcl, args.getFileOperation());
                if (dbNfsAclTemp != null) {
                    dbNfsAcl.setId(dbNfsAclTemp.getId());
                    _log.info("Modifying acl in DB: {}", dbNfsAcl);
                    _dbClient.updateObject(dbNfsAcl);
                }
            }
        }
        List<NfsACE> aceDelete = param.getAcesToDelete();
        if (aceDelete != null && !aceDelete.isEmpty()) {
            for (NfsACE ace : aceDelete) {
                NFSShareACL dbNfsAcl = new NFSShareACL();
                copyToPersistNfsACL(ace, dbNfsAcl, fs, args);
                NFSShareACL dbNfsAclTemp = getExistingNfsAclFromDB(dbNfsAcl, args.getFileOperation());
                if (dbNfsAclTemp != null) {
                    dbNfsAcl.setId(dbNfsAclTemp.getId());
                    dbNfsAcl.setInactive(true);
                    _log.info("Marking acl inactive in DB: {}", dbNfsAcl);
                    _dbClient.updateObject(dbNfsAcl);
                }
            }
        }
    } catch (Exception e) {
        _log.error("Error While executing CRUD Operations {}", e);
    }
}
Also used : NfsACE(com.emc.storageos.model.file.NfsACE) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 4 with NFSShareACL

use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.

the class FileDeviceController method getExistingNfsAclFromDB.

/**
 * Get the DB object to modify it
 *
 * @param dbShareAcl
 *            the DB object which need to be searched
 * @param isFile
 *            it is file or snapshot operation
 * @return
 */
private NFSShareACL getExistingNfsAclFromDB(NFSShareACL dbShareAcl, boolean isFile) {
    NFSShareACL acl = null;
    String index = null;
    URIQueryResultList result = new URIQueryResultList();
    if (isFile) {
        index = dbShareAcl.getFileSystemNfsACLIndex();
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileSystemNfsACLConstraint(index), result);
    } else {
        index = dbShareAcl.getSnapshotNfsACLIndex();
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotNfsACLConstraint(index), result);
    }
    Iterator<URI> it = result.iterator();
    while (it.hasNext()) {
        acl = _dbClient.queryObject(NFSShareACL.class, it.next());
        if (acl != null && !acl.getInactive()) {
            _log.info("Existing ACE found in DB: {}", acl);
            return acl;
        }
    }
    return null;
}
Also used : URI(java.net.URI) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 5 with NFSShareACL

use of com.emc.storageos.db.client.model.NFSShareACL in project coprhd-controller by CoprHD.

the class FileDeviceController method queryAllNfsACLInDB.

/**
 * To get all the ACLs of File System or a mention subDir.
 *
 * @param fs
 *            File System
 * @param subDir
 *            Sub directory
 * @return List of NFS ACL present in DB.
 */
private List<NFSShareACL> queryAllNfsACLInDB(FileShare fs, String subDir, FileDeviceInputOutput args) {
    List<NFSShareACL> allNfsShareAcl = null;
    List<NFSShareACL> returnNfsShareAcl = null;
    List<NFSShareACL> fsNfsShareAcl = new ArrayList<NFSShareACL>();
    List<NFSShareACL> subDirNfsShareAcl = new ArrayList<NFSShareACL>();
    _log.info("Querying all Nfs File System ACL Using FsId {}", fs.getId());
    try {
        ContainmentConstraint containmentConstraint = null;
        if (args.getFileOperation()) {
            containmentConstraint = ContainmentConstraint.Factory.getFileNfsAclsConstraint(fs.getId());
        } else {
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotNfsAclsConstraint(args.getSnapshotId());
        }
        allNfsShareAcl = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, NFSShareACL.class, containmentConstraint);
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    returnNfsShareAcl = fsNfsShareAcl;
    String absolutefsPath = fs.getPath();
    String absoluteDirPath = "";
    if (subDir != null && !subDir.isEmpty()) {
        absoluteDirPath = absolutefsPath + "/" + subDir;
        returnNfsShareAcl = subDirNfsShareAcl;
    }
    for (NFSShareACL nfsAcl : allNfsShareAcl) {
        if (nfsAcl.getFileSystemPath().equals(absoluteDirPath)) {
            subDirNfsShareAcl.add(nfsAcl);
        } else if (nfsAcl.getFileSystemPath().equals(absolutefsPath)) {
            fsNfsShareAcl.add(nfsAcl);
        }
    }
    return returnNfsShareAcl;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

NFSShareACL (com.emc.storageos.db.client.model.NFSShareACL)11 NfsACE (com.emc.storageos.model.file.NfsACE)6 ArrayList (java.util.ArrayList)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)3 ControllerException (com.emc.storageos.volumecontroller.ControllerException)3 WorkflowException (com.emc.storageos.workflow.WorkflowException)3 URISyntaxException (java.net.URISyntaxException)3 HashMap (java.util.HashMap)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 StoragePool (com.emc.storageos.db.client.model.StoragePool)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 UnManagedNFSShareACL (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedNFSShareACL)2 URI (java.net.URI)2 List (java.util.List)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1