Search in sources :

Example 1 with ExecutionContextConfiguration

use of org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration in project hive by apache.

the class PTest method main.

public static void main(String[] args) throws Exception {
    LOG.info("Args " + Arrays.toString(args));
    CommandLineParser parser = new GnuParser();
    Options options = new Options();
    options.addOption(null, PROPERTIES, true, "properties file");
    options.addOption(null, REPOSITORY, true, "Overrides git repository in properties file");
    options.addOption(null, REPOSITORY_NAME, true, "Overrides git repository *name* in properties file");
    options.addOption(null, BRANCH, true, "Overrides git branch in properties file");
    options.addOption(null, PATCH, true, "URI to patch, either file:/// or http(s)://");
    options.addOption(ANT_ARG, null, true, "Supplemental ant arguments");
    options.addOption(null, JAVA_HOME, true, "Java Home for compiling and running tests (unless " + JAVA_HOME_TEST + " is specified)");
    options.addOption(null, JAVA_HOME_TEST, true, "Java Home for running tests (optional)");
    options.addOption(null, ANT_TEST_ARGS, true, "Arguments to ant test on slave nodes only");
    options.addOption(null, ANT_ENV_OPTS, true, "ANT_OPTS environment variable setting");
    CommandLine commandLine = parser.parse(options, args);
    if (!commandLine.hasOption(PROPERTIES)) {
        throw new IllegalArgumentException(Joiner.on(" ").join(PTest.class.getName(), "--" + PROPERTIES, "config.properties"));
    }
    String testConfigurationFile = commandLine.getOptionValue(PROPERTIES);
    ExecutionContextConfiguration executionContextConfiguration = ExecutionContextConfiguration.fromFile(testConfigurationFile);
    String buildTag = System.getenv("BUILD_TAG") == null ? "undefined-" + System.currentTimeMillis() : System.getenv("BUILD_TAG");
    File logDir = Dirs.create(new File(executionContextConfiguration.getGlobalLogDirectory(), buildTag));
    LogDirectoryCleaner cleaner = new LogDirectoryCleaner(new File(executionContextConfiguration.getGlobalLogDirectory()), 5);
    cleaner.setName("LogCleaner-" + executionContextConfiguration.getGlobalLogDirectory());
    cleaner.setDaemon(true);
    cleaner.start();
    TestConfiguration conf = TestConfiguration.fromFile(testConfigurationFile, LOG);
    String repository = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY)).trim();
    if (!repository.isEmpty()) {
        conf.setRepository(repository);
    }
    String repositoryName = Strings.nullToEmpty(commandLine.getOptionValue(REPOSITORY_NAME)).trim();
    if (!repositoryName.isEmpty()) {
        conf.setRepositoryName(repositoryName);
    }
    String branch = Strings.nullToEmpty(commandLine.getOptionValue(BRANCH)).trim();
    if (!branch.isEmpty()) {
        conf.setBranch(branch);
    }
    String patch = Strings.nullToEmpty(commandLine.getOptionValue(PATCH)).trim();
    if (!patch.isEmpty()) {
        conf.setPatch(patch);
    }
    String javaHome = Strings.nullToEmpty(commandLine.getOptionValue(JAVA_HOME)).trim();
    if (!javaHome.isEmpty()) {
        conf.setJavaHome(javaHome);
    }
    String javaHomeForTests = Strings.nullToEmpty(commandLine.getOptionValue(JAVA_HOME_TEST)).trim();
    if (!javaHomeForTests.isEmpty()) {
        conf.setJavaHomeForTests(javaHomeForTests);
    }
    String antTestArgs = Strings.nullToEmpty(commandLine.getOptionValue(ANT_TEST_ARGS)).trim();
    if (!antTestArgs.isEmpty()) {
        conf.setAntTestArgs(antTestArgs);
    }
    String antEnvOpts = Strings.nullToEmpty(commandLine.getOptionValue(ANT_ENV_OPTS)).trim();
    if (!antEnvOpts.isEmpty()) {
        conf.setAntEnvOpts(antEnvOpts);
    }
    String antTestTarget = Strings.nullToEmpty(commandLine.getOptionValue(ANT_TEST_TARGET)).trim();
    if (!antTestTarget.isEmpty()) {
        conf.setAntTestTarget(antTestTarget);
    }
    String[] supplementalAntArgs = commandLine.getOptionValues(ANT_ARG);
    if (supplementalAntArgs != null && supplementalAntArgs.length > 0) {
        String antArgs = Strings.nullToEmpty(conf.getAntArgs());
        if (!(antArgs.isEmpty() || antArgs.endsWith(" "))) {
            antArgs += " ";
        }
        antArgs += "-" + ANT_ARG + Joiner.on(" -" + ANT_ARG).join(supplementalAntArgs);
        conf.setAntArgs(antArgs);
    }
    ExecutionContextProvider executionContextProvider = null;
    ExecutionContext executionContext = null;
    int exitCode = 0;
    try {
        executionContextProvider = executionContextConfiguration.getExecutionContextProvider();
        executionContext = executionContextProvider.createExecutionContext();
        LocalCommandFactory localCommandFactory = new LocalCommandFactory(LOG);
        PTest ptest = new PTest(conf, executionContext, buildTag, logDir, localCommandFactory, new SSHCommandExecutor(LOG, localCommandFactory, conf.getSshOpts()), new RSyncCommandExecutor(LOG, 10, localCommandFactory), LOG);
        exitCode = ptest.run();
    } finally {
        if (executionContext != null) {
            executionContext.terminate();
        }
        if (executionContextProvider != null) {
            executionContextProvider.close();
        }
    }
    System.exit(exitCode);
}
Also used : Options(org.apache.commons.cli.Options) ExecutionContextConfiguration(org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration) GnuParser(org.apache.commons.cli.GnuParser) TestConfiguration(org.apache.hive.ptest.execution.conf.TestConfiguration) SSHCommandExecutor(org.apache.hive.ptest.execution.ssh.SSHCommandExecutor) CommandLine(org.apache.commons.cli.CommandLine) ExecutionContext(org.apache.hive.ptest.execution.context.ExecutionContext) RSyncCommandExecutor(org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File) ExecutionContextProvider(org.apache.hive.ptest.execution.context.ExecutionContextProvider)

