org.apache.brooklyn.core.entity.StartableApplication Java Examples

The following examples show how to use org.apache.brooklyn.core.entity.StartableApplication. 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: HttpCommandEffectorYamlRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void runRebindWhenIsUp(String catalogYaml, String appId) throws Exception {
   addCatalogItems(catalogYaml);

   String appYaml = Joiner.on("\n").join(
           "services: ",
           "- type: " + appId);
   createStartWaitAndLogApplication(appYaml);

   // Rebind
   StartableApplication newApp = rebind();
   TestEntity testEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
   Effector effector = assertHasInitializers(testEntity, "myEffector");

   // Confirm HttpCommandEffector still functions
   Object result = testEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
   assertEquals(((String)result).trim(), "myId");
}
 
Example #2
Source File: SeaCloudsManagementPolicy.java    From SeaCloudsPlatform with Apache License 2.0 6 votes vote down vote up
private Effector<Void> newStopEffector() {
    return Effectors.effector(Startable.STOP)
            .parameter(SoftwareProcess.StopSoftwareParameters.STOP_PROCESS_MODE)
            .parameter(SoftwareProcess.StopSoftwareParameters.STOP_MACHINE_MODE)
            .impl(new EffectorBody<Void>() {
                @Override
                public Void call(ConfigBag parameters) {
                    LOG.info("Stopping SeaCloudsInitializerPolicy " + "for " + entity.getId());
                    removeSlaAgreement();
                    removeMonitoringRules();
                    removeInfluxDbObservers();
                    removeGrafanaDashboard();

                    // Rewire the original behaviour
                    ((StartableApplication) entity).stop();

                    return null;
                }
            })
            .build();
}
 
Example #3
Source File: SeaCloudsManagementPolicy.java    From SeaCloudsPlatform with Apache License 2.0 6 votes vote down vote up
private Effector<Void> newStartEffector() {
    return Effectors.effector(Startable.START)
            .impl(new EffectorBody<Void>() {
                @Override
                public Void call(ConfigBag parameters) {
                    LOG.info("Starting SeaCloudsInitializerPolicy " + "for " + entity.getId());
                    installSLA();
                    installMonitoringRules();
                    notifyRulesReady();
                    installInfluxDbObservers();
                    installGrafanaDashboards();

                    // Rewire the original behaviour
                    Collection<? extends Location> locations = null;
                    Object locationRaw = parameters.getStringKey(EffectorStartableImpl.StartParameters.LOCATIONS.getName());
                    locations = Locations.coerceToCollectionOfLocationsManaged(getManagementContext(), locationRaw);
                    ((StartableApplication) entity).start(locations);

                    return null;
                }
            })
            .build();
}
 
Example #4
Source File: EffectorBasicTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeEffectorListWithEmptyUsingUnmanagedContext() throws Exception {
    // Previously this threw the IllegalStateException directly, because DynamicTasks called
    // ((EntityInternal)entity).getManagementSupport().getExecutionContext();
    // (so it successfully called getManagementSupport, and then hit the exception.
    // Now it calls ((EntityInternal)entity).getExecutionContext(), so the exception happens in
    // the entity-proxy and is thus wrapped.
    TestEntity entity = app.addChild(EntitySpec.create(TestEntity.class));
    Entities.unmanage(entity);
    try {
        Entities.invokeEffectorList(entity, ImmutableList.<StartableApplication>of(), Startable.STOP).get(Duration.THIRTY_SECONDS);
        Asserts.shouldHaveFailedPreviously();
    } catch (Exception e) {
        IllegalStateException e2 = Exceptions.getFirstThrowableOfType(e, IllegalStateException.class);
        if (e2 == null) throw e;
        Asserts.expectedFailureContains(e2, "no longer managed");
    }
}
 
