-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathJobsWithMantaJobBuilder.java
More file actions
59 lines (52 loc) · 2.35 KB
/
JobsWithMantaJobBuilder.java
File metadata and controls
59 lines (52 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Copyright (c) 2016-2017, Joyent, Inc. All rights reserved.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import com.joyent.manta.client.MantaClient;
import com.joyent.manta.client.jobs.MantaJobBuilder;
import com.joyent.manta.client.jobs.MantaJobPhase;
import com.joyent.manta.config.ConfigContext;
import com.joyent.manta.config.SystemSettingsConfigContext;
import java.io.IOException;
import java.util.stream.Stream;
/**
* Creating a job using the MantaJobBuilder allows for a more fluent style of
* job creation. Using this approach allows for a more fluent configuration of
* job initialization.
*/
public class JobsWithMantaJobBuilder {
public static void main(String... args) throws IOException {
ConfigContext config = new SystemSettingsConfigContext();
MantaClient client = new MantaClient(config);
// You can only get a builder from a MantaClient
final MantaJobBuilder builder = client.jobBuilder();
MantaJobBuilder.Run runningJob = builder.newJob("example")
.addInputs("/user/stor/logs/input_1",
"/user/stor/logs/input_2",
"/user/stor/logs/input_3",
"/user/stor/logs/input_4")
.addPhase(new MantaJobPhase()
.setType("map")
.setExec("grep foo"))
.addPhase(new MantaJobPhase()
.setType("reduce")
.setExec("sort | uniq"))
// This is an optional command that will validate that the inputs
// specified are available
.validateInputs()
.run();
// This will wait until the job is finished
MantaJobBuilder.Done finishedJob = runningJob.waitUntilDone()
// This will validate if the job finished without errors.
// If there was an error an exception will be thrown
.validateJobsSucceeded();
// You will always need to close streams because we do everything online
try (Stream<String> outputs = finishedJob.outputs()) {
// Print each output
outputs.forEach(System.out::println);
}
}
}