Search in sources :

Example 1 with UnManagedFSExportMap

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

the class IsilonCommunicationInterface method getUnManagedFSExportMap.

/**
 * Generate Export Map for UnManagedFileSystem
 * Ignore exports with multiple exports for the same path
 * Ignore exports that have multiple security flavors
 * Ignore exports with multiple paths
 * Ignore exports not found on the array
 * Ignore exports which have the same internal export key ( <sec, perm, root-mapping>)
 *
 * @param umfs
 * @param isilonExportIds
 * @param storagePort
 * @param fsPath
 * @param isilonApi
 * @return boolean
 */
private boolean getUnManagedFSExportMap(UnManagedFileSystem umfs, HashSet<Integer> isilonExportIds, StoragePort storagePort, String fsPath, String zoneName, IsilonApi isilonApi, List<UnManagedFileExportRule> expRules) {
    UnManagedFSExportMap exportMap = new UnManagedFSExportMap();
    int generatedExportCount = 0;
    ArrayList<IsilonExport> isilonExports = new ArrayList<>();
    if (isilonExportIds != null && isilonExportIds.size() > 1) {
        _log.info("Found multiple export rules for file system path {}, {} ", fsPath, isilonExportIds.size());
    }
    for (Integer expId : isilonExportIds) {
        IsilonExport exp = getIsilonExport(isilonApi, expId, zoneName);
        if (exp == null) {
            _log.info("Ignoring export {} as it is not found", expId);
            continue;
        }
        for (String expPath : exp.getPaths()) {
            if (expPath != null && !expPath.equalsIgnoreCase(fsPath) && !expPath.startsWith(fsPath + "/")) {
                _log.info("Ignoring export {} as it's path doesn't match with file path {} ", expId, fsPath);
                continue;
            }
        }
        isilonExports.add(exp);
    }
    StringSet secTypes = new StringSet();
    for (IsilonExport exp : isilonExports) {
        String csSecurityTypes = "";
        Set<String> orderedList = new TreeSet<>();
        // store all security flavor separated by comma(,)
        for (String sec : exp.getSecurityFlavors()) {
            String securityFlavor = sec;
            // Isilon Maps sys to unix and we do this conversion during export from ViPR
            if (sec.equalsIgnoreCase(UNIXSECURITY)) {
                securityFlavor = SYSSECURITY;
            }
            orderedList.add(securityFlavor);
        }
        Iterator<String> secIter = orderedList.iterator();
        csSecurityTypes = secIter.next().toString();
        while (secIter.hasNext()) {
            csSecurityTypes += "," + secIter.next().toString();
        }
        if (!csSecurityTypes.isEmpty() && secTypes.contains(csSecurityTypes)) {
            _log.warn("Ignoring file system exports {}, as it contains multiple export rules with same security {}", fsPath, csSecurityTypes);
            return false;
        }
        secTypes.add(csSecurityTypes);
        String path = exp.getPaths().get(0);
        // Get User
        String rootUserMapping = "";
        String mapAllUserMapping = "";
        if (exp.getMap_root() != null && exp.getMap_root().getUser() != null) {
            rootUserMapping = exp.getMap_root().getUser();
        } else if (exp.getMap_all() != null && exp.getMap_all().getUser() != null) {
            mapAllUserMapping = exp.getMap_all().getUser();
        }
        String resolvedUser = (rootUserMapping != null && (!rootUserMapping.isEmpty())) ? rootUserMapping : mapAllUserMapping;
        // Create Export rule!!
        UnManagedFileExportRule expRule = new UnManagedFileExportRule();
        expRule.setExportPath(path);
        expRule.setSecFlavor(csSecurityTypes);
        expRule.setAnon(resolvedUser);
        expRule.setDeviceExportId(exp.getId().toString());
        expRule.setFileSystemId(umfs.getId());
        expRule.setMountPoint(storagePort.getPortNetworkId() + ":" + path);
        if (exp != null && exp.getReadOnlyClients() != null && !exp.getReadOnlyClients().isEmpty()) {
            UnManagedFSExport unManagedROFSExport = new UnManagedFSExport(exp.getReadOnlyClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RO, resolvedUser, NFS, storagePort.getPortName(), path, exp.getPaths().get(0));
            unManagedROFSExport.setIsilonId(exp.getId().toString());
            exportMap.put(unManagedROFSExport.getFileExportKey(), unManagedROFSExport);
            generatedExportCount++;
            expRule.setReadOnlyHosts(new StringSet(exp.getReadOnlyClients()));
        }
        if (exp != null && exp.getReadWriteClients() != null && !exp.getReadWriteClients().isEmpty()) {
            UnManagedFSExport unManagedRWFSExport = new UnManagedFSExport(exp.getReadWriteClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RW, resolvedUser, NFS, storagePort.getPortName(), path, exp.getPaths().get(0));
            unManagedRWFSExport.setIsilonId(exp.getId().toString());
            exportMap.put(unManagedRWFSExport.getFileExportKey(), unManagedRWFSExport);
            generatedExportCount++;
            expRule.setReadWriteHosts(new StringSet(exp.getReadWriteClients()));
        }
        if (exp != null && exp.getRootClients() != null && !exp.getRootClients().isEmpty()) {
            UnManagedFSExport unManagedROOTFSExport = new UnManagedFSExport(exp.getRootClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, ROOT, resolvedUser, NFS, storagePort.getPortName(), path, path);
            unManagedROOTFSExport.setIsilonId(exp.getId().toString());
            exportMap.put(unManagedROOTFSExport.getFileExportKey(), unManagedROOTFSExport);
            generatedExportCount++;
            expRule.setRootHosts(new StringSet(exp.getRootClients()));
        }
        if (exp.getReadOnlyClients() != null && exp.getReadWriteClients() != null && exp.getRootClients() != null) {
            // Check Clients size
            if (exp.getReadOnlyClients().isEmpty() && exp.getReadWriteClients().isEmpty() && exp.getRootClients().isEmpty()) {
                if (exp.getReadOnly()) {
                    // This is a read only export for all hosts
                    UnManagedFSExport unManagedROFSExport = new UnManagedFSExport(exp.getClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RO, rootUserMapping, NFS, storagePort.getPortName(), path, path);
                    unManagedROFSExport.setIsilonId(exp.getId().toString());
                    exportMap.put(unManagedROFSExport.getFileExportKey(), unManagedROFSExport);
                    generatedExportCount++;
                    // This is a read only export for all hosts
                    expRule.setReadOnlyHosts(new StringSet(exp.getClients()));
                } else {
                    // Not read Only case
                    if (exp.getMap_all() != null && exp.getMap_all().getUser() != null && exp.getMap_all().getUser().equalsIgnoreCase(ROOT)) {
                        // All hosts with root permission
                        UnManagedFSExport unManagedROOTFSExport = new UnManagedFSExport(exp.getClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, ROOT, mapAllUserMapping, NFS, storagePort.getPortName(), path, path);
                        unManagedROOTFSExport.setIsilonId(exp.getId().toString());
                        exportMap.put(unManagedROOTFSExport.getFileExportKey(), unManagedROOTFSExport);
                        generatedExportCount++;
                        // All hosts with root permission
                        expRule.setRootHosts(new StringSet(exp.getClients()));
                    } else if (exp.getMap_all() != null) {
                        // All hosts with RW permission
                        UnManagedFSExport unManagedRWFSExport = new UnManagedFSExport(exp.getClients(), storagePort.getPortName(), storagePort.getPortName() + ":" + path, csSecurityTypes, RW, rootUserMapping, NFS, storagePort.getPortName(), path, path);
                        unManagedRWFSExport.setIsilonId(exp.getId().toString());
                        exportMap.put(unManagedRWFSExport.getFileExportKey(), unManagedRWFSExport);
                        generatedExportCount++;
                        // All hosts with RW permission
                        expRule.setReadWriteHosts(new StringSet(exp.getClients()));
                    }
                }
            }
        }
        // Create Export rule for the export!!!
        expRules.add(expRule);
    }
    if (exportMap.values().size() < generatedExportCount) {
        // The keys are not unique and so all the exports are not valid
        _log.info("Ignoring Exports because they have multiple exports with the same internal export key <sec, perm, root-mapping>. Expected {} got {}", generatedExportCount, exportMap.values().size());
        return false;
    }
    // Return valid
    UnManagedFSExportMap allExportMap = umfs.getFsUnManagedExportMap();
    if (allExportMap == null) {
        allExportMap = new UnManagedFSExportMap();
    }
    allExportMap.putAll(exportMap);
    umfs.setFsUnManagedExportMap(allExportMap);
    return true;
}
Also used : IsilonExport(com.emc.storageos.isilon.restapi.IsilonExport) UnManagedFileExportRule(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule) ArrayList(java.util.ArrayList) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) UnManagedFSExport(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExport) TreeSet(java.util.TreeSet) StringSet(com.emc.storageos.db.client.model.StringSet) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)

