如何在Wildfly中使用CLI创建(或切换)xa-data-source?

时间:2014-08-04 14:46:22

标签: datasource command-line-interface wildfly

您好我需要使用CLI动态切换数据源。 我怎样才能做到这一点 ? 本手册有一些例子: https://docs.jboss.org/author/display/AS71/CLI+Recipes

我想删除旧的xa-data-source并创建新的。 但它不起作用。 这个命令:

xa-data-source add \
    --name=TestXADS \
    --driver-name=postgresql \
    --jndi-name=java:jboss/jdbc/TestXADS \
    --user-name=demouser \
    --password=password \
    --recovery-username= demouser \
    --recovery-password = password \
    --use-ccm=false \
    --max-pool-size=25 \
    --blocking-timeout-wait-millis=5000 \
    --new-connection-sql="set datestyle = ISO, European;"
/subsystem=datasources/xa-data-source=TestXADS/xa-datasource-properties=ServerName:add(value=localhost)
/subsystem=datasources/xa-data-source=TestXADS/xa-datasource-properties=PortNumber:add(value=5432)
/subsystem=datasources/xa-data-source=TestXADS/xa-datasource-properties=DatabaseName:add(value=arctic_naryan)
xa-data-source enable --name = TestXADS

给出了这个结果:

[standalone@127.0.0.1:9990 /] xa-data-source add \
>     --name=TestXADS \
>     --driver-name=postgresql \
>     --jndi-name=java:jboss/jdbc/TestXADS \
>     --user-name=demouser \
>     --password=password \
>     --recovery-username= demouser \
>     --recovery-password = password \
>     --use-ccm=false \
>     --max-pool-size=25 \
>     --blocking-timeout-wait-millis=5000 \
>     --new-connection-sql="set datestyle = ISO, European;"
{"JBAS014653: Composite operation failed and was rolled back. Steps that failed:
" => {"Operation step-1" => "JBAS010469: At least one xa-datasource-property is
required for an xa-datasource"}}

[standalone@127.0.0.1:9990 /] /subsystem=datasources/xa-data-source=TestXADS/xa-
datasource-properties=ServerName:add(value=localhost)
{
    "outcome" => "failed",
    "failure-description" => "JBAS014766: Resource [
    (\"subsystem\" => \"datasources\"),
    (\"xa-data-source\" => \"TestXADS\")
] does not exist; a resource at address [
    (\"subsystem\" => \"datasources\"),
    (\"xa-data-source\" => \"TestXADS\"),
    (\"xa-datasource-properties\" => \"ServerName\")
] cannot be created until all ancestor resources have been added",
    "rolled-back" => true
}
[standalone@127.0.0.1:9990 /] /subsystem=datasources/xa-data-source=TestXADS/xa-
datasource-properties=PortNumber:add(value=5432)
{
    "outcome" => "failed",
    "failure-description" => "JBAS014766: Resource [
    (\"subsystem\" => \"datasources\"),
    (\"xa-data-source\" => \"TestXADS\")
] does not exist; a resource at address [
    (\"subsystem\" => \"datasources\"),
    (\"xa-data-source\" => \"TestXADS\"),
    (\"xa-datasource-properties\" => \"PortNumber\")
] cannot be created until all ancestor resources have been added",
    "rolled-back" => true
}
[standalone@127.0.0.1:9990 /] /subsystem=datasources/xa-data-source=TestXADS/xa-
datasource-properties=DatabaseName:add(value=arctic_naryan)
{
    "outcome" => "failed",
    "failure-description" => "JBAS014766: Resource [
    (\"subsystem\" => \"datasources\"),
    (\"xa-data-source\" => \"TestXADS\")
] does not exist; a resource at address [
    (\"subsystem\" => \"datasources\"),
    (\"xa-data-source\" => \"TestXADS\"),
    (\"xa-datasource-properties\" => \"DatabaseName\")
] cannot be created until all ancestor resources have been added",
    "rolled-back" => true
}
[standalone@127.0.0.1:9990 /] xa-data-source enable --name = TestXADS

这是手册的例子。为什么它不起作用?

UPD。 试图执行此命令(根据Wildfly手册)

/subsystem=datasources/xa-data-source add --name=TestXADS  --driver-name=postgresql --jndi-name=java:jboss/jdbc/TestXADS 

但它没有帮助

[standalone@127.0.0.1:9990 /] /subsystem=datasources/xa-data-source add --name=T
estXADS  --driver-name=postgresql --jndi-name=java:jboss/jdbc/TestXADS
Can't proceed with node type 'TestXADS--driver-name' until the node name for the
 previous node type has been specified.
[standalone@127.0.0.1:9990 /]

1 个答案:

答案 0 :(得分:0)

您引用的文档不适用于WildFly,而是适用于JBoss AS 7.1.1.Final。大多数操作都是一样的,但有些操作已经改变。有关详细信息,请参阅新的CLI recipes

如果您尝试有条件地添加或删除数据源,请查看if-else control flow