Search in sources :

Example 1 with UnManagedCifsShareACL

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

the class UnManagedFilesystemService method createACL.

/**
 * copy unmanaged cifs share into new cifs share acls
 *
 * @param origACL
 * @param shareACLList
 * @param fileshare
 */
private void createACL(UnManagedCifsShareACL origACL, List<CifsShareACL> shareACLList, FileShare fileshare) {
    CifsShareACL shareACL = null;
    shareACL = new CifsShareACL();
    // user, permission, permission type
    shareACL.setId(URIUtil.createId(CifsShareACL.class));
    String user = origACL.getUser();
    if (user != null) {
        shareACL.setUser(user);
    } else {
        shareACL.setGroup(origACL.getGroup());
    }
    String permissionText = null;
    switch(origACL.getPermission().toLowerCase()) {
        case "read":
            permissionText = FileControllerConstants.CIFS_SHARE_PERMISSION_READ;
            break;
        case "change":
            permissionText = FileControllerConstants.CIFS_SHARE_PERMISSION_CHANGE;
            break;
        case "full":
        case "fullcontrol":
            permissionText = FileControllerConstants.CIFS_SHARE_PERMISSION_FULLCONTROL;
            break;
    }
    shareACL.setPermission(permissionText);
    // share name
    shareACL.setShareName(origACL.getShareName());
    // file system id
    shareACL.setFileSystemId(fileshare.getId());
    // Add new acl into ACL list
    shareACLList.add(shareACL);
    _logger.info("share ACLs details {}", shareACL.toString());
}
Also used : CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL) UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL)

Example 2 with UnManagedCifsShareACL

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

the class UnManagedFilesystemService method copyACLs.

/**
 * copy unmanaged cifs share into new cifs share acls
 *
 * @param origACLList
 * @param shareACLList
 * @param fileshare
 */
private void copyACLs(List<UnManagedCifsShareACL> origACLList, List<CifsShareACL> shareACLList, FileShare fileshare) {
    CifsShareACL shareACL = null;
    for (UnManagedCifsShareACL origACL : origACLList) {
        shareACL = new CifsShareACL();
        // user, permission, permission type
        shareACL.setId(URIUtil.createId(CifsShareACL.class));
        shareACL.setUser(origACL.getUser());
        shareACL.setPermission(origACL.getPermission());
        // share name
        shareACL.setShareName(origACL.getShareName());
        // file system id
        shareACL.setFileSystemId(fileshare.getId());
        // Add new acl into ACL list
        shareACLList.add(shareACL);
        _logger.info("share ACLs details {}", shareACL.toString());
    }
}
Also used : UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL) UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL)

Example 3 with UnManagedCifsShareACL

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

the class UnManagedFilesystemService method queryDBCifsShares.

private List<UnManagedCifsShareACL> queryDBCifsShares(UnManagedFileSystem fs) {
    _logger.info("Querying All Cifs Share ACLs Using FsId {}", fs.getId());
    try {
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getUnManagedCifsShareAclsConstraint(fs.getId());
        List<UnManagedCifsShareACL> cifsShareACLList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, UnManagedCifsShareACL.class, containmentConstraint);
        return cifsShareACLList;
    } catch (Exception e) {
        _logger.error("Error while querying {}", e);
    }
    return new ArrayList<UnManagedCifsShareACL>();
}
Also used : UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) 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)

Example 4 with UnManagedCifsShareACL

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

the class VNXFileCommunicationInterface method applyCifsSecurityRules.

