1

I have quite regular data source definition in standalone.xml

<subsystem xmlns="urn:jboss:domain:datasources:2.0">
    <datasources>
        <datasource jndi-name="java:jboss/datasources/MYDS" pool-name="MYDS" enabled="true" use-java-context="true">
            <connection-url>jdbc:hsqldb:file:MYDB</connection-url>
            <security>
                <user-name>superman</user-name>
            </security>
        </datasource>
   </datasources>
</subsystem>

Try to change some property from command-line and this works fine:

/subsystem=datasources/data-source=MYDS:write-attribute(name=connection-url,value=achooo)

result:

{
    "outcome" => "success",
    "response-headers" => {
        "operation-requires-reload" => true,
        "process-state" => "reload-required"
    }
}

But using ModelNode API, it gets me crazy.

ModelNode request = new ModelNode();
request.get(ClientConstants.OP_ADDR).add("subsystem", "datasources");
request.get(ClientConstants.OP_ADDR).add("data-source", "MYDS");
request.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);
request.get("connection-url").set("achooo");
myCliExecutor.executeCliCommandWithResult(request);

result:

{
    "outcome" => "failed",
    "failure-description" => "JBAS014746: name may not be null",
    "rolled-back" => true,
    "response-headers" => {"process-state" => "reload-required"}
}
LancerX
  • 1,211
  • 7
  • 23
  • 40

1 Answers1

1

You're DMR is not quite correct. For the write-attribute operation you need to define a name and value attribute. It should look something more like:

final ModelNode address = new ModelNode().setEmptyList();
address.add("subsystem", "datasources");
address.add("data-source", "ExampleDS");

ModelNode request = new ModelNode();
request.get(ClientConstants.OP_ADDR).set(address);
request.get(ClientConstants.OP).set(ClientConstants.WRITE_ATTRIBUTE_OPERATION);
request.get("name").set("connection-url");
request.get("value").set("achooo");
myCliExecutor.executeCliCommandWithResult(request);

In the org.wildfly.core:controller-client there is also an Operations helper which should help.

final ModelNode address = Operations.createAddress("subsystem", "datasources", "data-source", "MYDS");
final ModelNod op = Operations.createWriteAttributeOperation(address, "connection-url", "achooo");
myCliExecutor.executeCliCommandWithResult(op);
James R. Perkins
  • 16,800
  • 44
  • 60
  • Unfortunately on line `writeOp.get("name").set("connection-url");` I get java.lang.IllegalArgumentException because writeOp object has only `protected = false` and `value = "write-attribute"`. I dont have such API like Operations.createAddress, maybe because I use Wildfly 8.2 – LancerX Aug 20 '18 at 13:00
  • Ah yeah sorry. The `createAddress()` wasn't introduced until later. I think the `Operations.createWriteAttributeOperation()` should exist. I'll edit and fix the longer example though. It is incorrect my apologies for that. – James R. Perkins Aug 20 '18 at 16:47