本文整理匯總了Java中org.apache.hadoop.yarn.api.records.YarnApplicationState類的典型用法代碼示例。如果您正苦於以下問題:Java YarnApplicationState類的具體用法?Java YarnApplicationState怎麽用?Java YarnApplicationState使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
YarnApplicationState類屬於org.apache.hadoop.yarn.api.records包,在下文中一共展示了YarnApplicationState類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: computeState
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
static StateView computeState(Map<UUID, JobDefinition> jobs, Map<UUID, InstanceInfo> instances) {
// Instance ID -> JobDefinition ID
HashMap<UUID, UUID> instanceToJob = new HashMap<>();
HashMap<UUID, List<InstanceInfo>> jobInstances = new HashMap<>();
for (Map.Entry<UUID, InstanceInfo> e : instances.entrySet()) {
YarnApplicationState state = YarnApplicationState.valueOf(e.getValue().status().getState().toString());
if (!isInstanceAlive(state)) {
continue;
}
UUID jobId = e.getValue().metadata().jobDefinition();
UUID instanceId = e.getKey();
instanceToJob.put(instanceId, jobId);
if (!jobInstances.containsKey(jobId)) {
jobInstances.put(jobId, new ArrayList<>());
}
jobInstances.get(jobId).add(e.getValue());
}
jobs.keySet().stream().filter(x -> !jobInstances.containsKey(x))
.forEach(x -> jobInstances.put(x, Collections.emptyList()));
return new StateView(jobs, instances, instanceToJob, jobInstances);
}
示例2: awaitApplication
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
boolean awaitApplication(ApplicationId appId) throws Exception {
Set<YarnApplicationState> terminated = Sets.newHashSet(
YarnApplicationState.FAILED,
YarnApplicationState.FINISHED,
YarnApplicationState.KILLED);
while (true) {
ApplicationReport report = yarnClient.getApplicationReport(appId);
YarnApplicationState state = report.getYarnApplicationState();
if (state.equals(YarnApplicationState.RUNNING)) {
ClusterSpec clusterSpec = Client.getClusterSpec(yarnClient, appId);
if (isClusterSpecSatisfied(clusterSpec)) {
System.out.println("ClusterSpec: " + Utils.toJsonString(clusterSpec.getCluster()));
return true;
}
} else if (terminated.contains(state)) {
return false;
} else {
Thread.sleep(1000);
}
}
}
示例3: clarifyAppState
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
private String clarifyAppState(YarnApplicationState state) {
String ret = state.toString();
switch (state) {
case NEW:
return ret + ": waiting for application to be initialized";
case NEW_SAVING:
return ret + ": waiting for application to be persisted in state-store.";
case SUBMITTED:
return ret + ": waiting for application to be accepted by scheduler.";
case ACCEPTED:
return ret + ": waiting for AM container to be allocated, launched and"
+ " register with RM.";
case RUNNING:
return ret + ": AM has registered with RM and started running.";
default:
return ret;
}
}
示例4: buildScoreboard
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
private static Map<YarnApplicationState, Map<String, Long>> buildScoreboard(
Set<String> states, Set<String> types) {
Map<YarnApplicationState, Map<String, Long>> scoreboard
= new HashMap<YarnApplicationState, Map<String, Long>>();
// default states will result in enumerating all YarnApplicationStates
assert !states.isEmpty();
for (String state : states) {
Map<String, Long> partScoreboard = new HashMap<String, Long>();
scoreboard.put(
YarnApplicationState.valueOf(StringUtils.toUpperCase(state)),
partScoreboard);
// types is verified no to be empty
for (String type : types) {
partScoreboard.put(type, 0L);
}
}
return scoreboard;
}
示例5: render
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Override public void render(Block html) {
UL<DIV<Hamlet>> mainList = html.
div("#nav").
h3("Cluster").
ul().
li().a(url("cluster"), "About")._().
li().a(url("nodes"), "Nodes")._().
li().a(url("nodelabels"), "Node Labels")._();
UL<LI<UL<DIV<Hamlet>>>> subAppsList = mainList.
li().a(url("apps"), "Applications").
ul();
subAppsList.li()._();
for (YarnApplicationState state : YarnApplicationState.values()) {
subAppsList.
li().a(url("apps", state.toString()), state.toString())._();
}
subAppsList._()._();
mainList.
li().a(url("scheduler"), "Scheduler")._()._().
h3("Tools").
ul().
li().a("/conf", "Configuration")._().
li().a("/logs", "Local logs")._().
li().a("/stacks", "Server stacks")._().
li().a("/jmx?qry=Hadoop:*", "Server metrics")._()._()._();
}
示例6: ApplicationFinishedEvent
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
public ApplicationFinishedEvent(
ApplicationId appId,
String diagnosticsInfo,
FinalApplicationStatus appStatus,
YarnApplicationState state,
ApplicationAttemptId latestAppAttemptId,
long finishedTime,
RMAppMetrics appMetrics) {
super(SystemMetricsEventType.APP_FINISHED, finishedTime);
this.appId = appId;
this.diagnosticsInfo = diagnosticsInfo;
this.appStatus = appStatus;
this.latestAppAttemptId = latestAppAttemptId;
this.state = state;
this.appMetrics=appMetrics;
}
示例7: createApplicationState
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
public static YarnApplicationState createApplicationState(
RMAppState rmAppState) {
switch (rmAppState) {
case NEW:
return YarnApplicationState.NEW;
case NEW_SAVING:
return YarnApplicationState.NEW_SAVING;
case SUBMITTED:
return YarnApplicationState.SUBMITTED;
case ACCEPTED:
return YarnApplicationState.ACCEPTED;
case RUNNING:
return YarnApplicationState.RUNNING;
case FINISHING:
case FINISHED:
return YarnApplicationState.FINISHED;
case KILLED:
return YarnApplicationState.KILLED;
case FAILED:
return YarnApplicationState.FAILED;
default:
throw new YarnRuntimeException("Unknown state passed!");
}
}
示例8: testAppsQueryState
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Test
public void testAppsQueryState() throws JSONException, Exception {
rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
RMApp app1 = rm.submitApp(CONTAINER_MB);
amNodeManager.nodeHeartbeat(true);
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("apps")
.queryParam("state", YarnApplicationState.ACCEPTED.toString())
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
JSONObject apps = json.getJSONObject("apps");
assertEquals("incorrect number of elements", 1, apps.length());
JSONArray array = apps.getJSONArray("app");
assertEquals("incorrect number of elements", 1, array.length());
verifyAppInfo(array.getJSONObject(0), app1);
rm.stop();
}
示例9: testAppsQueryStatesNone
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Test
public void testAppsQueryStatesNone() throws JSONException, Exception {
rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
rm.submitApp(CONTAINER_MB);
amNodeManager.nodeHeartbeat(true);
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("apps")
.queryParam("states", YarnApplicationState.RUNNING.toString())
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
rm.stop();
}
示例10: testAppsQueryStateNone
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Test
public void testAppsQueryStateNone() throws JSONException, Exception {
rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
rm.submitApp(CONTAINER_MB);
amNodeManager.nodeHeartbeat(true);
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("apps")
.queryParam("state", YarnApplicationState.RUNNING.toString())
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
rm.stop();
}
示例11: getApplicationReport
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Override
public ApplicationReport getApplicationReport(ApplicationId applicationId)
throws IOException {
List<ApplicationReport> reports = null;
try {
reports = getApplications(applicationId.getId());
} catch (Throwable e) {
LOG.info("Couldn't get application report for " + applicationId
+ ", might be completed already.");
}
if (reports == null || reports.isEmpty()) {
return ApplicationReport.newInstance(applicationId, null, "", "default",
"", "", 0, null, YarnApplicationState.FINISHED, "", "", 0, 0,
FinalApplicationStatus.SUCCEEDED, null, "", 100, null, null);
}
return reports.get(0);
}
示例12: validateStates
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
private static void
validateStates(String stateQuery, Set<String> statesQuery) {
// stateQuery is deprecated.
if (stateQuery != null && !stateQuery.isEmpty()) {
statesQuery.add(stateQuery);
}
Set<String> appStates = parseQueries(statesQuery, true);
for (String appState : appStates) {
switch (YarnApplicationState.valueOf(
StringUtils.toUpperCase(appState))) {
case FINISHED:
case FAILED:
case KILLED:
continue;
default:
throw new BadRequestException("Invalid application-state " + appState
+ " specified. It should be a final state");
}
}
}
示例13: testJobSubmissionFailure
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Test(timeout=20000)
public void testJobSubmissionFailure() throws Exception {
when(resourceMgrDelegate.submitApplication(any(ApplicationSubmissionContext.class))).
thenReturn(appId);
ApplicationReport report = mock(ApplicationReport.class);
when(report.getApplicationId()).thenReturn(appId);
when(report.getDiagnostics()).thenReturn(failString);
when(report.getYarnApplicationState()).thenReturn(YarnApplicationState.FAILED);
when(resourceMgrDelegate.getApplicationReport(appId)).thenReturn(report);
Credentials credentials = new Credentials();
File jobxml = new File(testWorkDir, "job.xml");
OutputStream out = new FileOutputStream(jobxml);
conf.writeXml(out);
out.close();
try {
yarnRunner.submitJob(jobId, testWorkDir.getAbsolutePath().toString(), credentials);
} catch(IOException io) {
LOG.info("Logging exception:", io);
assertTrue(io.getLocalizedMessage().contains(failString));
}
}
示例14: tesAllJobs
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Test
public void tesAllJobs() throws Exception {
final ApplicationClientProtocol applicationsManager = Mockito.mock(ApplicationClientProtocol.class);
GetApplicationsResponse allApplicationsResponse = Records
.newRecord(GetApplicationsResponse.class);
List<ApplicationReport> applications = new ArrayList<ApplicationReport>();
applications.add(getApplicationReport(YarnApplicationState.FINISHED,
FinalApplicationStatus.FAILED));
applications.add(getApplicationReport(YarnApplicationState.FINISHED,
FinalApplicationStatus.SUCCEEDED));
applications.add(getApplicationReport(YarnApplicationState.FINISHED,
FinalApplicationStatus.KILLED));
applications.add(getApplicationReport(YarnApplicationState.FAILED,
FinalApplicationStatus.FAILED));
allApplicationsResponse.setApplicationList(applications);
Mockito.when(
applicationsManager.getApplications(Mockito
.any(GetApplicationsRequest.class))).thenReturn(
allApplicationsResponse);
ResourceMgrDelegate resourceMgrDelegate = new ResourceMgrDelegate(
new YarnConfiguration()) {
@Override
protected void serviceStart() throws Exception {
Assert.assertTrue(this.client instanceof YarnClientImpl);
((YarnClientImpl) this.client).setRMClient(applicationsManager);
}
};
JobStatus[] allJobs = resourceMgrDelegate.getAllJobs();
Assert.assertEquals(State.FAILED, allJobs[0].getState());
Assert.assertEquals(State.SUCCEEDED, allJobs[1].getState());
Assert.assertEquals(State.KILLED, allJobs[2].getState());
Assert.assertEquals(State.FAILED, allJobs[3].getState());
}
示例15: testView
import org.apache.hadoop.yarn.api.records.YarnApplicationState; //導入依賴的package包/類
@Test
public void testView() throws Exception {
Injector injector =
WebAppTests.createMockInjector(ApplicationBaseProtocol.class,
mockApplicationHistoryClientService(5, 1, 1));
AHSView ahsViewInstance = injector.getInstance(AHSView.class);
ahsViewInstance.render();
WebAppTests.flushOutput(injector);
ahsViewInstance.set(YarnWebParams.APP_STATE,
YarnApplicationState.FAILED.toString());
ahsViewInstance.render();
WebAppTests.flushOutput(injector);
ahsViewInstance.set(YarnWebParams.APP_STATE, StringHelper.cjoin(
YarnApplicationState.FAILED.toString(), YarnApplicationState.KILLED));
ahsViewInstance.render();
WebAppTests.flushOutput(injector);
}