Search in sources :

Example 6 with SearchResults

use of com.emc.storageos.model.search.SearchResults in project coprhd-controller by CoprHD.

the class EventService method getOtherSearchResults.

@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    SearchResults searchResults = new SearchResults();
    if (parameters.containsKey(RESOURCE_QUERY_PARAM)) {
        URI resourceId = URI.create(parameters.get(RESOURCE_QUERY_PARAM).get(0));
        List<ActionableEvent> events = EventUtils.findResourceEvents(_dbClient, resourceId);
        searchResults.getResource().addAll(toSearchResults(events));
    }
    return searchResults;
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) SearchResults(com.emc.storageos.model.search.SearchResults) URI(java.net.URI)

Example 7 with SearchResults

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;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) SearchResults(com.emc.storageos.model.search.SearchResults) URI(java.net.URI) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) VArrayAttributeList(com.emc.storageos.model.varray.VArrayAttributeList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) StoragePortList(com.emc.storageos.model.ports.StoragePortList) ArrayList(java.util.ArrayList) StoragePoolList(com.emc.storageos.model.pools.StoragePoolList) VirtualArrayConnectivityList(com.emc.storageos.model.varray.VirtualArrayConnectivityList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) AttributeList(com.emc.storageos.model.varray.AttributeList) List(java.util.List) AutoTierPolicyList(com.emc.storageos.model.block.tier.AutoTierPolicyList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) NetworkList(com.emc.storageos.model.varray.NetworkList) Map(java.util.Map) HashMap(java.util.HashMap) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) HashSet(java.util.HashSet)

Example 8 with SearchResults

use of com.emc.storageos.model.search.SearchResults in project coprhd-controller by CoprHD.

the class OrderService method getOtherSearchResults.

