public void unregisterEnricher(Enricher enricher) { enrichers.remove(enricher.getId()); }
@Override protected Enricher getInstanceFromId(Optional<Entity> entity, String id) { if (id == null || !entity.isPresent()) return null; for (Enricher enricher : entity.get().enrichers()) { if (id.equals(enricher.getId())) { return enricher; } } return null; } }
@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"); } }
@Test public void testCheckPointAndLoadMemento() throws Exception { BrooklynMemento reloadedMemento = loadMemento(); assertNotNull(reloadedMemento); assertTrue(Iterables.contains(reloadedMemento.getEntityIds(), entity.getId())); assertEquals(Iterables.getOnlyElement(reloadedMemento.getLocationIds()), location.getId()); assertEquals(Iterables.getOnlyElement(reloadedMemento.getPolicyIds()), policy.getId()); assertTrue(reloadedMemento.getEnricherIds().contains(enricher.getId())); }
LookupContextImpl(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.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; } LookupContextImpl(ManagementContext mgmt, Map<String,? extends Entity> entities, Map<String,? extends Location> locations,
builder.enrichers.add(enricher.getId());
@Test public void testLoadAndCheckpointRawMemento() throws Exception { if (persister instanceof BrooklynMementoPersisterToObjectStore) { // Test loading BrooklynMementoRawData rawMemento = loadRawMemento((BrooklynMementoPersisterToObjectStore)persister); assertNotNull(rawMemento); assertTrue(Iterables.contains(rawMemento.getEntities().keySet(), entity.getId())); assertEquals(Iterables.getOnlyElement(rawMemento.getLocations().keySet()), location.getId()); assertEquals(Iterables.getOnlyElement(rawMemento.getPolicies().keySet()), policy.getId()); assertTrue(rawMemento.getEnrichers().keySet().contains(enricher.getId())); // And test persisting PersistenceExceptionHandler exceptionHandler = PersistenceExceptionHandlerImpl.builder().build(); ((BrooklynMementoPersisterToObjectStore) persister).checkpoint(rawMemento, exceptionHandler); } else { throw new SkipException("Persister "+persister+" not a "+BrooklynMementoPersisterToObjectStore.class.getSimpleName()); } } }
@Test public void testDeleteAndLoadMemento() throws Exception { Entities.destroy(entity); BrooklynMemento reloadedMemento = loadMemento(); assertNotNull(reloadedMemento); assertFalse(Iterables.contains(reloadedMemento.getEntityIds(), entity.getId())); assertEquals(Iterables.getOnlyElement(reloadedMemento.getLocationIds()), location.getId()); // Destroying the app should also unmanage its owned location, and adjuncts Entities.destroy(app); reloadedMemento = loadMemento(); assertFalse(Iterables.contains(reloadedMemento.getEntityIds(), entity.getId())); assertFalse(Iterables.contains(reloadedMemento.getPolicyIds(), policy.getId())); assertFalse(Iterables.contains(reloadedMemento.getEnricherIds(), enricher.getId())); assertFalse(Iterables.contains(reloadedMemento.getLocationIds(), location.getId())); }
result.enricher(instanceAdjunct.getId(), serializer.toString(newObjectMemento(instanceAdjunct)));