public static Function<Entity, Object> attribute(String attributeName) { return attribute(Sensors.newSensor(Object.class, attributeName)); }
public static Function<Entity, String> attribute(String attributeName, String format) { return attribute(Sensors.newSensor(Object.class, attributeName), format); }
@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)); }
@Test public void testEntityAttributeTest() { entity.sensors().set(TestEntity.NAME, "myname"); assertEquals(EntityFunctions.attribute(entity, TestEntity.NAME).apply(new Object()), "myname"); }
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; }
Predicates.compose(Predicates.equalTo(id), EntityFunctions.attribute(MesosTask.TASK_ID))); MesosTask task = null; if (taskEntity.isPresent()) {
String id = Strings.getFirstWord(line); Optional<Entity> container = Iterables.tryFind(getDockerContainerCluster().getMembers(), Predicates.compose(StringPredicates.startsWith(id), EntityFunctions.attribute(DockerContainer.DOCKER_CONTAINER_ID))); if (container.isPresent()) continue;
Predicates.compose(Predicates.equalTo(id), EntityFunctions.attribute(MesosSlave.MESOS_SLAVE_ID))); if (entity.isPresent()) { Entity found = entity.get();
@Override public void init() { super.init(); getMutableEntityType().addEffector(SelectMasterEffectorBody.SELECT_MASTER); getMutableEntityType().addEffector(BrooklynClusterUpgradeEffectorBody.UPGRADE_CLUSTER); ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER); addFeed(FunctionFeed.builder() .entity(this) .poll(new FunctionPollConfig<Object, BrooklynNode>(MASTER_NODE) .period(Duration.ONE_SECOND) .callable(new MasterChildFinder())) .build()); enrichers().add( Enrichers.builder().transforming(MASTER_NODE) .uniqueTag("master-node-web-uri") .publishing(BrooklynNode.WEB_CONSOLE_URI) .computing(EntityFunctions.attribute(BrooklynNode.WEB_CONSOLE_URI)) .build() ); }
.attributeName("requestCount") .enabled(retrieveUsageMetrics) .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT))) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME) .objectName(requestProcessorMbeanName)
.objectName(requestProcessorMbeanName) .attributeName("requestCount") .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT)) .enabled(retrieveUsageMetrics)) .pollAttribute(new JmxAttributePollConfig<Integer>(TOTAL_PROCESSING_TIME)
.objectName(statsMbeanName) .attributeName("requests") .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT))) .pollAttribute(new JmxAttributePollConfig<Integer>(RESPONSES_4XX_COUNT) .objectName(statsMbeanName)
.vars(includeRuntimeUriVars) .onSuccess(HttpValueFunctions.jsonContents("requestCount", Integer.class)) .onFailureOrException(EntityFunctions.attribute(this, REQUEST_COUNT)) .enabled(retrieveUsageMetrics)) .poll(new HttpPollConfig<Integer>(ERROR_COUNT)