Search in sources :

Example 26 with FileExportRule

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

the class FileService method queryDBFSExports.

private List<FileExportRule> queryDBFSExports(FileShare fs) {
    _log.info("Querying all ExportRules Using FsId {}", fs.getId());
    try {
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
        List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
        return fileExportRules;
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    return null;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) 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) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 27 with FileExportRule

use of com.emc.storageos.db.client.model.FileExportRule 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 28 with FileExportRule

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

the class FileSnapshotService method queryDBSnapshotExports.

private List<FileExportRule> queryDBSnapshotExports(Snapshot snapshot) {
    _log.info("Querying all ExportRules Using Snapshot Id {}", snapshot.getId());
    try {
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getSnapshotExportRulesConstraint(snapshot.getId());
        List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
        return fileExportRules;
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    return null;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 29 with FileExportRule

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

the class FileSnapshotService method deleteSnapshotExportRules.

/**
 * Delete Snapshot Export Rules
 *
 * @param id
 *            the URN of a ViPR file system
 * @brief Delete an export rule
 * @return TaskResponse
 */
@DELETE
@Path("/{id}/export")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteSnapshotExportRules(@PathParam("id") URI id) {
    // log input received.
    _log.info("Delete Snapshot Export Rules : request received for {}", new Object[] { id });
    String task = UUID.randomUUID().toString();
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snapshot = queryResource(id);
    FileShare fileShare = _permissionsHelper.getObjectById(snapshot.getParent(), FileShare.class);
    ArgValidator.checkEntity(snapshot, id, isIdEmbeddedInURL(id));
    /* check if the Snapshot has any export rules on it */
    List<FileExportRule> exports = queryDBSnapshotExports(snapshot);
    if (exports == null || exports.isEmpty()) {
        _log.error("Error Processing Export Updates for snapshot {} doesnot have exports", snapshot.getName());
        throw APIException.badRequests.snapshotHasNoExport(snapshot.getId());
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fileShare.getStorageDevice());
    String path = snapshot.getPath();
    _log.info("Export path found {} ", path);
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snapshot.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT);
    try {
        FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fileShare, _dbClient);
        fileServiceApi.deleteExportRules(device.getId(), snapshot.getId(), false, null, false, task);
        auditOp(OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), device.getId().toString(), false, null);
        return toTask(snapshot, task, op);
    } catch (BadRequestException e) {
        _log.error("Error Processing Export Updates {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Error Processing Export Updates {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 30 with FileExportRule

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

the class ExportVerificationUtility method verifyAddExportRule.

/**
 * Verify each export rule that can be added
 *
 * @param listExportRule
 */
private void verifyAddExportRule(List<ExportRule> listExportRule) throws Exception {
    if (listExportRule == null) {
        return;
    }
    _log.info("Checking if file system is exported before adding export rule");
    if (!isFileSystemExported()) {
        String msg = "File system is not exported. To add export rule, file system must be exported first.";
        _log.error(msg);
        String urn = fs != null ? fs.getId().toString() : snapshot.getId().toString();
        throw APIException.badRequests.fileSystemNotExported(ExportOperationType.ADD.name(), urn);
    }
    _log.info("Number of Export Rule(s) Requested to Add {} - 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.getErrorTypeIfNotToProceed() != null && !(exportRule.getErrorTypeIfNotToProceed().name().equals(ExportOperationErrorType.NO_ERROR.name()))) {
            _log.info("Same Security Flavor found across the exports {}", exportRule.toString());
            break;
        }
        // Now validate hosts
        FileExportRule rule = validateHosts(exportRule);
        // If same export already found -- Don't allow to add again.
        if (rule != null) {
            _log.info("Duplicate Export to Add {} Requested : {}", rule, exportRule);
            exportRule.setIsToProceed(false, ExportOperationErrorType.EXPORT_EXISTS);
            break;
        } else // If not found proceed for further verifications.
        {
            if (exportRule.isToProceed()) {
                _log.info("No Existing Export found in DB {}", exportRule);
                verifyExportAnon(exportRule);
            }
        }
    }
}
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)

Aggregations

FileExportRule (com.emc.storageos.db.client.model.FileExportRule)37 URI (java.net.URI)13 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)11 URISyntaxException (java.net.URISyntaxException)11 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)10 FileShare (com.emc.storageos.db.client.model.FileShare)10 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)10 ExportRule (com.emc.storageos.model.file.ExportRule)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 ArrayList (java.util.ArrayList)8 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 Snapshot (com.emc.storageos.db.client.model.Snapshot)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)5 FileExport (com.emc.storageos.db.client.model.FileExport)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 WorkflowException (com.emc.storageos.workflow.WorkflowException)5 StringSet (com.emc.storageos.db.client.model.StringSet)4