Search in sources :

Example 1 with StorageVirtualMachineInfo

use of com.iwave.ext.netappc.StorageVirtualMachineInfo in project coprhd-controller by CoprHD.

the class NetAppClusterModeCommIntf method discoverPorts.

/**
 * Discover the IP Interfaces/Storage Ports for NetApp Cluster mode array
 *
 * @param system
 *            Storage system information
 * @return Map of new and existing storage ports
 * @throws NetAppCException
 */
private Map<String, List<StoragePort>> discoverPorts(StorageSystem storageSystem, List<StorageVirtualMachineInfo> svms, List<StorageHADomain> haDomains) throws NetAppCException {
    URI storageSystemId = storageSystem.getId();
    HashMap<String, List<StoragePort>> storagePorts = new HashMap<String, List<StoragePort>>();
    List<StoragePort> newStoragePorts = new ArrayList<StoragePort>();
    List<StoragePort> existingStoragePorts = new ArrayList<StoragePort>();
    // Discover storage ports
    try {
        _logger.info("discoverPorts for storage system {} - start", storageSystemId);
        StoragePort storagePort = null;
        if (svms != null && !svms.isEmpty()) {
            for (StorageVirtualMachineInfo svm : svms) {
                for (SVMNetInfo intf : svm.getInterfaces()) {
                    if (intf.getRole().contains(MANAGEMENT_INTERFACE)) {
                        continue;
                    }
                    URIQueryResultList results = new URIQueryResultList();
                    String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, intf.getIpAddress(), NativeGUIDGenerator.PORT);
                    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid), results);
                    storagePort = null;
                    if (results.iterator().hasNext()) {
                        StoragePort tmpPort = _dbClient.queryObject(StoragePort.class, results.iterator().next());
                        if (tmpPort.getStorageDevice().equals(storageSystem.getId()) && tmpPort.getPortGroup().equals(svm.getName())) {
                            storagePort = tmpPort;
                            _logger.debug("found duplicate intf {}", intf.getIpAddress());
                        }
                    }
                    if (storagePort == null) {
                        storagePort = new StoragePort();
                        storagePort.setId(URIUtil.createId(StoragePort.class));
                        storagePort.setTransportType("IP");
                        storagePort.setNativeGuid(portNativeGuid);
                        storagePort.setLabel(portNativeGuid);
                        storagePort.setStorageDevice(storageSystemId);
                        storagePort.setPortName(intf.getIpAddress());
                        storagePort.setPortNetworkId(intf.getIpAddress());
                        storagePort.setPortGroup(svm.getName());
                        storagePort.setStorageHADomain(findMatchingHADomain(svm.getName(), haDomains));
                        storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                        _logger.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
                        newStoragePorts.add(storagePort);
                    } else {
                        existingStoragePorts.add(storagePort);
                    }
                    storagePort.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                    storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
                }
            }
        } else {
            // Check if storage port was already discovered
            URIQueryResultList results = new URIQueryResultList();
            String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, storageSystem.getIpAddress(), NativeGUIDGenerator.PORT);
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid), results);
            if (results.iterator().hasNext()) {
                StoragePort tmpPort = _dbClient.queryObject(StoragePort.class, results.iterator().next());
                if (tmpPort.getStorageDevice().equals(storageSystem.getId()) && tmpPort.getPortGroup().equals(storageSystem.getSerialNumber())) {
                    storagePort = tmpPort;
                    _logger.debug("found duplicate dm intf {}", storageSystem.getSerialNumber());
                }
            }
            if (storagePort == null) {
                // Create NetAppC storage port for IP address
                storagePort = new StoragePort();
                storagePort.setId(URIUtil.createId(StoragePort.class));
                storagePort.setTransportType("IP");
                storagePort.setNativeGuid(portNativeGuid);
                storagePort.setLabel(portNativeGuid);
                storagePort.setStorageDevice(storageSystemId);
                storagePort.setPortName(storageSystem.getIpAddress());
                storagePort.setPortNetworkId(storageSystem.getIpAddress());
                storagePort.setPortGroup(storageSystem.getSerialNumber());
                storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                _logger.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
                newStoragePorts.add(storagePort);
            } else {
                existingStoragePorts.add(storagePort);
            }
            storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        }
        _logger.info("discoverPorts for storage system {} - complete", storageSystemId);
        storagePorts.put(NEW, newStoragePorts);
        storagePorts.put(EXISTING, existingStoragePorts);
        return storagePorts;
    } catch (Exception e) {
        _logger.error("discoverPorts failed. Storage system: " + storageSystemId, e);
        throw new NetAppCException("discoverPorts failed. Storage system: " + storageSystemId, e);
    }
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI) SVMNetInfo(com.iwave.ext.netappc.SVMNetInfo) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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) NetAppCException(com.emc.storageos.netappc.NetAppCException) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageVirtualMachineInfo(com.iwave.ext.netappc.StorageVirtualMachineInfo)

