Search in sources :

Example 21 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method getFSSnapshotList.

// Get FS snapshot list from the array.
@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("NetAppFileStorageDevice getFSSnapshotList: {} - start", args.getFsName());
    BiosCommandResult result = new BiosCommandResult();
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
    try {
        List<String> deviceSnapshots = nApi.listSnapshots(args.getFsName());
        if (deviceSnapshots == null) {
            _log.warn("NetAppFileStorageDevice getFSSnapshotList {} - failed", args.getFsId());
            result.setCommandSuccess(false);
            result.setMessage("NetAppFileStorageDevice getFSSnapshotList failed for FS {}" + args.getFsName());
            result.setCommandStatus(Operation.Status.error.name());
        } else {
            for (String deviceSnapshotName : deviceSnapshots) {
                dbSnapshots.add(deviceSnapshotName);
            }
            _log.info("NetAppFileStorageDevice 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 (NetAppException 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 : BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppApi(com.emc.storageos.netapp.NetAppApi) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 22 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method updateExportRules.

@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    // 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<>();
    String exportPath;
    String subDir = args.getSubDirectory();
    if (!args.getFileOperation()) {
        exportPath = args.getSnapshotPath();
        if (subDir != null && subDir.length() > 0) {
            exportPath = args.getSnapshotPath() + "/" + subDir;
        }
    } else {
        exportPath = args.getFs().getPath();
        if (subDir != null && subDir.length() > 0) {
            exportPath = args.getFs().getPath() + "/" + subDir;
        }
    }
    _log.info("exportPath : {}", exportPath);
    args.setExportPath(exportPath);
    // ALL EXPORTS
    List<ExportRule> existingDBExportRule = args.getExistingDBExportRules();
    List<ExportRule> exportsToprocess = new ArrayList<>();
    for (ExportRule rule : existingDBExportRule) {
        if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
            exportsToprocess.add(rule);
        }
    }
    _log.info("Number of existng Rules found {}", exportsToprocess.size());
    // Handle Modified export Rules
    if (exportsToprocess != null && !exportsToprocess.isEmpty()) {
        for (ExportRule existingRule : exportsToprocess) {
            for (ExportRule modifiedrule : exportModify) {
                if (modifiedrule.getSecFlavor().equals(existingRule.getSecFlavor())) {
                    _log.info("Modifying Export Rule from {}, To {}", existingRule, modifiedrule);
                    // use a separate list to avoid concurrent modification exception for now.
                    exportsToRemove.add(existingRule);
                    exportsToAdd.add(modifiedrule);
                }
            }
        }
        // Handle Add export Rules
        if (exportAdd != null && !exportAdd.isEmpty()) {
            for (ExportRule newExport : exportAdd) {
                _log.info("Adding Export Rule {}", newExport);
                exportsToAdd.add(newExport);
            }
        }
        // Handle Delete export Rules
        if (exportDelete != null && !exportDelete.isEmpty()) {
            for (ExportRule existingRule : exportsToprocess) {
                for (ExportRule oldExport : exportDelete) {
                    if (oldExport.getSecFlavor().equals(existingRule.getSecFlavor())) {
                        _log.info("Deleting Export Rule {}", existingRule);
                        exportsToRemove.add(existingRule);
                    }
                }
            }
        }
        // No of exports found to remove from the list
        _log.info("No of exports found to remove from the existing exports list {}", exportsToRemove.size());
        exportsToprocess.removeAll(exportsToRemove);
        _log.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
        exportsToprocess.addAll(exportsToAdd);
        if (exportsToprocess.isEmpty() && !exportsToRemove.isEmpty()) {
            // If all exports rules deleted, export will get deleted too. So set back to its defaults
            ExportRule rule = new ExportRule();
            rule.setSecFlavor("sys");
            rule.setAnon("root");
            java.util.Set<String> roHosts = new HashSet<>();
            roHosts.add("Default");
            rule.setReadOnlyHosts(roHosts);
            exportsToprocess.add(rule);
        }
    } else {
        if (exportsToprocess == null) {
            exportsToprocess = new ArrayList<>();
        }
        exportsToprocess.addAll(exportAdd);
        exportsToprocess.addAll(exportModify);
    }
    // if only delete provided with no existing rules -- How do we handle this? [GOPI]
    _log.info("Number of Export Rules to update after processing found {}", exportsToprocess.size());
    BiosCommandResult result = new BiosCommandResult();
    try {
        String portGroup = null;
        if (args.getFileOperation() == true) {
            FileShare fileshare = args.getFs();
            portGroup = findVfilerName(fileshare);
        } else {
            // Get the FS from the snapshot
            URI snapshotUID = args.getSnapshotId();
            Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapshotUID);
            FileShare fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
            portGroup = findVfilerName(fileshare);
        }
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        if (!nApi.modifyNFSShare(exportPath, exportsToprocess)) {
            _log.error("NetAppFileStorageDevice updateFSExportRules {} - failed", args.getFsId());
            result.setMessage("NetAppFileStorageDevice updateFSExportRules {} - failed");
            result.setCommandStatus(Operation.Status.error.name());
            return result;
        }
        if ((args.getFileOperation() == true) && args.getSubDirectory() == null) {
            nApi.setQtreemode(exportPath, UNIX_QTREE_SETTING);
        }
    } catch (NetAppException e) {
        _log.info("Exception:" + e.getMessage());
        throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
    }
    _log.info("NetAppFileStorageDevice updateFSExportRules {} - complete", args.getFsId());
    result.setCommandSuccess(true);
    result.setCommandStatus(Operation.Status.ready.name());
    return result;
}
Also used : ArrayList(java.util.ArrayList) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) Snapshot(com.emc.storageos.db.client.model.Snapshot) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ExportRule(com.emc.storageos.model.file.ExportRule) NetAppApi(com.emc.storageos.netapp.NetAppApi) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Example 23 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method doExpandFS.

