org.apache.brooklyn.api.sensor.Enricher Java Examples

The following examples show how to use org.apache.brooklyn.api.sensor.Enricher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CampInternalUtils.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static EnricherSpec<?> createEnricherSpec(BrooklynClassLoadingContext loader, Object enricher, Set<String> encounteredCatalogTypes) {
    Map<String, Object> itemMap;
    if (enricher instanceof String) {
        itemMap = ImmutableMap.<String, Object>of("type", enricher);
    } else if (enricher instanceof Map) {
        itemMap = (Map<String, Object>) enricher;
    } else {
        throw new IllegalStateException("Enricher expected to be string or map. Unsupported object type " + enricher.getClass().getName() + " (" + enricher.toString() + ")");
    }

    String versionedId = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "enricher_type", "enricherType", "type"), "enricher type");
    EnricherSpec<? extends Enricher> spec = resolveEnricherSpec(versionedId, loader, encounteredCatalogTypes);
    initConfigAndParameters(spec, itemMap, loader);
    return spec;
}
 
Example #2
Source File: VanillaSoftwareProcessImpl.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
protected void connectSensors() {
    super.connectSensors();
    if (isSshMonitoringEnabled()) {
        connectServiceUpIsRunning();
    } else {
        // See SoftwareProcessImpl.waitForEntityStart(). We will already have waited for driver.isRunning.
        // We will not poll for that again.
        // 
        // Also disable the associated enricher - otherwise that would reset the not-up-indicator 
        // if serviceUp=false temporarily (e.g. if restart effector is called).
        // See https://issues.apache.org/jira/browse/BROOKLYN-547
        Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(enrichers(), "service-process-is-running-updating-not-up");
        if (enricher.isPresent()) {
            enrichers().remove(enricher.get());
        }
        ServiceNotUpLogic.clearNotUpIndicator(this, SERVICE_PROCESS_IS_RUNNING);
    }
}
 
Example #3
Source File: AbstractEntity.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void add(Enricher enricher) {
    Enricher old = findApparentlyEqualAndWarnIfNotSameUniqueTag(enrichersInternal, enricher);
    if (old!=null) {
        LOG.debug("Removing "+old+" when adding "+enricher+" to "+AbstractEntity.this);
        remove(old);
    }
    
    CatalogUtils.setCatalogItemIdOnAddition(AbstractEntity.this, enricher);
    enrichersInternal.add((AbstractEnricher) enricher);
    ((AbstractEnricher)enricher).setEntity(AbstractEntity.this);
    ConfigConstraints.assertValid(enricher);
    
    getManagementSupport().getEntityChangeListener().onEnricherAdded(enricher);
    // TODO Could add equivalent of AbstractEntity.POLICY_ADDED for enrichers; no use-case for that yet
}
 
Example #4
Source File: Dumper.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
static void dumpInfo(Enricher enr, Writer out, String currentIndentation, String tab) throws IOException {
    out.append(currentIndentation+enr.toString()+"\n");

    for (ConfigKey<?> key : sortConfigKeys(enr.getEnricherType().getConfigKeys())) {
        Maybe<Object> val = ((BrooklynObjectInternal)enr).config().getRaw(key);
        if (!isTrivial(val)) {
            out.append(currentIndentation+tab+tab+key);
            out.append(" = ");
            if (isSecret(key.getName())) out.append("xxxxxxxx");
            else out.append(""+val.get());
            out.append("\n");
        }
    }

    out.flush();
}
 