Example 2 with UnManagedFSExportMap

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

the class DataDomainCommunicationInterface method createUnManagedFileSystem.

private UnManagedFileSystem createUnManagedFileSystem(UnManagedFileSystem unManagedFileSystem, String unManagedFileSystemNativeGuid, DDMTreeInfoDetail mtree, StorageSystem system, StoragePool pool, StringSet vPools) {
    if (null == unManagedFileSystem) {
        unManagedFileSystem = new UnManagedFileSystem();
        unManagedFileSystem.setId(URIUtil.createId(UnManagedFileSystem.class));
        unManagedFileSystem.setNativeGuid(unManagedFileSystemNativeGuid);
        unManagedFileSystem.setStorageSystemUri(system.getId());
        unManagedFileSystem.setFsUnManagedExportMap(new UnManagedFSExportMap());
        unManagedFileSystem.setHasExports(false);
        unManagedFileSystem.setHasShares(false);
    } else {
        // existing File System
        UnManagedFSExportMap exportMap = unManagedFileSystem.getFsUnManagedExportMap();
        if (exportMap != null) {
            exportMap.clear();
        }
    }
    Map<String, StringSet> unManagedFileSystemInformation = new HashMap<String, StringSet>();
    StringMap unManagedFileSystemCharacteristics = new StringMap();
    // TODO: DD does not provide snapshot API yet
    // This will be determined at snapshot discovery, once implemented
    unManagedFileSystemCharacteristics.put(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_SNAP_SHOT.toString(), FALSE);
    // DD supports only thinly provisioned FS
    unManagedFileSystemCharacteristics.put(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_THINLY_PROVISIONED.toString(), TRUE);
    unManagedFileSystemCharacteristics.put(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_INGESTABLE.toString(), TRUE);
    // Don't yet know if the FS is exported, to be determined at export discovery
    unManagedFileSystemCharacteristics.put(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), FALSE);
    unManagedFileSystem.setHasExports(false);
    if (null != pool) {
        StringSet pools = new StringSet();
        pools.add(pool.getId().toString());
        unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.STORAGE_POOL.toString(), pools);
        unManagedFileSystem.setStoragePoolUri(pool.getId());
    }
    _log.debug("Matched Pools : {}", Joiner.on("\t").join(vPools));
    if (null == vPools || vPools.isEmpty()) {
        unManagedFileSystem.getSupportedVpoolUris().clear();
    } else {
        unManagedFileSystem.getSupportedVpoolUris().replace(vPools);
        _log.info("Replaced Pools :" + Joiner.on("\t").join(unManagedFileSystem.getSupportedVpoolUris()));
    }
    List<StoragePort> ports = getPortFromDB(system);
    if (ports != null) {
        StringSet storagePorts = new StringSet();
        for (StoragePort storagePort : ports) {
            String portId = storagePort.getId().toString();
            storagePorts.add(portId);
        }
        unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.STORAGE_PORT.toString(), storagePorts);
    }
    if (null != system) {
        StringSet systemTypes = new StringSet();
        systemTypes.add(system.getSystemType());
        unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.SYSTEM_TYPE.toString(), systemTypes);
    }
    StringSet provisionedCapacity = new StringSet();
    if (mtree.quotaConfig != null) {
        provisionedCapacity.add(Long.toString(mtree.quotaConfig.getHardLimit()));
    } else {
        provisionedCapacity.add(Long.toString(mtree.logicalCapacity.getTotal()));
    }
    unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.PROVISIONED_CAPACITY.toString(), provisionedCapacity);
    StringSet allocatedCapacity = new StringSet();
    if (mtree.logicalCapacity != null) {
        allocatedCapacity.add(Long.toString(mtree.logicalCapacity.getUsed()));
    } else {
        allocatedCapacity.add(Long.toString(0));
    }
    unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.ALLOCATED_CAPACITY.toString(), allocatedCapacity);
    // Save off FileSystem Name, Path, Mount and label information
    String name = mtree.name;
    StringSet fsName = new StringSet();
    fsName.add(name);
    StringSet fsMountPath = new StringSet();
    fsMountPath.add(mtree.name);
    StringSet nativeId = new StringSet();
    nativeId.add(mtree.id);
    unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.NAME.toString(), fsName);
    unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.NATIVE_ID.toString(), nativeId);
    unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.DEVICE_LABEL.toString(), fsName);
    unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.PATH.toString(), fsName);
    unManagedFileSystemInformation.put(UnManagedFileSystem.SupportedFileSystemInformation.MOUNT_PATH.toString(), fsMountPath);
    // Add fileSystemInformation and Characteristics.
    unManagedFileSystem.addFileSystemInformation(unManagedFileSystemInformation);
    unManagedFileSystem.setFileSystemCharacterstics(unManagedFileSystemCharacteristics);
    return unManagedFileSystem;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) StringSet(com.emc.storageos.db.client.model.StringSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)

