Java Code Examples for org.apache.brooklyn.core.entity.Entities#unmanage()
The following examples show how to use
org.apache.brooklyn.core.entity.Entities#unmanage() .
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: FollowTheSunPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testItemRemovedCausesRecalculationOfOptimalLocation() { // Set-up containers and items. MockContainerEntity containerA = newContainer(app, loc1, "A"); MockContainerEntity containerB = newContainer(app, loc2, "B"); MockItemEntity item1 = newItem(app, containerA, "1"); MockItemEntity item2 = newItem(app, containerA, "2"); MockItemEntity item3 = newItem(app, containerB, "3"); item1.sensors().set(MockItemEntity.ITEM_USAGE_METRIC, ImmutableMap.<Entity,Double>of(item2, 100d, item3, 1000d)); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item2), containerB, ImmutableList.of(item1, item3))); item3.stop(); Entities.unmanage(item3); assertItemDistributionEventually(ImmutableMap.of(containerA, ImmutableList.of(item1, item2), containerB, ImmutableList.<MockItemEntity>of())); }
Example 2
Source File: EffectorBasicTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testInvokeEffectorListWithEmptyUsingUnmanagedContext() throws Exception { // Previously this threw the IllegalStateException directly, because DynamicTasks called // ((EntityInternal)entity).getManagementSupport().getExecutionContext(); // (so it successfully called getManagementSupport, and then hit the exception. // Now it calls ((EntityInternal)entity).getExecutionContext(), so the exception happens in // the entity-proxy and is thus wrapped. TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class)); Entities.unmanage(entity); try { Entities.invokeEffectorList(entity, ImmutableList.<StartableApplication>of(), Startable.STOP).get(Duration.THIRTY_SECONDS); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { IllegalStateException e2 = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class); if (e2 == null) throw e; Asserts.expectedFailureContains(e2, "no longer managed"); } }
Example 3
Source File: NginxUrlMappingIntegrationTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = "Integration") public void testUrlMappingRemovedWhenMappingEntityRemoved() throws Exception { DynamicCluster c0 = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure("initialSize", 1) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(Tomcat8Server.class).configure("httpPort", "8100+")) .configure(JavaWebAppService.ROOT_WAR, getTestWar())); UrlMapping u0 = urlMappingsGroup.addChild(EntitySpec.create(UrlMapping.class) .configure("domain", "localhost2") .configure("target", c0)); nginx = app.createAndManageChild(EntitySpec.create(NginxController.class) .configure("domain", "localhost") .configure("port", "8000+") .configure("portNumberSensor", WebAppService.HTTP_PORT) .configure("urlMappings", urlMappingsGroup)); app.start(ImmutableList.of(localLoc)); int port = nginx.getAttribute(NginxController.PROXY_HTTP_PORT); // Wait for deployment to be successful HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://localhost2:"+port+"/", 200); // Now remove mapping; will no longer route requests Entities.unmanage(u0); HttpTestUtils.assertHttpStatusCodeEventuallyEquals("http://localhost2:"+port+"/", 404); }
Example 4
Source File: DynamicGroupTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testStoppedGroupIgnoresComingAndGoingsOfEntities() throws Exception { group.setEntityFilter(Predicates.instanceOf(TestEntity.class)); assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2)); group.stop(); Entity e3 = app.addChild(EntitySpec.create(TestEntity.class)); Asserts.succeedsContinually(MutableMap.of("timeout", VERY_SHORT_WAIT_MS), new Runnable() { @Override public void run() { assertEquals(ImmutableSet.copyOf(group.getMembers()), ImmutableSet.of(e1, e2)); }}); Entities.unmanage(e3); Asserts.succeedsContinually(MutableMap.of("timeout", VERY_SHORT_WAIT_MS), new Runnable() { @Override public void run() { assertEqualsIgnoringOrder(ImmutableSet.copyOf(group.getMembers()), ImmutableSet.of(e1, e2)); }}); }
Example 5
Source File: SoftwareProcessEntityTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
public void doTestReleaseEvenIfErrorDuringStop(final Class<? extends SimulatedDriver> driver) throws Exception { MyService entity = app.addChild(EntitySpec.create(MyServiceWithCustomDriver.class) .configure(MyServiceWithCustomDriver.DRIVER_CLASS, driver)); entity.start(ImmutableList.of(loc)); Task<Void> t = entity.invoke(Startable.STOP, ImmutableMap.<String, Object>of()); t.blockUntilEnded(); assertFalse(t.isError(), "Expected parent to succeed, not fail with " + Tasks.getError(t)); Iterator<Task<?>> failures; failures = Tasks.failed(Tasks.descendants(t, true)).iterator(); Assert.assertTrue(failures.hasNext(), "Expected error in descendants"); Optional<Task<?>> stopping = Iterables.tryFind(Tasks.children(t), TaskPredicates.displayNameEqualTo("stopping")); Assert.assertTrue(stopping.isPresent(), "Could not find stopping task"); failures = Tasks.failed(Tasks.children(stopping.get())).iterator(); Assert.assertTrue(failures.hasNext(), "Expected error in child"); Throwable e = Tasks.getError(failures.next()); if (e == null || !e.toString().contains("Simulating stop error")) Assert.fail("Wrong error", e); Assert.assertEquals(loc.getAvailable(), ImmutableSet.of(machine), "Expected location to be available again"); Entities.unmanage(entity); }
Example 6
Source File: LoadBalancingPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups="WIP") public void testRemoveContainerCausesRebalancing() { // Set-up containers and items. MockContainerEntity containerA = newContainer(app, "A", 10, 30); MockContainerEntity containerB = newContainer(app, "B", 10, 30); MockContainerEntity containerC = newContainer(app, "C", 10, 30); MockItemEntity item1 = newItem(app, containerA, "1", 10); MockItemEntity item2 = newItem(app, containerA, "2", 10); MockItemEntity item3 = newItem(app, containerB, "3", 10); MockItemEntity item4 = newItem(app, containerB, "4", 10); MockItemEntity item5 = newItem(app, containerC, "5", 10); MockItemEntity item6 = newItem(app, containerC, "6", 10); Entities.unmanage(containerC); item5.move(containerA); item6.move(containerA); assertWorkratesEventually( ImmutableList.of(containerA, containerB), ImmutableList.of(item1, item2, item3, item4, item5, item6), ImmutableList.of(30d, 30d)); }
Example 7
Source File: ElectPrimaryTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testFailover() throws Exception { Entity app = runSetPreferredViaWeightConfigOnB(); Entity b = (Entity)mgmt().<Entity>lookup(EntityPredicates.displayNameEqualTo("b")); Entities.unmanage(b); EntityAsserts.assertAttributeEventually(app, PRIMARY, EntityPredicates.displayNameEqualTo("a")); }
Example 8
Source File: PortAttributeSensorAndConfigKeyTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected void runStoppingEntityReleasesPortFromLocalhostForReuse(Location loc) throws Exception { MyEntity e1 = app.createAndManageChild(EntitySpec.create(MyEntity.class)); e1.start(ImmutableList.of(loc)); assertEquals(e1.getAttribute(MyEntity.MY_PORT), (Integer)47653); e1.stop(); Entities.unmanage(e1); MyEntity e2 = app.createAndManageChild(EntitySpec.create(MyEntity.class)); e2.start(ImmutableList.of(loc)); assertEquals(e2.getAttribute(MyEntity.MY_PORT), (Integer)47653); }
Example 9
Source File: SoftwareProcessEntityLatchTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** * Deploy a cluster of 4 SoftwareProcesses, which all share the same CountingLatch instance so * that only two can obtain it at a time. The {@link CountingLatch} is configured with a really * long sleep after it acquires the lock, so we should have just 2 entities having acquired it * and the others blocked. * * We assert that we got into this state, and then we tear it down by unmanaging the cluster * (we unmanage because the cluster would otherwise takes ages due to the sleep in * {@link CountingLatch}. */ @Test(dataProvider="latchAndTaskNamesProvider", timeOut=Asserts.THIRTY_SECONDS_TIMEOUT_MS) public void testConcurrencyAllowsExactlyMax(ConfigKey<Boolean> latch, List<String> _ignored) throws Exception { boolean isLatchOnStop = latch.getName().contains("stop"); LocalhostMachineProvisioningLocation loc = app.newLocalhostProvisioningLocation(ImmutableMap.of("address", "127.0.0.1")); final int maxConcurrency = 2; final ReleaseableLatch latchSemaphore = ReleaseableLatch.Factory.newMaxConcurrencyLatch(maxConcurrency); final AttributeSensor<Object> latchSensor = Sensors.newSensor(Object.class, "latch"); final CountingLatch countingLatch = new CountingLatch(latchSemaphore, maxConcurrency, Asserts.DEFAULT_LONG_TIMEOUT.multiply(2)); DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.INITIAL_SIZE, maxConcurrency*2) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(MyService.class) .configure(ConfigKeys.newConfigKey(Object.class, latch.getName()), (Object)DependentConfiguration.attributeWhenReady(app, latchSensor)))); app.sensors().set(latchSensor, countingLatch); try { if (isLatchOnStop) { // Start will complete; then invoke stop async (don't expect it to complete!) app.start(ImmutableList.of(loc)); Entities.invokeEffector(app, app, MyService.STOP, ImmutableMap.<String, Object>of()); } else { // Invoke start async (don't expect it to complete!) Entities.invokeEffector(app, app, MyService.START, ImmutableMap.of("locations", ImmutableList.of(loc))); } // Because CountingLatch waits for ages, we'll eventually have maxConcurrent having successfully // acquired, but the others blocked. Wait for that, and assert it stays that way. countingLatch.assertMaxCounterEventually(Predicates.equalTo(maxConcurrency)); countingLatch.assertMaxCounterContinually(Predicates.equalTo(maxConcurrency), Duration.millis(100)); } finally { // Don't wait for cluster to start/stop (because of big sleep in CountingLatch) - unmanage it. Entities.unmanage(cluster); } }
Example 10
Source File: BrooklynNodeImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public void run() { if (latchTask != null) { latchTask.blockUntilEnded(); } else { log.debug("No latch task provided for UnmanageTask, falling back to fixed wait"); Time.sleep(Duration.FIVE_SECONDS); } synchronized (this) { Entities.unmanage(unmanageEntity); } }
Example 11
Source File: ElectPrimaryTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testSimpleRebind() throws Exception { runSetPreferredViaWeightConfigOnB(); StartableApplication app = rebind(); Assert.assertEquals(app.sensors().get(PRIMARY).getDisplayName(), "b"); Entity a = (Entity)mgmt().<Entity>lookup(EntityPredicates.displayNameEqualTo("a")); Entity b = (Entity)mgmt().<Entity>lookup(EntityPredicates.displayNameEqualTo("b")); a.sensors().set(WEIGHT_SENSOR, 2.0d); Entities.unmanage(b); EntityAsserts.assertAttributeEqualsEventually(app, PRIMARY, a); }
Example 12
Source File: CheckpointEntityTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testAutoCheckpointsOnUnmanageEntity() throws Exception { Entities.unmanage(origE); newApp = rebind(); // Assert does not container unmanaged entity assertEquals(ImmutableList.copyOf(newApp.getChildren()), Collections.emptyList()); assertNull(((EntityInternal)newApp).getManagementContext().getEntityManager().getEntity(origE.getId())); }
Example 13
Source File: UrlMappingTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Test(groups = "Integration") public void testTargetMappingsRemovesUnmanagedMember() { Iterable<StubAppServer> members = Iterables.filter(cluster.getChildren(), StubAppServer.class); assertEquals(Iterables.size(members), 2); StubAppServer target1 = Iterables.get(members, 0); StubAppServer target2 = Iterables.get(members, 1); // First wait for targets to be listed assertExpectedTargetsEventually(members); // Unmanage one member, and expect the URL Mapping to be updated accordingly Entities.unmanage(target1); assertExpectedTargetsEventually(ImmutableSet.of(target2)); }
Example 14
Source File: DynamicWebAppClusterTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Test public void testSetsServiceUpIfMemberIsUp() throws Exception { DynamicWebAppCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicWebAppCluster.class) .configure("initialSize", 1) .configure(ControlledDynamicWebAppCluster.MEMBER_SPEC, EntitySpec.create(TestJavaWebAppEntity.class)) ); app.start(ImmutableList.of(loc)); // Should initially be true (now that TestJavaWebAppEntity sets true) EntityAsserts.assertAttributeEqualsEventually(cluster, DynamicWebAppCluster.SERVICE_UP, true); // When child is !service_up, should report false Iterables.get(cluster.getMembers(), 0).sensors().set(Startable.SERVICE_UP, false); EntityAsserts.assertAttributeEqualsEventually(cluster, DynamicWebAppCluster.SERVICE_UP, false); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", SHORT_WAIT_MS), cluster, DynamicWebAppCluster.SERVICE_UP, false); cluster.resize(2); // When one of the two children is service_up, should report true EntityAsserts.assertAttributeEqualsEventually(cluster, DynamicWebAppCluster.SERVICE_UP, true); // And if that serviceUp child goes away, should again report false Entities.unmanage(Iterables.get(cluster.getMembers(), 1)); Iterables.get(cluster.getMembers(), 0).sensors().set(Startable.SERVICE_UP, false); EntityAsserts.assertAttributeEqualsEventually(cluster, DynamicWebAppCluster.SERVICE_UP, false); }
Example 15
Source File: GroupTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test public void testAddingUnmanagedGroupDoesNotFailBadly() throws Exception { Entities.unmanage(group); entity1.groups().add(group); Entities.unmanage(entity1); }
Example 16
Source File: GroupTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test public void testUnmanagedGroupAutomaticallyRemovedMembers() throws Exception { group.addMember(entity1); Entities.unmanage(group); Asserts.assertEqualsIgnoringOrder(entity1.groups(), ImmutableSet.of()); }
Example 17
Source File: GroupTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test public void testUnmanagedMemberAutomaticallyRemoved() throws Exception { group.addMember(entity1); Entities.unmanage(entity1); assertGroupMembers(new Entity[0]); }
Example 18
Source File: HotStandbyTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test(groups={"Integration", "Broken", "Manual"}) public void testHotStandbyDoesNotLeakBigObjects() throws Exception { log.info("Starting test "+JavaClassNames.niceClassAndMethod()); final int SIZE = 5; final int SIZE_UP_BOUND = SIZE+2; final int SIZE_DOWN_BOUND = SIZE-1; final int GRACE = 2; // the XML persistence uses a lot of space, we approx at between 2x and 3c final int SIZE_IN_XML = 3*SIZE; final int SIZE_IN_XML_DOWN = 2*SIZE; HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER); TestApplication app = createFirstAppAndPersist(n1); noteUsedMemory("Finished seeding"); Long initialUsed = usedMemory.peekLast(); app.config().set(TestEntity.CONF_OBJECT, new BigObject(SIZE*1000*1000)); assertUsedMemoryMaxDelta("Set a big config object", SIZE_UP_BOUND); forcePersistNow(n1); assertUsedMemoryMaxDelta("Persisted a big config object", SIZE_IN_XML); HaMgmtNode n2 = createHotStandby(Duration.PRACTICALLY_FOREVER); forceRebindNow(n2); assertUsedMemoryMaxDelta("Rebinded", SIZE_UP_BOUND); for (int i=0; i<10; i++) forceRebindNow(n2); assertUsedMemoryMaxDelta("Several more rebinds", GRACE); for (int i=0; i<10; i++) { forcePersistNow(n1); forceRebindNow(n2); } assertUsedMemoryMaxDelta("And more rebinds and more persists", GRACE); app.config().set(TestEntity.CONF_OBJECT, "big is now small"); assertUsedMemoryMaxDelta("Big made small at primary", -SIZE_DOWN_BOUND); forcePersistNow(n1); assertUsedMemoryMaxDelta("And persisted", -SIZE_IN_XML_DOWN); forceRebindNow(n2); assertUsedMemoryMaxDelta("And at secondary", -SIZE_DOWN_BOUND); Entities.unmanage(app); forcePersistNow(n1); forceRebindNow(n2); assertUsedMemoryLessThan("And now all unmanaged", initialUsed+GRACE*1000*1000); }
Example 19
Source File: HotStandbyTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
public void doTestHotStandbySeesStructuralChangesIncludingRemoval(boolean immediate) throws Exception { HaMgmtNode n1 = createMaster(immediate ? Duration.PRACTICALLY_FOREVER : Duration.millis(200)); TestApplication app = createFirstAppAndPersist(n1); HaMgmtNode n2 = createHotStandby(immediate ? Duration.PRACTICALLY_FOREVER : Duration.millis(200)); assertEquals(n2.mgmt.getApplications().size(), 1); Application appRO = n2.mgmt.lookup(app.getId(), Application.class); Assert.assertNotNull(appRO); assertEquals(appRO.getChildren().size(), 0); // test additions - new child, new app TestEntity child = app.addChild(EntitySpec.create(TestEntity.class).configure(TestEntity.CONF_NAME, "first-child")); TestApplication app2 = TestApplication.Factory.newManagedInstanceForTests(n1.mgmt); app2.config().set(TestEntity.CONF_NAME, "second-app"); app.sensors().set(TestEntity.SEQUENCE, 4); appRO = expectRebindSequenceNumber(n1, n2, app, 4, immediate); assertEquals(appRO.getChildren().size(), 1); Entity childRO = Iterables.getOnlyElement(appRO.getChildren()); assertEquals(childRO.getId(), child.getId()); assertEquals(childRO.getConfig(TestEntity.CONF_NAME), "first-child"); assertEquals(n2.mgmt.getApplications().size(), 2); Application app2RO = n2.mgmt.lookup(app2.getId(), Application.class); Assert.assertNotNull(app2RO); assertEquals(app2RO.getConfig(TestEntity.CONF_NAME), "second-app"); assertEquals(n2.mgmt.getEntityManager().getEntities().size(), 3); // now test removals Entities.unmanage(child); Entities.unmanage(app2); app.sensors().set(TestEntity.SEQUENCE, 5); appRO = expectRebindSequenceNumber(n1, n2, app, 5, immediate); EntityAsserts.assertAttributeEqualsEventually(appRO, TestEntity.SEQUENCE, 5); assertEquals(n2.mgmt.getEntityManager().getEntities().size(), 1); assertEquals(appRO.getChildren().size(), 0); assertEquals(n2.mgmt.getApplications().size(), 1); Assert.assertNull(n2.mgmt.lookup(app2.getId(), Application.class)); Assert.assertNull(n2.mgmt.lookup(child.getId(), Application.class)); }
Example 20
Source File: GroupTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test public void testAddingUnmanagedMemberDoesNotFailBadly() throws Exception { Entities.unmanage(entity1); group.addMember(entity1); Entities.unmanage(group); }