Java Code Examples for org.apache.brooklyn.core.location.Locations#unmanage()

The following examples show how to use org.apache.brooklyn.core.location.Locations#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: StubHostLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void release(StubContainerLocation machine) {
    DynamicCluster cluster = dockerHost.getDockerContainerCluster();
    StubContainer container = machine.getOwner();
    if (cluster.removeMember(container)) {
        LOG.info("Docker Host {}: member {} released", dockerHost, machine);
    } else {
        LOG.warn("Docker Host {}: member {} not found for release", dockerHost, machine);
    }

    // Now close and unmange the container
    try {
        container.stop();
        machine.close();
    } catch (Exception e) {
        LOG.warn("Error stopping container: " + container, e);
        Exceptions.propagateIfFatal(e);
    } finally {
        Entities.unmanage(container);
        Locations.unmanage(machine);
    }
}
 
Example 2
Source File: RebindPolicyTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpungesOnEntityUnmanaged() throws Exception {
    Location loc = origManagementContext.getLocationRegistry().getLocationManaged("localhost");
    TestEntity entity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class));
    MyPolicy policy = entity.policies().add(PolicySpec.create(MyPolicy.class));
    MyEnricher enricher = entity.enrichers().add(EnricherSpec.create(MyEnricher.class));

    RebindTestUtils.waitForPersisted(origApp);

    Entities.unmanage(entity);
    Locations.unmanage(loc);
    RebindTestUtils.stopPersistence(origApp);
    
    BrooklynMementoManifest manifest = loadMementoManifest();
    assertFalse(manifest.getEntityIdToManifest().containsKey(entity.getId()));
    assertFalse(manifest.getPolicyIdToType().containsKey(policy.getId()));
    assertFalse(manifest.getEnricherIdToType().containsKey(enricher.getId()));
    assertFalse(manifest.getLocationIdToType().containsKey(loc.getId()));
}
 
Example 3
Source File: JcloudsAddressesLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void assertReachability(boolean expectedReachable, SshMachineLocation machine, String addr, String msg) {
    SshMachineLocation tmpMachine = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
            .configure(machine.config().getBag().getAllConfig())
            .configure("address", addr));
    try {
        boolean sshable = tmpMachine.isSshable();
        assertEquals(sshable, expectedReachable, addr+" not sshable; "+msg);
    } finally {
        Locations.unmanage(tmpMachine);
    }
}
 
Example 4
Source File: JcloudsSuseLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void assertSshable(Map<?,?> machineConfig) {
    SshMachineLocation machineWithThatConfig = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
            .configure(machineConfig));
    try {
        assertSshable(machineWithThatConfig);
    } finally {
        Streams.closeQuietly(machineWithThatConfig);
        Locations.unmanage(machineWithThatConfig);
    }
}
 
Example 5
Source File: AbstractJcloudsStubbedLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected JcloudsLocation replaceJcloudsLocation(String locationSpec) {
    if (machines != null && machines.size() > 0) {
        throw new IllegalStateException("Cannot replace jcloudsLocation after provisioning machine with old one");
    }
    if (jcloudsLocation != null) {
        Locations.unmanage(jcloudsLocation);
    }
    jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged(
            locationSpec,
            jcloudsLocationConfig(ImmutableMap.<Object, Object>of(
                    JcloudsLocationConfig.COMPUTE_SERVICE_REGISTRY, computeServiceRegistry,
                    JcloudsLocationConfig.WAIT_FOR_SSHABLE, "false",
                    JcloudsLocationConfig.POLL_FOR_FIRST_REACHABLE_ADDRESS, "false")));
    return jcloudsLocation;
}
 
Example 6
Source File: CleanOrphanedLocationsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandlesDanglingReference() throws Exception {
    SshMachineLocation todelete = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class));
    SshMachineLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class));
    origApp.addLocations(ImmutableList.of(todelete));
    origApp.sensors().set(Sensors.newSensor(Object.class, "mysensor"), loc);
    origApp.config().set(ConfigKeys.newConfigKey(Object.class, "myconfig"), loc);
    origApp.tags().addTag(loc);
    loc.config().set(ConfigKeys.newConfigKey(Object.class, "myconfig"), todelete);
    
    Locations.unmanage(todelete);
    assertFalse(getRawData().getLocations().containsKey(todelete.getId()));

    assertTransformIsNoop();
}
 