Example #5
Source File: CatalogTransformer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static CatalogItemSummary catalogItemSummary(BrooklynRestResourceUtils b, RegisteredType item, UriBuilder ub) {
    try {
        if (item.getSuperTypes().contains(Application.class) ||
                item.getSuperTypes().contains(Entity.class)) {
            return catalogEntitySummary(b, item, ub);
        } else if (item.getSuperTypes().contains(Policy.class)) {
            return catalogPolicySummary(b, item, ub);
        } else if (item.getSuperTypes().contains(Enricher.class)) {
            return catalogEnricherSummary(b, item, ub);
        } else if (item.getSuperTypes().contains(Location.class)) {
            return catalogLocationSummary(b, item, ub);
        } else {
            log.debug("Misc catalog item type when getting self link (supplying generic item): "+item+" "+item.getSuperTypes());
        }
    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);
        log.warn("Invalid item in catalog when converting REST summaries (supplying generic item), at "+item+": "+e, e);
    }
    return new CatalogItemSummary(item.getSymbolicName(), item.getVersion(), item.getContainingBundle(), item.getDisplayName(),
        item.getSuperTypes().toString(), 
        item.getKind()==RegisteredTypeKind.BEAN ? "bean" : "unknown",
        RegisteredTypes.getImplementationDataStringForSpec(item),
        item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), item.getTags(), item.isDeprecated(), makeLinks(item, ub));
}
 
Example #6
Source File: CatalogTransformer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected static URI getSelfLink(RegisteredType item, UriBuilder ub) {
    String itemId = item.getId();
    if (item.getSuperTypes().contains(Application.class)) {
        return serviceUriBuilder(ub, CatalogApi.class, "getApplication").build(itemId, item.getVersion());
    } else if (item.getSuperTypes().contains(Entity.class)) {
        return serviceUriBuilder(ub, CatalogApi.class, "getEntity").build(itemId, item.getVersion());
    } else if (item.getSuperTypes().contains(Policy.class)) {
        return serviceUriBuilder(ub, CatalogApi.class, "getPolicy").build(itemId, item.getVersion());
    } else if (item.getSuperTypes().contains(Enricher.class)) {
        return serviceUriBuilder(ub, CatalogApi.class, "getEnricher").build(itemId, item.getVersion());
    } else if (item.getSuperTypes().contains(Location.class)) {
        return serviceUriBuilder(ub, CatalogApi.class, "getLocation").build(itemId, item.getVersion());
    } else {
        log.warn("Unexpected catalog item type when getting self link (not supplying self link): "+item+" "+item.getSuperTypes());
        return null;
    }
}
 
Example #7
Source File: CatalogTransformer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/** @deprecated since 0.12.0 use {@link RegisteredType} methods instead */  @Deprecated
public static CatalogEnricherSummary catalogEnricherSummary(BrooklynRestResourceUtils b, CatalogItem<? extends Enricher,EnricherSpec<?>> item, UriBuilder ub) {
    final Set<EnricherConfigSummary> config = Sets.newLinkedHashSet();
    try{
        final EnricherSpec<?> spec = (EnricherSpec<?>) b.getCatalog().peekSpec(item);
        AtomicInteger priority = new AtomicInteger();
        for (SpecParameter<?> input: spec.getParameters()) {
            config.add(ConfigTransformer.of(input).uiIncrementAndSetPriorityIfPinned(priority).transformLegacyEnricherConfig());
        }
    }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(),
            item.getJavaType(), item.getCatalogItemType().toString(), item.getPlanYaml(),
            item.getDescription(), tidyIconLink(b, item, item.getIconUrl(), ub), config,
            item.tags().getTags(), item.isDeprecated(), makeLinks(item, ub));
}
 
Example #8
Source File: AdjunctResource.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public Response destroy(String application, String entityToken, String adjunctId) {
    Entity entity = brooklyn().getEntity(application, entityToken);
    EntityAdjunct adjunct = brooklyn().getAdjunct(entity, adjunctId);

    if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.DELETE_ADJUNCT, adjunct)) {
        throw WebResourceUtils.forbidden("User '%s' is not authorized to delete adjuncts '%s'",
                Entitlements.getEntitlementContext().user(), adjunct);
    }

    if (adjunct instanceof Policy) {
        ((Policy)adjunct).suspend();
        entity.policies().remove((Policy) adjunct);
    } else if (adjunct instanceof Enricher) {
        entity.enrichers().remove((Enricher) adjunct);
    } else if (adjunct instanceof Feed) {
        ((Feed)adjunct).suspend();
        ((EntityInternal)entity).feeds().remove((Feed) adjunct);
    } else {
        // shouldn't come here
        throw WebResourceUtils.badRequest("Unexpected adjunct type %s", adjunct);
    }
    
    return Response.status(Response.Status.NO_CONTENT).build();
}
 