Example #5
Source File: BasicStartableTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #6
Source File: InfrastructureDeploymentTestCaseTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoInfrastructureSpec() {
    List<EntitySpec<? extends Startable>> testSpecs = ImmutableList.<EntitySpec<? extends Startable>>of(EntitySpec.create(StartableApplication.class));

    InfrastructureDeploymentTestCase infrastructureDeploymentTestCase = app.createAndManageChild(EntitySpec.create(InfrastructureDeploymentTestCase.class));
    infrastructureDeploymentTestCase.config().set(InfrastructureDeploymentTestCase.ENTITY_SPEC_TO_DEPLOY, testSpecs);
    infrastructureDeploymentTestCase.config().set(InfrastructureDeploymentTestCase.DEPLOYMENT_LOCATION_SENSOR_NAME, DEPLOYMENT_LOCATION_SENSOR.getName());

    try {
        app.start(ImmutableList.of(app.newSimulatedLocation()));
        Asserts.shouldHaveFailedPreviously();
    } catch (Throwable throwable) {
        Asserts.expectedFailureContains(throwable, "EntitySpec", "not configured");
    }

    assertThat(infrastructureDeploymentTestCase.sensors().get(SERVICE_UP)).isFalse();
}
 
Example #7
Source File: CliTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testStopAllApplications() throws Exception {
    LaunchCommand launchCommand = new Main.LaunchCommand();
    ManagementContext mgmt = LocalManagementContextForTests.newInstance();
    
    try {
        StartableApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(StartableApplication.class).impl(ExampleApp.class));
        ExampleApp appImpl = (ExampleApp) Entities.deproxy(app);
        SimulatedLocation loc = mgmt.getLocationManager().createLocation(LocationSpec.create(SimulatedLocation.class));
        app.start(ImmutableList.of(loc));
        assertTrue(appImpl.running);
        
        launchCommand.stopAllApps(ImmutableList.of(app));
        assertFalse(appImpl.running);
    } finally {
        // Stopping the app will make app.getManagementContext return the "NonDeploymentManagementContext";
        if (mgmt != null) Entities.destroyAll(mgmt);
    }
}
 
Example #8
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 #9
Source File: ServiceFailureDetectorYamlRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void runRebindWhenNotUp(String catalogYaml, String appId) throws Exception {
    addCatalogItems(catalogYaml);

    String appYaml = Joiner.on("\n").join(
            "services:",
            "- type: " + appId);
    Entity app = createStartWaitAndLogApplication(appYaml);
    
    // Make entity go on-fire
    TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
    RecordingSensorEventListener<Object> listener = subscribeToHaSensors(entity);
    ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Simulating a problem");
    listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED));

    // Rebind
    StartableApplication newApp = rebind();
    TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
    assertHasEnricher(newEntity, ServiceFailureDetector.class);
    
    // Confirm ServiceFailureDetector still functions
    RecordingSensorEventListener<Object> newListener = subscribeToHaSensors(newEntity);
    
    ServiceNotUpLogic.clearNotUpIndicator(newEntity, INDICATOR_KEY_1);
    newListener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_RECOVERED));
    newListener.assertEventCount(1);
}
 
Example #10
Source File: ServiceFailureDetectorYamlRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void runRebindWhenHealthy(String catalogYaml, String appId) throws Exception {
    addCatalogItems(catalogYaml);

    String appYaml = Joiner.on("\n").join(
            "services:",
            "- type: " + appId);
    createStartWaitAndLogApplication(appYaml);

    // Rebind
    StartableApplication newApp = rebind();
    TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
    assertHasEnricher(newEntity, ServiceFailureDetector.class);
    
    // Confirm ServiceFailureDetector still functions
    RecordingSensorEventListener<Object> listener = subscribeToHaSensors(newEntity);
    
    ServiceNotUpLogic.updateNotUpIndicator(newEntity, INDICATOR_KEY_1, "Simulate a problem");
    listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED));
    listener.assertEventCount(1);
}
 
