Java Code Examples for org.wso2.carbon.automation.extensions.servers.utils.ClientConnectionUtil#sendForcefulShutDownRequest()

The following examples show how to use org.wso2.carbon.automation.extensions.servers.utils.ClientConnectionUtil#sendForcefulShutDownRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CarbonServerManagerExtension.java    From product-iots with Apache License 2.0 4 votes vote down vote up
public synchronized void serverShutdown(int portOffset) throws AutomationFrameworkException {
        if(this.process != null) {
            log.info("Shutting down server..");
            if(ClientConnectionUtil.isPortOpen(Integer.parseInt("9443") + portOffset)) {
                int httpsPort = defaultHttpsPort + portOffset;
                String url = null;

                try {
                    url = this.automationContext.getContextUrls().getBackEndUrl();
                } catch (XPathExpressionException var10) {
                    throw new AutomationFrameworkException("Get context failed", var10);
                }

                String backendURL = url.replaceAll("(:\\d+)", ":" + httpsPort);

                try {
                    ClientConnectionUtil.sendForcefulShutDownRequest(backendURL, this.automationContext.getSuperTenant().getContextUser().getUserName(), this.automationContext.getSuperTenant().getContextUser().getPassword());
                } catch (AutomationFrameworkException var8) {
                    throw new AutomationFrameworkException("Get context failed", var8);
                } catch (XPathExpressionException var9) {
                    throw new AutomationFrameworkException("Get context failed", var9);
                }

                long time = System.currentTimeMillis() + 300000L;

//                while(!this.inputStreamHandler.getOutput().contains("Halting JVM") && System.currentTimeMillis() < time) {
//                    ;
//                }

                log.info("Server stopped successfully...");
            }

            this.inputStreamHandler.stop();
            this.errorStreamHandler.stop();
            this.process.destroy();
            this.process = null;
            if(this.isCoverageEnable) {
                try {
                    log.info("Generating Jacoco code coverage...");
                    this.generateCoverageReport(new File(this.carbonHome + File.separator + "wso2"
                            + File.separator + "components" + File.separator + "plugins" + File.separator));
                } catch (IOException var7) {
                    log.error("Failed to generate code coverage ", var7);
                    throw new AutomationFrameworkException("Failed to generate code coverage ", var7);
                }
            }

            if(portOffset == 0) {
                System.clearProperty("carbon.home");
            }
        }

    }
 
Example 2
Source File: StratosTestServerManager.java    From attic-stratos with Apache License 2.0 4 votes vote down vote up
public synchronized void serverShutdown(int portOffset) throws AutomationFrameworkException {
    if (this.process != null) {
        log.info("Shutting down server..");
        if (ClientConnectionUtil.isPortOpen(Integer.parseInt("9443") + portOffset)) {
            int e = defaultHttpsPort + portOffset;
            String url = null;

            try {
                url = this.automationContext.getContextUrls().getBackEndUrl();
            } catch (XPathExpressionException var10) {
                throw new AutomationFrameworkException("Get context failed", var10);
            }

            String backendURL = url.replaceAll("(:\\d+)", ":" + e);

            try {
                ClientConnectionUtil.sendForcefulShutDownRequest(backendURL,
                        this.automationContext.getSuperTenant().getContextUser().getUserName(),
                        this.automationContext.getSuperTenant().getContextUser().getPassword());
            } catch (AutomationFrameworkException var8) {
                throw new AutomationFrameworkException("Get context failed", var8);
            } catch (XPathExpressionException var9) {
                throw new AutomationFrameworkException("Get context failed", var9);
            }

            long time = System.currentTimeMillis() + 300000L;

            while (!this.inputStreamHandler.getOutput().contains("Halting JVM")
                    && System.currentTimeMillis() < time) {
                ;
            }

            log.info("Server stopped successfully...");
        }

        this.inputStreamHandler.stop();
        this.errorStreamHandler.stop();
        this.process.destroy();
        this.process = null;
        if (this.isCoverageEnable) {
            try {
                log.info("Generating Jacoco code coverage...");
                this.generateCoverageReport(
                        new File(this.carbonHome + File.separator + "repository" + File.separator + "components" +
                                File.separator + "plugins" + File.separator));
            } catch (IOException var7) {
                log.error("Failed to generate code coverage ", var7);
                throw new AutomationFrameworkException("Failed to generate code coverage ", var7);
            }
        }

        if (portOffset == 0) {
            System.clearProperty("carbon.home");
        }
    }

}