Search in sources :

Example 6 with NetAppCException

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

the class NetAppClusterModeDevice method updateExportRules.

@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) {
    // Requested Export Rules
    List<ExportRule> exportAdd = args.getExportRulesToAdd();
    List<ExportRule> exportDelete = args.getExportRulesToDelete();
    List<ExportRule> exportModify = args.getExportRulesToModify();
    // To be processed export rules
    List<ExportRule> exportsToRemove = new ArrayList<>();
    List<ExportRule> exportsToAdd = new ArrayList<>();
    List<ExportRule> exportsRemove = new ArrayList<>();
    // ALL EXPORTS
    List<ExportRule> exportsToprocess = args.getExistingDBExportRules();
    String fsName = "";
    if (exportsToprocess == null) {
        exportsToprocess = new ArrayList<>();
    }
    _log.info("Number of existng Rules found {}", exportsToprocess.size());
    String exportPath;
    String subDir = args.getSubDirectory();
    BiosCommandResult result = new BiosCommandResult();
    if (!args.getFileOperation()) {
        _log.error("NetAppClusterModeDevice::updateExportRules {} : Snapshot export/unexport is not Supported", args.getSnapshotId());
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportSnapshot();
        serviceError.setMessage(genDetailedMessage("updateExportRules", args.getSnapshotId().toString(), "Snapshot export/unexport is not Supported"));
        result = BiosCommandResult.createErrorResult(serviceError);
        return result;
    } else {
        exportPath = args.getFs().getPath();
        if (subDir != null && subDir.length() > 0) {
            exportPath = args.getFs().getPath() + "/" + subDir;
        }
    }
    // if only delete provided with no existing rules -- How do we handle this?
    _log.info("Number of Export Rules to update after processing found {}", exportsToprocess.size());
    try {
        String portGroup = null;
        if (args.getFileOperation() == true) {
            FileShare fileshare = args.getFs();
            fsName = fileshare.getName();
            portGroup = findSVMName(fileshare);
        }
        NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        String qtreePath = "";
        String qtreeName = null;
        if (args.getFileOperation()) {
            qtreePath = exportPath;
            if (subDir != null && subDir.length() > 0) {
                if (ncApi.isQtree(args.getFsName(), subDir)) {
                    qtreeName = subDir;
                    qtreePath = constructQtreePath(args.getFsName(), subDir);
                } else {
                    _log.error("NetAppClusterModeDevice::updateExportRules {} : Sub-directory export/unexport is not Supported", args.getFsId());
                    ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
                    serviceError.setMessage(genDetailedMessage("updateExportRules", args.getFsId().toString(), "Sub-directory export/unexport is not Supported"));
                    result = BiosCommandResult.createErrorResult(serviceError);
                    return result;
                }
            }
        }
        _log.info("exportPath : {}", exportPath);
        args.setExportPath(exportPath);
        // Handle Modified export Rules
        if (!exportsToprocess.isEmpty()) {
            for (ExportRule existingRule : exportsToprocess) {
                if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
                    for (ExportRule modifiedrule : exportModify) {
                        if (modifiedrule.getSecFlavor().equals(existingRule.getSecFlavor())) {
                            _log.info("Modifying Export Rule from {}, To {}", existingRule, modifiedrule);
                            if (!ncApi.modifyNFSShare(fsName, qtreeName, qtreePath, existingRule, modifiedrule)) {
                                _log.error("NetAppClusterModeDevice updateFSExportRules {} - failed", args.getFsId());
                                result.setMessage("NetAppClusterModeDevice updateFSExportRules {} - failed");
                                result.setCommandStatus(Operation.Status.error.name());
                                return result;
                            }
                        }
                    }
                }
            }
            // Handle Add export Rules
            if (exportAdd != null && !exportAdd.isEmpty()) {
                for (ExportRule newExport : exportAdd) {
                    _log.info("Adding Export Rule {}", newExport);
                    if (!ncApi.addNFSShare(fsName, qtreeName, qtreePath, newExport)) {
                        _log.error("NetAppClusterModeDevice updateFSExportRules {} - failed", args.getFsId());
                        result.setMessage("NetAppClusterModeDevice updateFSExportRules {} - failed");
                        result.setCommandStatus(Operation.Status.error.name());
                        return result;
                    }
                }
            }
            // Handle Delete export Rules
            if (exportDelete != null && !exportDelete.isEmpty()) {
                for (ExportRule existingRule : exportsToprocess) {
                    if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
                        exportsToRemove.add(existingRule);
                        for (ExportRule oldExport : exportDelete) {
                            if (oldExport.getSecFlavor().equals(existingRule.getSecFlavor())) {
                                _log.info("Deleting Export Rule {}", existingRule);
                                exportsRemove.add(existingRule);
                                if (!ncApi.deleteNFSShare(fsName, qtreeName, existingRule, qtreePath)) {
                                    _log.error("NetAppClusterModeDevice updateFSExportRules {} - failed", args.getFsId());
                                    result.setMessage("NetAppClusterModeDevice updateFSExportRules {} - failed");
                                    result.setCommandStatus(Operation.Status.error.name());
                                    return result;
                                }
                            }
                        }
                    }
                }
            }
            // No of exports found to remove from the list
            _log.info("No of exports found to remove from the existing exports list {}", exportsRemove.size());
            exportsToRemove.removeAll(exportsRemove);
            _log.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
            // If we delete filesystem without deleting export policy. Export policy will not get cleared on Array.
            if (exportsToRemove.isEmpty() && !exportsRemove.isEmpty()) {
                ncApi.deleteNFSExport(qtreePath);
            }
        }
    } catch (NetAppCException e) {
        _log.info("Exception:" + e.getMessage());
        throw new DeviceControllerException("Exception while performing export for {0} - {1} ", new Object[] { args.getFsId(), e.getMessage() });
    }
    _log.info("NetAppClusterModeDevice updateFSExportRules {} - complete", args.getFsId());
    result.setCommandSuccess(true);
    result.setCommandStatus(Operation.Status.ready.name());
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppCException(com.emc.storageos.netappc.NetAppCException) ExportRule(com.emc.storageos.model.file.ExportRule) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 7 with NetAppCException

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

