Search in sources :

Example 1 with LogDirectoryCleaner

use of org.apache.hive.ptest.execution.LogDirectoryCleaner in project hive by apache.

the class TestExecutor method run.

@Override
public void run() {
    while (execute) {
        Test test = null;
        PrintStream logStream = null;
        Logger logger = null;
        try {
            // start a log cleaner at the start of each test
            LogDirectoryCleaner cleaner = new LogDirectoryCleaner(new File(mExecutionContextConfiguration.getGlobalLogDirectory()), mExecutionContextConfiguration.getMaxLogDirectoriesPerProfile());
            cleaner.setName("LogCleaner-" + mExecutionContextConfiguration.getGlobalLogDirectory());
            cleaner.setDaemon(true);
            cleaner.start();
            test = mTestQueue.poll(30, TimeUnit.MINUTES);
            if (!execute) {
                terminateExecutionContext();
                break;
            }
            if (test == null) {
                terminateExecutionContext();
            } else {
                test.setStatus(Status.inProgress());
                test.setDequeueTime(System.currentTimeMillis());
                if (mExecutionContext == null) {
                    mExecutionContext = createExceutionContext();
                }
                test.setExecutionStartTime(System.currentTimeMillis());
                TestStartRequest startRequest = test.getStartRequest();
                String profile = startRequest.getProfile();
                File profileConfFile = new File(mExecutionContextConfiguration.getProfileDirectory(), String.format("%s.properties", profile));
                LOG.info("Attempting to run using profile file: {}", profileConfFile);
                if (!profileConfFile.isFile()) {
                    test.setStatus(Status.illegalArgument("Profile " + profile + " not found in directory " + mExecutionContextConfiguration.getProfileDirectory()));
                    test.setExecutionFinishTime(System.currentTimeMillis());
                } else {
                    File logDir = Dirs.create(new File(mExecutionContextConfiguration.getGlobalLogDirectory(), test.getStartRequest().getTestHandle()));
                    File logFile = new File(logDir, "execution.txt");
                    test.setOutputFile(logFile);
                    logStream = new PrintStream(logFile);
                    logger = new TestLogger(logStream, TestLogger.LEVEL.DEBUG);
                    TestConfiguration testConfiguration = TestConfiguration.fromFile(profileConfFile, logger);
                    testConfiguration.setPatch(startRequest.getPatchURL());
                    testConfiguration.setJiraName(startRequest.getJiraName());
                    testConfiguration.setClearLibraryCache(startRequest.isClearLibraryCache());
                    LocalCommandFactory localCommandFactory = new LocalCommandFactory(logger);
                    PTest ptest = mPTestBuilder.build(testConfiguration, mExecutionContext, test.getStartRequest().getTestHandle(), logDir, localCommandFactory, new SSHCommandExecutor(logger), new RSyncCommandExecutor(logger, mExecutionContextConfiguration.getMaxRsyncThreads(), localCommandFactory), logger);
                    int result = ptest.run();
                    if (result == Constants.EXIT_CODE_SUCCESS) {
                        test.setStatus(Status.ok());
                    } else {
                        test.setStatus(Status.failed("Tests failed with exit code " + result));
                    }
                    logStream.flush();
                    // if all drones where abandoned on a host, try replacing them.
                    mExecutionContext.replaceBadHosts();
                }
            }
        } catch (Exception e) {
            LOG.error("Unxpected Error", e);
            if (test != null) {
                test.setStatus(Status.failed("Tests failed with exception " + e.getClass().getName() + ": " + e.getMessage()));
                if (logger != null) {
                    String msg = "Error executing " + test.getStartRequest().getTestHandle();
                    logger.error(msg, e);
                }
            }
            // if we died for any reason lets get a new set of hosts
            terminateExecutionContext();
        } finally {
            if (test != null) {
                test.setExecutionFinishTime(System.currentTimeMillis());
            }
            if (logStream != null) {
                logStream.flush();
                logStream.close();
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) TestConfiguration(org.apache.hive.ptest.execution.conf.TestConfiguration) SSHCommandExecutor(org.apache.hive.ptest.execution.ssh.SSHCommandExecutor) Logger(org.slf4j.Logger) PTest(org.apache.hive.ptest.execution.PTest) CreateHostsFailedException(org.apache.hive.ptest.execution.context.CreateHostsFailedException) ServiceNotAvailableException(org.apache.hive.ptest.execution.context.ServiceNotAvailableException) LogDirectoryCleaner(org.apache.hive.ptest.execution.LogDirectoryCleaner) PTest(org.apache.hive.ptest.execution.PTest) RSyncCommandExecutor(org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor) TestStartRequest(org.apache.hive.ptest.api.request.TestStartRequest) LocalCommandFactory(org.apache.hive.ptest.execution.LocalCommandFactory) File(java.io.File)

Example 2 with LogDirectoryCleaner

use of org.apache.hive.ptest.execution.LogDirectoryCleaner in project hive by apache.

the class TestLogDirectoryCleaner method testClean.

@org.junit.Test
public void testClean() throws Exception {
    File dir = create("a-0", "a-1", "a-2", "malformed", "b-0", "c-0", "c-5");
    LogDirectoryCleaner cleaner = new LogDirectoryCleaner(dir, 1);
    cleaner.run();
    List<String> remaining = Lists.newArrayList(dir.list());
    Collections.sort(remaining);
    Assert.assertEquals(Lists.newArrayList("a-1", "a-2", "b-0", "c-5", "malformed"), remaining);
}
Also used : LogDirectoryCleaner(org.apache.hive.ptest.execution.LogDirectoryCleaner) File(java.io.File)

Aggregations

File (java.io.File)2 LogDirectoryCleaner (org.apache.hive.ptest.execution.LogDirectoryCleaner)2 PrintStream (java.io.PrintStream)1 TestStartRequest (org.apache.hive.ptest.api.request.TestStartRequest)1 LocalCommandFactory (org.apache.hive.ptest.execution.LocalCommandFactory)1 PTest (org.apache.hive.ptest.execution.PTest)1 TestConfiguration (org.apache.hive.ptest.execution.conf.TestConfiguration)1 CreateHostsFailedException (org.apache.hive.ptest.execution.context.CreateHostsFailedException)1 ServiceNotAvailableException (org.apache.hive.ptest.execution.context.ServiceNotAvailableException)1 RSyncCommandExecutor (org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor)1 SSHCommandExecutor (org.apache.hive.ptest.execution.ssh.SSHCommandExecutor)1 Logger (org.slf4j.Logger)1