Search in sources :

Example 11 with ExportRules

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

the class FileOrchestrationDeviceController method addStepsToReplicateNFSExportRules.

/**
 * Child workflow for replicating source file system NFS export Rules to target.
 *
 * @param systemTarget
 *            - URI of target StorageSystem where source NFS shares has to be replicated.
 * @param fsURI
 *            -URI of the source FileSystem
 * @param taskId
 */
public void addStepsToReplicateNFSExportRules(URI systemTarget, URI fsURI, String taskId) {
    s_logger.info("Generating steps for Replicating NFS export rules to Target Cluster");
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    Workflow workflow = null;
    FileShare targetFileShare = null;
    try {
        FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
        if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
            List<String> targetfileUris = new ArrayList<String>();
            targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
            targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        } else {
            targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
        }
        workflow = this._workflowService.getNewWorkflow(this, REPLICATE_NFS_EXPORT_RULES_TO_TARGET_WF_NAME, false, taskId, completer);
        FSExportMap sourceFSExportMap = sourceFileShare.getFsExports();
        FSExportMap targetFSExportMap = targetFileShare.getFsExports();
        if (sourceFSExportMap == null && targetFSExportMap != null) {
            // There are no export rule on source but there are on target!!
            List<ExportRule> exportRulesToDelete;
            HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
            for (String exportPath : targetExportRuleMap.keySet()) {
                FileExportUpdateParams params = new FileExportUpdateParams();
                if (exportPath.equals(targetFileShare.getPath())) {
                    // File system export rules....
                    exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath());
                } else {
                    // Sub directory export rules....
                    String subDir = exportPath.split(targetFileShare.getPath())[1];
                    exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
                    params.setSubDir(subDir.substring(1));
                }
                ExportRules deleteExportRules = new ExportRules();
                deleteExportRules.setExportRules(exportRulesToDelete);
                params.setExportRulesToDelete(deleteExportRules);
                updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
            }
        } else if (targetFSExportMap != null && sourceFSExportMap != null) {
            // Both source and target have export rules!!
            HashMap<String, List<ExportRule>> sourceExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(sourceFileShare, s_dbClient);
            HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
            for (String exportPath : sourceExportRuleMap.keySet()) {
                FileExportUpdateParams params = new FileExportUpdateParams();
                List<ExportRule> exportRulesToAdd = new ArrayList<ExportRule>();
                List<ExportRule> exportRulesToDelete = new ArrayList<ExportRule>();
                List<ExportRule> exportRulesToModify = new ArrayList<ExportRule>();
                List<ExportRule> sourceExportRules;
                List<ExportRule> targetExportRules;
                HashMap<String, ExportRule> srcExportRuleSecFlvMap;
                HashMap<String, ExportRule> trgtExportRuleSecFlvMap;
                if (exportPath.equals(sourceFileShare.getPath())) {
                    // File system export rules....
                    sourceExportRules = sourceExportRuleMap.get(exportPath);
                    targetExportRules = targetExportRuleMap.get(targetFileShare.getPath());
                } else {
                    // Sub directory export rules....
                    sourceExportRules = sourceExportRuleMap.get(exportPath);
                    String subDir = exportPath.split(sourceFileShare.getPath())[1];
                    targetExportRules = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
                    params.setSubDir(subDir.substring(1));
                }
                if (sourceExportRules != null && targetExportRules != null) {
                    srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
                    trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
                    FileOrchestrationUtils.checkForExportRuleToAdd(sourceFileShare, targetFileShare, srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToAdd);
                    FileOrchestrationUtils.checkForExportRuleToDelete(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToDelete);
                    sourceExportRules.removeAll(exportRulesToAdd);
                    targetExportRules.removeAll(exportRulesToDelete);
                    srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
                    trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
                    FileOrchestrationUtils.checkForExportRuleToModify(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToModify);
                    if (!exportRulesToAdd.isEmpty()) {
                        ExportRules addExportRules = new ExportRules();
                        addExportRules.setExportRules(exportRulesToAdd);
                        params.setExportRulesToAdd(addExportRules);
                    }
                    if (!exportRulesToDelete.isEmpty()) {
                        ExportRules deleteExportRules = new ExportRules();
                        deleteExportRules.setExportRules(exportRulesToDelete);
                        params.setExportRulesToDelete(deleteExportRules);
                    }
                    if (!exportRulesToModify.isEmpty()) {
                        ExportRules modifyExportRules = new ExportRules();
                        modifyExportRules.setExportRules(exportRulesToModify);
                        params.setExportRulesToModify(modifyExportRules);
                    }
                    if (params.retrieveAllExports() != null && !params.retrieveAllExports().isEmpty()) {
                        updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
                    }
                }
            }
        }
        String successMessage = String.format("Replicating source File System : %s, NFS Exports Rules to Target System finished successfully", sourceFileShare.getLabel());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem NFS Exports Rules : " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) FileWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter) FileExportUpdateParams(com.emc.storageos.model.file.FileExportUpdateParams) ExportRules(com.emc.storageos.model.file.ExportRules) ExportRule(com.emc.storageos.model.file.ExportRule) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with ExportRules

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

