/** * Creates a new {@link EnricherSpec} instance with the given config, for an enricher of the given type. * * This is primarily for groovy code; equivalent to {@code EnricherSpec.create(type).configure(config)}. * * @param config The spec's configuration (see {@link EnricherSpec#configure(Map)}). * @param type An {@link Enricher} class */ public static <T extends Enricher> EnricherSpec<T> create(Map<?,?> config, Class<T> type) { return EnricherSpec.create(type).configure(config); }
protected EnricherSpec<? extends Enricher> build() { EnricherSpec<? extends Enricher> spec = EnricherSpec.create(enricherType); String uniqueTag2 = uniqueTag; if (uniqueTag2==null) uniqueTag2 = getDefaultUniqueTag(); if (uniqueTag2!=null) spec.uniqueTag(uniqueTag2); if (!tags.isEmpty()) spec.tags(tags); if (suppressDuplicates!=null) spec.configure(AbstractEnricher.SUPPRESS_DUPLICATES, suppressDuplicates); return spec; } }
/** * Returns the detector. note that callers should then add this to the entity, * typically using {@link Entity#addEnricher(EnricherSpec)} * * @see {@link EnricherSpec} */ public EnricherSpec<HttpLatencyDetector> buildSpec() { return EnricherSpec.create(HttpLatencyDetector.class) .configureIfNotNull(PERIOD, period) .configureIfNotNull(ROLLUP_WINDOW_SIZE, rollupWindowSize) .configureIfNotNull(REQUIRE_SERVICE_UP, requireServiceUp) .configureIfNotNull((ConfigKey<Object>)URL, url) .configureIfNotNull(URL_SENSOR, urlSensor) .configureIfNotNull(URL_POST_PROCESSING, urlPostProcessing); } }
public static final EnricherSpec<?> newEnricherForServiceState(Class<? extends Enricher> type) { newEnricherForServiceUpFromChildren(); return EnricherSpec.create(type); }
enrichers().add(EnricherSpec.create(ComputeServiceIndicatorsFromChildrenAndMembers.class) .uniqueTag(ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.FROM_CHILDREN, true) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.ENTITY_FILTER, Predicates.or(ImmutableList.of( Predicates.<Entity>equalTo(slaves), Predicates.<Entity>equalTo(frameworks),
public static final EnricherSpec<?> newEnricherForServiceUpFromChildrenWithQuorumCheck(QuorumCheck quorumCheck) { EnricherSpec<?> serviceUp = newEnricherForServiceUpFromChildren() .configure(ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, quorumCheck); return serviceUp; } public static final EnricherSpec<?> newEnricherForServiceUp(Boolean fromChildren, Boolean fromMembers) {
@Test public void testAddsEnricherSpec() throws Exception { entity = app.createAndManageChild(EntitySpec.create(TestEntity.class, TestEntityNoEnrichersImpl.class) .enricher(EnricherSpec.create(MyEnricher.class) .displayName("myenrichername") .configure(MyEnricher.CONF1, "myconf1val") .configure("myfield", "myfieldval"))); Enricher enricher = Iterables.getOnlyElement(entity.enrichers()); assertTrue(enricher instanceof MyEnricher, "enricher="+enricher); assertEquals(enricher.getDisplayName(), "myenrichername"); assertEquals(enricher.getConfig(MyEnricher.CONF1), "myconf1val"); }
@Test public void testRestoresConfig() throws Exception { origApp.enrichers().add(EnricherSpec.create(MyEnricher.class) .displayName("My Enricher") .uniqueTag("tagU") .tag("tag1").tag("tag2") .configure(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_NO_SHORT_NAME, "myVal for with setFromFlag noShortName") .configure(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_WITH_SHORT_NAME, "myVal for setFromFlag withShortName") .configure(MyEnricher.MY_CONFIG_WITHOUT_SETFROMFLAG, "myVal for witout setFromFlag")); newApp = rebind(); MyEnricher newEnricher = (MyEnricher) Iterables.getOnlyElement(newApp.enrichers()); assertEquals(newEnricher.getDisplayName(), "My Enricher"); assertEquals(newEnricher.getUniqueTag(), "tagU"); assertEquals(newEnricher.tags().getTags(), MutableSet.of("tagU", "tag1", "tag2")); assertEquals(newEnricher.getConfig(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_NO_SHORT_NAME), "myVal for with setFromFlag noShortName"); assertEquals(newEnricher.getConfig(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_WITH_SHORT_NAME), "myVal for setFromFlag withShortName"); assertEquals(newEnricher.getConfig(MyEnricher.MY_CONFIG_WITHOUT_SETFROMFLAG), "myVal for witout setFromFlag"); }
@Override protected void initEnrichers() { super.initEnrichers(); ServiceNotUpLogic.updateNotUpIndicator(this, SERVICE_PROCESS_IS_RUNNING, "No information yet on whether this service is running"); // add an indicator above so that if is_running comes through, the map is cleared and an update is guaranteed enrichers().add(EnricherSpec.create(UpdatingNotUpFromServiceProcessIsRunning.class).uniqueTag("service-process-is-running-updating-not-up")); enrichers().add(EnricherSpec.create(ServiceNotUpDiagnosticsCollector.class).uniqueTag("service-not-up-diagnostics-collector")); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public <T extends Enricher> T createEnricher(EnricherSpec<T> spec) { if (spec.getFlags().containsKey("parent")) { throw new IllegalArgumentException("Spec's flags must not contain parent; use spec.parent() instead for "+spec); Class<? extends T> clazz = spec.getType(); if (spec.getDisplayName()!=null) theEnricher.setDisplayName(spec.getDisplayName()); if (spec.getCatalogItemId()!=null) { theEnricher.setCatalogItemIdAndSearchPath(spec.getCatalogItemId(), spec.getCatalogItemIdSearchPath()); enricher.tags().addTags(spec.getTags()); Map<String, Object> config = ConfigBag.newInstance().putAll(spec.getFlags()).putAll(spec.getConfig()).getAllConfig(); for (Map.Entry<ConfigKey<?>, Object> entry : spec.getConfig().entrySet()) { enricher.config().set((ConfigKey)entry.getKey(), entry.getValue());
@Override public K uniqueTag(String uniqueTag) { super.uniqueTag(uniqueTag); return self(); }
public static CatalogEnricherSummary catalogEnricherSummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) { final Set<EnricherConfigSummary> config = Sets.newLinkedHashSet(); EnricherSpec<?> spec = null; try{ spec = b.getTypeRegistry().createSpec(item, null, EnricherSpec.class); for (final SpecParameter<?> input : spec.getParameters()){ config.add(EntityTransformer.enricherConfigSummary(input)); } }catch (Exception e) { Exceptions.propagateIfFatal(e); log.trace("Unable to create policy spec for "+item+": "+e, e); } return new CatalogEnricherSummary(item.getSymbolicName(), item.getVersion(), item.getContainingBundle(), item.getDisplayName(), spec!=null ? spec.getType().getName() : item.getSuperTypes().toString(), CatalogItemType.ENRICHER.toString(), RegisteredTypes.getImplementationDataStringForSpec(item), item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config, item.getTags(), item.isDeprecated(), makeLinks(item, ub)); }
@Override public <V> K configureIfNotNull(ConfigKey<V> key, V val) { super.configureIfNotNull(key, val); return self(); }
@Test public void testPropagatorFailsWithEmptyConfig() throws Exception { EnricherSpec<?> spec = EnricherSpec.create(Propagator.class); assertAddEnricherThrowsIllegalStateException(spec, "must have"); }
Double headroomPercent = config().get(ContainerHeadroomEnricher.CONTAINER_HEADROOM_PERCENTAGE); if ((headroom != null && headroom > 0) || (headroomPercent != null && headroomPercent > 0d)) { enrichers().add(EnricherSpec.create(ContainerHeadroomEnricher.class) .configure(ContainerHeadroomEnricher.CONTAINER_HEADROOM, headroom) .configure(ContainerHeadroomEnricher.CONTAINER_HEADROOM_PERCENTAGE, headroomPercent)); hosts.enrichers().add(Enrichers.builder() .propagating( enrichers().add(EnricherSpec.create(ComputeServiceIndicatorsFromChildrenAndMembers.class) .uniqueTag(ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.FROM_CHILDREN, true) .configure(ComputeServiceIndicatorsFromChildrenAndMembers.ENTITY_FILTER, Predicates.or( Predicates.<Entity>equalTo(hosts), (sdn == null ? Predicates.<Entity>alwaysFalse() : Predicates.equalTo(sdn)))));
@Override public <V> K configure(ConfigKey<V> key, V val) { super.configure(key, val); return self(); }
@Test public void testAddSpec() throws Exception { MyEnricher enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class) .displayName("Bob") .configure(MyEnricher.STR_KEY, "aval").configure(MyEnricher.INT_KEY, 2)); assertTrue(app.enrichers().asList().contains(enricher), "enrichers="+app.enrichers()); assertEquals(enricher.getDisplayName(), "Bob"); assertEquals(enricher.getConfig(MyEnricher.STR_KEY), "aval"); assertEquals(enricher.getConfig(MyEnricher.INT_KEY), (Integer)2); }
@Test(groups={"WIP", "Broken"}) public void testServiceStateNotCalledExplicitly() throws Exception { ComputeServiceState oldEnricher = (ComputeServiceState) Iterables.find(app.enrichers(), Predicates.instanceOf(ComputeServiceState.class)); String oldUniqueTag = oldEnricher.getUniqueTag(); CountingComputeServiceState enricher = app.enrichers().add(EnricherSpec.create(CountingComputeServiceState.class) .uniqueTag(oldUniqueTag)); // Confirm that we only have one enricher now (i.e. we've replaced the original) Iterable<Enricher> newEnrichers = Iterables.filter(app.enrichers(), Predicates.instanceOf(ComputeServiceState.class)); assertEquals(Iterables.size(newEnrichers), 1, "newEnrichers="+newEnrichers); assertEquals(Iterables.getOnlyElement(newEnrichers), enricher, "newEnrichers="+newEnrichers); // When setting the expected state, previously that caused a onEvent(null) to be triggered synchronously ServiceStateLogic.setExpectedState(app, Lifecycle.RUNNING); assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); assertTrue(enricher.cntCalled.get() > 0); assertEquals(enricher.cntCalledWithNull.get(), 0); }