/**
 * parameter: 'orderStatus' The status for the order
 * parameter: 'startTime' Start time to search for orders
 * parameter: 'endTime' End time to search for orders
 *
 * @return Return a list of matching orders or an empty list if no match was found.
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    StorageOSUser user = getUserFromContext();
    String tenantId = user.getTenantId();
    if (parameters.containsKey(SearchConstants.TENANT_ID_PARAM)) {
        tenantId = parameters.get(SearchConstants.TENANT_ID_PARAM).get(0);
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), user);
    if (!parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM) && !parameters.containsKey(SearchConstants.START_TIME_PARAM) && !parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM + " or " + SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
    }
    if (parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM) && (parameters.containsKey(SearchConstants.START_TIME_PARAM) || parameters.containsKey(SearchConstants.END_TIME_PARAM))) {
        throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM, SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
    }
    List<Order> orders = Lists.newArrayList();
    if (parameters.containsKey(SearchConstants.ORDER_STATUS_PARAM)) {
        String orderStatus = parameters.get(SearchConstants.ORDER_STATUS_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(orderStatus, SearchConstants.ORDER_STATUS_PARAM);
        orders = orderManager.findOrdersByStatus(uri(tenantId), OrderStatus.valueOf(orderStatus));
    } else if (parameters.containsKey(SearchConstants.START_TIME_PARAM) || parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
        Date startTime = null;
        if (parameters.containsKey(SearchConstants.START_TIME_PARAM)) {
            startTime = TimeUtils.getDateTimestamp(parameters.get(SearchConstants.START_TIME_PARAM).get(0));
        }
        Date endTime = null;
        if (parameters.containsKey(SearchConstants.END_TIME_PARAM)) {
            endTime = TimeUtils.getDateTimestamp(parameters.get(SearchConstants.END_TIME_PARAM).get(0));
        }
        if (startTime == null && endTime == null) {
            throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_STATUS_PARAM + " or " + SearchConstants.START_TIME_PARAM + " or " + SearchConstants.END_TIME_PARAM);
        }
        if (startTime.after(endTime)) {
            throw APIException.badRequests.endTimeBeforeStartTime(startTime.toString(), endTime.toString());
        }
        int maxCount = -1;
        List<String> c = parameters.get(SearchConstants.ORDER_MAX_COUNT);
        if (c != null) {
            String maxCountParam = parameters.get(SearchConstants.ORDER_MAX_COUNT).get(0);
            maxCount = Integer.parseInt(maxCountParam);
        }
        orders = orderManager.findOrdersByTimeRange(uri(tenantId), startTime, endTime, maxCount);
    }
    ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
    List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
    for (Order order : orders) {
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), order.getId()));
        SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
        searchResultResourceRep.setId(order.getId());
        searchResultResourceRep.setLink(selfLink);
        if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
            searchResultResourceReps.add(searchResultResourceRep);
        }
    }
    SearchResults result = new SearchResults();
    result.setResource(searchResultResourceReps);
    return result;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) RestLinkRep(com.emc.storageos.model.RestLinkRep) OrderMapper.toExecutionLogList(com.emc.sa.api.mapper.OrderMapper.toExecutionLogList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) ArrayList(java.util.ArrayList) OrderMapper.toOrderLogList(com.emc.sa.api.mapper.OrderMapper.toOrderLogList) OrderLogList(com.emc.vipr.model.catalog.OrderLogList) OrderList(com.emc.vipr.model.catalog.OrderList) List(java.util.List) ExecutionLogList(com.emc.vipr.model.catalog.ExecutionLogList) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString) ResRepFilter(com.emc.storageos.api.service.impl.response.ResRepFilter) SearchResults(com.emc.storageos.model.search.SearchResults) Date(java.util.Date)

Example 9 with SearchResults

use of com.emc.storageos.model.search.SearchResults in project coprhd-controller by CoprHD.

the class ApprovalService method getOtherSearchResults.

/**
 * parameter: 'orderId' The id of the order to search for approvals
 * parameter: 'approvalStatus' The status for the approval.
 * parameter: 'tenantId' The id of the tenant (if not the current tenant)
 *
 * @return Return a list of matching approvals or an empty list if no match was found.
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    StorageOSUser user = getUserFromContext();
    String tenantId = user.getTenantId();
    if (parameters.containsKey(SearchConstants.TENANT_ID_PARAM)) {
        tenantId = parameters.get(SearchConstants.TENANT_ID_PARAM).get(0);
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), user);
    if (!parameters.containsKey(SearchConstants.ORDER_ID_PARAM) && !parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        throw APIException.badRequests.invalidParameterSearchMissingParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM + " or " + SearchConstants.APPROVAL_STATUS_PARAM);
    }
    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM) && parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        throw APIException.badRequests.parameterForSearchCouldNotBeCombinedWithAnyOtherParameter(getResourceClass().getName(), SearchConstants.ORDER_ID_PARAM, SearchConstants.APPROVAL_STATUS_PARAM);
    }
    List<ApprovalRequest> approvals = Lists.newArrayList();
    if (parameters.containsKey(SearchConstants.ORDER_ID_PARAM)) {
        String orderId = parameters.get(SearchConstants.ORDER_ID_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(orderId, SearchConstants.ORDER_ID_PARAM);
        approvals = approvalManager.findApprovalsByOrderId(uri(orderId));
    } else if (parameters.containsKey(SearchConstants.APPROVAL_STATUS_PARAM)) {
        String approvalStatus = parameters.get(SearchConstants.APPROVAL_STATUS_PARAM).get(0);
        ArgValidator.checkFieldNotEmpty(approvalStatus, SearchConstants.APPROVAL_STATUS_PARAM);
        approvals = approvalManager.findApprovalsByStatus(uri(tenantId), ApprovalStatus.valueOf(approvalStatus));
    }
    ResRepFilter<SearchResultResourceRep> resRepFilter = (ResRepFilter<SearchResultResourceRep>) getPermissionFilter(getUserFromContext(), _permissionsHelper);
    List<SearchResultResourceRep> searchResultResourceReps = Lists.newArrayList();
    for (ApprovalRequest approval : approvals) {
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), approval.getId()));
        SearchResultResourceRep searchResultResourceRep = new SearchResultResourceRep();
        searchResultResourceRep.setId(approval.getId());
        searchResultResourceRep.setLink(selfLink);
        if (authorized || resRepFilter.isAccessible(searchResultResourceRep)) {
            searchResultResourceReps.add(searchResultResourceRep);
        }
    }
    SearchResults result = new SearchResults();
    result.setResource(searchResultResourceReps);
    return result;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ApprovalRequest(com.emc.storageos.db.client.model.uimodels.ApprovalRequest) RestLinkRep(com.emc.storageos.model.RestLinkRep) ResRepFilter(com.emc.storageos.api.service.impl.response.ResRepFilter) SearchResults(com.emc.storageos.model.search.SearchResults)

Example 10 with SearchResults

use of com.emc.storageos.model.search.SearchResults in project coprhd-controller by CoprHD.

the class AbstractResources method performSearch.

/**
 * Performs a search for resources matching the given parameters.
 *
 * @param params
 *            the search query parameters.
 * @return the list of resources.
 */
public List<SearchResultResourceRep> performSearch(Map<String, Object> params) {
    UriBuilder builder = client.uriBuilder(getSearchUrl());
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        builder.queryParam(entry.getKey(), entry.getValue());
    }
    SearchResults searchResults = client.getURI(SearchResults.class, builder.build());
    List<SearchResultResourceRep> results = searchResults.getResource();
    if (results == null) {
        results = new ArrayList<SearchResultResourceRep>();
    }
    return results;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) UriBuilder(javax.ws.rs.core.UriBuilder) SearchResults(com.emc.storageos.model.search.SearchResults)

Aggregations

SearchResults (com.emc.storageos.model.search.SearchResults)13 SearchResultResourceRep (com.emc.storageos.model.search.SearchResultResourceRep)11 List (java.util.List)8 URI (java.net.URI)7 BulkList (com.emc.storageos.api.service.impl.response.BulkList)6 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)6 RestLinkRep (com.emc.storageos.model.RestLinkRep)6 ArrayList (java.util.ArrayList)6 ResRepFilter (com.emc.storageos.api.service.impl.response.ResRepFilter)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 Map (java.util.Map)5 StringMap (com.emc.storageos.db.client.model.StringMap)3 ITLRestRepList (com.emc.storageos.model.block.export.ITLRestRepList)3 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)3 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 HashMap (java.util.HashMap)2 OrderMapper.toExecutionLogList (com.emc.sa.api.mapper.OrderMapper.toExecutionLogList)1 OrderMapper.toOrderLogList (com.emc.sa.api.mapper.OrderMapper.toOrderLogList)1 MapCustomConfig (com.emc.storageos.api.mapper.functions.MapCustomConfig)1