Search in sources :

Example 1 with NetAppApi

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

the class NetAppFileStorageDevice method doExport.

@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    _log.info("NetAppFileStorageDevice doExport - start");
    // Verify inputs.
    validateExportArgs(exportList);
    List<String> rootHosts = new ArrayList<String>();
    List<String> rwHosts = new ArrayList<String>();
    List<String> roHosts = new ArrayList<String>();
    if (args.getFileObjExports() == null || args.getFileObjExports().isEmpty()) {
        args.initFileObjExports();
    }
    FSExportMap existingExpMap = args.getFileObjExports();
    List<FileExport> existingExportList = new ArrayList<FileExport>();
    FileExport existingExport = null;
    Iterator<String> it = existingExpMap.keySet().iterator();
    while (it.hasNext()) {
        existingExport = existingExpMap.get(it.next());
        _log.info("Existing export FileExport key : {} ", existingExport.getFileExportKey());
        existingExportList.add(existingExport);
    }
    // If it's a sub-directory no need to take existing hosts.
    boolean isSubDir = checkIfSubDirectory(args.getFsMountPath(), exportList.get(0).getMountPath());
    if (isSubDir) {
        existingExportList = null;
    }
    // TODO: Revisit once new Data Model for Exports is implemented.
    Map<String, List<String>> existingHosts = null;
    if ((null != existingExportList) && !existingExportList.isEmpty()) {
        existingHosts = sortHostsFromCurrentExports(existingExportList);
    }
    if (null != existingHosts) {
        if ((null != existingHosts.get(ROOT_HOSTS)) && !existingHosts.get(ROOT_HOSTS).isEmpty()) {
            addNewHostsOnly(rootHosts, existingHosts.get(ROOT_HOSTS));
        }
        if ((null != existingHosts.get(RW_HOSTS)) && !existingHosts.get(RW_HOSTS).isEmpty()) {
            addNewHostsOnly(rwHosts, existingHosts.get(RW_HOSTS));
        }
        if ((null != existingHosts.get(RO_HOSTS)) && !existingHosts.get(RO_HOSTS).isEmpty()) {
            addNewHostsOnly(roHosts, existingHosts.get(RO_HOSTS));
        }
    }
    BiosCommandResult result = new BiosCommandResult();
    try {
        for (int expCount = 0; expCount < exportList.size(); expCount++) {
            FileExport export = exportList.get(expCount);
            if (!(export.getMountPath().startsWith(VOL_ROOT_NO_SLASH))) {
                export.setMountPath(VOL_ROOT_NO_SLASH + export.getMountPath());
            }
            FileExport fileExport = new FileExport(export.getClients(), export.getStoragePortName(), export.getMountPoint(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getProtocol(), export.getStoragePort(), export.getPath(), export.getMountPath(), export.getSubDirectory(), export.getComments());
            args.getFileObjExports().put(fileExport.getFileExportKey(), fileExport);
            String portGroup = null;
            FileShare fileshare = null;
            if (args.getFileOperation() == true) {
                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 = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
                // Now get the VFiler from the fileshare
                portGroup = findVfilerName(fileshare);
            }
            NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
            List<String> endpointsList = export.getClients();
            if (endpointsList == null) {
                _log.error("NetAppFileStorageDevice::doExport {} failed:  No endpoints specified", args.getFsId());
                ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
                serviceError.setMessage(FileSystemConstants.FS_ERR_NO_ENDPOINTS_SPECIFIED);
                result = BiosCommandResult.createErrorResult(serviceError);
                return result;
            }
            sortNewEndPoints(rootHosts, rwHosts, roHosts, endpointsList, export.getPermissions());
            String root_user = export.getRootUserMapping();
            String mountPath = export.getMountPath();
            String exportPath = export.getPath();
            if (!nApi.exportFS(exportPath, mountPath, rootHosts, rwHosts, roHosts, root_user, export.getSecurityType())) {
                _log.error("NetAppFileStorageDevice::doExport {} failed", args.getFsId());
                ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
                serviceError.setMessage(genDetailedMessage("doExport", args.getFsId().toString()));
                result = BiosCommandResult.createErrorResult(serviceError);
                return result;
            }
            result = BiosCommandResult.createSuccessfulResult();
            if ((args.getFileOperation() == true) && (isSubDir == false)) {
                nApi.setQtreemode(exportPath, UNIX_QTREE_SETTING);
            }
        }
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doExport failed with a NetAppException", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::doExport failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToExportFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    _log.info("NetAppFileStorageDevice::doExport {} - complete", args.getFsId());
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) 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) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException) Snapshot(com.emc.storageos.db.client.model.Snapshot) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) List(java.util.List) NetAppApi(com.emc.storageos.netapp.NetAppApi)

