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;
}
}
Aggregations