private List<UnManagedCifsShareACL> applyCifsSecurityRules(UnManagedFileSystem vnxufs, String expPath, Map<String, String> fsExportInfo, StoragePort storagePort) {
    List<UnManagedCifsShareACL> cifsACLs = new ArrayList<UnManagedCifsShareACL>();
    UnManagedCifsShareACL unManagedCifsShareACL = new UnManagedCifsShareACL();
    String shareName = fsExportInfo.get(VNXFileConstants.SHARE_NAME);
    unManagedCifsShareACL.setShareName(shareName);
    // user
    unManagedCifsShareACL.setUser(FileControllerConstants.CIFS_SHARE_USER_EVERYONE);
    // permission
    unManagedCifsShareACL.setPermission(FileControllerConstants.CIFS_SHARE_PERMISSION_CHANGE);
    unManagedCifsShareACL.setId(URIUtil.createId(UnManagedCifsShareACL.class));
    // filesystem id
    unManagedCifsShareACL.setFileSystemId(vnxufs.getId());
    cifsACLs.add(unManagedCifsShareACL);
    return cifsACLs;
}
Also used : UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) ArrayList(java.util.ArrayList)

Example 5 with UnManagedCifsShareACL

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

the class VNXFileCommunicationInterface method discoverUnManagedCifsShares.

