Search in sources :

Example 1 with NetAppClusterApi

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

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

the class NetAppClusterModeDevice method doDeleteFS.

@Override
public BiosCommandResult doDeleteFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppClusterModeDevice doDeleteFS - start");
        if (null == args.getFsName()) {
            _log.error("NetAppClusterModeDevice::doDeletFS failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
            serviceError.setMessage("Filesystem name is either missing or empty");
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        // Now get the SVM from the fileShare
        String portGroup = findSVMName(args.getFs());
        if (null != args.getFsShares() && !args.getFsShares().isEmpty()) {
            if (!netAppDeleteCIFSExports(storage, args.getFsShares(), portGroup)) {
                _log.info("NetAppClusterModeDevice doDeletFS:netAppDeleteCIFSExports {} - failed", args.getFsName());
            } else {
                _log.info("NetAppClusterModeDevice doDeletFS:netAppDeleteCIFSExports {} - succeeded", args.getFsName());
            }
        }
        boolean failedStatus = false;
        NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        if (!ncApi.deleteFS(args.getFsName())) {
            failedStatus = true;
        }
        if (failedStatus == true) {
            _log.error("NetAppClusterModeDevice doDeletFS {} - failed", args.getFsName());
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
            result = BiosCommandResult.createErrorResult(serviceError);
        } else {
            _log.info("NetAppClusterModeDevice doDeletFS {} - complete", args.getFsName());
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doDeleteFS failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doDeleteFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileSystem();
        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 3 with NetAppClusterApi

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

the class NetAppClusterModeDevice method netAppDeleteCIFSExports.

private Boolean netAppDeleteCIFSExports(StorageSystem storage, SMBShareMap currentShares, String portGroup) throws NetAppCException {
    int failedCount = 0;
    Iterator<Entry<String, SMBFileShare>> it = currentShares.entrySet().iterator();
    List<String> removedShareKeys = new ArrayList<String>();
    while (it.hasNext()) {
        Map.Entry<String, SMBFileShare> entry = it.next();
        String key = entry.getKey();
        SMBFileShare smbFileShare = entry.getValue();
        NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        if (!ncApi.deleteShare(smbFileShare.getName())) {
            failedCount++;
        } else {
            removedShareKeys.add(key);
        }
    }
    for (String keys : removedShareKeys) {
        currentShares.remove(keys);
    }
    if (failedCount > 0) {
        return false;
    } else {
        return true;
    }
}
Also used : Entry(java.util.Map.Entry) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) ArrayList(java.util.ArrayList) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) HashMap(java.util.HashMap) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Map(java.util.Map) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap)

Example 4 with NetAppClusterApi

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

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

the class NetAppClusterModeDevice method doCheckFSExists.

/**
 * Checking a file system: - Check if the FS exists on Array or not
 *
 * @param StorageSystem storage
 * @param args FileDeviceInputOutput
 * @return boolean true if exists else false
 * @throws ControllerException
 */
@Override
public boolean doCheckFSExists(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    _log.info("checking file system existence on array: ", args.getFsName());
    boolean isFSExists = true;
    try {
        String portGroup = findSVMName(args.getFs());
        NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        List<String> fs = ncApi.listFileSystems();
        if (!fs.isEmpty() && fs.contains(args.getFsName())) {
            isFSExists = true;
        } else {
            isFSExists = false;
        }
    } catch (NetAppException e) {
        _log.error("NetAppClusterModeDevice::doCheckFSExists failed with an Exception", e);
    }
    return isFSExists;
}
Also used : NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) NetAppException(com.emc.storageos.netapp.NetAppException)

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