Java Code Examples for org.apache.brooklyn.core.entity.Entities#destroy()

The following examples show how to use org.apache.brooklyn.core.entity.Entities#destroy() . 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: EntityExecutionManagerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void testSubscriptionAndEffectorTasksGced() throws Exception {
    BasicExecutionManager em = (BasicExecutionManager) app.getManagementContext().getExecutionManager();
    // allow background enrichers to complete
    Time.sleep(Duration.ONE_SECOND);
    forceGc();
    Collection<Task<?>> t1 = em.getAllTasks();

    TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    entity.sensors().set(TestEntity.NAME, "bob");
    entity.invoke(TestEntity.MY_EFFECTOR, ImmutableMap.<String,Object>of()).get();
    Entities.destroy(entity);
    Time.sleep(Duration.ONE_SECOND);
    forceGc();
    Collection<Task<?>> t2 = em.getAllTasks();

    // no tasks from first batch were GC'd
    Asserts.assertSize(MutableList.builder().addAll(t1).removeAll(t2).build(), 0);

    // and we expect just the add/remove cycle at parent, and service problems
    Set<String> newOnes = MutableList.<Task<?>>builder().addAll(t2).removeAll(t1).build().stream().map(
        (t) -> t.getDisplayName()).collect(Collectors.toSet());
    Function<String,String> prefix = (s) -> "sensor "+app.getId()+":"+s;
    Assert.assertEquals(newOnes, MutableSet.of(
        prefix.apply("entity.children.removed"), prefix.apply("entity.children.added"), prefix.apply("service.problems"))); 
}
 
Example 2
Source File: BrooklynMementoPersisterTestFixture.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@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()));
}
 
Example 3
Source File: AbstractBlueprintTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
    try {
        if (mgmt != null) {
            for (Application app: mgmt.getApplications()) {
                LOG.debug("destroying app "+app+" (managed? "+Entities.isManaged(app)+"; mgmt is "+mgmt+")");
                try {
                    Entities.destroy(app);
                    LOG.debug("destroyed app "+app+"; mgmt now "+mgmt);
                } catch (Exception e) {
                    LOG.error("problems destroying app "+app, e);
                }
            }
        }
        if (launcher != null) launcher.destroyAll();
        if (viewer != null) viewer.terminate();
        if (mgmt != null) Entities.destroyAll(mgmt);
        if (mementoDir != null) FileBasedObjectStore.deleteCompletely(mementoDir);
    } catch (Throwable t) {
        LOG.error("Caught exception in tearDown method", t);
    } finally {
        mgmt = null;
        launcher = null;
    }
}
 
Example 4
Source File: ActivityRestTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void initEntity(int seed) {
    if (entity != null && Entities.isManaged(entity)) {
        Entities.destroy(entity.getApplication());
    }
    
    CreationResult<BasicApplication, Void> app = EntityManagementUtils.createStarting(getManagementContext(),
        EntitySpec.create(BasicApplication.class)
            .child(EntitySpec.create(TestEntityWithEffectors.class)) );
    app.blockUntilComplete();
    entity = Iterables.getOnlyElement( app.get().getChildren() );
    
    SampleManyTasksEffector manyTasksAdder = new SampleManyTasksEffector(ConfigBag.newInstance().configure(SampleManyTasksEffector.RANDOM_SEED, seed));
    effector = manyTasksAdder.getEffector();
    manyTasksAdder.apply((org.apache.brooklyn.api.entity.EntityLocal) entity);
}
 
Example 5
Source File: VanillaWindowsProcessWinrmExitStatusLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
    try {
        try {
            if (app != null) Entities.destroy(app);
        } catch (Throwable t) {
            LOG.error("Caught exception in tearDown method", t);
        }
    } finally {
        app = null;
    }
}
 
