Search in sources :

Example 1 with ContainmentConstraint

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

the class RPDeviceController method doDisableImageCopies.

/**
 * It is possible that RP snapshots are exported to more than one host and hence part of more than one ExportGroup.
 * If the same snapshot
 * is part of more than one active ExportGroup, do not disable Image Access on the RP CG.
 *
 * @param snapshot
 *            snapshot to be unexported
 * @return true if it is safe to disable image access on the CG, false otherwise
 */
public boolean doDisableImageCopies(BlockSnapshot snapshot) {
    ContainmentConstraint constraint = ContainmentConstraint.Factory.getBlockObjectExportGroupConstraint(snapshot.getId());
    URIQueryResultList exportGroupIdsForSnapshot = new URIQueryResultList();
    _dbClient.queryByConstraint(constraint, exportGroupIdsForSnapshot);
    Iterator<URI> exportGroupIdsForSnapshotIter = exportGroupIdsForSnapshot.iterator();
    Set<URI> exportGroupURIs = new HashSet<URI>();
    while (exportGroupIdsForSnapshotIter.hasNext()) {
        exportGroupURIs.add(exportGroupIdsForSnapshotIter.next());
    }
    if (exportGroupURIs.size() > 1) {
        _log.info(String.format("Snapshot %s is in %d active exportGroups. Not safe to disable the CG", snapshot.getEmName(), exportGroupURIs.size()));
        return false;
    }
    _log.info("Safe to disable image access on the CG");
    return true;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet)

Example 2 with ContainmentConstraint

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

the class FileDeviceController method queryFileExports.

private List<FileExportRule> queryFileExports(FileDeviceInputOutput args) {
    List<FileExportRule> fileExportRules = 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);
        }
        fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    return fileExportRules;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) 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 3 with ContainmentConstraint

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

the class FileDeviceController method resetReplicationFileSystemsRelation.

protected void resetReplicationFileSystemsRelation(FilePolicy filePolicy, PolicyStorageResource policyResource) {
    URI storageSystem = policyResource.getStorageSystem();
    String policyPath = policyResource.getResourcePath();
    // Remove the source - target relationship
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name())) {
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getStorageDeviceFileshareConstraint(storageSystem);
        List<FileShare> fileshares = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileShare.class, containmentConstraint);
        List<FileShare> modifiedFileshares = new ArrayList<>();
        for (FileShare fileshare : fileshares) {
            // should be decoupled!!!
            if (fileshare.getNativeId().startsWith(policyPath)) {
                if (fileshare.getPersonality() != null && fileshare.getPersonality().equalsIgnoreCase(PersonalityTypes.SOURCE.toString())) {
                    fileshare.setMirrorStatus(NullColumnValueGetter.getNullStr());
                    fileshare.setAccessState(NullColumnValueGetter.getNullStr());
                    fileshare.setPersonality(NullColumnValueGetter.getNullStr());
                    if (fileshare.getMirrorfsTargets() != null && !fileshare.getMirrorfsTargets().isEmpty()) {
                        StringSet targets = fileshare.getMirrorfsTargets();
                        for (String strTargetFs : targets) {
                            FileShare targetFs = _dbClient.queryObject(FileShare.class, URI.create(strTargetFs));
                            targetFs.setMirrorStatus(NullColumnValueGetter.getNullStr());
                            targetFs.setAccessState(NullColumnValueGetter.getNullStr());
                            targetFs.setParentFileShare(NullColumnValueGetter.getNullNamedURI());
                            targetFs.setPersonality(NullColumnValueGetter.getNullStr());
                            modifiedFileshares.add(targetFs);
                        }
                        targets.clear();
                        fileshare.setMirrorfsTargets(targets);
                    }
                }
                modifiedFileshares.add(fileshare);
            }
        }
        if (!modifiedFileshares.isEmpty()) {
            _dbClient.updateObject(modifiedFileshares);
        }
    }
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 4 with ContainmentConstraint

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

the class FileDeviceController method queryAllNfsACLInDB.

/**
 * To get all the ACLs of File System or a mention subDir.
 *
 * @param fs
 *            File System
 * @param subDir
 *            Sub directory
 * @return List of NFS ACL present in DB.
 */
private List<NFSShareACL> queryAllNfsACLInDB(FileShare fs, String subDir, FileDeviceInputOutput args) {
    List<NFSShareACL> allNfsShareAcl = null;
    List<NFSShareACL> returnNfsShareAcl = null;
    List<NFSShareACL> fsNfsShareAcl = new ArrayList<NFSShareACL>();
    List<NFSShareACL> subDirNfsShareAcl = new ArrayList<NFSShareACL>();
    _log.info("Querying all Nfs File System ACL Using FsId {}", fs.getId());
    try {
        ContainmentConstraint containmentConstraint = null;
        if (args.getFileOperation()) {
            containmentConstraint = ContainmentConstraint.Factory.getFileNfsAclsConstraint(fs.getId());
        } else {
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotNfsAclsConstraint(args.getSnapshotId());
        }
        allNfsShareAcl = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, NFSShareACL.class, containmentConstraint);
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    returnNfsShareAcl = fsNfsShareAcl;
    String absolutefsPath = fs.getPath();
    String absoluteDirPath = "";
    if (subDir != null && !subDir.isEmpty()) {
        absoluteDirPath = absolutefsPath + "/" + subDir;
        returnNfsShareAcl = subDirNfsShareAcl;
    }
    for (NFSShareACL nfsAcl : allNfsShareAcl) {
        if (nfsAcl.getFileSystemPath().equals(absoluteDirPath)) {
            subDirNfsShareAcl.add(nfsAcl);
        } else if (nfsAcl.getFileSystemPath().equals(absolutefsPath)) {
            fsNfsShareAcl.add(nfsAcl);
        }
    }
    return returnNfsShareAcl;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) NFSShareACL(com.emc.storageos.db.client.model.NFSShareACL) 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 5 with ContainmentConstraint

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

the class FileOrchestrationUtils method getFSExportRuleMap.

/**
 * This method generates export map for the file system export rules.
 *
 * @param fs File System Object
 * @param dbClient
 * @return
 */
public static HashMap<String, List<ExportRule>> getFSExportRuleMap(FileShare fs, DbClient dbClient) {
    ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
    List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileExportRule.class, containmentConstraint);
    HashMap<String, List<ExportRule>> exportRulesMap = new HashMap<String, List<ExportRule>>();
    for (FileExportRule fileExportRule : fileExportRules) {
        if (exportRulesMap.get(fileExportRule.getExportPath()) == null) {
            List<ExportRule> exportRules = new ArrayList<ExportRule>();
            ExportRule exportRule = convertFileExportRuleToExportRule(fileExportRule);
            exportRules.add(exportRule);
            exportRulesMap.put(fileExportRule.getExportPath(), exportRules);
        } else {
            List<ExportRule> exportRules = exportRulesMap.get(fileExportRule.getExportPath());
            ExportRule exportRule = convertFileExportRuleToExportRule(fileExportRule);
            exportRules.add(exportRule);
        }
    }
    return exportRulesMap;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

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