Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C39FC200C18 for ; Wed, 4 Jan 2017 01:02:04 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id C24D8160B46; Wed, 4 Jan 2017 00:02:04 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id EF4B7160B43 for ; Wed, 4 Jan 2017 01:02:03 +0100 (CET) Received: (qmail 34821 invoked by uid 500); 4 Jan 2017 00:02:02 -0000 Mailing-List: contact dev-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list dev@accumulo.apache.org Received: (qmail 34379 invoked by uid 99); 4 Jan 2017 00:02:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jan 2017 00:02:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 14E12DFB3D; Wed, 4 Jan 2017 00:02:02 +0000 (UTC) From: joshelser To: dev@accumulo.apache.org Reply-To: dev@accumulo.apache.org References: In-Reply-To: Subject: [GitHub] accumulo-testing pull request #1: Accumulo 4510 Content-Type: text/plain Message-Id: <20170104000202.14E12DFB3D@git1-us-west.apache.org> Date: Wed, 4 Jan 2017 00:02:02 +0000 (UTC) archived-at: Wed, 04 Jan 2017 00:02:04 -0000 Github user joshelser commented on a diff in the pull request: https://github.com/apache/accumulo-testing/pull/1#discussion_r94508860 --- Diff: twill/src/main/java/org/apache/accumulo/testing/twill/TestRunner.java --- @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.accumulo.testing.twill; + +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import com.google.common.base.Preconditions; +import org.apache.accumulo.testing.core.TestProps; +import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.twill.api.ResourceSpecification; +import org.apache.twill.api.TwillApplication; +import org.apache.twill.api.TwillController; +import org.apache.twill.api.TwillRunnerService; +import org.apache.twill.api.TwillSpecification; +import org.apache.twill.ext.BundledJarRunnable; +import org.apache.twill.ext.BundledJarRunner; +import org.apache.twill.yarn.YarnTwillRunnerService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.atomic.AtomicBoolean; + +public class TestRunner { + + private static final Logger LOG = LoggerFactory.getLogger(TestRunner.class); + + private static class TestRunnerApp implements TwillApplication { + + private TestRunnerOpts opts; + private Properties props; + + TestRunnerApp(TestRunnerOpts opts, Properties props) { + this.opts = opts; + this.props = props; + } + + @Override + public TwillSpecification configure() { + + int numCores = Integer.valueOf(props.getProperty(TestProps.CONTAINER_CORES)); + int memory = Integer.valueOf(props.getProperty(TestProps.CONTAINER_MEMORY_MB)); + int instances = Integer.valueOf(props.getProperty(TestProps.CONTAINER_INSTANCES)); + + ResourceSpecification resourceSpec = ResourceSpecification.Builder.with() + .setVirtualCores(numCores).setMemory(memory, ResourceSpecification.SizeUnit.MEGA) + .setInstances(instances).build(); + + File jarFile = new File(opts.jarPath); + File testProps = new File(opts.testProps); + File log4jProps = new File(opts.logProps); + + return TwillSpecification.Builder.with() + .setName(opts.testName) + .withRunnable() + .add("BundledJarRunnable", new BundledJarRunnable(), resourceSpec) + .withLocalFiles() + .add(jarFile.getName(), jarFile.toURI(), false) + .add(testProps.getName(), testProps.toURI()) + .add(log4jProps.getName(), log4jProps.toURI()) + .apply() + .anyOrder() + .build(); + } + } + + private static class TestRunnerOpts { + + @Parameter(names={"--name", "-n"}, required = true, description = "Test name") + String testName; + + @Parameter(names={"--jar", "-j"}, required = true, description = "Bundled jar path") + String jarPath; + + @Parameter(names={"--main", "-m"}, required = true, description = "Main class") + String mainClass; + + @Parameter(names={"--testProps", "-t"}, required = true, description = "Test properties path") + String testProps; + + @Parameter(names={"--logProps", "-l"}, required = true, description = "Log properties path") + String logProps; + + @Parameter(names={"--args", "-a"}, variableArity = true, description = "Main class args") + List mainArgs = new ArrayList<>(); + } + + private static void verifyPath(String path) { + File f = new File(path); + Preconditions.checkState(f.exists()); + Preconditions.checkState(f.canRead()); + } + + public static void main(String[] args) throws Exception { + + TestRunnerOpts opts = new TestRunnerOpts(); + new JCommander(opts, args); + + verifyPath(opts.jarPath); + verifyPath(opts.testProps); + verifyPath(opts.logProps); + + String[] mainArgs = opts.mainArgs.stream().toArray(String[]::new); + BundledJarRunner.Arguments arguments = new BundledJarRunner.Arguments(opts.jarPath, "/lib", + opts.mainClass, mainArgs); + + Properties props = new Properties(); + FileInputStream fis = new FileInputStream(opts.testProps); + props.load(fis); + fis.close(); + String zookeepers = props.getProperty(TestProps.ZOOKEEPERS); + + final TwillRunnerService twillRunner = new YarnTwillRunnerService(new YarnConfiguration(), + zookeepers); + twillRunner.start(); + + final TwillController controller = twillRunner.prepare( + new TestRunnerApp(opts, props)) + .addJVMOptions("-Dlog4j.configuration=file:$PWD/" + new File(opts.logProps).getName()) + .withArguments("BundledJarRunnable", arguments.toArray()) + .start(); + + final AtomicBoolean done = new AtomicBoolean(false); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + try { + if (!done.get()) { + controller.kill(); + } + } finally { + twillRunner.stop(); + } + })); + + LOG.info("Waiting for {} to finish in YARN...", opts.testName); + LOG.info("Press ctrl-c to kill {} in YARN", opts.testName); + + try { + controller.awaitTerminated(); + done.set(true); + } catch (ExecutionException e) { + LOG.error("Error", e); --- End diff -- Wouldn't we want to re-throw the exception so that we get a non-zero exit code? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---