Example 2 with NetAppApi

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

the class NetAppFileStorageDevice method doDeleteSnapshot.

@Override
public BiosCommandResult doDeleteSnapshot(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    if (null == args.getFsName()) {
        throw new DeviceControllerException("Filesystem name is either missing or empty", new Object[] {});
    }
    if (null == args.getSnapshotName()) {
        throw new DeviceControllerException("Snapshot name is either missing or empty for filesystem name {0}", new Object[] { args.getFsName() });
    }
    _log.info("NetAppFileStorageDevice doDeleteSnapshot: {},{} - start", args.getSnapshotId(), args.getSnapshotName());
    BiosCommandResult result = new BiosCommandResult();
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
    try {
        if (!nApi.deleteSnapshot(args.getFsName(), args.getSnapshotName())) {
            _log.error("NetAppFileStorageDevice doDeleteSnapshot {} - failed", args.getFsId());
            result.setCommandSuccess(false);
            result.setMessage("NetAppFileStorageDevice doDeleteSnapshot - failed");
            result.setCommandStatus(Operation.Status.error.name());
        } else {
            _log.info("doDeleteSnapshot for snapshot {} on filesystem {} successful", args.getSnapshotName(), args.getFsName());
            result.setCommandSuccess(true);
            result.setCommandStatus(Operation.Status.ready.name());
            result.setMessage("Snapshot," + args.getSnapshotName() + " has been successfully deleted");
        }
    } catch (NetAppException e) {
        throw new DeviceControllerException("Failed to delete snapshot, {0} for filesystem, {1} with: {2}", new Object[] { args.getSnapshotName(), args.getFsName(), e.getMessage() });
    }
    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 3 with NetAppApi

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

the class NetAppFileStorageDevice method updateShareACLs.

@Override
public BiosCommandResult updateShareACLs(StorageSystem storage, FileDeviceInputOutput args) {
    List<ShareACL> existingAcls = new ArrayList<ShareACL>();
    existingAcls = args.getExistingShareAcls();
    BiosCommandResult result = new BiosCommandResult();
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
    try {
        processAclsForShare(nApi, args);
        result = BiosCommandResult.createSuccessfulResult();
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::updateShareACLs failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToUpdateCIFSShareAcl();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
        // if delete or modify fails , revert to old acl
        _log.info("update ACL failed ,going to roll back to existing ACLs");
        rollbackShareACLs(storage, args, existingAcls);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ArrayList(java.util.ArrayList) NetAppApi(com.emc.storageos.netapp.NetAppApi) ShareACL(com.emc.storageos.model.file.ShareACL) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 4 with NetAppApi

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

the class NetAppFileStorageDevice method doRestoreFS.

@Override
public BiosCommandResult doRestoreFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppFileStorageDevice doRestoreFS - start");
        if (null == args.getFsName()) {
            _log.error("NetAppFileStorageDevice::doRestoreFS failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
            serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (null == args.getSnapshotName()) {
            _log.error("NetAppFileStorageDevice::doRestoreFS failed:  Snapshot name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
            serviceError.setMessage(FileSystemConstants.FS_ERR_SNAPSHOT_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
        if (!nApi.restoreSnapshot(args.getFsName(), args.getSnapshotName())) {
            _log.error("NetAppFileStorageDevice doRestoreFS {} - failed", args.getFsName());
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
            result = BiosCommandResult.createErrorResult(serviceError);
        } else {
            _log.info("doRestoreFS - restore of snapshot, {}  was successfully for filesystem, {} ", args.getSnapshotName(), args.getFsName());
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doRestoreFS failed with a NetAppException", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::doRestoreFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToRestoreFileSystem();
        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 5 with NetAppApi

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

the class NetAppFileStorageDevice method netAppDeleteCIFSExports.

private Boolean netAppDeleteCIFSExports(StorageSystem storage, SMBShareMap currentShares, String portGroup) throws NetAppException {
    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();
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        if (!nApi.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) ArrayList(java.util.ArrayList) NetAppApi(com.emc.storageos.netapp.NetAppApi) 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)

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