CLI scripts: flow control and commands vs operations

Latest response

We are trying to write some CLI scripts that can be used on both standalone development servers and domain-managed production servers.
'if' flow control statements are not working how I would expect them to.

E.g., running this file on a standalone server:

if (result == DOMAIN) of /:read-attribute(name=launch-type)
    cd /profile=my_profile
end-if

results in:

JBAS014808: Child resource '"profile" => "my_profile"' not found
Press any key to continue . . .

I would not expect the 'cd' line to be evaluated. Is this a bug, or a misunderstanding of how the flow control statements work?
Tried in both EAP 6.2 and EAP 6.3-beta with the same result.

Responses

I have recreated your example script and get the same results when running a 'standalone' instance. I have tried amending the logic a little but am still getting odd results. I have asked others for assistance and will report the results here when they come in.

David,

Sorry it's taken so long to get back to this topic. The issue you're describing is already logged as affecting WildFly, the upstream project upon which JBoss EAP is based. See full details here: https://issues.jboss.org/browse/WFLY-3662.

The if-then-else processing of JBoss EAP operates by treating the commands within the if-then-else statement as individual management CLI batches. The if-then-else condition is then evaluated and the appropriate batch is then processed. There is one important caveat here: any command which is not an operation - e.g. echo and module - is executed immediately, not added to the batch.

In your example:
if (result == DOMAIN) of /:read-attribute(name=launch-type)
cd /profile=my_profile
end-if

The "cd ..." line is run immediately the management CLI parses the line, regardless of the outcome of the test ("if (result == DOMAIN)").

Judging by JIRA issue WFLY-3662 this behaviour has been changed for WildFly and that change may be applied to JBoss EAP in a future release.

Given your example script, I can only suggest avoiding the "cd" command and instead referring to attributes by their full path.

Thanks Russell, I appreciate your efforts.

I will keep an eye on the JIRA issue and hope it trickles down to EAP at some point. In the meantime we are stuck with more complexity to manage between development and production environments.

Actually, based on this comment in the JIRA issue you referenced, I'm not sure that this will ever be fixed: "When the CLI is in a batch mode and meets a command which can't be a part of the batch, it executes the command right away. (That's a deliberate decision and is useful for commands like cd, etc.)"

David - I have tested your sample script on the upcoming JBoss EAP 6.4 release and confirmed that the behaviour is now as you expected. That is, there is no output because the server is running in 'standalone' mode. The change has been committed to the JBoss EAP 6.4 source, so barring a problem being found with this change and it being reverted, the behaviour will then be different. I would not expect this change to be backported to JBoss EAP 6.3 or JBoss EAP 6.2. I would encourage you to try this for yourself, at least to confirm that the behaviour is what you're seeking.

As a side note, JIRA WFLY-3662 is noted as having been resolved in WildFly 9.0.0 Alpha1. To test this I downloaded this build from the WildFly downloads page [1] and tested your example script against that version. Again I confirmed that the results are as you would expect.

[1] http://wildfly.org/downloads/