the class NetAppClusterModeDevice method doExpandFS.

@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppClusterModeDevice doExpandFS - start");
        long newFsExpandSize = args.getNewFSCapacity();
        String volumeName = args.getFsName();
        if (args.getNewFSCapacity() % BYTESPERMB == 0) {
            newFsExpandSize = newFsExpandSize / BYTESPERMB;
        } else {
            newFsExpandSize = newFsExpandSize / BYTESPERMB + 1;
        }
        _log.info("FileSystem new size translation : {} : {}", args.getNewFSCapacity(), newFsExpandSize);
        String strNewFsSize = String.valueOf(newFsExpandSize) + "m";
        String portGroup = findSVMName(args.getFs());
        NetAppClusterApi nApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        if (!nApi.setVolumeSize(volumeName, strNewFsSize)) {
            _log.error("NetAppClusterModeDevice doExpandFS - failed");
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToExpandFileSystem();
            result = BiosCommandResult.createErrorResult(serviceError);
        } else {
            _log.info("NetAppClusterModeDevice doExpandFS - complete");
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doExpandFS failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToExpandFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doExpandFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToExpandFileSystem();
        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) NetAppCException(com.emc.storageos.netappc.NetAppCException) 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 8 with NetAppCException

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

the class NetAppClusterModeDevice method getFSSnapshotList.

@Override
public BiosCommandResult getFSSnapshotList(StorageSystem storage, FileDeviceInputOutput args, List<String> dbSnapshots) throws ControllerException {
    if (null == args.getFsName()) {
        throw new DeviceControllerException("Filesystem name is either missing or empty", new Object[] {});
    }
    _log.info("NetAppClusterModeDevice getFSSnapshotList: {} - start", args.getFsName());
    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 {
        List<String> deviceSnapshots = ncApi.listSnapshots(args.getFsName());
        if (deviceSnapshots == null) {
            _log.warn("NetAppClusterModeDevice getFSSnapshotList {} - failed", args.getFsId());
            result.setCommandSuccess(false);
            result.setMessage("NetAppClusterModeDevice getFSSnapshotList failed for FS {}" + args.getFsName());
            result.setCommandStatus(Operation.Status.error.name());
        } else {
            for (String deviceSnapshotName : deviceSnapshots) {
                dbSnapshots.add(deviceSnapshotName);
            }
            _log.info("NetAppClusterModeDevice getFSSnapshotList - successful for filesystem, {} ", args.getFsName());
            result.setCommandSuccess(true);
            result.setCommandStatus(Operation.Status.ready.name());
            result.setMessage("List of snapshots for FS " + args.getFsName() + " was successfully retreived from device ");
        }
    } catch (NetAppCException e) {
        String[] params = { storage.getId().toString(), args.getFsName() };
        throw new DeviceControllerException("Failed to retrieve list of snapshots from device {1} for filesystem {2}", params);
    }
    return result;
}
Also used : NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppCException(com.emc.storageos.netappc.NetAppCException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 9 with NetAppCException

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

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

Aggregations

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