private void testLocationUnmanagedOnStop(LocationSpec<? extends Location> locationSpec) {
    EntitySpec<BasicApplication> appSpec =
        EntitySpec.create(BasicApplication.class)
            .location(locationSpec)
            .child(
                EntitySpec.create(EmptySoftwareProcess.class)
                    .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, Boolean.TRUE)
                    .configure(EmptySoftwareProcess.USE_SSH_MONITORING, Boolean.FALSE));

    BasicApplication app = mgmt.getEntityManager().createEntity(appSpec);
    Entity child = Iterables.getOnlyElement(app.getChildren());

    Assert.assertEquals(child.getLocations(), ImmutableList.of());

    app.start(ImmutableList.<Location>of());
    Location appLocation = Iterables.getOnlyElement(app.getLocations());
    assertOwned(app, appLocation);
    Location entityLocation = Iterables.getOnlyElement(child.getLocations());
    // No owner tag because it's created by SoftwareProcess, not by Brooklyn internals
    assertNotOwned(entityLocation);
    app.stop();

    Assert.assertEquals(child.getLocations(), ImmutableList.of());

    Assert.assertFalse(mgmt.getEntityManager().isManaged(child));
    Assert.assertFalse(mgmt.getEntityManager().isManaged(app));
    Set<Location> locs = ImmutableSet.copyOf(mgmt.getLocationManager().getLocations());
    Assert.assertFalse(
        locs.contains(entityLocation), locs + " should not contain " + entityLocation);
    Assert.assertFalse(locs.contains(appLocation), locs + " should not contain " + appLocation);
  }
  @Override
  public void initApp() {
    StringConfigMap config = getManagementContext().getConfig();

    GeoscalingDnsService geoDns =
        addChild(
            EntitySpec.create(GeoscalingDnsService.class)
                .displayName("GeoScaling DNS")
                .configure(
                    "username",
                    checkNotNull(config.getFirst("brooklyn.geoscaling.username"), "username"))
                .configure(
                    "password",
                    checkNotNull(config.getFirst("brooklyn.geoscaling.password"), "password"))
                .configure(
                    "primaryDomainName",
                    checkNotNull(
                        config.getFirst("brooklyn.geoscaling.primaryDomain"), "primaryDomain"))
                .configure("smartSubdomainName", "brooklyn"));

    DynamicRegionsFabric webFabric =
        addChild(
            EntitySpec.create(DynamicRegionsFabric.class)
                .displayName("Web Fabric")
                .configure(DynamicRegionsFabric.FACTORY, new ElasticJavaWebAppService.Factory())

                // specify the WAR file to use
                .configure(
                    JavaWebAppService.ROOT_WAR, Entities.getRequiredUrlConfig(this, WAR_PATH)));

    // tell GeoDNS what to monitor
    geoDns.setTargetEntityProvider(webFabric);
  }
 @Test
 public void testStartsWhenNoStartableChildren() {
   BasicStartable startable =
       app.createAndManageChild(
           EntitySpec.create(BasicStartable.class).child(EntitySpec.create(BasicEntity.class)));
   app.start(ImmutableList.of(app.newSimulatedLocation()));
   EntityAsserts.assertAttributeEquals(
       startable, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
 }
  @Test
  public void testDefaultIsAllLocations() throws Exception {
    BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class));
    TestEntity entity = startable.addChild(EntitySpec.create(TestEntity.class));
    TestEntity entity2 = startable.addChild(EntitySpec.create(TestEntity.class));
    app.start(ImmutableList.of(loc1, loc2));

    assertEqualsIgnoringOrder(entity.getLocations(), ImmutableSet.of(loc1, loc2));
    assertEqualsIgnoringOrder(entity2.getLocations(), ImmutableSet.of(loc1, loc2));
  }
 @Override
 @BeforeMethod(alwaysRun = true)
 public void setUp() throws Exception {
   super.setUp();
   origCluster =
       origApp.createAndManageChild(
           EntitySpec.create(DynamicCluster.class)
               .configure("memberSpec", EntitySpec.create(TestEntity.class)));
   origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class));
   origLoc =
       origManagementContext
           .getLocationManager()
           .createLocation(LocationSpec.create(SimulatedLocation.class));
 }
  @BeforeMethod(alwaysRun = true)
  public void setUp() throws Exception {
    events = new CopyOnWriteArrayList<SensorEvent<FailureDescriptor>>();

    managementContext = new LocalManagementContextForTests();
    app = ApplicationBuilder.newManagedApp(TestApplication.class, managementContext);
    e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    e1.sensors().set(TestEntity.SERVICE_UP, true);
    ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING);

    app.getManagementContext()
        .getSubscriptionManager()
        .subscribe(
            e1,
            HASensors.ENTITY_FAILED,
            new SensorEventListener<FailureDescriptor>() {
              @Override
              public void onEvent(SensorEvent<FailureDescriptor> event) {
                events.add(event);
              }
            });
    app.getManagementContext()
        .getSubscriptionManager()
        .subscribe(
            e1,
            HASensors.ENTITY_RECOVERED,
            new SensorEventListener<FailureDescriptor>() {
              @Override
              public void onEvent(SensorEvent<FailureDescriptor> event) {
                events.add(event);
              }
            });
  }
  /** Test that a core can be created and used with SolrJ client. */
  @Test(groups = "Integration")
  public void testConnection() throws Exception {
    solr =
        app.createAndManageChild(
            EntitySpec.create(SolrServer.class)
                .configure(
                    SolrServer.SOLR_CORE_CONFIG,
                    ImmutableMap.of("example", "classpath://solr/example.tgz")));
    app.start(ImmutableList.of(testLocation));

    EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, true);

    SolrJSupport client = new SolrJSupport(solr, "example");

    Iterable<SolrDocument> results = client.getDocuments();
    assertTrue(Iterables.isEmpty(results));

    client.addDocument(MutableMap.<String, Object>of("id", "1", "description", "first"));
    client.addDocument(MutableMap.<String, Object>of("id", "2", "description", "second"));
    client.addDocument(MutableMap.<String, Object>of("id", "3", "description", "third"));
    client.commit();

    results = client.getDocuments();
    assertEquals(Iterables.size(results), 3);
  }
  // TODO BROOKLYN-272, Disabled, because fails non-deterministically in jenkins: BROOKLYN-256
  //    java.lang.AssertionError: Expected: eventually IsEqualTo([starting, running, stopping,
  // stopped]); got most recently: [starting, running, starting, running, stopping, stopped] (waited
  // 1s 11ms 498us 762ns, checked 100)
  //        at org.apache.brooklyn.test.Asserts.fail(Asserts.java:721)
  //        at org.apache.brooklyn.test.Asserts.eventually(Asserts.java:791)
  //        at org.apache.brooklyn.test.Asserts.eventually(Asserts.java:751)
  //        at
  // org.apache.brooklyn.entity.stock.BasicStartableTest.testTransitionsThroughLifecycles(BasicStartableTest.java:170)
  @Test(groups = {"Broken"})
  public void testTransitionsThroughLifecycles() throws Exception {
    BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class));
    EntityAsserts.assertAttributeEqualsEventually(
        app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED);

    final RecordingSensorEventListener<Lifecycle> listener =
        new RecordingSensorEventListener<Lifecycle>(true);
    mgmt.getSubscriptionContext(startable)
        .subscribe(startable, Attributes.SERVICE_STATE_ACTUAL, listener);

    app.start(ImmutableList.of(loc1));
    app.config().set(StartableApplication.DESTROY_ON_STOP, false);
    app.stop();

    Iterable<Lifecycle> expected =
        Lists.newArrayList(
            Lifecycle.STARTING, Lifecycle.RUNNING, Lifecycle.STOPPING, Lifecycle.STOPPED);
    Asserts.eventually(
        new Supplier<Iterable<Lifecycle>>() {
          @Override
          public Iterable<Lifecycle> get() {
            return MutableList.copyOf(listener.getEventValuesSortedByTimestamp());
          }
        },
        Predicates.equalTo(expected));
  }
 @BeforeMethod(alwaysRun = true)
 @Override
 public void setUp() throws Exception {
   super.setUp();
   loc = new LocalhostMachineProvisioningLocation();
   entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
   app.start(ImmutableList.of(loc));
 }
  @Override
  protected void doTest(Location loc) throws Exception {
    RiakNode entity =
        app.createAndManageChild(
            EntitySpec.create(RiakNode.class).configure(RiakNode.SUGGESTED_VERSION, "2.1.1"));
    app.start(ImmutableList.of(loc));

    EntityTestUtils.assertAttributeEqualsEventually(entity, RiakNode.SERVICE_UP, true);
  }
 @BeforeMethod(alwaysRun = true)
 @Override
 public void setUp() throws Exception {
   catalogPersistenceWasEnabled =
       BrooklynFeatureEnablement.isEnabled(
           BrooklynFeatureEnablement.FEATURE_CATALOG_PERSISTENCE_PROPERTY);
   BrooklynFeatureEnablement.enable(
       BrooklynFeatureEnablement.FEATURE_CATALOG_PERSISTENCE_PROPERTY);
   super.setUp();
   origApp.createAndManageChild(EntitySpec.create(TestEntity.class));
 }
