org.apache.brooklyn.api.mgmt.LocationManager.getLocations()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(100)

本文整理了Java中org.apache.brooklyn.api.mgmt.LocationManager.getLocations()方法的一些代码示例,展示了LocationManager.getLocations()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocationManager.getLocations()方法的具体详情如下:
包路径:org.apache.brooklyn.api.mgmt.LocationManager
类名称:LocationManager
方法名:getLocations

LocationManager.getLocations介绍

[英]All locations under control of this management plane. This returns a snapshot of the current locations; it will not reflect future changes in the locations. If no locations are found, the collection will be empty (i.e. null is never returned).
[中]此管理平面控制下的所有位置。这将返回当前位置的快照;它不会反映位置的未来变化。如果未找到任何位置,则集合将为空(即从不返回null)。

代码示例

代码示例来源: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

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-core

@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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Test
public void testRebindWhenOnlyByonLocationSpec() throws Exception {
  int before = mgmt().getLocationManager().getLocations().size();
  getLocationSpec("localhost");
  
  rebind();
  int after = mgmt().getLocationManager().getLocations().size();
  assertEquals(after, before);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

for (Location loc : mgmt.getLocationManager().getLocations()) {
  destroyCatching(loc);

代码示例来源: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

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");

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-camp

private void assertLocationManagerInstancesCount(int size) {
  Asserts.assertThat(mgmt().getLocationManager().getLocations(), CollectionFunctionals.sizeEquals(size));
}
private void assertCatalogCount(int size) {

代码示例来源:origin: org.apache.brooklyn/brooklyn-launcher

Location restoredLoc = Iterables.getOnlyElement(lastMgmt().getLocationManager().getLocations());
assertEquals(restoredApp.getId(), appToKeep.get().getId());
assertEquals(restoredLoc.getId(), locToKeep.get().getId());

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

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);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

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

/** 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>"));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

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));

代码示例来源: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

@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-core

for (Location instance: mgmt.getLocationManager().getLocations())
  result.location(instance.getId(), serializer.toString(newObjectMemento(instance)));
for (Entity instance: mgmt.getEntityManager().getEntities()) {

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

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();

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/**
   * 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;
  }
}

相关文章