Search in sources :

Example 1 with RestLinkRep

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

the class TaskService method getLatestTasks.

// This method uses heap sort to return latest n tasks where n <= 10K.
private TasksList getLatestTasks(Set<URI> tenantIds, String startTime, String endTime, Integer maxCount) {
    PriorityQueue<TimestampedURIQueryResult.TimestampedURI> taskHeap = new PriorityQueue<>(maxCount, new MinTaskComparator());
    Date startWindowDate = TimeUtils.getDateTimestamp(startTime);
    Date endWindowDate = TimeUtils.getDateTimestamp(endTime);
    // Fetch index entries and load into sorted set
    int taskCount = 0;
    for (URI normalizedTenantId : tenantIds) {
        log.debug("Retriving tasks from tenant {}", normalizedTenantId);
        TimestampedURIQueryResult taskIds = new TimestampedURIQueryResult();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getTimedTenantOrgTaskConstraint(normalizedTenantId, startWindowDate, endWindowDate), taskIds);
        Iterator<TimestampedURIQueryResult.TimestampedURI> it = taskIds.iterator();
        while (it.hasNext()) {
            TimestampedURIQueryResult.TimestampedURI timestampedURI = it.next();
            // Add first maxCount tasks to PQ
            if (taskHeap.size() < maxCount) {
                taskHeap.add(timestampedURI);
                taskCount++;
            } else {
                // Add the rest tasks into PQ if task timestamp is >= than the lowest timestamp task in PQ
                if (timestampedURI.getTimestamp() >= taskHeap.peek().getTimestamp()) {
                    taskHeap.poll();
                    taskHeap.add(timestampedURI);
                }
                taskCount++;
            }
        }
    }
    log.debug("The number of tasks of all tenants is {}, heap size is {}", taskCount, taskHeap.size());
    List<NamedRelatedResourceRep> resourceReps = Lists.newArrayList();
    while (!taskHeap.isEmpty()) {
        TimestampedURIQueryResult.TimestampedURI uri = taskHeap.poll();
        RestLinkRep link = new RestLinkRep("self", RestLinkFactory.newLink(ResourceTypeEnum.TASK, uri.getUri()));
        resourceReps.add(new NamedRelatedResourceRep(uri.getUri(), link, uri.getName()));
    }
    return new TasksList(resourceReps);
}
Also used : RestLinkRep(com.emc.storageos.model.RestLinkRep) TimestampedURIQueryResult(com.emc.storageos.db.client.TimestampedURIQueryResult) PriorityQueue(java.util.PriorityQueue) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Date(java.util.Date) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) TasksList(com.emc.storageos.model.tasks.TasksList)

Example 2 with RestLinkRep

use of com.emc.storageos.model.RestLinkRep 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;
}
Also used : SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) SearchResults(com.emc.storageos.model.search.SearchResults) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 3 with RestLinkRep

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

the class ExportGroupService method buildExportGroupSearchResponse.

/**
 * Build search response based on query result.
 *
 * @param exportGroups from query
 * @param resRepLists result
 * @param selfOnly true or false
 * @param type Cluster, Host or Initiator
 */
private void buildExportGroupSearchResponse(List<ExportGroup> exportGroups, List<SearchResultResourceRep> resRepLists, boolean selfOnly, String type, boolean authorized) {
    PermissionsEnforcingResourceFilter<ExportGroup> filter = new ExportGroupSearchFilter(getUserFromContext(), _permissionsHelper);
    for (ExportGroup eg : exportGroups) {
        if (!authorized && !filter.isExposed(eg)) {
            // authorization failed, don't add to search result
            continue;
        }
        if (selfOnly) {
            if (!eg.getType().equals(type)) {
                // match invalid, only return matching types, process next
                continue;
            }
        }
        RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), eg.getId()));
        SearchResultResourceRep searchResult = new SearchResultResourceRep(eg.getId(), selfLink, eg.getLabel());
        resRepLists.add(searchResult);
    }
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) RestLinkRep(com.emc.storageos.model.RestLinkRep)

Example 4 with RestLinkRep

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

the class CustomConfigService method getCustomConfigTypes.

/**
 * List config types.
 *
 * @brief List of config types
 * @return The list of config types.
 */