Example 2 with ExecutionContextConfiguration

use of org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration in project hive by apache.

the class TestTestExecutor method setup.

@Before
public void setup() throws Exception {
    startRequest = new TestStartRequest();
    startRequest.setProfile(PROFILE);
    startRequest.setTestHandle(TEST_HANDLE);
    test = new Test(startRequest, Status.pending(), System.currentTimeMillis());
    testQueue = new ArrayBlockingQueue<Test>(1);
    executionContextConfiguration = mock(ExecutionContextConfiguration.class);
    executionContextProvider = mock(ExecutionContextProvider.class);
    ptest = mock(PTest.class);
    Set<Host> hosts = Sets.newHashSet();
    String baseDirPath = baseDir.getRoot().getAbsolutePath();
    executionContext = new ExecutionContext(executionContextProvider, hosts, baseDirPath, PRIVATE_KEY);
    profileProperties = new File(baseDirPath, PROFILE + ".properties");
    when(executionContextConfiguration.getProfileDirectory()).thenReturn(baseDirPath);
    when(executionContextConfiguration.getGlobalLogDirectory()).thenReturn(baseDirPath);
    when(executionContextProvider.createExecutionContext()).thenReturn(executionContext);
    Assert.assertTrue(profileProperties.toString(), profileProperties.createNewFile());
    OutputStream profilePropertiesOutputStream = new FileOutputStream(profileProperties);
    Resources.copy(Resources.getResource("test-configuration.properties"), profilePropertiesOutputStream);
    profilePropertiesOutputStream.close();
    ptestBuilder = new PTest.Builder() {

        @Override
        public PTest build(TestConfiguration configuration, ExecutionContext executionContext, String buildTag, File logDir, LocalCommandFactory localCommandFactory, SSHCommandExecutor sshCommandExecutor, RSyncCommandExecutor rsyncCommandExecutor, Logger logger) throws Exception {
            return ptest;
        }
    };
    testExecutor = new TestExecutor(executionContextConfiguration, executionContextProvider, testQueue, ptestBuilder);
    testExecutor.setDaemon(true);
    testExecutor.start();
    TimeUnit.MILLISECONDS.sleep(100);
}
Also used : ExecutionContextConfiguration(org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) TestConfiguration(org.apache.hive.ptest.execution.conf.TestConfiguration) Host(org.apache.hive.ptest.execution.conf.Host) SSHCommandExecutor(org.apache.hive.ptest.execution.ssh.SSHCommandExecutor) Logger(org.slf4j.Logger) PTest(org.apache.hive.ptest.execution.PTest) ExecutionContext(org.apache.hive.ptest.execution.context.ExecutionContext) PTest(org.apache.hive.ptest.execution.PTest) RSyncCommandExecutor(org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor) FileOutputStream(java.io.FileOutputStream) TestStartRequest(org.apache.hive.ptest.api.request.TestStartRequest) LocalCommandFactory(org.apache.hive.ptest.execution.LocalCommandFactory) ExecutionContextProvider(org.apache.hive.ptest.execution.context.ExecutionContextProvider) File(java.io.File) Before(org.junit.Before)

Aggregations

File (java.io.File)2 ExecutionContextConfiguration (org.apache.hive.ptest.execution.conf.ExecutionContextConfiguration)2 TestConfiguration (org.apache.hive.ptest.execution.conf.TestConfiguration)2 ExecutionContext (org.apache.hive.ptest.execution.context.ExecutionContext)2 ExecutionContextProvider (org.apache.hive.ptest.execution.context.ExecutionContextProvider)2 RSyncCommandExecutor (org.apache.hive.ptest.execution.ssh.RSyncCommandExecutor)2 SSHCommandExecutor (org.apache.hive.ptest.execution.ssh.SSHCommandExecutor)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 GnuParser (org.apache.commons.cli.GnuParser)1 Options (org.apache.commons.cli.Options)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 Host (org.apache.hive.ptest.execution.conf.Host)1 Before (org.junit.Before)1 Logger (org.slf4j.Logger)1