org.apache.brooklyn.api.entity.EntitySpec Java Examples

The following examples show how to use org.apache.brooklyn.api.entity.EntitySpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptHelperIntegrationTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups={"Integration","Broken"})
public void testStopCommandWaitsToStopWithSigTerm() {
    StopCommandSoftwareProcess entity = app.createAndManageChild(EntitySpec.create(StopCommandSoftwareProcess.class, StopCommandSoftwareProcessImpl.class));
    entity.start(ImmutableList.of(loc));
    VanillaSoftwareProcessSshDriver driver = (VanillaSoftwareProcessSshDriver) entity.getDriver();
    String launchContents = Joiner.on('\n')
            .join("#!/usr/bin/env bash",
                    "function trap_handler_command {",
                    "  echo stopping...",
                    "  exit 13",
                    "}",
                    "trap \"trap_handler_command\" SIGTERM",
                    "while true; do",
                    "  sleep 1",
                    "done");
    driver.copyResource(ImmutableMap.of(), new ReaderInputStream(new StringReader(launchContents), "UTF-8"), "launch.sh", true);
    driver.executeLaunchCommand("nohup bash launch.sh > /dev/null &");
    ScriptHelper stopCommandScriptHelper = driver.stopCommandScriptHelper();
    stopCommandScriptHelper.execute();
    assertEquals(StringUtils.countMatches(stopCommandScriptHelper.getResultStdout(), "Attempted to stop PID"), 1, "SIGTERM should be tried one time");
    assertFalse(stopCommandScriptHelper.getResultStdout().contains("stopped with SIGKILL"), "SIGKILL should not be sent after SIGTERM fails.");

    SshMachineLocation machineLocation = (SshMachineLocation) Iterables.getFirst(entity.getLocations(), null);
    int checkPidFileExitCode = machineLocation.execCommands("Check for pid file", ImmutableList.of("ls " + driver.getRunDir() + '/' + VanillaSoftwareProcessSshDriver.PID_FILENAME));
    assertEquals(checkPidFileExitCode, 2, "pid file should be deleted.");
}
 
Example #2
Source File: MongoDBRebindIntegrationTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"Integration"})
public void testRebindMongoDb() throws Exception {
    MongoDBServer origEntity = origApp.createAndManageChild(EntitySpec.create(MongoDBServer.class)
            .configure("mongodbConfTemplateUrl", "classpath:///test-mongodb.conf"));
    origApp.start(ImmutableList.of(loc));
    EntityAsserts.assertAttributeEventuallyNonNull(origEntity, MongoDBServer.STATUS_BSON);

    // rebind
    rebind();
    final MongoDBServer newEntity = (MongoDBServer) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MongoDBServer.class));

    // confirm effectors still work on entity
    EntityAsserts.assertAttributeEqualsEventually(newEntity, MongoDBServer.SERVICE_UP, true);
    newEntity.stop();
    EntityAsserts.assertAttributeEqualsEventually(newEntity, MongoDBServer.SERVICE_UP, false);
}
 
Example #3
Source File: TestHttpCallTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups = "Integration")
public void testHttpBodyAssertions() {
    app.createAndManageChild(EntitySpec.create(TestHttpCall.class)
            .configure(TestHttpCall.TARGET_URL, server.getUrl() + "/201")
            .configure(TestHttpCall.TIMEOUT, new Duration(10L, TimeUnit.SECONDS))
            .configure(TestSensor.ASSERTIONS, newAssertion("isEqualTo", "Created - " + testId)));
    app.createAndManageChild(EntitySpec.create(TestHttpCall.class)
            .configure(TestHttpCall.TARGET_URL, server.getUrl() + "/204")
            .configure(TestHttpCall.TIMEOUT, new Duration(10L, TimeUnit.SECONDS))
            .configure(TestSensor.ASSERTIONS, newAssertion("isEqualTo", "")));
    app.createAndManageChild(EntitySpec.create(TestHttpCall.class)
            .configure(TestHttpCall.TARGET_URL, server.getUrl() + "/index.html")
            .configure(TestHttpCall.TIMEOUT, new Duration(10L, TimeUnit.SECONDS))
            .configure(TestSensor.ASSERTIONS, newAssertion("contains", "Im a H1 tag!")));
    app.createAndManageChild(EntitySpec.create(TestHttpCall.class)
            .configure(TestHttpCall.TARGET_URL, server.getUrl() + "/body.json")
            .configure(TestHttpCall.TIMEOUT, new Duration(10L, TimeUnit.SECONDS))
            .configure(TestSensor.ASSERTIONS, newAssertion("matches", ".*123.*")));
    app.createAndManageChild(EntitySpec.create(TestHttpCall.class)
            .configure(TestHttpCall.TARGET_URL, server.getUrl() + "/foo/bar")
            .configure(TestHttpCall.TARGET_METHOD, TestHttpCall.HttpMethod.POST)
            .configure(TestHttpCall.TIMEOUT, new Duration(10L, TimeUnit.SECONDS))
            .configure(TestSensor.ASSERTIONS, newAssertion("isEqualTo", "hello world")));
    app.start(ImmutableList.of(loc));
}
 
