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

The following examples show how to use org.apache.brooklyn.core.internal.BrooklynProperties#getConfig() . 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: BailOutJcloudsLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/**
 * Takes identity and access credential from management context's Brooklyn properties and sets
 * inbound ports to [22, 80, 9999].
 */
public static BailOutJcloudsLocation newBailOutJcloudsLocationForLiveTest(LocalManagementContext mgmt, Map<ConfigKey<?>, ?> config) {
    BrooklynProperties brooklynProperties = mgmt.getBrooklynProperties();
    String identity = (String) brooklynProperties.getConfig("brooklyn.location.jclouds.aws-ec2.identity");
    if (identity == null) identity = (String) brooklynProperties.getConfig("brooklyn.jclouds.aws-ec2.identity");
    String credential = (String) brooklynProperties.getConfig("brooklyn.location.jclouds.aws-ec2.credential");
    if (credential == null) credential = (String) brooklynProperties.getConfig("brooklyn.jclouds.aws-ec2.credential");

    Map<ConfigKey<?>, ?> allConfig = MutableMap.<ConfigKey<?>, Object>builder()
            .put(CLOUD_PROVIDER, AbstractJcloudsLiveTest.AWS_EC2_PROVIDER)
            .put(CLOUD_REGION_ID, AbstractJcloudsLiveTest.AWS_EC2_USEAST_REGION_NAME)
            .put(IMAGE_ID, US_EAST_IMAGE_ID) // so Brooklyn does not attempt to load all EC2 images
            .put(ACCESS_IDENTITY, identity)
            .put(ACCESS_CREDENTIAL, credential)
            .put(INBOUND_PORTS, "[22, 80, 9999]")
            .put(BUILD_TEMPLATE, true)
            .putAll(config)
            .build();

    return newBailOutJcloudsLocation(mgmt, allConfig);
}
 
Example 2
Source File: ExternalConfigBrooklynPropertiesTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void runExternalisedConfigGetters(BrooklynProperties props, String property, String expectedVal, boolean testSubMap) throws Exception {
    ExecutionContext exec = mgmt().getServerExecutionContext();

    String val1 = props.getConfig(ConfigKeys.newStringConfigKey(property));
    assertEquals(val1, expectedVal);
    
    DeferredSupplier<?> val2 = (DeferredSupplier<?>) props.getConfigRaw(ConfigKeys.newStringConfigKey(property)).get();
    assertEquals(Tasks.resolveValue(val2, String.class, exec), expectedVal);
    
    DeferredSupplier<?> val3 = (DeferredSupplier<?>) props.getConfigLocalRaw(ConfigKeys.newStringConfigKey(property)).get();
    assertEquals(Tasks.resolveValue(val3, String.class, exec), expectedVal);

    DeferredSupplier<?> val4 = (DeferredSupplier<?>) props.getAllConfigLocalRaw().get(ConfigKeys.newStringConfigKey(property));
    assertEquals(Tasks.resolveValue(val4, String.class, exec), expectedVal);
    
    String val5 = props.getFirst(property);
    assertTrue(val5.startsWith("$brooklyn:external"), "val="+val5);
    
    if (testSubMap) {
        BrooklynProperties submap = props.submap(ConfigPredicates.nameEqualTo(property));
        runExternalisedConfigGetters(submap, property, expectedVal, false);
    }
}
 
Example 3
Source File: LocalBrooklynNodeImpl.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
protected void connectSensors() {
    // Override management username and password from brooklyn.properties
    // TODO Why use BrooklynProperties, rather than StringConfigMap returned by mgmt.getConfig()?
    BrooklynProperties properties = ((ManagementContextInternal)getManagementContext()).getBrooklynProperties();
    String user = (String) properties.getConfig(String.format(LOCAL_BROOKLYN_NODE_KEY, "user"));
    String password = (String) properties.getConfig(String.format(LOCAL_BROOKLYN_NODE_KEY, "password"));
    if (Strings.isBlank(password)) {
        if (Strings.isBlank(user)) user = "admin";
        password = (String) properties.getConfig(String.format(BROOKLYN_WEBCONSOLE_PASSWORD_KEY, user));
    }
    if (Strings.isNonBlank(user) && Strings.isNonBlank(password)) {
        config().set(MANAGEMENT_USER, user);
        config().set(MANAGEMENT_PASSWORD, password);
    }
    super.connectSensors();
}
 
