8 Replies Latest reply on Jan 29, 2019 4:54 PM by jfisherdev

    Offline CLI Alternatives?

    jfisherdev

      I am currently working on upgrading from WildFly 9.0.2.Final to WildFly 15.

       

      I have a Java-based deployment process that is used to set up a base WildFly configuration and does the following:

      • Unpacking downloaded WildFly distribution
      • Copying added-on files to the modules directory and other locations of the unpacked distribution, as well as deleting items that are not needed.
      • Configuring management resources for interfaces and socket bindings

       

      This process currently does management resource configuration by manipulating the standalone.xml file.

       

      While it works, I have been trying to move away from XML manipulation and using the management API whenever possible.

       

      I understand that since WildFly 9 the CLI has supported embedding an offline server for configuration purposes specifically like the one I mentioned earlier as discussed here

      Offline CLI Work

       

      It also sounds like this has more capabilities in newer versions.

       

      I am open to using this CLI approach, but was wondering if there are alternatives. For example, I am familiar with writing Java applications that use the ModelControllerClient API and

      would find it natural to incorporate that into the process, though I am not sure how to embed an offline server or how to communicate with it.

       

      If the CLI is the way to go, the main thing I would be looking for are resources and/or recommendations about how to embed/incorporate that in a Java-based process.

       

      Also, if there are any tools that can help with other parts of the deployment process, such as adding on modules, I would be interested to learn more about that as well.

       

      I appreciate any further information that may help.

        • 1. Re: Offline CLI Alternatives?
          mayerw01
          1 of 1 people found this helpful
          • 2. Re: Offline CLI Alternatives?
            jfisherdev

            What I am mainly looking to do is start an offline server [no management interfaces open] in a Java process and to do some configuration on it.

             

            I understand this can be done using the CLI, but was wondering if there were other approaches to this before I proceed with it.

             

            The Advanced CLI scripting article links to this article about the CLI public API which I may look into if I need something more complicated JBoss AS7 Command-line public API

             

            The other two things that maybe come to mind, but am not sure if they would work for this purpose:

             

            • The embedded API as discussed in the developer documentation Developer Guide
            • The wildfly-launcher API using CliCommandBuilder or one of the other CommandBuilder implementations [jamezp could these be used to launch an offline server?]

             

            Thank you for the information.

            • 3. Re: Offline CLI Alternatives?
              jamezp

              The launcher API is meant to mimic what the scripts would do. So you could use it and pass the --admin-only argument.

               

              That said you could use CLI and CLI scripts.

              embed-server
              /system-property=my.config.property:add(value="dev")
              
              
              module add --name=org.postgresql --resources=~/Downloads/postgresql-9.4-1203.jdbc42.jar --dependencies=javax.api,javax.transaction.api
              
              
              batch
              /subsystem=datasources/jdbc-driver=org.postgresql:add(driver-name=org.postgresql, driver-module-name=org.postgresql, driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource)
              /subsystem=datasources/data-source=postgresql:add(driver-name=org.postgresql, jndi-name="java:/jdbc/PostgresDS", enabled=true, connection-url="jdbc:postgresql://localhost/test")
              run-batch
              
              
              stop-embedded-server
              
              
              

               

              Then you'd just run it like

              $JBOSS_HOME/bin/jboss-cli.sh --file=my-script.cli

               

              --

              James R. Perkins

              1 of 1 people found this helpful
              • 4. Re: Offline CLI Alternatives?
                mayerw01

                I understand this can be done using the CLI, but was wondering if there were other approaches to this before I proceed with it.

                 

                In previous versions JBoss suported JSR-88 (JavaTM EE Application Deployment). But as mentioned in WildFly 8 Final is released! · WildFly JSR-88 is not supported anymore. so CLI is this only option for WildFly.

                • 5. Re: Offline CLI Alternatives?
                  jfisherdev

                  mayerw01 I would say you are correct about the CLI being the way to go

                   

                  I think I see now that offline configuration using the management API is unique to the CLI if I understand things correctly, which is what I was trying to figure out initially.

                   

                  What I will probably look at doing is having my Java process use the wildfly-launcher API to start the CLI to run a CLI script that does offline configuration--thank you jamezp for the information on that.

                   

                  That should probably cover what I need, but if I need something more complicated I can look at embedding the CLI in my process.

                   

                  Thank you both for your input.

                  • 6. Re: Offline CLI Alternatives?
                    jfisherdev

                    This is the way I am currently going and it seems to be working so far.

                     

                    One thing I wanted to note about this in case anyone else decides to try it is that it requires explicitly adding a JBOSS_HOME environment variable when building the Launcher like this:

                     

                    void launchCLI() {
                        final String wildflyHome = ...;
                        final String scriptPath = ...;   
                       
                        CliCommandBuilder cliBuilder = CliCommandBuilder.of(wildflyHome);
                        cliBuilder.setScriptFile(scriptPath);
                        ...
                    
                        Launcher launcher = Launcher.of(cliBuilder);
                        launcher.addEnvironmentVariable("JBOSS_HOME", wildflyHome);
                        ...
                    }

                     

                    The embed-server command in particular made this apparent, as it requires a home directory either from the JBOSS_HOME environment variable or the --jboss-home argument, which is not allowed in a modular environment, which is how I understand the Launcher will start the CLI.

                     

                    I have not used the Launcher API beyond this yet, though I am looking at it for future use, but I was wondering if this environment variable always needs to be set like this when using the Launcher for other processes besides the CLI, or if this was a unique case?

                    • 7. Re: Offline CLI Alternatives?
                      jamezp

                      I'd consider it a bug if the JBOSS_HOME is required by CLI and not being set in the launcher API. This should be unique to CLI. You might also be able to set the jboss.home or jboss.home.dir environment variables IIRC.

                       

                      --

                      James R. Perkins

                      • 8. Re: Offline CLI Alternatives?
                        jfisherdev

                        I looked into it a bit further and here is what I could gather [keep in mind my understanding of the internals of the CLI is pretty limited]:

                         

                        The CLI appears to get JBOSS_HOME information in two different ways:

                        1. Using JBOSS_HOME environment variable obtained through System.getEnv()/WildFlySecurityManager.getEnvPropertyPrivileged()
                        2. Using jboss.home.dir system property obtained through System.getProperty()/WildFlySecurityManager.getPropertyPrivileged()

                         

                        It appears to be context-specific as far as which one gets used, though the JBOSS_HOME environment variable appears to be used more often.

                         

                        I did a less complicated test of using the the Launcher to simply run the version command, which echoes the JBOSS_HOME environment variable, and found that it would show null unless the Launcher sets the JBOSS_HOME environment variable.

                         

                        It looks like the jboss-cli.bat/sh scripts do set the JBOSS_HOME environment variable. The CliCommandBuilder currently sets the jboss.home.dir system property using the home directory passed to it, but not the JBOSS_HOME environment variable.

                         

                        It would seem to make sense to have the Launcher set JBOSS_HOME when launching the CLI [probably just for the CLI and not for standalone/domain server processes from the sound of it], but I would defer to you and those more familiar with the CLI and Launcher to determine if that is something that needs to be fixed.

                         

                        I think I have what I need to keep going and can set the JBOSS_HOME environment variable for now.

                         

                        Thank you for your help.