本文整理了Java中org.apache.brooklyn.api.mgmt.LocationManager
类的一些代码示例,展示了LocationManager
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager
类的具体详情如下:
包路径:org.apache.brooklyn.api.mgmt.LocationManager
类名称:LocationManager
[英]For managing and querying entities.
[中]用于管理和查询实体。
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
protected SshMachineLocation createMachine(String addr) {
if (lm==null)
return new SshMachineLocation(makeConfig(addr));
else
return lm.createLocation(makeConfig(addr), SshMachineLocation.class);
}
private Map makeConfig(String address) {
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testCreateLocationUsingSpec() {
SshMachineLocation loc = locationManager.createLocation(LocationSpec.create(SshMachineLocation.class)
.configure("address", "1.2.3.4"));
assertEquals(loc.getAddress().getHostAddress(), "1.2.3.4");
assertSame(locationManager.getLocation(loc.getId()), loc);
}
代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-mesos
@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);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/**
* Registers the given location (and all its children) with the management context.
* @throws IllegalStateException if the parent location is not already managed
*
* @since 0.6.0 (added only for backwards compatibility, where locations are being created directly; previously in {@link Entities}).
* @deprecated in 0.6.0; use {@link LocationManager#createLocation(LocationSpec)} instead.
*/
@Deprecated
public static void manage(Location loc, ManagementContext managementContext) {
if (!managementContext.getLocationManager().isManaged(loc)) {
log.warn("Deprecated use of unmanaged location ("+loc+"); will be managed automatically now but not supported in future versions");
// FIXME this occurs MOST OF THE TIME e.g. including BrooklynLauncher.location(locationString)
// not sure what is the recommend way to convert from locationString to locationSpec, or the API we want to expose;
// deprecating some of the LocationRegistry methods seems sensible?
log.debug("Stack trace for location of: Deprecated use of unmanaged location; will be managed automatically now but not supported in future versions", new Exception("TRACE for: Deprecated use of unmanaged location"));
managementContext.getLocationManager().manage(loc);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override protected Location getInstanceFromId(String id) { return mgmt.getLocationManager().getLocation(id); }
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@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));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-webapp
@BeforeMethod(alwaysRun=true)
@Override
public void setUp() throws Exception {
super.setUp();
EntitySpec<StubAppServer> serverSpec = EntitySpec.create(StubAppServer.class);
cluster = app().createAndManageChild(EntitySpec.create(DynamicCluster.class)
.configure(DynamicCluster.INITIAL_SIZE, initialClusterSize)
.configure(DynamicCluster.MEMBER_SPEC, serverSpec));
urlMapping = app().createAndManageChild(EntitySpec.create(UrlMapping.class)
.configure("domain", "localhost")
.configure("target", cluster));
app().start( ImmutableList.of(
mgmt().getLocationManager().createLocation(
LocationSpec.create(LocalhostMachineProvisioningLocation.class))
));
log.info("app's location managed: "+mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(app().getLocations())));
log.info("clusters's location managed: "+mgmt().getLocationManager().isManaged(Iterables.getOnlyElement(cluster.getLocations())));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@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));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@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);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public Collection<Location> getLocations() {
if (isInitialManagementContextReal()) {
return initialManagementContext.getLocationManager().getLocations();
} else {
return Collections.emptyList();
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
public static boolean isManaged(Location loc) {
ManagementContext mgmt = ((LocationInternal)loc).getManagementContext();
return (mgmt != null) && mgmt.isRunning() && mgmt.getLocationManager().isManaged(loc);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
@Deprecated
public Location manage(Location loc) {
if (isInitialManagementContextReal()) {
return initialManagementContext.getLocationManager().manage(loc);
} else {
throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation: cannot manage "+loc);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
@SuppressWarnings("unchecked")
public <T extends BrooklynObject> T lookup(String id, Class<T> type) {
Object result;
result = getEntityManager().getEntity(id);
if (result!=null && type.isInstance(result)) return (T)result;
result = getLocationManager().getLocation(id);
if (result!=null && type.isInstance(result)) return (T)result;
// TODO policies, enrichers, feeds; bundles?
return null;
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testChangeModeToDisabledAndBack() throws Exception {
HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER);
n1.mgmt.getLocationManager().createLocation(LocationSpec.create(LocalhostMachine.class));
@SuppressWarnings("unused")
TestApplication app = createFirstAppAndPersist(n1);
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");
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@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));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
public static void unmanage(Location loc) {
if (isManaged(loc)) {
ManagementContext mgmt = ((LocationInternal)loc).getManagementContext();
mgmt.getLocationManager().unmanage(loc);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
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)));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Override
public void reloaded() {
Location resolved = context.getLocationRegistry().resolve(definition);
context.getLocationRegistry().updateDefinedLocation(definition);
context.getLocationManager().manage(resolved);
}
};
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override @Deprecated
public Maybe<Location> resolve(String spec, Boolean manage, Map locationFlags) {
if (manage!=null) {
locationFlags = MutableMap.copyOf(locationFlags);
locationFlags.put(LocalLocationManager.CREATE_UNMANAGED, !manage);
}
Maybe<LocationSpec<? extends Location>> lSpec = getLocationSpec(spec, locationFlags);
if (lSpec.isAbsent()) return (Maybe)lSpec;
return Maybe.of((Location)mgmt.getLocationManager().createLocation(lSpec.get()));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test
public void testFlagFieldsNotReturnedInConfig() throws Exception {
MyLocation origLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(MyLocation.class));
origLoc.myfield = "myval";
origLoc.requestPersist();
// Check (before rebind) that the 'myfield' isn't also in the config
assertNull(origLoc.config().getBag().getStringKey("myfield"));
// Check after rebind that we are the same: 'myfield' isn't also in the config
rebind();
MyLocation newLoc = (MyLocation) mgmt().getLocationManager().getLocation(origLoc.getId());
assertEquals(newLoc.myfield, "myval");
assertNull(newLoc.config().getBag().getStringKey("myfield"));
}
内容来源于网络,如有侵权,请联系作者删除!