-
Notifications
You must be signed in to change notification settings - Fork 39
/
KittenClient.java
109 lines (93 loc) · 3.74 KB
/
KittenClient.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Copyright (c) 2012, Cloudera, Inc. All Rights Reserved.
*
* Cloudera, Inc. 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
*
* This software 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 com.cloudera.kitten.client;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.yarn.api.records.ApplicationReport;
import org.apache.hadoop.yarn.api.records.FinalApplicationStatus;
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
import com.cloudera.kitten.client.params.lua.LuaYarnClientParameters;
import com.cloudera.kitten.client.service.YarnClientServiceImpl;
import com.google.common.collect.ImmutableMap;
/**
* A simple client for cases where there does not need to be any client-side logic to run a job.
*/
public class KittenClient extends Configured implements Tool {
private static final Log LOG = LogFactory.getLog(KittenClient.class);
private Map<String, Object> extraLuaValues;
private Map<String, String> extraLocalResources;
public KittenClient() {
this(ImmutableMap.<String, Object>of());
}
public KittenClient(Map<String, Object> extraLuaValues) {
this(extraLuaValues, ImmutableMap.<String, String>of());
}
public KittenClient(Map<String, Object> extraLuaValues, Map<String, String> extraLocalResources) {
this.extraLuaValues = extraLuaValues;
this.extraLocalResources = extraLocalResources;
}
@Override
public int run(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: kitten [conf params] <kitten config file> <job name>");
return -1;
}
Configuration conf = getConf();
YarnClientParameters params = new LuaYarnClientParameters(args[0], args[1], conf,
extraLuaValues, extraLocalResources);
YarnClientService service = new YarnClientServiceImpl(params);
return handle(service);
}
public int handle(YarnClientService service) throws Exception {
service.startAndWait();
if (!service.isRunning()) {
LOG.error("Service failed to startup, exiting...");
return 1;
}
String trackingUrl = null;
while (service.isRunning()) {
if (trackingUrl == null) {
Thread.sleep(1000);
ApplicationReport report = service.getApplicationReport();
YarnApplicationState yarnAppState = report.getYarnApplicationState();
if (yarnAppState == YarnApplicationState.RUNNING) {
trackingUrl = report.getTrackingUrl();
if (trackingUrl == null || trackingUrl.isEmpty()) {
LOG.info("Application is running, but did not specify a tracking URL");
trackingUrl = "";
} else {
LOG.info("Master Tracking URL = " + trackingUrl);
}
}
}
}
LOG.info("Checking final app report");
ApplicationReport report = service.getFinalReport();
if (report == null || report.getFinalApplicationStatus() != FinalApplicationStatus.SUCCEEDED) {
return 1;
}
LOG.info("Kitten client finishing...");
return 0;
}
public static void main(String[] args) throws Exception {
int rc = ToolRunner.run(new Configuration(), new KittenClient(), args);
System.exit(rc);
}
}