Use conditional statements in WildFly CLI

综合编程 2018-03-14
Details
Published: 13 March 2018

WildFly Command Line Interfaceis not a real programming language with complex structures. Nevertheless it's possible to execute conditional logic in it and this short tutorial will show how to do it.

WildFly Command Line Interfacecontains the "if" keywords which can be used to build conditional logic.

here is the synopsys of the command:

if (condition_expression) of (command_line)

The if
statement includes a command that is executed at the beginning of the if-else control flow. After the response of the command_line is received from the controller, it is evaluated using the condition_expression.

The condition_expression
consists of a node path, equals sign ('==') and a specific value. If the target value designated with the node path equals to the specified value, then the condition is met and the if block (which is a batch) is executed.

If the condition wasn't met then the else
block, if present, would be executed.

For example, here is how you can execute a conditional deployment- e.g. to check if the application myproject.war is not already deployed:

if (outcome != success) of /deployment=myproject.war:read-resource   
     deploy myproject.war   
end-if

Another example, slightly more complex, will check if the com.mysql module has been already installed. The conditional execution will either install it (if not installed already) or just print a message (saying that it’s already installed):

if (outcome != success) of /core-service=module-loading/:list-resource-loader-paths(module=com.mysql)   
    module add --name=com.mysql --resources=mysql-connector-java-5.1.31-bin.jar --dependencies=javax.api,javax.transaction.api
else
    echo module com.mysql already installed
end-if

Finally, you can check also the return value of a particular node and execute conditional logic based on the value of it:

if (result.value==true) of /system-property=test:read-resource
        /system-property=test:write-attribute(name=value,value=false)
else
        /system-property=test:write-attribute(name=value,value=true)

您可能感兴趣的

Elytron: A New Security Framework in WildFly/JBoss... Elytron is a new security framework that ships with WildFly version 10 and Red Hat JBoss Enterprise Application Platform (EAP) 7.1. This proje...
A Look At Eclipse MicroProfile Healthcheck I recently looked at the Eclipse MicroProfile Healthcheck API to investigate its support in WildFly . WildFly Swarm is provi...
Deploying Certificates to WildFly with Octopus Dep... A recent feature added to Octopus Deploy is the ability to manage and deploy certificates within your infrastructure. In this blog, post I’ll show...
Hollowjars, Deployment scanner and why Wildfly swa... In aprevious post I described how you can use OpenLiberty and maven to start the server, either as a standalone, or as part of the maven build, and h...
Create a Singleton in a Cluster on WildFly 10 Details Published: 19 June 2017 Using a Singleton Service in a cluster is not something completely new concept. In JBo...