Search in sources :

Example 6 with NFSShareACL

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

the class NfsACLUtility method queryDBSFileNfsACLs.

/**
 * Get the list of DB Object for current file System
 *
 * @param allDirs if true function will return complete list of ACL including its SubDir
 * @return list of NFS ACLs
 */
private List<NFSShareACL> queryDBSFileNfsACLs(boolean allDirs) {
    try {
        ContainmentConstraint containmentConstraint = null;
        if (this.fs != null) {
            _log.info("Querying DB for Nfs ACLs of fs{} of filesystemId {} ", this.fs.getPath(), fs.getId());
            containmentConstraint = ContainmentConstraint.Factory.getFileNfsAclsConstraint(this.fs.getId());
        } else {
            // Snapshot
            _log.info("Querying DB for Nfs ACLs of fs {} of snapshotId {} ", this.snapShot.getPath(), this.snapShot.getId());
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotNfsAclsConstraint(this.snapShot.getId());
        }
        List<NFSShareACL> nfsAclList = CustomQueryUtility.queryActiveResourcesByConstraint(this.dbClient, NFSShareACL.class, containmentConstraint);
        if (allDirs) {
            return nfsAclList;
        }
        List<NFSShareACL> rootAclList = new ArrayList<NFSShareACL>();
        List<NFSShareACL> subDirAclList = new ArrayList<NFSShareACL>();
        String absoluteSubdir = "";
        if (this.subDir != null && !this.subDir.isEmpty()) {
            absoluteSubdir = this.fs.getPath() + "/" + subDir;
        }
        for (NFSShareACL nfsAcl : nfsAclList) {
            if (nfsAcl.getFileSystemPath().equals(fs.getPath())) {
                rootAclList.add(nfsAcl);
            }
            if (!absoluteSubdir.isEmpty()) {
                if (nfsAcl.getFileSystemPath().equals(absoluteSubdir)) {
                    subDirAclList.add(nfsAcl);
                }
            }
        }
        if (!absoluteSubdir.isEmpty()) {
            _log.info("Found {} Nfs ACLs for subdir {} ", subDirAclList.size(), this.subDir);
            return subDirAclList;
        }
        _log.info("Found {} Nfs ACLs ", rootAclList.size());
        return rootAclList;
    } catch (Exception e) {
        _log.error("Error while querying DB for ACL of a NFS {}", e);
    }
    return null;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 7 with NFSShareACL

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

the class NfsACLUtility method getNfsAclFromDB.

/**
 * This function return all the ACL in the DB in the format of xml Object
 *
 * @param allDirs if true function will return complete list of ACL including its SubDir
 * @return list of NFS ACLs.
 */
public NfsACLs getNfsAclFromDB(boolean allDirs) {
    NfsACLs acls = new NfsACLs();
    List<NfsACL> nfsAclList = new ArrayList<NfsACL>();
    Map<String, List<NfsACE>> nfsAclMap = new HashMap<String, List<NfsACE>>();
    _log.info("Sub-directory {} and allDirs {}", this.subDir, allDirs);
    // Query All ACl Specific to a File System.
    List<NFSShareACL> nfsAcls = queryDBSFileNfsACLs(allDirs);
    _log.info("Number of existing ACL found : {} ", nfsAcls.size());
    // Group the ACLs based on file system path!!!
    for (NFSShareACL nfsAcl : nfsAcls) {
        String fsPath = nfsAcl.getFileSystemPath();
        List<NfsACE> nfsAceList = nfsAclMap.get(fsPath);
        if (nfsAceList == null) {
            nfsAceList = new ArrayList<NfsACE>();
        }
        NfsACE ace = getNFSAce(nfsAcl);
        nfsAceList.add(ace);
        nfsAclMap.put(fsPath, nfsAceList);
    }
    // Convert all ACE to ACLs!!
    for (Map.Entry<String, List<NfsACE>> pathAcls : nfsAclMap.entrySet()) {
        String mountPath = pathAcls.getKey();
        NfsACL nfsAcl = new NfsACL(mountPath, pathAcls.getValue());
        if (mountPath.length() > fs.getPath().length()) {
            nfsAcl.setSubDir(mountPath.substring(fs.getPath().length() + 1));
        }
        nfsAclList.add(nfsAcl);
    }
    if (!nfsAclList.isEmpty()) {
        acls.setNfsACLs(nfsAclList);
    }
    return acls;
}
Also used : NfsACLs(com.emc.storageos.model.file.NfsACLs) NfsACL(com.emc.storageos.model.file.NfsACL) NfsACE(com.emc.storageos.model.file.NfsACE) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL)

