-
Notifications
You must be signed in to change notification settings - Fork 288
Application Properties
The properties are important aspect of any application. They enable configuration reusability across different components like activities/triggers across different flows. e.g. Log level for all LOG Message activities in given app to be set to INFO initially and later change to DEBUG. Here is proposal to let Flogo developers define application level properties which can be used in:
- Activity Mappings
- Action Mappings
- Activity Configuration
- Trigger Configuration
For simple usecases, following model should be sufficient.
{
"name": "FlogoApp",
....
"properties": [
{
"name": <PROPERTY_NAME>, // Name of property
"type": <PROPERTY_TYPE>, // Type of property. Supported Types - string, boolean, long, double, integer, object
"value": <PROPERTY_DEFAULT_VALUE>
}
],
...
}
These properties can be referenced by $property[<PROPERTY_NAME>]
A developer can switch to a certain profile by setting FLOGO_APP_PROFILE_FILE environment variable.
Sometimes grouping of properties is desired for convenience and naming consistency. e.g. same DB_URL property name for both Inventory and Approval services instead of INVENTORY_SERVICE_DB_URL and APPROVAL_SERVICE_DB_URL
{
"name": "FlogoApp",
....
"properties": [
{
"name": <HIERARCHICAL_PATH>.<PROPERTY_NAME>, // Name of property
"type": <PROPERTY_TYPE>, // Type of property. Supported Types - string, boolean, long, double, integer
"value": <PROPERTY_DEFAULT_VALUE>
}
],
.....
}
e.g.
[
{
"name": "services.inventory.postgres.DB_URL",
"type": "string"
"value": "postges://localhost:5233/mydb"
},
{
"name": "services.approval.postgres.DB_URL",
"type": "string"
"value": "postges://localhost:5233/mydb"
}
]
[
{
"name": "services.inventory.postgres.DB_URL",
"type": "string"
"value": "$env[ENV_DB_URL]"
},
{
"name": "services.approval.postgres.DB_URL",
"type": "string"
"value": "postges://localhost:5233/mydb"
}
]
These properties can be referenced by $property[services.approval.postgres.DB_URL] or $property[services.inventory.postgres.DB_URL]
You can override app properties at runtime in two ways:
Using JSON: Define your new value for a given app prop in a json file as shown below:
props.json
{
"MyProp1": "This is new value",
"MyProp2": 20
}
Run app with FLOGO_APP_PROPS_OVERRIDE=props.json ./MyApp
Using Key/Value pair:
Run app with FLOGO_APP_PROPS_OVERRIDE="MyProp1=This is newvalue,MyProp2=30" ./MyApp
You can plug-in your own value resolver to resolve application property value from external configuration management services Consul, Spring Cloud Config etc. Just implement following interface and register implementation with the runtime:
// PropertyValueResolver used to resolve value from external configuration like env, file etc
type PropertyValueResolver interface {
// Should return value and true if the given application property exists in the external configuration otherwise should return nil and false.
LookupValue(propertyName string) (interface{}, bool)
}
Sample Resolver
package sampleresolver
type SamplePropertyResolver struct {
}
func init() {
app.RegisterPropertyValueResolver("sampleresolver", &SamplePropertyResolver{})
}
func (resolver *SamplePropertyResolver) LookupValue(propertyName string) (interface{}, bool) {
// Resolve property value
return some_value, true
}
Set FLOGO_APP_PROPS_RESOLVERS
to sampleresolver
while running application.
e.g.
FLOGO_APP_PROPS_RESOLVERS=sampleresolver ./<app_binary>