Search in sources :

Example 6 with FileShareExport

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

the class VNXeStorageDevice method doUnexport.

@Override
public BiosCommandResult doUnexport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    _logger.info("unexporting the file system: " + args.getFsName());
    boolean isFile = args.getFileOperation();
    for (FileExport exp : exportList) {
        VNXeApiClient apiClient = getVnxeClient(storage);
        String vnxeShareId = exp.getIsilonId();
        VNXeCommandJob job = null;
        VNXeFileTaskCompleter completer = null;
        try {
            if (isFile) {
                String fsId = args.getFs().getNativeId();
                job = apiClient.removeNfsShare(vnxeShareId, fsId);
            } else {
                job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
            }
            if (job != null) {
                if (isFile) {
                    completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                } else {
                    completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                }
                FileShareExport export = new FileShareExport(exp);
                VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, export, export.getPath(), isFile);
                ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
            } else {
                _logger.error("No job returned from exportFileSystem");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
                return BiosCommandResult.createErrorResult(error);
            }
        } catch (VNXeException e) {
            _logger.error("Unexport file system got the exception", e);
            if (completer != null) {
                completer.error(_dbClient, e);
            }
            return BiosCommandResult.createErrorResult(e);
        } catch (Exception ex) {
            _logger.error("Delete file system got the exception", ex);
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", ex.getMessage());
            if (completer != null) {
                completer.error(_dbClient, error);
            }
            return BiosCommandResult.createErrorResult(error);
        }
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Unexport filesystem job submitted - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
        _logger.info(logMsgBuilder.toString());
    }
    return BiosCommandResult.createPendingResult();
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeFileTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) VNXeException(com.emc.storageos.vnxe.VNXeException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeException(com.emc.storageos.vnxe.VNXeException) FileExport(com.emc.storageos.db.client.model.FileExport) VNXeUnexportFileSystemJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeUnexportFileSystemJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Example 7 with FileShareExport

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

the class VNXeStorageDevice method doExport.

@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    _logger.info("exporting the file system: " + args.getFsName());
    if (args.getFileObjExports() == null || args.getFileObjExports().isEmpty()) {
        args.initFileObjExports();
    }
    for (FileExport exp : exportList) {
        VNXeApiClient apiClient = getVnxeClient(storage);
        String fsId = args.getFs().getNativeId();
        String fsName = args.getFsName();
        String permission = exp.getPermissions();
        String path = "/";
        String subdirName = "";
        String mountPathArg = exp.getMountPath();
        String comments = exp.getComments();
        VNXeCommandJob job = null;
        VNXeFileTaskCompleter completer = null;
        String exportKey = exp.getFileExportKey();
        FileShareExport newExport = new FileShareExport(exp);
        try {
            AccessEnum access = null;
            List<String> roClients = null;
            List<String> rwClients = null;
            List<String> rootClients = null;
            FileExport existingExport = null;
            if (args.getFileOperation()) {
                FSExportMap exportMap = args.getFileObjExports();
                existingExport = exportMap.get(exportKey);
            } else {
                FSExportMap exportMap = args.getSnapshotExports();
                existingExport = exportMap.get(exportKey);
            }
            if (existingExport != null) {
                if (permission.equalsIgnoreCase(FileShareExport.Permissions.rw.name())) {
                    access = AccessEnum.READWRITE;
                    if (existingExport.getClients() != null && !existingExport.getClients().isEmpty()) {
                        if (rwClients == null) {
                            rwClients = new ArrayList<String>();
                        }
                        rwClients.addAll(existingExport.getClients());
                    }
                } else if (permission.equalsIgnoreCase(FileShareExport.Permissions.ro.name())) {
                    access = AccessEnum.READ;
                    if (existingExport.getClients() != null && !existingExport.getClients().isEmpty()) {
                        if (roClients == null) {
                            roClients = new ArrayList<String>();
                        }
                        roClients.addAll(existingExport.getClients());
                    }
                } else if (permission.equalsIgnoreCase(FileShareExport.Permissions.root.name())) {
                    access = AccessEnum.ROOT;
                    if (existingExport.getClients() != null && !existingExport.getClients().isEmpty()) {
                        if (rootClients == null) {
                            rootClients = new ArrayList<String>();
                        }
                        rootClients.addAll(existingExport.getClients());
                    }
                }
            }
            if (permission.equalsIgnoreCase(FileShareExport.Permissions.rw.name())) {
                access = AccessEnum.READWRITE;
                if (exp.getClients() != null && !exp.getClients().isEmpty()) {
                    if (rwClients == null) {
                        rwClients = new ArrayList<String>();
                    }
                    rwClients.addAll(exp.getClients());
                }
            } else if (permission.equalsIgnoreCase(FileShareExport.Permissions.ro.name())) {
                access = AccessEnum.READ;
                if (exp.getClients() != null && !exp.getClients().isEmpty()) {
                    if (roClients == null) {
                        roClients = new ArrayList<String>();
                    }
                    roClients.addAll(exp.getClients());
                }
            } else if (permission.equalsIgnoreCase(FileShareExport.Permissions.root.name())) {
                access = AccessEnum.ROOT;
                if (exp.getClients() != null && !exp.getClients().isEmpty()) {
                    if (rootClients == null) {
                        rootClients = new ArrayList<String>();
                    }
                    rootClients.addAll(exp.getClients());
                }
            }
            if (args.getFileOperation()) {
                String mountPathFs = args.getFsMountPath();
                if (!mountPathArg.equals(mountPathFs)) {
                    // subdirectory specified.
                    subdirName = mountPathArg.substring(mountPathFs.length() + 1);
                    path += subdirName;
                }
                String shareName = VNXeUtils.buildNfsShareName(fsName, subdirName);
                job = apiClient.exportFileSystem(fsId, roClients, rwClients, rootClients, access, path, shareName, null, comments);
                if (job != null) {
                    completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                    VNXeExportFileSystemJob exportFSJob = new VNXeExportFileSystemJob(job.getId(), storage.getId(), completer, newExport, shareName, true);
                    ControllerServiceImpl.enqueueJob(new QueueJob(exportFSJob));
                } else {
                    _logger.error("No job returned from exportFileSystem");
                    ServiceError error = DeviceControllerErrors.vnxe.jobFailed("exportFileSystem", "No Job returned from exportFileSystem");
                    return BiosCommandResult.createErrorResult(error);
                }
            } else {
                String snapId = args.getSnapNativeId();
                String snapName = args.getSnapshotName();
                String shareName = VNXeUtils.buildNfsShareName(snapName, path);
                job = apiClient.createNfsShareForSnap(snapId, roClients, rwClients, rootClients, access, path, shareName, comments);
                if (job != null) {
                    completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                    VNXeExportFileSystemJob exportFSJob = new VNXeExportFileSystemJob(job.getId(), storage.getId(), completer, newExport, shareName, false);
                    ControllerServiceImpl.enqueueJob(new QueueJob(exportFSJob));
                } else {
                    _logger.error("No job returned from exportFileSystem");
                    ServiceError error = DeviceControllerErrors.vnxe.jobFailed("exportFileSystem", "No Job returned from exportFileSystem");
                    return BiosCommandResult.createErrorResult(error);
                }
            }
        } catch (VNXeException e) {
            _logger.error("Export file system got the exception", e);
            if (completer != null) {
                completer.error(_dbClient, e);
            }
            return BiosCommandResult.createErrorResult(e);
        } catch (Exception ex) {
            _logger.error("export file system got the exception", ex);
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("exportFileSystem", ex.getMessage());
            if (completer != null) {
                completer.error(_dbClient, error);
            }
            return BiosCommandResult.createErrorResult(error);
        }
        _logger.info("Export job submitted");
    }
    return BiosCommandResult.createPendingResult();
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ArrayList(java.util.ArrayList) VNXeFileTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) VNXeException(com.emc.storageos.vnxe.VNXeException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeExportFileSystemJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeExportFileSystemJob) VNXeException(com.emc.storageos.vnxe.VNXeException) FileExport(com.emc.storageos.db.client.model.FileExport) AccessEnum(com.emc.storageos.vnxe.models.AccessEnum) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Example 8 with FileShareExport

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