Example 2 with StorageVirtualMachineInfo

use of com.iwave.ext.netappc.StorageVirtualMachineInfo in project coprhd-controller by CoprHD.

the class NetAppClusterModeCommIntf method discoverUnManagedCifsShares.

/**
 * discover the unmanaged cifs shares and add shares to ViPR db
 *
 * @param profile
 */
private void discoverUnManagedCifsShares(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 Cifs started";
    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 {
        // Used to Save the Acl to DB
        List<UnManagedCifsShareACL> unManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
        List<UnManagedCifsShareACL> oldunManagedCifsShareACLList = new ArrayList<UnManagedCifsShareACL>();
        HashSet<UnManagedSMBFileShare> unManagedSMBFileShareHashSet = null;
        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 All cifs shares and ACLs
            List<Map<String, String>> listShares = netAppCApi.listShares(null);
            if (listShares != null && !listShares.isEmpty()) {
                _logger.info("total no of shares in netappC system (s) {}", listShares.size());
            }
            // prepare the unmanagedSmbshare
            HashMap<String, HashSet<UnManagedSMBFileShare>> unMangedSMBFileShareMapSet = getAllCifsShares(listShares);
            for (String key : unMangedSMBFileShareMapSet.keySet()) {
                unManagedSMBFileShareHashSet = unMangedSMBFileShareMapSet.get(key);
                String fileSystem = key;
                String nativeId = fileSystem;
                // get a fileSystem name from the path
                int index = fileSystem.indexOf('/', 1);
                if (-1 != index) {
                    fileSystem = fileSystem.substring(0, index);
                    _logger.info("Unmanaged FileSystem Name {}", fileSystem);
                }
                // build native id
                String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), fileSystem);
                UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(fsUnManagedFsNativeGuid);
                boolean fsAlreadyExists = unManagedFs == null ? false : true;
                if (fsAlreadyExists) {
                    _logger.debug("retrieve info for file system: " + fileSystem);
                    String svm = getOwningSVM(fileSystem, fileSystemInfo);
                    String addr = getSVMAddress(svm, svms);
                    UnManagedSMBShareMap tempUnManagedSMBShareMap = new UnManagedSMBShareMap();
                    // get the SMB shares
                    createSMBShareMap(unManagedSMBFileShareHashSet, tempUnManagedSMBShareMap, addr, nativeId);
                    // add shares to fs object and set hasShare to true
                    if (tempUnManagedSMBShareMap.size() > 0 && !tempUnManagedSMBShareMap.isEmpty()) {
                        unManagedFs.setUnManagedSmbShareMap(tempUnManagedSMBShareMap);
                        unManagedFs.setHasShares(true);
                        unManagedFs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                        _logger.debug("SMB Share map for NetAppC UMFS {} = {}", unManagedFs.getLabel(), unManagedFs.getUnManagedSmbShareMap());
                    }
                    // get the acls details for given fileshare of given fs
                    UnManagedCifsShareACL existingACL = null;
                    List<UnManagedCifsShareACL> tempUnManagedCifsShareAclList = getACLs(unManagedSMBFileShareHashSet, netAppCApi, storageSystem, unManagedFs.getId());
                    if (tempUnManagedCifsShareAclList != null && !tempUnManagedCifsShareAclList.isEmpty()) {
                        for (UnManagedCifsShareACL unManagedCifsShareACL : tempUnManagedCifsShareAclList) {
                            // Check whether the CIFS share ACL was present in ViPR DB.
                            existingACL = checkUnManagedFsCifsACLExistsInDB(_dbClient, unManagedCifsShareACL.getNativeGuid());
                            if (existingACL == null) {
                                // add new acl
                                unManagedCifsShareACLList.add(unManagedCifsShareACL);
                            } else {
                                // delete the existing acl by setting object to inactive to true
                                existingACL.setInactive(true);
                                oldunManagedCifsShareACLList.add(existingACL);
                                // then add new acl and save
                                unManagedCifsShareACLList.add(unManagedCifsShareACL);
                            }
                        }
                    }
                    // store or update the FS object into DB
                    if (unManagedSMBFileShareHashSet != null && !unManagedSMBFileShareHashSet.isEmpty()) {
                        _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.size() >= MAX_UMFS_RECORD_SIZE) {
                        _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", unManagedCifsShareACLList.size());
                        _partitionManager.insertInBatches(unManagedCifsShareACLList, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_SHARE_ACL);
                        unManagedCifsShareACLList.clear();
                    }
                    if (!oldunManagedCifsShareACLList.isEmpty() && oldunManagedCifsShareACLList.size() >= MAX_UMFS_RECORD_SIZE) {
                        _logger.info("Update Number of Old UnManagedCifsShareACL(s) {}", oldunManagedCifsShareACLList.size());
                        _partitionManager.updateInBatches(oldunManagedCifsShareACLList, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_SHARE_ACL);
                        oldunManagedCifsShareACLList.clear();
                    }
                } else {
                    _logger.info("FileSystem " + unManagedFs + "is not present in ViPR DB. Hence ignoring " + fileSystem + " share");
                }
            }
        }
        if (unManagedCifsShareACLList != null && !unManagedCifsShareACLList.isEmpty()) {
            _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", unManagedCifsShareACLList.size());
            _partitionManager.insertInBatches(unManagedCifsShareACLList, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_SHARE_ACL);
            unManagedCifsShareACLList.clear();
        }
        if (oldunManagedCifsShareACLList != null && !oldunManagedCifsShareACLList.isEmpty()) {
            _logger.info("Saving Number of Old UnManagedCifsShareACL(s) {}", oldunManagedCifsShareACLList.size());
            _partitionManager.updateInBatches(oldunManagedCifsShareACLList, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_SHARE_ACL);
            oldunManagedCifsShareACLList.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 : UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) ArrayList(java.util.ArrayList) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) 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) UnManagedSMBFileShare(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBFileShare) 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) HashSet(java.util.HashSet)