Example #4
Source File: PostgreSqlSaltLiveTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Test(groups="Live")
public void testPostgresScriptAndAccess() throws Exception {
    SaltLiveTestSupport.createLocation(mgmt);
    PortRange randomPort = PortRanges.fromString(""+(5420+new Random().nextInt(10))+"+");
    psql = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class, PostgreSqlNodeSaltImpl.class)
            .configure(SaltConfig.MASTERLESS_MODE, true)
            .configure(PostgreSqlNode.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)
            .configure(PostgreSqlNode.POSTGRESQL_PORT, randomPort));

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

    String url = psql.getAttribute(PostgreSqlNode.DATASTORE_URL);
    log.info("Trying to connect to "+psql+" at "+url);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.contains("542"));

    new VogellaExampleAccess("org.postgresql.Driver", url).readModifyAndRevertDataBase();
}
 
Example #5
Source File: Jboss7ServerGoogleComputeLiveTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Override
protected void doTest(Location loc) throws Exception {
    final JBoss7Server server = app.createAndManageChild(EntitySpec.create(JBoss7Server.class)
            .configure("war", getTestWar()));
    
    app.start(ImmutableList.of(loc));
    
    String url = server.getAttribute(JBoss7Server.ROOT_URL);
    
    HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200);
    HttpTestUtils.assertContentContainsText(url, "Hello");
    
    Asserts.succeedsEventually(new Runnable() {
        @Override public void run() {
            assertNotNull(server.getAttribute(JBoss7Server.REQUEST_COUNT));
            assertNotNull(server.getAttribute(JBoss7Server.ERROR_COUNT));
            assertNotNull(server.getAttribute(JBoss7Server.TOTAL_PROCESSING_TIME));
            assertNotNull(server.getAttribute(JBoss7Server.MAX_PROCESSING_TIME));
            assertNotNull(server.getAttribute(JBoss7Server.BYTES_RECEIVED));
            assertNotNull(server.getAttribute(JBoss7Server.BYTES_SENT));
        }});
}
 
Example #6
Source File: HotStandbyTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testHotStandbyDoesNotStartFeeds() throws Exception {
    HaMgmtNode n1 = createMaster(Duration.PRACTICALLY_FOREVER);
    TestApplication app = createFirstAppAndPersist(n1);
    TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithFunctionFeedImpl.class));
    forcePersistNow(n1);
    Assert.assertTrue(entity.feeds().getFeeds().size() > 0, "Feeds: "+entity.feeds().getFeeds());
    for (Feed feed : entity.feeds().getFeeds()) {
        assertTrue(feed.isRunning(), "Feed expected running, but it is non-running");
    }

    HaMgmtNode n2 = createHotStandby(Duration.PRACTICALLY_FOREVER);
    TestEntity entityRO = (TestEntity) n2.mgmt.lookup(entity.getId(), Entity.class);
    Assert.assertTrue(entityRO.feeds().getFeeds().size() > 0, "Feeds: "+entity.feeds().getFeeds());
    for (Feed feedRO : entityRO.feeds().getFeeds()) {
        assertFalse(feedRO.isRunning(), "Feed expected non-active, but it is running");
    }
}
 
