Search in sources :

Example 11 with NetAppClusterApi

use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.

the class NetAppClusterModeDevice method rollbackShareACLs.

private BiosCommandResult rollbackShareACLs(StorageSystem storage, FileDeviceInputOutput args, List<ShareACL> existingList) {
    BiosCommandResult result = new BiosCommandResult();
    String portGroup = findSVMName(args.getFs());
    NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
    try {
        // We can have multiple ace added/modified in one put call ,some of them can fail due to some reason.
        // In case of failure, to make it consistent in vipr db and NetApp share, delete all currently
        // added and modified ace and revert it to old acl list
        _log.info("NetAppClusterModeDevice::Rolling back update ACL by trying delete ACL for share {}", args.getShareName());
        List<ShareACL> aclsToClear = new ArrayList<ShareACL>();
        aclsToClear.addAll(args.getShareAclsToAdd());
        aclsToClear.addAll(args.getShareAclsToModify());
        updateShareAcl(ncApi, args.getShareName(), aclsToClear, AclOperation.FORCE_DELETE);
        _log.info("NetAppClusterModeDevice::Adding back old ACL to Share {}", args.getShareName());
        updateShareAcl(ncApi, args.getShareName(), existingList, AclOperation.FORCE_ADD);
        result = BiosCommandResult.createSuccessfulResult();
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::Roll Back of ACL failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToUpdateCIFSShareAcl();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ArrayList(java.util.ArrayList) ShareACL(com.emc.storageos.model.file.ShareACL) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetAppCException(com.emc.storageos.netappc.NetAppCException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 12 with NetAppClusterApi

use of com.emc.storageos.netappc.NetAppClusterApi in project coprhd-controller by CoprHD.

the class NetAppClusterModeDevice method createNtpShare.

/**
 * create NetAppC share with right permissions
 *
 * @param StorageSystem mount path of the fileshare
 * @param args containing input/out arguments of filedevice
 * @param smbFileShare smbFileshare object
 * @param forceGroup Name of the group the fileshare belongs.
 * @return
 */
private Boolean createNtpShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare, String forceGroup) throws NetAppCException {
    String shareId = null;
    String portGroup = findSVMName(args.getFs());
    NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
    shareId = smbFileShare.getPath();
    _log.info("NetAppClusterModeDevice doShare for {} with id {}", shareId, args.getFileObjId());
    if (!ncApi.doShare(shareId, smbFileShare.getName(), smbFileShare.getDescription(), smbFileShare.getMaxUsers(), smbFileShare.getPermission(), forceGroup)) {
        _log.info("NetAppClusterModeDevice doShare for {} with id {} - failed", shareId, args.getFileObjId());
        return false;
    } else {
        // permission.
        if (!ncApi.modifyShare(shareId, smbFileShare.getName(), smbFileShare.getDescription(), smbFileShare.getMaxUsers(), smbFileShare.getPermission(), forceGroup)) {
            // Cleanup the share if permission update is
            // unsuccessful.
            doDeleteShare(storage, args, smbFileShare);
            _log.info("NetAppClusterModeDevice doShare for {} with id {} - failed", shareId, args.getFileObjId());
            return false;
        } else {
            smbFileShare.setNativeId(shareId);
            // share creation is successful,no need to set permission,clear the default one.
            List<CifsAcl> existingAcls = new ArrayList<CifsAcl>();
            CifsAcl defaultAcl = new CifsAcl();
            // By default NetApp share get everyone full access.
            defaultAcl.setUserName("everyone");
            defaultAcl.setAccess(CifsAccess.full);
            existingAcls.add(defaultAcl);
            ncApi.deleteCIFSShareAcl(smbFileShare.getName(), existingAcls);
            smbFileShare.setNetBIOSName(ncApi.getNetBiosName());
            _log.info("NetAppClusterModeDevice doShare for {} with id {} - complete", shareId, args.getFileObjId());
            return true;
        }
    }
}
Also used : NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) CifsAcl(com.iwave.ext.netappc.model.CifsAcl) ArrayList(java.util.ArrayList)

Example 13 with NetAppClusterApi

use of com.emc.storageos.netappc.NetAppClusterApi 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 14 with NetAppClusterApi

use of com.emc.storageos.netappc.NetAppClusterApi 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 15 with NetAppClusterApi

use of com.emc.storageos.netappc.NetAppClusterApi 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)

Aggregations

NetAppClusterApi (com.emc.storageos.netappc.NetAppClusterApi)29 NetAppCException (com.emc.storageos.netappc.NetAppCException)24 NetAppException (com.emc.storageos.netapp.NetAppException)20 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)18 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)18 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)16 ControllerException (com.emc.storageos.volumecontroller.ControllerException)14 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 IOException (java.io.IOException)5 URI (java.net.URI)5 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 StorageVirtualMachineInfo (com.iwave.ext.netappc.StorageVirtualMachineInfo)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 StringMap (com.emc.storageos.db.client.model.StringMap)3 UnManagedFSExportMap (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap)3