Example #12
0
 @Override
 public void addHost(DockerHost host) {
   SshMachineLocation machine = host.getDynamicLocation().getMachine();
   EntitySpec<?> spec =
       EntitySpec.create(sensors().get(SDN_AGENT_SPEC))
           .configure(CalicoNode.DOCKER_HOST, host)
           .configure(CalicoNode.ETCD_NODE, host.sensors().get(DockerHost.ETCD_NODE));
   CalicoNode agent = (CalicoNode) getAgents().addChild(spec);
   getAgents().addMember(agent);
   agent.start(ImmutableList.of(machine));
   if (LOG.isDebugEnabled()) LOG.debug("{} added calico plugin {}", this, agent);
 }
  /** Test that a node starts and sets SERVICE_UP correctly. */
  @Test(groups = "Integration")
  public void canStartupAndShutdown() {
    solr = app.createAndManageChild(EntitySpec.create(SolrServer.class));
    app.start(ImmutableList.of(testLocation));

    EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, true);
    Entities.dumpInfo(app);

    solr.stop();

    EntityAsserts.assertAttributeEqualsEventually(solr, Startable.SERVICE_UP, false);
  }
Example #14
0
  @Override
  public void init() {
    LOG.info("Starting Calico network id {}", getId());
    super.init();

    EntitySpec<?> agentSpec =
        EntitySpec.create(config().get(CALICO_NODE_SPEC)).configure(CalicoNode.SDN_PROVIDER, this);
    String calicoVersion = config().get(CALICO_VERSION);
    if (Strings.isNonBlank(calicoVersion)) {
      agentSpec.configure(SoftwareProcess.SUGGESTED_VERSION, calicoVersion);
    }
    sensors().set(SDN_AGENT_SPEC, agentSpec);
  }
  @BeforeMethod(alwaysRun = true)
  @Override
  public void setUp() throws Exception {
    super.setUp();

    entities = Lists.newArrayList();
    for (int i = 0; i < 10; i++) {
      entities.add(app.createAndManageChild(EntitySpec.create(TestEntity.class)));
    }
    entity = entities.get(0);

    app.start(ImmutableList.of(loc));
  }
  @Test
  public void testAppliesFilterToEntities() throws Exception {
    final List<Object> contexts = Lists.newCopyOnWriteArrayList();

    LocationsFilter filter =
        new LocationsFilter() {
          private static final long serialVersionUID = 7078046521812992013L;

          @Override
          public List<Location> filterForContext(List<Location> locations, Object context) {
            contexts.add(context);
            assertEquals(locations, ImmutableList.of(loc1, loc2));
            if (context instanceof Entity) {
              String entityName = ((Entity) context).getDisplayName();
              if ("1".equals(entityName)) {
                return ImmutableList.<Location>of(loc1);
              } else if ("2".equals(entityName)) {
                return ImmutableList.<Location>of(loc2);
              } else {
                return ImmutableList.<Location>of();
              }
            } else {
              return ImmutableList.<Location>of();
            }
          }
        };
    BasicStartable startable =
        app.addChild(
            EntitySpec.create(BasicStartable.class)
                .configure(BasicStartable.LOCATIONS_FILTER, filter));
    TestEntity entity = startable.addChild(EntitySpec.create(TestEntity.class).displayName("1"));
    TestEntity entity2 = startable.addChild(EntitySpec.create(TestEntity.class).displayName("2"));
    app.start(ImmutableList.of(loc1, loc2));

    assertEqualsIgnoringOrder(entity.getLocations(), ImmutableSet.of(loc1));
    assertEqualsIgnoringOrder(entity2.getLocations(), ImmutableSet.of(loc2));
    assertEqualsIgnoringOrder(contexts, ImmutableList.of(entity, entity2));
  }
  @Test
  public void testIgnoresUnstartableEntities() throws Exception {
    final AtomicReference<Exception> called = new AtomicReference<Exception>();
    LocationsFilter filter =
        new LocationsFilter() {
          private static final long serialVersionUID = -5625121945234751178L;

          @Override
          public List<Location> filterForContext(List<Location> locations, Object context) {
            called.set(new Exception());
            return locations;
          }
        };
    BasicStartable startable =
        app.addChild(
            EntitySpec.create(BasicStartable.class)
                .configure(BasicStartable.LOCATIONS_FILTER, filter));
    BasicEntity entity = startable.addChild(EntitySpec.create(BasicEntity.class));
    app.start(ImmutableList.of(loc1, loc2));

    assertEqualsIgnoringOrder(entity.getLocations(), ImmutableSet.of());
    assertNull(called.get());
  }
  @BeforeMethod(alwaysRun = true)
  public void setUp() throws Exception {
    jmxObjectName = new ObjectName(objectName);

    // Create an entity and configure it with the above JMX service
    app = TestApplication.Factory.newManagedInstanceForTests();
    entity =
        app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(TestEntityWithJmx.class));
    app.start(ImmutableList.of(new SimulatedLocation()));

    jmxHelper = new JmxHelper(entity);

    jmxService = new JmxService(entity);
  }
