/** * Returns 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 Input get(Object key, Args namespace) { Util.ensureNamespaceIsExact(namespace); return retrieveInput((String)key, namespace); }
/** * Joins the strings in {@code joinees}, separated by {@code joiner}. * * For example, {@code list} contains the strings {@code "a"}, {@code "b"}, * and {@code "c"}. To combine these strings as "a/b/c", use * {@code join("/", list)}. * * @param joiner The string to use as the delimiter between each element. * @param joinees The array of strings to join. * @return The combined strings in {@code joinees} separated by the * {@code joiner} delimiter. */ public static String join(String joiner, String[] joinees) { return join(joiner, Arrays.asList(joinees)); }
/** * Returns the input kind for a given path. * * @param path The relative endpoint path (the path that follows * data/inputs). * @return A member of {@code InputKind}, indicating the type of input. */ protected InputKind itemKind(String path) { String relpathWithInputName = Util.substringAfter(path, "/data/inputs/", null); for (InputKind kind : inputKinds) { if (relpathWithInputName.startsWith(kind.getRelativePath())) { return kind; } } // Not good. This means that there is an input of an unknown kind. return InputKind.Unknown; }
/** * Sets the values for the specified field name, with the assumption that * the value delimiter is a comma (,). * * @param key The field name. * @param values The delimited set of values. */ void putArray(String key, String[] values) { arrayValues.put(key, values); // For backward compatibility with the Map interface super.put(key, Util.join(",", values)); }
/** * {@inheritDoc} */ @Override public Input remove( String key, Args namespace) { Util.ensureNamespaceIsExact(namespace); Input input = retrieveInput(key, namespace); if (input != null) { input.remove(); } return input; }
/** * Returns an {@code InputKind} representing this input's type. * * The input kind is inferred from the input's path. */ public InputKind getKind() { String[] pathComponents = Util.substringAfter(this.path, "/data/inputs/", null).split("/"); String kindPath; if (pathComponents[0].equals("tcp")) { kindPath = "tcp/" + pathComponents[1]; } else { kindPath = pathComponents[0]; } return InputKind.create(kindPath); } }
/** * Sets the regular expressions (regexes) that are compared to registry * event types for this Windows Registry input. Only types that match * at least one regex are monitored. * * @param regexes An array of regex strings for event types. */ public void setType(String[] regexes) { String val = Util.join("|", regexes); setCacheValue("type", val); }
/** * 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; }
/** * Sets the list of slaves that are members of this license pool. * * @param slaves The array of slaves. To accept all slaves, use an * array with a single asterisk element ("*"). */ public void setSlaves(String[] slaves) { setSlaves(Util.join(",", slaves)); } }
/** * 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; }
@Override JsonElement toJson() { JsonObject root = new JsonObject(); addCommonFields(root); root.add("attributeName", new JsonPrimitive(this.getAttributeName())); root.add("attributeOwner", new JsonPrimitive(Util.join(".", this.getAttributeOwnerLineage()))); if (sortDirection == SortDirection.ASCENDING) { root.add("limitType", new JsonPrimitive("lowest")); } else if (sortDirection == SortDirection.DESCENDING) { root.add("limitType", new JsonPrimitive("highest")); } root.add("limitAmount", new JsonPrimitive(this.limit)); root.add("statsFn", new JsonPrimitive(this.statsFunction.toString())); return root; } }
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; } }
/** * Add keys common to all row splits to a JSON serialization. * * @param obj JSON serialization to modify. */ protected void addCommonFields(JsonObject obj) { DataModelField field = this.dataModelObject.getField(this.fieldName); obj.addProperty("fieldName", this.fieldName); obj.addProperty("owner", Util.join(".", field.getOwnerLineage())); obj.addProperty("type", field.getType().toString()); obj.addProperty("label", this.label); }
/** * 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; } }
protected void addCommonFields(JsonObject obj) { DataModelField field = this.owner.getField(this.fieldName); obj.addProperty("fieldName", this.fieldName); obj.addProperty("owner", Util.join(".", field.getOwnerLineage())); obj.addProperty("type", field.getType().toString()); }
/** * Called by subclasses to add the fields common to all subclasses to JSON serializations. * * @param root a JsonObject instance representing a serialization of this object. */ protected void addCommonFields(JsonObject root) { root.addProperty("fieldName", this.fieldName); root.addProperty("owner", Util.join(".", this.dataModelObject.getField(fieldName).getOwnerLineage())); root.addProperty("type", this.getType().toString()); } }
/** * @return a JSON serialization of this object. */ JsonObject toJson() { JsonObject root = new JsonObject(); DataModelField f = this.dataModelObject.getField(fieldName); root.addProperty("fieldName", this.fieldName); root.addProperty("owner", Util.join(".", f.getOwnerLineage())); root.addProperty("type", f.getType().toString()); root.addProperty("label", this.label); root.addProperty("sparkline", false); // Not properly implemented in core yet. root.addProperty("value", this.statsFunction.toString()); return root; } }
/** * {@inheritDoc} */ @Override public void update() { // If not present in the update keys, add required attributes as long // as one pre-existing update pair exists if (toUpdate.size() > 0 && !toUpdate.containsKey("baseline")) { setCacheValue("baseline", getBaseline()); } if (toUpdate.size() > 0 && !toUpdate.containsKey("hive")) { setCacheValue("hive", getHive()); } if (toUpdate.size() > 0 && !toUpdate.containsKey("proc")) { setCacheValue("proc", getProc()); } if (toUpdate.size() > 0 && !toUpdate.containsKey("type")) { setCacheValue("type", Util.join("|", getType())); } super.update(); } }
/** * {@inheritDoc} */ @Override public void update(Map<String, Object> args) { // Add required arguments if not already present if (!args.containsKey("baseline")) { args = Args.create(args).add("baseline", getBaseline()); } if (!args.containsKey("hive")) { args = Args.create(args).add("hive", getHive()); } if (!args.containsKey("proc")) { args = Args.create(args).add("proc", getProc()); } if (!args.containsKey("type")) { args = Args.create(args).add("type", Util.join("|", getType())); } super.update(args); }