本文整理汇总了Java中org.apache.apex.api.Launcher.ShutdownMode类的典型用法代码示例。如果您正苦于以下问题:Java ShutdownMode类的具体用法?Java ShutdownMode怎么用?Java ShutdownMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShutdownMode类属于org.apache.apex.api.Launcher包,在下文中一共展示了ShutdownMode类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testApplication
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Test
public void testApplication() throws Exception
{
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(Launcher.LaunchMode.EMBEDDED);
Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
EnricherAppWithJSONFile enricherAppWithJSONFile = new EnricherAppWithJSONFile();
enricherAppWithJSONFile.outputFn = outputFn;
Launcher.AppHandle appHandle = launcher.launchApp(enricherAppWithJSONFile, conf, launchAttributes);
int sleepTimeCounterForLoopExit = 0;
int sleepTimePerIteration = 500;
// wait until expected result count or timeout
while (results.size() < enricherAppWithJSONFile.getDataGenerator().getLimit()) {
sleepTimeCounterForLoopExit += sleepTimePerIteration;
if (sleepTimeCounterForLoopExit > 30000) {
break;
}
Thread.sleep(sleepTimePerIteration);
}
appHandle.shutdown(ShutdownMode.KILL);
assertTrue(results.size() >= enricherAppWithJSONFile.getDataGenerator().getLimit());
assertEnrichedOutput();
}
示例2: testApplication
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Test
public void testApplication() throws Exception {
EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(LaunchMode.EMBEDDED);
Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
//launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, false);
//launchAttributes.put(EmbeddedAppLauncher.HEARTBEAT_MONITORING, false);
Configuration conf = new Configuration(false);
conf.addResource(new Path(TEMPLATE_PROPERTIES_PATH));
conf.addResource(new Path(PROPERTIES_PATH));
//conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
conf.setBooleanIfUnset(TwitterStatsApp.IS_TWITTER_SAMPLE_INPUT, defaultTwitterInput);
conf.setBooleanIfUnset(TwitterStatsApp.IS_WEBSOCKET_OUTPUT, defaultWebsocketOutput);
StreamingApplication app = /*new TestApplication();*/ new TwitterStatsApp();
AppHandle appHandle = launcher.launchApp(app, conf, launchAttributes);
long timeoutMillis = System.currentTimeMillis() + Duration.standardMinutes(15).getMillis();
while (!appHandle.isFinished() && System.currentTimeMillis() < timeoutMillis) {
Thread.sleep(500);
}
appHandle.shutdown(ShutdownMode.KILL);
}
示例3: testApplication
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Test
public void testApplication() throws Exception {
EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(LaunchMode.EMBEDDED);
Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
//launchAttributes.put(EmbeddedAppLauncher.HEARTBEAT_MONITORING, false);
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
conf.addResource(this.getClass().getResourceAsStream("/wordcounttest-properties.xml"));
File resultFile = new File("./target/wordcountresult_4.0");
if (resultFile.exists() && !resultFile.delete()) {
throw new AssertionError("Failed to delete " + resultFile);
}
AppHandle appHandle = launcher.launchApp(new Application(), conf, launchAttributes);
long timeoutMillis = System.currentTimeMillis() + 30000;
while (!appHandle.isFinished() && System.currentTimeMillis() < timeoutMillis) {
Thread.sleep(500);
if (resultFile.exists() && resultFile.length() > 0) {
break;
}
}
appHandle.shutdown(ShutdownMode.KILL);
Assert.assertTrue(resultFile.exists() && resultFile.length() > 0);
String result = FileUtils.readFileToString(resultFile);
Assert.assertTrue(result, result.contains("MyFirstApplication=5"));
}
示例4: testApplication
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Test
public void testApplication() throws Exception {
EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(LaunchMode.EMBEDDED);
Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
//launchAttributes.put(EmbeddedAppLauncher.HEARTBEAT_MONITORING, false);
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
conf.addResource(this.getClass().getResourceAsStream("/wordcounttest-properties.xml"));
File resultFile = new File("./target/wordcountresult_4.5");
if (resultFile.exists() && !resultFile.delete()) {
throw new AssertionError("Failed to delete " + resultFile);
}
AppHandle appHandle = launcher.launchApp(new Application(), conf, launchAttributes);
long timeoutMillis = System.currentTimeMillis() + 10000;
while (!appHandle.isFinished() && System.currentTimeMillis() < timeoutMillis) {
Thread.sleep(500);
if (resultFile.exists() && resultFile.length() > 0) {
break;
}
}
appHandle.shutdown(ShutdownMode.KILL);
Assert.assertTrue(resultFile.exists() && resultFile.length() > 0);
String result = FileUtils.readFileToString(resultFile);
Assert.assertTrue(result, result.contains("="));
}
示例5: testWithHighLevelAPI
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Test
public void testWithHighLevelAPI() throws Exception
{
EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(LaunchMode.EMBEDDED);
Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
Configuration conf = new Configuration(false);
AppHandle appHandle = launcher.launchApp(new ApplicationWithHighLevelAPI(), conf, launchAttributes);
long timeoutMillis = System.currentTimeMillis() + 10000;
while (!appHandle.isFinished() && System.currentTimeMillis() < timeoutMillis) {
Thread.sleep(500);
}
appHandle.shutdown(ShutdownMode.KILL);
}
示例6: launchApp
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
protected AppHandle launchApp(LaunchParams params) throws IOException {
File tmpFile = File.createTempFile("beam-runner-apex", "params");
tmpFile.deleteOnExit();
try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
SerializationUtils.serialize(params, fos);
}
if (params.getCmd() == null) {
ApexYarnLauncher.main(new String[] {tmpFile.getAbsolutePath()});
} else {
String cmd = params.getCmd() + " " + tmpFile.getAbsolutePath();
ByteArrayOutputStream consoleOutput = new ByteArrayOutputStream();
LOG.info("Executing: {} with {}", cmd, params.getEnv());
ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd);
Map<String, String> env = pb.environment();
env.putAll(params.getEnv());
Process p = pb.start();
ProcessWatcher pw = new ProcessWatcher(p);
InputStream output = p.getInputStream();
InputStream error = p.getErrorStream();
while (!pw.isFinished()) {
IOUtils.copy(output, consoleOutput);
IOUtils.copy(error, consoleOutput);
}
if (pw.rc != 0) {
String msg = "The Beam Apex runner in non-embedded mode requires the Hadoop client"
+ " to be installed on the machine from which you launch the job"
+ " and the 'hadoop' script in $PATH";
LOG.error(msg);
throw new RuntimeException("Failed to run: " + cmd + " (exit code " + pw.rc + ")" + "\n"
+ consoleOutput.toString());
}
}
return new AppHandle() {
@Override
public boolean isFinished() {
// TODO (future PR): interaction with child process
LOG.warn("YARN application runs asynchronously and status check not implemented.");
return true;
}
@Override
public void shutdown(ShutdownMode arg0) throws LauncherException {
// TODO (future PR): interaction with child process
throw new UnsupportedOperationException();
}
};
}
示例7: cancel
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Override
public State cancel() throws IOException {
apexApp.shutdown(ShutdownMode.KILL);
state = State.CANCELLED;
return state;
}
示例8: testApplication
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Test
public void testApplication() throws Exception
{
KafkaUnit ku = kafkaUnitRule.getKafkaUnit();
String topicName = "testTopic";
// topic creation is async and the producer may also auto-create it
ku.createTopic(topicName, 1);
// produce test data
String[] words = "count the words from kafka and store them in the db".split("\\s+");
for (String word : words) {
ku.sendMessages(new KeyedMessage<String, String>(topicName, word));
}
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
conf.set("apex.operator.kafkaInput.prop.topics", topicName);
conf.set("apex.operator.kafkaInput.prop.clusters", "localhost:" + brokerPort);
conf.set("apex.operator.kafkaInput.prop.maxTuplesPerWindow", "1"); // consume one word per window
conf.set("apex.operator.kafkaInput.prop.initialOffset", "EARLIEST");
conf.set("apex.operator.store.prop.store.databaseDriver", DB_DRIVER);
conf.set("apex.operator.store.prop.store.databaseUrl", DB_URL);
EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(LaunchMode.EMBEDDED);
Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true); // terminate after results are available
AppHandle appHandle = launcher.launchApp(new ExactlyOnceJdbcOutputApp(), conf, launchAttributes);
HashSet<String> wordsSet = Sets.newHashSet(words);
Connection con = DriverManager.getConnection(DB_URL);
Statement stmt = con.createStatement();
int rowCount = 0;
long timeout = System.currentTimeMillis() + 30000; // 30s timeout
while (rowCount < wordsSet.size() && timeout > System.currentTimeMillis()) {
Thread.sleep(500);
String countQuery = "SELECT count(*) from " + TABLE_NAME;
ResultSet resultSet = stmt.executeQuery(countQuery);
resultSet.next();
rowCount = resultSet.getInt(1);
resultSet.close();
LOG.info("current row count in {} is {}", TABLE_NAME, rowCount);
}
Assert.assertEquals("number of words", wordsSet.size(), rowCount);
appHandle.shutdown(ShutdownMode.KILL);
}
示例9: testApplication
import org.apache.apex.api.Launcher.ShutdownMode; //导入依赖的package包/类
@Test
public void testApplication() throws Exception
{
File targetDir = new File(TARGET_DIR);
FileUtils.deleteDirectory(targetDir);
FileUtils.forceMkdir(targetDir);
KafkaUnit ku = kafkaUnitRule.getKafkaUnit();
String topicName = "testTopic";
// topic creation is async and the producer may also auto-create it
ku.createTopic(topicName, 1);
// produce test data
String[] words = "count count the words from kafka and store them in a file".split("\\s+");
for (String word : words) {
ku.sendMessages(new KeyedMessage<String, String>(topicName, word));
}
Configuration conf = new Configuration(false);
conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
conf.set("apex.operator.kafkaInput.prop.topics", topicName);
conf.set("apex.operator.kafkaInput.prop.clusters", "localhost:" + brokerPort);
conf.set("apex.operator.kafkaInput.prop.maxTuplesPerWindow", "2"); // consume one word per window
conf.set("apex.operator.kafkaInput.prop.initialOffset", "EARLIEST");
conf.set("apex.operator.fileWriter.prop.filePath", TARGET_DIR);
EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(LaunchMode.EMBEDDED);
Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true); // terminate after results are available
AppHandle appHandle = launcher.launchApp(new ExactlyOnceFileOutputApp(), conf, launchAttributes);
long timeout = System.currentTimeMillis() + 60000; // 60s timeout
File outputFile = new File(TARGET_DIR, ExactlyOnceFileOutputApp.FileWriter.FILE_NAME_PREFIX);
while (!outputFile.exists() && timeout > System.currentTimeMillis()) {
Thread.sleep(1000);
LOG.debug("Waiting for {}", outputFile);
}
Assert.assertTrue("output file exists " + ExactlyOnceFileOutputApp.FileWriter.FILE_NAME_PREFIX, outputFile.exists() &&
outputFile.isFile());
String result = FileUtils.readFileToString(outputFile);
Assert.assertTrue(result.contains("count=2"));
appHandle.shutdown(ShutdownMode.KILL);
}