Example 8 with NFSShareACL

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

the class FileOrchestrationUtils method queryNFSACL.

public static Map<String, List<NfsACE>> queryNFSACL(FileShare fs, DbClient dbClient) {
    Map<String, List<NfsACE>> map = new HashMap<String, List<NfsACE>>();
    ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileNfsAclsConstraint(fs.getId());
    List<NFSShareACL> nfsAclList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, NFSShareACL.class, containmentConstraint);
    if (nfsAclList != null) {
        Iterator<NFSShareACL> aclIter = nfsAclList.iterator();
        while (aclIter.hasNext()) {
            NFSShareACL dbNFSAcl = aclIter.next();
            String fsPath = dbNFSAcl.getFileSystemPath();
            NfsACE ace = convertNFSShareACLToNfsACE(dbNFSAcl);
            if (map.get(fsPath) == null) {
                List<NfsACE> acl = new ArrayList<NfsACE>();
                acl.add(ace);
                map.put(fsPath, acl);
            } else {
                map.get(fsPath).add(ace);
            }
        }
    }
    return map;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) NfsACE(com.emc.storageos.model.file.NfsACE) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL)

Example 9 with NFSShareACL

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

the class UnManagedFilesystemService method ingestFileSystems.

/**
 * UnManaged file systems are file systems, which are present within ViPR
 * storage systems,but have not been ingested by ViPR which moves the unmanaged file systems under ViPR management.
 *
 * File system ingest provides flexibility in bringing unmanaged
 * file systems under ViPR management.
 * An unmanaged file system must be associated with a virtual pool, project,
 * and virtual array before it can be managed by ViPR.
 * List of supported virtual pools for each unmanaged file system is exposed using /vdc/unmanaged/filesystems/bulk.
 * Using an unsupported virtual pool results in an error
 *
 * Size of unmanaged file systems which can be ingested via a single API Call
 * is limited to 4000.
 *
 * @param param
 *            parameters required for unmanaged filesystem ingestion
 *
 * @prereq none
 * @brief Ingest unmanaged file systems
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/ingest")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public NamedFileSystemList ingestFileSystems(FileSystemIngest param) throws InternalException {
    if ((null == param.getUnManagedFileSystems()) || (param.getUnManagedFileSystems().toString().length() == 0) || (param.getUnManagedFileSystems().isEmpty()) || (param.getUnManagedFileSystems().get(0).toString().isEmpty())) {
        throw APIException.badRequests.invalidParameterUnManagedFsListEmpty();
    }
    if (null == param.getProject() || (param.getProject().toString().length() == 0)) {
        throw APIException.badRequests.invalidParameterProjectEmpty();
    }
    if (null == param.getVarray() || (param.getVarray().toString().length() == 0)) {
        throw APIException.badRequests.invalidParameterVirtualArrayEmpty();
    }
    if (null == param.getVpool() || (param.getVpool().toString().length() == 0)) {
        throw APIException.badRequests.invalidParameterVirtualPoolEmpty();
    }
    if (param.getUnManagedFileSystems().size() > getMaxBulkSize()) {
        throw APIException.badRequests.exceedingLimit("unmanaged filesystems", getMaxBulkSize());
    }
    _logger.info("Ingest called with Virtual Array {}", param.getVarray());
    _logger.info("Ingest called with Virtual Pool {}", param.getVpool());
    _logger.info("Ingest called with Project {}", param.getProject());
    _logger.info("Ingest called with UnManagedFileSystems {}", param.getUnManagedFileSystems());
    NamedFileSystemList filesystemList = new NamedFileSystemList();
    List<UnManagedFileSystem> unManagedFileSystems = new ArrayList<UnManagedFileSystem>();
    try {
        // Get and validate the project.
        Project project = _permissionsHelper.getObjectById(param.getProject(), Project.class);
        ArgValidator.checkUri(param.getProject());
        ArgValidator.checkEntity(project, param.getProject(), false);
        VirtualArray neighborhood = FileSystemIngestionUtil.getVirtualArrayForFileSystemCreateRequest(project, param.getVarray(), _permissionsHelper, _dbClient);
        // Get and validate the VirtualPool.
        VirtualPool cos = FileSystemIngestionUtil.getVirtualPoolForFileSystemCreateRequest(project, param.getVpool(), _permissionsHelper, _dbClient);
        if (null != cos.getVirtualArrays() && !cos.getVirtualArrays().isEmpty() && !cos.getVirtualArrays().contains(param.getVarray().toString())) {
            throw APIException.internalServerErrors.virtualPoolNotMatchingVArray(param.getVarray());
        }
        // check for Quotas
        long unManagedFileSystemsCapacity = FileSystemIngestionUtil.getTotalUnManagedFileSystemCapacity(_dbClient, param.getUnManagedFileSystems());
        _logger.info("Requested UnManagedFile System Capacity {}", unManagedFileSystemsCapacity);
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
        CapacityUtils.validateQuotasForProvisioning(_dbClient, cos, project, tenant, unManagedFileSystemsCapacity, "filesystem");
        FileSystemIngestionUtil.isIngestionRequestValidForUnManagedFileSystems(param.getUnManagedFileSystems(), cos, _dbClient);
        List<FileShare> filesystems = new ArrayList<FileShare>();
        Map<URI, FileShare> unManagedFSURIToFSMap = new HashMap<>();
        List<FileExportRule> fsExportRules = new ArrayList<FileExportRule>();
        List<CifsShareACL> fsCifsShareAcls = new ArrayList<CifsShareACL>();
        List<NFSShareACL> fsNfsShareAcls = new ArrayList<NFSShareACL>();
        List<UnManagedFileExportRule> inActiveUnManagedExportRules = new ArrayList<UnManagedFileExportRule>();
        List<UnManagedCifsShareACL> inActiveUnManagedShareCifs = new ArrayList<UnManagedCifsShareACL>();
        List<UnManagedNFSShareACL> inActiveUnManagedShareNfs = new ArrayList<UnManagedNFSShareACL>();
        // cifs share acl's
        List<CifsShareACL> cifsShareACLList = new ArrayList<CifsShareACL>();
        List<URI> full_pools = new ArrayList<URI>();
        List<URI> full_systems = new ArrayList<URI>();
        Calendar timeNow = Calendar.getInstance();
        for (URI unManagedFileSystemUri : param.getUnManagedFileSystems()) {
            long softLimit = 0;
            int softGrace = 0;
            long notificationLimit = 0;
            UnManagedFileSystem unManagedFileSystem = _dbClient.queryObject(UnManagedFileSystem.class, unManagedFileSystemUri);
            if (null == unManagedFileSystem || null == unManagedFileSystem.getFileSystemCharacterstics() || null == unManagedFileSystem.getFileSystemInformation()) {
                _logger.warn("UnManaged FileSystem {} partially discovered, hence not enough information available to validate neither virtualPool nor other criterias.Skipping Ingestion..", unManagedFileSystemUri);
                continue;
            }
            if (unManagedFileSystem.getInactive()) {
                _logger.warn("UnManaged FileSystem {} is inactive.Skipping Ingestion..", unManagedFileSystemUri);
                continue;
            }
            if (!FileSystemIngestionUtil.checkVirtualPoolValidForUnManagedFileSystem(_dbClient, cos, unManagedFileSystemUri)) {
                continue;
            }
            StringSetMap unManagedFileSystemInformation = unManagedFileSystem.getFileSystemInformation();
            String fsNativeGuid = unManagedFileSystem.getNativeGuid().replace(FileSystemIngestionUtil.UNMANAGEDFILESYSTEM, FileSystemIngestionUtil.FILESYSTEM);
            String deviceLabel = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.DEVICE_LABEL.toString(), unManagedFileSystemInformation);
            String fsName = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.NAME.toString(), unManagedFileSystemInformation);
            URI storagePoolUri = unManagedFileSystem.getStoragePoolUri();
            String storagePortUri = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.STORAGE_PORT.toString(), unManagedFileSystemInformation);
            String capacity = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.PROVISIONED_CAPACITY.toString(), unManagedFileSystemInformation);
            String usedCapacity = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.ALLOCATED_CAPACITY.toString(), unManagedFileSystemInformation);
            String nasUri = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.NAS.toString(), unManagedFileSystemInformation);
            String path = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.PATH.toString(), unManagedFileSystemInformation);
            String mountPath = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.MOUNT_PATH.toString(), unManagedFileSystemInformation);
            String nativeId = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.NATIVE_ID.toString(), unManagedFileSystemInformation);
            String systemType = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.SYSTEM_TYPE.toString(), unManagedFileSystemInformation);
            String softLt = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.SOFT_LIMIT.toString(), unManagedFileSystemInformation);
            String softGr = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.SOFT_GRACE.toString(), unManagedFileSystemInformation);
            String notificationLt = PropertySetterUtil.extractValueFromStringSet(SupportedFileSystemInformation.NOTIFICATION_LIMIT.toString(), unManagedFileSystemInformation);
            if (null != softLt && !softLt.isEmpty()) {
                softLimit = Long.valueOf(softLt);
            }
            if (null != softGr && !softGr.isEmpty()) {
                softGrace = Integer.valueOf(softGr);
            }
            if (null != notificationLt && !notificationLt.isEmpty()) {
                notificationLimit = Long.valueOf(notificationLt);
            }
            Long lcapcity = Long.valueOf(capacity);
            Long lusedCapacity = Long.valueOf(usedCapacity);
            // pool uri cannot be null
            StoragePool pool = _dbClient.queryObject(StoragePool.class, storagePoolUri);
            StoragePort port = null;
            if (storagePortUri != null) {
                port = _dbClient.queryObject(StoragePort.class, URI.create(storagePortUri));
            }
            StorageHADomain dataMover = null;
            if (port != null && port.getStorageHADomain() != null) {
                dataMover = _dbClient.queryObject(StorageHADomain.class, port.getStorageHADomain());
            }
            if (dataMover != null) {
                _logger.info("Data Mover to Use {} {} {}", new Object[] { dataMover.getAdapterName(), dataMover.getName(), dataMover.getLabel() });
            }
            // Check for same name File Share in this project
            if (FileSystemIngestionUtil.checkForDuplicateFSName(_dbClient, project.getId(), deviceLabel, filesystems)) {
                _logger.info("File System with name: {}  already exists in the given project: {} so, ignoring it..", deviceLabel, project.getLabel());
                continue;
            }
            // check ingestion is valid for given project
            if (!isIngestUmfsValidForProject(project, _dbClient, nasUri)) {
                _logger.info("UnManaged FileSystem path {} is mounted on vNAS URI {} which is invalid for project.", path, nasUri);
                continue;
            }
            // Check for same named File Share in this project
            if (FileSystemIngestionUtil.checkForDuplicateFSName(_dbClient, project.getId(), deviceLabel, filesystems)) {
                _logger.info("File System with name: {}  already exists in given project: {} so, ignoring it..", deviceLabel, project.getLabel());
                continue;
            }
            // if not don't ingest
            if (null != pool) {
                StringSet taggedVirtualArrays = pool.getTaggedVirtualArrays();
                if ((null == taggedVirtualArrays) || (!taggedVirtualArrays.contains(neighborhood.getId().toString()))) {
                    _logger.warn("UnManaged FileSystem {} storagepool doesn't related to the Virtual Array {}. Skipping Ingestion..", unManagedFileSystemUri, neighborhood.getId().toString());
                    continue;
                }
            } else {
                _logger.warn("UnManaged FileSystem {} doesn't contain a storagepool. Skipping Ingestiong", unManagedFileSystemUri);
                continue;
            }
            if (full_pools.contains(storagePoolUri)) {
                // skip this fileshare
                continue;
            }
            if (pool.getIsResourceLimitSet()) {
                if (pool.getMaxResources() <= StoragePoolService.getNumResources(pool, _dbClient)) {
                    // reached limit for this pool
                    full_pools.add(storagePoolUri);
                    continue;
                }
            }
            FileShare filesystem = new FileShare();
            filesystem.setId(URIUtil.createId(FileShare.class));
            filesystem.setNativeGuid(fsNativeGuid);
            filesystem.setCapacity(lcapcity);
            filesystem.setUsedCapacity(lusedCapacity);
            filesystem.setPath(path);
            filesystem.setMountPath(mountPath);
            filesystem.setVirtualPool(param.getVpool());
            filesystem.setVirtualArray(param.getVarray());
            filesystem.setSoftLimit(softLimit);
            filesystem.setSoftGracePeriod(softGrace);
            filesystem.setNotificationLimit(notificationLimit);
            if (nasUri != null) {
                filesystem.setVirtualNAS(URI.create(nasUri));
                if (!doesNASServerSupportVPoolProtocols(nasUri, cos.getProtocols())) {
                    _logger.warn("UnManaged FileSystem NAS server {} doesn't support vpool protocols. Skipping Ingestion...", nasUri);
                    continue;
                }
            }
            if (nativeId != null) {
                filesystem.setNativeId(nativeId);
            }
            URI storageSystemUri = unManagedFileSystem.getStorageSystemUri();
            StorageSystem system = _dbClient.queryObject(StorageSystem.class, storageSystemUri);
            if (full_systems.contains(storageSystemUri)) {
                // skip this fileshare
                continue;
            }
            if (system.getIsResourceLimitSet()) {
                if (system.getMaxResources() <= StorageSystemService.getNumResources(system, _dbClient)) {
                    // reached limit for this system
                    full_systems.add(storageSystemUri);
                    continue;
                }
            }
            filesystem.setStorageDevice(storageSystemUri);
            filesystem.setCreationTime(timeNow);
            filesystem.setPool(storagePoolUri);
            filesystem.setProtocol(new StringSet());
            StringSet fsSupportedProtocols = new StringSet();
            for (StorageProtocol.File fileProtocol : StorageProtocol.File.values()) {
                fsSupportedProtocols.add(fileProtocol.name());
            }
            // fs support protocol which is present in StoragePool and VirtualPool both
            fsSupportedProtocols.retainAll(pool.getProtocols());
            fsSupportedProtocols.retainAll(cos.getProtocols());
            filesystem.getProtocol().addAll(fsSupportedProtocols);
            filesystem.setLabel(null == deviceLabel ? "" : deviceLabel);
            filesystem.setName(null == fsName ? "" : fsName);
            filesystem.setTenant(new NamedURI(project.getTenantOrg().getURI(), filesystem.getLabel()));
            filesystem.setProject(new NamedURI(param.getProject(), filesystem.getLabel()));
            _logger.info("Un Managed File System {} has exports? : {}", unManagedFileSystem.getId(), unManagedFileSystem.getHasExports());
            StoragePort sPort = null;
            if (port != null && neighborhood != null) {
                if (StorageSystem.Type.isilon.toString().equals(system.getSystemType())) {
                    sPort = getIsilonStoragePort(port, nasUri, neighborhood.getId());
                } else {
                    sPort = compareAndSelectPortURIForUMFS(system, port, neighborhood);
                }
            }
            /*
                 * If UMFS storage port is not part of the vArray then skip ingestion
                 */
            if (sPort == null) {
                _logger.warn("Storage port of UMFS {} doesn't belong to a matching NetWork. So skipping ingestion", unManagedFileSystemUri);
                continue;
            }
            _logger.info("Storage Port Found {}", sPort);
            filesystem.setPortName(sPort.getPortName());
            filesystem.setStoragePort(sPort.getId());
            if (unManagedFileSystem.getHasExports()) {
                filesystem.setFsExports(PropertySetterUtil.convertUnManagedExportMapToManaged(unManagedFileSystem.getFsUnManagedExportMap(), sPort, dataMover));
                _logger.info("Export map for {} = {}", fsName, filesystem.getFsExports());
                // Process Exports
                // Step 1 : Query them and Retrive associated Exports
                List<UnManagedFileExportRule> exports = queryDBFSExports(unManagedFileSystem);
                _logger.info("Number of Exports Found : {} for UnManaged Fs path : {}", exports.size(), unManagedFileSystem.getMountPath());
                if (exports != null && !exports.isEmpty()) {
                    for (UnManagedFileExportRule rule : exports) {
                        // Step 2 : Convert them to File Export Rule
                        // Step 3 : Keep them as a list to store in db, down the line at a shot
                        // Important to relate the exports to a
                        rule.setFileSystemId(filesystem.getId());
                        // FileSystem.
                        createRule(rule, fsExportRules);
                        // Step 4: Update the UnManaged Exports : Set Inactive as true
                        rule.setInactive(true);
                        // Step 5 : Keep this list as updated.
                        inActiveUnManagedExportRules.add(rule);
                    }
                }
            }
            if (unManagedFileSystem.getHasShares()) {
                filesystem.setSMBFileShares(PropertySetterUtil.convertUnManagedSMBMapToManaged(unManagedFileSystem.getUnManagedSmbShareMap(), sPort, dataMover));
                _logger.info("Share map for {} = {}", fsName, filesystem.getSMBFileShares());
                // Process Exports
                // Step 1 : Query them and Retrive associated Exports
                List<UnManagedCifsShareACL> cifsACLs = queryDBCifsShares(unManagedFileSystem);
                _logger.info("Number of Cifs ACL Found : {} for UnManaged Fs path : {}", cifsACLs.size(), unManagedFileSystem.getMountPath());
                if (cifsACLs != null && !cifsACLs.isEmpty()) {
                    for (UnManagedCifsShareACL umCifsAcl : cifsACLs) {
                        // Step 2 : Convert them to Cifs Share ACL
                        // Step 3 : Keep them as a list to store in db, down the line at a shot
                        // Important to relate the shares to a
                        umCifsAcl.setFileSystemId(filesystem.getId());
                        // FileSystem.
                        createACL(umCifsAcl, fsCifsShareAcls, filesystem);
                        // Step 4: Update the UnManaged Share ACL : Set Inactive as true
                        umCifsAcl.setInactive(true);
                        // Step 5 : Keep this list as updated.
                        inActiveUnManagedShareCifs.add(umCifsAcl);
                    }
                }
            }
            if (unManagedFileSystem.getHasNFSAcl()) {
                List<UnManagedNFSShareACL> nfsACLs = queryDBNfsShares(unManagedFileSystem);
                if (nfsACLs != null && !nfsACLs.isEmpty()) {
                    for (UnManagedNFSShareACL umNfsAcl : nfsACLs) {
                        // Step 2 : Convert them to nfs Share ACL
                        // Step 3 : Keep them as a list to store in db, down the line at a shot
                        // Important to relate the shares to a
                        umNfsAcl.setFileSystemId(filesystem.getId());
                        // FileSystem.
                        if (umNfsAcl.getPermissions().isEmpty()) {
                            continue;
                        }
                        createNFSACL(umNfsAcl, fsNfsShareAcls, filesystem);
                        // Step 4: Update the UnManaged Share ACL : Set Inactive as true
                        umNfsAcl.setInactive(true);
                        // Step 5 : Keep this list as updated.
                        inActiveUnManagedShareNfs.add(umNfsAcl);
                    }
                }
            }
            // Set quota
            if (null != unManagedFileSystem.getExtensions() && null != unManagedFileSystem.getExtensions().get(QUOTA)) {
                if (null == filesystem.getExtensions()) {
                    filesystem.setExtensions(new StringMap());
                }
                filesystem.getExtensions().put(QUOTA, unManagedFileSystem.getExtensions().get(QUOTA));
            }
            filesystems.add(PropertySetterUtil.addFileSystemDetails(unManagedFileSystemInformation, filesystem));
            // Process Export Rules for the validated FS.
            filesystemList.getFilesystems().add(toNamedRelatedResource(ResourceTypeEnum.FILE, filesystem.getId(), filesystem.getNativeGuid()));
            unManagedFileSystem.setInactive(true);
            unManagedFileSystems.add(unManagedFileSystem);
            unManagedFSURIToFSMap.put(unManagedFileSystemUri, filesystem);
        }
        int i = 0;
        // Test
        for (FileShare fs : filesystems) {
            ++i;
            _logger.info("{} --> Saving FS to DB {}", i, fs);
            _logger.info(" --> Fs  Storage Pool {} and Virtual Pool {}", fs.getPool(), fs.getVirtualPool());
        }
        _dbClient.createObject(filesystems);
        for (URI unManagedFSURI : param.getUnManagedFileSystems()) {
            FileShare fs = unManagedFSURIToFSMap.get(unManagedFSURI);
            if (fs != null) {
                _logger.debug("ingesting quota directories for filesystem {}", fs.getId());
                ingestFileQuotaDirectories(fs);
            }
        }
        i = 0;
        // Test
        for (FileExportRule rule : fsExportRules) {
            ++i;
            _logger.info("{} --> Saving Export rule to DB {}", i, rule);
        }
        // Step 6.1 : Update the same in DB & Add new export rules
        _dbClient.createObject(fsExportRules);
        // Step 6.2 : Update Cifs Acls in DB & Add new ACLs
        i = 0;
        for (CifsShareACL acl : fsCifsShareAcls) {
            ++i;
            _logger.info("{} --> Saving New Cifs ACL to DB {}", i, acl);
        }
        if (fsCifsShareAcls != null && !fsCifsShareAcls.isEmpty()) {
            _dbClient.createObject(fsCifsShareAcls);
        }
        // Step 7.1 : Update the same in DB & clean ingested UnManagedCifsACLs
        i = 0;
        for (UnManagedCifsShareACL acl : inActiveUnManagedShareCifs) {
            ++i;
            _logger.info("{} Updating UnManagedACL DB as InActive TRUE {}", acl);
        }
        _dbClient.updateObject(inActiveUnManagedShareCifs);
        // Step 7.2 : Update the same in DB & clean Unmanaged ExportRule
        i = 0;
        for (UnManagedFileExportRule rule : inActiveUnManagedExportRules) {
            ++i;
            _logger.info("{} Updating DB as InActive TRUE {}", rule);
        }
        _dbClient.updateObject(inActiveUnManagedExportRules);
        _dbClient.updateObject(unManagedFileSystems);
        // Step 8.1 : Update NFS Acls in DB & Add new ACLs
        if (fsNfsShareAcls != null && !fsNfsShareAcls.isEmpty()) {
            _logger.info("Saving {} NFS ACLs to DB", fsNfsShareAcls.size());
            _dbClient.createObject(fsNfsShareAcls);
        }
        // UnManagedNFSShareACLs
        if (inActiveUnManagedShareNfs != null && !inActiveUnManagedShareNfs.isEmpty()) {
            _logger.info("Saving {} UnManagedNFS ACLs to DB", inActiveUnManagedShareNfs.size());
            _dbClient.updateObject(inActiveUnManagedShareNfs);
        }
        // record the events after they have been created
        for (FileShare filesystem : filesystems) {
            recordFileSystemOperation(_dbClient, OperationTypeEnum.INGEST_FILE_SYSTEM, Status.ready, filesystem.getId());
        }
    } catch (InternalException e) {
        throw e;
    } catch (Exception e) {
        _logger.error("Unexpected exception:", e);
        throw APIException.internalServerErrors.genericApisvcError(e.getMessage(), e);
    }
    return filesystemList;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StringMap(com.emc.storageos.db.client.model.StringMap) UnManagedFileExportRule(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule) StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) UnManagedNFSShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedNFSShareACL) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL) UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) UnManagedFileExportRule(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) StringSet(com.emc.storageos.db.client.model.StringSet) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) UnManagedNFSShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedNFSShareACL) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) Calendar(java.util.Calendar) StoragePort(com.emc.storageos.db.client.model.StoragePort) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) IOException(java.io.IOException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) StorageProtocol(com.emc.storageos.db.client.model.StorageProtocol) NamedFileSystemList(com.emc.storageos.model.file.NamedFileSystemList) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with NFSShareACL

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