Example 3 with UnManagedFSExportMap

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

the class NetAppClusterModeCommIntf method discoverUnManagedNewExports.

private void discoverUnManagedNewExports(AccessProfile profile) {
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString());
    String detailedStatusMessage = "Discovery of NetAppC Unmanaged Exports started";
    unManagedExportRulesInsert = new ArrayList<UnManagedFileExportRule>();
    unManagedExportRulesUpdate = new ArrayList<UnManagedFileExportRule>();
    // Used to Save the rules to DB
    List<UnManagedFileExportRule> newUnManagedExportRules = new ArrayList<UnManagedFileExportRule>();
    NetAppClusterApi netAppCApi = new NetAppClusterApi.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 {
        List<Map<String, String>> fileSystemInfo = netAppCApi.listVolumeInfo(null, attrs);
        List<StorageVirtualMachineInfo> svms = netAppCApi.listSVM();
        for (StorageVirtualMachineInfo svmInfo : svms) {
            netAppCApi = new NetAppClusterApi.Builder(storageSystem.getIpAddress(), storageSystem.getPortNumber(), storageSystem.getUsername(), storageSystem.getPassword()).https(true).svm(svmInfo.getName()).build();
            // Get exports on the array and loop through each export.
            List<ExportsRuleInfo> exports = netAppCApi.listNFSExportRules(null);
            // Verification Utility
            UnManagedExportVerificationUtility validationUtility = new UnManagedExportVerificationUtility(_dbClient);
            for (ExportsRuleInfo deviceExport : exports) {
                String filesystem = deviceExport.getPathname();
                _logger.info("Export Path {}", filesystem);
                String nativeId = filesystem;
                String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), nativeId);
                UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
                boolean fsAlreadyExists = unManagedFs == null ? false : true;
                // Used as for rules validation
                List<UnManagedFileExportRule> unManagedExportRules = new ArrayList<UnManagedFileExportRule>();
                List<UnManagedFileExportRule> unManagedExportRulesToInsert = new ArrayList<UnManagedFileExportRule>();
                List<UnManagedFileExportRule> unManagedExportRulesToUpdate = new ArrayList<UnManagedFileExportRule>();
                if (fsAlreadyExists) {
                    _logger.debug("retrieve info for file system: " + filesystem);
                    String svm = getOwningSVM(filesystem, fileSystemInfo);
                    // Use IP address of SVM.
                    String addr = getSVMAddress(svm, svms);
                    UnManagedFSExportMap tempUnManagedExpMap = new UnManagedFSExportMap();
                    createExportMap(deviceExport, tempUnManagedExpMap, addr);
                    if (tempUnManagedExpMap.size() > 0) {
                        unManagedFs.setFsUnManagedExportMap(tempUnManagedExpMap);
                        _logger.debug("Export map for NetAppC UMFS {} = {}", unManagedFs.getLabel(), unManagedFs.getFsUnManagedExportMap());
                    }
                    List<UnManagedFileExportRule> exportRules = applyAllSecurityRules(deviceExport, addr, unManagedFs.getId());
                    _logger.info("Number of export rules discovered for file system {} is {}", unManagedFs.getId(), exportRules.size());
                    for (UnManagedFileExportRule dbExportRule : exportRules) {
                        _logger.info("Un Managed File Export Rule : {}", dbExportRule);
                        String fsExportRulenativeId = dbExportRule.getFsExportIndex();
                        _logger.info("Native Id using to build Native Guid {}", fsExportRulenativeId);
                        String fsUnManagedFileExportRuleNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileExportRule(storageSystem, fsExportRulenativeId);
                        _logger.info("Native GUID {}", fsUnManagedFileExportRuleNativeGuid);
                        UnManagedFileExportRule unManagedExportRule = checkUnManagedFsExportRuleExistsInDB(_dbClient, fsUnManagedFileExportRuleNativeGuid);
                        UnManagedFileExportRule unManagedExpRule = null;
                        if (unManagedExportRule == null) {
                            unManagedExportRule = new UnManagedFileExportRule();
                            unManagedExportRule.setNativeGuid(fsUnManagedFileExportRuleNativeGuid);
                            unManagedExportRule.setFileSystemId(unManagedFs.getId());
                            unManagedExportRule.setId(URIUtil.createId(UnManagedFileExportRule.class));
                            unManagedExpRule = copyProperties(unManagedExportRule, dbExportRule);
                            unManagedExportRulesToInsert.add(unManagedExpRule);
                            // Build all export rules list.
                            unManagedExportRules.add(unManagedExpRule);
                            _logger.info("Unmanaged File Export Rule : {}", unManagedExpRule);
                        } else {
                            dbExportRule.setNativeGuid(fsUnManagedFileExportRuleNativeGuid);
                            dbExportRule.setId(URIUtil.createId(UnManagedFileExportRule.class));
                            unManagedExportRulesToInsert.add(dbExportRule);
                            // Build all export rules list.
                            unManagedExportRules.add(dbExportRule);
                            // Delete the existing rule!!
                            unManagedExportRule.setInactive(true);
                            unManagedExportRulesToUpdate.add(unManagedExportRule);
                            _logger.info("Unmanaged File Export Rule : {}", dbExportRule);
                        }
                    }
                    // apply as per API SVC Validations.
                    if (!unManagedExportRules.isEmpty()) {
                        boolean isAllRulesValid = validationUtility.validateUnManagedExportRules(unManagedExportRules, false);
                        if (isAllRulesValid) {
                            _logger.info("Validating rules success for export {}", filesystem);
                            unManagedExportRulesInsert.addAll(unManagedExportRulesToInsert);
                            unManagedExportRulesUpdate.addAll(unManagedExportRulesToUpdate);
                            unManagedFs.setHasExports(true);
                            unManagedFs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                            _dbClient.persistObject(unManagedFs);
                            _logger.info("File System {} has Exports and their size is {}", unManagedFs.getId(), newUnManagedExportRules.size());
                        } else {
                            _logger.warn("Validating rules failed for export {}. Ignroing to import these rules into ViPR DB", filesystem);
                            // Delete the UMFS as it having invalid rule!!!
                            unManagedFs.setInactive(true);
                            _dbClient.persistObject(unManagedFs);
                        }
                    }
                    // Adding this additional logic to avoid OOM
                    if (unManagedExportRulesInsert.size() == MAX_UMFS_RECORD_SIZE) {
                        // Add UnManagedFileSystem
                        _partitionManager.insertInBatches(unManagedExportRulesInsert, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
                        unManagedExportRulesInsert.clear();
                        unManagedExportRulesToInsert.clear();
                    }
                    if (unManagedExportRulesUpdate.size() == MAX_UMFS_RECORD_SIZE) {
                        // Update UnManagedFilesystem
                        _partitionManager.updateInBatches(unManagedExportRulesUpdate, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
                        unManagedExportRulesUpdate.clear();
                        unManagedExportRulesToUpdate.clear();
                    }
                } else {
                    _logger.info("FileSystem " + unManagedFs + "is not present in ViPR DB. Hence ignoring " + deviceExport + " export");
                }
            }
        }
        if (!unManagedExportRulesInsert.isEmpty()) {
            // Add UnManagedFileSystem
            _partitionManager.insertInBatches(unManagedExportRulesInsert, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
            unManagedExportRulesInsert.clear();
        }
        if (!unManagedExportRulesUpdate.isEmpty()) {
            // Update UnManagedFilesystem
            _partitionManager.updateInBatches(unManagedExportRulesUpdate, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
            unManagedExportRulesUpdate.clear();
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for NetAppC: %s", storageSystemId.toString());
    } catch (NetAppCException ve) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
            storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        }
        _logger.error("discoverStorage failed.  Storage system: " + storageSystemId);
    } catch (Exception e) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
            storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        }
        _logger.error("discoverStorage failed. Storage system: " + storageSystemId, 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 : UnManagedExportVerificationUtility(com.emc.storageos.volumecontroller.impl.utils.UnManagedExportVerificationUtility) UnManagedFileExportRule(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule) ArrayList(java.util.ArrayList) URI(java.net.URI) ExportsRuleInfo(com.iwave.ext.netapp.model.ExportsRuleInfo) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) NetAppException(com.emc.storageos.netapp.NetAppException) NetAppCException(com.emc.storageos.netappc.NetAppCException) IOException(java.io.IOException) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) NetAppCException(com.emc.storageos.netappc.NetAppCException) StorageVirtualMachineInfo(com.iwave.ext.netappc.StorageVirtualMachineInfo) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) Map(java.util.Map) 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) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)

