WildFly-maven-plugin: WFLYCTL0412: Required services that are not installed:

702 Views Asked by At

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?

1

There are 1 best solutions below

9
On BEST ANSWER

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.