/** * Ensures that the given path is fully qualified, prepending a path * prefix if necessary. The path prefix is constructed using the current * owner and app context when available. * * @param path The path to verify. * @return A fully-qualified resource path. */ String fullpath(String path) { return fullpath(path, null); }
try { while (true) { Object obj = constructor.newInstance(service, service.fullpath(path, namespace));
/** * Determines whether a scoped, namespace-constrained key * exists within this collection. * * @param key The key to look up. * @param namespace The namespace to constrain the search to. * @return {@code true} if the key exists, {@code false} if not. */ public boolean containsKey(Object key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); LinkedList<T> entities = items.get(key); if (entities == null || entities.size() == 0) return false; String pathMatcher = service.fullpath("", namespace); for (T entity: entities) { if (entity.path.startsWith(pathMatcher)) { return true; } } return false; }
/** * Gets a the value of a scoped, namespace-constrained key, if it exists * within this collection. * * @param key The key to look up. * @param namespace The namespace to constrain the search to. * @return The value indexed by the key, or {@code null} if it doesn't * exist. */ public T get(Object key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); LinkedList<T> entities = items.get(key); if (entities == null || entities.size() == 0) return null; String pathMatcher = service.fullpath("", namespace); for (T entity: entities) { if (entity.path.startsWith(pathMatcher)) { return entity; } } return null; }
private Input retrieveInput(String key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); // Because scripted input names are not 1:1 with the original name // (they are the absolute path on the Splunk instance followed by // the original name), we will iterate over the entities in the list, // and if we find one that matches, return it. String pathMatcher = service.fullpath("", namespace); Set<Entry<String, LinkedList<Input>>> set = items.entrySet(); for (Entry<String, LinkedList<Input>> entry: set) { String entryKey = entry.getKey(); LinkedList<Input> entryValue = entry.getValue(); InputKind kind = entryValue.get(0).getKind(); if (InputCollection.matchesInputName(kind, key, entryKey)) { for (Input entity: entryValue) { if (entity.path.startsWith(pathMatcher)) { return entity; } } } } return null; } }
/** * Issues an HTTP request against the service using a request path and * message. * This method overrides the base {@code HttpService.send} method * and applies the Splunk authorization header, which is required for * authenticated interactions with the Splunk service. * * @param path The request path. * @param request The request message. * @return The HTTP response. */ @Override public ResponseMessage send(String path, RequestMessage request) { // cookieStore is a protected member of HttpService if (token != null && cookieStore.isEmpty()) { request.getHeader().put("Authorization", token); } return super.send(fullpath(path), request); }
/** * Removes an entity from this collection, with a namespace restriction. * * @param key The name of the entity to remove. * @param namespace The namespace restriction within the collection. * @return This collection. */ public T remove(String key, Args namespace) { Util.ensureNamespaceIsExact(namespace); validate(); if (!containsKey(key)) return null; LinkedList<T> entities = items.get(key); String pathMatcher = service.fullpath("", namespace); if (entities == null || entities.size() == 0) return null; for (T entity: entities) { if (entity.path.startsWith(pathMatcher)) { entity.remove(); // By invalidating, any access to items will get refreshed invalidate(); return entity; } } return null; } }
/** * Class constructor. * * @param service The connected {@code Service} instance. * @param path The target endpoint. * @param args Arguments to use when you instantiate the entity. */ Resource(Service service, String path, Args args) { // Clone the original argument list, since it will be modified args = Args.create(args); Args namespace = extractNamespaceFrom(args); if (!args.containsKey("count")) { args.put("count", "-1"); } this.service = service; this.path = service.fullpath( path, namespace.size() == 0 ? null : namespace); this.refreshArgs = args; }