Search in sources :

Example 31 with Constraint

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

the class GeoTest method testQueryByConstraint.

private void testQueryByConstraint() throws Exception {
    Constraint constraint = PrefixConstraint.Factory.getConstraint(VirtualArray.class, "label", "fo");
    URIQueryResultList ret = new URIQueryResultList();
    geoClient.queryByConstraint(constraint, ret);
    boolean foundId1 = false;
    boolean foundId2 = false;
    Iterator<URI> it = ret.iterator();
    while (it.hasNext()) {
        URI id = it.next();
        if (id1.equals(id)) {
            foundId1 = true;
        } else if (id2.equals(id)) {
            foundId2 = true;
        }
    }
    Assert.assertTrue("Can't find " + id1 + " in the query result", foundId1);
    Assert.assertTrue("Can't find " + id2 + " in the query result", foundId2);
    URIQueryResultList ids = new URIQueryResultList();
    geoClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolTypeVpoolConstraint(VirtualPool.Type.block), ids);
    it = ids.iterator();
    boolean found = false;
    while (it.hasNext()) {
        if (it.next().equals(virtualPoolId)) {
            found = true;
            break;
        }
    }
    Assert.assertTrue("Failed to found VirtualPool: " + virtualPoolId, found);
}
Also used : Constraint(com.emc.storageos.db.client.constraint.Constraint) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 32 with Constraint

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

the class QueryService method queryByConstraint.

@POST
@Path("geo-visible/constraint/{className}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public Response queryByConstraint(@PathParam("className") String className, ConstraintDescriptor constraintDescriptor, @QueryParam("start_id") URI startId, @QueryParam("max_count") Integer maxCount) throws DatabaseException {
    Constraint condition;
    try {
        condition = constraintDescriptor.toConstraint();
    } catch (ClassNotFoundException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | InstantiationException e) {
        throw APIException.badRequests.invalidParameterWithCause(constraintDescriptor.getClass().getName(), constraintDescriptor.toString(), e);
    }
    try {
        Class clazz = Class.forName(className);
        QueryResultList<?> resultList = (QueryResultList<?>) clazz.newInstance();
        if (maxCount == null) {
            dbClient.queryByConstraint(condition, resultList);
        } else {
            dbClient.queryByConstraint(condition, resultList, startId, maxCount);
        }
        return genResourcesResponse(resultList);
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        log.error("Can't find the class e=", e);
        throw APIException.badRequests.invalidParameter("className", className);
    }
}
Also used : QueryResultList(com.emc.storageos.db.client.constraint.QueryResultList) Constraint(com.emc.storageos.db.client.constraint.Constraint) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 33 with Constraint

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

the class BlockService method validateSRDFStopOperation.

/**
 * Cant Perform SRDF STOP operation Sync/Async with CG if it has active snap or clone.
 *
 * @param id
 * @param param
 */
private void validateSRDFStopOperation(URI id, CopiesParam param) {
    List<URI> srdfVolumeURIList = new ArrayList<URI>();
    Volume srdfSourceVolume = _dbClient.queryObject(Volume.class, id);
    if (srdfSourceVolume.checkForSRDF() && srdfSourceVolume.hasConsistencyGroup()) {
        srdfVolumeURIList.add(id);
        for (Copy copy : param.getCopies()) {
            URI copyID = copy.getCopyID();
            if (URIUtil.isType(copyID, Volume.class) && URIUtil.isValid(copyID)) {
                srdfVolumeURIList.add(copyID);
                break;
            }
        }
        for (URI srdfVolURI : srdfVolumeURIList) {
            Volume volume = _dbClient.queryObject(Volume.class, srdfVolURI);
            URIQueryResultList list = new URIQueryResultList();
            Constraint constraint = ContainmentConstraint.Factory.getVolumeSnapshotConstraint(srdfVolURI);
            _dbClient.queryByConstraint(constraint, list);
            Iterator<URI> it = list.iterator();
            while (it.hasNext()) {
                URI snapshotID = it.next();
                BlockSnapshot snapshot = _dbClient.queryObject(BlockSnapshot.class, snapshotID);
                if (snapshot != null && !snapshot.getInactive()) {
                    throw APIException.badRequests.cannotStopSRDFBlockSnapShotExists(volume.getLabel());
                }
            }
            // Also check for snapshot sessions.
            List<BlockSnapshotSession> snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, BlockSnapshotSession.class, ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(srdfVolURI));
            if (!snapSessions.isEmpty()) {
                throw APIException.badRequests.cannotStopSRDFBlockSnapShotExists(volume.getLabel());
            }
            // full copies deleting the volume may not be allowed.
            if (!getFullCopyManager().volumeCanBeDeleted(volume)) {
                throw APIException.badRequests.cantStopSRDFFullCopyNotDetached(volume.getLabel());
            }
        }
    }
}
Also used : BlockSnapshotSession(com.emc.storageos.db.client.model.BlockSnapshotSession) MapVolume(com.emc.storageos.api.mapper.functions.MapVolume) Volume(com.emc.storageos.db.client.model.Volume) Copy(com.emc.storageos.model.block.Copy) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 34 with Constraint

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

the class RPDeviceController method setProtectionSetStatus.

private void setProtectionSetStatus(RecoverPointVolumeProtectionInfo volumeProtectionInfo, String protectionSetStatus, ProtectionSystem system) {
    // 
    if (volumeProtectionInfo.getRpVolumeCurrentProtectionStatus() == RecoverPointVolumeProtectionInfo.volumeProtectionStatus.PROTECTED_SOURCE) {
        URIQueryResultList list = new URIQueryResultList();
        Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(system.getId());
        try {
            _dbClient.queryByConstraint(constraint, list);
            Iterator<URI> it = list.iterator();
            while (it.hasNext()) {
                URI protectionSetId = it.next();
                _log.info("Check protection set ID: " + protectionSetId);
                ProtectionSet protectionSet;
                protectionSet = _dbClient.queryObject(ProtectionSet.class, protectionSetId);
                if (protectionSet.getInactive() == false) {
                    _log.info("Change the status to: " + protectionSetStatus);
                    protectionSet.setProtectionStatus(protectionSetStatus);
                    _dbClient.updateObject(protectionSet);
                    break;
                }
            }
        } catch (DatabaseException e) {
        // Don't worry about this
        }
    } else {
        _log.info("Did not pause the protection source.  Not updating protection status");
    }
}
Also used : AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

Constraint (com.emc.storageos.db.client.constraint.Constraint)34 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)25 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)24 URI (java.net.URI)23 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)18 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)16 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)16 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)14 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)13 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 NamedURI (com.emc.storageos.db.client.model.NamedURI)7 Volume (com.emc.storageos.db.client.model.Volume)5 AggregationQueryResultList (com.emc.storageos.db.client.constraint.AggregationQueryResultList)4 Project (com.emc.storageos.db.client.model.Project)4 ProtectionSet (com.emc.storageos.db.client.model.ProtectionSet)4 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 DataObject (com.emc.storageos.db.client.model.DataObject)3 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)3 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)2