Search in sources :

Example 16 with FileShareExport

use of com.emc.storageos.volumecontroller.FileShareExport in project coprhd-controller by CoprHD.

the class FileSnapshotService method export.

/**
 * Add file share snapshot export.
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @param param
 *            File system export parameters
 * @brief Create file snapshot export
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep export(@PathParam("id") URI id, FileSystemExportParam param) throws InternalException {
    _log.info("Snapshot Export request recieved {}", id);
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    ArgValidator.checkEntity(snap, id, true);
    if (!param.getPermissions().equals(FileShareExport.Permissions.ro.name())) {
        throw APIException.badRequests.snapshotExportPermissionReadOnly();
    }
    ArgValidator.checkFieldValueFromEnum(param.getSecurityType(), "type", EnumSet.allOf(FileShareExport.SecurityTypes.class));
    ArgValidator.checkFieldValueFromEnum(param.getProtocol(), "protocol", EnumSet.allOf(StorageProtocol.File.class));
    ArgValidator.checkSubDirName("sub_directory", param.getSubDirectory());
    FileService.validateIpInterfacesRegistered(param.getEndpoints(), _dbClient);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    // Locate storage port for exporting file snap
    // We use file system in the call since file snap belongs to the same neighbourhood as its parent file system
    StoragePort sport = _fileScheduler.placeFileShareExport(fs, param.getProtocol(), param.getEndpoints());
    String path = snap.getPath();
    String mountPath = snap.getMountPath();
    _log.info("Check whether there is a NFS Export already for the path {}", path);
    FSExportMap exportMap = snap.getFsExports();
    if (exportMap != null) {
        Iterator it = snap.getFsExports().keySet().iterator();
        boolean exportExists = false;
        while (it.hasNext()) {
            String fsExpKey = (String) it.next();
            FileExport fileExport = snap.getFsExports().get(fsExpKey);
            _log.info("Snap export key {} does it exist ? {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
            if (fileExport.getPath().equalsIgnoreCase(path)) {
                exportExists = true;
                _log.info("Snap export key {} exist {}", fsExpKey + ":" + fileExport.getPath(), exportExists);
                break;
            }
        }
        if (exportExists) {
            throw APIException.badRequests.snapshotHasExistingExport();
        }
    }
    verifyFileSnapshotExports(snap, param, path);
    FileShareExport export = new FileShareExport(param.getEndpoints(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol(), sport.getPortGroup(), sport.getPortNetworkId(), path, mountPath, param.getSubDirectory(), param.getComments());
    _log.info("FileSnapExport --- FileSnap id: " + id + ", Clients: " + export.getClients() + ", StoragePort:" + sport.getPortName() + ", StoragePort :" + export.getStoragePort() + ", SecurityType: " + export.getSecurityType() + ", Permissions: " + export.getPermissions() + ", Root user mapping: " + export.getRootUserMapping() + ",Protocol: " + export.getProtocol() + ",path:" + export.getPath() + ",mountPath:" + export.getMountPath());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.EXPORT_FILE_SNAPSHOT);
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.export(device.getId(), snap.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.EXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), device.getId().toString(), export.getClients(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol());
    return toTask(snap, task, op);
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) Iterator(java.util.Iterator) FileExport(com.emc.storageos.db.client.model.FileExport) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 17 with FileShareExport

use of com.emc.storageos.volumecontroller.FileShareExport in project coprhd-controller by CoprHD.

the class FileDeviceController method unexport.

@Override
public void unexport(URI storage, URI fileUri, List<FileShareExport> exports, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fileUri, opId);
    FileObject fsObj = null;
    FileShare fs = null;
    Snapshot snapshotObj = null;
    StorageSystem storageObj = null;
    try {
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        boolean isFile = false;
        if (URIUtil.isType(fileUri, FileShare.class)) {
            isFile = true;
            fs = _dbClient.queryObject(FileShare.class, fileUri);
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
            fsObj = fs;
            args.addFSFileObject(fs);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
        } else {
            snapshotObj = _dbClient.queryObject(Snapshot.class, fileUri);
            fsObj = snapshotObj;
            fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
            args.addFileShare(fs);
            args.addSnapshotFileObject(snapshotObj);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
        }
        args.setFileOperation(isFile);
        args.setOpId(opId);
        _log.info("Export details...  ");
        List<FileExport> fileExports = new ArrayList<FileExport>();
        List<FileExportRule> exportRules = new ArrayList<FileExportRule>();
        if (exports != null) {
            for (FileShareExport fileShareExport : exports) {
                FileExport fileExport = fileShareExport.getFileExport();
                fileExports.add(fileExport);
                _log.info("FileExport:" + fileExport.getClients() + ":" + fileExport.getStoragePortName() + ":" + fileExport.getStoragePort() + ":" + fileExport.getRootUserMapping() + ":" + fileExport.getPermissions() + ":" + fileExport.getProtocol() + ":" + fileExport.getSecurityType() + ":" + fileExport.getMountPoint() + ":" + fileExport.getMountPath() + ":" + fileExport.getPath());
                _log.info("FileShareExport: " + fileExport.getFileExportKey());
                // Per New Model : Lets create the Export Rules, So these will not get missed.
                FileExportRule rule = getFileExportRule(fileUri, fileExport, args);
                exportRules.add(rule);
            }
        } else {
            _log.info("Exports are null");
        }
        WorkflowStepCompleter.stepExecuting(opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doUnexport(storageObj, args, fileExports);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        // Set status
        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        OperationTypeEnum auditType = (isFile) ? OperationTypeEnum.UNEXPORT_FILE_SYSTEM : OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT;
        if (result.isCommandSuccess()) {
            // Remove Export
            for (FileExport fileExport : fileExports) {
                fsObj.getFsExports().remove(fileExport.getFileExportKey());
                _log.info("FileShareExport removed : " + fileExport.getFileExportKey());
            }
            // Query Existing Export rule and if found set to delete.
            for (FileExportRule rule : exportRules) {
                URIQueryResultList dbresult = new URIQueryResultList();
                if (!args.getFileOperation() && rule.getSnapshotExportIndex() != null) {
                    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotExportRuleConstraint(rule.getSnapshotExportIndex()), dbresult);
                } else if (rule.getFsExportIndex() != null) {
                    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileExportRuleConstraint(rule.getFsExportIndex()), dbresult);
                }
                Iterator<URI> it = dbresult.iterator();
                while (it.hasNext()) {
                    if (dbresult.iterator().hasNext()) {
                        rule = _dbClient.queryObject(FileExportRule.class, it.next());
                        if (rule != null && !rule.getInactive()) {
                            _log.info("Existing DB Model found {}", rule);
                            rule.setInactive(true);
                            _dbClient.updateObject(rule);
                            break;
                        }
                    }
                }
            }
            FSExportMap exportsMap = fsObj.getFsExports();
            List<FileExport> fsExports = new ArrayList<FileExport>(exportsMap.values());
            if (isFile) {
                recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fsExports), fs, storageObj);
            } else {
                recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fsExports), snapshotObj, fs, storageObj);
            }
        }
        _dbClient.updateObject(fsObj);
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(opId);
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        String[] params = { storage.toString(), fileUri.toString(), e.getMessage() };
        _log.error("Unable to unexport file system or snapshot: storage {}, FS/snapshot URI {}: {}", params);
        for (FileShareExport fsExport : exports) {
            _log.error("{}  ", fsExport);
        }
        updateTaskStatus(opId, fsObj, e);
        if (URIUtil.isType(fileUri, FileShare.class)) {
            if ((fs != null) && (storageObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
            }
        } else {
            if ((fs != null) && (storageObj != null) && (snapshotObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
            }
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) ArrayList(java.util.ArrayList) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) 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) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) FileExport(com.emc.storageos.db.client.model.FileExport) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 18 with FileShareExport

use of com.emc.storageos.volumecontroller.FileShareExport in project coprhd-controller by CoprHD.

the class FileDeviceController method export.

@Override
public void export(URI storage, URI uri, List<FileShareExport> exports, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(uri, opId);
    FileObject fsObj = null;
    FileShare fs = null;
    Snapshot snapshotObj = null;
    StorageSystem storageObj = null;
    try {
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        boolean isFile = false;
        if (URIUtil.isType(uri, FileShare.class)) {
            isFile = true;
            fs = _dbClient.queryObject(FileShare.class, uri);
            fsObj = fs;
            args.addFSFileObject(fs);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
        } else {
            snapshotObj = _dbClient.queryObject(Snapshot.class, uri);
            fsObj = snapshotObj;
            fs = _dbClient.queryObject(FileShare.class, snapshotObj.getParent());
            args.addFileShare(fs);
            args.addSnapshotFileObject(snapshotObj);
            StoragePool pool = _dbClient.queryObject(StoragePool.class, fs.getPool());
            args.addStoragePool(pool);
            setVirtualNASinArgs(fs.getVirtualNAS(), args);
        }
        args.setFileOperation(isFile);
        args.setOpId(opId);
        _log.info("Export details...  ");
        List<FileExport> fileExports = new ArrayList<FileExport>();
        if (exports != null) {
            for (FileShareExport fileShareExport : exports) {
                args.setBypassDnsCheck(fileShareExport.getBypassDnsCheck());
                FileExport fExport = fileShareExport.getFileExport();
                fExport.setMountPoint(fileShareExport.getMountPath());
                _log.info("FileExport:clients:" + fExport.getClients() + ":portName:" + fExport.getStoragePortName() + ":port:" + fExport.getStoragePort() + ":rootMapping:" + fExport.getRootUserMapping() + ":permissions:" + fExport.getPermissions() + ":protocol:" + fExport.getProtocol() + ":security:" + fExport.getSecurityType() + ":mountpoint:" + fExport.getMountPoint() + ":path:" + fExport.getPath() + ":comments:" + fExport.getComments() + ":subDirectory:" + fExport.getSubDirectory());
                fileExports.add(fExport);
            }
        } else {
            _log.info("Exports are null");
        }
        // Acquire lock for VNXFILE Storage System
        acquireStepLock(storageObj, opId);
        WorkflowStepCompleter.stepExecuting(opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).doExport(storageObj, args, fileExports);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        // Set Mount path info for the exports
        FSExportMap fsExports = fsObj.getFsExports();
        // Per New model get the rules and see if any rules that are already saved and available.
        List<FileExportRule> existingRules = queryFileExports(args);
        if (null != fsExports) {
            Iterator it = fsExports.keySet().iterator();
            while (it.hasNext()) {
                String fsExpKey = (String) it.next();
                FileExport fileExport = fsObj.getFsExports().get(fsExpKey);
                if ((fileExport.getMountPath() != null) && (fileExport.getMountPath().length() > 0)) {
                    fileExport.setMountPoint(ExportUtils.getFileMountPoint(fileExport.getStoragePort(), fileExport.getMountPath()));
                } else {
                    fileExport.setMountPoint(ExportUtils.getFileMountPoint(fileExport.getStoragePort(), fileExport.getPath()));
                }
                _log.info("FileExport mountpath set to {} {}", fsExpKey, fileExport.getMountPoint());
                // Per New Model of Export Rules Lets create the rule and save it as FileExportRule.
                if (result.isCommandSuccess()) {
                    FileExportRule newRule = getFileExportRule(fsObj.getId(), fileExport, args);
                    _log.debug("ExportRule Constucted per expotkey {}, {}", fsExpKey, newRule);
                    if (existingRules != null && existingRules.isEmpty()) {
                        newRule.setId(URIUtil.createId(FileExportRule.class));
                        _log.info("No Existing rules available for this FS Export and so creating the rule now {}", newRule);
                        _dbClient.createObject(newRule);
                    } else {
                        _log.debug("Checking for existing rule(s) available for this export...");
                        boolean isRuleFound = false;
                        for (FileExportRule rule : existingRules) {
                            _log.debug("Available Export Rule {} - Matching with New Rule {}", rule, newRule);
                            if (newRule.getFsExportIndex() != null && rule.getFsExportIndex().equals(newRule.getFsExportIndex())) {
                                isRuleFound = true;
                                _log.info("Match Found : Skipping this rule as already available {}", newRule);
                                break;
                            }
                        }
                        if (!isRuleFound) {
                            _log.info("Creating new Export Rule {}", newRule);
                            newRule.setId(URIUtil.createId(FileExportRule.class));
                            _dbClient.createObject(newRule);
                            isRuleFound = false;
                        }
                    }
                }
            }
        }
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        OperationTypeEnum auditType = null;
        auditType = (isFile) ? OperationTypeEnum.EXPORT_FILE_SYSTEM : OperationTypeEnum.EXPORT_FILE_SNAPSHOT;
        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
        if (isFile) {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fileExports), fs, storageObj);
        } else {
            recordFileDeviceOperation(_dbClient, auditType, result.isCommandSuccess(), eventMsg, getExportClientExtensions(fileExports), snapshotObj, fs, storageObj);
        }
        _dbClient.updateObject(fsObj);
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(opId);
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        String[] params = { storage.toString(), uri.toString(), e.getMessage() };
        _log.error("Unable to export file system or snapshot: storage {}, FS/snapshot URI {}: {}", params);
        for (FileShareExport fsExport : exports) {
            _log.error("{}", fsExport);
        }
        updateTaskStatus(opId, fsObj, e);
        if (URIUtil.isType(uri, FileShare.class)) {
            if ((fs != null) && (storageObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.EXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
            }
        } else {
            if ((fs != null) && (storageObj != null) && (snapshotObj != null)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.EXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
            }
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) ArrayList(java.util.ArrayList) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) FileExport(com.emc.storageos.db.client.model.FileExport) Iterator(java.util.Iterator) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

FileExport (com.emc.storageos.db.client.model.FileExport)18 FileShareExport (com.emc.storageos.volumecontroller.FileShareExport)18 FileShare (com.emc.storageos.db.client.model.FileShare)17 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)15 Snapshot (com.emc.storageos.db.client.model.Snapshot)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 ControllerException (com.emc.storageos.volumecontroller.ControllerException)10 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)9 ArrayList (java.util.ArrayList)9 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)8 VNXeException (com.emc.storageos.vnxe.VNXeException)8 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)8 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)8 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)8 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 VNXeUnexportFileSystemJob (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeUnexportFileSystemJob)6 Operation (com.emc.storageos.db.client.model.Operation)5 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)5