Using properties in Wildfly-CLI scripts for if/else Logic











up vote
0
down vote

favorite












In the Wildfly CLI-scripts it is possible to test for existence of a resource and execute some conditional logic:



if (outcome != success) of /subsystem=datasources/xa-data-source=MY_DATASOURCE:read-resource  
// now do something


When you run the cli, you can provide properties that are available in your scripts like this:



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


I would like to introduce some conditional logic based on these properties to do some conditional configuration.



One example is that to configure a mail-server, sometimes the mail-server requires a username and a password and in other cases it allows anonymous access. When setting up the mail-server config i would like to be able to have conditional logic like this



if MAILSERVER_USERNAME is defined //confiure mailserver with username password else // configure mailserver without attributes username/password


The only thing that I can see that is possible is if I already have added a system-property setting to my standalone-full.xml, i can query it like this:



if (outcome != success) of /system-property=foo:read-resource  
// now do something


I would like to do something simuilar based on the properties passed in from my.properties.



Is this possible?



Thanks,



Daniel










share|improve this question


























    up vote
    0
    down vote

    favorite












    In the Wildfly CLI-scripts it is possible to test for existence of a resource and execute some conditional logic:



    if (outcome != success) of /subsystem=datasources/xa-data-source=MY_DATASOURCE:read-resource  
    // now do something


    When you run the cli, you can provide properties that are available in your scripts like this:



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


    I would like to introduce some conditional logic based on these properties to do some conditional configuration.



    One example is that to configure a mail-server, sometimes the mail-server requires a username and a password and in other cases it allows anonymous access. When setting up the mail-server config i would like to be able to have conditional logic like this



    if MAILSERVER_USERNAME is defined //confiure mailserver with username password else // configure mailserver without attributes username/password


    The only thing that I can see that is possible is if I already have added a system-property setting to my standalone-full.xml, i can query it like this:



    if (outcome != success) of /system-property=foo:read-resource  
    // now do something


    I would like to do something simuilar based on the properties passed in from my.properties.



    Is this possible?



    Thanks,



    Daniel










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      In the Wildfly CLI-scripts it is possible to test for existence of a resource and execute some conditional logic:



      if (outcome != success) of /subsystem=datasources/xa-data-source=MY_DATASOURCE:read-resource  
      // now do something


      When you run the cli, you can provide properties that are available in your scripts like this:



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


      I would like to introduce some conditional logic based on these properties to do some conditional configuration.



      One example is that to configure a mail-server, sometimes the mail-server requires a username and a password and in other cases it allows anonymous access. When setting up the mail-server config i would like to be able to have conditional logic like this



      if MAILSERVER_USERNAME is defined //confiure mailserver with username password else // configure mailserver without attributes username/password


      The only thing that I can see that is possible is if I already have added a system-property setting to my standalone-full.xml, i can query it like this:



      if (outcome != success) of /system-property=foo:read-resource  
      // now do something


      I would like to do something simuilar based on the properties passed in from my.properties.



      Is this possible?



      Thanks,



      Daniel










      share|improve this question













      In the Wildfly CLI-scripts it is possible to test for existence of a resource and execute some conditional logic:



      if (outcome != success) of /subsystem=datasources/xa-data-source=MY_DATASOURCE:read-resource  
      // now do something


      When you run the cli, you can provide properties that are available in your scripts like this:



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


      I would like to introduce some conditional logic based on these properties to do some conditional configuration.



      One example is that to configure a mail-server, sometimes the mail-server requires a username and a password and in other cases it allows anonymous access. When setting up the mail-server config i would like to be able to have conditional logic like this



      if MAILSERVER_USERNAME is defined //confiure mailserver with username password else // configure mailserver without attributes username/password


      The only thing that I can see that is possible is if I already have added a system-property setting to my standalone-full.xml, i can query it like this:



      if (outcome != success) of /system-property=foo:read-resource  
      // now do something


      I would like to do something simuilar based on the properties passed in from my.properties.



      Is this possible?



      Thanks,



      Daniel







      jboss wildfly






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 7 at 10:41









      38leinad

      326




      326
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          The properties you pass through --properties can't be used in every context, which makes testing their existence bothersome :



          [standalone@localhost] :resolve-expression(expression=$myProperty)
          Unrecognized variable myProperty
          [standalone@localhost] :resolve-expression(expression=${myProperty})
          {
          "outcome" => "failed",
          "failure-description" => "WFLYCTL0211: Cannot resolve expression '${myProperty}'",
          "rolled-back" => true
          }


          You can however solve that problem by using the set command in your cli script :



          [standalone@localhost] set myProperty=${myProperty}
          [standalone@localhost] :resolve-expression(expression=$myProperty)
          {
          "outcome" => "success",
          "result" => "myValue"
          }


          You can then use the outcome of the resolve-expression command to test for the existence of your property :



          [standalone@localhost] if (outcome == success) of :resolve-expression(expression=$myProperty)
          [standalone@localhost] echo success ! myProperty is set ( $myProperty )
          [standalone@localhost] end-if
          success ! myProperty is set ( myValue )


          If your property isn't defined, trying to resolve it with resolve-expression will raise an error :



          [standalone@localhost] set myProperty=${notMyProperty}
          [standalone@localhost] :resolve-expression(expression=$myProperty)
          {
          "outcome" => "failed",
          "failure-description" => "WFLYCTL0211: Cannot resolve expression '${notMyProperty}'",
          "rolled-back" => true
          }





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187833%2fusing-properties-in-wildfly-cli-scripts-for-if-else-logic%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            The properties you pass through --properties can't be used in every context, which makes testing their existence bothersome :



            [standalone@localhost] :resolve-expression(expression=$myProperty)
            Unrecognized variable myProperty
            [standalone@localhost] :resolve-expression(expression=${myProperty})
            {
            "outcome" => "failed",
            "failure-description" => "WFLYCTL0211: Cannot resolve expression '${myProperty}'",
            "rolled-back" => true
            }


            You can however solve that problem by using the set command in your cli script :



            [standalone@localhost] set myProperty=${myProperty}
            [standalone@localhost] :resolve-expression(expression=$myProperty)
            {
            "outcome" => "success",
            "result" => "myValue"
            }


            You can then use the outcome of the resolve-expression command to test for the existence of your property :



            [standalone@localhost] if (outcome == success) of :resolve-expression(expression=$myProperty)
            [standalone@localhost] echo success ! myProperty is set ( $myProperty )
            [standalone@localhost] end-if
            success ! myProperty is set ( myValue )


            If your property isn't defined, trying to resolve it with resolve-expression will raise an error :



            [standalone@localhost] set myProperty=${notMyProperty}
            [standalone@localhost] :resolve-expression(expression=$myProperty)
            {
            "outcome" => "failed",
            "failure-description" => "WFLYCTL0211: Cannot resolve expression '${notMyProperty}'",
            "rolled-back" => true
            }





            share|improve this answer



























              up vote
              1
              down vote



              accepted










              The properties you pass through --properties can't be used in every context, which makes testing their existence bothersome :



              [standalone@localhost] :resolve-expression(expression=$myProperty)
              Unrecognized variable myProperty
              [standalone@localhost] :resolve-expression(expression=${myProperty})
              {
              "outcome" => "failed",
              "failure-description" => "WFLYCTL0211: Cannot resolve expression '${myProperty}'",
              "rolled-back" => true
              }


              You can however solve that problem by using the set command in your cli script :



              [standalone@localhost] set myProperty=${myProperty}
              [standalone@localhost] :resolve-expression(expression=$myProperty)
              {
              "outcome" => "success",
              "result" => "myValue"
              }


              You can then use the outcome of the resolve-expression command to test for the existence of your property :



              [standalone@localhost] if (outcome == success) of :resolve-expression(expression=$myProperty)
              [standalone@localhost] echo success ! myProperty is set ( $myProperty )
              [standalone@localhost] end-if
              success ! myProperty is set ( myValue )


              If your property isn't defined, trying to resolve it with resolve-expression will raise an error :



              [standalone@localhost] set myProperty=${notMyProperty}
              [standalone@localhost] :resolve-expression(expression=$myProperty)
              {
              "outcome" => "failed",
              "failure-description" => "WFLYCTL0211: Cannot resolve expression '${notMyProperty}'",
              "rolled-back" => true
              }





              share|improve this answer

























                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                The properties you pass through --properties can't be used in every context, which makes testing their existence bothersome :



                [standalone@localhost] :resolve-expression(expression=$myProperty)
                Unrecognized variable myProperty
                [standalone@localhost] :resolve-expression(expression=${myProperty})
                {
                "outcome" => "failed",
                "failure-description" => "WFLYCTL0211: Cannot resolve expression '${myProperty}'",
                "rolled-back" => true
                }


                You can however solve that problem by using the set command in your cli script :



                [standalone@localhost] set myProperty=${myProperty}
                [standalone@localhost] :resolve-expression(expression=$myProperty)
                {
                "outcome" => "success",
                "result" => "myValue"
                }


                You can then use the outcome of the resolve-expression command to test for the existence of your property :



                [standalone@localhost] if (outcome == success) of :resolve-expression(expression=$myProperty)
                [standalone@localhost] echo success ! myProperty is set ( $myProperty )
                [standalone@localhost] end-if
                success ! myProperty is set ( myValue )


                If your property isn't defined, trying to resolve it with resolve-expression will raise an error :



                [standalone@localhost] set myProperty=${notMyProperty}
                [standalone@localhost] :resolve-expression(expression=$myProperty)
                {
                "outcome" => "failed",
                "failure-description" => "WFLYCTL0211: Cannot resolve expression '${notMyProperty}'",
                "rolled-back" => true
                }





                share|improve this answer














                The properties you pass through --properties can't be used in every context, which makes testing their existence bothersome :



                [standalone@localhost] :resolve-expression(expression=$myProperty)
                Unrecognized variable myProperty
                [standalone@localhost] :resolve-expression(expression=${myProperty})
                {
                "outcome" => "failed",
                "failure-description" => "WFLYCTL0211: Cannot resolve expression '${myProperty}'",
                "rolled-back" => true
                }


                You can however solve that problem by using the set command in your cli script :



                [standalone@localhost] set myProperty=${myProperty}
                [standalone@localhost] :resolve-expression(expression=$myProperty)
                {
                "outcome" => "success",
                "result" => "myValue"
                }


                You can then use the outcome of the resolve-expression command to test for the existence of your property :



                [standalone@localhost] if (outcome == success) of :resolve-expression(expression=$myProperty)
                [standalone@localhost] echo success ! myProperty is set ( $myProperty )
                [standalone@localhost] end-if
                success ! myProperty is set ( myValue )


                If your property isn't defined, trying to resolve it with resolve-expression will raise an error :



                [standalone@localhost] set myProperty=${notMyProperty}
                [standalone@localhost] :resolve-expression(expression=$myProperty)
                {
                "outcome" => "failed",
                "failure-description" => "WFLYCTL0211: Cannot resolve expression '${notMyProperty}'",
                "rolled-back" => true
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 7 at 14:18

























                answered Nov 7 at 13:57









                Aaron

                14.6k11636




                14.6k11636






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53187833%2fusing-properties-in-wildfly-cli-scripts-for-if-else-logic%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()