Search in sources :

Example 21 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot 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 22 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class NetAppFileStorageDevice method doDeleteShare.

/**
 * Deletes CIFS FileShare
 *
 * @param StorageSystem storage
 * @param FileDeviceInputOutput args
 * @param SMBFileShare smbFileShare
 * @return BiosCommandResult
 * @throws ControllerException
 */
@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppFileStorageDevice doDeleteShare - start");
        FileShare fileshare = null;
        if (args.getFileOperation() == true) {
            fileshare = args.getFs();
        } else {
            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
        String portGroup = findVfilerName(fileshare);
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        SMBShareMap shares = args.getFileObjShares();
        if (shares == null || shares.isEmpty()) {
            _log.error("NetAppFileStorageDevice::doDeleteShare failed: FileShare(s) is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
            serviceError.setMessage("FileShare(s) is either missing or empty");
            result = BiosCommandResult.createErrorResult(serviceError);
        }
        SMBFileShare fileShare = shares.get(smbFileShare.getName());
        if (fileShare != null) {
            if (!nApi.deleteShare(smbFileShare.getName())) {
                _log.error("NetAppFileStorageDevice doDeleteShare {} - failed", args.getFileObjId());
                ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
                serviceError.setMessage("Deletion of CIFS File Share failed");
                result = BiosCommandResult.createErrorResult(serviceError);
            } else {
                _log.info("NetAppFileStorageDevice doDeleteShare {} - complete", args.getFileObjId());
                args.getFileObjShares().remove(smbFileShare.getName());
                args.getFileObjShares().remove(smbFileShare.getNativeId());
                result = BiosCommandResult.createSuccessfulResult();
            }
        }
    } catch (NetAppException e) {
        _log.error("NetAppFileStorageDevice::doDeleteShare failed with a NetAppException", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppFileStorageDevice::doCreateFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netapp.unableToDeleteFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppApi(com.emc.storageos.netapp.NetAppApi) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) 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)

Example 23 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class VNXFileCommApi method doDeleteShare.

/**
 * Delete a CIFS Share
 *
 * @param system
 * @param moverOrVdm
 *            data mover the share is on.
 * @param shareName
 *            name of the CIFS share.
 * @return result of the operation.
 */
public XMLApiResult doDeleteShare(StorageSystem system, StorageHADomain moverOrVdm, String shareName, String mountPoint, boolean deleteMount, FileDeviceInputOutput args) {
    _log.info("CommApi: delete share {}", shareName);
    XMLApiResult result = new XMLApiResult();
    result.setCommandSuccess();
    Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
    try {
        updateAttributes(reqAttributeMap, system);
        if (null == moverOrVdm) {
            result.setCommandFailed();
            result.setMessage("Export failed:  data mover or VDM not found.");
            return result;
        }
        String moverOrVdmName = moverOrVdm.getAdapterName();
        String isVdm = "false";
        String moverOrVdmId = moverOrVdm.getName();
        reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverOrVdmId);
        reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
        if (moverOrVdm.getVirtual() != null && moverOrVdm.getVirtual() == true) {
            isVdm = "true";
        }
        _log.info("Using Mover {} to Delete share {}", moverOrVdmId + ":" + moverOrVdmName, shareName);
        updateAttributes(reqAttributeMap, system);
        reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverOrVdmId);
        reqAttributeMap.put(VNXFileConstants.DATAMOVER_NAME, moverOrVdmName);
        reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
        _provExecutor.setKeyMap(reqAttributeMap);
        _provExecutor.execute((Namespace) _provNamespaces.getNsList().get(PROV_CIFS_SERVERS));
        List<VNXCifsServer> cifsServers = (List<VNXCifsServer>) _provExecutor.getKeyMap().get(VNXFileConstants.CIFS_SERVERS);
        for (VNXCifsServer cifsServer : cifsServers) {
            _log.info("CIFServer:" + cifsServer.toString());
        }
        if (cifsServers == null || cifsServers.isEmpty()) {
            _log.info("No CIFS Servers retrieved for mover {} with id {}", moverOrVdmName, moverOrVdmId);
        }
        String netBios = null;
        // Only set netbios for VDM CIFS exports
        if (cifsServers != null && !cifsServers.isEmpty() && moverOrVdm.getVirtual()) {
            netBios = cifsServers.get(0).getName();
        }
        sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
        String data = sshApi.formatDeleteShareCmd(moverOrVdmName, shareName, netBios);
        _log.info("doDeleteShare command {}", data);
        result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
        FileShare fileShare = null;
        if (!args.getFileOperation()) {
            Snapshot snapshot = _dbClient.queryObject(Snapshot.class, args.getSnapshotId());
            fileShare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
        } else {
            fileShare = _dbClient.queryObject(FileShare.class, args.getFileObjId());
        }
        if (result.isCommandSuccess() && getVNXFSDependencies(fileShare, false) <= 1) {
            // FileSystem Mount Point
            // Delete the mount
            data = sshApi.formatUnMountCmd(moverOrVdmName, mountPoint, "CIFS");
            _log.info("Unmount filesystem command {}", data);
            result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
        }
        sshApi.clearConnParams();
    } catch (Exception e) {
        throw new VNXException("Failure", e);
    }
    return result;
}
Also used : VNXCifsServer(com.emc.storageos.vnx.xmlapi.VNXCifsServer) Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXSnapshot(com.emc.storageos.vnx.xmlapi.VNXSnapshot) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) FileObject(com.emc.storageos.db.client.model.FileObject) ArrayList(java.util.ArrayList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URISyntaxException(java.net.URISyntaxException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException)

Example 24 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class VNXFileCommApi method doDeleteExport.

public XMLApiResult doDeleteExport(final StorageSystem system, String exportPath, FileDeviceInputOutput args, boolean deleteMount) {
    XMLApiResult result = new XMLApiResult();
    result.setCommandSuccess();
    Map<String, Object> reqAttributeMap = new ConcurrentHashMap<String, Object>();
    _log.info("Delete VNX Export : {}", exportPath);
    if (exportPath == null || (exportPath != null && exportPath.isEmpty())) {
        _log.info("Invalid Export Path");
        return result;
    }
    try {
        updateAttributes(reqAttributeMap, system);
        String moverId;
        StorageHADomain dataMover = null;
        String mountPath = "";
        if (args.getFileOperation()) {
            StoragePort storagePort = _dbClient.queryObject(StoragePort.class, args.getFs().getStoragePort());
            URI dataMoverId = storagePort.getStorageHADomain();
            dataMover = _dbClient.queryObject(StorageHADomain.class, dataMoverId);
            moverId = dataMover.getName();
            mountPath = args.getFsMountPath();
            _log.info("Using Mover Id {} to unexport FS mounted at {}", moverId, exportPath);
            // Delete export from storage system.
            sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
            if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), exportPath).containsKey(exportPath)) {
                // Delete the Export.
                String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), exportPath);
                result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
            }
            // we check for any exports and share exists and then run umount operation
            if (result.isCommandSuccess() && getVNXFSDependencies(args.getFs(), false) <= 1) {
                // Delete the mount
                String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), mountPath, "NFS");
                result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
            }
            sshApi.clearConnParams();
        } else {
            String isVdm = "false";
            Snapshot snapshot = _dbClient.queryObject(Snapshot.class, args.getSnapshotId());
            FileShare fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
            StoragePort storagePort = _dbClient.queryObject(StoragePort.class, fileshare.getStoragePort());
            URI dataMoverId = storagePort.getStorageHADomain();
            dataMover = _dbClient.queryObject(StorageHADomain.class, dataMoverId);
            moverId = dataMover.getName();
            _log.info("Using Mover Id {} to unexport FS mounted at {}", moverId, exportPath);
            if (dataMover.getVirtual()) {
                isVdm = "true";
            }
            // Delete export from storage system.
            reqAttributeMap.put(VNXFileConstants.MOVER_ID, moverId);
            reqAttributeMap.put(VNXFileConstants.MOUNT_PATH, exportPath);
            reqAttributeMap.put(VNXFileConstants.ISVDM, isVdm);
            _provExecutor.setKeyMap(reqAttributeMap);
            sshApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
            if (sshApi.getNFSExportsForPath(dataMover.getAdapterName(), exportPath).containsKey(exportPath)) {
                String data = sshApi.formatDeleteNfsExportCmd(dataMover.getAdapterName(), exportPath);
                result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_EXPORT_CMD, data);
            }
            // Delete the Snapshot mount, only if No depending exports, shares for that snapshot.
            if (result.isCommandSuccess() && getVNXFSDependencies(args.getFs(), true) <= 1) {
                // Delete the mount
                String data = sshApi.formatUnMountCmd(dataMover.getAdapterName(), exportPath, "NFS");
                result = sshApi.executeSshRetry(VNXFileSshApi.SERVER_UNMOUNT_CMD, data);
            }
            sshApi.clearConnParams();
        }
    } catch (Exception e) {
        throw new VNXException("File Export Delete Exception: ", e);
    }
    return result;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXSnapshot(com.emc.storageos.vnx.xmlapi.VNXSnapshot) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) StoragePort(com.emc.storageos.db.client.model.StoragePort) FileObject(com.emc.storageos.db.client.model.FileObject) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URISyntaxException(java.net.URISyntaxException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException)

