Java Code Examples for org.apache.brooklyn.core.internal.BrooklynProperties#put()

The following examples show how to use org.apache.brooklyn.core.internal.BrooklynProperties#put() . 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: RubyRepRackspaceLiveTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
public void test(String osRegex) throws Exception {
    PostgreSqlNode db1 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
            .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)
            .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111)));
    PostgreSqlNode db2 = app.createAndManageChild(EntitySpec.create(PostgreSqlNode.class)
            .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, PostgreSqlIntegrationTest.CREATION_SCRIPT)
            .configure(PostgreSqlNode.POSTGRESQL_PORT, PortRanges.fromInteger(9111)));

    BrooklynProperties brooklynProperties = mgmt.getBrooklynProperties();
    brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex);
    brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id");
    brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId");
    brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 9111));
    Location loc = mgmt.getLocationRegistry().getLocationManaged("jclouds:rackspace-cloudservers-uk");
    
    startInLocation(app, db1, db2, loc);

    //hack to get the port for mysql open; is the inbounds property not respected on rackspace??
    for (DatastoreCommon node : ImmutableSet.of(db1, db2)) {
        SshMachineLocation l = (SshMachineLocation) node.getLocations().iterator().next();
        l.execCommands("add iptables rule", ImmutableList.of(IptablesCommands.insertIptablesRule(Chain.INPUT, Protocol.TCP, 9111, Policy.ACCEPT)));
    }

    testReplication(db1, db2);
}
 
Example 2
Source File: MariaDbLiveRackspaceTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
public void test(String osRegex) throws Exception {
    MariaDbNode mariadb = app.createAndManageChild(EntitySpec.create(MariaDbNode.class)
            .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT));

    BrooklynProperties brooklynProperties = mgmt.getBrooklynProperties();
    brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageNameRegex", osRegex);
    brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.image-id");
    brooklynProperties.remove("brooklyn.location.jclouds.rackspace-cloudservers-uk.imageId");
    brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.inboundPorts", Arrays.asList(22, 3306));
    JcloudsLocation jcloudsLocation = (JcloudsLocation) mgmt.getLocationRegistry().getLocationManaged("jclouds:rackspace-cloudservers-uk");

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

    SshMachineLocation l = (SshMachineLocation) mariadb.getLocations().iterator().next();
    l.execCommands("add iptables rule", ImmutableList.of(IptablesCommands.insertIptablesRule(Chain.INPUT, Protocol.TCP, 3306, Policy.ACCEPT)));

    new VogellaExampleAccess("com.mysql.jdbc.Driver", mariadb.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase();
}
 
Example 3
Source File: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testWhenExternalisedConfigSupplierDoesNotExist() throws Exception {
    BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
    props.put("brooklyn.external.myprovider", "wrong.classname.DoesNotExist");

    try {
        LocalManagementContextForTests.builder(true)
                .useProperties(props)
                .build();
        fail();
    } catch (Exception e) {
        if (Exceptions.getFirstThrowableOfType(e, ClassNotFoundException.class) == null) {
            throw e;
        }
    }
}
 
Example 4
Source File: LocationRegistryTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testNonsenseParentSupported() {
    BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
    properties.put(LocalhostLocationResolver.LOCALHOST_ENABLED.getName(), false);
    properties.put("brooklyn.location.named.bogus_will_fail_eventually", "totally_bogus");
    mgmt = LocalManagementContextForTests.newInstance(properties);
    
    Assert.assertTrue( findLocationMatching("bogus_will_fail_eventually") );
    Maybe<LocationSpec<?>> l = mgmt.getLocationRegistry().getLocationSpec("bogus_will_fail_eventually");
    Assert.assertTrue( l.isAbsent(), "Should not have resolved: "+l );
    try {
        l.get();
        Asserts.shouldHaveFailedPreviously();
    } catch (Exception e) {
        Asserts.expectedFailureContains(e, "bogus_will_fail", "totally_bogus");
    }
}
 
Example 5
Source File: ConfigUtils.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static BrooklynProperties filterForPrefix(BrooklynProperties properties, String prefix) {
    BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
    Set<ConfigKey<?>> keys = properties.findKeys(ConfigPredicates.nameSatisfies(StringPredicates.startsWith(prefix)));
    for (ConfigKey<?> key : keys) {
        result.put(key, properties.getConfig(key));
    }
    return result;
}
 
