@Override public void unmanage(Location loc) { if (isInitialManagementContextReal()) { initialManagementContext.getLocationManager().unmanage(loc); } else { throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation: cannot unmanage "+loc); } }
public static void unmanage(Location loc) { if (isManaged(loc)) { ManagementContext mgmt = ((LocationInternal)loc).getManagementContext(); mgmt.getLocationManager().unmanage(loc); } }
public boolean removeChild(Location child) { boolean removed; synchronized (children) { removed = children.remove(child); } if (removed) { if (child instanceof Closeable) { Streams.closeQuietly((Closeable)child); } child.setParent(null); if (isManaged() && Locations.isManaged(child)) { // This is called as part of child's LocalLocationManager.unmanage; don't try to // unmanage it yet again as then would get a log.warn! getManagementContext().getLocationManager().unmanage(child); } } onChanged(); return removed; }
@Override public void deleteLocation() { DockerContainerLocation location = getDynamicLocation(); if (location != null) { try { location.close(); } catch (IOException ioe) { LOG.debug("Error closing container location", ioe); } LocationManager mgr = getManagementContext().getLocationManager(); if (mgr.isManaged(location)) { mgr.unmanage(location); } } sensors().set(DYNAMIC_LOCATION, null); sensors().set(LOCATION_NAME, null); }
@Override public void deleteLocation() { LocationManager mgr = getManagementContext().getLocationManager(); ServerPoolLocation location = getDynamicLocation(); if (location != null && mgr.isManaged(location)) { LOG.debug("{} deleting and unmanaging location {}", this, location); location.deregister(); mgr.unmanage(location); } sensors().set(LOCATION_SPEC, null); sensors().set(DYNAMIC_LOCATION, null); sensors().set(LOCATION_NAME, null); }
@Override public void deleteLocation() { MarathonTaskLocation location = getDynamicLocation(); if (location != null) { LocationManager mgr = getManagementContext().getLocationManager(); if (mgr.isManaged(location)) { mgr.unmanage(location); } } sensors().set(DYNAMIC_LOCATION, null); sensors().set(LOCATION_NAME, null); }
@Test public void testRestoresEntityLocationAndCleansUp() throws Exception { MyEntity child = origApp.createAndManageChild(EntitySpec.create(MyEntity.class).location(LocationSpec.create(MyLocation.class))); Location loc = Iterables.getOnlyElement(child.getLocations()); newApp = rebind(); MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class)); Assert.assertEquals(newE.getLocations().size(), 1); Location loc2 = Iterables.getOnlyElement(newE.getLocations()); Assert.assertEquals(loc, loc2); Assert.assertFalse(loc==loc2); newApp.stop(); // TODO how to trigger automatic unmanagement? see notes in RebindLocalhostLocationTest newManagementContext.getLocationManager().unmanage(loc2); switchOriginalToNewManagementContext(); RebindTestUtils.waitForPersisted(origManagementContext); BrooklynMementoManifest mf = loadMementoManifest(); Assert.assertTrue(mf.getLocationIdToType().isEmpty(), "Expected no locations; had "+mf.getLocationIdToType()); }
@Override public void deleteLocation() { StubContainerLocation location = getDynamicLocation(); if (location != null) { try { location.close(); } catch (IOException ioe) { LOG.debug("Error closing container location", ioe); } LocationManager mgr = getManagementContext().getLocationManager(); if (mgr.isManaged(location)) { mgr.unmanage(location); } } sensors().set(DYNAMIC_LOCATION, null); sensors().set(LOCATION_NAME, null); } }
@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)); }
@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 testManagedLocationsCreateAndCleanup() { assertLocationRegistryCount(0); assertLocationManagerInstancesCount(0); assertCatalogCount(0); String symbolicName = "lh1"; addCatalogLocation(symbolicName, LOCALHOST_LOCATION_TYPE, null); assertLocationRegistryCount(1); assertCatalogCount(1); assertLocationManagerInstancesCount(0); Location loc = mgmt().getLocationRegistry().getLocationManaged("lh1"); assertLocationRegistryCount(1); assertCatalogCount(1); assertLocationManagerInstancesCount(1); mgmt().getLocationManager().unmanage(loc); assertLocationRegistryCount(1); assertCatalogCount(1); assertLocationManagerInstancesCount(0); deleteCatalogEntity("lh1"); assertLocationRegistryCount(0); assertCatalogCount(0); assertLocationManagerInstancesCount(0); }