: path; try { elementForSensor = getElementByPath(jsonElement.getAsJsonObject(), prefixedPath); } catch(IllegalArgumentException e) { log.error("Entity {}: bad Chef attribute {} for sensor {}: {}", new Object[]{
@Override protected void preStart() { final Callable<SshPollValue> getAttributesFromKnife = new Callable<SshPollValue>() { public SshPollValue call() throws Exception { ProcessTaskWrapper<String> taskWrapper = knifeTaskFactory.newTask(); final ExecutionContext executionContext = ((EntityInternal) entity).getManagementSupport().getExecutionContext(); log.debug("START: Running knife to query attributes of Chef node {}", nodeName); executionContext.submit(taskWrapper); taskWrapper.block(); log.debug("DONE: Running knife to query attributes of Chef node {}", nodeName); return new SshPollValue(null, taskWrapper.getExitCode(), taskWrapper.getStdout(), taskWrapper.getStderr()); } }; ((Poller<SshPollValue>) poller).scheduleAtFixedRate( new CallInEntityExecutionContext<SshPollValue>(entity, getAttributesFromKnife), new SendChefAttributesToSensors(entity, chefAttributeSensors), periodUnits.toMillis(period)); }
@Override public void onError(Exception exception) { onException(exception); }
private JsonElement getElementByPath(JsonElement element, Iterable<String> path) { if (Iterables.isEmpty(path)) { return element; } else { String head = Iterables.getFirst(path, null); Preconditions.checkArgument(!Strings.isNullOrEmpty(head), "path must not contain empty or null elements"); Iterable<String> tail = Iterables.skip(path, 1); JsonElement child = ((JsonObject) element).get(head); return child != null ? getElementByPath(child, tail) : null; } }