@Override public Iterable<AmbariNode> getAmbariNodes() { return Entities.descendants(this, AmbariNode.class); }
@Test @SuppressWarnings("deprecation") public void testDescendantsFilteredByType() throws Exception { Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(app, TestEntity.class), ImmutableList.of(entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(app, TestEntity.class), ImmutableList.of(entity, entity2)); }
@Test @SuppressWarnings("deprecation") public void testDescendants() throws Exception { Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(app), ImmutableList.of(app, entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(app), ImmutableList.of(app, entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(entity), ImmutableList.of(entity)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(entity), ImmutableList.of(entity)); }
private Iterable<AmbariHostGroup> getHostGroups() { return Entities.descendants(this, AmbariHostGroup.class); }
@Test @SuppressWarnings("deprecation") public void testDescendantsFilteredByPredicate() throws Exception { Asserts.assertEqualsIgnoringOrder(Entities.descendantsAndSelf(app, Predicates.instanceOf(TestEntity.class)), ImmutableList.of(entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(app, Predicates.instanceOf(TestEntity.class)), ImmutableList.of(entity, entity2)); }
@Override public Iterable<AmbariAgent> getAmbariAgents() { return Entities.descendants(this, AmbariAgent.class); }
@Override public Iterable<AmbariServer> getAmbariServers() { return Entities.descendants(this, AmbariServer.class); }
@Nonnull private Iterable<ExtraService> getExtraServices() { return Entities.descendants(this, ExtraService.class); }
@Override public AmbariServer getMasterAmbariServer() { return Iterables.getFirst(Entities.descendants(this, AmbariServer.class), null); }
private List<AmbariAgent> getAmbariAgents(Collection<Entity> entities) { ImmutableList.Builder<AmbariAgent> builder = ImmutableList.<AmbariAgent>builder(); for (Entity entity : entities) { if(entity instanceof AmbariAgent) { builder.add((AmbariAgent) entity); } else { builder.addAll(Entities.descendants(entity, AmbariAgent.class)); } } return builder.build(); }
@Override public List<String> getHostFQDNs() { ImmutableList.Builder<String> builder = ImmutableList.builder(); for (AmbariAgent agent : Entities.descendants(this, AmbariAgent.class)) { String fqdn = agent.getFqdn(); if (fqdn != null) { builder.add(fqdn); } } return builder.build(); }
@Nullable private AmbariAgent getAmbariAgentByFqdn(@Nonnull String fqdn) { checkNotNull(fqdn); for (AmbariAgent ambariAgent : Entities.descendants(this, AmbariAgent.class)) { if (StringUtils.equals(ambariAgent.getFqdn(), fqdn)) { return ambariAgent; } } return null; }
@Test public void testDescendantsWithExplicitIncludeSelf() throws Exception { Asserts.assertEqualsIgnoringOrder(Entities.descendants(app, Predicates.alwaysTrue(), true), ImmutableList.of(app, entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(app, Predicates.alwaysTrue(), false), ImmutableList.of(entity, entity2)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(entity, Predicates.alwaysTrue(), true), ImmutableList.of(entity)); Asserts.assertEqualsIgnoringOrder(Entities.descendants(entity, Predicates.alwaysTrue(), false), ImmutableList.of()); }
@Override public void customize() { List<String> extraStackDefinitions = getExtraStackDefinitionUrls(); ImmutableList.Builder<String> builder = ImmutableList.<String>builder(); if (!extraStackDefinitions.isEmpty()) { for (String extraStackDefinition : extraStackDefinitions) { String tmpLocation = copyToTmp(extraStackDefinition); builder.add(getUnpackCommand(tmpLocation)); } } AmbariCluster ambariCluster = getParentAmbariCluster(); for (Entity customService: Entities.descendants(ambariCluster, Predicates.instanceOf(CustomService.class), false)) { if (Entities.isManaged(customService)) { ((CustomService)customService).customizeService(); } } builder.add(sudo("ambari-server setup -s")); newScript(CUSTOMIZING) .body.append(builder.build()) .failOnNonZeroResultCode() .execute(); }
for (ExtraService extraService : Entities.descendants(this, ExtraService.class)) { if (extraService.getConfig(ExtraService.SERVICE_NAME) == null && extraService.getConfig(ExtraService.COMPONENT_NAMES) == null) { continue;
@Test public void testThrottleAppliesAfterRebind() throws Exception { DynamicCluster cluster = origApp.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.MAX_CONCURRENT_CHILD_COMMANDS, 1) .configure(DynamicCluster.INITIAL_SIZE, 1) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(DynamicClusterTest.ThrowOnAsyncStartEntity.class)) .configure(DynamicClusterTest.ThrowOnAsyncStartEntity.COUNTER, new AtomicInteger())); app().start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); EntityAsserts.assertAttributeEquals(cluster, DynamicCluster.GROUP_SIZE, 1); rebind(RebindOptions.create().terminateOrigManagementContext(true)); cluster = Entities.descendants(app(), DynamicCluster.class).iterator().next(); cluster.resize(10); EntityAsserts.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 10); EntityAsserts.assertAttributeEquals(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); }