Example #11
Source File: LocationExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void testProvisioningPropertyInheritance() throws Exception {
    String yaml = Joiner.on("\n").join(
            "services:",
            "- type: "+EmptySoftwareProcess.class.getName(),
            "  provisioning.properties:",
            "      simple: 42",
            "      my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")",
            "location: localhost");

    origApp = (StartableApplication) createAndStartApplication(new StringReader(yaml));

    Entity entity = Iterables.getOnlyElement( origApp.getChildren() );
    Location l = Iterables.getOnlyElement( entity.getLocations() );
    assertEquals(l.config().get(ConfigKeys.builder(Integer.class, "simple").build()), (Integer)42);
    assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
            
    Maybe<Object> rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
    Assert.assertTrue(rawConfig.isPresentAndNonNull());
    Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred raw value; got "+rawConfig.get());
}
 
Example #12
Source File: LocationExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void testLocalhostInheritance() throws Exception {
    String yaml = Joiner.on("\n").join(
            "services:",
            "- type: "+EmptySoftwareProcess.class.getName(),
            "location:",
            "  localhost:",
            "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");

    origApp = (StartableApplication) createAndStartApplication(new StringReader(yaml));

    Entity entity = Iterables.getOnlyElement( origApp.getChildren() );
    Location l = Iterables.getOnlyElement( entity.getLocations() );
    assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
            
    Maybe<Object> rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
    Assert.assertTrue(rawConfig.isPresentAndNonNull());
    Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred raw value; got "+rawConfig.get());
}
 
Example #13
Source File: CompositeEffectorYamlRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void runRebindWhenIsUp(String catalogYaml, String appId) throws Exception {
   addCatalogItems(catalogYaml);

   String appYaml = Joiner.on("\n").join(
           "services: ",
           "- type: " + appId);
   Entity app = createStartWaitAndLogApplication(appYaml);
   TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
   
   // start was overridden, so java method not called; but composite will have called "testEntity.myEffector"
   assertEquals(entity.getCallHistory(), ImmutableList.of("myEffector"));
   entity.clearCallHistory();
   
   // Rebind
   StartableApplication newApp = rebind();
   TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity"));
   Effector<?> effector = assertHasInitializers(newEntity, "start");

   // Confirm HttpCommandEffector still functions
   Object results = newEntity.invoke(effector, ImmutableMap.<String, Object>of()).get();
   assertEquals(results, MutableList.of("myId", null));
   
   assertEquals(newEntity.getCallHistory(), ImmutableList.of("myEffector"));
}
 
Example #14
Source File: RebindOsgiTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testValInEntityFromOtherBundle() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OSGI_BUNDLE_PATH);

    installBundle(mgmt(), OSGI_BUNDLE_URL);
    bundleUrlsToInstallOnRebind.add(OSGI_BUNDLE_URL);
    
    // Create an app, using that catalog item
    String appBlueprintYaml = Joiner.on("\n").join(
            "services:",
            "- type: " + TestEntity.class.getName());
    origApp = (StartableApplication) createAndStartApplication(appBlueprintYaml);
    Entity origEntity = Iterables.getOnlyElement(origApp.getChildren());

    Object configVal = newOsgiSimpleObject("myEntityConfigVal");
    origEntity.config().set(ConfigKeys.newConfigKey(Object.class, OSGI_ENTITY_CONFIG_NAME), configVal);
    
    // Rebind
    rebind();

    // Ensure app is still there, and that it is usable - e.g. "stop" effector functions as expected
    Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());

    Object newConfigVal = newEntity.config().get(ConfigKeys.newConfigKey(Object.class, OSGI_ENTITY_CONFIG_NAME));
    assertOsgiSimpleObjectsEqual(newConfigVal, configVal);
}
 
