1

我在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>

尝试从命令行更改一些属性,这工作正常:

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

结果:

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

但是使用 ModelNode API,它让我抓狂。

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);

结果:

{
    "outcome" => "failed",
    "failure-description" => "JBAS014746: name may not be null",
    "rolled-back" => true,
    "response-headers" => {"process-state" => "reload-required"}
}
4

1 回答 1

1

你的 DMR 不太正确。对于write-attribute操作,您需要定义一个namevalue属性。它应该看起来更像:

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);

org.wildfly.core:controller-client里面还有一个Operations应该帮助的助手。

final ModelNode address = Operations.createAddress("subsystem", "datasources", "data-source", "MYDS");
final ModelNod op = Operations.createWriteAttributeOperation(address, "connection-url", "achooo");
myCliExecutor.executeCliCommandWithResult(op);
于 2018-08-09T17:09:45.217 回答