Example #19
0
  public List<String> scanFrameworks(JsonArray frameworks) {
    List<String> frameworkNames = MutableList.<String>of();
    for (int i = 0; i < frameworks.size(); i++) {
      JsonObject task = frameworks.get(i).getAsJsonObject();
      String id = task.get("id").getAsString();
      JsonElement pidObj = task.get("pid");
      String pid = null;
      if (pidObj != null && !pidObj.isJsonNull()) {
        pid = pidObj.getAsString();
      }
      String name = task.get("name").getAsString();
      String url = task.get("webui_url").getAsString();
      frameworkNames.add(name);

      Optional<Entity> entity =
          Iterables.tryFind(
              sensors().get(MESOS_FRAMEWORKS).getMembers(),
              Predicates.compose(
                  Predicates.equalTo(id), EntityFunctions.attribute(MesosFramework.FRAMEWORK_ID)));
      if (entity.isPresent()) continue;

      EntitySpec<? extends MesosFramework> frameworkSpec =
          EntitySpec.create(
                  FRAMEWORKS.containsKey(name)
                      ? FRAMEWORKS.get(name)
                      : EntitySpec.create(MesosFramework.class))
              .configure(MesosFramework.FRAMEWORK_ID, id)
              .configure(MesosFramework.FRAMEWORK_PID, pid)
              .configure(MesosFramework.FRAMEWORK_NAME, name)
              .configure(MesosFramework.FRAMEWORK_URL, url)
              .configure(MesosFramework.MESOS_CLUSTER, this)
              .displayName(String.format("%s Framework", Strings.toInitialCapOnly(name)));
      MesosFramework added = sensors().get(MESOS_FRAMEWORKS).addMemberChild(frameworkSpec);
      added.start(ImmutableList.<Location>of());
    }
    return frameworkNames;
  }
  @Override
  protected void doTest(Location loc) throws Exception {
    MySqlNode mysql =
        app.createAndManageChild(
            EntitySpec.create(MySqlNode.class)
                .configure(
                    DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT)
                .configure("test.table.name", "COMMENTS"));

    app.start(ImmutableList.of(loc));

    new VogellaExampleAccess(
            "com.mysql.jdbc.Driver", mysql.getAttribute(DatastoreCommon.DATASTORE_URL))
        .readModifyAndRevertDataBase();
  }
  public static void main(String[] argv) {
    List<String> args = Lists.newArrayList(argv);
    String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String locations =
        CommandLineUtil.getCommandLineOption(
            args, "--locations", Joiner.on(",").join(DEFAULT_LOCATIONS));

    BrooklynLauncher launcher =
        BrooklynLauncher.newInstance()
            .application(
                EntitySpec.create(StartableApplication.class, GlobalWebFabricExample.class)
                    .displayName("Brooklyn Global Web Fabric Example"))
            .webconsolePort(port)
            .locations(Arrays.asList(locations))
            .start();

    Entities.dumpInfo(launcher.getApplications());
  }