Example 6
Source File: EffectorTaskTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Void call(ConfigBag parameters) {
    Entity child = Iterables.getOnlyElement(entity().getChildren());
    AtomicBoolean lock = new AtomicBoolean();
    Task<Void> dummyTask = null;

    try {
        // Queue a (DST secondary) task which waits until notified, so that tasks queued later will get blocked
        queue(Effectors.invocation(entity(), STALL, ImmutableMap.of("lock", lock)));
    
        // Start a new task - submitted directly to child's ExecutionContext, as well as added as a
        // DST secondary of the current effector.
        dummyTask = child.invoke(DUMMY, ImmutableMap.<String, Object>of());
        dummyTask.getUnchecked();

        // Execution completed in the child's ExecutionContext, but still queued as a secondary.
        // Destroy the child entity so that no subsequent tasks can be executed in its context.
        Entities.destroy(child);
    } finally {
        // Let STALL complete
        synchronized(lock) {
            lock.set(true);
            lock.notifyAll();
        }
        // At this point DUMMY will be unblocked and the DST will try to execute it as a secondary.
        // Submission will be ignored because DUMMY already executed.
        // If it's not ignored then submission will fail because entity is already unmanaged.
    }
    return null;
}
 
Example 7
Source File: EntityExecutionManagerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public void testUnmanagedEntityCanBeGcedEvenIfPreviouslyTagged() throws Exception {
    TestEntity e = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    String eId = e.getId();
    
    e.invoke(TestEntity.MY_EFFECTOR, ImmutableMap.<String,Object>of()).get();
    Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(app.getManagementContext().getExecutionManager(), e);
    Task<?> task = Iterables.get(tasks, 0);
    assertTrue(task.getTags().contains(BrooklynTaskTags.tagForContextEntity(e)));

    Set<Object> tags = app.getManagementContext().getExecutionManager().getTaskTags();
    assertTrue(tags.contains(BrooklynTaskTags.tagForContextEntity(e)), "tags="+tags);
    
    Entities.destroy(e);
    forceGc();
    
    Set<Object> tags2 = app.getManagementContext().getExecutionManager().getTaskTags();
    for (Object tag : tags2) {
        if (tag instanceof Entity && ((Entity)tag).getId().equals(eId)) {
            fail("tags contains unmanaged entity "+tag);
        }
        if ((tag instanceof WrappedEntity) && ((WrappedEntity)tag).unwrap().getId().equals(eId) 
                && ((WrappedItem<?>)tag).getWrappingType().equals(BrooklynTaskTags.CONTEXT_ENTITY)) {
            fail("tags contains unmanaged entity (wrapped) "+tag);
        }
    }
    return;
}
 
Example 8
Source File: EffectorResourceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyMethod() throws Exception {
    try {
        if (app != null) Entities.destroy(app);
    } finally {
        super.destroyMethod();
    }
}
 
Example 9
Source File: VanillaWindowsProcessWinrmStreamsLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun = true)
@Override
public void tearDown() throws Exception {
    try {
        if (app != null) Entities.destroy(app);
    } catch (Throwable t) {
        LOG.error("Caught exception in tearDown method", t);
    } finally {
        app = null;
    }
}
 
Example 10
Source File: VanillaWindowsProcessWinrmStreamsLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
    super.setUp();
    if (app != null) Entities.destroy(app);
    
    location = WindowsTestFixture.setUpWindowsLocation(mgmt);
    machine = location.obtain(ImmutableMap.of());
}
 
Example 11
Source File: MongoDBWinEc2LiveTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun = true)
public void tearDown() throws Exception {
    try {
        try {
            if (app != null)
                Entities.destroy(app);
        } catch (Throwable t) {
            LOG.error("Caught exception in tearDown method", t);
        }
    } finally {
        app = null;
    }
}
 
Example 12
Source File: AbstractServerPoolTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun=true)
public void tearDown() throws Exception {
    // Kills the apps before terminating the pool
    for (TestApplication app : createdApps) {
        Entities.destroy(app);
    }
    if (mgmt != null) {
        Entities.destroyAll(mgmt);
        mgmt = null;
    }
}
 
Example 13
Source File: WindowsYamlLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun = true)
@Override
public void tearDown() {
    try {
        if (app != null) Entities.destroy(app);
    } catch (Throwable t) {
        log.error("Caught exception in tearDown method", t);
    } finally {
        app = null;
    }
}
 