private void discoverUnManagedCifsShares(AccessProfile profile) {
    // Get Storage System
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    String detailedStatusMessage = "Discovery of VNX Unmanaged Shares started";
    _logger.info(detailedStatusMessage);
    // Used to Save the CIFS ACLs to DB
    List<UnManagedCifsShareACL> newUnManagedCifsACLs = new ArrayList<UnManagedCifsShareACL>();
    List<UnManagedCifsShareACL> oldUnManagedCifsACLs = new ArrayList<UnManagedCifsShareACL>();
    try {
        // Discover port groups (data mover ids) and group names (data mover names)
        Set<StorageHADomain> activeDataMovers = discoverActiveDataMovers(storageSystem);
        // Reused from discoverAll
        // Discover ports (data mover interfaces) with the data movers in the active set.
        Map<String, List<StoragePort>> ports = discoverPorts(storageSystem, activeDataMovers);
        _logger.info("No of newly discovered port {}", ports.get(NEW).size());
        _logger.info("No of existing discovered port {}", ports.get(EXISTING).size());
        if (!ports.get(NEW).isEmpty()) {
            _dbClient.createObject(ports.get(NEW));
        }
        List<StoragePort> allPortsList = ports.get(NEW);
        allPortsList.addAll(ports.get(EXISTING));
        Map<String, List<StoragePort>> allPorts = new ConcurrentHashMap<String, List<StoragePort>>();
        for (StoragePort sPort : allPortsList) {
            _logger.debug("DM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        Map<String, List<StorageHADomain>> allVdms = discoverVdmPortGroups(storageSystem, activeDataMovers);
        if (!allVdms.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdms.get(NEW));
        }
        Set<StorageHADomain> allActiveVDMs = new HashSet();
        allActiveVDMs.addAll(allVdms.get(NEW));
        allActiveVDMs.addAll(allVdms.get(EXISTING));
        activeDataMovers.addAll(allVdms.get(NEW));
        activeDataMovers.addAll(allVdms.get(EXISTING));
        Map<String, List<StoragePort>> allVdmPorts = discoverVdmPorts(storageSystem, allActiveVDMs);
        if (!allVdmPorts.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdmPorts.get(NEW));
        }
        List<StoragePort> allVDMPortsList = allVdmPorts.get(NEW);
        allVDMPortsList.addAll(allVdmPorts.get(EXISTING));
        for (StoragePort sPort : allVDMPortsList) {
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            _logger.debug("VDM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        List<UnManagedFileSystem> unManagedExportBatch = new ArrayList<UnManagedFileSystem>();
        for (StorageHADomain mover : activeDataMovers) {
            // Get storage port and name for the DM
            if (allPorts.get(mover.getId().toString()) == null || allPorts.get(mover.getId().toString()).isEmpty()) {
                // Did not find a single storage port for this DM, ignore it
                _logger.debug("No Ports found for {} {}", mover.getName(), mover.getAdapterName());
                continue;
            } else {
                _logger.debug("Number of  Ports found for {} : {} ", mover.getName() + ":" + mover.getAdapterName(), allPorts.get(mover.getId().toString()).size());
            }
            Collections.shuffle(allPorts.get(mover.getId().toString()));
            StoragePort storagePort = allPorts.get(mover.getId().toString()).get(0);
            if (storagePort == null) {
                // Did not find a single storage port for this DM, ignore it
                _logger.debug("StoragePort is null");
                continue;
            }
            // storagePort.setStorageHADomain(mover.getId());
            // get vnas uri
            URI moverURI = getNASUri(mover, storageSystem);
            // Retrieve FS-mountpath map for the Data Mover.
            _logger.info("Retrieving FS-mountpath map for Data Mover {}.", mover.getAdapterName());
            VNXFileSshApi sshDmApi = new VNXFileSshApi();
            sshDmApi.setConnParams(storageSystem.getIpAddress(), storageSystem.getUsername(), storageSystem.getPassword());
            Map<String, String> fileSystemMountpathMap = sshDmApi.getFsMountpathMap(mover.getAdapterName());
            Map<String, Map<String, String>> moverExportDetails = sshDmApi.getCIFSExportsForPath(mover.getAdapterName());
            Map<String, String> nameIdMap = getFsNameFsNativeIdMap(storageSystem);
            // Loop through the map and, if the file exists in DB, retrieve the
            // export, process export, and associate export with the FS
            Set<String> fsNames = fileSystemMountpathMap.keySet();
            for (String fsName : fsNames) {
                // Retrieve FS from DB. If FS found, retrieve export and process
                String fsMountPath = fileSystemMountpathMap.get(fsName);
                // Get FS ID for nativeGUID
                // VNXFileSystem vnxFileSystems = discoverNamedFileSystem(storageSystem, fsName);
                String fsId = nameIdMap.get(fsName);
                _logger.debug("Resolved FileSystem name {} to native Id {}", fsName, fsId);
                UnManagedFileSystem vnxufs = null;
                if (fsId != null) {
                    String fsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), fsId);
                    vnxufs = checkUnManagedFileSystemExistsInDB(fsNativeGuid);
                }
                if (vnxufs != null) {
                    int noOfShares = 0;
                    // Get export info
                    for (String expPath : moverExportDetails.keySet()) {
                        if (!expPath.contains(fsMountPath)) {
                            // Ignore this path as it is not among the exports
                            continue;
                        } else {
                            // We should process only FS and its sub-directory exports only.
                            String subDir = expPath.substring(fsMountPath.length());
                            if (!subDir.isEmpty() && !subDir.startsWith("/")) {
                                continue;
                            }
                            _logger.info("Path : {} ", expPath);
                        }
                        Map<String, String> fsExportInfo = moverExportDetails.get(expPath);
                        if ((fsExportInfo != null) && (fsExportInfo.size() > 0)) {
                            noOfShares += 1;
                            _logger.info("Associating FS share map for VNX UMFS {}", vnxufs.getLabel());
                            associateCifsExportWithFS(vnxufs, expPath, fsExportInfo, storagePort);
                            vnxufs.setHasShares(true);
                            vnxufs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                            _logger.debug("Export map for VNX UMFS {} = {}", vnxufs.getLabel(), vnxufs.getUnManagedSmbShareMap());
                            List<UnManagedCifsShareACL> cifsACLs = applyCifsSecurityRules(vnxufs, expPath, fsExportInfo, storagePort);
                            _logger.info("Number of acls discovered for file system {} is {}", vnxufs.getId() + ":" + vnxufs.getLabel(), cifsACLs.size());
                            for (UnManagedCifsShareACL cifsAcl : cifsACLs) {
                                _logger.info("Unmanaged File share acl: {}", cifsAcl);
                                String fsShareNativeId = cifsAcl.getFileSystemShareACLIndex();
                                _logger.info("UMFS Share ACL index: {}", fsShareNativeId);
                                String fsUnManagedFileShareNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileShare(storageSystem, fsShareNativeId);
                                _logger.info("Native GUID {}", fsUnManagedFileShareNativeGuid);
                                cifsAcl.setNativeGuid(fsUnManagedFileShareNativeGuid);
                                // Check whether the CIFS share ACL was present in ViPR DB.
                                UnManagedCifsShareACL existingACL = checkUnManagedFsCifsACLExistsInDB(_dbClient, cifsAcl.getNativeGuid());
                                if (existingACL == null) {
                                    newUnManagedCifsACLs.add(cifsAcl);
                                } else {
                                    newUnManagedCifsACLs.add(cifsAcl);
                                    existingACL.setInactive(true);
                                    oldUnManagedCifsACLs.add(existingACL);
                                }
                            }
                            // set vNAS on umfs
                            StringSet moverSet = new StringSet();
                            moverSet.add(moverURI.toString());
                            vnxufs.putFileSystemInfo(UnManagedFileSystem.SupportedFileSystemInformation.NAS.toString(), moverSet);
                            unManagedExportBatch.add(vnxufs);
                        }
                    }
                    if (noOfShares == 0) {
                        _logger.info("FileSystem {} does not have shares ", vnxufs.getLabel());
                    }
                }
                if (unManagedExportBatch.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                    // Add UnManagedFileSystem batch
                    // Update UnManagedFilesystem
                    _dbClient.persistObject(unManagedExportBatch);
                    unManagedExportBatch.clear();
                }
                if (newUnManagedCifsACLs.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                    // create new UnManagedCifsShareACL
                    _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", newUnManagedCifsACLs.size());
                    _dbClient.createObject(newUnManagedCifsACLs);
                    newUnManagedCifsACLs.clear();
                }
                if (oldUnManagedCifsACLs.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                    // Update existing UnManagedCifsShareACL
                    _logger.info("Saving Number of Old UnManagedCifsShareACL(s) {}", oldUnManagedCifsACLs.size());
                    _dbClient.persistObject(oldUnManagedCifsACLs);
                    oldUnManagedCifsACLs.clear();
                }
            }
        }
        if (!unManagedExportBatch.isEmpty()) {
            // Update UnManagedFilesystem
            _dbClient.persistObject(unManagedExportBatch);
            unManagedExportBatch.clear();
        }
        if (!newUnManagedCifsACLs.isEmpty()) {
            // create new UnManagedCifsShareACL
            _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", newUnManagedCifsACLs.size());
            _dbClient.createObject(newUnManagedCifsACLs);
            newUnManagedCifsACLs.clear();
        }
        if (!oldUnManagedCifsACLs.isEmpty()) {
            // Update existing UnManagedCifsShareACL
            _logger.info("Saving Number of Old UnManagedCifsShareACL(s) {}", oldUnManagedCifsACLs.size());
            _dbClient.persistObject(oldUnManagedCifsACLs);
            oldUnManagedCifsACLs.clear();
        }
        // discovery succeeds
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        detailedStatusMessage = String.format("Discovery completed successfully for VNXFile shares: %s", storageSystemId.toString());
    } catch (Exception ex) {
        if (storageSystem != null) {
            cleanupDiscovery(storageSystem);
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        detailedStatusMessage = String.format("Discovery failed for VNXFile cifs shares %s because %s", storageSystemId.toString(), ex.getLocalizedMessage());
        _logger.error(detailedStatusMessage, ex);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (Exception ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) StoragePort(com.emc.storageos.db.client.model.StoragePort) VNXFileSshApi(com.emc.storageos.vnx.xmlapi.VNXFileSshApi) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) IOException(java.io.IOException) VNXFileCollectionException(com.emc.storageos.plugins.metering.vnxfile.VNXFileCollectionException) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) CifsServerMap(com.emc.storageos.db.client.model.CifsServerMap)

Aggregations

UnManagedCifsShareACL (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL)21 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)9 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)8 URI (java.net.URI)8 StoragePort (com.emc.storageos.db.client.model.StoragePort)7 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)6 UnManagedSMBFileShare (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare)6 HashMap (java.util.HashMap)6 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 StringMap (com.emc.storageos.db.client.model.StringMap)4 UnManagedSMBShareMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap)4 HashSet (java.util.HashSet)4 CifsShareACL (com.emc.storageos.db.client.model.CifsShareACL)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)3