@Override public Collection<Location> getLocations() { if (isInitialManagementContextReal()) { return initialManagementContext.getLocationManager().getLocations(); } else { return Collections.emptyList(); } }
private Optional<Location> findPortForwardManager(ManagementContext mgmt, String scope) { return Iterables.tryFind(mgmt.getLocationManager().getLocations(), Predicates.and( Predicates.instanceOf(PortForwardManager.class), LocationPredicates.configEqualTo(PortForwardManager.SCOPE, scope))); }
@Test public void testRebindWhenOnlyByonLocationSpec() throws Exception { int before = mgmt().getLocationManager().getLocations().size(); String spec = "byon(hosts=\"1.1.1.1\")"; getLocationSpec(spec); rebind(); int after = mgmt().getLocationManager().getLocations().size(); assertEquals(after, before); }
@Test public void testRebindWhenOnlyByonLocationSpec() throws Exception { int before = mgmt().getLocationManager().getLocations().size(); getLocationSpec("localhost"); rebind(); int after = mgmt().getLocationManager().getLocations().size(); assertEquals(after, before); }
for (Location loc : mgmt.getLocationManager().getLocations()) { destroyCatching(loc);
@Test public void testManagedLocationsSimpleCreateAndCleanup() { Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); Location loc = mgmt.getLocationRegistry().getLocationManaged("localhost"); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(1)); mgmt.getLocationManager().unmanage(loc); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); }
if (!managementContext.getEntityManager().getEntities().isEmpty() || !managementContext.getLocationManager().getLocations().isEmpty()) { LOG.warn("Rebind requested for "+mode+" node "+managementContext.getManagementNodeId()+" " + "when it already has active state; discouraged, " + "will likely overwrite: "+managementContext.getEntityManager().getEntities()+" and "+managementContext.getLocationManager().getLocations()+" and more");
private void testLocationUnmanagedOnStop(LocationSpec<? extends Location> locationSpec) { EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class) .location(locationSpec); BasicApplication app = mgmt.getEntityManager().createEntity(appSpec); app.start(ImmutableList.<Location>of()); Location appLocation = Iterables.getOnlyElement(app.getLocations()); NamedStringTag ownerEntityTag = BrooklynTags.findFirst(BrooklynTags.OWNER_ENTITY_ID, appLocation.tags().getTags()); Assert.assertNotNull(ownerEntityTag); Assert.assertEquals(ownerEntityTag.getContents(), app.getId()); app.stop(); Assert.assertFalse(mgmt.getEntityManager().isManaged(app)); Set<Location> locs = ImmutableSet.copyOf(mgmt.getLocationManager().getLocations()); Assert.assertFalse(locs.contains(appLocation), locs + " should not contain " + appLocation); }
private void assertLocationManagerInstancesCount(int size) { Asserts.assertThat(mgmt().getLocationManager().getLocations(), CollectionFunctionals.sizeEquals(size)); } private void assertCatalogCount(int size) {
Location restoredLoc = Iterables.getOnlyElement(lastMgmt().getLocationManager().getLocations()); assertEquals(restoredApp.getId(), appToKeep.get().getId()); assertEquals(restoredLoc.getId(), locToKeep.get().getId());
private void testLocationUnmanagedOnStop(LocationSpec<? extends Location> locationSpec) { EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class) .location(locationSpec) .child(EntitySpec.create(EmptySoftwareProcess.class) .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, Boolean.TRUE) .configure(EmptySoftwareProcess.USE_SSH_MONITORING, Boolean.FALSE)); BasicApplication app = mgmt.getEntityManager().createEntity(appSpec); Entity child = Iterables.getOnlyElement(app.getChildren()); Assert.assertEquals(child.getLocations(), ImmutableList.of()); app.start(ImmutableList.<Location>of()); Location appLocation = Iterables.getOnlyElement(app.getLocations()); assertOwned(app, appLocation); Location entityLocation = Iterables.getOnlyElement(child.getLocations()); // No owner tag because it's created by SoftwareProcess, not by Brooklyn internals assertNotOwned(entityLocation); app.stop(); Assert.assertEquals(child.getLocations(), ImmutableList.of()); Assert.assertFalse(mgmt.getEntityManager().isManaged(child)); Assert.assertFalse(mgmt.getEntityManager().isManaged(app)); Set<Location> locs = ImmutableSet.copyOf(mgmt.getLocationManager().getLocations()); Assert.assertFalse(locs.contains(entityLocation), locs + " should not contain " + entityLocation); Assert.assertFalse(locs.contains(appLocation), locs + " should not contain " + appLocation); }
Assert.assertTrue(n1.mgmt.getApplications().isEmpty(), "n1 should have had no apps; instead had: "+n1.mgmt.getApplications()); Assert.assertTrue(n1.mgmt.getEntityManager().getEntities().isEmpty(), "n1 should have had no entities; instead had: "+n1.mgmt.getEntityManager().getEntities()); Assert.assertTrue(n1.mgmt.getLocationManager().getLocations().isEmpty(), "n1 should have had no locations; instead had: "+n1.mgmt.getLocationManager().getLocations()); Assert.assertFalse(n1.mgmt.getLocationManager().getLocations().isEmpty(), "n1 should have had locations now");
/** clears all managed items from the management context; same items destroyed as in the course of a rebind cycle */ protected void clearManagedItems(ManagementTransitionMode mode) { // start with the root applications for (Application app: managementContext.getApplications()) { if (((EntityInternal)app).getManagementSupport().isDeployed()) { ((LocalEntityManager)((EntityInternal)app).getManagementContext().getEntityManager()).unmanage(app, mode); } } // for active management, call above will remove recursively at present, // but for read-only, and if we stop recursively, go through them all for (Entity entity: managementContext.getEntityManager().getEntities()) { ((LocalEntityManager)managementContext.getEntityManager()).unmanage(entity, mode); } // again, for locations, call unmanage on parents first for (Location loc: managementContext.getLocationManager().getLocations()) { if (loc.getParent()==null) ((LocationManagerInternal)managementContext.getLocationManager()).unmanage(loc, mode); } for (Location loc: managementContext.getLocationManager().getLocations()) { ((LocationManagerInternal)managementContext.getLocationManager()).unmanage(loc, mode); } ((BasicBrooklynCatalog)managementContext.getCatalog()).reset(CatalogDto.newEmptyInstance("<reset-by-ha-status-change>")); }
Collection<Location> le = entity.getLocations(); log.info("Locs at entity are: "+le); Collection<Location> lm = managementContext.getLocationManager().getLocations(); log.info("Locs managed are: "+lm); log.info(" objs: "+identities(lm)); Collection<Location> llmm = managementContext.getLocationManager().getLocations(); log.info("Locs managed are: "+llmm); log.info(" objs: "+identities(llmm));
@Test public void testManagedLocationsNamedCreateAndCleanup() { Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(0)); Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); mgmt.getLocationRegistry().updateDefinedLocationNonPersisted( new BasicLocationDefinition("lh1", "localhost", null) ); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); // currently such defined locations do NOT appear in catalog -- see CatalogYamlLocationTest Asserts.assertThat(mgmt.getCatalog().getCatalogItems(), CollectionFunctionals.sizeEquals(0)); Location loc = mgmt.getLocationRegistry().getLocationManaged("lh1"); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(1)); mgmt.getLocationManager().unmanage(loc); Asserts.assertThat(mgmt.getLocationRegistry().getDefinedLocations(true).keySet(), CollectionFunctionals.sizeEquals(1)); Asserts.assertThat(locationManager.getLocations(), CollectionFunctionals.sizeEquals(0)); }
@Test public void testLocationManagementAllowed() throws Exception { // default is allowed Location loc1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); // when forbidden, should give error mgmt.getAccessManager().setLocationManagementAllowed(false); try { mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); fail(); } catch (Exception e) { // expect it to be forbidden if (Exceptions.getFirstThrowableOfType(e, IllegalStateException.class) == null) { throw e; } } // but when forbidden, still allowed to create entity mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)); // when re-enabled, can create entities again mgmt.getAccessManager().setLocationManagementAllowed(true); Location loc3 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class)); assertEquals(ImmutableSet.copyOf(mgmt.getLocationManager().getLocations()), ImmutableSet.of(loc1, loc3)); }
for (Location instance: mgmt.getLocationManager().getLocations()) result.location(instance.getId(), serializer.toString(newObjectMemento(instance))); for (Entity instance: mgmt.getEntityManager().getEntities()) {
newManagementContext = newApp.getManagementContext(); MultiLocation<?> newMultiLoc = (MultiLocation<?>) Iterables.find(newManagementContext.getLocationManager().getLocations(), Predicates.instanceOf(MultiLocation.class)); AvailabilityZoneExtension azExtension = newMultiLoc.getExtension(AvailabilityZoneExtension.class); List<Location> newSublLocs = azExtension.getAllSubLocations();
/** * Walks the contents of a ManagementContext, to create a corresponding memento. */ protected static BrooklynMemento newBrooklynMemento(ManagementContext managementContext) { BrooklynMementoImpl.Builder builder = BrooklynMementoImpl.builder(); for (Application app : managementContext.getApplications()) { builder.applicationId(app.getId()); } for (Entity entity : managementContext.getEntityManager().getEntities()) { builder.entity(((EntityInternal)entity).getRebindSupport().getMemento()); } for (Location location : managementContext.getLocationManager().getLocations()) { builder.location(((LocationInternal)location).getRebindSupport().getMemento()); if (location.getParent() == null) { builder.topLevelLocationId(location.getId()); } } BrooklynMemento result = builder.build(); MementoValidators.validateMemento(result); return result; } }