Example #9
Source File: RebindEnricherTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testEntityCreatingItsEnricherDoesNotReCreateItUnlessUniqueTagDifferent() throws Exception {
    TestEntity e1 = origApp.createAndManageChild(EntitySpec.create(TestEntity.class, MyTestEntityWithEnricher.class));
    Collection<Enricher> e1e = e1.enrichers().asList();
    log.info("enrichers1: "+e1e);
    Dumper.dumpInfo(e1);
    assertEquals(e1e.size(), 5);

    newApp = rebind();
    Entity e2 = Iterables.getOnlyElement( Entities.descendantsAndSelf(newApp, EntityPredicates.idEqualTo(e1.getId())) );
    Collection<Enricher> e2e = e2.enrichers().asList();
    log.info("enrichers2: "+e2e);
    Dumper.dumpInfo(e2);
    
    assertEquals(e2e.size(), e1e.size()+1);
}
 
Example #10
Source File: MementosGenerators.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/**
 * Inspects a brooklyn object to create a basic corresponding memento.
 * <p>
 * The memento is "basic" in the sense that it does not tie in to any entity-specific customization;
 * the corresponding memento may subsequently be customized by the caller.
 * <p>
 * This method is intended for use by {@link AbstractBrooklynObjectRebindSupport#getMemento()}
 * and callers wanting a memento for an object should use that, or the
 * {@link BrooklynPersistenceUtils#newObjectMemento(BrooklynObject)} convenience.
 */
@Beta
public static Memento newBasicMemento(BrooklynObject instance) {
    if (instance instanceof Entity) {
        return newEntityMemento((Entity)instance);
    } else if (instance instanceof Location) {
        return newLocationMemento((Location)instance);
    } else if (instance instanceof Policy) {
        return newPolicyMemento((Policy)instance);
    } else if (instance instanceof Enricher) {
        return newEnricherMemento((Enricher) instance);
    } else if (instance instanceof Feed) {
        return newFeedMemento((Feed)instance);
    } else if (instance instanceof CatalogItem) {
        return newCatalogItemMemento((CatalogItem<?,?>) instance);
    } else if (instance instanceof ManagedBundle) {
        return newManagedBundleMemento((ManagedBundle) instance);
    } else {
        throw new IllegalArgumentException("Unexpected brooklyn type: "+(instance == null ? "null" : instance.getClass())+" ("+instance+")");
    }
}
 
Example #11
Source File: MementosGenerators.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/**
 * Given an enricher, extracts its state for serialization.
 * @deprecated since 0.7.0, see {@link #newBasicMemento(BrooklynObject)}
 */
@Deprecated
public static EnricherMemento newEnricherMemento(Enricher enricher) {
    BasicEnricherMemento.Builder builder = BasicEnricherMemento.builder();
    populateBrooklynObjectMementoBuilder(enricher, builder);
    
    // TODO persist config keys as well? Or only support those defined on policy class;
    // current code will lose the ConfigKey type on rebind for anything not defined on class.
    // Whereas entities support that.
    // TODO Do we need the "nonPersistableFlagNames" that locations use?
    Map<ConfigKey<?>, Object> config = ((AbstractEnricher)enricher).config().getInternalConfigMap().getAllConfigLocalRaw();
    for (Map.Entry<ConfigKey<?>, Object> entry : config.entrySet()) {
        ConfigKey<?> key = checkNotNull(entry.getKey(), "config=%s", config);
        Object value = configValueToPersistable(entry.getValue(), enricher, key.getName());
        builder.config.put(key.getName(), value); 
    }
    
    Map<String, Object> persistableFlags = MutableMap.<String, Object>builder()
            .putAll(FlagUtils.getFieldsWithFlagsExcludingModifiers(enricher, Modifier.STATIC ^ Modifier.TRANSIENT))
            .remove("id")
            .remove("name")
            .build();
    builder.config.putAll(persistableFlags);

    return builder.build();
}
 