Example 6
Source File: LocationRegistryTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocationGetsDefaultDisplayName() {
    BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
    properties.put("brooklyn.location.named.foo", "byon:(hosts=\"[email protected].{1,2,3,4}\")");
    mgmt = LocalManagementContextForTests.newInstance(properties);
    LocationSpec<? extends Location> ls = mgmt.getLocationRegistry().getLocationSpec("foo").get();
    Location l = mgmt.getLocationManager().createLocation(ls);
    Assert.assertNotNull(l.getDisplayName());
    Assert.assertTrue(l.getDisplayName().startsWith(FixedListMachineProvisioningLocation.class.getSimpleName()), "name="+l.getDisplayName());
    // TODO currently it gives default name; it would be nice to use 'foo', 
    // or at least to have access to the spec (and use it e.g. in places such as DynamicFabric)
    // Assert.assertEquals(l.getDisplayName(), "foo");
}
 
Example 7
Source File: LocalUsageManagerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddUsageListenerInstance() throws Exception {
    BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newEmpty();
    brooklynProperties.put(UsageManager.USAGE_LISTENERS, ImmutableList.of(new RecordingStaticUsageListener()));
    replaceManagementContext(LocalManagementContextForTests.newInstance(brooklynProperties));
    assertUsageListenerCalledWhenApplicationStarted();
}
 
Example 8
Source File: LocationRegistryTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocalhostEnabled() {
    BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
    properties.put("brooklyn.location.localhost.enabled", true);
    mgmt = LocalManagementContextForTests.newInstance(properties);
    BasicLocationRegistry.addNamedLocationLocalhost(mgmt);

    Assert.assertTrue( findLocationMatching("localhost") );
}
 
Example 9
Source File: JcloudsRebindWithExternalConfigTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected BrooklynProperties createBrooklynProperties() {
    BrooklynProperties result = super.createBrooklynProperties();
    result.put("brooklyn.external.creds", InPlaceExternalConfigSupplier.class.getName());
    result.put("brooklyn.external.creds.test-identity", "myidentity");
    result.put("brooklyn.external.creds.test-credential", "mycredential");
    
    return result;
}
 
Example 10
Source File: CatalogScanTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private synchronized void loadTheDefaultCatalog(boolean lookOnDiskForDefaultCatalog) {
    if (defaultCatalog!=null) return;
    BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
    props.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL.getName(),
        // if default catalog is picked up from the system, we might get random stuff from ~/.brooklyn/ instead of the default;
        // useful as an integration check that we default correctly, but irritating for people to use if they have such a catalog installed
        (lookOnDiskForDefaultCatalog ? "" :
            "data:,"+Urls.encode(new ResourceUtils(this).getResourceAsString("classpath:/brooklyn/default.catalog.bom"))));
    LocalManagementContext mgmt = newManagementContext(props);
    defaultCatalog = mgmt.getCatalog();
    log.info("ENTITIES loaded for DEFAULT: "+defaultCatalog.getCatalogItems(Predicates.alwaysTrue()));
}
 
Example 11
Source File: EntityExecutionManagerTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testEffectorTasksGcedForAge() throws Exception {
    Duration maxTaskAge = Duration.millis(100);
    Duration maxOverhead = Duration.millis(250);
    Duration earlyReturnGrace = Duration.millis(10);
    BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newEmpty();
    brooklynProperties.put(BrooklynGarbageCollector.GC_PERIOD, Duration.ONE_MILLISECOND);
    brooklynProperties.put(BrooklynGarbageCollector.MAX_TASK_AGE, maxTaskAge);

    replaceManagementContext(LocalManagementContextForTests.newInstance(brooklynProperties));
    setUpApp();
    final TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));

    Stopwatch stopwatch = Stopwatch.createStarted();
    Task<?> oldTask = entity.invoke(TestEntity.MY_EFFECTOR, ImmutableMap.<String,Object>of());
    oldTask.get();

    Asserts.succeedsEventually(new Runnable() {
        @Override public void run() {
            Set<Task<?>> storedTasks = app.getManagementContext().getExecutionManager().getTasksWithAllTags(ImmutableList.of(
                    BrooklynTaskTags.tagForTargetEntity(entity),
                    ManagementContextInternal.EFFECTOR_TAG));
            assertEquals(storedTasks, ImmutableSet.of(), "storedTasks="+storedTasks);
        }});

    Duration timeToGc = Duration.of(stopwatch);
    assertTrue(timeToGc.isLongerThan(maxTaskAge.subtract(earlyReturnGrace)), "timeToGc="+timeToGc+"; maxTaskAge="+maxTaskAge);
    assertTrue(timeToGc.isShorterThan(maxTaskAge.add(maxOverhead)), "timeToGc="+timeToGc+"; maxTaskAge="+maxTaskAge);
}
 
