@Override public boolean apply(@Nullable Entity input) { return (input != null) && input.getLocations().contains(location); } };
@Override public boolean apply(@Nullable Entity input) { return (input != null) && condition.apply(input.getLocations()); } @Override
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; }
public static HostGeoInfo fromEntity(Entity e) { for (Location l : e.getLocations()) { HostGeoInfo hgi = fromLocation(l); if (hgi != null) return hgi; } return null; }
/** 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 */
/** 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; }
/** 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); } }
public static Set<Location> getAllInheritedLocations(Entity entity) { Set<Location> result = MutableSet.of(); while (entity!=null) { result.addAll(entity.getLocations()); entity = entity.getParent(); } return result; }
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; }
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; }
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()); }
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()); }
@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; }
@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); }
@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"); }
@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)); }
@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"); }
@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"); }
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; }
public void testMySqlOnProvisioningLocation() throws Exception { Entity mysql = createMysql(); app.start(MutableList.of(targetLocation)); checkStartsRunning(mysql); checkIsRunningAndStops(mysql, (SshMachineLocation) Iterables.getOnlyElement( mysql.getLocations() )); }