protected static ResourcePath toChildResourcePath(ResourcePath parent, String resourceId) { final ResourcePath child = toResourcePath(resourceId); final String childEls[] = child.elements(); final String parentEls[] = parent.elements(); if (childEls.length <= parentEls.length) { return null; } String els[] = new String[parentEls.length + 1]; for (int i = 0; i <= parentEls.length ; i++) { els[i] = childEls[i]; } return ResourcePath.get(els); }
/** * Converts a {@link org.opennms.netmgt.model.ResourcePath} to a Newts resource id. * * @param path path to convert * @return Newts resource id */ public static String toResourceId(ResourcePath path) { return s_splitter.joinElementsToId(Arrays.asList(path.elements())); }
/** * Converts a {@link org.opennms.netmgt.model.ResourcePath} to a Newts resource id. * * @param path path to convert * @return Newts resource id */ public static String toResourceId(ResourcePath path) { return s_splitter.joinElementsToId(Arrays.asList(path.elements())); }
protected static ResourcePath toChildResourcePath(ResourcePath parent, String resourceId) { final ResourcePath child = toResourcePath(resourceId); final String childEls[] = child.elements(); final String parentEls[] = parent.elements(); if (childEls.length <= parentEls.length) { return null; } String els[] = new String[parentEls.length + 1]; for (int i = 0; i <= parentEls.length ; i++) { els[i] = childEls[i]; } return ResourcePath.get(els); }
/** * Extends the attribute map with indices used by the {@link org.opennms.netmgt.dao.support.NewtsResourceStorageDao}. * * A resource path of the form [a, b, c, d] will be indexed with: * <ul> * <li> _idx1: (a, 4) * <li> _idx2: (a:b, 4) * <li> _idx3: (a:b:c, 4) */ public static void addIndicesToAttributes(ResourcePath path, Map<String, String> attributes) { final List<String> els = Arrays.asList(path.elements()); final int N = els.size(); for (int i = 0; i < N; i++) { final String id = s_splitter.joinElementsToId(els.subList(0, i+1)); attributes.put("_idx" + i, String.format("(%s,%d)", id, N)); } }
/** * Extends the attribute map with indices used by the {@link org.opennms.netmgt.dao.support.NewtsResourceStorageDao}. * * A resource path of the form [a, b, c, d] will be indexed with: * <ul> * <li> _idx1: (a, 4) * <li> _idx2: (a:b, 4) * <li> _idx3: (a:b:c, 4) */ public static void addIndicesToAttributes(ResourcePath path, Map<String, String> attributes) { final List<String> els = Arrays.asList(path.elements()); final int N = els.size(); for (int i = 0; i < N; i++) { final String id = s_splitter.joinElementsToId(els.subList(0, i+1)); attributes.put("_idx" + i, String.format("(%s,%d)", id, N)); } }
private String getNodeCriteriaFromResource(CollectionResource resource) { String nodeCriteria = null; if (resource.getParent() != null) { String[] resourcePathArray = resource.getParent().elements(); if (ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY.equals(resourcePathArray[0]) && resourcePathArray.length == 3) { // parent denotes nodeCriteria, form fs:fid nodeCriteria = resourcePathArray[1] + ":" + resourcePathArray[2]; } else if (checkNumeric(resourcePathArray[0])) { // parent denotes nodeId nodeCriteria = resourcePathArray[0]; } } return nodeCriteria; }
private String getNodeCriteriaFromResource(CollectionResource resource) { String nodeCriteria = null; if (resource.getParent() != null) { String[] resourcePathArray = resource.getParent().elements(); if (ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY.equals(resourcePathArray[0]) && resourcePathArray.length == 3) { // parent denotes nodeCriteria, form fs:fid nodeCriteria = resourcePathArray[1] + ":" + resourcePathArray[2]; } else if (checkNumeric(resourcePathArray[0])) { // parent denotes nodeId nodeCriteria = resourcePathArray[0]; } } return nodeCriteria; }
private CollectionSetProtos.ResponseTimeResource.Builder buildResponseTimeResource(CollectionResource resource) { boolean validIp = false; // Check if resource parent is an IpAddress. if (resource.getParent() != null && resource.getParent().elements().length == 1) { String[] resourcePathArray = resource.getParent().elements(); validIp = checkForValidIpAddress(resourcePathArray[0]); } if (resource.getPath() != null && validIp) { // extract path which consists of location and IpAddress. String[] resourcePathArray = resource.getPath().elements(); CollectionSetProtos.ResponseTimeResource.Builder responseTimeResourceBuilder = CollectionSetProtos.ResponseTimeResource .newBuilder(); if (resourcePathArray.length == 2) { // first element is location, 2nd IpAddress. responseTimeResourceBuilder.setLocation(resourcePathArray[0]); responseTimeResourceBuilder.setInstance(resourcePathArray[1]); } else if (resourcePathArray.length == 1) { responseTimeResourceBuilder.setInstance(resourcePathArray[0]); } return responseTimeResourceBuilder; } return null; }
private CollectionSetProtos.ResponseTimeResource.Builder buildResponseTimeResource(CollectionResource resource) { boolean validIp = false; // Check if resource parent is an IpAddress. if (resource.getParent() != null && resource.getParent().elements().length == 1) { String[] resourcePathArray = resource.getParent().elements(); validIp = checkForValidIpAddress(resourcePathArray[0]); } if (resource.getPath() != null && validIp) { // extract path which consists of location and IpAddress. String[] resourcePathArray = resource.getPath().elements(); CollectionSetProtos.ResponseTimeResource.Builder responseTimeResourceBuilder = CollectionSetProtos.ResponseTimeResource .newBuilder(); if (resourcePathArray.length == 2) { // first element is location, 2nd IpAddress. responseTimeResourceBuilder.setLocation(resourcePathArray[0]); responseTimeResourceBuilder.setInstance(resourcePathArray[1]); } else if (resourcePathArray.length == 1) { responseTimeResourceBuilder.setInstance(resourcePathArray[0]); } return responseTimeResourceBuilder; } return null; }
/** * Constructs a query used to find all of the resources that have * one or more metrics at the given depth bellow the path. * * Requires resources to have been indexed using {@link #addIndicesToAttributes}. */ public static Query findResourcesWithMetricsAtDepth(ResourcePath path, int depth) { // Numeric suffix for the index name, based on the length of parent path int idxSuffix = path.elements().length - 1; // The length of the resource ids we're interested in finding int targetLen = idxSuffix + depth + 2; TermQuery tq = new TermQuery(new Term( "_idx"+idxSuffix, // key String.format("(%s,%d)", toResourceId(path), targetLen) // value )); BooleanQuery q = new BooleanQuery(); q.add(tq, Operator.OR); return q; }
/** * Constructs a query used to find all of the resources that have * one or more metrics at the given depth bellow the path. * * Requires resources to have been indexed using {@link #addIndicesToAttributes}. */ public static Query findResourcesWithMetricsAtDepth(ResourcePath path, int depth) { // Numeric suffix for the index name, based on the length of parent path int idxSuffix = path.elements().length - 1; // The length of the resource ids we're interested in finding int targetLen = idxSuffix + depth + 2; TermQuery tq = new TermQuery(new Term( "_idx"+idxSuffix, // key String.format("(%s,%d)", toResourceId(path), targetLen) // value )); BooleanQuery q = new BooleanQuery(); q.add(tq, Operator.OR); return q; }