Search in sources :

Example 11 with UnManagedSMBFileShare

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

the class NetAppClusterModeCommIntf method getACLs.

/**
 * get ACLs for smb shares of fs object
 *
 * @param unManagedSMBFileShareHashSet
 * @param netAppClusterApi
 * @param fsId
 * @return
 */
private List<UnManagedCifsShareACL> getACLs(HashSet<UnManagedSMBFileShare> unManagedSMBFileShareHashSet, NetAppClusterApi netAppClusterApi, StorageSystem storageSystem, URI fsId) {
    _logger.info("gets all acls of fileshares given fsid ", fsId);
    // get list of acls for given set of shares
    UnManagedCifsShareACL unManagedCifsShareACL = null;
    List<UnManagedCifsShareACL> unManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
    // get acls for each share
    List<CifsAcl> cifsAclList = null;
    for (UnManagedSMBFileShare unManagedSMBFileShare : unManagedSMBFileShareHashSet) {
        // find acl for given share
        String unManagedSMBFileShareName = unManagedSMBFileShare.getName();
        _logger.info("new smb share name: {} and fs: {}", unManagedSMBFileShareName, fsId);
        cifsAclList = netAppClusterApi.listCIFSShareAcl(unManagedSMBFileShareName);
        if (cifsAclList != null && !cifsAclList.isEmpty()) {
            for (CifsAcl cifsAcl : cifsAclList) {
                _logger.info("cifs share ACL: {} ", cifsAcl.toString());
                unManagedCifsShareACL = new UnManagedCifsShareACL();
                unManagedCifsShareACL.setShareName(unManagedSMBFileShareName);
                String user = cifsAcl.getUserName();
                if (user != null) {
                    unManagedCifsShareACL.setUser(user);
                } else {
                    unManagedCifsShareACL.setGroup(cifsAcl.getGroupName());
                }
                // permission
                unManagedCifsShareACL.setPermission(cifsAcl.getAccess().name());
                unManagedCifsShareACL.setId(URIUtil.createId(UnManagedCifsShareACL.class));
                // filesystem id
                unManagedCifsShareACL.setFileSystemId(fsId);
                // set the native guid
                String fsShareNativeId = unManagedCifsShareACL.getFileSystemShareACLIndex();
                // _logger.info("UMFS Share ACL index {}", fsShareNativeId);
                String fsUnManagedFileShareNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileShare(storageSystem, fsShareNativeId);
                _logger.info("Native GUID {}", fsUnManagedFileShareNativeGuid);
                unManagedCifsShareACL.setNativeGuid(fsUnManagedFileShareNativeGuid);
                // add the acl to acl-list
                unManagedCifsShareACLList.add(unManagedCifsShareACL);
            }
            _logger.info("new smb share name-: {} and ACL count: {}", unManagedSMBFileShareName, cifsAclList.size());
        }
    }
    return unManagedCifsShareACLList;
}
Also used : UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) CifsAcl(com.iwave.ext.netappc.model.CifsAcl) ArrayList(java.util.ArrayList)

Example 12 with UnManagedSMBFileShare

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

the class NetAppFileCommunicationInterface method createShareMap.

/**
 * add Unmanaged SMB share to FS Object
 *
 * @param unManagedSMBFileShareHashSet
 * @param unManagedSMBShareMap
 * @param addr
 * @param nativeid
 */
private void createShareMap(HashSet<UnManagedSMBFileShare> unManagedSMBFileShareHashSet, UnManagedSMBShareMap unManagedSMBShareMap, String addr, String nativeid) {
    UnManagedSMBFileShare newUnManagedSMBFileShare = null;
    if (unManagedSMBFileShareHashSet != null && !unManagedSMBFileShareHashSet.isEmpty()) {
        for (UnManagedSMBFileShare unManagedSMBFileShare : unManagedSMBFileShareHashSet) {
            String mountPoint = "\\\\" + addr + "\\" + unManagedSMBFileShare.getName();
            newUnManagedSMBFileShare = new UnManagedSMBFileShare(unManagedSMBFileShare.getName(), unManagedSMBFileShare.getDescription(), // for netApp 7 mode permission and permission type is not used, setting to default values
            FileControllerConstants.CIFS_SHARE_PERMISSION_TYPE_ALLOW, FileControllerConstants.CIFS_SHARE_PERMISSION_CHANGE, unManagedSMBFileShare.getMaxUsers(), mountPoint);
            newUnManagedSMBFileShare.setNativeId(nativeid);
            newUnManagedSMBFileShare.setPath(nativeid);
            // add new cifs share to File Object
            unManagedSMBShareMap.put(unManagedSMBFileShare.getName(), newUnManagedSMBFileShare);
            _logger.info("New SMB share name: {} has mount point: {}", unManagedSMBFileShare.getName(), mountPoint);
        }
    }
}
Also used : UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare)

Example 13 with UnManagedSMBFileShare

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

the class NetAppFileCommunicationInterface method discoverUnManagedCifsShares.

/**
 * discover the unmanaged cifs shares and add shares to vipr db
 *
 * @param profile
 */
