Java Code Examples for org.apache.brooklyn.core.config.ConfigKeys#newStringConfigKey()

The following examples show how to use org.apache.brooklyn.core.config.ConfigKeys#newStringConfigKey() . 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: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void testExternalisedLocationConfigInheritanceReferencedFromYaml() throws Exception {
    ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");

    String yaml = Joiner.on("\n").join(
            "services:",
            "- type: "+EmptySoftwareProcess.class.getName(),
            "location:",
            "  localhost:",
            "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");

    Entity app = createAndStartApplication(yaml);
    waitForApplicationTasks(app);
    Entity entity = Iterables.getOnlyElement( app.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 2
Source File: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testExternalisedConfigValueNotLogged() throws Exception {
    ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");

    String loggerName = BrooklynDslDeferredSupplier.class.getName();
    ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.DEBUG;
    Predicate<ILoggingEvent> filter = EventPredicates.containsMessage("myval");

    try (LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter)) {
        String yaml = Joiner.on("\n").join(
            "services:",
            "- serviceType: org.apache.brooklyn.core.test.entity.TestApplication",
            "  brooklyn.config:",
            "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");

        TestApplication app = (TestApplication) createAndStartApplication(yaml);
        waitForApplicationTasks(app);

        assertEquals(app.getConfig(MY_CONFIG_KEY), "myval");
    
        List<ILoggingEvent> events = watcher.getEvents();
        assertTrue(events.isEmpty(), "events="+events);
    }
}
 
Example 3
Source File: SpecParameterUnwrappingTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "brooklynTypes")
public void testParameters(Class<? extends BrooklynObject> testClass) {
    addCatalogItems(
            "brooklyn.catalog:",
            "  id: " + SYMBOLIC_NAME,
            "  version: " + TEST_VERSION,
            "  itemType: " + inferItemType(testClass),
            "  item:",
            "    type: " + testClass.getName(),
            "    brooklyn.parameters:",
            "    - simple");

    ConfigKey<String> SIMPLE_CONFIG = ConfigKeys.newStringConfigKey("simple");
    SpecParameter<String> SIMPLE_PARAM = new BasicSpecParameter<>("simple", true, SIMPLE_CONFIG);
    AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
    assertTrue(Iterables.tryFind(spec.getParameters(), Predicates.<SpecParameter<?>>equalTo(SIMPLE_PARAM)).isPresent());
}
 
Example 4
Source File: FixedListMachineProvisioningLocationTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testMachineConfigRestoredToDefaultsOnRelease() throws Exception {
    ConfigKey<String> mykey = ConfigKeys.newStringConfigKey("mykey");
    
    boolean origContains = machine.config().getBag().getAllConfig().containsKey("mykey");
    SshMachineLocation obtained = provisioner.obtain();
    obtained.config().set(mykey, "myNewVal");
    Object obtainedVal = obtained.config().getBag().getAllConfig().get("mykey");
    
    provisioner.release(obtained);
    boolean releasedContains = machine.config().getBag().getAllConfig().containsKey("mykey");
    releasedContains |= (machine.config().get(mykey) != null);
    
    assertEquals(obtained, machine);
    assertFalse(origContains);
    assertEquals(obtainedVal, "myNewVal");
    assertFalse(releasedContains);
}
 