Example 4 with UnManagedFSExportMap

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

the class NetAppFileCommunicationInterface method discoverUnManagedNewExports.

private void discoverUnManagedNewExports(AccessProfile profile) {
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString());
    String detailedStatusMessage = "Discovery of NetApp Unmanaged Exports started";
    // Used to Save the rules to DB
    List<UnManagedFileExportRule> newUnManagedExportRules = new ArrayList<UnManagedFileExportRule>();
    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 {
        List<Map<String, String>> fileSystemInfo = netAppApi.listVolumeInfo(null, attrs);
        List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
        // Get exports on the array and loop through each export.
        List<ExportsRuleInfo> exports = netAppApi.listNFSExportRules(null);
        // Verification Utility
        UnManagedExportVerificationUtility validationUtility = new UnManagedExportVerificationUtility(_dbClient);
        for (ExportsRuleInfo deviceExport : exports) {
            String filesystem = deviceExport.getPathname();
            _logger.info("Export Path {}", filesystem);
            String nativeId = null;
            if (!filesystem.startsWith(VOL_ROOT_NO_SLASH)) {
                nativeId = VOL_ROOT_NO_SLASH + filesystem;
            } else {
                nativeId = filesystem;
            }
            // Ignore export for root volume and don't pull it into ViPR db.
            if (filesystem.contains(ROOT_VOL)) {
                _logger.info("Ignore exports for root volume {} on NTP array", filesystem);
                continue;
            }
            // Ignore export for snapshots and don't pull it into ViPR db.
            if (filesystem.contains(SNAPSHOT)) {
                _logger.info("Ignore exports for snapshot {}", filesystem);
                continue;
            }
            nativeId = getFSPathIfSubDirectoryExport(nativeId);
            String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), nativeId);
            UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
            boolean fsAlreadyExists = unManagedFs == null ? false : true;
            // Used as for rules validation
            List<UnManagedFileExportRule> unManagedExportRules = new ArrayList<UnManagedFileExportRule>();
            if (fsAlreadyExists) {
                _logger.debug("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);
                }
                UnManagedFSExportMap tempUnManagedExpMap = new UnManagedFSExportMap();
                // create the export map for FS
                createExportMap(deviceExport, tempUnManagedExpMap, addr);
                if (tempUnManagedExpMap.size() > 0) {
                    unManagedFs.setFsUnManagedExportMap(tempUnManagedExpMap);
                    _logger.debug("Export map for NetApp UMFS {} = {}", unManagedFs.getLabel(), unManagedFs.getFsUnManagedExportMap());
                }
                List<UnManagedFileExportRule> exportRules = applyAllSecurityRules(deviceExport, addr, unManagedFs.getId());
                _logger.info("Number of export rules discovered for file system {} is {}", unManagedFs.getId(), exportRules.size());
                for (UnManagedFileExportRule dbExportRule : exportRules) {
                    _logger.info("Un Managed File Export Rule : {}", dbExportRule);
                    String fsExportRulenativeId = dbExportRule.getFsExportIndex();
                    _logger.info("Native Id using to build Native Guid {}", fsExportRulenativeId);
                    String fsUnManagedFileExportRuleNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileExportRule(storageSystem, fsExportRulenativeId);
                    _logger.info("Native GUID {}", fsUnManagedFileExportRuleNativeGuid);
                    dbExportRule.setNativeGuid(fsUnManagedFileExportRuleNativeGuid);
                    // dbExportRule.setFileSystemId(unManagedFs.getId());
                    dbExportRule.setId(URIUtil.createId(UnManagedFileExportRule.class));
                    // Build all export rules list.
                    unManagedExportRules.add(dbExportRule);
                }
                // apply as per API SVC Validations.
                if (!unManagedExportRules.isEmpty()) {
                    boolean isAllRulesValid = validationUtility.validateUnManagedExportRules(unManagedExportRules, false);
                    if (isAllRulesValid) {
                        _logger.info("Validating rules success for export {}", filesystem);
                        for (UnManagedFileExportRule exportRule : unManagedExportRules) {
                            UnManagedFileExportRule existingRule = checkUnManagedFsExportRuleExistsInDB(_dbClient, exportRule.getNativeGuid());
                            if (existingRule == null) {
                                newUnManagedExportRules.add(exportRule);
                            } else {
                                // Remove the existing rule.
                                existingRule.setInactive(true);
                                _dbClient.persistObject(existingRule);
                                newUnManagedExportRules.add(exportRule);
                            }
                        }
                        unManagedFs.setHasExports(true);
                        unManagedFs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                        _dbClient.persistObject(unManagedFs);
                        _logger.info("File System {} has Exports and their size is {}", unManagedFs.getId(), newUnManagedExportRules.size());
                    } else {
                        _logger.warn("Validating rules failed for export {}. Ignroing to import these rules into ViPR DB", filesystem);
                        unManagedFs.setInactive(true);
                        _dbClient.persistObject(unManagedFs);
                    }
                }
                // Adding this additional logic to avoid OOM
                if (newUnManagedExportRules.size() == MAX_UMFS_RECORD_SIZE) {
                    _logger.info("Saving Number of UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
                    _partitionManager.updateInBatches(newUnManagedExportRules, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
                    newUnManagedExportRules.clear();
                }
            } else {
                _logger.info("FileSystem " + unManagedFs + "is not present in ViPR DB. Hence ignoring " + deviceExport + " export");
            }
        }
        if (!newUnManagedExportRules.isEmpty()) {
            _logger.info("Saving Number of UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
            _partitionManager.updateInBatches(newUnManagedExportRules, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_EXPORT_RULE);
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for NetApp: %s", storageSystemId.toString());
    } catch (NetAppException ve) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
            storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        }
        _logger.error("discoverStorage failed.  Storage system: " + storageSystemId);
    } catch (Exception e) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
            storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        }
        _logger.error("discoverStorage failed. Storage system: " + storageSystemId, 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 : UnManagedExportVerificationUtility(com.emc.storageos.volumecontroller.impl.utils.UnManagedExportVerificationUtility) UnManagedFileExportRule(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) ExportsRuleInfo(com.iwave.ext.netapp.model.ExportsRuleInfo) 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) 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) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)

