view src/org/thermostat/qa2/framework/services/Tomcat.java @ 198:085c86ddaeed

fixed problem with random generator for tomcat
author Zdenek Zambersky <zzambers@redhat.com>
date Tue, 11 Aug 2015 19:41:59 +0200
parents 5d335809cd51
children
line wrap: on
line source

/*
 ThermostatQA - test framework for Thermostat Monitoring Tool

 Copyright 2015 Red Hat, Inc.

 This file is part of ThermostatQA

 ThermostatQA is distributed under the GNU General Public License,
 version 2 or any later version (with a special exception described
 below, commonly known as the "Classpath Exception").

 A copy of GNU General Public License (GPL) is included in this
 distribution, in the file COPYING.

 Linking ThermostatQA code with other modules is making a combined work
 based on ThermostatQA.  Thus, the terms and conditions of the GPL
 cover the whole combination.

 As a special exception, the copyright holders of ThermostatQA give you
 permission to link this code with independent modules to produce an
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on ThermostatQA code.  If you modify ThermostatQA, you may
 extend this exception to your version of the software, but you are
 not obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version.
 */
package org.thermostat.qa2.framework.services;

import java.io.File;
import java.io.IOException;
import org.thermostat.qa2.framework.NativeProcess;
import org.thermostat.qa2.framework.ThermostatQAConfig;
import org.thermostat.qa2.framework.utils.CommonUtilities;

/**
 *
 * @author Zdeněk Žamberský
 */
public class Tomcat extends AbstractService {

    String tomcatHome;
    String thermostatEtcDir;
    boolean packaged = false;

    public Tomcat() throws IOException {
        this("tested");
    }

    public Tomcat(String targetThermostat) throws IOException {
        this(ThermostatQAConfig.tomcatHome, ThermostatQAConfig.getThermostatEtcDir(targetThermostat));
        if (targetThermostat.equals("tested") && ThermostatQAConfig.thermostatPackaged) {
            packaged = true;
        }
    }

    public Tomcat(String tomcatHome, String thermostatEtcDir) {
        this.tomcatHome = tomcatHome;
        this.thermostatEtcDir = thermostatEtcDir;
    }

    @Override
    public String getServiceName() throws Exception {
        return "Apache Tomcat";
    }

    int webPort = ThermostatQAConfig.webStoragePort;
    int shutdownPort = 8005;
    int timeout = 30;

    @Override
    public void startServiceImpl() throws Exception {
        setRunning(true);
        NativeProcess process;
        if (packaged) {
            process = new org.thermostat.qa2.framework.NativeProcess("sudo", "-n", "systemctl", "start", "tomcat@thermostat");
        } else {
            process = new org.thermostat.qa2.framework.NativeProcess(tomcatHome + File.separator + "bin" + File.separator + "startup.sh");
            if (thermostatEtcDir != null) {
                process.setEnvironmentVariable("JAVA_OPTS", "-Djava.security.auth.login.config=" + thermostatEtcDir + File.separator + "thermostat_jaas.conf -Djava.security.egd=file:/dev/./urandom");
            }
        }
        process.setLabel(getServiceName());
        process.start();
        process.waitFor();
        waitForListeningPort(webPort, timeout, true);
        waitForListeningPort(shutdownPort, timeout, true);
    }

    @Override
    public void stopServiceImpl() throws Exception {
        setRunning(false);
        NativeProcess process;
        if (packaged) {
            process = new org.thermostat.qa2.framework.NativeProcess("sudo", "-n", "systemctl", "stop", "tomcat@thermostat");
        } else {
            process = new org.thermostat.qa2.framework.NativeProcess(tomcatHome + File.separator + "bin" + File.separator + "shutdown.sh");
        }
        process.setLabel(getServiceName());
        process.start();
        process.waitFor();
        waitForListeningPort(webPort, timeout, false);
        waitForListeningPort(shutdownPort, timeout, false);
        CommonUtilities.sleep(2000);
    }
}