the class VNXeStorageDevice 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> newExportsForDelete = new ArrayList<>();
    VNXeFileTaskCompleter completer = null;
    VNXeApiClient apiClient = getVnxeClient(storage);
    String subDir = args.getSubDirectory();
    // ALL EXPORTS
    List<ExportRule> exportsToprocess = args.getExistingDBExportRules();
    Map<String, ArrayList<ExportRule>> existingExportsMapped = new HashMap();
    try {
        String exportPath;
        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;
            }
        }
        _logger.info("exportPath : {}", exportPath);
        args.setExportPath(exportPath);
        try {
            // add the new export rule from the array into the update request.
            Map<String, ExportRule> arrayExportRuleMap = extraExportRuleFromArray(storage, args);
            if (!arrayExportRuleMap.isEmpty()) {
                if (exportModify != null) {
                    // merge the end point for which sec flavor is common.
                    for (ExportRule exportRule : exportModify) {
                        ExportRule arrayExportRule = arrayExportRuleMap.remove(exportRule.getSecFlavor());
                        if (arrayExportRule != null) {
                            if (exportRule.getReadOnlyHosts() != null) {
                                exportRule.getReadOnlyHosts().addAll(arrayExportRule.getReadOnlyHosts());
                            } else {
                                exportRule.setReadOnlyHosts(arrayExportRule.getReadOnlyHosts());
                            }
                            if (exportRule.getReadWriteHosts() != null) {
                                exportRule.getReadWriteHosts().addAll(arrayExportRule.getReadWriteHosts());
                            } else {
                                exportRule.setReadWriteHosts(arrayExportRule.getReadWriteHosts());
                            }
                            if (exportRule.getRootHosts() != null) {
                                exportRule.getRootHosts().addAll(arrayExportRule.getRootHosts());
                            } else {
                                exportRule.setRootHosts(arrayExportRule.getRootHosts());
                            }
                        }
                    }
                    // now add the remaining export rule
                    exportModify.addAll(arrayExportRuleMap.values());
                } else {
                    // if exportModify is null then create a new export rule and add
                    exportModify = new ArrayList<ExportRule>();
                    exportModify.addAll(arrayExportRuleMap.values());
                }
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            _logger.error("Not able to fetch latest Export rule from backend array.", e);
        }
        if (exportsToprocess == null) {
            exportsToprocess = new ArrayList<>();
        }
        _logger.info("Number of existng Rules found {}", exportsToprocess.size());
        // Process Exports
        for (ExportRule existingRule : exportsToprocess) {
            ArrayList<ExportRule> exps = existingExportsMapped.get(existingRule.getExportPath());
            if (exps == null) {
                exps = new ArrayList<>();
            }
            exps.add(existingRule);
            _logger.info("Checking existing export for {} : exps : {}", existingRule.getExportPath(), exps);
            existingExportsMapped.put(existingRule.getExportPath(), exps);
        }
        // Handle Add export Rules
        if (exportAdd != null && !exportAdd.isEmpty()) {
            // Check for existing exports for the export path including subdirectory
            ArrayList<ExportRule> exps = existingExportsMapped.get(exportPath);
            if (exps != null && !exps.isEmpty()) {
                _logger.error("Adding export rules is not supported as there can be only one export rule for VNXe.");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", "Adding export rule is not supported for VNXe");
                return BiosCommandResult.createErrorResult(error);
            }
        }
        // Handle Modified export Rules
        if (!exportsToprocess.isEmpty()) {
            if (subDir != null && !subDir.isEmpty()) {
                for (ExportRule existingRule : exportsToprocess) {
                    if (existingRule.getExportPath().endsWith("/" + subDir)) {
                        // Filter for a specific Sub Directory export
                        _logger.info("Updating all subdir exports rules at ViPR and  sub directory export at device {}", subDir);
                        processModifyRules(exportModify, existingRule, exportsToRemove, exportsToAdd);
                    } else {
                        exportsToRemove.add(existingRule);
                    }
                }
                // Handle Delete export Rules
                if (exportDelete != null && !exportDelete.isEmpty()) {
                    for (ExportRule existingRule : exportsToprocess) {
                        if (existingRule.getExportPath().endsWith("/" + subDir)) {
                            processDeleteRules(exportDelete, existingRule, exportsToRemove, newExportsForDelete);
                        } else {
                            exportsToRemove.add(existingRule);
                        }
                    }
                    exportsToAdd.addAll(newExportsForDelete);
                }
            } else {
                for (ExportRule existingRule : exportsToprocess) {
                    if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
                        processModifyRules(exportModify, existingRule, exportsToRemove, exportsToAdd);
                    } else {
                        exportsToRemove.add(existingRule);
                    }
                }
                // Handle Delete export Rules
                if (exportDelete != null && !exportDelete.isEmpty()) {
                    for (ExportRule existingRule : exportsToprocess) {
                        if (existingRule.getExportPath().equalsIgnoreCase(exportPath)) {
                            processDeleteRules(exportDelete, existingRule, exportsToRemove, newExportsForDelete);
                        } else {
                            exportsToRemove.add(existingRule);
                        }
                    }
                    exportsToAdd.addAll(newExportsForDelete);
                }
            }
            // No of exports found to remove from the list
            _logger.info("No of exports found to remove from the existing exports list {}", exportsToRemove.size());
            exportsToprocess.removeAll(exportsToRemove);
            _logger.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
            exportsToprocess.addAll(exportsToAdd);
        } else {
            // This is valid only if no rules to modify exists
            if (exportAdd != null && !exportAdd.isEmpty()) {
                for (ExportRule newExport : exportAdd) {
                    if (args.getFileObjExports() != null) {
                        Collection<FileExport> expList = args.getFileObjExports().values();
                        Iterator<FileExport> it = expList.iterator();
                        FileExport exp = null;
                        while (it.hasNext()) {
                            FileExport export = it.next();
                            if (export.getPath().equalsIgnoreCase(exportPath)) {
                                exp = export;
                            }
                        }
                        if (exp != null) {
                            if (exp.getIsilonId() != null) {
                                newExport.setDeviceExportId(exp.getIsilonId());
                            }
                            if (exp.getNativeId() != null) {
                                newExport.setDeviceExportId(exp.getNativeId());
                            }
                        }
                    }
                    _logger.info("Add Export Rule {}", newExport);
                    newExport.setExportPath(exportPath);
                    exportsToAdd.add(newExport);
                }
            }
            exportsToprocess.addAll(exportsToAdd);
        }
        _logger.info("exportPath : {}", exportPath);
        args.setExportPath(exportPath);
        VNXeCommandJob job = null;
        for (ExportRule rule : exportsToprocess) {
            AccessEnum access = null;
            List<String> roHosts = null;
            List<String> rwHosts = null;
            List<String> rootHosts = null;
            String path = "/";
            String subdirName = "";
            String mountPathFs = args.getFsMountPath();
            String shareName = null;
            FileShareExport fsExport = null;
            boolean isDeleteRule = false;
            if (args.getFileObjExports() != null) {
                Collection<FileExport> expList = args.getFileObjExports().values();
                Iterator<FileExport> it = expList.iterator();
                FileExport exp = null;
                while (it.hasNext()) {
                    FileExport export = it.next();
                    if (export.getPath().equalsIgnoreCase(rule.getExportPath())) {
                        exp = export;
                    }
                }
                fsExport = new FileShareExport(exp);
            }
            String mountPathArg = rule.getExportPath();
            if (rule.getReadWriteHosts() != null && !rule.getReadWriteHosts().isEmpty()) {
                access = AccessEnum.READWRITE;
                if (rwHosts == null) {
                    rwHosts = new ArrayList<String>();
                }
                rwHosts.addAll(rule.getReadWriteHosts());
            }
            if (rule.getReadOnlyHosts() != null && !rule.getReadOnlyHosts().isEmpty()) {
                access = AccessEnum.READ;
                if (roHosts == null) {
                    roHosts = new ArrayList<String>();
                }
                roHosts.addAll(rule.getReadOnlyHosts());
            }
            if (rule.getRootHosts() != null && !rule.getRootHosts().isEmpty()) {
                access = AccessEnum.ROOT;
                if (rootHosts == null) {
                    rootHosts = new ArrayList<String>();
                }
                rootHosts.addAll(rule.getRootHosts());
            }
            if (newExportsForDelete.contains(rule)) {
                isDeleteRule = true;
            }
            if (args.getFileOperation()) {
                if (!mountPathArg.equals(mountPathFs)) {
                    // subdirectory specified.
                    subdirName = mountPathArg.substring(mountPathFs.length() + 1);
                    path += subdirName;
                }
                if (isDeleteRule) {
                    job = apiClient.removeNfsShare(rule.getDeviceExportId(), args.getFs().getNativeId());
                    if (job != null) {
                        completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                        VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, args.getExportPath(), true);
                        ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
                    } else {
                        _logger.error("No job returned from unexport FileSystem");
                        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("UnExportFileSystem", "No Job returned from UnExportFileSystem");
                        return BiosCommandResult.createErrorResult(error);
                    }
                } else {
                    job = apiClient.exportFileSystem(args.getFs().getNativeId(), roHosts, rwHosts, rootHosts, access, path, null, rule.getDeviceExportId(), null);
                    if (job != null) {
                        completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                        VNXeModifyExportJob modifyExportJob = new VNXeModifyExportJob(job.getId(), storage.getId(), completer, rule, fsExport, args.getExportPath(), args.getFileOperation(), isDeleteRule, shareName);
                        ControllerServiceImpl.enqueueJob(new QueueJob(modifyExportJob));
                    } else {
                        _logger.error("No job returned from updateExportRules");
                        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", "No Job returned from updateExportRules");
                        return BiosCommandResult.createErrorResult(error);
                    }
                }
            } else {
                shareName = VNXeUtils.buildNfsShareName(args.getSnapshotName(), path);
                if (isDeleteRule) {
                    job = apiClient.deleteNfsShareForSnapshot(rule.getDeviceExportId());
                    if (job != null) {
                        completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                        VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, rule.getExportPath(), false);
                        ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
                    } else {
                        _logger.error("No job returned from unexportFileSystem Snapshot");
                        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("UnExportFileSystem", "No Job returned from UnExportFileSystem");
                        return BiosCommandResult.createErrorResult(error);
                    }
                } else {
                    job = apiClient.createNfsShareForSnap(args.getSnapNativeId(), roHosts, rwHosts, rootHosts, access, path, shareName, null);
                    if (job != null) {
                        completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                        VNXeModifyExportJob modifyExportJob = new VNXeModifyExportJob(job.getId(), storage.getId(), completer, rule, fsExport, args.getExportPath(), args.getFileOperation(), isDeleteRule, shareName);
                        ControllerServiceImpl.enqueueJob(new QueueJob(modifyExportJob));
                    } else {
                        _logger.error("No job returned from updateExportRules");
                        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", "No Job returned from updateExportRules");
                        return BiosCommandResult.createErrorResult(error);
                    }
                }
            }
        }
    } catch (VNXeException e) {
        _logger.error("updateExportRules got the exception", e);
        if (completer != null) {
            completer.error(_dbClient, e);
        }
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception ex) {
        _logger.error("updateExportRules got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("updateExportRules", ex.getMessage());
        if (completer != null) {
            completer.error(_dbClient, error);
        }
        return BiosCommandResult.createErrorResult(error);
    }
    _logger.info("UpdateExportRules job submitted");
    return BiosCommandResult.createPendingResult();
}
Also used : VNXeModifyExportJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeModifyExportJob) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VNXeFileTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) AccessEnum(com.emc.storageos.vnxe.models.AccessEnum) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) VNXeException(com.emc.storageos.vnxe.VNXeException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeException(com.emc.storageos.vnxe.VNXeException) FileExport(com.emc.storageos.db.client.model.FileExport) ExportRule(com.emc.storageos.model.file.ExportRule) VNXeUnexportFileSystemJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeUnexportFileSystemJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Example 9 with FileShareExport

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

the class VNXUnityFileStorageDevice method deleteExportRules.

@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) {
    List<ExportRule> allExports = args.getExistingDBExportRules();
    String subDir = args.getSubDirectory();
    boolean allDirs = args.isAllDir();
    VNXeCommandJob job = null;
    VNXeFileTaskCompleter completer = null;
    boolean isFile = args.getFileOperation();
    boolean ifRulePresent = false;
    String exportPath;
    String subDirExportPath = "";
    subDir = args.getSubDirectory();
    if (!args.getFileOperation()) {
        exportPath = args.getSnapshotPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getSnapshotPath() + "/" + subDir;
        }
    } else {
        exportPath = args.getFs().getPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getFs().getPath() + "/" + subDir;
        }
    }
    _logger.info("exportPath : {}", exportPath);
    args.setExportPath(exportPath);
    _logger.info("Number of existing exports found {}", allExports.size());
    try {
        VNXeApiClient apiClient = getVnxUnityClient(storage);
        if (allDirs) {
            // ALL EXPORTS
            _logger.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
            for (ExportRule rule : allExports) {
                FileShareExport fsExport = null;
                if (args.getFileObjExports() != null) {
                    Collection<FileExport> expList = args.getFileObjExports().values();
                    Iterator<FileExport> it = expList.iterator();
                    FileExport exp = null;
                    while (it.hasNext()) {
                        FileExport export = it.next();
                        if (export.getPath().equalsIgnoreCase(rule.getExportPath())) {
                            exp = export;
                        }
                    }
                    fsExport = new FileShareExport(exp);
                }
                String vnxeShareId = rule.getDeviceExportId();
                _logger.info("Delete UnityExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
                if (isFile) {
                    String fsId = args.getFs().getNativeId();
                    job = apiClient.removeNfsShare(vnxeShareId, fsId);
                } else {
                    job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
                }
                if (job != null) {
                    if (isFile) {
                        completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                    } else {
                        completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                    }
                    VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, rule.getExportPath(), isFile);
                    ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
                } else {
                    _logger.error("No job returned from exportFileSystem");
                    ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
                    return BiosCommandResult.createErrorResult(error);
                }
            }
        } else if (subDir != null && !subDir.isEmpty()) {
            // Filter for a specific Sub Directory export
            _logger.info("Deleting all subdir exports rules at ViPR and  sub directory export at device {}", subDir);
            FileShareExport fsExport = null;
            String vnxeShareId = null;
            if (args.getFileObjExports() != null) {
                Collection<FileExport> expList = args.getFileObjExports().values();
                Iterator<FileExport> it = expList.iterator();
                FileExport exp = null;
                while (it.hasNext()) {
                    FileExport export = it.next();
                    if (export.getPath().equalsIgnoreCase(subDirExportPath)) {
                        exp = export;
                        break;
                    }
                }
                fsExport = new FileShareExport(exp);
            }
            for (ExportRule rule : allExports) {
                _logger.info("Delete UnityExport id for path {} f containing subdirectory {}", rule.getDeviceExportId() + ":" + rule.getExportPath(), subDir);
                if (rule.getExportPath().equalsIgnoreCase(subDirExportPath)) {
                    ifRulePresent = true;
                    vnxeShareId = rule.getDeviceExportId();
                }
            }
            if (!ifRulePresent) {
                if (fsExport != null) {
                    vnxeShareId = fsExport.getIsilonId();
                }
            }
            _logger.info("Delete UnityExport id {} for path {}", vnxeShareId, subDirExportPath);
            if (isFile) {
                String fsId = args.getFs().getNativeId();
                job = apiClient.removeNfsShare(vnxeShareId, fsId);
            } else {
                job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
            }
            if (job != null) {
                if (isFile) {
                    completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                } else {
                    completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                }
                VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, subDirExportPath, isFile);
                ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
            } else {
                _logger.error("No job returned from exportFileSystem");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
                return BiosCommandResult.createErrorResult(error);
            }
        } else {
            // Filter for No SUBDIR - main export rules with no sub dirs
            _logger.info("Deleting all export rules  from DB and export at device not included sub dirs");
            FileShareExport fsExport = null;
            String vnxeShareId = null;
            if (args.getFileObjExports() != null) {
                Collection<FileExport> expList = args.getFileObjExports().values();
                Iterator<FileExport> it = expList.iterator();
                FileExport exp = null;
                while (it.hasNext()) {
                    FileExport export = it.next();
                    if (export.getPath().equalsIgnoreCase(exportPath)) {
                        exp = export;
                        break;
                    }
                }
                fsExport = new FileShareExport(exp);
            }
            for (ExportRule rule : allExports) {
                if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
                    ifRulePresent = true;
                    vnxeShareId = rule.getDeviceExportId();
                }
            }
            if (!ifRulePresent) {
                if (fsExport != null) {
                    vnxeShareId = fsExport.getIsilonId();
                }
            }
            _logger.info("Delete UnityExport id {} for path {}", vnxeShareId, fsExport.getPath());
            if (isFile) {
                String fsId = args.getFs().getNativeId();
                job = apiClient.removeNfsShare(vnxeShareId, fsId);
            } else {
                job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
            }
            if (job != null) {
                if (isFile) {
                    completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                } else {
                    completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                }
                VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, fsExport.getPath(), isFile);
                ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
            } else {
                _logger.error("No job returned from exportFileSystem");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
                return BiosCommandResult.createErrorResult(error);
            }
        }
    } catch (VNXeException e) {
        _logger.error("Unexport file system got the exception", e);
        if (completer != null) {
            completer.error(dbClient, e);
        }
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception ex) {
        _logger.error("Delete file system got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", ex.getMessage());
        if (completer != null) {
            completer.error(dbClient, error);
        }
        return BiosCommandResult.createErrorResult(error);
    }
    if (job != null) {
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Unexport filesystem job submitted - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
        _logger.info(logMsgBuilder.toString());
        return BiosCommandResult.createPendingResult();
    } else {
        StringBuilder logMsgBuilder = new StringBuilder(String.format("No export found - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
        _logger.info(logMsgBuilder.toString());
        return BiosCommandResult.createSuccessfulResult();
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeFileTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) Snapshot(com.emc.storageos.db.client.model.Snapshot) VNXeException(com.emc.storageos.vnxe.VNXeException) FileExport(com.emc.storageos.db.client.model.FileExport) Iterator(java.util.Iterator) ExportRule(com.emc.storageos.model.file.ExportRule) Collection(java.util.Collection) VNXeUnexportFileSystemJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeUnexportFileSystemJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

Example 10 with FileShareExport

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

the class VNXeStorageDevice method deleteExportRules.

@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) {
    List<ExportRule> allExports = args.getExistingDBExportRules();
    String subDir = args.getSubDirectory();
    boolean allDirs = args.isAllDir();
    VNXeCommandJob job = null;
    VNXeFileTaskCompleter completer = null;
    boolean isFile = args.getFileOperation();
    boolean ifRulePresent = false;
    String exportPath;
    String subDirExportPath = "";
    subDir = args.getSubDirectory();
    if (!args.getFileOperation()) {
        exportPath = args.getSnapshotPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getSnapshotPath() + "/" + subDir;
        }
    } else {
        exportPath = args.getFs().getPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getFs().getPath() + "/" + subDir;
        }
    }
    _logger.info("exportPath : {}", exportPath);
    args.setExportPath(exportPath);
    _logger.info("Number of existing exports found {}", allExports.size());
    try {
        VNXeApiClient apiClient = getVnxeClient(storage);
        if (allDirs) {
            // ALL EXPORTS
            _logger.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
            for (ExportRule rule : allExports) {
                FileShareExport fsExport = null;
                if (args.getFileObjExports() != null) {
                    Collection<FileExport> expList = args.getFileObjExports().values();
                    Iterator<FileExport> it = expList.iterator();
                    FileExport exp = null;
                    while (it.hasNext()) {
                        FileExport export = it.next();
                        if (export.getPath().equalsIgnoreCase(rule.getExportPath())) {
                            exp = export;
                        }
                    }
                    fsExport = new FileShareExport(exp);
                }
                String vnxeShareId = rule.getDeviceExportId();
                _logger.info("Delete IsilonExport id {} for path {}", rule.getDeviceExportId(), rule.getExportPath());
                if (isFile) {
                    String fsId = args.getFs().getNativeId();
                    job = apiClient.removeNfsShare(vnxeShareId, fsId);
                } else {
                    job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
                }
                if (job != null) {
                    if (isFile) {
                        completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                    } else {
                        completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                    }
                    VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, rule.getExportPath(), isFile);
                    ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
                } else {
                    _logger.error("No job returned from exportFileSystem");
                    ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
                    return BiosCommandResult.createErrorResult(error);
                }
            }
        } else if (subDir != null && !subDir.isEmpty()) {
            // Filter for a specific Sub Directory export
            _logger.info("Deleting all subdir exports rules at ViPR and  sub directory export at device {}", subDir);
            FileShareExport fsExport = null;
            String vnxeShareId = null;
            if (args.getFileObjExports() != null) {
                Collection<FileExport> expList = args.getFileObjExports().values();
                Iterator<FileExport> it = expList.iterator();
                FileExport exp = null;
                while (it.hasNext()) {
                    FileExport export = it.next();
                    if (export.getPath().equalsIgnoreCase(subDirExportPath)) {
                        exp = export;
                        break;
                    }
                }
                fsExport = new FileShareExport(exp);
            }
            for (ExportRule rule : allExports) {
                _logger.info("Delete IsilonExport id for path {} f containing subdirectory {}", rule.getDeviceExportId() + ":" + rule.getExportPath(), subDir);
                if (rule.getExportPath().equalsIgnoreCase(subDirExportPath)) {
                    ifRulePresent = true;
                    vnxeShareId = rule.getDeviceExportId();
                }
            }
            if (!ifRulePresent) {
                if (fsExport != null) {
                    vnxeShareId = fsExport.getIsilonId();
                }
            }
            _logger.info("Delete IsilonExport id {} for path {}", vnxeShareId, subDirExportPath);
            if (isFile) {
                String fsId = args.getFs().getNativeId();
                job = apiClient.removeNfsShare(vnxeShareId, fsId);
            } else {
                job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
            }
            if (job != null) {
                if (isFile) {
                    completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                } else {
                    completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                }
                VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, subDirExportPath, isFile);
                ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
            } else {
                _logger.error("No job returned from exportFileSystem");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
                return BiosCommandResult.createErrorResult(error);
            }
        } else {
            // Filter for No SUBDIR - main export rules with no sub dirs
            _logger.info("Deleting all export rules  from DB and export at device not included sub dirs");
            FileShareExport fsExport = null;
            String vnxeShareId = null;
            if (args.getFileObjExports() != null) {
                Collection<FileExport> expList = args.getFileObjExports().values();
                Iterator<FileExport> it = expList.iterator();
                FileExport exp = null;
                while (it.hasNext()) {
                    FileExport export = it.next();
                    if (export.getPath().equalsIgnoreCase(exportPath)) {
                        exp = export;
                        break;
                    }
                }
                fsExport = new FileShareExport(exp);
            }
            for (ExportRule rule : allExports) {
                if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
                    ifRulePresent = true;
                    vnxeShareId = rule.getDeviceExportId();
                }
            }
            if (!ifRulePresent) {
                if (fsExport != null) {
                    vnxeShareId = fsExport.getIsilonId();
                }
            }
            _logger.info("Delete IsilonExport id {} for path {}", vnxeShareId, fsExport.getPath());
            if (isFile) {
                String fsId = args.getFs().getNativeId();
                job = apiClient.removeNfsShare(vnxeShareId, fsId);
            } else {
                job = apiClient.deleteNfsShareForSnapshot(vnxeShareId);
            }
            if (job != null) {
                if (isFile) {
                    completer = new VNXeFileTaskCompleter(FileShare.class, args.getFsId(), args.getOpId());
                } else {
                    completer = new VNXeFileTaskCompleter(Snapshot.class, args.getSnapshotId(), args.getOpId());
                }
                VNXeUnexportFileSystemJob unexportFSJob = new VNXeUnexportFileSystemJob(job.getId(), storage.getId(), completer, fsExport, fsExport.getPath(), isFile);
                ControllerServiceImpl.enqueueJob(new QueueJob(unexportFSJob));
            } else {
                _logger.error("No job returned from exportFileSystem");
                ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", "No Job returned from deleteFileSystem");
                return BiosCommandResult.createErrorResult(error);
            }
        }
    } catch (VNXeException e) {
        _logger.error("Unexport file system got the exception", e);
        if (completer != null) {
            completer.error(_dbClient, e);
        }
        return BiosCommandResult.createErrorResult(e);
    } catch (Exception ex) {
        _logger.error("Delete file system got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("DeleteFileSystem", ex.getMessage());
        if (completer != null) {
            completer.error(_dbClient, error);
        }
        return BiosCommandResult.createErrorResult(error);
    }
    if (job != null) {
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Unexport filesystem job submitted - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
        _logger.info(logMsgBuilder.toString());
        return BiosCommandResult.createPendingResult();
    } else {
        StringBuilder logMsgBuilder = new StringBuilder(String.format("No export found - Array:%s, fileSystem: %s", storage.getSerialNumber(), args.getFsName()));
        _logger.info(logMsgBuilder.toString());
        return BiosCommandResult.createSuccessfulResult();
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeFileTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) VNXeException(com.emc.storageos.vnxe.VNXeException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeException(com.emc.storageos.vnxe.VNXeException) FileExport(com.emc.storageos.db.client.model.FileExport) Iterator(java.util.Iterator) ExportRule(com.emc.storageos.model.file.ExportRule) Collection(java.util.Collection) VNXeUnexportFileSystemJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeUnexportFileSystemJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob)

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