Search in sources :

Example 6 with ExportRule

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

the class FileService method isSecurityValid.

private boolean isSecurityValid(FileShare fs, FileSystemMountParam param) {
    List<String> allowedSecurities = new ArrayList<String>();
    String subDirectory = param.getSubDir();
    if (StringUtils.isEmpty(param.getSubDir())) {
        subDirectory = null;
    }
    List<ExportRule> exports = FileOperationUtils.getExportRules(fs.getId(), false, subDirectory, _dbClient);
    for (ExportRule rule : exports) {
        List<String> securityTypes = Arrays.asList(rule.getSecFlavor().split("\\s*,\\s*"));
        allowedSecurities.addAll(securityTypes);
    }
    if (allowedSecurities.contains(param.getSecurity())) {
        return true;
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule)

Example 7 with ExportRule

use of com.emc.storageos.model.file.ExportRule 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 8 with ExportRule

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

the class ExportVerificationUtility method verifyDeleteExportRule.

/**
 * Verify each export rule that can be added
 *
 * @param fs
 * @param listExportRule
 */
private void verifyDeleteExportRule(List<ExportRule> listExportRule) throws Exception {
    if (listExportRule == null) {
        return;
    }
    _log.info("{} Export Rule(s) Requested to Delete {} - Iterating ..", listExportRule.size());
    for (ExportRule exportRule : listExportRule) {
        exportRule.setIsToProceed(true, ExportOperationErrorType.NO_ERROR);
        _log.info("Verifying Export Rule {}", exportRule.toString());
        // is same security flavor found in several exports - report the error
        scanForDuplicateSecFlavor(exportRule);
        if (!exportRule.isToProceed()) {
            _log.info("Same Security Flavor found across the exports {}", exportRule.toString());
            break;
        }
        FileExportRule rule = validateInputAndQueryDB(exportRule);
        // If found -- allow to delete.
        if (rule != null) {
            exportRule.setIsToProceed(true, ExportOperationErrorType.NO_ERROR);
        } else // If not, stop proceed further.
        {
            _log.info("Export not found to delete");
            exportRule.setIsToProceed(false, ExportOperationErrorType.EXPORT_NOT_FOUND);
        }
    }
}
Also used : FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule)

Example 9 with ExportRule

use of com.emc.storageos.model.file.ExportRule 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 10 with ExportRule

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

the class ExportVerificationUtility method saveAndRetrieveExportURIs.

public void saveAndRetrieveExportURIs(List<ExportRule> listExportRule, ExportOperationType type) {
    if (listExportRule == null) {
        return;
    }
    for (ExportRule exportRule : listExportRule) {
        if (exportRule.isToProceed()) {
            FileExportRule rule = new FileExportRule();
            copyPropertiesToSave(rule, exportRule);
            rule.setOpType(type.name());
            URI uri = URIUtil.createId(FileExportRule.class);
            rule.setId(uri);
            _log.debug("Saving Object {}", rule.toString());
            _dbClient.createObject(rule);
            allSavedURIs.add(uri);
        }
        continue;
    }
}
Also used : FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) URI(java.net.URI)

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