Example #7
Source File: TestSshCommandTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncludeEnv() throws Exception {
    Map<String, Object> env = ImmutableMap.<String, Object>of("ENV1", "val1", "ENV2", "val2");
    
    TestSshCommand test = app.createAndManageChild(EntitySpec.create(TestSshCommand.class)
        .configure(TARGET_ENTITY, testEntity)
        .configure(COMMAND, "mycmd")
        .configure(SHELL_ENVIRONMENT, env));

    app.start(ImmutableList.<Location>of());

    assertEntityHealthy(test);
    
    ExecCmd cmdExecuted = RecordingSshTool.getLastExecCmd();
    assertThat(cmdExecuted.commands).isEqualTo(ImmutableList.of("mycmd"));
    assertThat(cmdExecuted.env).isEqualTo(env);
}
 
Example #8
Source File: SequenceEntityTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testSequenceReset() throws Exception {
    sequence = app.addChild(EntitySpec.create(SequenceEntity.class));
    app.start(ImmutableList.of(loc1));

    assertAttributeEqualsEventually(sequence, Startable.SERVICE_UP, true);

    assertEquals(sequence.get(), Integer.valueOf(1));

    sequence.increment();
    sequence.increment();
    sequence.increment();

    assertEquals(sequence.get(), Integer.valueOf(4));
    assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 4);

    sequence.invoke(SequenceEntity.RESET, ImmutableMap.<String, Object>of()).getUnchecked();

    assertEquals(sequence.get(), Integer.valueOf(1));
    assertAttributeEquals(sequence, SequenceEntity.SEQUENCE_VALUE, 1);
}
 
Example #9
Source File: EntityExecutionManagerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public void testGcTaskAtEntityLimit() throws Exception {
    final TestEntity e = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    
    ((BrooklynProperties)app.getManagementContext().getConfig()).put(
        BrooklynGarbageCollector.MAX_TASKS_PER_ENTITY, 2);
    
    AtomicBoolean stopCondition = new AtomicBoolean();
    scheduleRecursiveTemporaryTask(stopCondition, e, "boring-tag");
    scheduleRecursiveTemporaryTask(stopCondition, e, "boring-tag");
    scheduleRecursiveTemporaryTask(stopCondition, app, "boring-tag");
    scheduleRecursiveTemporaryTask(stopCondition, app, "boring-tag");

    for (int count=0; count<5; count++)
        runEmptyTaskWithNameAndTags(e, "task-e-"+count, ManagementContextInternal.NON_TRANSIENT_TASK_TAG, "boring-tag");
    for (int count=0; count<5; count++)
        runEmptyTaskWithNameAndTags(app, "task-app-"+count, ManagementContextInternal.NON_TRANSIENT_TASK_TAG, "boring-tag");

    // Makes sure there's a GC while the transient tasks are running
    forceGc();
    stopCondition.set(true);

    assertTaskMaxCountForEntityEventually(app, 2);
    assertTaskMaxCountForEntityEventually(e, 2);
}
 
Example #10
Source File: VanillaWindowsProcessWinrmStreamsLiveTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups = "Live")
@Override
public void testGetsStreams() {
    VanillaWindowsProcess entity = app.createAndManageChild(EntitySpec.create(VanillaWindowsProcess.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "echo " + getCommands().get("winrm: pre-install-command.*"))
            .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "echo " + getCommands().get("winrm: install.*"))
            .configure(VanillaSoftwareProcess.POST_INSTALL_COMMAND, "echo " + getCommands().get("winrm: post-install-command.*"))
            .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, "echo " + getCommands().get("winrm: customize.*"))
            .configure(VanillaSoftwareProcess.PRE_LAUNCH_COMMAND, "echo " + getCommands().get("winrm: pre-launch-command.*"))
            .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "echo " + getCommands().get("winrm: launch.*"))
            .configure(VanillaSoftwareProcess.POST_LAUNCH_COMMAND, "echo " + getCommands().get("winrm: post-launch-command.*"))
            .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "echo true"));
    app.start(ImmutableList.of(machine));
    assertStreams(entity);
}
 