Example #15
Source File: AbstractLoadTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
protected <T extends StartableApplication> Callable<T> newProvisionAppTask(final EntitySpec<T> appSpec) {
    return new Callable<T>() {
        public T call() {
            try {
                Stopwatch stopwatch = Stopwatch.createStarted();
                T app = mgmt().getEntityManager().createEntity(appSpec);
                app.start(ImmutableList.of(localhost));
                Duration duration = Duration.of(stopwatch.elapsed(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
                LOG.info("Provisioning time: "+duration);
                provisioningTimes.add(duration);

                return app;
            } catch (Throwable t) {
                LOG.error("Error deploying app (rethrowing)", t);
                throw Exceptions.propagate(t);
            }
        }
    };
}
 
Example #16
Source File: CatalogYamlRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
private void doTestLongReferenceSequence() throws Exception {
    // adds a0, a1 extending a0, a2 extending a1, ... a9 extending a8
    // osgi rebind of types can fail because bundles are restored in any order
    // and dependencies might not yet be installed;
    // ensure items are added first without validation, then validating
    for (int i = 0; i<10; i++) {
        addCatalogItems(
            "brooklyn.catalog:",
            "  id: a" + i,
            "  version: 1",
            "  itemType: entity",
            "  item:",
            "    type: " + (i==0 ? BasicEntity.class.getName() : "a" + (i-1)));
    }
    origApp = (StartableApplication) createAndStartApplication("services: [ { type: a9 } ]");
    rebind();
    Entity child = Iterables.getOnlyElement( newApp.getChildren() );
    Asserts.assertTrue(child instanceof BasicEntity);
    Asserts.assertEquals(child.getCatalogItemId(), "a9:1");
}
 
Example #17
Source File: AbstractYamlRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
protected StartableApplication rebind(RebindOptions options) throws Exception {
    StartableApplication result = super.rebind(options);
    if (launcher != null) {
        launcher.stopServers();
        launcher = new BrooklynCampPlatformLauncherNoServer() {
            @Override
            protected LocalManagementContext newMgmtContext() {
                return (LocalManagementContext) mgmt();
            }
        };
        launcher.launch();
        platform = launcher.getCampPlatform();
    }
    return result;
}
 
Example #18
Source File: CatalogOsgiVersionMoreEntityRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testRebindAppIncludingBundleAllWorksAndPreservesChecksum() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V1_PATH);
    ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( 
        new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V1_URL) );
    
    RegisteredType item = mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
    Assert.assertNotNull(item);
    Assert.assertEquals(item.getContainingBundle(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL+":"+"0.1.0");
    
    ManagedBundle mb = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundle(VersionedName.fromString(item.getContainingBundle()));
    Assert.assertNotNull(mb);
    String c1 = mb.getChecksum();
    Assert.assertTrue(Strings.isNonBlank(c1), "Missing checksum for bundle");

    Map<String, ManagedBundle> bundles1 = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles();
    
    createAndStartApplication("services: [ { type: "+BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY+" } ]");
    
    StartableApplication newApp = rebind();

    // bundles installed
    Map<String, ManagedBundle> bundles = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles();
    Asserts.assertEquals(bundles, bundles1);
    
    //item installed
    item = mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
    Assert.assertNotNull(item);
    Assert.assertEquals(item.getContainingBundle(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL+":"+"0.1.0");
    
    // containing bundle set, matches, and checksum matches
    mb = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundle(VersionedName.fromString(item.getContainingBundle()));
    Assert.assertEquals(mb, bundles.get(mb.getId()));
    Assert.assertEquals(mb.getChecksum(), c1, "checksums should be the same after rebinding");
    
    Assert.assertNotNull(newApp);
}
 
Example #19
Source File: WebClusterDatabaseExampleApp.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) {
    List<String> args = Lists.newArrayList(argv);
    String port =  CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION);

    BrooklynLauncher launcher = BrooklynLauncher.newInstance()
             .application(EntitySpec.create(StartableApplication.class, WebClusterDatabaseExampleApp.class)
                     .displayName("Brooklyn WebApp Cluster with Database example"))
             .restServerPort(port)
             .location(location)
             .start();
         
    Entities.dumpInfo(launcher.getApplications());
}
 
