brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Kennedy <andrew.kenn...@cloudsoftcorp.com>
Subject Re: Problem using ConfigKey<Map<String, String>>
Date Fri, 26 Sep 2014 06:24:43 GMT
Jose,

You're right, the `#keySet()` method returns the set of sub-keys in
the configuration map, which is what you need. Just make sure the
value type `T` in the `MapConfigKey<T>` declaration is `Object`
otherwise every value will be coerced to whatever type you declare,
which may fail and is probably not what you want with mixed content.
Essentially what is happening is the equivalent of declaring a set of
`ConfigKey<Object>` fields with names like
'php.db.connection.config.params.g_DatabaseHost' and
'php.db.connection.config.params.g_DatabasePort' that you can also
extract in a `Map`.

/* Note that in some circumstances the host and port may be mapped via
a `SubnetTier`, such as when deployed to a Docker container or a NAT
environment, so you should support (and check for) a key of type
`String` with the name 'g_DatabaseHostAndPort' containing a
'hostname:portnumber' string, which you obtain from the
`AttributeSensor<String>` named 'mapped.mysql.port' on the database
entity. I can provide a code snippet for this if you want, but it is
not really required for normal operation. */

Andrew.
--
-- andrew kennedy ? cloud engineer : http://blog.abstractvisitorpattern.co.uk/ ;


On 25 September 2014 23:21, josec <josec@lcc.uma.es> wrote:
> Hi Andrew,
>
> Thanks for your reply.
> I checked this class las afternoon, but I do not undertand how the keySet(in
> this case d_DatabaseHost and g_DatabasePort) is returned by MapConfigKey.
> This keys are specified by the user, so they arenot known by the Java code
> in runtime.
>
> However I can find the next lines:
>
> MapConfigKey<String> SALT_FORMULAS = new MapConfigKey<String>(String.class,
>             "salt.formulaUrls", "Map of Salt formula URLs (normally GutHub
> repository archives from the salt-formulas user)");
>
> and
>
> Map<String, String> formulas = app.getConfig(SaltConfig.SALT_FORMULAS);
>
> So, I hope formulas.keySet() returns <"g_DatabaseHost", "g_DatabasePort">,
> then I could interate over the map
>
> I think it could be working good, I will tell you. :)
>
> Thanks a lot.
> Jose
>
> El 25.09.2014 23:47, Andrew Kennedy escribió:
>
>> Jose, Hi.
>>
>> There are some issues using $brooklyn functions and deferred values
>> using Map valued ConfigKeys at the moment, which I am working on
>> resolving in pull request #182, however in the mean time I suggest you
>> try this:
>>
>> Change the type of the key to MapConfigKey, declared like this:
>>
>>     MapConfigKey<Object> DB_CONNECTION_CONFIG_PARAMS = new
>> MapConfigKey<Object>(Object.class, "php.db.connection.config.params");
>>
>> Then you should be able to specify the configuration in the YAML like
>> this:
>>
>>     brooklyn.config:
>>       db_connection_config_params:
>>         g_DatabaseHost:
>>           $brooklyn:component("db").attributeWhenReady("datastore.url")
>>         g_DatabasePort:
>>           $brooklyn:component("db").attributeWhenReady("mysql.port")
>>
>> Hopefully this is helpful.
>>
>> Cheers,
>> Andrew.
>> --
>> -- andrew kennedy ? cloud engineer :
>> http://blog.abstractvisitorpattern.co.uk/ ;
>>
>>
>> On 25 September 2014 19:16, Jose Carrasco <josec@lcc.uma.es> wrote:
>>>
>>> Hello,
>>>
>>> I am currently developing a new entities for Brooklyn (into SeaClouds
>>> project context).
>>> I have found a problem using the ConfigKey.
>>>
>>> I am using a ConfigKey<Map< String, String>> to my entity the parameters
>>> necessaty to stablish a database
>>> connection. I have decided to use a Map because the user could find a
>>> smart
>>> and flexible way flexible to specify
>>> several attributes and their values, e.g.:
>>>
>>> name: PHP HelloWorld
>>> services:
>>> - serviceType: brooklyn.entity.webapp.apache.ApacheServer
>>> name: Apache Server
>>> location: localhost
>>> brooklyn.config:
>>> http_port: 80
>>> app_git_repo_url:https://bitbucket.org/seaclDem/nurocasestudyphp5-5.git
>>>
>>> <https://seaclDem:seaclouds@bitbucket.org/seaclDem/nurocasestudyphp5-5.git>
>>> db_connection_config_params:
>>>       g_DatabaseHost: $brooklyn:formatString("%s",
>>> component("db").attributeWhenReady("datastore.url"))
>>>       g_DatabasePort:
>>> $brooklyn:component("db").attributeWhenReady("mysql.port")
>>>
>>> - serviceType: brooklyn.entity.database.mysql.MySqlNode
>>> id: db
>>> name: My DB
>>> location: localhost
>>> brooklyn.config:
>>> datastore.creation.script.url:
>>> file:///root/Desktop/brooklynTest/create.sql
>>>
>>> In this example the db_connection_config_params is a MapConfigKey:
>>>
>>> @SetFromFlag("db_connection_config_params")
>>>     public static final ConfigKey<Map<String,String>>
>>> DB_CONNECTION_CONFIG_PARAMS = new BasicConfigKey(
>>>             Map.class, "php.db.connection.config.params", "PHP
>>> application
>>> file to start e.g. main.php, or launch.php");
>>>
>>> Which contains two items which are used to configure the database. In
>>> this
>>> case, the values of the
>>> aforementioned items are provided by MySQL entity. It works ok.
>>> Here, I find a problem getting the values of the g_DatabaseHost and
>>> g_DatabasePort in my java code. When
>>> I read the values of the aforementiond items the returned values are
>>> $brooklyn:formatString("%s").
>>>
>>> I have changed the YAML definition using:
>>>
>>> g_DatabaseHost:
>>> $brooklyn:component("db").attributeWhenReady("datastore.url"))
>>>       g_DatabasePort:
>>> $brooklyn:component("db").attributeWhenReady("mysql.port")
>>>
>>> But I have obteined
>>> $brooklyn:component("db").attributeWhenReady("datastore.url"))  and
>>> $brooklyn:component("db").attributeWhenReady("mysql.portl"))
>>> respectively.
>>>
>>> I thought the problem could be the component values request (e.g.
>>> $brooklyn:component("db").
>>> attributeWhenReady("datastore.url"))), then I assinged these values to
>>> simple ConfigKey<String>  but
>>> they worked good.
>>>
>>> Thus, the problem may be ConfigKey<Map<,>> parser does not  evalue
the
>>> expresions which uses
>>> $brooklyn:...  but I do not know.
>>>
>>> Could anyone  point me in the right direction? Thank you very much.
>>>
>>> Thanks a lot,
>>> Jose.
>>>
>>>
>>>
>

Mime
View raw message