Example #12
Source File: RebindExceptionHandlerImpl.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void onAddEnricherFailed(EntityLocal entity, Enricher enricher, Exception e) {
    Exceptions.propagateIfFatal(e);
    String errmsg = "problem adding enricher "+enricher.getId()+" ("+enricher+") to entity "+entity.getId()+" ("+entity+")";

    switch (addPolicyFailureMode) {
    case FAIL_FAST:
        throw new IllegalStateException("Rebind: aborting due to "+errmsg, e);
    case FAIL_AT_END:
        addPolicyFailures.add(new IllegalStateException(errmsg, e));
        break;
    case CONTINUE:
        warn(errmsg+"; continuing", e);
        break;
    default:
        throw new IllegalStateException("Unexpected state '"+addPolicyFailureMode+"' for addPolicyFailureMode");
    }
}
 
Example #13
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
LookupContextImpl(String description, ManagementContext mgmt, Iterable<? extends Entity> entities, Iterable<? extends Location> locations,
        Iterable<? extends Policy> policies, Iterable<? extends Enricher> enrichers, Iterable<? extends Feed> feeds,
        Iterable<? extends CatalogItem<?, ?>> catalogItems, Iterable<? extends ManagedBundle> bundles,
            boolean failOnDangling) {
    this.description = new Stack<>();
    this.description.push(description);
    this.mgmt = mgmt;
    this.entities = Maps.newLinkedHashMap();
    this.locations = Maps.newLinkedHashMap();
    this.policies = Maps.newLinkedHashMap();
    this.enrichers = Maps.newLinkedHashMap();
    this.feeds = Maps.newLinkedHashMap();
    this.catalogItems = Maps.newLinkedHashMap();
    this.bundles = Maps.newLinkedHashMap();
    for (Entity entity : entities) this.entities.put(entity.getId(), entity);
    for (Location location : locations) this.locations.put(location.getId(), location);
    for (Policy policy : policies) this.policies.put(policy.getId(), policy);
    for (Enricher enricher : enrichers) this.enrichers.put(enricher.getId(), enricher);
    for (Feed feed : feeds) this.feeds.put(feed.getId(), feed);
    for (CatalogItem<?, ?> catalogItem : catalogItems) this.catalogItems.put(catalogItem.getId(), catalogItem);
    for (ManagedBundle bundle : bundles) this.bundles.put(bundle.getId(), bundle);
    this.failOnDangling = failOnDangling;
}
 
Example #14
Source File: CampInternalUtils.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private static EnricherSpec<? extends Enricher> resolveEnricherSpec(
        String versionedId,
        BrooklynClassLoadingContext loader,
        Set<String> encounteredCatalogTypes) {

    EnricherSpec<? extends Enricher> spec;
    RegisteredType item = loader.getManagementContext().getTypeRegistry().get(
        CatalogUpgrades.getTypeUpgradedIfNecessary(loader.getManagementContext(), versionedId));
    if (item != null && !encounteredCatalogTypes.contains(item.getSymbolicName())) {
        RegisteredTypeLoadingContext context = RegisteredTypeLoadingContexts.alreadyEncountered(encounteredCatalogTypes);
        return loader.getManagementContext().getTypeRegistry().createSpec(item, context, EnricherSpec.class);
    } else {
        // TODO-type-registry pass the loader in to the above, and allow it to load with the loader
        spec = EnricherSpec.create(loader.loadClass(versionedId, Enricher.class));
    }
    return spec;
}
 
Example #15
Source File: AbstractEntity.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(Enricher enricher) {
    ((AbstractEnricher)enricher).destroy();
    boolean changed = enrichersInternal.remove(enricher);
    
    if (changed) {
        getManagementSupport().getEntityChangeListener().onEnricherRemoved(enricher);
    }
    return changed;

}
 