Example 7
Source File: CleanOrphanedLocationsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandlesDanglingReferencesInLocationListSurroundingValidReference() throws Exception {
    SshMachineLocation todelete = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class));
    SshMachineLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class));
    SshMachineLocation todelete2 = mgmt().getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class));
    origApp.addLocations(ImmutableList.of(todelete, loc, todelete2));
    Locations.unmanage(todelete);

    assertTransformIsNoop();
}
 
Example 8
Source File: BrooklynNodeIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private boolean isPidRunning(File pidFile) throws Exception {
    SshMachineLocation machine = loc.obtain();
    try {
        int result = machine.execScript("check-pid", ImmutableList.of(
                "test -f "+pidFile+" || exit 1",
                "ps -p `cat "+pidFile+"`"));
        return result == 0;
    } finally {
        loc.release(machine);
        Locations.unmanage(machine);
    }
}
 
Example 9
Source File: StubInfrastructureImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteLocation() {
    StubInfrastructureLocation location = getDynamicLocation();

    if (location != null) {
        location.deregister();
        Locations.unmanage(location);
    }

    sensors().set(LocationOwner.DYNAMIC_LOCATION, null);
    sensors().set(LocationOwner.LOCATION_NAME, null);
}
 
Example 10
Source File: StubHostImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteLocation() {
    StubHostLocation loc = (StubHostLocation) sensors().get(DYNAMIC_LOCATION);
    if (loc != null) {
        loc.deregister();
        Locations.unmanage(loc);
    }
    sensors().set(DYNAMIC_LOCATION, null);
    sensors().set(LOCATION_NAME, null);
}
 
Example 11
Source File: DynamicClusterWithAvailabilityZonesRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testRebindWithDefaultZoneFailureDetector() throws Exception {
    // Start and then unmanage a cluster (so it's detector was populated).
    // Do this in case the ZoneFailureDetector is shared!
    SimulatedLocation loc = mgmt().getLocationManager().createLocation(LocationSpec.create(SimulatedLocationWithZoneExtension.class)
            .configure(SimulatedLocationWithZoneExtension.ZONE_NAMES, ImmutableList.of("zone1", "zone2"))
            .configure(SimulatedLocationWithZoneExtension.ZONE_FAIL_CONDITIONS, ImmutableMap.of("zone1", Predicates.alwaysTrue())));

    DynamicCluster cluster = app().addChild(EntitySpec.create(DynamicCluster.class)
            .configure(DynamicCluster.ENABLE_AVAILABILITY_ZONES, true)
            .configure(DynamicCluster.INITIAL_SIZE, 2)
            .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
    
    cluster.start(ImmutableList.of(loc));
    
    Entities.unmanage(cluster);
    Locations.unmanage(loc);

    // Start a second cluster
    SimulatedLocation locUnrelated = mgmt().getLocationManager().createLocation(LocationSpec.create(SimulatedLocationWithZoneExtension.class)
            .configure(SimulatedLocationWithZoneExtension.ZONE_NAMES, ImmutableList.of("zone3", "zone4"))
            .configure(SimulatedLocationWithZoneExtension.ZONE_FAIL_CONDITIONS, ImmutableMap.of("zone3", Predicates.alwaysTrue())));
    
    DynamicCluster clusterUnrelated = app().addChild(EntitySpec.create(DynamicCluster.class)
            .configure(DynamicCluster.ENABLE_AVAILABILITY_ZONES, true)
            .configure(DynamicCluster.INITIAL_SIZE, 2)
            .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
    clusterUnrelated.start(ImmutableList.of(locUnrelated));
    
    rebind();
    
    // Confirm that cluster is usable
    DynamicCluster newClusterUnrelated = (DynamicCluster) mgmt().getEntityManager().getEntity(clusterUnrelated.getId());
    newClusterUnrelated.resize(4);
}
 
Example 12
Source File: LocationPredicatesTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testManaged() throws Exception {
    // TODO get exception in LocalhostMachineProvisioningLocation.removeChild because childLoc is "in use";
    // this happens from the call to unmanage(loc), which first unmanaged the children.
    loc.release(childLoc);
    
    assertTrue(LocationPredicates.managed().apply(loc));
    Locations.unmanage(loc);
    assertFalse(LocationPredicates.managed().apply(loc));
}