1

I am trying to configure WildFly using wildfly-maven-plugin and I keep getting different exceptions, but non of my approaches works.

    Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:2.0.1.Final:execute-commands (Configure2) on project xp-distribution: Command execution failed for command '        attribute-mapping=[{index=1, to=roles}]}])'. {
    "outcome" => "failed",
    "failure-description" => {
        "WFLYCTL0412: Required services that are not installed:" => ["org.wildfly.data-source.xpDS"],
        "WFLYCTL0180: Services with missing/unavailable dependencies" => ["org.wildfly.security.security-realm.xpDbRealm is missing [org.wildfly.data-source.xpDS]"]
    },
    "rolled-back" => true
}

my configuration looks like:

<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.1.Final</version>
<executions>
    <execution>
        <id>start-wildfly1</id>
        <goals>
            <goal>start</goal>
        </goals>
        <phase>prepare-package</phase>
    </execution>
    <execution>
        <id>Configure1</id>
        <phase>install</phase>
        <goals>
            <goal>execute-commands</goal>
        </goals>
        <configuration>
            <commands>
                <command>module add --name=org.postgresql
                    --dependencies=javax.api,javax.transaction.api
                    --resources=${project.build.directory}${file.separator}postgresql-${version.postgres.jdbc}.jar</command>
                <command>/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql", driver-class-name="org.postgresql.Driver")</command>
                <command>data-source add
                    --name=xpDS
                    --driver-name=postgres
                    --connection-url=jdbc:postgresql://localhost:5432/xp_test
                    --jndi-name=java:jboss/datasources/xpDS
                    --use-java-context=true
                    --user-name=postgres
                    --password=postgres
                    --max-pool-size=25
                    --blocking-timeout-wait-millis=5000
                    --idle-timeout-minutes=5
                    --enabled=true</command>
            </commands>
        </configuration>
    </execution>
    <execution>
        <id>Configure2</id>
        <phase>install</phase>
        <goals>
            <goal>execute-commands</goal>
        </goals>
        <configuration>
            <batch>false</batch>
            <scripts>
                <script>src/templates/xd1.cli</script>
            </scripts>
        </configuration>
    </execution>
    ...

I tried to restart wildfly in between adding datasource and executing script, but error stays the same. Going to target/wildfly-15.0.1.Final/modules I can see that the PostgreSQL module has been added there. Opening standalone.xml we can find that xpDS (data-source) has been added.

xd1.cli file :

###create JDBC-Realm for user validation
/subsystem=elytron/jdbc-realm=xpDbRealm:add( \
    principal-query=[ \
        { data-source=xpDS, \
        sql="select PASSWORD, SALT, ITERATION_COUNT from T_USER WHERE status = TRUE AND username = ?", \
        scram-mapper={algorithm=scram-sha-256,password-index=1, salt-index=2, iteration-count-index=3}}, \
        {data-source=xpDS, \
        sql="SELECT r.name AS name, 'Roles' as roles from ROLE r INNER JOIN JOIN_UO j ON j.roles = r.u_id INNER JOIN USER u ON j.users = u.um_id WHERE u.username = ?", \
        attribute-mapping=[{index=1, to=roles}]}])

###Adding user role decoders
/subsystem=elytron/simple-role-decoder=from-roles-attribute:add(attribute=roles)

:reload


###Creating a Elytron security domain and adding the created JDBC-Realms
./subsystem=elytron/security-domain=xpDbSD:add( \
    realms=[{realm=xpDbRealm, role-decoder=from-roles-attribute}, \
            {realm=local, role-mapper=super-user-mapper}], \
    default-realm=xpDbRealm, \
    permission-mapper=default-permission-mapper, post-realm-principal-transformer=myPostPrincipalTransformer)

:reload

Should I keep using install phase? Any suggestion how to fix this issue?

Serafins
  • 1,237
  • 1
  • 17
  • 36

1 Answers1

3

