0

I'm accessing the Wildfly CLI through the Java API using the ModelControllerClient (and the ServerDeploymentManager).

I'd like to run my changes as a CLI batch, but can't find an API for that.

Simply executing new ModelNode().get("operation").set("batch"); throws a WFLYCTL0031: No operation named 'batch' exists at address [].

Maybe the batch command is like the other 'convenience methods' like data-source add, etc.? How would I execute those?

rü-
  • 2,129
  • 17
  • 37

1 Answers1

1

There is no batch operation, it's a CLI command only. The ModelControllerClient accepts DMR operations. CLI converts commands into DMR operations. What you're looking for is a composite operation.

There is a helper in the in the org.wildfly.core:wildfly-controller-client dependency. Here's an example of using the CompositeOperationBuilder.

import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.Operation;
import org.jboss.as.controller.client.helpers.Operations.CompositeOperationBuilder;
import org.jboss.dmr.ModelNode;

public class ExampleOperation {

    public ModelNode executeCompositeOperation(final ModelControllerClient client, final ModelNode... ops) throws IOException {
        final CompositeOperationBuilder builder = CompositeOperationBuilder.create(true);
        for (ModelNode op : ops) {
            builder.addStep(op);
        }
        final ModelNode result = client.execute(builder.build());
        if (!Operations.isSuccessfulOutcome(result)) {
            throw new RuntimeException(Operations.getFailureDescription(result).asString());
        }
        return Operations.readResult(result);
    }
}

If you're also using the ServerDeploymentManager there is a newish API which that has a few more options. It's what the wildfly-maven-plugin uses internally and it's now just a separate module so others can consume it.

James R. Perkins
  • 16,800
  • 44
  • 60