private void discoverUnManagedCifsShares(AccessProfile profile) {
    URI systemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, systemId);
    if (null == storageSystem) {
        return;
    }
    String detailedStatusMessage = "Discovery of NetApp Unmanaged Cifs shares started";
    NetAppApi netAppApi = new NetAppApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).build();
    Collection<String> attrs = new ArrayList<String>();
    for (String property : ntpPropertiesList) {
        attrs.add(SupportedNtpFileSystemInformation.getFileSystemInformation(property));
    }
    try {
        // Used to Save the Acl to DB
        List<UnManagedCifsShareACL> unManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
        List<UnManagedCifsShareACL> oldunManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
        List<Map<String, String>> fileSystemInfo = netAppApi.listVolumeInfo(null, attrs);
        List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
        // Get All cifs shares and ACLs
        List<Map<String, String>> listShares = netAppApi.listShares(null);
        if (listShares != null && !listShares.isEmpty()) {
            _logger.info("total no of shares in netapp system (s) {}", listShares.size());
        }
        HashSet<UnManagedSMBFileShare> unManagedSMBFileShareHashSet = null;
        // prepare the unmanagedSmbshare
        HashMap<String, HashSet<UnManagedSMBFileShare>> unMangedSMBFileShareMapSet = getAllCifsShares(listShares);
        for (String key : unMangedSMBFileShareMapSet.keySet()) {
            String filesystem = key;
            unManagedSMBFileShareHashSet = unMangedSMBFileShareMapSet.get(key);
            _logger.info("FileSystem Path {}", filesystem);
            String nativeId = null;
            if (!filesystem.startsWith(VOL_ROOT_NO_SLASH)) {
                nativeId = VOL_ROOT_NO_SLASH + filesystem;
            } else {
                nativeId = filesystem;
            }
            // Ignore root volume and don't pull it into ViPR db.
            if (filesystem.contains(ROOT_VOL)) {
                _logger.info("Ignore and not discover root filesystem {} on NTP array", filesystem);
                continue;
            }
            // Ignore snapshots and don't pull it into ViPR db.
            if (filesystem.contains(SNAPSHOT)) {
                _logger.info("Ignore exports for snapshot {}", filesystem);
                continue;
            }
            String shareNativeId = getFSPathIfSubDirectoryExport(nativeId);
            String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), shareNativeId);
            UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
            boolean fsAlreadyExists = unManagedFs == null ? false : true;
            if (fsAlreadyExists) {
                _logger.info("retrieve info for file system: " + filesystem);
                String vFiler = getOwningVfiler(filesystem, fileSystemInfo);
                if (vFiler != null && !vFiler.equalsIgnoreCase(DEFAULT_FILER)) {
                    _logger.info("Ignoring {} because it is owned by {}", filesystem, vFiler);
                    continue;
                }
                String addr = null;
                if (vFiler == null || vFiler.isEmpty()) {
                    // No vfilers, use system storage port
                    StoragePort port = getStoragePortPool(storageSystem);
                    addr = port.getPortName();
                } else {
                    // Use IP address of vFiler.
                    addr = getVfilerAddress(vFiler, vFilers);
                }
                UnManagedSMBShareMap tempUnManagedSMBShareMap = new UnManagedSMBShareMap();
                // add smb shares to FS object
                createShareMap(unManagedSMBFileShareHashSet, tempUnManagedSMBShareMap, addr, nativeId);
                // add shares to fs object
                if (!tempUnManagedSMBShareMap.isEmpty() && tempUnManagedSMBShareMap.size() > 0) {
                    unManagedFs.setUnManagedSmbShareMap(tempUnManagedSMBShareMap);
                    unManagedFs.setHasShares(true);
                    unManagedFs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                    _logger.debug("SMB Share map for NetApp UMFS {} = {}", unManagedFs.getLabel(), unManagedFs.getUnManagedSmbShareMap());
                }
                List<UnManagedCifsShareACL> tempUnManagedCifsShareAclList = getACLs(unManagedSMBFileShareHashSet, netAppApi, unManagedFs.getId());
                // get the acl details for given fileshare
                UnManagedCifsShareACL existingACL = null;
                for (UnManagedCifsShareACL unManagedCifsShareACL : tempUnManagedCifsShareAclList) {
                    _logger.info("Unmanaged File share acls : {}", unManagedCifsShareACL);
                    String fsShareNativeId = unManagedCifsShareACL.getFileSystemShareACLIndex();
                    _logger.info("UMFS Share ACL index {}", fsShareNativeId);
                    String fsUnManagedFileShareNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileShare(storageSystem, fsShareNativeId);
                    _logger.info("Native GUID {}", fsUnManagedFileShareNativeGuid);
                    unManagedCifsShareACL.setNativeGuid(fsUnManagedFileShareNativeGuid);
                    // Check whether the CIFS share ACL was present in ViPR DB.
                    existingACL = checkUnManagedFsCifsACLExistsInDB(_dbClient, unManagedCifsShareACL.getNativeGuid());
                    if (existingACL == null) {
                        unManagedCifsShareACLList.add(unManagedCifsShareACL);
                    } else {
                        // delete the existing acl
                        existingACL.setInactive(true);
                        oldunManagedCifsShareACLList.add(existingACL);
                        // then add new acl
                        unManagedCifsShareACLList.add(unManagedCifsShareACL);
                    }
                }
                // save the object
                {
                    _dbClient.persistObject(unManagedFs);
                    _logger.info("File System {} has Shares and their Count is {}", unManagedFs.getId(), tempUnManagedSMBShareMap.size());
                }
                // Adding this additional logic to avoid OOM
                if (!unManagedCifsShareACLList.isEmpty() && unManagedCifsShareACLList.size() >= MAX_UMFS_RECORD_SIZE) {
                    _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", unManagedCifsShareACLList.size());
                    _dbClient.createObject(unManagedCifsShareACLList);
                    unManagedCifsShareACLList.clear();
                }
                if (!oldunManagedCifsShareACLList.isEmpty() && oldunManagedCifsShareACLList.size() >= MAX_UMFS_RECORD_SIZE) {
                    _logger.info("Update Number of Old UnManagedCifsShareACL(s) {}", oldunManagedCifsShareACLList.size());
                    _dbClient.persistObject(oldunManagedCifsShareACLList);
                    oldunManagedCifsShareACLList.clear();
                }
            } else {
                _logger.info("FileSystem " + unManagedFs + "is not present in ViPR DB. Hence ignoring " + filesystem + " share");
            }
        }
        // 
        if (!unManagedCifsShareACLList.isEmpty()) {
            _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", unManagedCifsShareACLList.size());
            _dbClient.createObject(unManagedCifsShareACLList);
        }
        if (!oldunManagedCifsShareACLList.isEmpty()) {
            _logger.info("Saving Number of Old UnManagedCifsShareACL(s) {}", oldunManagedCifsShareACLList.size());
            _dbClient.persistObject(oldunManagedCifsShareACLList);
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for NetApp: %s", systemId.toString());
    } catch (NetAppException ve) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
            storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        }
        _logger.error("discoverStorage failed.  Storage system: " + systemId);
    } catch (Exception e) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
            storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        }
        _logger.error("discoverStorage failed. Storage system: " + systemId, e);
    } 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 : UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) NetAppException(com.emc.storageos.netapp.NetAppException) NetAppFileCollectionException(com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException) IOException(java.io.IOException) VFilerInfo(com.iwave.ext.netapp.VFilerInfo) UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) NetAppApi(com.emc.storageos.netapp.NetAppApi) 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) StringMap(com.emc.storageos.db.client.model.StringMap) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Example 14 with UnManagedSMBFileShare

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

