Search in sources :

Example 26 with FSExportMap

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

the class VNXeUnexportFileSystemJob method updateSnapExport.

private Snapshot updateSnapExport(DbClient dbClient, VNXeApiClient apiClient) {
    URI snapId = getTaskCompleter().getId();
    Snapshot snapObj = dbClient.queryObject(Snapshot.class, snapId);
    FSExportMap exports = snapObj.getFsExports();
    if (exports == null) {
        _logger.info("No exports found in the file system. ");
        return snapObj;
    }
    if (exportInfo != null) {
        FileExport export = exportInfo.getFileExport();
        FileExport existExport = exports.get(export.getFileExportKey());
        if (existExport != null) {
            exports.remove(existExport.getFileExportKey());
            dbClient.persistObject(snapObj);
        }
    }
    return snapObj;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) FileExport(com.emc.storageos.db.client.model.FileExport) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) URI(java.net.URI)

Example 27 with FSExportMap

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

the class VNXUnityFileStorageDevice 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 = getVnxUnityClient(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) 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) 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 28 with FSExportMap

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

the class DataDomainFileStorageDevice method doDeleteFS.

@Override
public BiosCommandResult doDeleteFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    try {
        _log.info("DataDomainFileStorageDevice doDeleteFS {} - start", args.getFsId());
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doDeleteFS failed, provider unreachable");
            String op = "FS delete";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        URI storagePoolId = args.getFs().getPool();
        StoragePool storagePool = _dbClient.queryObject(StoragePool.class, storagePoolId);
        // Delete the exports for this file system
        FSExportMap exportMap = args.getFsExports();
        List<FileExport> exportMapvalues = null;
        if (exportMap != null) {
            exportMapvalues = new ArrayList<>(exportMap.values());
        }
        if ((exportMap != null) && (exportMapvalues != null)) {
            try {
                ddDeleteExports(ddClient, storagePool.getNativeId(), exportMap, exportMapvalues);
            } catch (DataDomainApiException dde) {
                _log.error("Unable to delete exports for the FS: ", dde);
            }
        }
        // Delete the SMB shares for this file system
        SMBShareMap shareMap = args.getFsShares();
        List<SMBFileShare> shareMapValues = null;
        if (shareMap != null) {
            shareMapValues = new ArrayList<>(shareMap.values());
        }
        if ((shareMap != null) && (shareMapValues != null)) {
            try {
                ddDeleteShares(ddClient, storagePool.getNativeId(), shareMap, shareMapValues);
            } catch (DataDomainApiException dde) {
                _log.error("Unable to delete cifs shares for the FS: ", dde);
            }
        }
        // Delete mtree on the DD array
        DDServiceStatus ddSvcStatus = ddClient.deleteMTree(storagePool.getNativeId(), args.getFs().getNativeId());
        _log.info("DataDomainFileStorageDevice doDeleteFS {} - complete", args.getFsId());
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doDeleteFS failed, device error", e);
        return BiosCommandResult.createErrorResult(e);
    } catch (DataDomainResourceNotFoundException e) {
        _log.error("doDeleteFS failed, Mtree not found.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) DDServiceStatus(com.emc.storageos.datadomain.restapi.model.DDServiceStatus) DataDomainResourceNotFoundException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainResourceNotFoundException) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient) URI(java.net.URI) DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) FileExport(com.emc.storageos.db.client.model.FileExport) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 29 with FSExportMap

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

the class DataDomainFileStorageDevice method doExport.

@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    _log.info("DataDomainFileStorageDevice doExport {} - start", args.getFileObjId());
    // Snapshot Export operation is not supported by Data Domain.
    if (args.getFileOperation() == false) {
        return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.doCreateSnapshotExportFailed());
    }
    if ((exportList == null) || (exportList.isEmpty())) {
        return BiosCommandResult.createSuccessfulResult();
    }
    try {
        DataDomainClient ddClient = getDataDomainClient(storage);
        if (ddClient == null) {
            _log.error("doExport failed, provider unreachable");
            String op = "FS export";
            return BiosCommandResult.createErrorResult(DeviceControllerErrors.datadomain.operationFailedProviderInaccessible(op));
        }
        if ((args.getFsExports() == null) || (args.getFsExports().isEmpty())) {
            // Initialize exports map
            args.initFileObjExports();
        }
        // Go through the list of new exports and add each to create list
        // if not in the list of existing exports or to the modify list if
        // contained in the existing list
        FSExportMap currExpMap = args.getFsExports();
        List<FileExport> modifyFileExports = new ArrayList<>();
        List<FileExport> createFileExports = new ArrayList<>();
        ddInitCreateModifyFileExportLists(currExpMap, exportList, modifyFileExports, createFileExports);
        // Create new exports and add to file export map
        ddCreateExports(ddClient, args.getStoragePool().getNativeId(), args.getFsExports(), createFileExports);
        // Modify existing exports
        ddModifyExports(ddClient, args.getStoragePool().getNativeId(), args.getFsExports(), modifyFileExports);
        _log.info("DataDomainFileStorageDevice doExport {} - complete", args.getFileObjId());
        return BiosCommandResult.createSuccessfulResult();
    } catch (DataDomainApiException e) {
        _log.error("doExport failed, device error.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : DataDomainApiException(com.emc.storageos.datadomain.restapi.errorhandling.DataDomainApiException) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) DataDomainClient(com.emc.storageos.datadomain.restapi.DataDomainClient)

Example 30 with FSExportMap

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

the class NetAppFileStorageDevice method netAppDeleteNFSExports.

private Boolean netAppDeleteNFSExports(StorageSystem storage, FSExportMap exportMap) throws NetAppException {
    int failedCount = 0;
    Iterator<Map.Entry<String, FileExport>> it = exportMap.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, FileExport> entry = it.next();
        String key = entry.getKey();
        FileExport fsExport = entry.getValue();
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
        if (!nApi.deleteNFS(fsExport.getPath())) {
            failedCount++;
        } else {
            exportMap.remove(key);
        }
    }
    if (failedCount > 0) {
        return false;
    } else {
        return true;
    }
}
Also used : Entry(java.util.Map.Entry) FileExport(com.emc.storageos.db.client.model.FileExport) NetAppApi(com.emc.storageos.netapp.NetAppApi) HashMap(java.util.HashMap) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Map(java.util.Map) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap)

Aggregations

FSExportMap (com.emc.storageos.db.client.model.FSExportMap)46 FileExport (com.emc.storageos.db.client.model.FileExport)33 ArrayList (java.util.ArrayList)22 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)20 FileShare (com.emc.storageos.db.client.model.FileShare)18 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 Snapshot (com.emc.storageos.db.client.model.Snapshot)11 URI (java.net.URI)11 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)9 WorkflowException (com.emc.storageos.workflow.WorkflowException)7 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 FileShareExport (com.emc.storageos.volumecontroller.FileShareExport)6 List (java.util.List)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)5