Search in sources :

Example 1 with ServerLogReader

use of org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader in project product-iots by wso2.

the class CarbonServerManagerExtension method startServerUsingCarbonHome.

public synchronized void startServerUsingCarbonHome(String carbonHome, Map<String, String> commandMap) throws AutomationFrameworkException {
    if (this.process == null) {
        this.portOffset = this.checkPortAvailability(commandMap);
        Process tempProcess = null;
        try {
            if (!commandMap.isEmpty() && this.getPortOffsetFromCommandMap(commandMap) == 0) {
                System.setProperty("carbon.home", carbonHome);
            }
            File commandDir = new File(carbonHome);
            log.info("Starting carbon server............. ");
            String scriptName = TestFrameworkUtils.getStartupScriptFileName(carbonHome);
            String[] parameters = this.expandServerStartupCommandList(commandMap);
            String[] cmdArray;
            if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                commandDir = new File(carbonHome + File.separator + "bin");
                cmdArray = new String[] { "cmd.exe", "/c", scriptName + ".bat" };
                cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
                tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, commandDir);
            } else {
                cmdArray = new String[] { "sh", "bin/" + scriptName + ".sh" };
                cmdArray = this.mergePropertiesToCommandArray(parameters, cmdArray);
                tempProcess = Runtime.getRuntime().exec(cmdArray, (String[]) null, commandDir);
            }
            this.errorStreamHandler = new ServerLogReader("errorStream", tempProcess.getErrorStream());
            this.inputStreamHandler = new ServerLogReader("inputStream", tempProcess.getInputStream());
            this.inputStreamHandler.start();
            this.errorStreamHandler.start();
            Runtime.getRuntime().addShutdownHook(new Thread() {

                public void run() {
                    try {
                        CarbonServerManagerExtension.this.serverShutdown(CarbonServerManagerExtension.this.portOffset);
                    } catch (Exception var2) {
                        CarbonServerManagerExtension.log.error("Error while server shutdown ..", var2);
                    }
                }
            });
            ClientConnectionUtil.waitForPort(defaultHttpPort + this.portOffset, DEFAULT_START_STOP_WAIT_MS, false, (String) this.automationContext.getInstance().getHosts().get("default"));
            long time = System.currentTimeMillis() + 60000L;
            // while(true) {
            // if(this.inputStreamHandler.getOutput().contains("Mgt Console URL") || System.currentTimeMillis() >= time) {
            // int httpsPort = defaultHttpsPort + this.portOffset;
            // String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
            // User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
            // ClientConnectionUtil.waitForLogin(backendURL, superUser);
            // log.info("Server started successfully.");
            // break;
            // }
            // }
            int httpsPort = defaultHttpsPort + this.portOffset;
            String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
            User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
            ClientConnectionUtil.waitForLogin(backendURL, superUser);
        } catch (XPathExpressionException | IOException var13) {
            throw new IllegalStateException("Unable to start server", var13);
        }
        this.process = tempProcess;
    }
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ServerLogReader(org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException) AutomationFrameworkException(org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 User (org.wso2.carbon.automation.engine.context.beans.User)1 AutomationFrameworkException (org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException)1 ServerLogReader (org.wso2.carbon.automation.extensions.servers.utils.ServerLogReader)1