Search in sources :

Example 1 with ExportRules

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

the class FileService method getFSExportRules.

/**
 * Get FS Export Rules
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param subDir
 *            sub-directory within a filesystem
 * @param allDirs
 *            All Dirs within a filesystem
 * @brief Show export rules for a file system
 * @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 getFSExportRules(@PathParam("id") URI id, @QueryParam("allDirs") boolean allDirs, @QueryParam("subDir") String subDir) {
    _log.info("Request recieved for Exports  with Id : {}  allDirs : {} subDir : {}", new Object[] { id, allDirs, subDir });
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    // validate the subDir,no need to check return value as it is optional.
    ArgValidator.checkSubDirName("subDir", subDir);
    List<ExportRule> exportRule = FileOperationUtils.getExportRules(id, allDirs, subDir, _dbClient);
    ExportRules rules = new ExportRules();
    if (!exportRule.isEmpty()) {
        rules.setExportRules(exportRule);
    }
    return rules;
}
Also used : ExportRules(com.emc.storageos.model.file.ExportRules) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with ExportRules

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

the class ExportVerificationUtility method verifyExports.

/**
 * Since, Modifying an export is not allowed This method verifies the
 * existing export params with the new one issued to modify.
 *
 * @param fs
 * @param param
 */
public void verifyExports(FileShare fileShare, Snapshot snapshot, FileExportUpdateParams fsParam) throws Exception {
    fs = fileShare;
    param = fsParam;
    this.snapshot = snapshot;
    // Add Payload
    ExportRules exportRules = param.getExportRulesToAdd();
    validateExportRules(exportRules, ExportOperationType.ADD);
    reportErrors(fsParam, ExportOperationType.ADD);
    // Modify Payload
    ExportRules exportModifyRules = param.getExportRulesToModify();
    validateExportRules(exportModifyRules, ExportOperationType.MODIFY);
    reportErrors(fsParam, ExportOperationType.MODIFY);
    // Delete Payload
    ExportRules exportDeleteRules = param.getExportRulesToDelete();
    validateExportRules(exportDeleteRules, ExportOperationType.DELETE);
    reportErrors(fsParam, ExportOperationType.DELETE);
// letThisObjEligibleForGC();
}
Also used : ExportRules(com.emc.storageos.model.file.ExportRules)

Example 3 with ExportRules

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

the class ExportVerificationUtility method reportDeleteErrors.

private void reportDeleteErrors(FileExportUpdateParams param) throws Exception {
    String opName = ExportOperationType.DELETE.name();
    // Report Delete Export Errors
    ExportRules listExportRules = param.getExportRulesToDelete();
    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 INVALID_SECURITY_TYPE:
                    {
                        if (exportRule.getSecFlavor() != null) {
                            throw APIException.badRequests.invalidSecurityType(exportRule.getSecFlavor());
                        } else {
                            throw APIException.badRequests.missingInputTypeFound(SEC_TYPE, ExportOperationType.DELETE.name());
                        }
                    }
                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 EXPORT_NOT_FOUND:
                    {
                        throw APIException.badRequests.exportNotFound(ExportOperationType.DELETE.name(), exportRule.toString());
                    }
                case EXPORT_EXISTS:
                case INVALID_ANON:
                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) ExportOperationErrorType(com.emc.storageos.model.file.FileExportUpdateParams.ExportOperationErrorType)

Example 4 with ExportRules

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

the class ExportVerificationUtility method reportModifyErrors.

private void reportModifyErrors(FileExportUpdateParams param) throws Exception {
    String opName = ExportOperationType.MODIFY.name();
    // Report Modify Export Errors
    ExportRules listExportRules = param.getExportRulesToModify();
    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 EXPORT_NOT_FOUND:
                    {
                        throw APIException.badRequests.exportNotFound(opName, exportRule.toString());
                    }
                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:
                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) ExportOperationErrorType(com.emc.storageos.model.file.FileExportUpdateParams.ExportOperationErrorType)

Example 5 with ExportRules

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

the class FileStorageUtils method updateFileSnapshotExport.

public static String updateFileSnapshotExport(URI fileSnapshotId, String subDirectory, FileExportRule[] fileExportRules) {
    List<ExportRule> exportRuleList = getFileSnapshotExportRules(fileSnapshotId, 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(fileSnapshotId);
        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);
        }
    }
    SnapshotExportUpdateParams params = new SnapshotExportUpdateParams();
    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);
    }
    Task<FileSnapshotRestRep> task = execute(new UpdateFileSnapshotExport(fileSnapshotId, subDirectory, params));
    addAffectedResource(task);
    String exportId = task.getResourceId().toString();
    logInfo("file.storage.export.task", exportId, task.getOpId());
    return exportId;
}
Also used : SnapshotExportUpdateParams(com.emc.storageos.model.file.SnapshotExportUpdateParams) FileSnapshotRestRep(com.emc.storageos.model.file.FileSnapshotRestRep) 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) 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) HashSet(java.util.HashSet) UpdateFileSnapshotExport(com.emc.sa.service.vipr.file.tasks.UpdateFileSnapshotExport)

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