Example #16
Source File: Enrichers.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: Dumper.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static void dumpInfo(Enricher enr) {
    try {
        dumpInfo(enr, new PrintWriter(System.out), "", "  ");
    } catch (IOException exc) {
        // system.out throwing an exception is odd, so don't have IOException on signature
        throw new RuntimeException(exc);
    }
}
 
Example #18
Source File: EntityAdjuncts.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static List<Enricher> getNonSystemEnrichers(Entity entity) {
    List<Enricher> result = MutableList.copyOf(entity.enrichers());
    Iterator<Enricher> ri = result.iterator();
    while (ri.hasNext()) {
        if (isSystemEnricher(ri.next())) ri.remove();
    }
    return result;
}
 
Example #19
Source File: EnrichersTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdding() {
    Enricher enr = entity.enrichers().add(Enrichers.builder()
            .combining(NUM1, NUM2)
            .publishing(NUM3)
            .computingSum()
            .build());
    
    Assert.assertEquals(EntityAdjuncts.getNonSystemEnrichers(entity), ImmutableList.of(enr));
    
    entity.sensors().set(NUM1, 2);
    entity.sensors().set(NUM2, 3);
    EntityAsserts.assertAttributeEqualsEventually(entity, NUM3, 5);
}
 
Example #20
Source File: BrooklynTypes.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public BrooklynDynamicType<?, ?> call() throws Exception {
    if (Entity.class.isAssignableFrom(brooklynClass)) {
        return new ImmutableEntityType((Class<? extends Entity>)brooklynClass);
    } else if (Location.class.isAssignableFrom(brooklynClass)) {
        return new ImmutableEntityType((Class<? extends Entity>)brooklynClass);
    } else if (Policy.class.isAssignableFrom(brooklynClass)) {
        return new PolicyDynamicType((Class<? extends Policy>)brooklynClass); // TODO immutable?
    } else if (Enricher.class.isAssignableFrom(brooklynClass)) {
        return new EnricherDynamicType((Class<? extends Enricher>)brooklynClass); // TODO immutable?
    } else {
        throw new IllegalStateException("Invalid brooklyn type "+brooklynClass);
    }
}
 
Example #21
Source File: RebindEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testPolicyTags() throws Exception {
    Enricher origEnricher = origApp.enrichers().add(EnricherSpec.create(MyEnricher.class));
    origEnricher.tags().addTag("foo");
    origEnricher.tags().addTag(origApp);

    newApp = rebind();
    Enricher newEnricher = Iterables.getOnlyElement(newApp.enrichers());

    Asserts.assertEqualsIgnoringOrder(newEnricher.tags().getTags(), ImmutableSet.of("foo", newApp));
}
 
Example #22
Source File: NonDeploymentEntityManager.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Enricher> T createEnricher(EnricherSpec<T> spec) {
    if (isInitialManagementContextReal()) {
        return initialManagementContext.getEntityManager().createEnricher(spec);
    } else {
        throw new IllegalStateException("Non-deployment context "+this+" (with no initial management context supplied) is not valid for this operation.");
    }
}
 
Example #23
Source File: LocalEntityManager.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Enricher> T createEnricher(EnricherSpec<T> spec) {
    try {
        return policyFactory.createEnricher(spec);
    } catch (Throwable e) {
        log.warn("Failed to create enricher using spec "+spec+" (rethrowing)", e);
        throw Exceptions.propagate(e);
    }
}
 
Example #24
Source File: BasicEnricherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSameUniqueTagEnricherNotAddedTwice() throws Exception {
    MyEnricher enricher1 = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(99).uniqueTag("x"));
    MyEnricher enricher2 = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(94).uniqueTag("x"));
    
    // the more recent one should dominate
    assertEquals(app.enrichers().asList(), ImmutableList.of(enricher2));
    
    Enricher enricher = Iterables.getOnlyElement(app.enrichers());
    Assert.assertTrue(enricher.tags().containsTag(94));
    Assert.assertFalse(enricher.tags().containsTag(99));
}
 
