org.wso2.carbon.automation.extensions.servers.utils.ClientConnectionUtil Java Examples

The following examples show how to use org.wso2.carbon.automation.extensions.servers.utils.ClientConnectionUtil. 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: CarbonServerManager.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private int checkPortAvailability(Map<String, String> commandMap)
        throws AutomationFrameworkException {
    final int portOffset = getPortOffsetFromCommandMap(commandMap);

    //check whether http port is already occupied
    if (ClientConnectionUtil.isPortOpen(defaultHttpPort + portOffset)) {
        throw new AutomationFrameworkException("Unable to start carbon server on port " +
                                               (defaultHttpPort + portOffset) + " : Port already in use");
    }
    //check whether https port is already occupied
    if (ClientConnectionUtil.isPortOpen(defaultHttpsPort + portOffset)) {
        throw new AutomationFrameworkException("Unable to start carbon server on port " +
                                               (defaultHttpsPort + portOffset) + " : Port already in use");
    }
    return portOffset;
}
 
Example #2
Source File: CarbonServerManagerExtension.java    From product-iots with Apache License 2.0 5 votes vote down vote up
private int checkPortAvailability(Map<String, String> commandMap) throws AutomationFrameworkException {
    int portOffset = this.getPortOffsetFromCommandMap(commandMap);
    if(ClientConnectionUtil.isPortOpen(defaultHttpPort + portOffset)) {
        throw new AutomationFrameworkException("Unable to start carbon server on port " + (defaultHttpPort + portOffset) + " : Port already in use");
    } else if(ClientConnectionUtil.isPortOpen(defaultHttpsPort + portOffset)) {
        throw new AutomationFrameworkException("Unable to start carbon server on port " + (defaultHttpsPort + portOffset) + " : Port already in use");
    } else {
        return portOffset;
    }
}
 
Example #3
Source File: CarbonServerManagerExtension.java    From product-iots with Apache License 2.0 5 votes vote down vote up
public synchronized void restartGracefully() throws AutomationFrameworkException {
        try {
            int httpsPort = defaultHttpsPort + this.portOffset;
            String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
            User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
            ClientConnectionUtil.sendGraceFullRestartRequest(backendURL, superUser.getUserName(), superUser.getPassword());
        } catch (XPathExpressionException var5) {
            throw new AutomationFrameworkException("restart failed", var5);
        }

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

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

        time = System.currentTimeMillis();

        while(System.currentTimeMillis() < time + 5000L) {
            ;
        }

        try {
            ClientConnectionUtil.waitForPort(Integer.parseInt((String)this.automationContext.getInstance().getPorts().get("https")), (String)this.automationContext.getInstance().getHosts().get("default"));
            ClientConnectionUtil.waitForLogin(this.automationContext);
        } catch (XPathExpressionException var4) {
            throw new AutomationFrameworkException("Connection attempt to carbon server failed", var4);
        }
    }
 
Example #4
Source File: StratosTestServerManager.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private int checkPortAvailability(Map<String, String> commandMap) throws AutomationFrameworkException {
    int portOffset = this.getPortOffsetFromCommandMap(commandMap);
    if (ClientConnectionUtil.isPortOpen(defaultHttpPort + portOffset)) {
        throw new AutomationFrameworkException(
                "Unable to start carbon server on port " + (defaultHttpPort + portOffset) +
                        " : Port already in use");
    } else if (ClientConnectionUtil.isPortOpen(defaultHttpsPort + portOffset)) {
        throw new AutomationFrameworkException(
                "Unable to start carbon server on port " + (defaultHttpsPort + portOffset) +
                        " : Port already in use");
    } else {
        return portOffset;
    }
}
 
Example #5
Source File: StratosTestServerManager.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public synchronized void restartGracefully() throws AutomationFrameworkException {
    try {
        int time = defaultHttpsPort + this.portOffset;
        String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl()
                .replaceAll("(:\\d+)", ":" + time);
        User e = this.automationContext.getSuperTenant().getTenantAdmin();
        ClientConnectionUtil.sendGraceFullRestartRequest(backendURL, e.getUserName(), e.getPassword());
    } catch (XPathExpressionException var5) {
        throw new AutomationFrameworkException("restart failed", var5);
    }

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

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

    time1 = System.currentTimeMillis();

    while (System.currentTimeMillis() < time1 + 5000L) {
        ;
    }

    try {
        ClientConnectionUtil.waitForPort(
                Integer.parseInt((String) this.automationContext.getInstance().getPorts().get("https")),
                RESTART_TIMEOUT, true, (String) this.automationContext.getInstance().getHosts().get("default"));
        ClientConnectionUtil.waitForLogin(this.automationContext);
    } catch (XPathExpressionException var4) {
        throw new AutomationFrameworkException("Connection attempt to carbon server failed", var4);
    }
}
 
Example #6
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 #7
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");
        }
    }

}