コード例 #1
0
  @Override
  protected void doTest(Location loc) throws Exception {
    EntityDriverManager entityDriverManager = ctx.getEntityDriverManager();
    entityDriverManager.registerDriver(
        MySqlDriver.class, SshMachineLocation.class, MySqlChefSoloSshDriver.class);

    mysql = app.createAndManageChild(BasicEntitySpec.newInstance(MySqlNode.class));
    app.start(ImmutableList.of(loc));

    EntityTestUtils.assertAttributeEqualsEventually(mysql, SoftwareProcess.SERVICE_UP, true);
  }
コード例 #2
0
  @Override
  protected void doTest(Location loc) throws Exception {
    MongoDbServer entity =
        app.createAndManageChild(BasicEntitySpec.newInstance(MongoDbServer.class));
    app.start(ImmutableList.of(loc));

    EntityTestUtils.assertAttributeEqualsEventually(entity, MongoDbServer.SERVICE_UP, true);

    String id = insert(entity, "hello", "world!");
    DBObject docOut = getById(entity, id);
    assertEquals(docOut.get("hello"), "world!");
  }
コード例 #3
0
 @Test
 public void testReloadBrooklynPropertiesDeploy() {
   brooklynMgmt.reloadBrooklynProperties();
   CampPlatform reloadedPlatform =
       brooklynMgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM);
   Assert.assertNotNull(reloadedPlatform);
   Reader input =
       Streams.reader(
           new ResourceUtils(this).getResourceFromUrl("test-entity-basic-template.yaml"));
   AssemblyTemplate template = reloadedPlatform.pdp().registerDeploymentPlan(input);
   try {
     Assembly assembly =
         template.getInstantiator().newInstance().instantiate(template, reloadedPlatform);
     LOG.info("Test - created " + assembly);
     final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId());
     LOG.info("App - " + app);
     Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template");
     EntityTestUtils.assertAttributeEqualsEventually(app, Startable.SERVICE_UP, true);
   } catch (Exception e) {
     LOG.warn("Unable to instantiate " + template + " (rethrowing): " + e);
     throw Exceptions.propagate(e);
   }
 }
  private void assertAppFunctional(StartableApplication app) throws Exception {
    // expect standard config to (still) be set
    assertNotNull(app.getConfig(WebClusterDatabaseExampleApp.WAR_PATH));
    assertEquals(app.getConfig(WebClusterDatabaseExampleApp.USE_HTTPS), Boolean.FALSE);
    assertNotNull(app.getConfig(WebClusterDatabaseExampleApp.DB_SETUP_SQL_URL));

    // expect entities to be there
    MySqlNode mysql =
        (MySqlNode) Iterables.find(app.getChildren(), Predicates.instanceOf(MySqlNode.class));
    ControlledDynamicWebAppCluster web =
        (ControlledDynamicWebAppCluster)
            Iterables.find(
                app.getChildren(), Predicates.instanceOf(ControlledDynamicWebAppCluster.class));
    final NginxController nginx =
        (NginxController)
            Iterables.find(web.getChildren(), Predicates.instanceOf(NginxController.class));
    DynamicWebAppCluster webCluster =
        (DynamicWebAppCluster)
            Iterables.find(web.getChildren(), Predicates.instanceOf(DynamicWebAppCluster.class));
    Collection<Entity> appservers = web.getMembers();
    assertEquals(appservers.size(), 2);
    String clusterUrl =
        checkNotNull(app.getAttribute(WebClusterDatabaseExampleApp.ROOT_URL), "cluster url");
    String dbUrl = checkNotNull(mysql.getAttribute(MySqlNode.DATASTORE_URL), "database url");
    final String expectedJdbcUrl =
        String.format(
            "jdbc:%s%s?user=%s\\&password=%s",
            dbUrl,
            WebClusterDatabaseExampleApp.DB_TABLE,
            WebClusterDatabaseExampleApp.DB_USERNAME,
            WebClusterDatabaseExampleApp.DB_PASSWORD);

    // expect web-app to be reachable, and wired up to database
    HttpTestUtils.assertHttpStatusCodeEventuallyEquals(clusterUrl, 200);
    for (Entity appserver : appservers) {
      String appserverUrl =
          checkNotNull(
              appserver.getAttribute(JBoss7Server.ROOT_URL), "appserver url of " + appserver);

      HttpTestUtils.assertHttpStatusCodeEventuallyEquals(appserverUrl, 200);
      assertEquals(
          expectedJdbcUrl,
          appserver.getConfig(JavaEntityMethods.javaSysProp("brooklyn.example.db.url")),
          "of " + appserver);
    }

    WebAppMonitor monitor = newWebAppMonitor(clusterUrl, 200);

    // expect auto-scaler policy to be there, and to be functional (e.g. can trigger resize)
    AutoScalerPolicy autoScalerPolicy =
        (AutoScalerPolicy)
            Iterables.find(webCluster.getPolicies(), Predicates.instanceOf(AutoScalerPolicy.class));

    autoScalerPolicy.config().set(AutoScalerPolicy.MIN_POOL_SIZE, 3);
    EntityTestUtils.assertGroupSizeEqualsEventually(web, 3);
    final Collection<Entity> webMembersAfterGrow = web.getMembers();

    for (final Entity appserver : webMembersAfterGrow) {
      Asserts.succeedsEventually(
          MutableMap.of("timeout", Duration.TWO_MINUTES),
          new Runnable() {
            @Override
            public void run() {
              String appserverUrl =
                  checkNotNull(
                      appserver.getAttribute(JBoss7Server.ROOT_URL),
                      "appserver url of " + appserver);
              HttpTestUtils.assertHttpStatusCodeEquals(appserverUrl, 200);
              assertEquals(
                  expectedJdbcUrl,
                  appserver.getConfig(JavaEntityMethods.javaSysProp("brooklyn.example.db.url")),
                  "of " + appserver);
              Asserts.assertEqualsIgnoringOrder(
                  nginx.getAttribute(NginxController.SERVER_POOL_TARGETS).keySet(),
                  webMembersAfterGrow);
            }
          });
    }

    // expect enrichers to be there
    Iterables.find(web.getEnrichers(), Predicates.instanceOf(HttpLatencyDetector.class));
    Iterable<Enricher> propagatorEnrichers =
        Iterables.filter(web.getEnrichers(), Predicates.instanceOf(Propagator.class));
    assertEquals(
        Iterables.size(propagatorEnrichers), 2, "propagatorEnrichers=" + propagatorEnrichers);

    // Check we see evidence of the enrichers having an effect.
    // Relying on WebAppMonitor to stimulate activity.
    EntityTestUtils.assertAttributeEqualsEventually(
        app, WebClusterDatabaseExampleApp.APPSERVERS_COUNT, 3);
    EntityTestUtils.assertAttributeChangesEventually(
        web, DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW);
    EntityTestUtils.assertAttributeChangesEventually(
        app, DynamicWebAppCluster.REQUESTS_PER_SECOND_IN_WINDOW);
    EntityTestUtils.assertAttributeChangesEventually(
        web, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_MOST_RECENT);
    EntityTestUtils.assertAttributeChangesEventually(
        web, HttpLatencyDetector.REQUEST_LATENCY_IN_SECONDS_IN_WINDOW);

    // Restore the web-cluster to its original size of 2
    autoScalerPolicy.config().set(AutoScalerPolicy.MIN_POOL_SIZE, 2);
    EntityTestUtils.assertGroupSizeEqualsEventually(web, 2);

    final Entity removedAppserver =
        Iterables.getOnlyElement(
            Sets.difference(
                ImmutableSet.copyOf(webMembersAfterGrow), ImmutableSet.copyOf(web.getMembers())));
    Asserts.succeedsEventually(
        new Runnable() {
          @Override
          public void run() {
            assertFalse(Entities.isManaged(removedAppserver));
          }
        });

    monitor.assertNoFailures("hitting nginx url");
    monitor.terminate();
  }