Example 5
Source File: InboundPortsUtilsTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetRequiredOpenPortsGetsDynamicallyAddedPortBasedKeys() {
    TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));

    PortAttributeSensorAndConfigKey newTestConfigKeyPort = ConfigKeys.newPortSensorAndConfigKey("new.test.config.port.string.first", "port", "7777+");
    PortAttributeSensorAndConfigKey newTestConfigKeyPort2 = ConfigKeys.newPortSensorAndConfigKey("new.test.config.port.string.second", "port");

    ConfigKey<Object> newTestConfigKeyObject = ConfigKeys.newConfigKey(Object.class, "new.test.config.object");
    ConfigKey<String> newTestConfigKeyString = ConfigKeys.newStringConfigKey("new.test.config.key.string");
    entity.config().set(newTestConfigKeyPort, PortRanges.fromString("8888+"));
    entity.config().set(newTestConfigKeyPort2, PortRanges.fromInteger(9999));
    entity.config().set(newTestConfigKeyObject, PortRanges.fromInteger(2222));
    entity.config().set(newTestConfigKeyString, "foo.bar");

    Collection<Integer> dynamicRequiredOpenPorts = InboundPortsUtils.getRequiredOpenPorts(entity, ImmutableSet.<ConfigKey<?>>of(), true, null);
    Assert.assertTrue(dynamicRequiredOpenPorts.contains(8888));
    Assert.assertTrue(dynamicRequiredOpenPorts.contains(9999));
    Assert.assertTrue(dynamicRequiredOpenPorts.contains(2222));
}
 
Example 6
Source File: InboundPortsUtilsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRequiredOpenPortsGetsDynamicallyAddedKeys() {
    TestEntity entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    Collection<Integer> defaultRequiredOpenPorts = InboundPortsUtils.getRequiredOpenPorts(entity, ImmutableSet.<ConfigKey<?>>of(), true, null);
    Assert.assertEquals(defaultRequiredOpenPorts, ImmutableSet.of(), "Expected no ports");
    ConfigKey<Integer> newTestConfigKeyPort = ConfigKeys.newIntegerConfigKey("new.test.config.key.port");
    ConfigKey<String> newTestConfigKeyString = ConfigKeys.newStringConfigKey("new.test.config.key.string");
    entity.config().set(newTestConfigKeyPort, 9999);
    entity.config().set(newTestConfigKeyString, "foo.bar");
    Collection<Integer> dynamicRequiredOpenPorts = InboundPortsUtils.getRequiredOpenPorts(entity, ImmutableSet.<ConfigKey<?>>of(), true, null);
    Assert.assertEquals(dynamicRequiredOpenPorts, ImmutableSet.of(9999), "Expected new port to be added");
}
 
Example 7
Source File: LocalManagementContextTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testScratchpadSurvivesReload() throws Exception {
    String globalPropertiesContents = "brooklyn.location.localhost.displayName=myname";
    Files.write(globalPropertiesContents, globalPropertiesFile, Charsets.UTF_8);
    BrooklynProperties brooklynProperties = BrooklynProperties.Factory.builderDefault()
        .globalPropertiesFile(globalPropertiesFile.getAbsolutePath())
        .build();
    context = LocalManagementContextForTests.builder(true).useProperties(brooklynProperties).build();
    ConfigKey<String> myKey = ConfigKeys.newStringConfigKey("my");
    context.getScratchpad().put(myKey, "key");
    assertEquals(context.getScratchpad().get(myKey), "key");
    context.reloadBrooklynProperties();
    assertEquals(context.getScratchpad().get(myKey), "key");
}
 
Example 8
Source File: LocalManagementContextRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testScratchpadLostOnRebind() throws Exception {
    ConfigKey<String> myKey = ConfigKeys.newStringConfigKey("my");
    origManagementContext.getScratchpad().put(myKey, "key");
    assertEquals(origManagementContext.getScratchpad().get(myKey), "key");
    rebind();
    assertFalse(newManagementContext.getScratchpad().contains(myKey), "Scratchpad lost on rebind");
}
 