the class FileSnapshotService method getSnapshotExportRules.

/**
 * Get Snapshot Export Rules
 *
 * @param id
 *            the URN of a file system
 * @param allDirs
 *            All Dirs within a file system
 * @param subDir
 *            sub-directory within a file system
 * @brief List the export rules for a snapshot
 * @return ExportRules
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/export")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ExportRules getSnapshotExportRules(@PathParam("id") URI id, @QueryParam("allDirs") boolean allDirs, @QueryParam("subDir") String subDir) {
    _log.info("Request recieved to list snapshotExports with Id : {}", new Object[] { id });
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snapshot = queryResource(id);
    ExportRules exportRules = new ExportRules();
    List<ExportRule> exportRule = new ArrayList<>();
    // Query All Export Rules Specific to a File System.
    List<FileExportRule> exports = queryDBSnapshotExports(snapshot);
    _log.info("Number of existing snapshot exports found : {} ", exports.size());
    // All EXPORTS
    for (FileExportRule rule : exports) {
        ExportRule expRule = new ExportRule();
        // Copy Props
        copyPropertiesToSave(rule, expRule, snapshot);
        exportRule.add(expRule);
    }
    _log.info("Number of snapshot export rules returning {}", exportRule.size());
    exportRules.setExportRules(exportRule);
    return exportRules;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) ExportRules(com.emc.storageos.model.file.ExportRules) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ArrayList(java.util.ArrayList) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with ExportRules

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

the class FileStorageUtils method updateFileSystemExport.

public static String updateFileSystemExport(URI fileSystemId, String subDirectory, FileExportRule[] fileExportRules, boolean bypassDnsCheck) {
    List<ExportRule> exportRuleList = getFileSystemExportRules(fileSystemId, false, subDirectory);
    Set<String> existingRuleSet = Sets.newHashSet();
    for (ExportRule rule : exportRuleList) {
        existingRuleSet.add(rule.getSecFlavor());
    }
    List<ExportRule> exportRuleListToAdd = Lists.newArrayList();
    List<ExportRule> exportRuleListToModify = Lists.newArrayList();
    for (FileExportRule rule : fileExportRules) {
        ExportRule exportRule = new ExportRule();
        exportRule.setFsID(fileSystemId);
        exportRule.setSecFlavor(rule.security);
        String rootUserMapping = rule.rootUserMapping;
        String domain = rule.domain;
        if (StringUtils.isNotBlank(domain)) {
            rootUserMapping = domain.trim() + "\\" + rootUserMapping.trim();
        }
        exportRule.setAnon(rootUserMapping);
        Set<String> exportHosts = new HashSet<String>(rule.exportHosts);
        switch(rule.getPermission()) {
            case "ro":
                exportRule.setReadOnlyHosts(exportHosts);
                break;
            case "rw":
                exportRule.setReadWriteHosts(exportHosts);
                break;
            case "root":
                exportRule.setRootHosts(exportHosts);
                break;
            default:
                break;
        }
        if (existingRuleSet.contains(exportRule.getSecFlavor())) {
            exportRuleListToModify.add(exportRule);
        } else {
            exportRuleListToAdd.add(exportRule);
        }
    }
    FileShareExportUpdateParams params = new FileShareExportUpdateParams();
    if (!exportRuleListToAdd.isEmpty()) {
        ExportRules exportRulesToAdd = new ExportRules();
        exportRulesToAdd.setExportRules(exportRuleListToAdd);
        params.setExportRulesToAdd(exportRulesToAdd);
    }
    if (!exportRuleListToModify.isEmpty()) {
        ExportRules exportRulesToModify = new ExportRules();
        exportRulesToModify.setExportRules(exportRuleListToModify);
        params.setExportRulesToModify(exportRulesToModify);
    }
    params.setBypassDnsCheck(bypassDnsCheck);
    Task<FileShareRestRep> task = execute(new UpdateFileSystemExport(fileSystemId, subDirectory, params));
    addAffectedResource(task);
    String exportId = task.getResourceId().toString();
    logInfo("file.storage.export.task", exportId, task.getOpId());
    return exportId;
}
Also used : UpdateFileSystemExport(com.emc.sa.service.vipr.file.tasks.UpdateFileSystemExport) FindFileSnapshotExportRules(com.emc.sa.service.vipr.file.tasks.FindFileSnapshotExportRules) FindFileSystemExportRules(com.emc.sa.service.vipr.file.tasks.FindFileSystemExportRules) ExportRules(com.emc.storageos.model.file.ExportRules) FileShareExportUpdateParams(com.emc.storageos.model.file.FileShareExportUpdateParams) DeactivateFileSystemExportRule(com.emc.sa.service.vipr.file.tasks.DeactivateFileSystemExportRule) DeactivateFileSnapshotExportRule(com.emc.sa.service.vipr.file.tasks.DeactivateFileSnapshotExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileShareRestRep(com.emc.storageos.model.file.FileShareRestRep) HashSet(java.util.HashSet)

Example 14 with ExportRules

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

the class FileSystems method deleteFileSystemExport.

@FlashException(referrer = { "fileSystem" })
public static void deleteFileSystemExport(String fileSystemId, String security, String exportPath) {
    ViPRCoreClient client = BourneUtil.getViprClient();
    ExportRule rule = new ExportRule();
    rule.setSecFlavor(security);
    List<ExportRule> list = Lists.newArrayList();
    list.add(rule);
    ExportRules exportRules = new ExportRules();
    exportRules.setExportRules(list);
    FileShareExportUpdateParams params = new FileShareExportUpdateParams();
    params.setExportRulesToDelete(exportRules);
    FileShareRestRep fileSystem = client.fileSystems().get(uri(fileSystemId));
    String subDir = FileUtils.findSubDirectory(fileSystem.getMountPath(), exportPath);
    client.fileSystems().updateExport(uri(fileSystemId), subDir, params);
    flash.put("info", MessagesUtils.get("resources.filesystem.export.deactivate"));
    fileSystem(fileSystemId);
}
Also used : ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) ExportRules(com.emc.storageos.model.file.ExportRules) FileShareExportUpdateParams(com.emc.storageos.model.file.FileShareExportUpdateParams) ExportRule(com.emc.storageos.model.file.ExportRule) FileShareRestRep(com.emc.storageos.model.file.FileShareRestRep) FlashException(controllers.util.FlashException)

Example 15 with ExportRules

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

the class ExportVerificationUtility method reportAddErrors.

private void reportAddErrors(FileExportUpdateParams param) throws Exception {
    String opName = ExportOperationType.ADD.name();
    // Report Add Export Errors
    ExportRules listExportRules = param.getExportRulesToAdd();
    if (listExportRules == null || listExportRules.getExportRules().isEmpty()) {
        return;
    }
    List<ExportRule> listExportRule = listExportRules.getExportRules();
    for (ExportRule exportRule : listExportRule) {
        if (!exportRule.isToProceed()) {
            ExportOperationErrorType error = exportRule.getErrorTypeIfNotToProceed();
            switch(error) {
                case SNAPSHOT_EXPORT_SHOULD_BE_READ_ONLY:
                    {
                        throw APIException.badRequests.snapshotExportPermissionReadOnly();
                    }
                case INVALID_SECURITY_TYPE:
                    {
                        if (exportRule.getSecFlavor() != null) {
                            throw APIException.badRequests.invalidSecurityType(exportRule.getSecFlavor());
                        } else {
                            throw APIException.badRequests.missingInputTypeFound(SEC_TYPE, opName);
                        }
                    }
                case MULTIPLE_EXPORTS_WITH_SAME_SEC_FLAVOR:
                    {
                        if (exportRule.getSecFlavor() != null) {
                            throw APIException.badRequests.sameSecurityFlavorInMultipleExportsFound(exportRule.getSecFlavor(), opName);
                        } else {
                            throw APIException.badRequests.missingInputTypeFound(SEC_TYPE, opName);
                        }
                    }
                case INVALID_ANON:
                    {
                        if (exportRule.getAnon() != null) {
                            throw APIException.badRequests.invalidAnon(exportRule.getAnon());
                        } else {
                            throw APIException.badRequests.missingInputTypeFound(ANON_TYPE, opName);
                        }
                    }
                case NO_HOSTS_FOUND:
                    {
                        throw APIException.badRequests.missingInputTypeFound(NO_HOSTS_FOUND, opName);
                    }
                case EXPORT_EXISTS:
                    {
                        throw APIException.badRequests.exportExists(opName, exportRule.toString());
                    }
                case STORAGE_SYSTEM_NOT_SUPPORT_MUL_SECS:
                    {
                        StorageSystem system = null;
                        String systemName = "";
                        if (fs != null) {
                            system = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
                        } else if (snapshot != null) {
                            FileShare fileSystem = _dbClient.queryObject(FileShare.class, snapshot.getParent());
                            system = _dbClient.queryObject(StorageSystem.class, fileSystem.getStorageDevice());
                        }
                        if (system != null) {
                            systemName = system.getSystemType();
                        }
                        throw APIException.badRequests.storageDoesNotSupportMulSecRule(opName, systemName, exportRule.toString());
                    }
                case EXPORT_NOT_FOUND:
                case NO_ERROR:
                default:
                    break;
            }
        }
    }
}
Also used : ExportRules(com.emc.storageos.model.file.ExportRules) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) FileShare(com.emc.storageos.db.client.model.FileShare) ExportOperationErrorType(com.emc.storageos.model.file.FileExportUpdateParams.ExportOperationErrorType) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

ExportRules (com.emc.storageos.model.file.ExportRules)16 ExportRule (com.emc.storageos.model.file.ExportRule)13 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)6 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)4 FlashException (controllers.util.FlashException)4 ExportOperationErrorType (com.emc.storageos.model.file.FileExportUpdateParams.ExportOperationErrorType)3 FileShareExportUpdateParams (com.emc.storageos.model.file.FileShareExportUpdateParams)3 SnapshotExportUpdateParams (com.emc.storageos.model.file.SnapshotExportUpdateParams)3 HashSet (java.util.HashSet)3 DeactivateFileSnapshotExportRule (com.emc.sa.service.vipr.file.tasks.DeactivateFileSnapshotExportRule)2 DeactivateFileSystemExportRule (com.emc.sa.service.vipr.file.tasks.DeactivateFileSystemExportRule)2 FindFileSnapshotExportRules (com.emc.sa.service.vipr.file.tasks.FindFileSnapshotExportRules)2 FindFileSystemExportRules (com.emc.sa.service.vipr.file.tasks.FindFileSystemExportRules)2 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 FileShareRestRep (com.emc.storageos.model.file.FileShareRestRep)2 FileSnapshotRestRep (com.emc.storageos.model.file.FileSnapshotRestRep)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2