The reload doesn't work so well with the plugin. However you can use offline CLI which will start an embedded server and execute the commends. You'll need to set the jboss-home property to use the embedded server.

Here's an example:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>validate</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>org.wildfly</groupId>
                        <artifactId>wildfly-dist</artifactId>
                        <version>15.0.1.Final</version>
                        <type>zip</type>
                        <overWrite>false</overWrite>
                        <outputDirectory>target</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <version>2.0.1.Final</version>
    <configuration>
        <offline>true</offline>
        <jboss-home>target/wildfly-15.0.1.Final</jboss-home>
    </configuration>
    <executions>
        <execution>
            <id>Configure1</id>
            <phase>install</phase>
            <goals>
                <goal>execute-commands</goal>
            </goals>
            <configuration>
                <commands>
                    <command>embed-server</command>
                    <command>module add --name=org.postgresql
                        --dependencies=javax.api,javax.transaction.api
                        --resources=${project.build.directory}${file.separator}postgresql-${version.postgres.jdbc}.jar</command>
                    <command>/subsystem=datasources/jdbc-driver=postgres:add(driver-name="postgres",driver-module-name="org.postgresql", driver-class-name="org.postgresql.Driver")</command>
                    <command>data-source add
                        --name=xpDS
                        --driver-name=postgres
                        --connection-url=jdbc:postgresql://localhost:5432/xp_test
                        --jndi-name=java:jboss/datasources/xpDS
                        --use-java-context=true
                        --user-name=postgres
                        --password=postgres
                        --max-pool-size=25
                        --blocking-timeout-wait-millis=5000
                        --idle-timeout-minutes=5
                        --enabled=true</command>
                    <command>stop-embedded-server</command>
                </commands>
            </configuration>
        </execution>
        <execution>
            <id>Configure2</id>
            <phase>install</phase>
            <goals>
                <goal>execute-commands</goal>
            </goals>
            <configuration>
                <batch>false</batch>
                <scripts>
                    <script>src/templates/xd1.cli</script>
                </scripts>
            </configuration>
        </execution>
    </executions>
</plugin>

You'd need to add the embed-server and stop-embedded-server in your CLI script too.

James R. Perkins
  • 16,800
  • 44
  • 60
  • thanks! I had to add \ after every line. First part is being executed, however, second one is failing. _"WFLYCTL0412: Required services that are not installed:" => ["org.wildfly.data-source.XpDS"]_ How should I add **embed-server** to my CLI file? I added in the fisr line, without : is that correct? – Serafins Sep 13 '19 at 13:02
  • but XpDS is present in standalone.xml – Serafins Sep 13 '19 at 13:11
  • Yes. They are high level commands so you’d enter them without the :. – James R. Perkins Sep 14 '19 at 01:03
  • Okay, but still second Config doesn't see changes from the first one. Basically XpDS is missing, but once I open standalone manually, data source is defined there. Any idea? – Serafins Sep 15 '19 at 08:48
  • Is there a reason not to just add it all to the script instead of having part of it in a script and part of it in the POM? Also make sure the server is started after these commands are executed. – James R. Perkins Sep 16 '19 at 16:29
  • The only thing that stops me from placing everything in one file is actually adding Postgres driver, the version is taken from Maven properties and with an update on I do not want to update CLI file. – Serafins Sep 19 '19 at 08:22
  • Creating a single file, starting a server and running the file I get en exception: **WFLYEMB0024: The embedded server is reloading and invocations on the ModelControllerClient are not yet available** – Serafins Sep 19 '19 at 08:56
  • It's ideal, especially from the plugin, to use offline CLI to configure the server. Reloads just don't work well from the plugin. – James R. Perkins Sep 19 '19 at 17:53
  • I am not sure if that didn't work with a previous WildFly or with older plugin or I did something wrong but it works perfectly fine with WildFly 19 ! I added **embed-server** and **stop-embedded-server** in every file and removed all **:reload** Thanks @James – Serafins May 14 '20 at 14:41