org.wildfly.swarm:config-api-generator

WildFly Swarm: Parent

License

License

AL2
Categories

Categories

WildFly Container Application Servers config Application Layer Libs Configuration
GroupId

GroupId

org.wildfly.swarm
ArtifactId

ArtifactId

config-api-generator
Last Version

Last Version

1.3.1
Release Date

Release Date

Type

Type

jar
Description

Description

WildFly Swarm: Parent
Project Organization

Project Organization

JBoss by Red Hat

Download config-api-generator

How to add to project

<!-- https://jarcasting.com/artifacts/org.wildfly.swarm/config-api-generator/ -->
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>config-api-generator</artifactId>
    <version>1.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.wildfly.swarm/config-api-generator/
implementation 'org.wildfly.swarm:config-api-generator:1.3.1'
// https://jarcasting.com/artifacts/org.wildfly.swarm/config-api-generator/
implementation ("org.wildfly.swarm:config-api-generator:1.3.1")
'org.wildfly.swarm:config-api-generator:jar:1.3.1'
<dependency org="org.wildfly.swarm" name="config-api-generator" rev="1.3.1">
  <artifact name="config-api-generator" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.wildfly.swarm', module='config-api-generator', version='1.3.1')
)
libraryDependencies += "org.wildfly.swarm" % "config-api-generator" % "1.3.1"
[org.wildfly.swarm/config-api-generator "1.3.1"]

Dependencies

compile (9)

Group / Artifact Type Version
org.jboss.xnio : xnio-api jar 3.5.0.Beta6
org.jboss.xnio : xnio-nio jar 3.5.0.Beta6
org.wildfly.swarm : config-api-runtime jar 1.3.1
org.wildfly.core : wildfly-controller jar
org.wildfly.core : wildfly-server jar
com.google.guava : guava jar 18.0
org.jboss.forge.roaster : roaster-jdt jar 2.19.4.Final
com.eclipsesource.minimal-json : minimal-json jar 0.9.4
org.jboss : jandex jar 2.0.0.Beta1

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

WildFly Configuration API

This projects breaks down into three parts:

  • API Generator (generator module)
  • Generated WildFly configuration API (api module)
  • Runtime dependencies for both the 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/

Generating the 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.

  1. Start a stock Wildfly 10 distribution in standalone full ha mode ./bin/standalone.sh -server-config=standalone-full-ha.xml
  2. Update the *-config.json to reflect your setup
  3. Perform a regular maven build mvn clean install

If all goes well, you be able to access the generated sources at api/target/generated-sources.

Working with the config API

Maven dependencies

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.

<dependency>
	<groupId>org.wildfly</groupId>
	<artifactId>api</artifactId>
	<version>...</version>
</dependency>
<dependency>
	<groupId>org.wildfly</groupId>
	<artifactId>runtime</artifactId>
	<version>...</version>
</dependency>

API usage

Java to DMR

To generate DMR from Java simply instantiate the object model and run it through the EntityAdapter<T>:

DataSource dataSource = ...;
EntityAdapter<DataSource> entityAdapter = new EntityAdapter<>(DataSource.class);
ModelNode modelNode = entityAdapter.fromEntity(dataSource);

DMR to Java

Creating object instances work in a similar way, by using the EntityAdapter<T>:

ModelNode payload = ...;
EntityAdapter<DataSource> entityAdapter = new EntityAdapter<>(DataSource.class);
DataSource 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:

 DataSource dataSource = ...;

 dataSource.put("userName", "${database.user.name:defaultName}");
 dataSource.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).

DataSource dataSource = ...;

// setup capture 
Map<String, Object> changeset = new HashMap<>();
dataSource.addPropertyChangeListener(evt -> {
	changeset.put(evt.getPropertyName(), evt.getNewValue());
});

// modify beans
dataSource.userName("...");
dataSource.password("...");

EntityAdapter<DataSource> entityAdapter = new EntityAdapter<>(DataSource.class);
ModelNode operation = entityAdapter.fromChangeset(changeset, "ds-name");

The IntegrationTestCase.java contains more examples.

Status and limitations

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.

Contributions

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.

org.wildfly.swarm

WildFly Swarm

WildFly deconstructed

Versions

Version
1.3.1
1.3.0
1.2.0
1.1.0.Final
1.0.3.Final
1.0.2.Final
1.0.1.Final
1.0.0.Final
0.5.3
0.5.2
0.5.1
0.5.0
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.28
0.3.27
0.3.26
0.3.25
0.3.24
0.3.23
0.3.22
0.3.21
0.3.20
0.3.18
0.3.17
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.5