Exemplo n.º 1
0
 @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);
   }
 }
Exemplo n.º 2
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))))));
  }