Example 9
Source File: XmlMementoSerializerPerformanceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups={"Live", "Acceptance"})
public void testSerializeEntityMemento() throws Exception {
    int numIterations = numIterations();
    double minRatePerSec = 10 * PERFORMANCE_EXPECTATION;

    // Create an entity with lots of config/parameters, and sensors
    Map<ConfigKey<?>, String> config = Maps.newLinkedHashMap();
    List<BasicSpecParameter<?>> params = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        ConfigKey<String> key = ConfigKeys.newStringConfigKey("myparam"+i);
        params.add(new BasicSpecParameter<String>("mylabel"+i, false, key));
        config.put(key, "val"+i);
    }
    Entity entity = app.addChild(EntitySpec.create(TestEntity.class)
            .configure(TestEntity.CONF_NAME, "myname")
            .configure(config)
            .parametersAdd(params)
            .tags(ImmutableList.<Object>of("tag1", "tag2"))
            .enricher(EnricherSpec.create(TestEnricher.class))
            .policy(PolicySpec.create(TestPolicy.class)));
    
    for (int i = 0; i < 100; i++) {
        AttributeSensor<String> sensor = Sensors.newStringSensor("mysensor"+i);
        entity.sensors().set(sensor, "valsensor"+i);
    }

    // Create the memento for that entity (only once)
    final Memento memento = MementosGenerators.newBasicMemento(Entities.deproxy(entity));
    int serializedLength = serializeToString(memento).length();

    // Run the performance test
    measure(PerformanceTestDescriptor.create()
            .summary("mementoSerializer.serializeEntityMemento(size="+serializedLength+"chars)")
            .iterations(numIterations)
            .minAcceptablePerSecond(minRatePerSec)
            .job(new Runnable() {
                @Override public void run() {
                    serializeToString(memento);
                }}));
}
 
Example 10
Source File: ServerResource.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public String getConfig(String configKey) {
    if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ALL_SERVER_INFO, null)) {
        throw WebResourceUtils.forbidden("User '%s' is not authorized to perform this operation", Entitlements.getEntitlementContext().user());
    }
    ConfigKey<String> config = ConfigKeys.newStringConfigKey(configKey);
    return (String) WebResourceUtils.getValueForDisplay(mapper(), mgmt().getConfig().getConfig(config), true, true);
}
 
Example 11
Source File: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalisedConfigReferencedFromYaml() throws Exception {
    ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");

    String yaml = Joiner.on("\n").join(
        "services:",
        "- serviceType: org.apache.brooklyn.core.test.entity.TestApplication",
        "  brooklyn.config:",
        "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");

    TestApplication app = (TestApplication) createAndStartApplication(yaml);
    waitForApplicationTasks(app);

    assertEquals(app.getConfig(MY_CONFIG_KEY), "myval");
}
 
Example 12
Source File: DslTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testConfigImmediatelyDoesNotBlock() throws Exception {
    ConfigKey<String> configKey = ConfigKeys.newStringConfigKey("testConfig");
    BrooklynDslDeferredSupplier<?> attributeDsl = BrooklynDslCommon.attributeWhenReady(TestApplication.MY_ATTRIBUTE.getName());
    app.config().set((ConfigKey)configKey, attributeDsl); // ugly cast because val is DSL, resolving to a string
    BrooklynDslDeferredSupplier<?> configDsl = BrooklynDslCommon.config(configKey.getName());
    Maybe<?> actualValue = execDslImmediately(configDsl, configKey.getTypeToken(), app, true);
    assertTrue(actualValue.isAbsent());
}
 
Example 13
Source File: DslTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigUsesParameterDefaultValue() throws Exception {
    final ConfigKey<String> configKey = ConfigKeys.newStringConfigKey("testConfig");
    ConfigKey<String> configParam = ConfigKeys.newStringConfigKey("testParam", "myDescription", "myDefaultConfigValue");
    BrooklynDslDeferredSupplier<?> dsl = BrooklynDslCommon.config(configKey.getName());
    Supplier<ConfigValuePair> valueSupplier = new Supplier<ConfigValuePair>() {
        @Override public ConfigValuePair get() {
            return new ConfigValuePair(BrooklynDslCommon.config("testParam"), "myDefaultConfigValue");
        }
    };
    new ConfigTestWorker(app, configKey, valueSupplier, dsl)
            .childSpec(EntitySpec.create(TestEntity.class).parameters(ImmutableList.of(new BasicSpecParameter<String>("myLabel", true, configParam))))
            .run();
}
 