Example #25
Source File: RebindExceptionHandlerImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Enricher onDanglingEnricherRef(String id) {
    missingEnrichers.add(id);
    if (danglingRefFailureMode == RebindManager.RebindFailureMode.FAIL_FAST) {
        throw new IllegalStateException("No enricher found with id "+id);
    } else {
        warn("No enricher found with id "+id+"; dangling reference on rebind");
        return null;
    }
}
 
Example #26
Source File: RebindFailuresTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testRebindWithFailingEnricherContinuesWithoutEnricher() throws Exception {
    origApp.enrichers().add(EnricherSpec.create(MyEnricherFailingImpl.class)
            .configure(MyEnricherFailingImpl.FAIL_ON_REBIND, true));
    
    newApp = rebind(RebindOptions.create().defaultExceptionHandler());
    
    Optional<Enricher> newEnricher = Iterables.tryFind(newApp.enrichers(), Predicates.instanceOf(MyEnricherFailingImpl.class));
    assertFalse(newEnricher.isPresent(), "enricher="+newEnricher);
}
 
Example #27
Source File: ServiceStateLogic.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private static void setExpectedState(Entity entity, Lifecycle state, boolean waitBrieflyForServiceUpIfRunning) {
    if (waitBrieflyForServiceUpIfRunning) {
        waitBrieflyForServiceUpIfStateIsRunning(entity, state);
    }
    ((EntityInternal)entity).sensors().set(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state, new Date()));

    Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.enrichers(), ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG);
    if (enricher.isPresent() && enricher.get() instanceof ComputeServiceState) {
        ((ComputeServiceState)enricher.get()).onEvent(null);
    }
}
 
Example #28
Source File: EnrichersTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testLookup() {
    Enricher enr = entity.enrichers().add(Enrichers.builder()
            .combining(NUM1, NUM2)
            .publishing(NUM3)
            .computingSum()
            .build());
    
    Assert.assertEquals(mgmt.lookup(enr.getId()), enr);
}
 
Example #29
Source File: Enrichers.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public EnricherSpec<? extends Enricher> build() {
    return super.build().configure(MutableMap.builder()
                    .putIfNotNull(Propagator.PRODUCER, fromEntity)
                    .putIfNotNull(Propagator.PRODUCER, fromEntitySupplier)
                    .putIfNotNull(Propagator.SENSOR_MAPPING, propagating)
                    .putIfNotNull(Propagator.PROPAGATING_ALL, propagatingAll)
                    .putIfNotNull(Propagator.PROPAGATING_ALL_BUT, propagatingAllBut)
                    .build());
}
 
Example #30
Source File: RebindIteration.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new enricher, passing to its constructor the enricher id and all of memento.getConfig().
 */
protected Enricher newEnricher(EnricherMemento memento) {
    String id = memento.getId();
    LoadedClass<? extends Enricher> loaded = load(Enricher.class, memento);
    Class<? extends Enricher> enricherClazz = loaded.clazz;

    Enricher enricher;
    if (InternalFactory.isNewStyle(enricherClazz)) {
        InternalPolicyFactory policyFactory = managementContext.getPolicyFactory();
        enricher = policyFactory.constructEnricher(enricherClazz);
        FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", id), enricher);
        ((AbstractEnricher)enricher).setManagementContext(managementContext);

    } else {
        LOG.warn("Deprecated rebind of enricher without no-arg constructor; " +
            "this may not be supported in future versions: id=" + id + "; type="+enricherClazz);

        // There are several possibilities for the constructor; find one that works.
        // Prefer passing in the flags because required for Application to set the management context
        // TODO Feels very hacky!
        Map<String, Object> flags = MutableMap.<String, Object>of(
            "id", id, 
            "deferConstructionChecks", true,
            "noConstructionInit", true);
        flags.putAll(memento.getConfig());

        enricher = invokeConstructor(reflections, enricherClazz, new Object[] {flags});
    }
    
    setCatalogItemIds(enricher, loaded.catalogItemId, loaded.searchPath);
    return enricher;
}