@Override
 protected void initEnrichers() {
   // don't add default ones
   addEnricher(
       EnricherSpec.create(MyEnricher.class).uniqueTag("x").tag(Identifiers.makeRandomId(8)));
   addEnricher(EnricherSpec.create(MyEnricher.class));
 }
 @Override
 public void onManagementStarted() {
   super.onManagementStarted();
   addEnricher(
       EnricherSpec.create(MyEnricher.class).uniqueTag("z").tag(Identifiers.makeRandomId(8)));
   // all the enrichers above should not be added on rebind, but this one will be:
   addEnricher(
       EnricherSpec.create(MyEnricher.class)
           .uniqueTag(Identifiers.makeRandomId(8))
           .tag(Identifiers.makeRandomId(8)));
 }
  @Test
  public void testRestoresConfig() throws Exception {
    origApp.addEnricher(
        EnricherSpec.create(MyEnricher.class)
            .displayName("My Enricher")
            .uniqueTag("tagU")
            .tag("tag1")
            .tag("tag2")
            .configure(
                MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_NO_SHORT_NAME,
                "myVal for with setFromFlag noShortName")
            .configure(
                MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_WITH_SHORT_NAME,
                "myVal for setFromFlag withShortName")
            .configure(MyEnricher.MY_CONFIG_WITHOUT_SETFROMFLAG, "myVal for witout setFromFlag"));

    newApp = (TestApplication) rebind();
    MyEnricher newEnricher = (MyEnricher) Iterables.getOnlyElement(newApp.getEnrichers());

    assertEquals(newEnricher.getDisplayName(), "My Enricher");

    assertEquals(newEnricher.getUniqueTag(), "tagU");
    assertEquals(newEnricher.tags().getTags(), MutableSet.of("tagU", "tag1", "tag2"));

    assertEquals(
        newEnricher.getConfig(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_NO_SHORT_NAME),
        "myVal for with setFromFlag noShortName");
    assertEquals(
        newEnricher.getConfig(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_WITH_SHORT_NAME),
        "myVal for setFromFlag withShortName");
    assertEquals(
        newEnricher.getConfig(MyEnricher.MY_CONFIG_WITHOUT_SETFROMFLAG),
        "myVal for witout setFromFlag");
  }
  @Test(groups = "Integration") // Because slow
  public void testRecoversThenDownUpResetsStabilisationCount() throws Exception {
    final long stabilisationDelay = 1000;

    e1.enrichers()
        .add(
            EnricherSpec.create(ServiceFailureDetector.class)
                .configure(
                    ServiceFailureDetector.ENTITY_RECOVERED_STABILIZATION_DELAY,
                    Duration.of(stabilisationDelay)));

    e1.sensors().set(TestEntity.SERVICE_UP, false);
    assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null);
    events.clear();

    e1.sensors().set(TestEntity.SERVICE_UP, true);
    assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD));

    e1.sensors().set(TestEntity.SERVICE_UP, false);
    Thread.sleep(OVERHEAD);
    e1.sensors().set(TestEntity.SERVICE_UP, true);
    assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD));

    assertHasEventEventually(HASensors.ENTITY_RECOVERED, Predicates.<Object>equalTo(e1), null);
  }
  @Test
  public void testReboundConfigDoesNotContainId() throws Exception {
    MyEnricher policy = origApp.addEnricher(EnricherSpec.create(MyEnricher.class));

    newApp = (TestApplication) rebind();
    MyEnricher newEnricher = (MyEnricher) Iterables.getOnlyElement(newApp.getEnrichers());

    assertNull(newEnricher.getConfig(ConfigKeys.newStringConfigKey("id")));
    assertEquals(newEnricher.getId(), policy.getId());
  }
  @Test
  public void testPolicyTags() throws Exception {
    Enricher origEnricher = origApp.addEnricher(EnricherSpec.create(MyEnricher.class));
    origEnricher.tags().addTag("foo");
    origEnricher.tags().addTag(origApp);

    newApp = rebind();
    Enricher newEnricher = Iterables.getOnlyElement(newApp.getEnrichers());

    Asserts.assertEqualsIgnoringOrder(newEnricher.tags().getTags(), ImmutableSet.of("foo", newApp));
  }
  @Test
  public void testIsRebinding() throws Exception {
    origApp.addEnricher(EnricherSpec.create(EnricherChecksIsRebinding.class));

    newApp = (TestApplication) rebind();
    EnricherChecksIsRebinding newEnricher =
        (EnricherChecksIsRebinding) Iterables.getOnlyElement(newApp.getEnrichers());

    assertTrue(newEnricher.isRebindingValWhenRebinding());
    assertFalse(newEnricher.isRebinding());
  }
  @Test(groups = "Integration") // Because slow
  public void testNotNotifiedOfTemporaryFailuresDuringStabilisationDelay() throws Exception {
    e1.enrichers()
        .add(
            EnricherSpec.create(ServiceFailureDetector.class)
                .configure(
                    ServiceFailureDetector.ENTITY_FAILED_STABILIZATION_DELAY, Duration.ONE_MINUTE));

    e1.sensors().set(TestEntity.SERVICE_UP, false);
    Thread.sleep(100);
    e1.sensors().set(TestEntity.SERVICE_UP, true);

    assertNoEventsContinually();
  }
  @Test(groups = "Integration") // Because slow
  public void testNotifiedOfFailureAfterStabilisationDelay() throws Exception {
    final int stabilisationDelay = 1000;

    e1.enrichers()
        .add(
            EnricherSpec.create(ServiceFailureDetector.class)
                .configure(
                    ServiceFailureDetector.ENTITY_FAILED_STABILIZATION_DELAY,
                    Duration.of(stabilisationDelay)));

    e1.sensors().set(TestEntity.SERVICE_UP, false);

    assertNoEventsContinually(Duration.of(stabilisationDelay - OVERHEAD));
    assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(e1), null);
  }
 @Override
 public void onManagementStarting() {
   super.onManagementStarted();
   addEnricher(
       EnricherSpec.create(MyEnricher.class).uniqueTag("y").tag(Identifiers.makeRandomId(8)));
 }