Example #11
Source File: DeployFailureTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testFailedGetParent() throws Exception {
    entityManager.getAllEntitiesInApplication(app);

    try {
        mgmt.getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)
                .child(EntitySpec.create(TestEntity.class)
                        .impl(TestEntityFailingGetParentImpl.class)));
        Asserts.shouldHaveFailedPreviously();
    } catch (ClassCastException e) {
        // TODO Should give nicer exception
        Asserts.expectedFailureContains(e, "cannot be cast", "WrongParentEntity");
    }

    // This should continue to work, after the failed entity-deploy above
    // See https://issues.apache.org/jira/browse/BROOKLYN-599
    entityManager.getAllEntitiesInApplication(app);

    // Should have disposed of entities that failed to be created
    assertEntitiesNotKnown(constructedEntities);
}
 
Example #12
Source File: BasicSpecParameter.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static List<SpecParameter<?>> fromSpec(ManagementContext mgmt, AbstractBrooklynObjectSpec<?, ?> spec) {
    if (!spec.getParameters().isEmpty()) {
        return spec.getParameters();
    }
    Class<?> type = null;
    if (spec instanceof EntitySpec) {
        EntitySpec<?> entitySpec = (EntitySpec<?>)spec;
        if (entitySpec.getImplementation() != null) {
            type = entitySpec.getImplementation();
        }
    }
    if (type == null) {
        type = getImplementedBy(mgmt, spec.getType());
    }
    return ParseClassParameters.collectParameters(getImplementedBy(mgmt, type));
}
 
Example #13
Source File: LoopOverGroupMembersTestCaseTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleChildrenWhichPass() {
    Set<EmptySoftwareProcess> emptySoftwareProcesses = addMultipleEmptySoftwareProcessesToGroup(4);
    EntitySpec<TestSensor> testSpec = createPassingTestSensorSpec();

    LoopOverGroupMembersTestCase loopOverGroupMembersTestCase = app.addChild(EntitySpec.create(LoopOverGroupMembersTestCase.class)
            .configure(LoopOverGroupMembersTestCase.TEST_SPEC, testSpec)
            .configure(LoopOverGroupMembersTestCase.TARGET_ENTITY, testGroup));

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

    assertThat(loopOverGroupMembersTestCase.getChildren().size()).isEqualTo(4);
    assertThat(loopOverGroupMembersTestCase.sensors().get(SERVICE_UP)).isTrue();

    for (Entity loopChildEntity : loopOverGroupMembersTestCase.getChildren()) {
        assertThat(loopChildEntity).isInstanceOf(TestSensor.class);
        assertThat(loopChildEntity.sensors().get(SERVICE_UP)).isTrue();
        assertThat(emptySoftwareProcesses.contains(loopChildEntity.config().get(LoopOverGroupMembersTestCase.TARGET_ENTITY))).isTrue();
        emptySoftwareProcesses.remove(loopChildEntity.config().get(LoopOverGroupMembersTestCase.TARGET_ENTITY));
    }
}
 
Example #14
Source File: TargetableTestComponentTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testTargetEntityByIdNotFound() {
    app.addChild(EntitySpec.create(TestSensor.class)
            .configure(TestSensor.TARGET_ID, "myTargetId")
            .configure(TestSensor.SENSOR_NAME, STRING_SENSOR.getName())
            .configure(TestSensor.ASSERTIONS, ImmutableList.of(ImmutableMap.of("equals", "myval"))));

    try {
        app.start(ImmutableList.<Location>of());
        Asserts.shouldHaveFailedPreviously();
    } catch (Exception e) {
        NoSuchElementException e2 = Exceptions.getFirstThrowableOfType(e, NoSuchElementException.class);
        if (e2 == null) throw e;
        Asserts.expectedFailureContains(e2, "No entity matching id myTargetId");
    }
}
 
Example #15
Source File: EnrichersTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testAggregatingGroupSum() {
    TestEntity child1 = group.addChild(EntitySpec.create(TestEntity.class));
    group.addMember(entity);
    group.addMember(entity2);
    group.enrichers().add(Enrichers.builder()
            .aggregating(NUM1)
            .publishing(NUM2)
            .fromMembers()
            .computingSum()
            .build());
    
    child1.sensors().set(NUM1, 1);
    entity.sensors().set(NUM1, 2);
    entity2.sensors().set(NUM1, 3);
    EntityAsserts.assertAttributeEqualsEventually(group, NUM2, 5);
}
 