the class UnManagedFilesystemService method createNFSACL.

/**
 * copy unmanaged nfs share into new nfs share acls
 *
 * @param origACL
 * @param shareACLList
 * @param fileshare
 */
private void createNFSACL(UnManagedNFSShareACL origACL, List<NFSShareACL> shareACLList, FileShare fileshare) {
    NFSShareACL shareACL = new NFSShareACL();
    // user, permission, permission type
    shareACL.setFileSystemPath(origACL.getFileSystemPath());
    shareACL.setDomain(origACL.getDomain());
    shareACL.setType(origACL.getType());
    shareACL.setPermissionType(origACL.getPermissionType());
    String user = origACL.getUser();
    if (user != null) {
        shareACL.setUser(user);
    }
    String aclPermissions = origACL.getPermissions();
    if (!StringUtils.isEmpty(aclPermissions)) {
        StringBuilder permissionText = new StringBuilder();
        boolean isFirstPermissionSet = false;
        for (String tempPermission : aclPermissions.toLowerCase().split(",")) {
            switch(tempPermission) {
                case "read":
                    tempPermission = FileControllerConstants.NFS_FILE_PERMISSION_READ;
                    break;
                case "write":
                    tempPermission = FileControllerConstants.NFS_FILE_PERMISSION_WRITE;
                    break;
                case "execute":
                    tempPermission = FileControllerConstants.NFS_FILE_PERMISSION_EXECUTE;
                    break;
                case "fullcontrol":
                    tempPermission = FileControllerConstants.NFS_FILE_PERMISSION_FULLCONTROL;
                    break;
            }
            if (!isFirstPermissionSet) {
                permissionText.append(tempPermission);
                isFirstPermissionSet = true;
            } else {
                permissionText.append("," + tempPermission);
            }
        }
        shareACL.setPermissions(permissionText.toString());
    } else {
        shareACL.setPermissions("");
    }
    shareACL.setFileSystemId(fileshare.getId());
    shareACL.setId(URIUtil.createId(NFSShareACL.class));
    // Add new acl into ACL list
    shareACLList.add(shareACL);
    _logger.info("share ACLs details {}", shareACL.toString());
}
Also used : NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) UnManagedNFSShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedNFSShareACL)

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