Search in sources :

Example 1 with ExportRule

use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.

the class FileDeviceController method filterExportRules.

private Map<ExportRule, List<String>> filterExportRules(List<ExportRule> newExportList, List<ExportRule> existingExportList) {
    Map<ExportRule, List<String>> filteredExports = new HashMap<ExportRule, List<String>>();
    _log.info("filtering export rules");
    for (ExportRule newExport : newExportList) {
        for (ExportRule oldExport : existingExportList) {
            if (newExport.getSecFlavor().equalsIgnoreCase(oldExport.getSecFlavor())) {
                List<String> hosts = new ArrayList<String>();
                if (oldExport.getReadOnlyHosts() != null) {
                    hosts.addAll(oldExport.getReadOnlyHosts());
                }
                if (oldExport.getReadWriteHosts() != null) {
                    hosts.addAll(oldExport.getReadWriteHosts());
                }
                if (oldExport.getRootHosts() != null) {
                    hosts.addAll(oldExport.getRootHosts());
                }
                if (newExport.getReadOnlyHosts() != null) {
                    hosts.removeAll(newExport.getReadOnlyHosts());
                }
                if (newExport.getReadWriteHosts() != null) {
                    hosts.removeAll(newExport.getReadWriteHosts());
                }
                if (newExport.getRootHosts() != null) {
                    hosts.removeAll(newExport.getRootHosts());
                }
                filteredExports.put(oldExport, hosts);
            }
        }
    }
    return filteredExports;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List)

Example 2 with ExportRule

use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.

the class FileDeviceController method getRulesToUnmount.

private List<MountInfo> getRulesToUnmount(ExportRules rules, List<MountInfo> mountList, URI fsId, String subDir) {
    List<MountInfo> unmountList = new ArrayList<MountInfo>();
    List<ExportRule> exportList = new ArrayList<ExportRule>();
    exportList.addAll(rules.getExportRules());
    Map<ExportRule, List<String>> filteredExports = filterExportRules(exportList, FileOperationUtils.getExportRules(fsId, false, subDir, _dbClient));
    for (MountInfo mount : mountList) {
        String hostname = _dbClient.queryObject(Host.class, mount.getHostId()).getHostName();
        if (StringUtils.isEmpty(subDir) && StringUtils.isEmpty(mount.getSubDirectory()) || (!StringUtils.isEmpty(mount.getSubDirectory()) && mount.getSubDirectory().equals(subDir))) {
            for (Entry<ExportRule, List<String>> rule : filteredExports.entrySet()) {
                if (rule.getValue().contains(hostname) && rule.getKey().getSecFlavor().equals(mount.getSecurityType())) {
                    unmountList.add(mount);
                }
            }
        }
    }
    return unmountList;
}
Also used : ArrayList(java.util.ArrayList) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) Host(com.emc.storageos.db.client.model.Host) FileMountInfo(com.emc.storageos.db.client.model.FileMountInfo) MountInfo(com.emc.storageos.model.file.MountInfo)

Example 3 with ExportRule

use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.

the class FileDeviceController method deleteExportRules.

@Override
public void deleteExportRules(URI storage, URI fileUri, boolean allDirs, String subDir, String opId) throws ControllerException {
    ControllerUtils.setThreadLocalLogData(fileUri, opId);
    FileObject fsObj = null;
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    FileShare fs = null;
    Snapshot snapshotObj = null;
    StorageSystem storageObj = null;
    boolean isFile = false;
    try {
        storageObj = _dbClient.queryObject(StorageSystem.class, storage);
        // File
        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);
            args.setAllDir(allDirs);
            args.setSubDirectory(subDir);
        } else {
            // Snapshot
            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.setAllDir(true);
            args.setSubDirectory(null);
        }
        args.setFileOperation(isFile);
        args.setOpId(opId);
        List<ExportRule> existingExportRules = queryExports(args);
        args.setExistingDBExportRules(existingExportRules);
        // Do the Operation on device.
        _log.info("Delete Export Rules : request received for {}, with allDirs : {}, subDir : {}", new Object[] { fs.getId(), allDirs, subDir });
        acquireStepLock(storageObj, opId);
        WorkflowStepCompleter.stepExecuting(opId);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).deleteExportRules(storageObj, args);
        if (result.isCommandSuccess()) {
            // Update Database
            doDeleteExportRulesFromDB(allDirs, subDir, args);
            doDeleteExportsFromFSObjMap(allDirs, subDir, args);
            WorkflowStepCompleter.stepSucceded(opId);
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        // Audit & Update the task status
        String eventMsg = result.isCommandSuccess() ? "" : result.getMessage();
        fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
        if (isFile) {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, result.isCommandSuccess(), eventMsg, "", fs, storageObj);
        } else {
            recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, result.isCommandSuccess(), eventMsg, "", snapshotObj, fs, storageObj);
        }
        _dbClient.updateObject(fsObj);
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
        String[] params = { storage.toString(), fileUri.toString() };
        _log.error("Unable to export file system or snapshot: storage {}, FS/snapshot URI {}", params);
        if ((fsObj != null) && (storageObj != null)) {
            if (URIUtil.isType(fileUri, FileShare.class)) {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SYSTEM, false, e.getMessage(), "", fs, storageObj);
            } else {
                recordFileDeviceOperation(_dbClient, OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, false, e.getMessage(), "", snapshotObj, fs, storageObj);
            }
        }
        updateTaskStatus(opId, fsObj, e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) 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) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 4 with ExportRule