@GET
@Path("/types")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public CustomConfigTypeList getCustomConfigTypes() {
    List<CustomConfigType> items = customConfigHandler.getCustomConfigTypes();
    List<RelatedConfigTypeRep> types = new ArrayList<RelatedConfigTypeRep>();
    for (CustomConfigType item : items) {
        RelatedConfigTypeRep type = new RelatedConfigTypeRep();
        // build config type Link
        String service = ResourceTypeEnum.CONFIG_TYPE.getService();
        StringBuilder build = (new StringBuilder(service)).append('/').append(item.getName());
        type.setConfigName(item.getName());
        try {
            type.setSelfLink(new RestLinkRep("self", new URI(build.toString())));
        } catch (URISyntaxException e) {
        // it should not happen
        }
        types.add(type);
    }
    return new CustomConfigTypeList(types);
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) RelatedConfigTypeRep(com.emc.storageos.model.customconfig.RelatedConfigTypeRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CustomConfigTypeList(com.emc.storageos.model.customconfig.CustomConfigTypeList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with RestLinkRep

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

the class CustomConfigService method search.

/**
 * Search configs
 * <p>
 * Users could search configs by name, or config_name, or scope or system_default flag. e.g. /search?name=;
 * /search?config_name=SanZoneName; /search?config_name=SanZoneName&&scope=systemType.mds
 *
 * @brief Search configs
 * @return search result
 */
@GET
@Path("/search")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SearchResults search() {
    Map<String, List<String>> parameters = uriInfo.getQueryParameters();
    // remove non-search related common parameters
    parameters.remove(RequestProcessingUtils.REQUESTING_COOKIES);
    SearchedResRepList resRepList = null;
    SearchResults result = new SearchResults();
    String name = null;
    if (parameters.containsKey(NAME)) {
        name = parameters.get(NAME).get(0);
        ArgValidator.checkFieldNotEmpty(name, NAME);
        resRepList = new SearchedResRepList(getResourceType());
        _dbClient.queryByConstraint(PrefixConstraint.Factory.getLabelPrefixConstraint(CustomConfig.class, name), resRepList);
        String systemDefault = null;
        if (parameters.containsKey(SYSTEM_DEFAULT)) {
            systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
            List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
            Iterator<SearchResultResourceRep> it = resRepList.iterator();
            while (it.hasNext()) {
                SearchResultResourceRep rp = it.next();
                URI id = rp.getId();
                CustomConfig config = queryResource(id);
                if (systemDefault.equals(config.getSystemDefault().toString())) {
                    RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), id));
                    SearchResultResourceRep searchResult = new SearchResultResourceRep(id, selfLink, config.getLabel());
                    searchResultList.add(searchResult);
                }
            }
            result.setResource(searchResultList);
        } else {
            result.setResource(resRepList);
        }
    } else if (parameters.containsKey(CONFIG_TYPE)) {
        String configName = parameters.get(CONFIG_TYPE).get(0);
        // Validate the user passed a value for the config type.
        ArgValidator.checkFieldNotEmpty(configName, CONFIG_TYPE);
        StringMap scopeMap = null;
        if (parameters.containsKey(SCOPE)) {
            String scope = parameters.get(SCOPE).get(0);
            scopeMap = new StringMap();
            if (scope.contains(".")) {
                String[] scopeSplits = scope.split("\\.");
                scopeMap.put(scopeSplits[0], scopeSplits[1]);
            } else {
                throw APIException.badRequests.invalidScopeFomart(scope);
            }
        }
        String systemDefault = null;
        if (parameters.containsKey(SYSTEM_DEFAULT)) {
            systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
        }
        List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
        List<CustomConfig> configList = getCustomConfig(configName, scopeMap);
        for (CustomConfig config : configList) {
            if (config.getInactive()) {
                continue;
            }
            if (systemDefault != null && !systemDefault.equals(config.getSystemDefault().toString())) {
                continue;
            }
            RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), config.getId()));
            SearchResultResourceRep searchResult = new SearchResultResourceRep(config.getId(), selfLink, config.getLabel());
            searchResultList.add(searchResult);
        }
        result.setResource(searchResultList);
    } else if (parameters.containsKey(SYSTEM_DEFAULT)) {
        // search parameters only contains system_default
        List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
        String systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
        List<URI> ids = _dbClient.queryByType(CustomConfig.class, true);
        Iterator<CustomConfig> iter = _dbClient.queryIterativeObjects(CustomConfig.class, ids);
        while (iter.hasNext()) {
            CustomConfig config = iter.next();
            if (systemDefault.equals(config.getSystemDefault().toString())) {
                RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), config.getId()));
                SearchResultResourceRep searchResult = new SearchResultResourceRep(config.getId(), selfLink, config.getLabel());
                searchResultList.add(searchResult);
            }
        }
        result.setResource(searchResultList);
    }
    return result;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) SearchResults(com.emc.storageos.model.search.SearchResults) URI(java.net.URI) CustomConfigVariableList(com.emc.storageos.model.customconfig.CustomConfigVariableList) List(java.util.List) ArrayList(java.util.ArrayList) ScopeParamList(com.emc.storageos.model.customconfig.ScopeParamList) CustomConfigList(com.emc.storageos.model.customconfig.CustomConfigList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) CustomConfigRuleList(com.emc.storageos.model.customconfig.CustomConfigRuleList) CustomConfigTypeList(com.emc.storageos.model.customconfig.CustomConfigTypeList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

RestLinkRep (com.emc.storageos.model.RestLinkRep)22 URI (java.net.URI)9 SearchResultResourceRep (com.emc.storageos.model.search.SearchResultResourceRep)8 SearchResults (com.emc.storageos.model.search.SearchResults)6 ArrayList (java.util.ArrayList)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 StringMap (com.emc.storageos.db.client.model.StringMap)4 URISyntaxException (java.net.URISyntaxException)4 List (java.util.List)4 BulkList (com.emc.storageos.api.service.impl.response.BulkList)3 ResRepFilter (com.emc.storageos.api.service.impl.response.ResRepFilter)3 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)2 TimestampedURIQueryResult (com.emc.storageos.db.client.TimestampedURIQueryResult)2 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)2 Constraint (com.emc.storageos.db.client.constraint.Constraint)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2 StringSet (com.emc.storageos.db.client.model.StringSet)2