5 Replies Latest reply on Oct 17, 2012 2:55 AM by olpf

    Using CLI in @Startup resource

    olpf

      Hi,

       

      I want to implement an automatically setup for the data sources upon environmental properties. Therefore I defined a class with @Startup and @Singleton (EJB) annotation and @PostConstruct method to setup the data sources on jboss startup. The code cleans and creates the data sources on every startup.

      If I test my code outside the @Startup, @Singleton, @PostConstruct it works. Unfortunately it doesn't work on jboss startup. E. g. the registering of a data source is getting a timeout:

       

      13:03:38,412 INFO  [stdout] (MSC service thread 1-5) 2012-10-16 13:03:38,412 1482  INFO  [package.jboss.DataSourceRegistrationImpl|registerDataSources] (MSC service thread 1-5) Going to register data sources list with size: 1

      13:04:35,868 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "my-ear-x-SNAPSHOT.ear" was rolled back with failure message Operation cancelled

      13:04:35,869 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015052: Did not receive a response to the deployment operation within the allowed timeout period [60 seconds]. Check the server configuration file and the server logs to find more about the status of the deployment.

      13:08:37,193 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffffc0a8040e:-742041f3:507d3efd:8 in state  RUN

      13:08:39,075 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffffc0a8040e:-742041f3:507d3efd:8 invoked while multiple threads active within it.

      13:08:39,077 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffffc0a8040e:-742041f3:507d3efd:8 aborting with 1 threads active!

      13:08:39,078 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,main] successfully canceled TX 0:ffffc0a8040e:-742041f3:507d3efd:8

       

      Tried:

      CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();

      ctx.connectController("localhost", 9999);

       

      and

       

      ModelControllerClient mcc = ModelControllerClient.Factory.create("localhost", 9999);

       

      with the same result.

       

      Registration of a data source:

       

      ModelNode requestCreateDs = new ModelNode();

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

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

                          requestCreateDs.get(ClientConstants.OP_ADDR).add("data-source", curDsName);

       

       

                          requestCreateDs.get("jndi-name").set(curDsJndiName);

                          requestCreateDs.get("connection-url").set(curDsDbUrl);

                          requestCreateDs.get("driver-class").set(driverClass);

                          requestCreateDs.get("driver-name").set(driverName);

                          requestCreateDs.get("user-name").set(curUserName);

                          requestCreateDs.get("password").set(curPassword);

                          //requestCreateDs.get("pool-name").set("pool_NewDatasource");

       

      mcc.execute(request);

       

      // close cc or mcc afterwards...

       

      Any idea?

       

      Regards,

      Oliver

        • 1. Re: Using CLI in @Startup resource
          olpf

          I forgot to mention that I execute this code from an ear.

          • 2. Re: Using CLI in @Startup resource
            olpf

            Figured out that the query for existing data sources succeeds also in the ear:

             

            final ModelNode request = new ModelNode();

                                request.get(ClientConstants.OP).set("read-resource");

                                request.get("recursive").set(false);

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

             

             

                                ModelNode dsNode = null;

                                final ModelNode response = executeRequest(mcc, request);

                                if (response != null) {

                                          ModelNode responseResult = response.get(ClientConstants.RESULT);

                                          if (responseResult != null) {

                                                    dsNode = responseResult.get("data-source");

                                          }

                                }

             

            But adding a data source blocks....security problem?:

             

            ModelNode requestCreateDs = new ModelNode();

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

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

                                requestCreateDs.get(ClientConstants.OP_ADDR).add("data-source", curDsName);

             

             

                                requestCreateDs.get("jndi-name").set(curDsJndiName);

                                requestCreateDs.get("connection-url").set(curDsDbUrl);

                                requestCreateDs.get("driver-class").set(driverClass);

                                requestCreateDs.get("driver-name").set(driverName);

                                requestCreateDs.get("user-name").set(curUserName);

                                requestCreateDs.get("password").set(curPassword);

             

                                requestCreateDs.get("max-pool-size").set(20);

                                requestCreateDs.get("min-pool-size").set(5);

            • 3. Re: Using CLI in @Startup resource
              ctomc

              Hi,

               

              it wont work.

               

              As you dead lock ModelController when you do that.

              Deploy operation holds lock on ModelController while it is performing it, and when you try to do add when deploy operation is still in progress you are waiting for lock to be released which will never be in you case, and lock is then released after timeout and also failed deployment.

               

              In short, you cannot add any other resource while your are inside "deploy" that goes if you are using ModelController, you can however bypass that if you run your code for adding new resource inside a subsystem.

               

               

              --

              tomaz

              • 4. Re: Using CLI in @Startup resource
                olpf

                Thanks for your reply. Can you be more conrete what do you mean with adding it inside a subsystem, maybe with an example?

                • 5. Re: Using CLI in @Startup resource
                  olpf

                  Execution of the data source adding code with executeAsync works.