use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.

the class FileOrchestrationUtils method getFSExportRuleMap.

/**
 * This method generates export map for the file system export rules.
 *
 * @param fs File System Object
 * @param dbClient
 * @return
 */
public static HashMap<String, List<ExportRule>> getFSExportRuleMap(FileShare fs, DbClient dbClient) {
    ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
    List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileExportRule.class, containmentConstraint);
    HashMap<String, List<ExportRule>> exportRulesMap = new HashMap<String, List<ExportRule>>();
    for (FileExportRule fileExportRule : fileExportRules) {
        if (exportRulesMap.get(fileExportRule.getExportPath()) == null) {
            List<ExportRule> exportRules = new ArrayList<ExportRule>();
            ExportRule exportRule = convertFileExportRuleToExportRule(fileExportRule);
            exportRules.add(exportRule);
            exportRulesMap.put(fileExportRule.getExportPath(), exportRules);
        } else {
            List<ExportRule> exportRules = exportRulesMap.get(fileExportRule.getExportPath());
            ExportRule exportRule = convertFileExportRuleToExportRule(fileExportRule);
            exportRules.add(exportRule);
        }
    }
    return exportRulesMap;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 5 with ExportRule

use of com.emc.storageos.model.file.ExportRule in project coprhd-controller by CoprHD.

the class FileOrchestrationUtils method checkForExportRuleToAdd.

/**
 * This method checks for export rules that has to added on target file system
 *
 * @param sourceFileShare
 * @param targetFileShare
 * @param sourceExportRuleMap
 * @param targetExportRuleMap
 * @param exportRulesToAdd
 */
public static void checkForExportRuleToAdd(FileShare sourceFileShare, FileShare targetFileShare, HashMap<String, ExportRule> sourceExportRuleMap, HashMap<String, ExportRule> targetExportRuleMap, List<ExportRule> exportRulesToAdd) {
    for (String secFlavour : sourceExportRuleMap.keySet()) {
        if (!targetExportRuleMap.containsKey(secFlavour)) {
            ExportRule sourceExportRule = sourceExportRuleMap.get(secFlavour);
            ExportRule exportRule = new ExportRule();
            exportRule.setFsID(targetFileShare.getId());
            if (sourceExportRule.getExportPath().equals(sourceFileShare.getPath())) {
                exportRule.setExportPath(targetFileShare.getPath());
            } else {
                ArrayList<String> subdirName = new ArrayList<String>();
                subdirName.add(sourceExportRule.getExportPath().split(sourceFileShare.getPath())[1]);
                exportRule.setExportPath(targetFileShare.getPath() + subdirName.get(0));
            }
            exportRule.setAnon(sourceExportRule.getAnon());
            exportRule.setReadOnlyHosts(sourceExportRule.getReadOnlyHosts());
            exportRule.setRootHosts(sourceExportRule.getRootHosts());
            exportRule.setReadWriteHosts(sourceExportRule.getReadWriteHosts());
            exportRule.setSecFlavor(sourceExportRule.getSecFlavor());
            exportRulesToAdd.add(exportRule);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule)

Aggregations

ExportRule (com.emc.storageos.model.file.ExportRule)67 ArrayList (java.util.ArrayList)27 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)22 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)17 FileShare (com.emc.storageos.db.client.model.FileShare)16 ExportRules (com.emc.storageos.model.file.ExportRules)13 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 HashSet (java.util.HashSet)12 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 HashMap (java.util.HashMap)10 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)8 Snapshot (com.emc.storageos.db.client.model.Snapshot)7 FileExport (com.emc.storageos.db.client.model.FileExport)6 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)6 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)6 URI (java.net.URI)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 VNXeException (com.emc.storageos.vnxe.VNXeException)4 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)4