/
EmrExample.java
60 lines (51 loc) · 2.28 KB
/
EmrExample.java
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
60
/**
* Copyright 2010 the original author or authors.
*
* Licensed 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 datameer.awstasks;
import java.io.File;
import java.io.IOException;
import datameer.awstasks.aws.emr.EmrCluster;
import datameer.awstasks.util.Ec2Configuration;
public class EmrExample {
public static void main(String[] args) throws IOException, InterruptedException {
String clusterName = "my-cluster";
String s3Bucket = "testbucket";
// have your aws access data
// String accessKeyId = null;
// String accessKeySecret = null;
// String privateKeyName;
// EmrSettings settings = new EmrSettings(clusterName, accessKeyId, privateKeyName,
// s3Bucket, 5);
// EmrCluster emrCluster = new EmrCluster(settings, accessKeySecret);
// or alternatively use the Ec2Configuration
Ec2Configuration ec2Configuration = new Ec2Configuration(); // searches for ec2.properties
EmrCluster emrCluster = ec2Configuration.createEmrCluster(clusterName, "0.20", s3Bucket, 5);
// start a new flow
emrCluster.startup();
// or connect to an existing
// emrCluster.setName("myCluster"); //by name
// emrCluster.connect();
//
// emrCluster.connect("j-9RFYACO46O2Z");//by id
// execute a flow step
String remoteInputPath = "/emr/input";
String remoteOutputPath = "/emr/output";
String inputUri = "s3n://" + s3Bucket + remoteInputPath;
String outputUri = "s3n://" + s3Bucket + remoteOutputPath;
emrCluster.createJobStep("wordcount-" + System.currentTimeMillis(), new File("lib/test/hadoop-0.18.3-examples.jar")).setMainArgs(inputUri, outputUri).submit().join();
// shut the flow down
emrCluster.shutdown();
}
}