Example 12
Source File: JcloudsLocationExtensionStubbedTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected LocalManagementContext newManagementContext() {
    LocalManagementContext result = super.newManagementContext();
    BrooklynProperties brooklynProperties = result.getBrooklynProperties();
    brooklynProperties.put("brooklyn.location.named.jclouds-with-extension", super.getLocationSpec());
    brooklynProperties.put("brooklyn.location.named.jclouds-with-extension.extensions", 
            "{ "+HttpExecutorFactory.class.getName()+": "+MyHttpExecutorFactory.class.getName()+" }");
   return result;
}
 
Example 13
Source File: BrooklynLauncherTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsesSuppliedBrooklynProperties() throws Exception {
    BrooklynProperties props = LocalManagementContextForTests.builder(true).buildProperties();
    props.put("mykey", "myval");
    launcher = newLauncherForTests(false)
            .restServer(false)
            .brooklynProperties(props)
            .start();
    
    assertEquals(launcher.getServerDetails().getManagementContext().getConfig().getFirst("mykey"), "myval");
}
 
Example 14
Source File: LocationRegistryTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testLocationGetsDisplayName() {
    BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
    properties.put("brooklyn.location.named.foo", "byon:(hosts=\"[email protected].{1,2,3,4}\")");
    properties.put("brooklyn.location.named.foo.displayName", "My Foo");
    mgmt = LocalManagementContextForTests.newInstance(properties);
    LocationSpec<?> ls = mgmt.getLocationRegistry().getLocationSpec("foo").get();
    Location l = mgmt.getLocationManager().createLocation(ls);
    Assert.assertEquals(l.getDisplayName(), "My Foo");
}
 
Example 15
Source File: BrooklynFeatureEnablementTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetDefaultAfterBrooklynPropsDoesNotChangeValue() throws Exception {
    String featureProperty = "brooklyn.experimental.feature.testSetDefaultAfterBrooklynPropsDoesNotChangeValue";
    BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
    props.put(featureProperty, false);
    BrooklynFeatureEnablement.init(props);
    BrooklynFeatureEnablement.setDefault(featureProperty, true);
    assertFalse(BrooklynFeatureEnablement.isEnabled(featureProperty));
}
 
Example 16
Source File: ManagementPlaneIdTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected LocalManagementContext createManagementContext(PersistMode persistMode, HighAvailabilityMode haMode, boolean backedUp) {
    BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
    props.put(BrooklynServerConfig.PERSISTENCE_BACKUPS_DIR, mementoDir);
    LocalManagementContext mgmt = RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
            .persistPeriodMillis(1)
            .persistMode(persistMode)
            .haMode(haMode)
            .enablePersistenceBackups(backedUp)
            .emptyCatalog(true)
            .properties(props)
            .setOsgiEnablementAndReuse(false, false)
            .buildStarted();
    markForTermination(mgmt);
    return mgmt;
}
 
Example 17
Source File: ManagementNodeStateListenerTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = ClassCastException.class)
public void testErrorWhenConfiguredClassIsNotAListener() {
    BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newEmpty();
    brooklynProperties.put(BrooklynServerConfig.MANAGEMENT_NODE_STATE_LISTENERS, Integer.class.getName());
    replaceManagementContext(LocalManagementContextForTests.newInstance(brooklynProperties));
}
 
Example 18
Source File: HighAvailabilityManagerTestFixture.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected ManagementContextInternal newLocalManagementContext() {
    BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newEmpty();
    brooklynProperties.put(BrooklynServerConfig.MANAGEMENT_NODE_STATE_LISTENERS, ImmutableList.of(stateListener));
    ManagementContextInternal result = LocalManagementContextForTests.newInstance(brooklynProperties);
    return result;
}
 
Example 19
Source File: LocalUsageManagerTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test(expectedExceptions = ClassCastException.class)
public void testErrorWhenConfiguredClassIsNotAUsageListener() {
    BrooklynProperties brooklynProperties = BrooklynProperties.Factory.newEmpty();
    brooklynProperties.put(UsageManager.USAGE_LISTENERS, Integer.class.getName());
    replaceManagementContext(LocalManagementContextForTests.newInstance(brooklynProperties));
}
 
Example 20
Source File: EffectorExceptionLoggedTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
protected BrooklynProperties getBrooklynProperties() {
    BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
    result.put(Entitlements.GLOBAL_ENTITLEMENT_MANAGER, ThrowingEntitlementManager.class.getName());
    return result;
}