Example 25 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class VNXFileCommApi method getFSSnapshots.

private List<Snapshot> getFSSnapshots(FileShare fs) {
    URI fsId = fs.getId();
    List<Snapshot> snapshots = new ArrayList<Snapshot>();
    URIQueryResultList snapIDList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(fsId), snapIDList);
    while (snapIDList.iterator().hasNext()) {
        URI uri = snapIDList.iterator().next();
        Snapshot snap = _dbClient.queryObject(Snapshot.class, uri);
        if (!snap.getInactive()) {
            snapshots.add(snap);
        }
    }
    return snapshots;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXSnapshot(com.emc.storageos.vnx.xmlapi.VNXSnapshot) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

Snapshot (com.emc.storageos.db.client.model.Snapshot)92 FileShare (com.emc.storageos.db.client.model.FileShare)59 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)52 URI (java.net.URI)36 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 ControllerException (com.emc.storageos.volumecontroller.ControllerException)34 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)31 ArrayList (java.util.ArrayList)24 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)23 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)22 FileObject (com.emc.storageos.db.client.model.FileObject)21 URISyntaxException (java.net.URISyntaxException)21 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)19 WorkflowException (com.emc.storageos.workflow.WorkflowException)19 MapFileSnapshot (com.emc.storageos.api.mapper.functions.MapFileSnapshot)18 Path (javax.ws.rs.Path)18 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)17 Produces (javax.ws.rs.Produces)17