public static Function<Entity, Object> attribute(String attributeName) { return attribute(Sensors.newSensor(Object.class, attributeName)); }
public static Function<Entity, String> config(String keyName, String format) { return config(ConfigKeys.newConfigKey(Object.class, keyName), format); }
@Override public List<String> call() throws Exception { return ImmutableList.copyOf(Iterables.transform(children, EntityFunctions.id())); }}) .description("Add and start "+childrenCountString);
/** as {@link #settingSensorsConstant(Map)} but as a {@link Runnable} */ public static Runnable settingSensorsConstant(final Entity entity, final Map<AttributeSensor<?>,Object> values) { checkNotNull(entity, "entity"); checkNotNull(values, "values"); return Functionals.runnable(Suppliers.compose(settingSensorsConstant(values), Suppliers.ofInstance(entity))); }
@Test public void testDisplayName() throws Exception { assertEquals(EntityFunctions.displayName().apply(entity), "mydisplayname"); }
@Test public void testLocationMatching() throws Exception { entity.addLocations(ImmutableList.of(loc)); assertEquals(EntityFunctions.locationMatching(Predicates.alwaysTrue()).apply(entity), loc); } }
private void newMultiFeed(URL baseUrl) { feed = HttpFeed.builder() .entity(entity) .baseUrl(baseUrl) .poll(HttpPollConfig.forMultiple() .onSuccess(new Function<HttpToolResponse,Void>() { @Override public Void apply(HttpToolResponse response) { entity.sensors().set(SENSOR_INT, response.getResponseCode()); if (response.getResponseCode()==200) entity.sensors().set(SENSOR_STRING, response.getContentAsString()); return null; } }) .onFailureOrException(Functionals.function(EntityFunctions.settingSensorsConstant(entity, MutableMap.<AttributeSensor<?>,Object>of( SENSOR_INT, -1, SENSOR_STRING, PollConfig.REMOVE)))) .period(100)) .build(); }
public static Function<Entity, String> attribute(String attributeName, String format) { return attribute(Sensors.newSensor(Object.class, attributeName), format); }
public static Function<Entity, Object> config(String keyName) { return config(ConfigKeys.newConfigKey(Object.class, keyName)); }
protected static List<String> getIds(List<ScoredRecord<?>> filterHealthy) { return ImmutableList.copyOf(Iterables.transform(filterHealthy, EntityFunctions.id())); }
@Test public void testAttribute() throws Exception { entity.sensors().set(TestEntity.NAME, "myname"); assertEquals(EntityFunctions.attribute(TestEntity.NAME).apply(entity), "myname"); assertEquals(EntityFunctions.attribute(TestEntity.NAME.getName()).apply(entity), "myname"); assertEquals(EntityFunctions.attribute(TestEntity.NAME, "%s - suffix").apply(entity), "myname - suffix"); assertEquals(EntityFunctions.attribute(TestEntity.NAME.getName(), "%s - suffix").apply(entity), "myname - suffix"); assertNull(EntityFunctions.attribute(TestEntity.SEQUENCE).apply(entity)); }
@Override public boolean apply(DockerHostLocation input) { Iterable<Entity> deployed = Iterables.filter( Iterables.transform(input.getDockerContainerList(), EntityFunctions.config(DockerContainer.ENTITY.getConfigKey())), Predicates.notNull()); return Iterables.size(deployed) > 0; } }
private Set<String> toIds(Iterable<? extends Identifiable> instances) { return ImmutableSet.copyOf(Iterables.transform(instances, EntityFunctions.id())); }
@Test public void testEntityAttributeTest() { entity.sensors().set(TestEntity.NAME, "myname"); assertEquals(EntityFunctions.attribute(entity, TestEntity.NAME).apply(new Object()), "myname"); }
@Override public boolean apply(DockerHostLocation input) { Iterable<Entity> deployed = Iterables.filter( Iterables.transform(input.getDockerContainerList(), EntityFunctions.config(DockerContainer.ENTITY.getConfigKey())), Predicates.notNull()); Iterable<Entity> sameParent = Iterables.filter(deployed, EntityPredicates.isChildOf(parent)); if (Iterables.isEmpty(sameParent)) { LOG.debug("No entities with parent {} on {}", parent, input ); return false; } else { LOG.debug("Found entities with parent {} on {}", parent, input ); return true; } } }
@Test public void testId() throws Exception { assertEquals(EntityFunctions.id().apply(entity), entity.getId()); }
public List<String> scanFrameworks(JsonArray frameworks) { List<String> frameworkNames = MutableList.<String>of(); for (int i = 0; i < frameworks.size(); i++) { JsonObject task = frameworks.get(i).getAsJsonObject(); String id = task.get("id").getAsString(); JsonElement pidObj = task.get("pid"); String pid = null; if (pidObj != null && !pidObj.isJsonNull()) { pid = pidObj.getAsString(); } String name = task.get("name").getAsString(); String url = task.get("webui_url").getAsString(); frameworkNames.add(name); Optional<Entity> entity = Iterables.tryFind(sensors().get(MESOS_FRAMEWORKS).getMembers(), Predicates.compose(Predicates.equalTo(id), EntityFunctions.attribute(MesosFramework.FRAMEWORK_ID))); if (entity.isPresent()) continue; EntitySpec<? extends MesosFramework> frameworkSpec = EntitySpec.create(FRAMEWORKS.containsKey(name) ? FRAMEWORKS.get(name) : EntitySpec.create(MesosFramework.class)) .configure(MesosFramework.FRAMEWORK_ID, id) .configure(MesosFramework.FRAMEWORK_PID, pid) .configure(MesosFramework.FRAMEWORK_NAME, name) .configure(MesosFramework.FRAMEWORK_URL, url) .configure(MesosFramework.MESOS_CLUSTER, this) .displayName(String.format("%s Framework", Strings.toInitialCapOnly(name))); MesosFramework added = sensors().get(MESOS_FRAMEWORKS).addMemberChild(frameworkSpec); added.start(ImmutableList.<Location>of()); } return frameworkNames; }
@Override public boolean apply(DockerHostLocation input) { Iterable<Entity> deployed = Iterables.filter( Iterables.transform(input.getDockerContainerList(), EntityFunctions.config(DockerContainer.ENTITY.getConfigKey())), Predicates.notNull()); Iterable<Entity> sameApplication = Iterables.filter(deployed, EntityPredicates.applicationIdEqualTo(applicationId)); if (Iterables.isEmpty(sameApplication)) { LOG.debug("No entities with application id {} on {}", applicationId, input); return false; } else { LOG.debug("Found entities with application id {} on {}", applicationId, input); return true; } } }
private Set<String> getCatalogItemIds(Iterable<CatalogItem<Object, Object>> catalogItems) { return FluentIterable.from(catalogItems) .transform(EntityFunctions.id()) .copyInto(Sets.<String>newHashSet()); }
Predicates.compose(Predicates.equalTo(id), EntityFunctions.attribute(MesosTask.TASK_ID))); MesosTask task = null; if (taskEntity.isPresent()) {