@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppFileStorageDevice 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";
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
        if (!nApi.setVolumeSize(volumeName, strNewFsSize)) {
            _log.error("NetAppFileStorageDevice doExpandFS - failed");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToExpandFileSystem();
            result = BiosCommandResult.createErrorResult(serviceError);
        } else {
            _log.info("NetAppFileStorageDevice doExpandFS - complete");
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doExpandFS failed with a NetAppException", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToExpandFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::doExpandFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToExpandFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppApi(com.emc.storageos.netapp.NetAppApi) NetAppException(com.emc.storageos.netapp.NetAppException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 24 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method modifyNtpShare.

/**
 * modify NetApp share with right permissions and other parameters
 *
 * @param StorageSystem mount path of the fileshare
 * @param args containing input/out arguments of filedevice
 * @param smbFileShare existingShare smbFileshare object that needs to be modified.
 * @param forceGroup Name of the group the fileshare belongs.
 * @return
 */
private Boolean modifyNtpShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare, String forceGroup, SMBFileShare existingShare) throws NetAppException {
    String portGroup = findVfilerName(args.getFs());
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
    // String shareId = args.getFileObj().getPath();
    String shareId = smbFileShare.getPath();
    if (!nApi.modifyShare(shareId, smbFileShare.getName(), smbFileShare.getDescription(), smbFileShare.getMaxUsers(), smbFileShare.getPermission(), forceGroup)) {
        _log.info("NetAppFileStorageDevice doShare (modification) for {} with id {} - failed", shareId, args.getFileObjId());
        return false;
    } else {
        _log.info("NetAppFileStorageDevice doShare (modification) for {} with id {} - complete", shareId, args.getFileObjId());
        return true;
    }
}
Also used : NetAppApi(com.emc.storageos.netapp.NetAppApi)

Example 25 with NetAppApi

use of com.emc.storageos.netapp.NetAppApi in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice 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 = findVfilerName(args.getFs());
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        List<String> fs = nApi.listFileSystems();
        if (!fs.isEmpty() && fs.contains(args.getFsName())) {
            isFSExists = true;
        } else {
            isFSExists = false;
        }
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doCheckFSExists failed with an Exception", e);
    }
    return isFSExists;
}
Also used : NetAppApi(com.emc.storageos.netapp.NetAppApi) NetAppException(com.emc.storageos.netapp.NetAppException)

Aggregations

NetAppApi (com.emc.storageos.netapp.NetAppApi)32 NetAppException (com.emc.storageos.netapp.NetAppException)26 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)18 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)18 ArrayList (java.util.ArrayList)15 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)14 ControllerException (com.emc.storageos.volumecontroller.ControllerException)14 HashMap (java.util.HashMap)11 URI (java.net.URI)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 NetAppFileCollectionException (com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)7 IOException (java.io.IOException)7 Map (java.util.Map)7 FileShare (com.emc.storageos.db.client.model.FileShare)6 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 VFilerInfo (com.iwave.ext.netapp.VFilerInfo)6 StringMap (com.emc.storageos.db.client.model.StringMap)5