Search in sources :

Example 41 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class ExportUtils method validateConsistencyGroupBookmarksExported.

/**
 * Validates the given consistency group to ensure there are no RecoverPoint snapshots that have been
 * exported. If any RecoverPoint snapshots associated with the consistency group have been exported,
 * an exception will be thrown.
 *
 * @param dbClient the database client
 * @param consistencyGroupUri the consistency group URI
 */
public static void validateConsistencyGroupBookmarksExported(DbClient dbClient, URI consistencyGroupUri) {
    if (consistencyGroupUri == null) {
        // If the consistency group URI is null we cannot proceed with this validation so fail.
        throw APIException.badRequests.invalidConsistencyGroup();
    }
    _log.info(String.format("Performing validation to ensure no RP bookmarks have been exported for consistency group %s.", consistencyGroupUri));
    URIQueryResultList snapshotUris = new URIQueryResultList();
    ContainmentConstraint constraint = ContainmentConstraint.Factory.getBlockSnapshotByConsistencyGroup(consistencyGroupUri);
    dbClient.queryByConstraint(constraint, snapshotUris);
    List<BlockSnapshot> blockSnapshots = dbClient.queryObject(BlockSnapshot.class, snapshotUris);
    for (BlockSnapshot snapshot : blockSnapshots) {
        if (TechnologyType.RP.name().equalsIgnoreCase(snapshot.getTechnologyType())) {
            _log.info(String.format("Examining RP bookmark %s to see if it has been exported.", snapshot.getId()));
            // We have found an RP bookmark. Now lets see if that bookmark has been exported. Using the same
            // call that BlockSnapshotService uses to get snapshot exports.
            ContainmentConstraint exportGroupConstraint = ContainmentConstraint.Factory.getBlockObjectExportGroupConstraint(snapshot.getId());
            URIQueryResultList exportGroupIdsForSnapshot = new URIQueryResultList();
            dbClient.queryByConstraint(exportGroupConstraint, exportGroupIdsForSnapshot);
            Iterator<URI> exportGroupIdsForSnapshotIter = exportGroupIdsForSnapshot.iterator();
            if (exportGroupIdsForSnapshotIter != null && exportGroupIdsForSnapshotIter.hasNext()) {
                // The consistency group has a bookmark that is already exported so fail the operation.
                throw APIException.badRequests.cannotPerformOperationWithExportedBookmarks(snapshot.getId(), consistencyGroupUri);
            }
        }
    }
    _log.info(String.format("No RP bookmarks have been exported for consistency group %s.", consistencyGroupUri));
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 42 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class FileDeviceController method queryDBShareAcls.

private List<CifsShareACL> queryDBShareAcls(FileDeviceInputOutput args) {
    List<CifsShareACL> acls = new ArrayList<CifsShareACL>();
    try {
        ContainmentConstraint containmentConstraint = null;
        if (args.getFileOperation()) {
            FileShare fs = args.getFs();
            _log.info("Querying DB for Share ACLs of share {} of filesystemId {} ", args.getShareName(), fs.getId());
            containmentConstraint = ContainmentConstraint.Factory.getFileCifsShareAclsConstraint(fs.getId());
        } else {
            URI snapshotId = args.getSnapshotId();
            _log.info("Querying DB for Share ACLs of share {} of snapshotId {} ", args.getShareName(), snapshotId);
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotCifsShareAclsConstraint(snapshotId);
        }
        List<CifsShareACL> shareAclList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, CifsShareACL.class, containmentConstraint);
        Iterator<CifsShareACL> shareAclIter = shareAclList.iterator();
        while (shareAclIter.hasNext()) {
            CifsShareACL shareAcl = shareAclIter.next();
            if (shareAcl != null && args.getShareName().equals(shareAcl.getShareName())) {
                acls.add(shareAcl);
            }
        }
    } catch (Exception e) {
        _log.error("Error while querying DB for ACL(s) of a share {}", e);
    }
    return acls;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) 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) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL)

Example 43 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class FileDeviceController method checkIfMountExistsOnHost.