Example 14
Source File: CatalogMakeOsgiBundleTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun = true)
public void cleanUpButKeepMgmt() throws Exception {
    for (Application app: MutableList.copyOf(mgmt().getApplications())) {
        Entities.destroy(app);
    }
    for (Bundle b: bundlesToRemove) {
        ((ManagementContextInternal)mgmt()).getOsgiManager().get().uninstallUploadedBundle(
            ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundle(new VersionedName(b)));
    }
    bundlesToRemove.clear();
}
 
Example 15
Source File: Infinispan5ServerIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"Integration", "WIP"})
public void testInfinispanStartsAndStops() {
    Application app = new TestApplicationImpl();
    try {
        final Infinispan5Server infini = new Infinispan5Server(ImmutableMap.of("parent", app));
        infini.config().set(Infinispan5Server.PORT.getConfigKey(), PortRanges.fromInteger(DEFAULT_PORT));
        infini.start(ImmutableList.of(new LocalhostMachineProvisioningLocation(ImmutableMap.of("name","london"))));
        EntityAsserts.assertAttributeEqualsEventually(infini, Infinispan5Server.SERVICE_UP, Boolean.TRUE);
    } finally {
        Entities.destroy(app);
    }
}
 
Example 16
Source File: MySqlClusterIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testDumpReplication() throws Exception {
    try {
        Location loc = getLocation();
        EntitySpec<MySqlCluster> clusterSpec = EntitySpec.create(MySqlCluster.class)
                .configure(MySqlMaster.MASTER_CREATION_SCRIPT_CONTENTS, MySqlClusterTestHelper.CREATION_SCRIPT)
                .configure(MySqlNode.MYSQL_SERVER_CONF, MySqlClusterTestHelper.minimalMemoryConfig());
        MySqlCluster cluster = MySqlClusterTestHelper.initCluster(app, loc, clusterSpec);
        MySqlNode master = (MySqlNode) cluster.getAttribute(MySqlCluster.FIRST);
        purgeLogs(cluster, master);

        // test dump replication from master
        MySqlNode slave = (MySqlNode) Iterables.getOnlyElement(cluster.invoke(MySqlCluster.RESIZE_BY_DELTA, ImmutableMap.of("delta", 1)).getUnchecked());
        assertEquals(cluster.getAttribute(MySqlCluster.REPLICATION_LAST_SLAVE_SNAPSHOT).getEntityId(), master.getId());
        MySqlClusterTestHelper.assertReplication(master, slave);

        // test dump replication from slave, missing dump on node
        deleteSnapshot(cluster);
        cluster.config().set(MySqlCluster.REPLICATION_PREFERRED_SOURCE, slave.getId());
        MySqlNode secondSlave = (MySqlNode) Iterables.getOnlyElement(cluster.invoke(MySqlCluster.RESIZE_BY_DELTA, ImmutableMap.of("delta", 1)).getUnchecked());
        assertEquals(cluster.getAttribute(MySqlCluster.REPLICATION_LAST_SLAVE_SNAPSHOT).getEntityId(), slave.getId());
        MySqlClusterTestHelper.assertReplication(master, secondSlave);

        // test dump replication from slave, missing snapshot entity
        Entities.destroy(slave);
        cluster.config().set(MySqlCluster.REPLICATION_PREFERRED_SOURCE, secondSlave.getId());
        MySqlNode thirdSlave = (MySqlNode) Iterables.getOnlyElement(cluster.invoke(MySqlCluster.RESIZE_BY_DELTA, ImmutableMap.of("delta", 1)).getUnchecked());
        assertEquals(cluster.getAttribute(MySqlCluster.REPLICATION_LAST_SLAVE_SNAPSHOT).getEntityId(), secondSlave.getId());
        MySqlClusterTestHelper.assertReplication(master, thirdSlave);
    } finally {
        cleanData();
    }
}
 
Example 17
Source File: AbstractWebAppFixtureIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@AfterMethod(alwaysRun=true)
public void shutdownApp() {
    if (entity != null) {
        Application app = entity.getApplication();
        if (app != null) Entities.destroy(app);
    }
}