Example 5 with UnManagedFSExportMap

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

the class NetAppFileCommunicationInterface method discoverUnManagedExports.

private void discoverUnManagedExports(AccessProfile profile) {
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    Boolean invalidateFS = false;
    if (null == storageSystem) {
        return;
    }
    String detailedStatusMessage = "Discovery of NetApp Unmanaged Exports started";
    List<UnManagedFileSystem> existingUnManagedFileSystems = new ArrayList<UnManagedFileSystem>();
    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 {
        URIQueryResultList storagePoolURIs = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePoolConstraint(storageSystem.getId()), storagePoolURIs);
        // Get storageport
        HashMap<String, StoragePool> pools = new HashMap<String, StoragePool>();
        Iterator<URI> poolsItr = storagePoolURIs.iterator();
        while (poolsItr.hasNext()) {
            URI storagePoolURI = poolsItr.next();
            StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolURI);
            pools.put(storagePool.getNativeGuid(), storagePool);
        }
        // Retrieve all the file system and vFiler info.
        List<Map<String, String>> fileSystemInfo = netAppApi.listVolumeInfo(null, attrs);
        List<VFilerInfo> vFilers = netAppApi.listVFilers(null);
        // Get exports on the array and loop through each export.
        List<ExportsRuleInfo> exports = netAppApi.listNFSExportRules(null);
        for (ExportsRuleInfo export : exports) {
            String filesystem = export.getPathname();
            String nativeId = null;
            if (!filesystem.startsWith(VOL_ROOT_NO_SLASH)) {
                nativeId = VOL_ROOT_NO_SLASH + filesystem;
            } else {
                nativeId = filesystem;
            }
            // Ignore export for root volume and don't pull it into ViPR db.
            if (filesystem.contains(ROOT_VOL)) {
                _logger.info("Ignore exports for root volumes on NTP array");
                continue;
            }
            // Ignore exports that have multiple security rules and security flavors.
            String secflavors = export.getSecurityRuleInfos().get(0).getSecFlavor();
            String[] secFlavorsAry = secflavors.split(",");
            Integer secFlavorAryLength = secFlavorsAry.length;
            Integer secRulesSize = export.getSecurityRuleInfos().size();
            if ((secRulesSize > 1) || (secFlavorAryLength > 1)) {
                invalidateFS = true;
            } else {
                invalidateFS = false;
            }
            nativeId = getFSPathIfSubDirectoryExport(nativeId);
            String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), nativeId);
            UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
            boolean fsAlreadyExists = unManagedFs == null ? false : true;
            if (fsAlreadyExists) {
                // TODO: Come up with list of UMFSes to be presented to API.
                if (invalidateFS) {
                    _logger.info("FileSystem " + nativeId + "has a complex export with multiple secruity flavors and security rules, hence ignoring the filesystem and NOT brining into ViPR DB");
                    unManagedFs.setInactive(true);
                } else {
                    _logger.debug("retrieve info for file system: " + filesystem);
                    String vFiler = getOwningVfiler(filesystem, fileSystemInfo);
                    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);
                    }
                    UnManagedFSExportMap tempUnManagedExpMap = new UnManagedFSExportMap();
                    createExportMap(export, tempUnManagedExpMap, addr);
                    if (tempUnManagedExpMap.size() > 0) {
                        unManagedFs.setFsUnManagedExportMap(tempUnManagedExpMap);
                    }
                }
                existingUnManagedFileSystems.add(unManagedFs);
                // Adding this additional logic to avoid OOM
                if (existingUnManagedFileSystems.size() == MAX_UMFS_RECORD_SIZE) {
                    _partitionManager.updateInBatches(existingUnManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
                    existingUnManagedFileSystems.clear();
                }
            } else {
                _logger.info("FileSystem " + unManagedFs + "is not present in ViPR DB. Hence ignoring " + export + " export");
            }
        }
        if (!existingUnManagedFileSystems.isEmpty()) {
            // Update UnManagedFilesystem
            _partitionManager.updateInBatches(existingUnManagedFileSystems, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
        }
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for NetApp: %s", storageSystemId.toString());
    } catch (NetAppException ve) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
        }
        throw ve;
    } catch (Exception e) {
        if (null != storageSystem) {
            cleanupDiscovery(storageSystem);
        }
        _logger.error("discoverStorage failed. Storage system: " + storageSystemId, e);
        throw NetAppException.exceptions.discoveryFailed(storageSystemId.toString(), 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 : StoragePool(com.emc.storageos.db.client.model.StoragePool) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NetAppApi(com.emc.storageos.netapp.NetAppApi) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ExportsRuleInfo(com.iwave.ext.netapp.model.ExportsRuleInfo) 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) 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)

Aggregations

UnManagedFSExportMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)9 HashMap (java.util.HashMap)6 StringMap (com.emc.storageos.db.client.model.StringMap)5 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)5 ArrayList (java.util.ArrayList)5 UnManagedSMBShareMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap)4 StoragePort (com.emc.storageos.db.client.model.StoragePort)3 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 UnManagedFSExport (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExport)3 UnManagedFileExportRule (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 NetAppException (com.emc.storageos.netapp.NetAppException)3 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)3 ExportsRuleInfo (com.iwave.ext.netapp.model.ExportsRuleInfo)3 IOException (java.io.IOException)3 URI (java.net.URI)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2