Example #20
Source File: SingleWebServerExample.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) throws Exception {
    List<String> args = Lists.newArrayList(argv);
    String port =  CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost");

    BrooklynLauncher launcher = BrooklynLauncher.newInstance()
            .application(EntitySpec.create(StartableApplication.class, SingleWebServerExample.class).displayName("Brooklyn WebApp example"))
            .restServerPort(port)
            .location(location)
            .start();
     
    Entities.dumpInfo(launcher.getApplications());
}
 
Example #21
Source File: RebindWebClusterDatabaseExampleAppIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
protected StartableApplication createApp() {
    StartableApplication result = origManagementContext.getEntityManager().createEntity(EntitySpec.create(StartableApplication.class)
            .impl(WebClusterDatabaseExampleApp.class)
            .configure(DynamicCluster.INITIAL_SIZE, 2));
    return result;
}
 
Example #22
Source File: ControlledDynamicWebAppClusterTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testTheTestJavaWebApp() {
    SoftwareProcess n = app.createAndManageChild(EntitySpec.create(TestJavaWebAppEntity.class));
    app.start(locs);

    EntityAsserts.assertAttributeEqualsEventually(n, AbstractController.SERVICE_UP, true);

    app.config().set(StartableApplication.DESTROY_ON_STOP, false);
    app.stop();
    EntityAsserts.assertAttributeEqualsEventually(n, AbstractController.SERVICE_UP, false);
}
 
Example #23
Source File: SimulatedTheeTierApp.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) {
    List<String> args = Lists.newArrayList(argv);
    String port =  CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost");

    BrooklynLauncher launcher = BrooklynLauncher.newInstance()
             .application(EntitySpec.create(StartableApplication.class, SimulatedTheeTierApp.class)
                     .displayName("Brooklyn WebApp Cluster with Database example"))
             .restServerPort(port)
             .location(location)
             .start();
         
    Entities.dumpInfo(launcher.getApplications());
}
 
Example #24
Source File: ElectPrimaryPolicy.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void checkQuorums(Entity entity) {
    // set all quorums to 1 if not explicitly set
    if ( ((EntityInternal)entity).config().getRaw(StartableApplication.UP_QUORUM_CHECK).isAbsent() ) {
        entity.config().set(StartableApplication.UP_QUORUM_CHECK, QuorumChecks.newInstance(1, 0.0, false));
    }
    if ( ((EntityInternal)entity).config().getRaw(StartableApplication.RUNNING_QUORUM_CHECK).isAbsent() ) {
        entity.config().set(StartableApplication.RUNNING_QUORUM_CHECK, QuorumChecks.newInstance(1, 0.0, false));
    }
}
 
Example #25
Source File: WebClusterApp.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) {
    List<String> args = Lists.newArrayList(argv);
    String port =  CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
    String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost");

    BrooklynLauncher launcher = BrooklynLauncher.newInstance()
            .application(EntitySpec.create(StartableApplication.class, WebClusterApp.class).displayName("Brooklyn WebApp Cluster example"))
            .restServerPort(port)
            .location(location)
            .start();
     
    Entities.dumpInfo(launcher.getApplications());
}
 
Example #26
Source File: AbstractBrooklynLauncherRebindTestFixture.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void populatePersistenceDir(String dir, EntitySpec<? extends StartableApplication> appSpec) throws Exception {
    BrooklynLauncher launcher = newLauncherDefault(PersistMode.CLEAN)
            .highAvailabilityMode(HighAvailabilityMode.MASTER)
            .persistenceDir(dir)
            .application(appSpec)
            .start();
    launcher.terminate();
    assertMementoContainerNonEmptyForTypeEventually("entities");
}
 
Example #27
Source File: ServiceFailureDetectorYamlRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected StartableApplication rebind() throws Exception {
    RecordingRebindExceptionHandler exceptionHandler = new RecordingRebindExceptionHandler(RebindExceptionHandlerImpl.builder()
            .addPolicyFailureMode(RebindFailureMode.FAIL_AT_END)
            .loadPolicyFailureMode(RebindFailureMode.FAIL_AT_END)
            .danglingRefFailureMode(RebindFailureMode.FAIL_AT_END));
    return rebind(RebindOptions.create().exceptionHandler(exceptionHandler));
}
 