Example 3 with StorageVirtualMachineInfo

use of com.iwave.ext.netappc.StorageVirtualMachineInfo in project coprhd-controller by CoprHD.

the class NetAppClusterModeCommIntf method discoverPortGroups.

/**
 * Discover the Storage Virtual Machines (Port Groups) for NetApp Cluster mode array
 *
 * @param system
 *            Storage system information
 * @return Map of new and existing port groups
 * @throws NetAppCException
 */
private HashMap<String, List<StorageHADomain>> discoverPortGroups(StorageSystem system, List<StorageVirtualMachineInfo> vServerList) throws NetAppCException {
    HashMap<String, List<StorageHADomain>> portGroups = new HashMap<String, List<StorageHADomain>>();
    List<StorageHADomain> newPortGroups = new ArrayList<StorageHADomain>();
    List<StorageHADomain> existingPortGroups = new ArrayList<StorageHADomain>();
    _logger.info("Start port group discovery (vfilers) for storage system {}", system.getId());
    NetAppClusterApi netAppCApi = new NetAppClusterApi.Builder(system.getIpAddress(), system.getPortNumber(), system.getUsername(), system.getPassword()).https(true).build();
    StorageHADomain portGroup = null;
    List<StorageVirtualMachineInfo> svms = netAppCApi.listSVM();
    if (null == svms || svms.isEmpty()) {
        // Check if default port group was previously created.
        URIQueryResultList results = new URIQueryResultList();
        String adapterNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, DEFAULT_SVM, NativeGUIDGenerator.ADAPTER);
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageHADomainByNativeGuidConstraint(adapterNativeGuid), results);
        if (results.iterator().hasNext()) {
            StorageHADomain tmpGroup = _dbClient.queryObject(StorageHADomain.class, results.iterator().next());
            if (tmpGroup.getStorageDeviceURI().equals(system.getId())) {
                portGroup = tmpGroup;
                _logger.debug("Found existing port group {} ", tmpGroup.getName());
            }
        }
        if (portGroup == null) {
            portGroup = new StorageHADomain();
            portGroup.setId(URIUtil.createId(StorageHADomain.class));
            portGroup.setName("NetAppC");
            portGroup.setVirtual(false);
            portGroup.setNativeGuid(adapterNativeGuid);
            portGroup.setStorageDeviceURI(system.getId());
            StringSet protocols = new StringSet();
            protocols.add(StorageProtocol.File.NFS.name());
            protocols.add(StorageProtocol.File.CIFS.name());
            portGroup.setFileSharingProtocols(protocols);
            newPortGroups.add(portGroup);
        } else {
            existingPortGroups.add(portGroup);
        }
    } else {
        _logger.debug("Number svms found: {}", svms.size());
        vServerList.addAll(svms);
        StringSet protocols = new StringSet();
        protocols.add(StorageProtocol.File.NFS.name());
        protocols.add(StorageProtocol.File.CIFS.name());
        for (StorageVirtualMachineInfo vs : svms) {
            _logger.debug("SVM name: {}", vs.getName());
            // Check if port group was previously discovered
            URIQueryResultList results = new URIQueryResultList();
            String adapterNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, vs.getName(), NativeGUIDGenerator.ADAPTER);
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageHADomainByNativeGuidConstraint(adapterNativeGuid), results);
            portGroup = null;
            if (results.iterator().hasNext()) {
                StorageHADomain tmpGroup = _dbClient.queryObject(StorageHADomain.class, results.iterator().next());
                if (tmpGroup.getStorageDeviceURI().equals(system.getId())) {
                    portGroup = tmpGroup;
                    _logger.debug("Found duplicate {} ", vs.getName());
                }
            }
            if (portGroup == null) {
                portGroup = new StorageHADomain();
                portGroup.setId(URIUtil.createId(StorageHADomain.class));
                portGroup.setName(vs.getName());
                portGroup.setVirtual(true);
                portGroup.setAdapterType(StorageHADomain.HADomainType.VIRTUAL.toString());
                portGroup.setNativeGuid(adapterNativeGuid);
                portGroup.setStorageDeviceURI(system.getId());
                portGroup.setFileSharingProtocols(protocols);
                newPortGroups.add(portGroup);
            } else {
                existingPortGroups.add(portGroup);
            }
        }
    }
    portGroups.put(NEW, newPortGroups);
    portGroups.put(EXISTING, existingPortGroups);
    return portGroups;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageVirtualMachineInfo(com.iwave.ext.netappc.StorageVirtualMachineInfo) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain)