the class NetAppFileCommunicationInterface method getAllCifsShares.

/**
 * get All Cifs shares in Netapp Device
 *
 * @param listShares
 * @return
 */
private HashMap<String, HashSet<UnManagedSMBFileShare>> getAllCifsShares(List<Map<String, String>> listShares) {
    // Discover All FileSystem
    HashMap<String, HashSet<UnManagedSMBFileShare>> sharesHapMap = new HashMap<String, HashSet<UnManagedSMBFileShare>>();
    UnManagedSMBFileShare unManagedSMBFileShare = null;
    HashSet<UnManagedSMBFileShare> unManagedSMBFileShareHashSet = null;
    // prepare smb shares map elem for each fs path
    for (Map<String, String> shareMap : listShares) {
        String shareName = "";
        String mountpath = "";
        String description = "";
        String maxusers = "-1";
        for (String key : shareMap.keySet()) {
            String value = shareMap.get(key);
            _logger.info("cifs share - key : {} and value : {}", key, value);
            if (null != key) {
                switch(key) {
                    case "share-name":
                        shareName = value;
                        break;
                    case "mount-point":
                        mountpath = value;
                        break;
                    case "description":
                        description = value;
                        break;
                    case "maxusers":
                        maxusers = value;
                        break;
                    default:
                        break;
                }
            }
        }
        _logger.info("cifs share details- share-name:{} mount-point: {} ", shareName, mountpath);
        unManagedSMBFileShare = new UnManagedSMBFileShare();
        unManagedSMBFileShare.setName(shareName);
        unManagedSMBFileShare.setMountPoint(mountpath);
        unManagedSMBFileShare.setDescription(description);
        unManagedSMBFileShare.setMaxUsers(Integer.parseInt(maxusers));
        unManagedSMBFileShareHashSet = sharesHapMap.get(mountpath);
        if (null == unManagedSMBFileShareHashSet) {
            unManagedSMBFileShareHashSet = new HashSet<UnManagedSMBFileShare>();
        }
        unManagedSMBFileShareHashSet.add(unManagedSMBFileShare);
        sharesHapMap.put(mountpath, unManagedSMBFileShareHashSet);
    }
    return sharesHapMap;
}
Also used : UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Aggregations

UnManagedSMBFileShare (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare)14 UnManagedSMBShareMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap)8 IOException (java.io.IOException)6 UnManagedCifsShareACL (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL)5 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 StringSet (com.emc.storageos.db.client.model.StringSet)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 UnManagedFSExportMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)2 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)2 NetAppException (com.emc.storageos.netapp.NetAppException)2 URI (java.net.URI)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2