Example #28
Source File: ElectPrimaryTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleRebind() throws Exception {
    runSetPreferredViaWeightConfigOnB();
    
    StartableApplication app = rebind();
    Assert.assertEquals(app.sensors().get(PRIMARY).getDisplayName(), "b");
    
    Entity a = (Entity)mgmt().<Entity>lookup(EntityPredicates.displayNameEqualTo("a"));
    Entity b = (Entity)mgmt().<Entity>lookup(EntityPredicates.displayNameEqualTo("b"));
    a.sensors().set(WEIGHT_SENSOR, 2.0d);
    Entities.unmanage(b);
    EntityAsserts.assertAttributeEqualsEventually(app, PRIMARY, a);
}
 
Example #29
Source File: CatalogOsgiVersionMoreEntityRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testPolicyInBundleReferencedByStockCatalogItem() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
    
    String policyType = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_POLICY;
    
    addCatalogItems(
            "brooklyn.catalog:",
            "  id: wrapped-entity",
            "  version: 1.0",
            "  item:",
            "    services:",
            "    - type: " + TestEntity.class.getName());

    addCatalogItems(
            "brooklyn.catalog:",
            "  id: with-policy-from-library",
            "  version: 1.0",
            "  brooklyn.libraries:",
            "  - classpath:" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH,
            "  item:",
            "    services:",
            "    - type: " + BasicApplication.class.getName(),
            "      brooklyn.children:",
            "      - type: wrapped-entity:1.0",
            "        brooklyn.policies:",
            "        - type: " + policyType);
    
    Entity app = createAndStartApplication("services: [ { type: 'with-policy-from-library:1.0' } ]");
    Entity entity = Iterables.getOnlyElement(app.getChildren());
    Policy policy = Iterables.getOnlyElement(entity.policies());
    assertEquals(policy.getPolicyType().getName(), policyType);
    
    StartableApplication newApp = rebind();
    Entity newEntity = Iterables.getOnlyElement(newApp.getChildren());
    Policy newPolicy = Iterables.getOnlyElement(newEntity.policies());
    assertEquals(newPolicy.getPolicyType().getName(), policyType);
}
 
Example #30
Source File: LocationExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testLocationFromCatalogInheritanceAndRebind() throws Exception {
    ImmutableList.Builder<String> yamlL = ImmutableList.<String>builder().add(
            "brooklyn.catalog:",
            "  id: l1",
            "  itemType: location",
            "  item:",
            "    type: localhost",
            "    brooklyn.config:",
            "      simple: 42",
            "      my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");
    addCatalogItems(yamlL.build());

    String yaml = Joiner.on("\n").join(
            "services:",
            "- type: "+EmptySoftwareProcess.class.getName(),
            "location: l1");

    origApp = (StartableApplication) createAndStartApplication(new StringReader(yaml));

    Entity entity = Iterables.getOnlyElement( origApp.getChildren() );
    Location l = Iterables.getOnlyElement( entity.getLocations() );
    assertEquals(l.config().get(ConfigKeys.builder(Integer.class, "simple").build()), (Integer)42);
    assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
            
    Maybe<Object> rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
    Assert.assertTrue(rawConfig.isPresentAndNonNull());
    Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred raw value; got "+rawConfig.get());
    
    newApp = rebind();
    
    entity = Iterables.getOnlyElement( newApp.getChildren() );
    l = Iterables.getOnlyElement( entity.getLocations() );
    assertEquals(l.config().get(ConfigKeys.builder(Integer.class, "simple").build()), (Integer)42);
    assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
            
    rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
    Assert.assertTrue(rawConfig.isPresentAndNonNull());
    Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred raw value; got "+rawConfig.get());
}