Example 14
Source File: MementoGeneratorsPerformanceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups={"Live", "Acceptance"})
public void testGenerateEntityMemento() throws Exception {
    int numIterations = numIterations();
    double minRatePerSec = 10 * PERFORMANCE_EXPECTATION;

    // Create an entity with lots of config/parameters, and sensors
    Map<ConfigKey<?>, String> config = Maps.newLinkedHashMap();
    List<BasicSpecParameter<?>> params = Lists.newArrayList();
    for (int i = 0; i < 100; i++) {
        ConfigKey<String> key = ConfigKeys.newStringConfigKey("myparam"+i);
        params.add(new BasicSpecParameter<String>("mylabel"+i, false, key));
        config.put(key, "val"+i);
    }
    Entity entity = app.addChild(EntitySpec.create(TestEntity.class)
            .configure(TestEntity.CONF_NAME, "myname")
            .configure(config)
            .parametersAdd(params)
            .tags(ImmutableList.<Object>of("tag1", "tag2"))
            .enricher(EnricherSpec.create(TestEnricher.class))
            .policy(PolicySpec.create(TestPolicy.class)));
    
    for (int i = 0; i < 100; i++) {
        AttributeSensor<String> sensor = Sensors.newStringSensor("mysensor"+i);
        entity.sensors().set(sensor, "valsensor"+i);
    }

    final Entity deproxiedEntity = Entities.deproxy(entity);

    // Run the performance test
    measure(PerformanceTestDescriptor.create()
            .summary("mementosGenerators.newBasicMemento(entity)")
            .iterations(numIterations)
            .minAcceptablePerSecond(minRatePerSec)
            .job(new Runnable() {
                @Override public void run() {
                    MementosGenerators.newBasicMemento(deproxiedEntity);
                }}));
}
 
Example 15
Source File: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalisedConfigFromSupplierWithoutMapArg() throws Exception {
    ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");

    String yaml = Joiner.on("\n").join(
        "services:",
        "- serviceType: org.apache.brooklyn.core.test.entity.TestApplication",
        "  brooklyn.config:",
        "    my.config.key: $brooklyn:external(\"myproviderWithoutMapArg\", \"mykey\")");

    TestApplication app = (TestApplication) createAndStartApplication(yaml);
    waitForApplicationTasks(app);

    assertEquals(app.getConfig(MY_CONFIG_KEY), "myHardcodedVal");
}
 
Example 16
Source File: ExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalisedLocationConfigReferencedFromYaml() throws Exception {
    ConfigKey<String> MY_CONFIG_KEY = ConfigKeys.newStringConfigKey("my.config.key");

    String yaml = Joiner.on("\n").join(
        "services:",
        "- type: org.apache.brooklyn.core.test.entity.TestApplication",
        "location:",
        "  localhost:",
        "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");

    TestApplication app = (TestApplication) createAndStartApplication(yaml);
    waitForApplicationTasks(app);
    assertEquals(Iterables.getOnlyElement( app.getLocations() ).config().get(MY_CONFIG_KEY), "myval");
}
 
Example 17
Source File: BrooklynWebConfig.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public final static ConfigKey<String> PASSWORD_FOR_USER(String user) {
    return ConfigKeys.newStringConfigKey(BASE_NAME_SECURITY + ".user." + user + ".password");
}
 
Example 18
Source File: BrooklynWebConfig.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public final static ConfigKey<String> SALT_FOR_USER(String user) {
    return ConfigKeys.newStringConfigKey(BASE_NAME_SECURITY + ".user." + user + ".salt");
}
 
Example 19
Source File: BrooklynWebConfig.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public final static ConfigKey<String> SHA256_FOR_USER(String user) {
    return ConfigKeys.newStringConfigKey(BASE_NAME_SECURITY + ".user." + user + ".sha256");
}
 
Example 20
Source File: DslTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfig() throws Exception {
    ConfigKey<String> configKey = ConfigKeys.newStringConfigKey("testConfig");
    BrooklynDslDeferredSupplier<?> dsl = BrooklynDslCommon.config(configKey.getName());
    new ConfigTestWorker(app, configKey, dsl).run();
}