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.