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

x33g5p2x  于2022-01-19 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(170)

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

Entity.getLocations介绍

[英]Return all the Locations this entity is deployed to.
[中]返回此实体部署到的所有位置。

代码示例

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

@Override
  public boolean apply(@Nullable Entity input) {
    return (input != null) && input.getLocations().contains(location);
  }
};

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

@Override
public boolean apply(@Nullable Entity input) {
  return (input != null) && condition.apply(input.getLocations());
}
@Override

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

protected Multimap<Location, Entity> getMembersByLocation() {
  Multimap<Location, Entity> result = LinkedHashMultimap.create();
  for (Entity member : getMembers()) {
    Collection<Location> memberLocs = member.getLocations();
    Location memberLoc = Iterables.getFirst(memberLocs, null);
    if (memberLoc != null) {
      result.put(memberLoc, member);
    }
  }
  return result;
}

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

public static HostGeoInfo fromEntity(Entity e) {
  for (Location l : e.getLocations()) {
    HostGeoInfo hgi = fromLocation(l);
    if (hgi != null)
      return hgi;
  }
  return null;
}

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

/** unsubmitted task for starting children of the given entity at the same location as the entity */
public static TaskAdaptable<?> startingChildren(Entity entity) {
  return startingChildren(entity, entity.getLocations());
}
/** unsubmitted task for starting children of the given entity at the given location */

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

/** if no locations are supplied, returns locations on the entity, or in the ancestors, until it finds a non-empty set,
 * or ultimately the empty set if no locations are anywhere */ 
public static Collection<? extends Location> getLocationsCheckingAncestors(Collection<? extends Location> locations, Entity entity) {
  // look in ancestors if location not set here
  Entity ancestor = entity;
  while ((locations==null || locations.isEmpty()) && ancestor!=null) {
    locations = ancestor.getLocations();
    ancestor = ancestor.getParent();
  }
  return locations;
}

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

/** Finds a unique {@link MachineLocation} attached to the supplied entity
 * @throws IllegalStateException if there is not a unique such {@link SshMachineLocation} */
public static <T extends MachineLocation> T getMachine(Entity entity, Class<T> clazz) {
  try {
    return Machines.findUniqueMachineLocation(entity.getLocations(), clazz).get();
  } catch (Exception e) {
    throw new IllegalStateException("Entity "+entity+" (in "+Tasks.current()+") requires a single " + clazz.getName() + ", but has "+entity.getLocations(), e);
  }
}

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

public static Set<Location> getAllInheritedLocations(Entity entity) {
  Set<Location> result = MutableSet.of();
  while (entity!=null) {
    result.addAll(entity.getLocations());
    entity = entity.getParent();
  }
  return result;
}

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

protected List<Location> getLocationsOf(Iterable<? extends Entity> entities, Predicate<? super Location> filter) {
  List<Location> result = Lists.newArrayList();
  for (Entity entity : entities) {
    Iterables.addAll(result, Iterables.filter(entity.getLocations(), filter));
  }
  return result;
}

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

protected List<Location> getLocationsOf(Iterable<? extends Entity> entities) {
  List<Location> result = Lists.newArrayList();
  for (Entity entity : entities) {
    result.add(Iterables.getOnlyElement(entity.getLocations()));
  }
  return result;
}

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

public static Maybe<String> findSubnetIp(Entity entity) {
  String sh = entity.getAttribute(Attributes.SUBNET_ADDRESS);
  if (sh!=null) return Maybe.of(sh);
  return findSubnetIp(entity.getLocations());
}

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

public static Maybe<String> findSubnetHostname(Entity entity) {
  String sh = entity.getAttribute(Attributes.SUBNET_HOSTNAME);
  if (sh!=null) return Maybe.of(sh);
  return findSubnetHostname(entity.getLocations());
}

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

@Override
public List<LocationSummary> getLocations(String application, String entity) {
  List<LocationSummary> result = Lists.newArrayList();
  Entity e = brooklyn().getEntity(application, entity);
  for (Location l : e.getLocations()) {
    result.add(LocationTransformer.newInstance(mgmt(), l, LocationDetailLevel.NONE, ui.getBaseUriBuilder()));
  }
  return result;
}

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

@Test
public void testLocationString() throws Exception {
  String yaml = 
      "location: localhost\n"+
      "services:\n"+
      "- type: org.apache.brooklyn.core.test.entity.TestEntity\n";
  
  Entity app = createStartWaitAndLogApplication(yaml);
  LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(app.getLocations());
  assertNotNull(loc);
}

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

@Test
public void testLocationComplexString() throws Exception {
  String yaml = 
      "location: localhost:(name=myname)\n"+
      "services:\n"+
      "- type: org.apache.brooklyn.core.test.entity.TestEntity\n";
  
  Entity app = createStartWaitAndLogApplication(yaml);
  LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(app.getLocations());
  assertEquals(loc.getDisplayName(), "myname");
}

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

@Test
public void testPrefersMemberSpecLocation() throws Exception {
  @SuppressWarnings("deprecation")
  DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
      .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)
          .location(loc2))
      .configure(DynamicCluster.INITIAL_SIZE, 1));
  
  cluster.start(ImmutableList.of(loc));
  assertEquals(ImmutableList.copyOf(cluster.getLocations()), ImmutableList.of(loc));
  
  Entity member = Iterables.getOnlyElement(cluster.getMembers());
  assertEquals(ImmutableList.copyOf(member.getLocations()), ImmutableList.of(loc2));
}

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

@Test
public void testDeferredDslObjectAsFirstArgument() throws Exception {
  final Entity app = createAndStartApplication(
      "services:",
      "- type: " + BasicApplication.class.getName(),
      "  location: localhost",
      "  brooklyn.config:",
      "    dest: $brooklyn:attributeWhenReady(\"targetValue\").config(\"spec.final\")");
  AttributeSensor<Location> targetValueSensor = Sensors.newSensor(Location.class, "targetValue");
  app.sensors().set(targetValueSensor, Iterables.getOnlyElement(app.getLocations()));
  assertEquals(getConfigEventually(app, DEST), "localhost");
}

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

@Test
public void testLocationConfig() throws Exception {
  String yaml = 
      "location:\n"+
      "  localhost:\n"+
      "    displayName: myname\n"+
      "    myconfkey: myconfval\n"+
      "services:\n"+
      "- type: org.apache.brooklyn.core.test.entity.TestEntity\n";
  
  Entity app = createStartWaitAndLogApplication(yaml);
  LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(app.getLocations());
  assertEquals(loc.getDisplayName(), "myname");
  assertEquals(loc.config().getLocalBag().getStringKey("myconfkey"), "myconfval");
}

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

private Collection<String> locationsToAddresses(int port, Collection<Entity> entities) {
  Set<String> result = MutableSet.of();
  for (Entity e : entities) {
    SshMachineLocation machine = Machines.findUniqueMachineLocation(e.getLocations(), SshMachineLocation.class).get();
    result.add(machine.getAddress().getHostName()+":"+port);
  }
  return result;
}

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

public void testMySqlOnProvisioningLocation() throws Exception {
  Entity mysql = createMysql();
  app.start(MutableList.of(targetLocation));
  checkStartsRunning(mysql);
  checkIsRunningAndStops(mysql, (SshMachineLocation) Iterables.getOnlyElement( mysql.getLocations() ));
}

相关文章