Пример #11
0
  @Override
  public void init() {
    LOG.info("Starting Mesos cluster id {}", getId());
    registerLocationResolver();
    super.init();

    Group slaves = addChild(EntitySpec.create(BasicGroup.class).displayName("Mesos Slaves"));

    Group frameworks =
        addChild(EntitySpec.create(BasicGroup.class).displayName("Mesos Frameworks"));

    DynamicGroup tasks =
        addChild(
            EntitySpec.create(DynamicGroup.class)
                .configure(
                    DynamicGroup.ENTITY_FILTER,
                    Predicates.and(
                        Predicates.instanceOf(MesosTask.class),
                        EntityPredicates.attributeEqualTo(MesosAttributes.MESOS_CLUSTER, this)))
                .displayName("Mesos Tasks"));

    DynamicMultiGroup applications =
        addChild(
            EntitySpec.create(DynamicMultiGroup.class)
                .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 String apply(@Nullable Entity input) {
                        return input.getApplication().getDisplayName()
                            + ":"
                            + input.getApplicationId();
                      }
                    })
                .configure(DynamicMultiGroup.BUCKET_SPEC, EntitySpec.create(BasicGroup.class))
                .displayName("Mesos Applications"));

    if (config().get(SDN_ENABLE) && config().get(SDN_PROVIDER_SPEC) != null) {
      EntitySpec entitySpec = EntitySpec.create(config().get(SDN_PROVIDER_SPEC));
      entitySpec.configure(MesosAttributes.MESOS_CLUSTER, this);
      Entity sdn = addChild(entitySpec);
      sensors().set(SDN_PROVIDER, sdn);
    }

    sensors().set(MESOS_SLAVES, slaves);
    sensors().set(MESOS_FRAMEWORKS, frameworks);
    sensors().set(MESOS_TASKS, tasks);
    sensors().set(MESOS_APPLICATIONS, applications);

    // Override the health-check: just interested in the slaves, frameworks and sdn (rather than
    // the groups that show the tasks or apps).
    Entity sdn = sensors().get(SDN_PROVIDER);
    enrichers()
        .add(
            EnricherSpec.create(ComputeServiceIndicatorsFromChildrenAndMembers.class)
                .uniqueTag(ComputeServiceIndicatorsFromChildrenAndMembers.DEFAULT_UNIQUE_TAG)
                .configure(ComputeServiceIndicatorsFromChildrenAndMembers.FROM_CHILDREN, true)
                .configure(
                    ComputeServiceIndicatorsFromChildrenAndMembers.ENTITY_FILTER,
                    Predicates.or(
                        ImmutableList.of(
                            Predicates.<Entity>equalTo(slaves),
                            Predicates.<Entity>equalTo(frameworks),
                            (sdn == null
                                ? Predicates.<Entity>alwaysFalse()
                                : Predicates.equalTo(sdn))))));
  }