예제 #1
0
  /** De-register our {@link MesosLocation} and its children. */
  @Override
  public void stop() {
    disconnectSensors();

    sensors().set(SERVICE_UP, Boolean.FALSE);

    deleteLocation();

    Duration timeout = config().get(SHUTDOWN_TIMEOUT);

    // Find all applications and stop, blocking for up to five minutes until ended
    try {
      Iterable<Entity> entities =
          Iterables.filter(
              getManagementContext().getEntityManager().getEntities(),
              Predicates.and(
                  MesosUtils.sameCluster(this),
                  Predicates.not(EntityPredicates.applicationIdEqualTo(getApplicationId()))));
      Set<Application> applications =
          ImmutableSet.copyOf(
              Iterables.transform(
                  entities,
                  new Function<Entity, Application>() {
                    @Override
                    public Application apply(Entity input) {
                      return input.getApplication();
                    }
                  }));
      LOG.debug("Stopping applications: {}", Iterables.toString(applications));
      Entities.invokeEffectorList(this, applications, Startable.STOP).get(timeout);
    } catch (Exception e) {
      LOG.warn("Error stopping applications", e);
    }

    // Stop all framework tasks in parallel
    try {
      Group frameworks = sensors().get(MESOS_FRAMEWORKS);
      LOG.debug("Stopping framework tasks in: {}", Iterables.toString(frameworks.getMembers()));
      Entities.invokeEffectorList(this, frameworks.getMembers(), Startable.STOP).get(timeout);
    } catch (Exception e) {
      LOG.warn("Error stopping frameworks", e);
    }

    // Stop anything else left over
    // TODO Stop slave entities
    try {
      super.stop();
    } catch (Exception e) {
      LOG.warn("Error stopping children", e);
    }
  }
예제 #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))))));
  }