0 Replies Latest reply on Nov 2, 2016 9:01 PM by Mike Sandoval

    Wildfly, executing management operations while server is shutting down

    Mike Sandoval Newbie

      Hello, hope someone can help me with this issue I'm having,

      In wildfly 9.0.2, I have a web project that dynamically binds data sources, and I would like to remove those data sources from the server once the project gets undeployed or the server gets shutdown.

      For this, I'm using a ServletContextListener where I place the required logic in the contextDestroyed method, which is something like this:

       

      ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("127.0.0.1"), 9990);
      ModelNode op = new ModelNode();
      op.get("operation").set("remove");
      op.get("address").add("subsystem", "datasources");
      op.get("address").add("data-source", "TESTDS");
      client.executeAsync(op, null);
      

       

      However, that is only working if I undeploy the .war, it is not working when I shutdown the server via Ctrl-C, it gives me this error:

      Caused by: java.net.ConnectException: WFLYPRT0053: Could not connect to http-remoting://127.0.0.1:9990. The connection failed

        at org.jboss.as.protocol.ProtocolConnectionUtils.connectSync(ProtocolConnectionUtils.java:122)

        at org.jboss.as.protocol.ProtocolConnectionManager$EstablishingConnection.connect(ProtocolConnectionManager.java:257)

        at org.jboss.as.protocol.ProtocolConnectionManager.connect(ProtocolConnectionManager.java:71)

        at org.jboss.as.protocol.mgmt.FutureManagementChannel$Establishing.getChannel(FutureManagementChannel.java:212)

        at org.jboss.as.controller.client.impl.RemotingModelControllerClient.getOrCreateChannel(RemotingModelControllerClient.java:146)

        at org.jboss.as.controller.client.impl.RemotingModelControllerClient$1.getChannel(RemotingModelControllerClient.java:65)

        at org.jboss.as.protocol.mgmt.ManagementChannelHandler.executeRequest(ManagementChannelHandler.java:147)

        at org.jboss.as.protocol.mgmt.ManagementChannelHandler.executeRequest(ManagementChannelHandler.java:122)

        at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeRequest(AbstractModelControllerClient.java:263)

        at org.jboss.as.controller.client.impl.AbstractModelControllerClient.execute(AbstractModelControllerClient.java:168)

        at org.jboss.as.controller.client.impl.AbstractModelControllerClient.executeAsync(AbstractModelControllerClient.java:101)

        ... 13 more

      Caused by: java.net.ConnectException: Connection refused

        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)

        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)

        at org.xnio.nio.WorkerThread$ConnectHandle.handleReady(WorkerThread.java:319)

        at org.xnio.nio.WorkerThread.run(WorkerThread.java:539)

        at ...asynchronous invocation...(Unknown Source)

        at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:272)

        at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:253)

        at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:351)

        at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:339)

        at org.jboss.as.protocol.ProtocolConnectionUtils.connect(ProtocolConnectionUtils.java:83)

        at org.jboss.as.protocol.ProtocolConnectionUtils.connectSync(ProtocolConnectionUtils.java:114)

       

      If I use client.execute(op) instead, it will just hang and after some time it will give an error saying that the operation failed. Apparently the management interface is not available after the contextDestroyed method of my listener is executed.

      Would it even be possible to do what I'm trying? is there some other way to do it or a workaround?