Name: wildfly-config-api
Owner: WildFly Swarm
Owner: Thorntail
Description: Java API to configure Wildfly subsystems. Translates Java to DMR and vice versa.
Created: 2015-07-31 15:35:08.0
Updated: 2018-05-18 12:26:37.0
Pushed: 2018-04-20 08:42:11.0
Size: 15373
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
This projects breaks down into three parts:
generator
module)api
module)generator
and api
modules.The generator
module provides facilities to create a Java API which represents
the Wildfly management model (or parts of it).
The configuration API contains the object model created by the generator. Client such as WildFly Swarm may use this generated API to configure a running instance of WildFly via a fluent Java API.
The Javadocs for the generated API can be found at: http://wildfly-swarm.github.io/wildfly-config-api/
The API is created from the Wildfly management model as part of the maven build. It requires an active Wildfly instance to access the meta data and execute the integration tests.
./bin/standalone.sh -server-config=standalone-full-ha.xml
*-config.json
to reflect your setupmvn clean install
If all goes well, you be able to access the generated sources at
api/target/generated-sources
.
Clients typically depend on the API library itself, as well as the runtime
library to marshal between Java configuration instances and the JBoss DMR
ModelNode
instances.
endency>
<groupId>org.wildfly</groupId>
<artifactId>api</artifactId>
<version>...</version>
pendency>
endency>
<groupId>org.wildfly</groupId>
<artifactId>runtime</artifactId>
<version>...</version>
pendency>
Java to DMR
To generate DMR from Java simply instantiate the object model and run it through the EntityAdapter<T>
:
Source dataSource = ...;
tyAdapter<DataSource> entityAdapter = new EntityAdapter<>(DataSource.class);
lNode modelNode = entityAdapter.fromEntity(dataSource);
DMR to Java
Creating object instances work
in a similar way, by using the EntityAdapter<T>
:
lNode payload = ...;
tyAdapter<DataSource> entityAdapter = new EntityAdapter<>(DataSource.class);
Source dataSource = entityAdapter.fromDMR(payload);
Expressions
Expression replace actual values in the configuration model and will be resolved at runtime.
To set an expression for an attribute through the java API, you'd simply put
and expression for a given java property name:
aSource dataSource = ...;
aSource.put("userName", "${database.user.name:defaultName}");
aSource.password("...");
This will resolve the database.user.name
property at runtime and fallback to the value “defaultName” if the expression cannot be resolved.
Changesets
Modification to the java objects can be captured in changesets. The EntityAdapter turns these changes into a series of write-attribute operations (composite op).
Source dataSource = ...;
etup capture
String, Object> changeset = new HashMap<>();
Source.addPropertyChangeListener(evt -> {
changeset.put(evt.getPropertyName(), evt.getNewValue());
odify beans
Source.userName("...");
Source.password("...");
tyAdapter<DataSource> entityAdapter = new EntityAdapter<>(DataSource.class);
lNode operation = entityAdapter.fromChangeset(changeset, "ds-name");
The IntegrationTestCase.java
contains more examples.
This is pretty much work in it's early stages. Use cases covered by the test cases seem to work, but we didn't test plenty of scenarios.
But the project as it is should give you an idea where the config-lib is heading and what it might be used for.
Feel free to create ticket right here on github, fork the code and send pull request or join us on the Wildfly IRC channels and mailing lists.