use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class ProtectionSystemService method getConnectivity.
/**
* This method will assemble a connectivity table that expresses all of the storage systems
* that are connected via this protection system. We will mark which RP site each storage
* system is visible on.
*
* @param system protection system
* @return rest response
*/
private ProtectionSystemConnectivityRestRep getConnectivity(ProtectionSystem system) {
ProtectionSystemConnectivityRestRep response = new ProtectionSystemConnectivityRestRep();
// Dig through the RPSiteArray table for now and return connectivity
Map<String, Set<URI>> siteStorageSystemMap = new HashMap<String, Set<URI>>();
// Get the rp system's array mappings from the RP client
URIQueryResultList sitelist = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getRPSiteArrayProtectionSystemConstraint(system.getId().toString()), sitelist);
List<RPSiteArray> rpSiteArrays = new ArrayList<RPSiteArray>();
Iterator<URI> it = sitelist.iterator();
while (it.hasNext()) {
URI rpSiteArrayId = it.next();
RPSiteArray siteArray = _dbClient.queryObject(RPSiteArray.class, rpSiteArrayId);
if (siteArray != null) {
rpSiteArrays.add(siteArray);
}
}
for (RPSiteArray rpSiteArray : rpSiteArrays) {
_log.info("dicoverProtectionSystem(): analyzing rpsitearray: " + rpSiteArray.toString());
if (siteStorageSystemMap.get(rpSiteArray.getRpSiteName()) == null) {
siteStorageSystemMap.put(rpSiteArray.getRpSiteName(), new HashSet<URI>());
}
// Add this storage system associated with this RP Site
siteStorageSystemMap.get(rpSiteArray.getRpSiteName()).add(rpSiteArray.getStorageSystem());
}
// Translate the primitive type into a presentable type
for (String siteId : siteStorageSystemMap.keySet()) {
ProtectionSystemConnectivitySiteRestRep site = new ProtectionSystemConnectivitySiteRestRep();
site.setSiteID(siteId);
Set<URI> addedStorageSystems = new HashSet<URI>();
for (URI storageID : siteStorageSystemMap.get(siteId)) {
if (!addedStorageSystems.contains(storageID)) {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageID);
site.getStorageSystems().add(toRelatedResource(ResourceTypeEnum.STORAGE_SYSTEM, storageSystem.getId()));
addedStorageSystems.add(storageID);
}
}
if (response.getProtectionSites() == null) {
response.setProtectionSites(new ArrayList<ProtectionSystemConnectivitySiteRestRep>());
}
response.getProtectionSites().add(site);
}
response.setProtectionSystem(toNamedRelatedResource(ResourceTypeEnum.PROTECTION_SYSTEM, system.getId(), system.getLabel()));
return response;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class ResourceService method getDiscoveredComputeObjects.
/**
* Retrieves the list of objects with acls based on the tenant information.
*
* @param tenantId to used to filter the objects.
* @param clzz class of objects.
* @return the filtered list of objects with acls.
*/
protected <T extends DiscoveredComputeSystemWithAcls> Iterator<T> getDiscoveredComputeObjects(URI tenantId, Class<T> clzz) {
PermissionsKey permissionKey = new PermissionsKey(PermissionsKey.Type.TENANT, tenantId.toString());
URIQueryResultList resultURIs = new URIQueryResultList();
Constraint aclConstraint = ContainmentPermissionsConstraint.Factory.getDiscoveredObjsWithPermissionsConstraint(permissionKey.toString(), Vcenter.class);
_dbClient.queryByConstraint(aclConstraint, resultURIs);
List<URI> uris = new ArrayList<URI>();
for (URI result : resultURIs) {
uris.add(result);
}
Iterator<T> dataObjects = new ArrayList<T>().iterator();
if (uris != null && !uris.isEmpty()) {
dataObjects = _dbClient.queryIterativeObjectField(clzz, DATAOBJECT_NAME_FIELD, uris);
}
return dataObjects;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class FileService method getOtherSearchResults.
/**
* 'mountPath' is not case sensitive. The complete mountPath should be specified.
*
* If a matching filesystem is not found, an empty list is returned.
*
* Parameters - mountPath String - mountPath of the filesystem
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults result = new SearchResults();
// Here we search by mountPath
if (!parameters.containsKey("mountPath")) {
throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), "mountPath");
}
String mountPath = parameters.get("mountPath").get(0);
List<SearchResultResourceRep> resRepList = new ArrayList<SearchResultResourceRep>();
URIQueryResultList fsUriList = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileSystemMountPathConstraint(mountPath), fsUriList);
_log.info("After query of the database for {} and result {}", mountPath, fsUriList);
Iterator<URI> fsListIterator = fsUriList.iterator();
while (fsListIterator.hasNext()) {
URI uri = fsListIterator.next();
FileShare fs = _dbClient.queryObject(FileShare.class, uri);
if (!fs.getInactive()) {
if (authorized || isAuthorized(fs.getProject().getURI())) {
RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), uri));
SearchResultResourceRep r = new SearchResultResourceRep(uri, selfLink, fs.getMountPath());
resRepList.add(r);
_log.info("Mount path match " + fs.getMountPath());
} else {
_log.info("Mount path match but not authorized " + fs.getMountPath());
}
}
}
result.setResource(resRepList);
return result;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class FileService method getFileSystemSchedulePolicySnapshots.
/**
* Get file system Snapshot created by policy
*
* @param id
* The URN of a ViPR file system
* @param filePolicyUri
* The URN of a file policy schedule
* @param timeout
* Time limit in seconds to get the output .Default is 30 seconds
* @brief Get snapshots related to the specified policy
* @return List of snapshots created by a file policy
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/file-policies/{filePolicyUri}/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ScheduleSnapshotList getFileSystemSchedulePolicySnapshots(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, @QueryParam("timeout") int timeout) {
// valid value of timeout is 10 sec to 10 min
if (timeout < 10 || timeout > 600) {
// default timeout value.
timeout = 30;
}
ScheduleSnapshotList list = new ScheduleSnapshotList();
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
ArgValidator.checkUri(filePolicyUri);
FilePolicy sp = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
ArgValidator.checkEntityNotNull(sp, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
// verify the schedule policy is associated with file system or not.
if (!fs.getFilePolicies().contains(filePolicyUri.toString())) {
throw APIException.badRequests.cannotFindAssociatedPolicy(filePolicyUri);
}
String task = UUID.randomUUID().toString();
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
FileController controller = getController(FileController.class, device.getSystemType());
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE);
op.setDescription("list snapshots created by a policy");
try {
_log.info("No Errors found. Proceeding further {}, {}, {}", new Object[] { _dbClient, fs, sp });
controller.listSanpshotByPolicy(device.getId(), fs.getId(), sp.getId(), task);
Task taskObject = null;
auditOp(OperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), sp.getId());
int timeoutCounter = 0;
// wait till timeout or result from controller service ,whichever is earlier
do {
TimeUnit.SECONDS.sleep(1);
taskObject = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), task);
timeoutCounter++;
// exit the loop if task is completed with error/success or timeout
} while ((taskObject != null && !(taskObject.isReady() || taskObject.isError())) && timeoutCounter < timeout);
if (taskObject == null) {
throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots task information");
} else if (taskObject.isReady()) {
URIQueryResultList snapshotsURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id), snapshotsURIs);
List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapshotsURIs);
for (Snapshot snap : snapList) {
if (!snap.getInactive() && snap.getExtensions().containsKey("schedule")) {
ScheduleSnapshotRestRep snapRest = new ScheduleSnapshotRestRep();
getScheduleSnapshotRestRep(snapRest, snap);
list.getScheduleSnapList().add(snapRest);
snap.setInactive(true);
_dbClient.updateObject(snap);
}
}
} else if (taskObject.isError()) {
throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to" + taskObject.getMessage());
} else {
throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to timeout");
}
} catch (BadRequestException e) {
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Error while getting Filesystem policy Snapshots {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
} catch (Exception e) {
_log.error("Error while getting Filesystem policy Snapshots {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return list;
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class VirtualPoolUtil method isAutoTieringPolicyValidForDeviceType.
public static boolean isAutoTieringPolicyValidForDeviceType(String autoTierPolicyName, String systemType, DbClient dbClient) {
if (null == autoTierPolicyName || autoTierPolicyName.equalsIgnoreCase("NONE")) {
return true;
}
URIQueryResultList result = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFASTPolicyByNameConstraint(autoTierPolicyName), result);
while (result.iterator().hasNext()) {
AutoTieringPolicy policy = dbClient.queryObject(AutoTieringPolicy.class, result.iterator().next());
if (policy == null) {
continue;
}
if (systemType.equalsIgnoreCase(policy.getSystemType())) {
return true;
}
}
return false;
}
Aggregations