Example 4
Source File: BrooklynGarbageCollector.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public BrooklynGarbageCollector(BrooklynProperties brooklynProperties, BasicExecutionManager executionManager, BrooklynStorage storage) {
    this.executionManager = executionManager;
    this.storage = storage;
    this.brooklynProperties = brooklynProperties;

    if (brooklynProperties.getConfig(TRACK_SOFT_MAYBE_USAGE))
        SoftlyPresent.getUsageTracker().enable();
    
    executor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
            @Override public Thread newThread(Runnable r) {
                return new Thread(r, "brooklyn-gc");
            }});
    
    executionManager.addListener(new ExecutionListener() {
            @Override public void onTaskDone(Task<?> task) {
                BrooklynGarbageCollector.this.onTaskDone(task);
            }});

    scheduleCollector(true);
}
 
Example 5
Source File: ExplicitUsersSecurityProvider.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** checks the supplied candidate user and password against the
 * expect password (or SHA-256 + SALT thereof) defined as brooklyn properties.
 */
public static boolean checkExplicitUserPassword(ManagementContext mgmt, String user, String password) {
    BrooklynProperties properties = (BrooklynProperties) mgmt.getConfig();
    String expectedPassword = properties.getConfig(BrooklynWebConfig.PASSWORD_FOR_USER(user));
    String salt = properties.getConfig(BrooklynWebConfig.SALT_FOR_USER(user));
    String expectedSha256 = properties.getConfig(BrooklynWebConfig.SHA256_FOR_USER(user));
    
    return checkPassword(password, expectedPassword, expectedSha256, salt);
}
 
Example 6
Source File: BrooklynPropertiesTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAndPutConfig() {
    BrooklynProperties props = BrooklynProperties.Factory.newEmpty().addFromMap(ImmutableMap.of(
            "a.key", "aval", "a.key2", "aval2", "akey", "noval", "n.key", "234"));
    
    BasicConfigKey<String> aString = new BasicConfigKey<String>(String.class, "a.key");
    BasicConfigKey<Integer> nNum = new BasicConfigKey<Integer>(Integer.class, "n.key");
    BasicConfigKey<Integer> aBsent = new BasicConfigKey<Integer>(Integer.class, "ab.sent");
    BasicConfigKey<Integer> aMisstyped = new BasicConfigKey<Integer>(Integer.class, "am.isstyped");
    BasicConfigKey<Integer> aDfault = new BasicConfigKey<Integer>(Integer.class, "a.default", "-", 123);
    
    assertEquals(props.getConfig(aString), "aval");
    assertEquals(props.getConfig(nNum), (Integer)234);
    
    props.put(aString, "aval2");
    assertEquals(props.getConfig(aString), "aval2");
    assertEquals(props.getConfig("a.key"), "aval2");

    props.put(nNum, "345");
    assertEquals(props.getConfig(nNum), (Integer)345);
    assertEquals(props.getConfig("n.key"), "345");

    assertEquals(props.getConfig(aBsent), null);
    assertEquals(props.getConfig(aBsent, 123), (Integer)123);
    assertEquals(props.getConfig(aDfault), (Integer)123);
    
    props.put(aMisstyped, "x1");
    assertEquals(props.getConfig("am.isstyped"), "x1");
    boolean workedWhenShouldntHave = false;
    try { props.getConfig(aMisstyped); workedWhenShouldntHave = true; } catch (Exception e) {}
    if (workedWhenShouldntHave) fail("should have failed getting "+aMisstyped+" because can't coerce");
}