@ImplementedBy(BrooklynClusterImpl.class)
public interface BrooklynCluster extends DynamicCluster {

  ConfigKey<EntitySpec<?>> MEMBER_SPEC =
      ConfigKeys.newConfigKeyWithDefault(
          DynamicCluster.MEMBER_SPEC, EntitySpec.create(BrooklynNode.class));

  AttributeSensor<BrooklynNode> MASTER_NODE =
      Sensors.newSensor(
          BrooklynNode.class,
          "brooklyncluster.master",
          "Pointer to the child node with MASTER state in the cluster");

  interface SelectMasterEffector {
    ConfigKey<String> NEW_MASTER_ID =
        ConfigKeys.newStringConfigKey(
            "brooklyncluster.new_master_id", "The ID of the node to become master", null);
    Effector<Void> SELECT_MASTER =
        Effectors.effector(Void.class, "selectMaster")
            .description("Select a new master in the cluster")
            .parameter(NEW_MASTER_ID)
            .buildAbstract();
  }

  Effector<Void> SELECT_MASTER = SelectMasterEffector.SELECT_MASTER;

  interface UpgradeClusterEffector {
    ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
    ConfigKey<Map<String, Object>> EXTRA_CONFIG = BrooklynNodeUpgradeEffectorBody.EXTRA_CONFIG;