Example #16
Source File: BasicLauncher.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void startBrooklynNode() {
    final String classpath = System.getenv("INITIAL_CLASSPATH");
    if (Strings.isBlank(classpath)) {
        LOG.warn("Cannot find INITIAL_CLASSPATH environment variable, skipping BrooklynNode entity creation");
        return;
    }

    EntitySpec<LocalBrooklynNode> brooklynNodeSpec = EntitySpec.create(LocalBrooklynNode.class)
        .configure(SoftwareProcess.ENTITY_STARTED, true)
        .configure(BrooklynNode.CLASSPATH, Splitter.on(":").splitToList(classpath))
        .displayName("Brooklyn Console");

    brooklynNodeSpec = customizeBrooklynNodeSpec(brooklynNodeSpec);

    if (brooklynNodeSpec != null) {
        EntityManagementUtils.createStarting(managementContext,
                EntitySpec.create(BasicApplication.class)
                    .displayName("Brooklyn")
                    .child(brooklynNodeSpec));
    }
}
 
Example #17
Source File: AccessManagerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testLocationManagementAllowed() throws Exception {
    // default is allowed
    Location loc1 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));

    // when forbidden, should give error
    mgmt.getAccessManager().setLocationManagementAllowed(false);
    try {
        mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
        fail();
    } catch (Exception e) {
        // expect it to be forbidden
        if (Exceptions.getFirstThrowableOfType(e, IllegalStateException.class) == null) {
            throw e;
        }
    }

    // but when forbidden, still allowed to create entity
    mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    
    // when re-enabled, can create entities again
    mgmt.getAccessManager().setLocationManagementAllowed(true);
    Location loc3 = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
    
    assertEquals(ImmutableSet.copyOf(mgmt.getLocationManager().getLocations()), ImmutableSet.of(loc1, loc3));
}
 
Example #18
Source File: TestCaseTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testAbortsOnFailure() throws Exception {
    // continueOnFailure defaults to false
    TestCase testCase = app.createAndManageChild(EntitySpec.create(TestCase.class)
            .child(EntitySpec.create(FailingEntity.class)
                    .configure(FailingEntity.FAIL_ON_START, true))
            .child(EntitySpec.create(TestEntity.class).displayName("child2")));
    
    try {
        app.start(locs);
        Asserts.shouldHaveFailedPreviously();
    } catch (Throwable t) {
        Asserts.expectedFailureContains(t, "Simulating entity start failure for test");
    }

    TestEntity child2 = (TestEntity) Iterables.tryFind(testCase.getChildren(), EntityPredicates.displayNameEqualTo("child2")).get();
    assertEquals(child2.getCallHistory(), ImmutableList.of());
}
 
Example #19
Source File: BrooklynLauncherRebindTestFixture.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testRebindCanAddNewApps() throws Exception {
    populatePersistenceDir(persistenceDir, EntitySpec.create(TestApplication.class).displayName("myorig"));
    
    // Rebind to the app we started last time
    newLauncherDefault(PersistMode.REBIND)
            .application(EntitySpec.create(TestApplication.class).displayName("mynew"))
            .start();
    
    // New app was added, and orig app was rebound
    assertEquals(lastMgmt().getApplications().size(), 2, "apps="+lastMgmt().getApplications());
    assertNotNull(Iterables.find(lastMgmt().getApplications(), EntityPredicates.displayNameEqualTo("mynew"), null), "apps="+lastMgmt().getApplications());

    // And subsequently can create new apps
    StartableApplication app3 = lastMgmt().getEntityManager().createEntity(
            EntitySpec.create(TestApplication.class).displayName("mynew2"));
    app3.start(ImmutableList.<Location>of());
}
 
Example #20
Source File: QpidIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
/**
 * Test that the broker starts up with JMX and RMI ports configured, and sets SERVICE_UP correctly.
 */