public void checkIfMountExistsOnHost(URI fsId, String opId) {
    try {
        WorkflowStepCompleter.stepExecuting(opId);
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileMountsConstraint(fsId);
        List<FileMountInfo> fsDBMounts = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileMountInfo.class, containmentConstraint);
        FileShare fs = _dbClient.queryObject(FileShare.class, fsId);
        for (FileMountInfo fsMount : fsDBMounts) {
            LinuxMountUtils mountUtils = new LinuxMountUtils(_dbClient.queryObject(Host.class, fsMount.getHostId()));
            ExportRule export = FileOperationUtils.findExport(fs, fsMount.getSubDirectory(), fsMount.getSecurityType(), _dbClient);
            if (mountUtils.verifyMountPoints(export.getMountPoint(), fsMount.getMountPath())) {
                String errMsg = new String("delete file system from ViPR database failed because mounts exist for file system " + fs.getLabel() + " and once deleted the mounts cannot be ingested into ViPR");
                final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.DELETE_FILE_SYSTEM.toString(), errMsg);
                WorkflowStepCompleter.stepFailed(opId, serviceCoded);
            }
        }
        for (FileMountInfo fsMount : fsDBMounts) {
            fsMount.setInactive(true);
        }
        _dbClient.updateObject(fsDBMounts);
        WorkflowStepCompleter.stepSucceded(opId);
    } catch (ControllerException ex) {
        WorkflowStepCompleter.stepFailed(opId, ex);
        _log.error("Couldn't verify dependencies: ", fsId);
        throw ex;
    }
}
Also used : LinuxMountUtils(com.emc.storageos.computesystemcontroller.hostmountadapters.LinuxMountUtils) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileMountInfo(com.emc.storageos.db.client.model.FileMountInfo) Host(com.emc.storageos.db.client.model.Host) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 44 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class FileDeviceController method queryExports.

private List<ExportRule> queryExports(FileDeviceInputOutput args) {
    List<ExportRule> rules = null;
    try {
        ContainmentConstraint containmentConstraint;
        if (args.getFileOperation()) {
            FileShare fs = args.getFs();
            _log.info("Querying all ExportRules Using FsId {}", fs.getId());
            containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
        } else {
            URI snapshotId = args.getSnapshotId();
            _log.info("Querying all ExportRules Using Snapshot Id {}", snapshotId);
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotExportRulesConstraint(snapshotId);
        }
        List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
        rules = new ArrayList<>();
        for (FileExportRule fileExportRule : fileExportRules) {
            ExportRule rule = new ExportRule();
            getExportRule(fileExportRule, rule);
            rules.add(rule);
        }
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    return rules;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) 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)

Example 45 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class FileDeviceController method queryFileQuotaDirs.

private List<QuotaDirectory> queryFileQuotaDirs(FileDeviceInputOutput args) {
    if (args.getFileOperation()) {
        FileShare fs = args.getFs();
        _log.info("Querying all quota directories Using FsId {}", fs.getId());
        try {
            ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getQuotaDirectoryConstraint(fs.getId());
            List<QuotaDirectory> fsQuotaDirs = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, QuotaDirectory.class, containmentConstraint);
            return fsQuotaDirs;
        } catch (Exception e) {
            _log.error("Error while querying {}", e);
        }
    }
    return null;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) 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)

Aggregations

ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)47 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)18 ArrayList (java.util.ArrayList)17 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 URI (java.net.URI)15 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)11 URISyntaxException (java.net.URISyntaxException)11 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)10 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)9 FileShare (com.emc.storageos.db.client.model.FileShare)7 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)7 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 WorkflowException (com.emc.storageos.workflow.WorkflowException)6 ContainmentConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl)5 FileMountInfo (com.emc.storageos.db.client.model.FileMountInfo)5 CifsShareACL (com.emc.storageos.db.client.model.CifsShareACL)4 NFSShareACL (com.emc.storageos.db.client.model.NFSShareACL)4 ExportRule (com.emc.storageos.model.file.ExportRule)4 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)4