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);
}
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);
}
}
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());
}
}
}
}
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");
}
}
Aggregations