本文整理匯總了Java中org.apache.hadoop.yarn.client.api.YarnClient.init方法的典型用法代碼示例。如果您正苦於以下問題:Java YarnClient.init方法的具體用法?Java YarnClient.init怎麽用?Java YarnClient.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.yarn.client.api.YarnClient
的用法示例。
在下文中一共展示了YarnClient.init方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
}
示例2: 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");
}
示例3: 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));
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: killJobOnCluster
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
public static void killJobOnCluster(String applicationId, Logger log) throws YarnException,
IOException {
YarnConfiguration yarnConf = new YarnConfiguration();
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(yarnConf);
yarnClient.start();
String[] split = applicationId.split("_",-1);
ApplicationId aid = ApplicationId.newInstance(Long.parseLong(split[1]),
Integer.parseInt(split[2]));
yarnClient.killApplication(aid);
log.info("successfully killed application: " + aid);
yarnClient.close();
}
示例8: 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<NodeLabel, Set<NodeId>> expectedLabelsToNodes =
((MockYarnClient)client).getLabelsToNodesMap();
Map<NodeLabel, 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();
}
示例9: testSignalContainer
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
@Test
public void testSignalContainer() throws Exception {
Configuration conf = new Configuration();
@SuppressWarnings("resource")
final YarnClient client = new MockYarnClient();
client.init(conf);
client.start();
ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
applicationId, 1);
ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1);
SignalContainerCommand command = SignalContainerCommand.OUTPUT_THREAD_DUMP;
client.signalContainer(containerId, command);
final ArgumentCaptor<SignalContainerRequest> signalReqCaptor =
ArgumentCaptor.forClass(SignalContainerRequest.class);
verify(((MockYarnClient) client).getRMClient())
.signalContainer(signalReqCaptor.capture());
SignalContainerRequest request = signalReqCaptor.getValue();
Assert.assertEquals(containerId, request.getContainerId());
Assert.assertEquals(command, request.getCommand());
}
示例10: getLiveContainerIdsFromRM
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
public static HashSet<String> getLiveContainerIdsFromRM(String attemptId, String amContainerId) throws Exception {
HashSet<String> containerIds = new HashSet<>();
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(conf);
yarnClient.start();
List<ContainerReport> containerReports = yarnClient.getContainers(ConverterUtils.toApplicationAttemptId(attemptId));
yarnClient.stop();
// Since we at least has AM container, so we check whether the containerReports is reliable
if (containerReports == null) {
throw new Exception(
String.format("Container reports of attempt %s is empty , but AM container exists",
attemptId));
}
for (ContainerReport containerReport : containerReports) {
if (containerReport.getContainerState() == ContainerState.COMPLETE) {
continue;
}
containerIds.add(containerReport.getContainerId().toString());
}
if (!containerIds.contains(amContainerId)) {
throw new Exception(
String.format("Container reports of attempt %s does not contain AM container %s",
attemptId, amContainerId));
}
containerIds.remove(amContainerId);
return containerIds;
}
示例11: Client
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
Client(Configuration conf, YarnClient yarnClient) {
super("Client");
this.conf = conf;
this.yarnClient = yarnClient;
yarnClient.init(conf);
yarnClient.start();
LOG.info("Starting YarnClient...");
}
示例12: createYarnClient
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
@VisibleForTesting
protected YarnClient createYarnClient() {
YarnClient yarnClient = YarnClient.createYarnClient();
yarnClient.init(getConf());
yarnClient.start();
return yarnClient;
}
示例13: createAndStartYarnClient
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
protected YarnClient createAndStartYarnClient(Configuration conf) {
Configuration configuration = new YarnConfiguration(conf);
YarnClient client = YarnClient.createYarnClient();
client.init(configuration);
client.start();
return client;
}
示例14: testClientStop
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
@Test
public void testClientStop() {
Configuration conf = new Configuration();
ResourceManager rm = new ResourceManager();
rm.init(conf);
rm.start();
YarnClient client = YarnClient.createYarnClient();
client.init(conf);
client.start();
client.stop();
rm.stop();
}
示例15: testGetContainers
import org.apache.hadoop.yarn.client.api.YarnClient; //導入方法依賴的package包/類
@Test(timeout = 10000)
public void testGetContainers() throws YarnException, IOException {
Configuration conf = new Configuration();
conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED,
true);
final YarnClient client = new MockYarnClient();
client.init(conf);
client.start();
ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(
applicationId, 1);
List<ContainerReport> reports = client.getContainers(appAttemptId);
Assert.assertNotNull(reports);
Assert.assertEquals(reports.get(0).getContainerId(),
(ContainerId.newContainerId(appAttemptId, 1)));
Assert.assertEquals(reports.get(1).getContainerId(),
(ContainerId.newContainerId(appAttemptId, 2)));
Assert.assertEquals(reports.get(2).getContainerId(),
(ContainerId.newContainerId(appAttemptId, 3)));
//First2 containers should come from RM with updated state information and
// 3rd container is not there in RM and should
Assert.assertEquals(ContainerState.RUNNING,
(reports.get(0).getContainerState()));
Assert.assertEquals(ContainerState.RUNNING,
(reports.get(1).getContainerState()));
Assert.assertEquals(ContainerState.COMPLETE,
(reports.get(2).getContainerState()));
client.stop();
}