use of com.emc.storageos.model.search.SearchResults in project coprhd-controller by CoprHD.
the class IpInterfaceService method getOtherSearchResults.
/**
* parameter: 'ip_address' The ip address of the ipInterface
*
* @return Return a list of ipinterfaces that contains the ip address specified
* or an empty list if no match was found.
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults result = new SearchResults();
if (!parameters.containsKey("ip_address")) {
throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), "ip_address");
}
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
if (!entry.getKey().equals("ip_address")) {
throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), "ip_address", entry.getKey());
}
}
String ip = parameters.get("ip_address").get(0);
// Validate that the ip_address value is not empty
ArgValidator.checkFieldNotEmpty(ip, "ip_address");
// Validate the format of the initiator port.
if (!EndpointUtility.isValidEndpoint(ip, EndpointType.IP)) {
throw APIException.badRequests.invalidParameterInvalidIP("ip_address", ip);
}
SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
// Finds the IpInterface that includes the ip address specified, if any.
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getIpInterfaceIpAddressConstraint(ip), resRepList);
// Filter list based on permission
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.model.search.SearchResults in project coprhd-controller by CoprHD.
the class InitiatorService method getOtherSearchResults.
/**
* parameter: 'initiator_port' The identifier of the initiator port.
*
* @return Return a list of initiator that containts the initiator port specified
* or an empty list if no match was found.
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults result = new SearchResults();
if (!parameters.containsKey("initiator_port")) {
throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), "initiator_port");
}
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
if (!entry.getKey().equals("initiator_port")) {
throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), "initiator_port", entry.getKey());
}
}
String port = parameters.get("initiator_port").get(0);
// Validate that the initiator_port value is not empty
ArgValidator.checkFieldNotEmpty(port, "initiator_port");
// Validate the format of the initiator port.
if (!EndpointUtility.isValidEndpoint(port, EndpointType.SAN)) {
throw APIException.badRequests.initiatorPortNotValid();
}
SearchedResRepList resRepList = new SearchedResRepList(getResourceType());
// Finds the Initiator that includes the initiator port specified, if any.
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(port), resRepList);
// Filter list based on permission
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.model.search.SearchResults in project coprhd-controller by CoprHD.
the class VirtualArrayService method getOtherSearchResults.
/**
* Finds the virtual arrays for the initiator port with the passed
* identifier and returns the id, name, and self link for those virtual
* arrays. This API only supports fiber channel and iSCSI initiator ports,
* and the passed port identifier must be the WWN or IQN of the port.
*
* Note that in order for an initiator to be associated with any virtual,
* arrays it must be in an active network. The virtual arrays for the passed
* initiator are those active virtual arrays associated with the storage
* ports in the initiator's active network. If the initiator is not in a
* network, an empty list is returned.
*
* parameter: 'initiator_port' The identifier of the initiator port.
*
* @param parameters The search parameters.
* @param authorized Whether or not the caller is authorized.
*
* @return The search results specifying the virtual arrays for the
* initiator identified in the passed search parameters.
*/
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults result = new SearchResults();
String[] searchCriteria = { SEARCH_INITIATOR_PORT, SEARCH_HOST, SEARCH_CLUSTER };
validateSearchParameters(parameters, searchCriteria);
Set<String> varrayIds = new HashSet<String>();
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
if (entry.getKey().equals(SEARCH_INITIATOR_PORT)) {
String initiatorId = parameters.get(SEARCH_INITIATOR_PORT).get(0);
// Validate the user passed a value for the initiator port.
ArgValidator.checkFieldNotEmpty(initiatorId, SEARCH_INITIATOR_PORT);
// Validate the format of the passed initiator port.
if (!EndpointUtility.isValidEndpoint(initiatorId, EndpointType.ANY)) {
throw APIException.badRequests.initiatorPortNotValid();
}
_log.info("Searching for virtual arrays for initiator {}", initiatorId);
varrayIds.addAll(ConnectivityUtil.getInitiatorVarrays(initiatorId, _dbClient));
break;
} else if (entry.getKey().equals(SEARCH_HOST)) {
// find and validate host
String hostId = parameters.get(SEARCH_HOST).get(0);
URI hostUri = URI.create(hostId);
ArgValidator.checkFieldNotEmpty(hostId, SEARCH_HOST);
Host host = queryObject(Host.class, hostUri, false);
verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
_log.info("looking for virtual arrays connected to host " + host.getHostName());
varrayIds.addAll(getVarraysForHost(hostUri));
break;
} else if (entry.getKey().equals(SEARCH_CLUSTER)) {
// find and validate cluster
String clusterId = parameters.get(SEARCH_CLUSTER).get(0);
URI clusterUri = URI.create(clusterId);
ArgValidator.checkFieldNotEmpty(clusterId, SEARCH_CLUSTER);
Cluster cluster = queryObject(Cluster.class, clusterUri, false);
verifyAuthorizedInTenantOrg(cluster.getTenant(), getUserFromContext());
_log.info("looking for virtual arrays connected to cluster " + cluster.getLabel());
List<Set<String>> hostVarraySets = new ArrayList<Set<String>>();
List<NamedElementQueryResultList.NamedElement> dataObjects = listChildren(clusterUri, Host.class, "label", "cluster");
for (NamedElementQueryResultList.NamedElement dataObject : dataObjects) {
Set<String> hostVarrays = getVarraysForHost(dataObject.getId());
hostVarraySets.add(hostVarrays);
}
boolean first = true;
for (Set<String> varrays : hostVarraySets) {
if (first) {
varrayIds.addAll(varrays);
first = false;
} else {
varrayIds.retainAll(varrays);
}
}
break;
}
}
// For each virtual array in the set create a search result
// and add it to the search results list.
List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
if (!varrayIds.isEmpty()) {
for (String varrayId : varrayIds) {
URI varrayURI = URI.create(varrayId);
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayURI);
// Filter out those that are inactive or not accessible to the user.
if (varray == null || varray.getInactive()) {
_log.info("Could not find virtual array {} in the database, or " + "the virtual array is inactive", varrayURI);
continue;
}
if (!authorized) {
if (!_permissionsHelper.tenantHasUsageACL(URI.create(getUserFromContext().getTenantId()), varray)) {
_log.info("Virtual array {} is not accessible.", varrayURI);
continue;
}
}
RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), varrayURI));
SearchResultResourceRep searchResult = new SearchResultResourceRep(varrayURI, selfLink, varray.getLabel());
searchResultList.add(searchResult);
}
}
result.setResource(searchResultList);
return result;
}
use of com.emc.storageos.model.search.SearchResults in project coprhd-controller by CoprHD.
the class TaskService method getOtherSearchResults.
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults searchResults = new SearchResults();
Set<URI> tenantIds = getTenantIdsFromParams(parameters);
// Resource Query
if (parameters.containsKey(RESOURCE_QUERY_PARAM)) {
URI resourceId = URI.create(parameters.get(RESOURCE_QUERY_PARAM).get(0));
List<NamedURI> tasks = TaskUtils.findResourceTaskIds(_dbClient, resourceId);
if (!tasks.isEmpty()) {
// All the tasks will have the same TenantID as the Resource
Task task = queryResource(tasks.get(0).getURI());
verifyUserHasAccessToTenants(Collections.singletonList(task.getTenant()));
}
searchResults.getResource().addAll(toSearchResults(tasks));
} else if (parameters.containsKey(STATE_PARAM)) {
// Search by task state
String state = getStringParam(STATE_PARAM, parameters);
if (state != null) {
for (URI tenant : tenantIds) {
TaskUtils.ObjectQueryResult<Task> taskResult = TaskUtils.findTenantTasks(_dbClient, tenant);
while (taskResult.hasNext()) {
Task task = taskResult.next();
if (task.getStatus().equals(state)) {
searchResults.getResource().add(toSearchResult(task.getId()));
}
}
}
}
}
return searchResults;
}
use of com.emc.storageos.model.search.SearchResults 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;
}
Aggregations