    Effector<Void> UPGRADE_CLUSTER =
        Effectors.effector(Void.class, "upgradeCluster")
            .description(
                "Upgrade the cluster with new distribution version, "
                    + "by provisioning new nodes with the new version, failing over, "
                    + "and then deprovisioning the original nodes")
            .parameter(BrooklynNode.SUGGESTED_VERSION)
            .parameter(DOWNLOAD_URL)
            .parameter(EXTRA_CONFIG)
            .buildAbstract();
  }

  Effector<Void> UPGRADE_CLUSTER = UpgradeClusterEffector.UPGRADE_CLUSTER;
}
  @Test
  public void testEntityCreatingItsEnricherDoesNotReCreateItUnlessUniqueTagDifferent()
      throws Exception {
    TestEntity e1 =
        origApp.createAndManageChild(
            EntitySpec.create(TestEntity.class, MyTestEntityWithEnricher.class));
    Collection<Enricher> e1e = e1.getEnrichers();
    log.info("enrichers1: " + e1e);
    Entities.dumpInfo(e1);
    assertEquals(e1e.size(), 5);

    newApp = (TestApplication) rebind();
    Entity e2 =
        Iterables.getOnlyElement(
            Entities.descendants(newApp, EntityPredicates.idEqualTo(e1.getId())));
    Collection<Enricher> e2e = e2.getEnrichers();
    log.info("enrichers2: " + e2e);
    Entities.dumpInfo(e2);

    assertEquals(e2e.size(), e1e.size() + 1);
  }
 @Override
 public void init() {
   super.init();
   checkNotNull(
       getConfig(HOSTNAME_SENSOR),
       "%s requires value for %s",
       getClass().getName(),
       HOSTNAME_SENSOR);
   DynamicGroup entities =
       addChild(
           EntitySpec.create(DynamicGroup.class)
               .configure(DynamicGroup.ENTITY_FILTER, getEntityFilter()));
   setAttribute(ENTITIES, entities);
   setAttribute(A_RECORDS, ImmutableMap.<String, String>of());
   setAttribute(CNAME_RECORDS, ImmutableMultimap.<String, String>of());
   setAttribute(PTR_RECORDS, ImmutableMap.<String, String>of());
   setAttribute(ADDRESS_MAPPINGS, ImmutableMultimap.<String, String>of());
   synchronized (serialMutex) {
     setAttribute(SERIAL, System.currentTimeMillis());
   }
 }
 @Test
 public void testSetsLocations() throws Exception {
   BasicStartable startable = app.addChild(EntitySpec.create(BasicStartable.class));
   app.start(ImmutableList.of(loc1, loc2));
   assertEqualsIgnoringOrder(startable.getLocations(), ImmutableSet.of(loc1, loc2));
 }
 public RabbitQueue createQueue(Map properties) {
   RabbitQueue result = addChild(EntitySpec.create(RabbitQueue.class).configure(properties));
   result.create();
   return result;
 }