Example 4 with StorageVirtualMachineInfo

use of com.iwave.ext.netappc.StorageVirtualMachineInfo 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 5 with StorageVirtualMachineInfo

use of com.iwave.ext.netappc.StorageVirtualMachineInfo in project coprhd-controller by CoprHD.

the class NetAppClusterApi method listSVM.

public List<StorageVirtualMachineInfo> listSVM() {
    List<StorageVirtualMachineInfo> svms = null;
    try {
        netAppClusterFacade = new NetAppClusterFacade(_ipAddress, _portNumber, _userName, _password, _https);
        svms = netAppClusterFacade.listSVM();
    } catch (Exception e) {
        _logger.info("No vSevrers discovered.");
    }
    return svms;
}
Also used : NetAppClusterFacade(com.iwave.ext.netappc.NetAppClusterFacade) StorageVirtualMachineInfo(com.iwave.ext.netappc.StorageVirtualMachineInfo)

Aggregations

StorageVirtualMachineInfo (com.iwave.ext.netappc.StorageVirtualMachineInfo)7 ArrayList (java.util.ArrayList)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 NetAppException (com.emc.storageos.netapp.NetAppException)5 NetAppCException (com.emc.storageos.netappc.NetAppCException)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 IOException (java.io.IOException)5 URI (java.net.URI)5 HashMap (java.util.HashMap)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 NetAppClusterApi (com.emc.storageos.netappc.NetAppClusterApi)4 StoragePort (com.emc.storageos.db.client.model.StoragePort)3 StringMap (com.emc.storageos.db.client.model.StringMap)3 UnManagedFSExportMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)3 UnManagedFileSystem (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem)3 UnManagedSMBShareMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap)3 List (java.util.List)3 Map (java.util.Map)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2