@Test(groups = "Integration")
public void canStartupAndShutdown() {
    qpid = app.createAndManageChild(EntitySpec.create(QpidBroker.class)
            .configure("jmxPort", "9909+")
            .configure("rmiRegistryPort", "9910+"));
    qpid.start(ImmutableList.of(testLocation));
    EntityAsserts.assertAttributeEqualsEventually(qpid, Startable.SERVICE_UP, true);
    qpid.stop();
    assertFalse(qpid.getAttribute(Startable.SERVICE_UP));
}
 
Example #21
Source File: EntityConfigUsageTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigSetToGroovyTruthFalseIsAvailable() throws Exception {
    TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
            .configure(intKeyWithDefault, 0));
    
    assertEquals(entity.getConfig(intKeyWithDefault), (Integer)0);
}
 
Example #22
Source File: WebAppLiveIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Test(groups = "Live", dataProvider="basicEntities")
public void testStartsWebAppInAws(final EntitySpec<JavaWebAppSoftwareProcess> spec) {
    JavaWebAppSoftwareProcess server = app.createAndManageChild(spec);
    server.start(ImmutableList.of(loc));
    EntityAsserts.assertAttributeEqualsEventually(ImmutableMap.of("timeout", Duration.seconds(75)),
            server, Attributes.SERVICE_UP, Boolean.TRUE);
}
 
Example #23
Source File: ItemsInContainersGroupTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private MockContainerEntity newContainer(TestApplication app, String name, String membership) {
    MockContainerEntity container = app.createAndManageChild(EntitySpec.create(MockContainerEntity.class)
                    .displayName(name)
                    .configure(MockContainerEntity.MOCK_MEMBERSHIP, membership));
    container.start(ImmutableList.of(loc));
    return container;
}
 
Example #24
Source File: CassandraDatacenterIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
/**
 * Cassandra v2 needs Java >= 1.7. If you have java 6 as the defult locally, then you can use
 * something like {@code .configure("shell.env", MutableMap.of("JAVA_HOME", "/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"))}
 */
@Test(groups = "Integration")
public void testStartAndShutdownClusterSizeOneCassandraVersion2() throws Exception {
    String version = "2.0.9";
    
    EntitySpec<CassandraDatacenter> spec = EntitySpec.create(CassandraDatacenter.class)
            .configure(CassandraNode.SUGGESTED_VERSION, version)
            .configure("initialSize", 1);
    runStartAndShutdownClusterSizeOne(spec, false);
}
 
Example #25
Source File: JmxFeedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubscribeToJmxNotificationAndEmitCorrespondingNotificationSensor() throws Exception {
    final TestApplication app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
    final EntityWithEmitter entity = app2.addChild(EntitySpec.create(EntityWithEmitter.class));
    
    try {
        app2.start(ImmutableList.of(new SimulatedLocation()));
        
        final List<SensorEvent<String>> received = Lists.newArrayList();
        app2.subscriptions().subscribe(null, EntityWithEmitter.MY_NOTIF, new SensorEventListener<String>() {
            @Override
            public void onEvent(SensorEvent<String> event) {
                received.add(event);
            }});

        final StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of("one"), objectName);
        final AtomicInteger sequence = new AtomicInteger(0);
        
        jmxHelper.connect(TIMEOUT_MS);
        jmxHelper.addNotificationListener(jmxObjectName, new NotificationListener() {
                @Override
                public void handleNotification(Notification notif, Object callback) {
                    if (notif.getType().equals("one")) {
                        entity.sensors().emit(EntityWithEmitter.MY_NOTIF, (String) notif.getUserData());
                    }
                }});
        

        Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
            @Override
            public void run() {
                sendNotification(mbean, "one", sequence.getAndIncrement(), "abc");
                assertTrue(received.size() > 0, "received size should be bigger than 0");
                assertEquals(received.get(0).getValue(), "abc");
            }});
    } finally {
        Entities.destroyAll(app2.getManagementContext());
    }
}
 
Example #26
Source File: ActiveMQIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
/**
 * Test that the broker starts up and sets SERVICE_UP correctly.
 */
