本文整理匯總了Java中org.apache.hadoop.yarn.client.api.YarnClient類的典型用法代碼示例。如果您正苦於以下問題:Java YarnClient類的具體用法?Java YarnClient怎麽用?Java YarnClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
YarnClient類屬於org.apache.hadoop.yarn.client.api包,在下文中一共展示了YarnClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetClusterNodeLabelsWithLocalAccess
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test
public void testGetClusterNodeLabelsWithLocalAccess() throws Exception {
YarnClient client = mock(YarnClient.class);
when(client.getClusterNodeLabels()).thenReturn(
ImmutableSet.of("remote1", "remote2"));
ClusterCLI cli = new ClusterCLI();
cli.setClient(client);
cli.setSysOutPrintStream(sysOut);
cli.setSysErrPrintStream(sysErr);
ClusterCLI.localNodeLabelsManager = mock(CommonNodeLabelsManager.class);
when(ClusterCLI.localNodeLabelsManager.getClusterNodeLabels())
.thenReturn(ImmutableSet.of("local1", "local2"));
int rc =
cli.run(new String[] { ClusterCLI.CMD,
"-" + ClusterCLI.LIST_LABELS_CMD,
"-" + ClusterCLI.DIRECTLY_ACCESS_NODE_LABEL_STORE });
assertEquals(0, rc);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
// it should return local* instead of remote*
pw.print("Node Labels: local1,local2");
pw.close();
verify(sysOut).println(baos.toString("UTF-8"));
}
示例2: mockYarnClient
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
private static void mockYarnClient() throws YarnException, IOException {
yarnClient = mock(YarnClient.class);
doNothing().when(yarnClient).start();
YarnClientApplication app = mock(YarnClientApplication.class);
when(yarnClient.createApplication()).thenReturn(app);
GetNewApplicationResponse appResponse = mock(GetNewApplicationResponse.class);
when(app.getNewApplicationResponse()).thenReturn(appResponse);
ApplicationSubmissionContext appContext = mock(ApplicationSubmissionContext.class);
when(app.getApplicationSubmissionContext()).thenReturn(appContext);
appId = mock(ApplicationId.class);
when(appContext.getApplicationId()).thenReturn(appId);
doNothing().when(appContext).setApplicationName(Matchers.anyString());
report = mock(ApplicationReport.class);
when(yarnClient.getApplicationReport(appId)).thenReturn(report);
when(appId.getId()).thenReturn(1);
when(appId.toString()).thenReturn("application_1465186316357_0001");
when(report.getDiagnostics()).thenReturn("fake diagnostics");
when(report.getQueue()).thenReturn("fake queue");
when(report.getProgress()).thenReturn(0.5f);
}
示例3: testDeployerWithIsolatedConfiguration
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test
public void testDeployerWithIsolatedConfiguration() throws Exception {
YarnClusterConfiguration clusterConf = mock(YarnClusterConfiguration.class);
doReturn(new YarnConfiguration()).when(clusterConf).conf();
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
Configuration flinkConf = new Configuration();
YarnClient client = mock(YarnClient.class);
JobDeployer deploy = new JobDeployer(clusterConf, client, executor, flinkConf);
AthenaXYarnClusterDescriptor desc = mock(AthenaXYarnClusterDescriptor.class);
YarnClusterClient clusterClient = mock(YarnClusterClient.class);
doReturn(clusterClient).when(desc).deploy();
ActorGateway actorGateway = mock(ActorGateway.class);
doReturn(actorGateway).when(clusterClient).getJobManagerGateway();
doReturn(Future$.MODULE$.successful(null)).when(actorGateway).ask(any(), any());
JobGraph jobGraph = mock(JobGraph.class);
doReturn(JobID.generate()).when(jobGraph).getJobID();
deploy.start(desc, jobGraph);
ArgumentCaptor<Configuration> args = ArgumentCaptor.forClass(Configuration.class);
verify(desc).setFlinkConfiguration(args.capture());
assertNotSame(flinkConf, args.getValue());
}
示例4: testChangeState
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test
public void testChangeState() throws Exception {
YarnClient client = mock(YarnClient.class);
YarnClusterConfiguration conf = mock(YarnClusterConfiguration.class);
ClusterInfo clusterInfo = new ClusterInfo("foo", conf, client);
UUID app = UUID.randomUUID();
ApplicationId yarnAppId = mock(ApplicationId.class);
try (InstanceManager manager = new InstanceManager(
Collections.singletonMap("foo", clusterInfo),
mock(InstanceStateUpdateListener.class),
mock(ScheduledExecutorService.class),
AthenaXExtraConfigOptions.INSTANCE_MANAGER_RESCAN_INTERVAL.defaultValue())) {
InstanceInfo instance = new InstanceInfo("foo", yarnAppId,
mock(InstanceMetadata.class), mock(InstanceStatus.class));
manager.instances().put(app, instance);
manager.changeState(app, new InstanceState().state(InstanceState.StateEnum.KILLED));
verify(client).killApplication(eq(yarnAppId));
}
}
示例5: killApplication
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
public static void killApplication(String applicationId) throws Exception {
try {
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
LOGGER.logInfo("[yarn application -kill %s]", applicationId);
yarnClient.killApplication(ConverterUtils.toApplicationId(applicationId));
yarnClient.stop();
} catch (ApplicationNotFoundException ignored) {
} catch (Exception e) {
if (e.getMessage().toLowerCase().contains("invalid applicationid")) {
// ignored
} else {
throw e;
}
}
}
示例6: submitApplication
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
public static void submitApplication(
ApplicationSubmissionContext appContext, UserDescriptor user) throws Throwable {
UserGroupInformation ugi =
UserGroupInformation.createRemoteUser(user.getName());
// Need to start a new YarnClient for a new UGI, since its internal Hadoop RPC
// reuse the UGI after YarnClient.start().
try {
ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
yarnClient.submitApplication(appContext);
yarnClient.stop();
return null;
});
} catch (UndeclaredThrowableException e) {
throw e.getCause();
}
}
示例7: verifyApplicationState
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
private int verifyApplicationState(ApplicationId appId) throws IOException,
YarnException {
YarnClient yarnClient = createYarnClient();
try {
ApplicationReport appReport = yarnClient.getApplicationReport(appId);
switch (appReport.getYarnApplicationState()) {
case NEW:
case NEW_SAVING:
case SUBMITTED:
return -1;
case ACCEPTED:
case RUNNING:
case FAILED:
case FINISHED:
case KILLED:
default:
break;
}
} finally {
yarnClient.close();
}
return 0;
}
示例8: verifyClientConnection
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
private void verifyClientConnection() {
int numRetries = 3;
while(numRetries-- > 0) {
Configuration conf = new YarnConfiguration(this.conf);
YarnClient client = YarnClient.createYarnClient();
client.init(conf);
client.start();
try {
client.getApplications();
return;
} catch (Exception e) {
LOG.error(e);
} finally {
client.stop();
}
}
fail("Client couldn't connect to the Active RM");
}
示例9: verifyClientConnection
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
protected void verifyClientConnection() {
int numRetries = 3;
while(numRetries-- > 0) {
Configuration conf = new YarnConfiguration(this.conf);
YarnClient client = createAndStartYarnClient(conf);
try {
Thread.sleep(100);
client.getApplications();
return;
} catch (Exception e) {
LOG.error(e.getMessage());
} finally {
client.stop();
}
}
fail("Client couldn't connect to the Active RM");
}
示例10: testKillApplication
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test
public void testKillApplication() throws Exception {
MockRM rm = new MockRM();
rm.start();
RMApp app = rm.submitApp(2000);
Configuration conf = new Configuration();
@SuppressWarnings("resource")
final YarnClient client = new MockYarnClient();
client.init(conf);
client.start();
client.killApplication(app.getApplicationId());
verify(((MockYarnClient) client).getRMClient(), times(2))
.forceKillApplication(any(KillApplicationRequest.class));
}
示例11: testGetApplicationAttempts
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test(timeout = 10000)
public void testGetApplicationAttempts() throws YarnException, IOException {
Configuration conf = new Configuration();
final YarnClient client = new MockYarnClient();
client.init(conf);
client.start();
ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
List<ApplicationAttemptReport> reports = client
.getApplicationAttempts(applicationId);
Assert.assertNotNull(reports);
Assert.assertEquals(reports.get(0).getApplicationAttemptId(),
ApplicationAttemptId.newInstance(applicationId, 1));
Assert.assertEquals(reports.get(1).getApplicationAttemptId(),
ApplicationAttemptId.newInstance(applicationId, 2));
client.stop();
}
示例12: testGetApplicationAttempt
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test(timeout = 10000)
public void testGetApplicationAttempt() throws YarnException, IOException {
Configuration conf = new Configuration();
final YarnClient client = new MockYarnClient();
client.init(conf);
client.start();
List<ApplicationReport> expectedReports = ((MockYarnClient) client)
.getReports();
ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
applicationId, 1);
ApplicationAttemptReport report = client
.getApplicationAttemptReport(appAttemptId);
Assert.assertNotNull(report);
Assert.assertEquals(report.getApplicationAttemptId().toString(),
expectedReports.get(0).getCurrentApplicationAttemptId().toString());
client.stop();
}
示例13: testGetLabelsToNodes
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test (timeout = 10000)
public void testGetLabelsToNodes() throws YarnException, IOException {
Configuration conf = new Configuration();
final YarnClient client = new MockYarnClient();
client.init(conf);
client.start();
// Get labels to nodes mapping
Map<String, Set<NodeId>> expectedLabelsToNodes =
((MockYarnClient)client).getLabelsToNodesMap();
Map<String, Set<NodeId>> labelsToNodes = client.getLabelsToNodes();
Assert.assertEquals(labelsToNodes, expectedLabelsToNodes);
Assert.assertEquals(labelsToNodes.size(), 3);
// Get labels to nodes for selected labels
Set<String> setLabels = new HashSet<String>(Arrays.asList("x", "z"));
expectedLabelsToNodes =
((MockYarnClient)client).getLabelsToNodesMap(setLabels);
labelsToNodes = client.getLabelsToNodes(setLabels);
Assert.assertEquals(labelsToNodes, expectedLabelsToNodes);
Assert.assertEquals(labelsToNodes.size(), 2);
client.stop();
client.close();
}
示例14: waitTillAccepted
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
private void waitTillAccepted(YarnClient rmClient, ApplicationId appId)
throws Exception {
try {
long start = System.currentTimeMillis();
ApplicationReport report = rmClient.getApplicationReport(appId);
while (YarnApplicationState.ACCEPTED != report.getYarnApplicationState()) {
if (System.currentTimeMillis() - start > 20 * 1000) {
throw new Exception("App '" + appId +
"' time out, failed to reach ACCEPTED state");
}
Thread.sleep(200);
report = rmClient.getApplicationReport(appId);
}
} catch (Exception ex) {
throw new Exception(ex);
}
}
示例15: testParseTimelineDelegationTokenRenewer
import org.apache.hadoop.yarn.client.api.YarnClient; //導入依賴的package包/類
@Test
public void testParseTimelineDelegationTokenRenewer() throws Exception {
// Client side
YarnClientImpl client = (YarnClientImpl) YarnClient.createYarnClient();
Configuration conf = new YarnConfiguration();
conf.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, true);
conf.set(YarnConfiguration.RM_PRINCIPAL, "rm/[email protected]");
conf.set(
YarnConfiguration.RM_ADDRESS, "localhost:8188");
try {
client.init(conf);
client.start();
Assert.assertEquals("rm/[email protected]", client.timelineDTRenewer);
} finally {
client.stop();
}
}