Example #27
0
  public List<String> scanSlaves(JsonArray slaves) throws UnknownHostException {
    List<String> slaveIds = MutableList.<String>of();
    for (int i = 0; i < slaves.size(); i++) {
      JsonObject slave = slaves.get(i).getAsJsonObject();
      boolean active = slave.get("active").getAsBoolean();
      String id = slave.get("id").getAsString();
      String hostname = slave.get("hostname").getAsString();
      Double registered = slave.get("registered_time").getAsDouble();
      Group group = sensors().get(MESOS_SLAVES);

      Optional<Entity> entity =
          Iterables.tryFind(
              group.getMembers(),
              Predicates.compose(
                  Predicates.equalTo(id), EntityFunctions.attribute(MesosSlave.MESOS_SLAVE_ID)));
      if (entity.isPresent()) {
        Entity found = entity.get();
        found.sensors().set(MesosSlave.SLAVE_ACTIVE, active);
        if (!active) {
          Lifecycle state = found.sensors().get(Attributes.SERVICE_STATE_ACTUAL);
          if (Lifecycle.ON_FIRE.equals(state) || Lifecycle.STARTING.equals(state)) {
            continue;
          } else if (Lifecycle.STOPPING.equals(state) || Lifecycle.STOPPED.equals(state)) {
            group.removeMember(found);
            group.removeChild(found);
            Entities.unmanage(found);
          } else {
            ServiceStateLogic.setExpectedState(found, Lifecycle.STOPPING);
          }
        }
      } else if (active) {
        LocationSpec<SshMachineLocation> spec =
            LocationSpec.create(SshMachineLocation.class)
                .configure(SshMachineLocation.SSH_HOST, hostname)
                .configure("address", InetAddress.getByName(hostname))
                .displayName(hostname);
        if (config().get(MESOS_SLAVE_ACCESSIBLE)) {
          spec.configure(CloudLocationConfig.WAIT_FOR_SSHABLE, "true")
              .configure(SshMachineLocation.DETECT_MACHINE_DETAILS, true)
              .configure(SshMachineLocation.SSH_PORT, config().get(MesosSlave.SLAVE_SSH_PORT))
              .configure(LocationConfigKeys.USER, config().get(MesosSlave.SLAVE_SSH_USER))
              .configure(LocationConfigKeys.PASSWORD, config().get(MesosSlave.SLAVE_SSH_PASSWORD))
              .configure(SshTool.PROP_PASSWORD, config().get(MesosSlave.SLAVE_SSH_PASSWORD))
              .configure(SshTool.PROP_PORT, config().get(MesosSlave.SLAVE_SSH_PORT))
              .configure(
                  LocationConfigKeys.PRIVATE_KEY_DATA,
                  config().get(MesosSlave.SLAVE_SSH_PRIVATE_KEY_DATA))
              .configure(
                  LocationConfigKeys.PRIVATE_KEY_FILE,
                  config().get(MesosSlave.SLAVE_SSH_PRIVATE_KEY_FILE));
        } else {
          spec.configure(CloudLocationConfig.WAIT_FOR_SSHABLE, "false")
              .configure(SshMachineLocation.DETECT_MACHINE_DETAILS, false);
        }
        SshMachineLocation machine =
            getManagementContext().getLocationManager().createLocation(spec);

        // Setup port forwarding
        MarathonPortForwarder portForwarder = new MarathonPortForwarder();
        portForwarder.setManagementContext(getManagementContext());

        EntitySpec<MesosSlave> slaveSpec =
            EntitySpec.create(MesosSlave.class)
                .configure(MesosSlave.MESOS_SLAVE_ID, id)
                .configure(MesosSlave.REGISTERED_AT, registered.longValue())
                .configure(MesosSlave.MESOS_CLUSTER, this)
                .displayName("Mesos Slave (" + hostname + ")");
        MesosSlave added = sensors().get(MESOS_SLAVES).addMemberChild(slaveSpec);
        added.sensors().set(MesosSlave.SLAVE_ACTIVE, active);
        added.sensors().set(MesosSlave.HOSTNAME, hostname);
        added.sensors().set(MesosSlave.ADDRESS, hostname);

        added.start(ImmutableList.of(machine));
        portForwarder.init(hostname, this);

        // Setup subnet tier
        SubnetTier subnetTier =
            added.addChild(
                EntitySpec.create(SubnetTier.class)
                    .configure(SubnetTier.PORT_FORWARDER, portForwarder)
                    .configure(SubnetTier.SUBNET_CIDR, Cidr.UNIVERSAL));
        Entities.start(subnetTier, ImmutableList.of(machine));
        added.sensors().set(MesosSlave.SUBNET_TIER, subnetTier);
      }

      if (active) slaveIds.add(id);
    }
    return slaveIds;
  }
Example #28
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))))));
  }