use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.
the class VolumeService method findExportGroup.
protected ExportGroup findExportGroup(Volume vol) {
// Get export group for the volume
SearchedResRepList resRepList = new SearchedResRepList(ResourceTypeEnum.EXPORT_GROUP);
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getVolumeExportGroupConstraint(vol.getId()), resRepList);
if (resRepList.iterator() != null) {
for (SearchResultResourceRep res : resRepList) {
ExportGroup group = _dbClient.queryObject(ExportGroup.class, res.getId());
if ((group != null) && !(group.getInactive())) {
return group;
}
}
}
// if not found
return null;
}
use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.
the class BlockService method getProjectSearchResults.
/**
* Get search results by project alone.
*
* @return SearchedResRepList
*/
@Override
protected SearchedResRepList getProjectSearchResults(URI projectId) {
SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(projectId), resRepList);
return resRepList;
}
use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.
the class BlockService method getOtherSearchResults.
/**
* Additional search criteria for a volume.
*
* If a matching volume is not found, an empty list is returned.
*
* Parameters - wwn String - WWN of the volume
* - virtual_array String - URI of the source virtual array
* - personality String - source, target, metadata
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults result = new SearchResults();
String[] searchCriteria = { SEARCH_WWN, SEARCH_VARRAY, SEARCH_PERSONALITY, SEARCH_PROTECTION };
// Make sure the parameters passed in contain at least one of our search criteria
// Here we search by wwn or virtual_array
boolean found = false;
for (String search : searchCriteria) {
if (parameters.containsKey(search)) {
found = true;
}
}
if (!found) {
throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), searchCriteria.toString());
}
// Make sure all parameters are our parameters, otherwise post an exception because we don't support other
// search criteria than our
// own.
String nonVolumeKey = null;
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
found = false;
for (String search : searchCriteria) {
if (entry.getKey().equals(search)) {
found = true;
}
}
if (!found) {
nonVolumeKey = entry.getKey();
}
}
if (nonVolumeKey != null) {
throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), searchCriteria.toString(), nonVolumeKey);
}
boolean simpleSearch = false;
// Now perform individual searches based on the input criteria. These results are stored and joined later if
// there were
// multiple search criteria.
List<List<SearchResultResourceRep>> resRepLists = new ArrayList<List<SearchResultResourceRep>>();
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
for (String searchValue : entry.getValue()) {
SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
if (entry.getKey().equals(SEARCH_WWN)) {
simpleSearch = true;
String wwn = searchValue;
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn.toUpperCase()), resRepList);
} else if (entry.getKey().equals(SEARCH_VARRAY)) {
simpleSearch = true;
String varrayId = searchValue;
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getConstraint(Volume.class, "varray", varrayId), resRepList);
} else if (entry.getKey().equals(SEARCH_PERSONALITY)) {
simpleSearch = true;
String personality = searchValue;
// Validate the personality type
boolean valid = false;
for (PersonalityTypes personalityType : Volume.PersonalityTypes.values()) {
if (personalityType.toString().equals(personality)) {
valid = true;
}
}
if (!valid) {
throw APIException.badRequests.parameterForSearchHasInvalidSearchValueWithSuggestions(getResourceClass().getName(), entry.getKey(), personality, PersonalityTypes.values());
}
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getConstraint(Volume.class, "personality", personality), resRepList);
}
// Convert to a list; SearchedResRepList is immutable and not really made for what we're doing here.
List<SearchResultResourceRep> repList = new ArrayList<SearchResultResourceRep>();
if (resRepList.iterator() != null) {
for (SearchResultResourceRep res : resRepList) {
repList.add(res);
}
resRepLists.add(repList);
}
}
}
// Now perform a "join" on the resRepList entries to create a single set of resources
Set<SearchResultResourceRep> resRepSet = new HashSet<SearchResultResourceRep>();
for (List<SearchResultResourceRep> resList : resRepLists) {
for (SearchResultResourceRep res : resList) {
resRepSet.add(res);
}
}
// Remove entries that aren't in every collection
for (List<SearchResultResourceRep> resList : resRepLists) {
resRepSet.retainAll(resList);
}
//
// Non-Indexed (manual) query result business logic goes here, after we've already reduced the list
//
boolean advancedQuery = false;
if (parameters.containsKey(SEARCH_PROTECTION)) {
// Prevent the expensive advanced query unless you see certain parameters
advancedQuery = true;
}
// resRepSet
if (advancedQuery) {
// simple parameters, like personality=SOURCE to pre-fill a much smaller list of objects and avoid this.
if (!simpleSearch) {
List<URI> volumes = _dbClient.queryByType(Volume.class, true);
for (URI volumeId : volumes) {
RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(ResourceTypeEnum.VOLUME, volumeId));
resRepSet.add(new SearchResultResourceRep(volumeId, selfLink, null));
}
_log.warn(String.format("Performance of Volume search is poor when specifying only %s with no additional search parameters." + "Search performs faster when combined with other parameters such as %s, %s", SEARCH_PROTECTION, SEARCH_PERSONALITY, SEARCH_VARRAY));
}
List<SearchResultResourceRep> resToInclude = new ArrayList<SearchResultResourceRep>();
for (SearchResultResourceRep res : resRepSet) {
Volume volume = _dbClient.queryObject(Volume.class, res.getId());
boolean personalityIsSource = volume.getPersonality() == null || volume.getPersonality().equalsIgnoreCase(Volume.PersonalityTypes.SOURCE.toString());
boolean ha = volume.getAssociatedVolumes() != null && !volume.getAssociatedVolumes().isEmpty();
boolean srdf = volume.getSrdfTargets() != null && !volume.getSrdfTargets().isEmpty();
boolean rp = volume.getRpTargets() != null && !volume.getRpTargets().isEmpty();
boolean isProtected = personalityIsSource && (ha || srdf || rp);
boolean includeResource = true;
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
for (String searchValue : entry.getValue()) {
if (entry.getKey().equals(SEARCH_PROTECTION)) {
// Validate the protection parameter
boolean valid = false;
String[] validProtection = { TRUE_STR, FALSE_STR, RP, SRDF, VPLEX, HA };
for (String validValue : validProtection) {
if (validValue.toString().equalsIgnoreCase(searchValue)) {
valid = true;
}
}
if (!valid) {
throw APIException.badRequests.parameterForSearchHasInvalidSearchValueWithSuggestions(getResourceClass().getName(), entry.getKey(), searchValue, validProtection);
}
if ((searchValue.equals(TRUE_STR) && !isProtected) || (searchValue.equals(FALSE_STR) && isProtected)) {
includeResource = false;
} else if (searchValue.equalsIgnoreCase(RP) && !rp) {
includeResource = false;
} else if ((searchValue.equalsIgnoreCase(VPLEX) || searchValue.equalsIgnoreCase(HA)) && !ha) {
includeResource = false;
} else if (searchValue.equalsIgnoreCase(SRDF) && !srdf) {
includeResource = false;
}
}
}
}
if (includeResource) {
resToInclude.add(res);
}
}
// Reduce the set
resRepSet.retainAll(resToInclude);
}
// Convert to a format consumable by our utilities
List<SearchResultResourceRep> resRepList = new ArrayList<SearchResultResourceRep>();
for (SearchResultResourceRep res : resRepSet) {
resRepList.add(res);
}
if (!authorized) {
Iterator<SearchResultResourceRep> _queryResultIterator = resRepList.iterator();
ResRepFilter<SearchResultResourceRep> resrepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
SearchedResRepList filteredResRepList = new SearchedResRepList();
filteredResRepList.setResult(new FilterIterator<SearchResultResourceRep>(_queryResultIterator, resrepFilter));
result.setResource(filteredResRepList);
} else {
result.setResource(resRepList);
}
return result;
}
use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.
the class BlockSnapshotService method getProjectSearchResults.
/**
* Get search results by project alone.
*
* @return SearchedResRepList
*/
@Override
protected SearchedResRepList getProjectSearchResults(URI projectId) {
SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectBlockSnapshotConstraint(projectId), resRepList);
return resRepList;
}
use of com.emc.storageos.api.service.impl.response.SearchedResRepList in project coprhd-controller by CoprHD.
the class TaggedResource method search.
/**
* @brief search API
* Search resources by name, tag, project or additional parameters (for example, wwn or initiator_port etc.)
*
* @prereq none
* @return search results
*/
/*
* Parameters:
* Common Parameters:
* name: Name has to be a minimum of 2 characters. Could only be combined with project parameter
* tag: Tag has to be a minimum of 2 characters. Could only be combined with tenant parameter
* project: The full project URI needs to be provided.
*
* NOTE: Name and tag are not case sensitive.
* For Zone level resources, search by project is not allowed.
* Special Parameters:
* wwn: only used by block service
* initiator_port: only used by virtual array service.
*/
@GET
@Path("/search")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SearchResults search() {
// 1. Figure out user privilege
boolean bAuthorized = false;
StorageOSUser user = getUserFromContext();
if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_MONITOR)) {
bAuthorized = true;
} else if ((isZoneLevelResource() || isSysAdminReadableResource()) && (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN))) {
bAuthorized = true;
}
// 2. Parameter check and early detection for unsupported search
String name = null, tag = null;
URI projectId = null, tenant = null;
Map<String, List<String>> parameters = uriInfo.getQueryParameters();
// remove non-search related common parameters
parameters.remove(RequestProcessingUtils.REQUESTING_COOKIES);
if (parameters.containsKey("name")) {
name = parameters.get("name").get(0);
checkSearchParameterLength("name", name, getResourceClass());
checkParameterCombination(parameters, getResourceClass(), "name", "project");
}
if (parameters.containsKey("tag")) {
tag = parameters.get("tag").get(0);
checkSearchParameterLength("tag", tag, getResourceClass());
checkParameterCombination(parameters, getResourceClass(), "tag", "tenant");
// set tenant scope for non-zone resources
if (!isZoneLevelResource()) {
if (parameters.containsKey("tenant")) {
tenant = URI.create(parameters.get("tenant").get(0));
}
}
}
if (parameters.containsKey("project")) {
checkParameterCombination(parameters, getResourceClass(), "project", "name");
projectId = URI.create(parameters.get("project").get(0));
if (isZoneLevelResource()) {
throw APIException.badRequests.invalidParameterSearchProjectNotSupported(getResourceClass().getName());
}
// check if user is authorized for the project
if (!bAuthorized) {
if (!isAuthorized(projectId)) {
throw APIException.forbidden.insufficientPermissionsForUser(getUserFromContext().toString());
}
bAuthorized = true;
}
}
// 3. Search from db and response permission-eligible results
SearchResults result = new SearchResults();
if (name != null || tag != null) {
SearchedResRepList resRepList = null;
if (name != null) {
// search named resources
resRepList = getNamedSearchResults(name, projectId);
} else {
// search tagged resources
resRepList = getTagSearchResults(tag, tenant);
}
if (!bAuthorized) {
SearchedResRepList filteredResRepList = new SearchedResRepList();
Iterator<SearchResultResourceRep> _queryResultIterator = resRepList.iterator();
ResRepFilter<SearchResultResourceRep> resrepFilter = null;
resrepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
filteredResRepList.setResult(new FilterIterator<SearchResultResourceRep>(_queryResultIterator, resrepFilter));
result.setResource(filteredResRepList);
} else {
result.setResource(resRepList);
}
return result;
}
if (projectId != null) {
// start resource search within project
// note: for project resources search, the permission check
// has been addressed in parameter checke period.
result.setResource(getProjectSearchResults(projectId));
return result;
}
// some other resource specific search
return getOtherSearchResults(parameters, bAuthorized);
}
Aggregations