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);
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations