private ImmutableList<MySqlNode> getHealhtySlaves() { return FluentIterable.from(cluster.getMembers()) .filter(Predicates.not(MySqlClusterUtils.IS_MASTER)) .filter(EntityPredicates.attributeEqualTo(MySqlNode.SERVICE_UP, Boolean.TRUE)) .filter(MySqlNode.class) .toList(); }
protected void onServerPoolMemberRemoved(final Entity member) { Map<Entity, String> nodes = MutableMap.copyOf(sensors().get(ETCD_CLUSTER_NODES)); Duration timeout = config().get(BrooklynConfigKeys.START_TIMEOUT); String name = nodes.get(member); if (nodes.containsKey(member)) { synchronized (clusterMutex) { Optional<Entity> otherNode = Iterables.tryFind(nodes.keySet(), Predicates.and( Predicates.instanceOf(EtcdNode.class), EntityPredicates.attributeEqualTo(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE), Predicates.not(EntityPredicates.idEqualTo(member.getId())))); if (otherNode.isPresent()) { boolean ended = Entities.invokeEffectorWithArgs(this, otherNode.get(), EtcdNode.LEAVE_ETCD_CLUSTER, name).blockUntilEnded(timeout); if (!ended) { LOG.warn("Timeout invoking leaveCluster for {} on {}", member, otherNode.get()); } } removeNode(member, name); } } }
predicate = EntityPredicates.idEqualTo(entity.getId()); } else if (verb.equalsIgnoreCase(APPLICATION)) { predicate = EntityPredicates.applicationIdEqualTo(entity.getApplicationId()); } else { throw new IllegalStateException("Affinity rule parameter not specified: " + rule); predicate = EntityPredicates.idEqualTo(parameter); } else if (verb.equalsIgnoreCase(APPLICATION)) { predicate = EntityPredicates.applicationIdEqualTo(parameter); } else if (verb.equalsIgnoreCase(PREDICATE)) { try {
@Test public void testDisplayNameSatisfies() throws Exception { assertTrue(EntityPredicates.displayNameSatisfies(StringPredicates.matchesRegex("myd.*me")).apply(entity)); assertFalse(EntityPredicates.applicationIdEqualTo("wrongname").apply(entity)); }
private Entity getMember(String memberId) { Group cluster = (Group)entity(); try { return Iterables.find(cluster.getMembers(), EntityPredicates.idEqualTo(memberId)); } catch (NoSuchElementException e) { throw new IllegalStateException(memberId + " is not an ID of brooklyn node in this cluster"); } }
@Test public void testDisplayNameEqualTo() throws Exception { assertTrue(EntityPredicates.displayNameEqualTo("mydisplayname").apply(entity)); assertFalse(EntityPredicates.displayNameEqualTo("wrongname").apply(entity)); }
.configure(DynamicGroup.ENTITY_FILTER, Predicates.and( Predicates.instanceOf(MesosTask.class), EntityPredicates.attributeEqualTo(MesosAttributes.MESOS_CLUSTER, this))) .displayName("Mesos Tasks")); .configure(DynamicMultiGroup.ENTITY_FILTER, Predicates.and( MesosUtils.sameCluster(this), Predicates.not(EntityPredicates.applicationIdEqualTo(getApplicationId())))) .configure(DynamicMultiGroup.RESCAN_INTERVAL, 15L) .configure(DynamicMultiGroup.BUCKET_FUNCTION, new Function<Entity, String>() {
@Override public Collection<Entity> getEntitiesInApplication(Application application) { Predicate<Entity> predicate = EntityPredicates.applicationIdEqualTo(application.getId()); return ImmutableList.copyOf(Iterables.filter(entityProxiesById.values(), predicate)); }
@Override public void onCallback(String childId, boolean success) { Optional<Entity> child = Iterables.tryFind(getChildren(), EntityPredicates.idEqualTo(childId)); if (child.isPresent()) { ((AsyncEntity)child.get()).onCallback(success); } else { LOG.warn("Child not found with resourceId '"+childId+"'; not injecting state from callback"); } Optional<Entity> unstartedVm = Iterables.tryFind(getChildren(), EntityPredicates.attributeSatisfies(Attributes.SERVICE_STATE_EXPECTED, new Predicate<Lifecycle.Transition>() { @Override public boolean apply(Transition input) { return input == null || input.getState() == Lifecycle.STARTING; }})); if (!unstartedVm.isPresent()) { // No VMs are still starting; we are finished starting ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } }
Iterable<Entity> netcatI = Iterables.filter(app.getChildren(), EntityPredicates.configEqualTo(BrooklynCampConstants.PLAN_ID, "netcat-server")); Assert.assertTrue(netcatI.iterator().hasNext(), "no 'netcat-server' child of app: "+app.getChildren()); Entity netcat = Iterables.getOnlyElement(netcatI); Iterable<Entity> pingerI = Iterables.filter(app.getChildren(), EntityPredicates.displayNameEqualTo("Simple Pinger")); Assert.assertTrue(pingerI.iterator().hasNext(), "no 'Simple Pinger' child of app: "+app.getChildren()); Entity pinger = Iterables.getOnlyElement(pingerI);
public static <T> Predicate<Entity> configEqualTo(final HasConfigKey<T> configKey, final T val) { return configEqualTo(configKey.getConfigKey(), val); }
/** @deprecated since 0.7.0 use {@link #locationsIncludes(Location)} */ @Deprecated public static <T> Predicate<Entity> withLocation(final Location location) { return locationsIncludes(location); }
private MySqlNode getSnapshotNode() { String snapshotNodeId = cluster.getConfig(MySqlCluster.REPLICATION_PREFERRED_SOURCE); if (snapshotNodeId != null) { Optional<Entity> preferredNode = Iterables.tryFind(cluster.getMembers(), EntityPredicates.idEqualTo(snapshotNodeId)); if (preferredNode.isPresent()) { return (MySqlNode) preferredNode.get(); } else { log.warn("MySql cluster " + this + " configured with preferred snapshot node " + snapshotNodeId + " but it's not a member. Defaulting to a random slave."); } } return getRandomSlave(); }
@Override public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); assertNull(bucketA); assertNotNull(bucketB); assertEquals(ImmutableSet.copyOf(bucketB.getMembers()), ImmutableSet.of(child)); } });
@Override public Collection<Entity> findEntitiesInApplication(Application application, Predicate<? super Entity> filter) { Predicate<Entity> predicate = Predicates.and(EntityPredicates.applicationIdEqualTo(application.getId()), filter); return ImmutableList.copyOf(Iterables.filter(entityProxiesById.values(), predicate)); }
@Test public void testConfigEqualTo() throws Exception { entity.config().set(TestEntity.CONF_NAME, "myname"); assertTrue(EntityPredicates.configEqualTo(TestEntity.CONF_NAME, "myname").apply(entity)); assertTrue(EntityPredicates.configEqualTo(TestEntity.CONF_NAME.getName(), "myname").apply(entity)); assertFalse(EntityPredicates.configEqualTo(TestEntity.CONF_NAME, "wrongname").apply(entity)); assertFalse(EntityPredicates.configEqualTo(TestEntity.CONF_NAME.getName(), "wrongname").apply(entity)); }
@Test public void testWithLocation() throws Exception { entity.addLocations(ImmutableList.of(loc)); assertTrue(EntityPredicates.locationsIncludes(loc).apply(entity)); assertFalse(EntityPredicates.locationsIncludes(loc).apply(app)); }
@Override public MesosSlave getMesosSlave(String hostname) { Collection<Entity> slaves = sensors().get(MESOS_SLAVES).getMembers(); Optional<Entity> found = Iterables.tryFind(slaves, Predicates.or( EntityPredicates.attributeEqualTo(MesosSlave.HOSTNAME, hostname), EntityPredicates.attributeEqualTo(MesosSlave.ADDRESS, hostname))); if (found.isPresent()) { return (MesosSlave) found.get(); } else { throw new IllegalStateException("Cannot find slave for host: " + hostname); } }
@Override public void run() { Group bucketA = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketA"), null); Group bucketB = (Group) find(dmg.getChildren(), displayNameEqualTo("bucketB"), null); assertNotNull(bucketA); assertNull(bucketB); assertEquals(ImmutableSet.copyOf(bucketA.getMembers()), ImmutableSet.of(child1, child2)); } });