2 Replies Latest reply on May 21, 2018 11:19 PM by Hasitha Wijesekara

    ModelControllerClient - Create XA Data Source

    Hasitha Wijesekara Newbie

      I want to create XA data source using wildfly native management interface. Following is the code i used.

       

      public void createDataSource(final Dataset dataset) {

          try {

            final ModelControllerClient client = createClient(this.host, PORT, this.user, this.password.toCharArray());

       

            final ModelNode request = new ModelNode();

            request.get(ClientConstants.OP).set(ClientConstants.ADD);

          

            request.get(ClientConstants.OP_ADDR).add("subsystem", "datasources");

            request.get(ClientConstants.OP_ADDR).add("xa-data-source", dataset.getName());

       

            request.get("xa-datasource-properties").add("ServerName", "localhost");

            request.get("xa-datasource-properties").add("PortNumber", "5432");

            request.get("xa-datasource-properties").add("DatabaseName", "test");

       

            request.get("enabled").set(true);

            request.get("jndi-name").set(this.jndiDatasourcePrefix + dataset.getName());

            request.get("pool-name").set("ds-" + dataset.getName());

       

            request.get("driver-name").set("postgresql");

            request.get("user-name").set(dataset.getUsername());

            request.get("password").set(dataset.getPassword());

       

            final ModelNode result = client.execute(new OperationBuilder(request).build());

       

            if (Operations.isSuccessfulOutcome(result)) {

              System.out.println(Operations.readResult(result));

            } else {

              System.out.println(Operations.getFailureDescription(result));

            }

            client.close();

          } catch (final Exception e) {

            LOGGER.error("Could not create continer datasource: {}", dataset.getName(), e);

          }

      }

       

      But i got following error.

       

      18:18:09,931 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 3) WFLYCTL0013: Operation ("add") failed - address: ([

          ("subsystem" => "datasources"),

          ("xa-data-source" => "rotterdam")

      ]) - failure description: "WFLYJCA0069: At least one xa-datasource-property is required for an xa-datasource"

       

      I can create non XA data source without any issue. Seems problem here setting the xa-datasource-property. I have tried different ways but non of them are success. What is the wrong in my code and what is correct way to create XA data source?

       

      Thanks.

        • 1. Re: ModelControllerClient - Create XA Data Source
          Tomaz Cerar Master

          create composite operation and add all your operations on it as steps.

          1 of 1 people found this helpful
          • 2. Re: ModelControllerClient - Create XA Data Source
            Hasitha Wijesekara Newbie

            Thanks for the support. I was able to create composite operation as bellow and it's work successfully.

             

            final ModelNode request = new ModelNode();

            request.get(ClientConstants.OP).set(ClientConstants.COMPOSITE);

            request.get(ClientConstants.OP_ADDR).setEmptyList();

             

            final ModelNode stepNode1 = new ModelNode();

            stepNode1.get(ClientConstants.OP).set(ClientConstants.ADD);

            stepNode1.get(ClientConstants.OP_ADDR).add("subsystem", "datasources");

            stepNode1.get(ClientConstants.OP_ADDR).add("xa-data-source", "test");

             

            stepNode1.get("enabled").set(true);

            stepNode1.get("jndi-name").set("java:jboss/datasources/test");

            stepNode1.get("user-name").set("xxxxx");

            stepNode1.get("password").set("xxxxx");

            stepNode1.get("driver-name").set("postgresql");

             

            final ModelNode stepNode2 = new ModelNode();

            stepNode2.get(ClientConstants.OP_ADDR).add("subsystem", "datasources");

            stepNode2.get(ClientConstants.OP_ADDR).add("xa-data-source", "test");

            stepNode2.get(ClientConstants.OP_ADDR).add("xa-datasource-properties", "url");

            stepNode2.get(ClientConstants.OP).set(ClientConstants.ADD);

            stepNode2.get(ClientConstants.VALUE).set("jdbc:postgresql://localhost:5432/testdb");

             

            request.get(ClientConstants.STEPS).add(stepNode1);

            request.get(ClientConstants.STEPS).add(stepNode2);

             

            client.execute(new OperationBuilder(request).build());