@Test(groups = "Integration")
public void canStartupAndShutdown() throws Exception {
    activeMQ = app.createAndManageChild(EntitySpec.create(ActiveMQBroker.class));

    activeMQ.start(ImmutableList.of(testLocation));
    EntityAsserts.assertAttributeEqualsEventually(ImmutableMap.of("timeout", 10*60*1000), activeMQ, Startable.SERVICE_UP, true);
    log.info("JMX URL is "+activeMQ.getAttribute(UsesJmx.JMX_URL));
    activeMQ.stop();
    assertFalse(activeMQ.getAttribute(Startable.SERVICE_UP));
}
 
Example #27
Source File: AbstractYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected Application createApplicationUnstarted(String yaml) throws Exception {
    // not starting the app (would have happened automatically if we use camp to instantiate, 
    // but not if we use create spec approach).
    EntitySpec<Application> spec = createAppEntitySpec(yaml);
    final Entity app = brooklynMgmt.getEntityManager().createEntity(spec);
    return (Application) app;
}
 
Example #28
Source File: MongoDBShardedDeploymentEc2LiveTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void doTest(Location loc) throws Exception {
    final MongoDBShardedDeployment deployment = app.createAndManageChild(EntitySpec.create(MongoDBShardedDeployment.class)
            .configure(MongoDBShardedDeployment.INITIAL_ROUTER_CLUSTER_SIZE, ROUTER_CLUSTER_SIZE)
            .configure(MongoDBShardedDeployment.SHARD_REPLICASET_SIZE, REPLICASET_SIZE)
            .configure(MongoDBShardedDeployment.INITIAL_SHARD_CLUSTER_SIZE, SHARD_CLUSTER_SIZE)
            .configure(MongoDBShardedDeployment.MONGODB_REPLICA_SET_SPEC, EntitySpec.create(MongoDBReplicaSet.class)
                    .configure(MongoDBServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb.conf")
                    .configure(MongoDBReplicaSet.MEMBER_SPEC, EntitySpec.create(MongoDBServer.class)))
            .configure(MongoDBShardedDeployment.MONGODB_ROUTER_SPEC, EntitySpec.create(MongoDBRouter.class)
                    .configure(MongoDBConfigServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb-router.conf"))
            .configure(MongoDBShardedDeployment.MONGODB_CONFIG_SERVER_SPEC, EntitySpec.create(MongoDBConfigServer.class)
                    .configure(MongoDBConfigServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb-configserver.conf")));

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

    Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT), new Runnable() {
        @Override
        public void run() {
            Assert.assertEquals(deployment.getRouterCluster().getCurrentSize(), ROUTER_CLUSTER_SIZE);
            Assert.assertEquals(deployment.getShardCluster().getCurrentSize(), SHARD_CLUSTER_SIZE);
            Assert.assertEquals(deployment.getConfigCluster().getCurrentSize(), MongoDBShardedDeployment.CONFIG_CLUSTER_SIZE.getDefaultValue());
            for (Entity entity : deployment.getShardCluster().getMembers()) {
                Assert.assertEquals(((MongoDBReplicaSet) entity).getCurrentSize(), REPLICASET_SIZE);
            }
        }
    });
}
 
Example #29
Source File: JcloudsByonLocationResolverStubbedRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
@BeforeMethod(alwaysRun=true)
public void setUp() throws Exception {
    mementoDir = Os.newTempDir(getClass());
    File mementoDirParent = mementoDir.getParentFile();
    mementoDirBackup = new File(mementoDirParent, mementoDir.getName()+"."+Identifiers.makeRandomId(4)+".bak");

    origManagementContext = createOrigManagementContext();
    origApp = origManagementContext.getEntityManager().createEntity(EntitySpec.create(BasicApplication.class));
    LOG.info("Test "+getClass()+" persisting to "+mementoDir);
    
    super.setUp();
    
    initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of());
}
 
Example #30
Source File: ConfigEntityInheritanceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigKeysExtAndImplIntTwoRight() throws Exception {
    // this mirrors the bug observed in kafka entities;
    // the right-side interface normally dominates, but not when it is transitive
    // (although we shouldn't rely on order in any case;
    // new routines check whether one config key extends another and if so it takes the extending one)
    checkKeys(app.addChild(EntitySpec.create(MyEntityHereExtendingAndImplementingInterfaceImplementingTwoRight.class)), 4);
}