@Override protected Feed getInstanceFromId(Optional<Entity> entity, String id) { if (id == null || !entity.isPresent()) return null; for (Feed feed : ((EntityInternal)entity).feeds().getFeeds()) { if (id.equals(feed.getId())) { return feed; } } return null; } }
@Test public void testConcurrentAddFeed() throws Exception { final int NUM_TASKS = 100; List<ListenableFuture<?>> futures = Lists.newArrayList(); for (int i = 0; i < NUM_TASKS; i++) { ListenableFuture<?> future = executor.submit(new Runnable() { @Override public void run() { entity.feeds().addFeed(new MyFeed()); }}); futures.add(future); } Futures.allAsList(futures).get(); assertEquals(entity.feeds().getFeeds().size(), NUM_TASKS); } private static class MyFeed extends AbstractFeed {
@Test public void testFeedDeDupe() throws Exception { testPollsFunctionRepeatedlyToSetAttribute(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); Feed feed0 = feed; testPollsFunctionRepeatedlyToSetAttribute(); entity.addFeed(feed); log.info("Feed 1 is: "+feed); Feed feed1 = feed; Assert.assertFalse(feed1==feed0); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); // a couple extra checks, compared to the de-dupe test in other *FeedTest classes Feed feedAdded = Iterables.getOnlyElement(feeds.getFeeds()); Assert.assertTrue(feedAdded==feed1); Assert.assertFalse(feedAdded==feed0); }
instance = Entities.deproxy(instance); result.entity(instance.getId(), serializer.toString(newObjectMemento(instance))); for (Feed instanceAdjunct: ((EntityInternal)instance).feeds().getFeeds()) { result.feed(instanceAdjunct.getId(), serializer.toString(newObjectMemento(instanceAdjunct)));
EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_INT, 200); EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_STRING, "{\"foo\":\"myfoo\"}"); assertEquals(origEntity.feeds().getFeeds().size(), 1); origManagementContext.getRebindManager().forcePersistNow(); Collection<Feed> newFeeds = newEntity.feeds().getFeeds(); assertEquals(newFeeds.size(), 1);
EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_INT, 200); EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_STRING, "{\"foo\":\"myfoo\"}"); assertEquals(origEntity.feeds().getFeeds().size(), 1); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection<Feed> newFeeds = newEntity.feeds().getFeeds(); assertEquals(newFeeds.size(), 1);
MyFeed newFeed = (MyFeed) Iterables.find(newApp.feeds().getFeeds(), Predicates.instanceOf(MyFeed.class)); assertEquals(newFeed.config().get(MyFeed.KEY_1), "myval1"); assertEquals(newFeed.config().get(MyFeed.KEY_2), "myval2");
private void addReferencedObjects(DeltaCollector deltaCollector) { MutableSet<BrooklynObject> referencedObjects = MutableSet.of(); // collect references for (Entity entity : deltaCollector.entities) { // FIXME How to let the policy/location tell us about changes? Don't do this every time! for (Location location : entity.getLocations()) { Collection<Location> findLocationsInHierarchy = TreeUtils.findLocationsInHierarchy(location); referencedObjects.addAll(findLocationsInHierarchy); } if (persistPoliciesEnabled) { referencedObjects.addAll(entity.policies()); } if (persistEnrichersEnabled) { referencedObjects.addAll(entity.enrichers()); } if (persistFeedsEnabled) { referencedObjects.addAll(((EntityInternal)entity).feeds().getFeeds()); } } for (BrooklynObject instance : referencedObjects) { deltaCollector.addIfNotRemoved(instance); } }
@Test(groups="Integration") public void testHotStandbyDoesNotStartFeedsRebindingManyTimesWithAnotherFeedGenerator() throws Exception { HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER); TestApplication app = createFirstAppAndPersist(n1); TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithNewFeedsEachTimeImpl.class)); forcePersistNow(n1); Assert.assertTrue(entity.feeds().getFeeds().size() == 4, "Feeds: "+entity.feeds().getFeeds()); final HaMgmtNode hsb = createHotStandby(Duration.millis(10)); Repeater.create("until 10 rebinds").every(Duration.millis(100)).until( new Callable<Boolean>() { @Override public Boolean call() throws Exception { return ((RebindManagerImpl)hsb.mgmt.getRebindManager()).getReadOnlyRebindCount() >= 10; } }).runRequiringTrue(); // make sure not too many tasks (allowing 5 for rebind etc; currently just 2) RebindTestFixture.waitForTaskCountToBecome(hsb.mgmt, 5); }
@Test public void testHotStandbyDoesNotStartFeeds() throws Exception { HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER); TestApplication app = createFirstAppAndPersist(n1); TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithFunctionFeedImpl.class)); forcePersistNow(n1); Assert.assertTrue(entity.feeds().getFeeds().size() > 0, "Feeds: "+entity.feeds().getFeeds()); for (Feed feed : entity.feeds().getFeeds()) { assertTrue(feed.isRunning(), "Feed expected running, but it is non-running"); } HaMgmtNode n2 = createHotStandby(Duration.PRACTICALLY_FOREVER); TestEntity entityRO = (TestEntity) n2.mgmt.lookup(entity.getId(), Entity.class); Assert.assertTrue(entityRO.feeds().getFeeds().size() > 0, "Feeds: "+entity.feeds().getFeeds()); for (Feed feedRO : entityRO.feeds().getFeeds()) { assertFalse(feedRO.isRunning(), "Feed expected non-active, but it is running"); } }
protected void runJmxFeedIsPersisted(boolean preCreateJmxHelper) throws Exception { TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithJmxFeedImpl.class) .configure(MyEntityWithJmxFeedImpl.PRE_CREATE_JMX_HELPER, preCreateJmxHelper)); origApp.start(ImmutableList.<Location>of()); jmxService = new JmxService(origEntity); GeneralisedDynamicMBean mbean = jmxService.registerMBean(MutableMap.of(JMX_ATTRIBUTE_NAME, "myval"), OBJECT_NAME); EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_STRING, "myval"); assertEquals(origEntity.feeds().getFeeds().size(), 1); newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection<Feed> newFeeds = newEntity.feeds().getFeeds(); assertEquals(newFeeds.size(), 1); // Expect the feed to still be polling newEntity.sensors().set(SENSOR_STRING, null); EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_STRING, "myval"); }
@Test(groups="Integration") public void testSshFeedRegisteredInStartIsPersisted() throws Exception { LocalhostMachineProvisioningLocation origLoc = origApp.newLocalhostProvisioningLocation(); SshMachineLocation origMachine = origLoc.obtain(); TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithSshFeedImpl.class) .location(origMachine)); origApp.start(ImmutableList.<Location>of()); EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_INT, 0); assertEquals(origEntity.feeds().getFeeds().size(), 1); newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection<Feed> newFeeds = newEntity.feeds().getFeeds(); assertEquals(newFeeds.size(), 1); // Expect the feed to still be polling newEntity.sensors().set(SENSOR_INT, null); EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_INT, 0); }
@Test public void testFunctionFeedRegisteredInInitIsPersisted() throws Exception { TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithFunctionFeedImpl.class)); EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_INT, 1); assertEquals(origEntity.feeds().getFeeds().size(), 2); newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren()); Collection<Feed> newFeeds = newEntity.feeds().getFeeds(); assertEquals(newFeeds.size(), 2); // Expect the feed to still be polling newEntity.sensors().set(SENSOR_INT, null); EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_INT, 1); }
public void run() { Collection<Feed> feeds = ((EntityInternal)entity).feeds().getFeeds(); for (Feed feed : feeds) { if (uniqueTag.equals(feed.getUniqueTag())) { return; } } fail("No feed found with uniqueTag "+uniqueTag+" in entity "+entity+"; feeds="+feeds); }}); }
@Test public void testFeedDeDupe() throws Exception { testPollsAndParsesHttpGetResponse(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); testPollsAndParsesHttpGetResponse(); log.info("Feed 1 is: "+feed); entity.addFeed(feed); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); }
@Test(groups="Live") public void testFeedDeDupe() throws Exception { testReturnsStdoutAndInfersMachine(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); testReturnsStdoutAndInfersMachine(); log.info("Feed 1 is: "+feed); entity.addFeed(feed); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); }
@Override public String call() { DynamicTasks.markInessential(); for (Feed feed : entity().feeds().getFeeds()) { if (feed.isActivated()) feed.stop(); } DynamicTasks.waitForLast(); return "Stop feeds completed with no errors."; } }
@Test(groups="Integration") public void testFeedDeDupe() throws Exception { testReturnsShellExitStatus(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); testReturnsShellExitStatus(); log.info("Feed 1 is: "+feed); entity.addFeed(feed); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); }
@Test(groups="Integration") public void testFeedDeDupe() throws Exception { testReturnsSshStdoutAndInfersMachine(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); testReturnsSshStdoutAndInfersMachine(); log.info("Feed 1 is: "+feed); entity.addFeed(feed); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); }
@Override public synchronized void onUnmanaged(BrooklynObject instance) { if (LOG.isTraceEnabled()) LOG.trace("onUnmanaged: {}", instance); if (!isStopped()) { removeFromCollector(instance); if (instance instanceof Entity) { Entity entity = (Entity) instance; for (BrooklynObject adjunct : entity.policies()) removeFromCollector(adjunct); for (BrooklynObject adjunct : entity.enrichers()) removeFromCollector(adjunct); for (BrooklynObject adjunct : ((EntityInternal)entity).feeds().getFeeds()) removeFromCollector(adjunct); } } }