Java Code Examples for org.apache.hadoop.yarn.client.api.YarnClient

The following examples show how to use org.apache.hadoop.yarn.client.api.YarnClient. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: attic-apex-core   Source File: StramClientUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static List<ApplicationReport> cleanAppDirectories(YarnClient clientRMService, Configuration conf, FileSystem fs, long finishedBefore)
    throws IOException, YarnException
{
  List<ApplicationReport> result = new ArrayList<>();
  List<ApplicationReport> applications = clientRMService.getApplications(Sets.newHashSet(StramClient.YARN_APPLICATION_TYPE, StramClient.YARN_APPLICATION_TYPE_DEPRECATED),
      EnumSet.of(YarnApplicationState.FAILED, YarnApplicationState.FINISHED, YarnApplicationState.KILLED));
  Path appsBasePath = new Path(StramClientUtils.getApexDFSRootDir(fs, conf), StramClientUtils.SUBDIR_APPS);
  for (ApplicationReport ar : applications) {
    long finishTime = ar.getFinishTime();
    if (finishTime < finishedBefore) {
      try {
        Path appPath = new Path(appsBasePath, ar.getApplicationId().toString());
        if (fs.isDirectory(appPath)) {
          LOG.debug("Deleting finished application data for {}", ar.getApplicationId());
          fs.delete(appPath, true);
          result.add(ar);
        }
      } catch (Exception ex) {
        LOG.warn("Cannot delete application data for {}", ar.getApplicationId(), ex);
        continue;
      }
    }
  }
  return result;
}
 
Example 2
Source Project: hadoop   Source File: TestYarnClient.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 3
Source Project: big-c   Source File: TestYarnClient.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 4
public AbstractYarnClusterDescriptor(
		Configuration flinkConfiguration,
		YarnConfiguration yarnConfiguration,
		String configurationDirectory,
		YarnClient yarnClient,
		boolean sharedYarnClient) {

	this.yarnConfiguration = Preconditions.checkNotNull(yarnConfiguration);

	// for unit tests only
	if (System.getenv("IN_TESTS") != null) {
		try {
			yarnConfiguration.addResource(new File(System.getenv("YARN_CONF_DIR"), "yarn-site.xml").toURI().toURL());
		} catch (Throwable t) {
			throw new RuntimeException("Error", t);
		}
	}

	this.yarnClient = Preconditions.checkNotNull(yarnClient);
	this.sharedYarnClient = sharedYarnClient;

	this.flinkConfiguration = Preconditions.checkNotNull(flinkConfiguration);
	userJarInclusion = getUserJarInclusionMode(flinkConfiguration);

	this.configurationDirectory = Preconditions.checkNotNull(configurationDirectory);
}
 
Example 5
Source Project: hadoop   Source File: TestClusterCLI.java    License: Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example 6
Source Project: big-c   Source File: TestYarnClient.java    License: Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 7
Source Project: hadoop   Source File: LogsCLI.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 8
Source Project: big-c   Source File: TestClusterCLI.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEmptyClusterNodeLabels() throws Exception {
  YarnClient client = mock(YarnClient.class);
  when(client.getClusterNodeLabels()).thenReturn(new HashSet<String>());
  ClusterCLI cli = new ClusterCLI();
  cli.setClient(client);
  cli.setSysOutPrintStream(sysOut);
  cli.setSysErrPrintStream(sysErr);

  int rc =
      cli.run(new String[] { ClusterCLI.CMD, "-" + ClusterCLI.LIST_LABELS_CMD });
  assertEquals(0, rc);

  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  PrintWriter pw = new PrintWriter(baos);
  pw.print("Node Labels: ");
  pw.close();
  verify(sysOut).println(baos.toString("UTF-8"));
}
 
Example 9
Source Project: twill   Source File: Hadoop21YarnAppClient.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Adds RM delegation token to the given {@link ContainerLaunchContext} so that the AM can authenticate itself
 * with RM using the delegation token.
 */
protected void addRMToken(ContainerLaunchContext context, YarnClient yarnClient, ApplicationId appId) {
  if (!UserGroupInformation.isSecurityEnabled()) {
    return;
  }

  try {
    Credentials credentials = YarnUtils.decodeCredentials(context.getTokens());

    Configuration config = yarnClient.getConfig();
    Token<TokenIdentifier> token = ConverterUtils.convertFromYarn(
      yarnClient.getRMDelegationToken(new Text(YarnUtils.getYarnTokenRenewer(config))),
      YarnUtils.getRMAddress(config));

    LOG.debug("Added RM delegation token {} for application {}", token, appId);
    credentials.addToken(token.getService(), token);

    context.setTokens(YarnUtils.encodeCredentials(credentials));
  } catch (YarnException | IOException e) {
    throw new RuntimeException("Failed to acquire RM delegation token", e);
  }
}
 
Example 10
Source Project: big-c   Source File: TestLogsCLI.java    License: Apache License 2.0 6 votes vote down vote up
@Test(timeout = 5000l)
public void testFailResultCodes() throws Exception {
  Configuration conf = new YarnConfiguration();
  conf.setClass("fs.file.impl", LocalFileSystem.class, FileSystem.class);
  LogCLIHelpers cliHelper = new LogCLIHelpers();
  cliHelper.setConf(conf);
  YarnClient mockYarnClient = createMockYarnClient(YarnApplicationState.FINISHED);
  LogsCLI dumper = new LogsCLIForTest(mockYarnClient);
  dumper.setConf(conf);
  
  // verify dumping a non-existent application's logs returns a failure code
  int exitCode = dumper.run( new String[] {
      "-applicationId", "application_0_0" } );
  assertTrue("Should return an error code", exitCode != 0);
  
  // verify dumping a non-existent container log is a failure code 
  exitCode = cliHelper.dumpAContainersLogs("application_0_0", "container_0_0",
      "nonexistentnode:1234", "nobody");
  assertTrue("Should return an error code", exitCode != 0);
}
 
Example 11
Source Project: sylph   Source File: YarnModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public YarnClient get()
{
    YarnClient client = YarnClient.createYarnClient();
    if (yarnConfiguration.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, false)) {
        try {
            TimelineClient.createTimelineClient();
        }
        catch (NoClassDefFoundError e) {
            logger.warn("createTimelineClient() error with {}", TimelineClient.class.getResource(TimelineClient.class.getSimpleName() + ".class"), e);
            yarnConfiguration.setBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, false);
        }
    }
    client.init(yarnConfiguration);
    client.start();
    return client;
}
 
Example 12
Source Project: sylph   Source File: YarnJobDescriptor.java    License: Apache License 2.0 6 votes vote down vote up
YarnJobDescriptor(
        YarnClientApplication application,
        FlinkConfiguration flinkConf,
        YarnClient yarnClient,
        YarnConfiguration yarnConfiguration,
        FlinkJobConfig appConf,
        String jobId,
        Iterable<Path> userProvidedJars)
        throws IOException
{
    super(flinkConf.flinkConfiguration(), yarnConfiguration, flinkConf.getConfigurationDirectory(), yarnClient, false);
    this.application = application;
    this.jobName = jobId;
    this.flinkConf = flinkConf;
    this.yarnClient = yarnClient;
    this.appConf = appConf;
    this.userProvidedJars = userProvidedJars;

    FileSystem fileSystem = FileSystem.get(yarnClient.getConfig());
    this.uploadingDir = new Path(new Path(fileSystem.getHomeDirectory(), ".sylph"), application.getApplicationSubmissionContext().getApplicationId().toString());
}
 
Example 13
Source Project: AthenaX   Source File: InstanceManagerTest.java    License: Apache License 2.0 6 votes vote down vote up
@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));
  }
}
 
Example 14
Source Project: hadoop   Source File: TestLogsCLI.java    License: Apache License 2.0 6 votes vote down vote up
@Test(timeout = 5000l)
public void testFailResultCodes() throws Exception {
  Configuration conf = new YarnConfiguration();
  conf.setClass("fs.file.impl", LocalFileSystem.class, FileSystem.class);
  LogCLIHelpers cliHelper = new LogCLIHelpers();
  cliHelper.setConf(conf);
  YarnClient mockYarnClient = createMockYarnClient(YarnApplicationState.FINISHED);
  LogsCLI dumper = new LogsCLIForTest(mockYarnClient);
  dumper.setConf(conf);
  
  // verify dumping a non-existent application's logs returns a failure code
  int exitCode = dumper.run( new String[] {
      "-applicationId", "application_0_0" } );
  assertTrue("Should return an error code", exitCode != 0);
  
  // verify dumping a non-existent container log is a failure code 
  exitCode = cliHelper.dumpAContainersLogs("application_0_0", "container_0_0",
      "nonexistentnode:1234", "nobody");
  assertTrue("Should return an error code", exitCode != 0);
}
 
Example 15
Source Project: hadoop   Source File: TestLogsCLI.java    License: Apache License 2.0 5 votes vote down vote up
private YarnClient createMockYarnClientUnknownApp() throws YarnException,
    IOException {
  YarnClient mockClient = mock(YarnClient.class);
  doThrow(new YarnException("Unknown AppId")).when(mockClient)
      .getApplicationReport(any(ApplicationId.class));
  return mockClient;
}
 
Example 16
Source Project: big-c   Source File: TestRemoteAppChecker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates/initializes/starts a RemoteAppChecker with a spied
 * DummyYarnClientImpl.
 * 
 * @return the spied DummyYarnClientImpl in the created AppChecker
 */
private YarnClient createCheckerWithMockedClient() {
  YarnClient client = spy(new DummyYarnClientImpl());
  checker = new RemoteAppChecker(client);
  checker.init(new Configuration());
  checker.start();
  return client;
}
 
Example 17
Source Project: yarn-proto   Source File: SolrClient.java    License: Apache License 2.0 5 votes vote down vote up
protected void logYarnDiagnostics(YarnClient yarnClient) throws IOException, YarnException {
  YarnClusterMetrics clusterMetrics = yarnClient.getYarnClusterMetrics();
  log.info("Got Cluster metric info from ASM" + ", numNodeManagers="
          + clusterMetrics.getNumNodeManagers());

  List<NodeReport> clusterNodeReports = yarnClient.getNodeReports();
  log.info("Got Cluster node info from ASM");
  for (NodeReport node : clusterNodeReports) {
    log.info("Got node report from ASM for" + ", nodeId="
            + node.getNodeId() + ", nodeAddress"
            + node.getHttpAddress() + ", nodeRackName"
            + node.getRackName() + ", nodeNumContainers"
            + node.getNumContainers());
  }

  QueueInfo queueInfo = yarnClient.getQueueInfo("default");
  log.info("Queue info" + ", queueName=" + queueInfo.getQueueName()
          + ", queueCurrentCapacity=" + queueInfo.getCurrentCapacity()
          + ", queueMaxCapacity=" + queueInfo.getMaximumCapacity()
          + ", queueApplicationCount="
          + queueInfo.getApplications().size()
          + ", queueChildQueueCount=" + queueInfo.getChildQueues().size());

  List<QueueUserACLInfo> listAclInfo = yarnClient.getQueueAclsInfo();
  for (QueueUserACLInfo aclInfo : listAclInfo) {
    for (QueueACL userAcl : aclInfo.getUserAcls()) {
      log.info("User ACL Info for Queue" + ", queueName="
              + aclInfo.getQueueName() + ", userAcl="
              + userAcl.name());
    }
  }
}
 
Example 18
/**
 * Kills YARN application and stops YARN client.
 *
 * <p>Use this method to kill the App before it has been properly deployed
 */
private void failSessionDuringDeployment(YarnClient yarnClient, YarnClientApplication yarnApplication) {
	LOG.info("Killing YARN application");

	try {
		yarnClient.killApplication(yarnApplication.getNewApplicationResponse().getApplicationId());
	} catch (Exception e) {
		// we only log a debug message here because the "killApplication" call is a best-effort
		// call (we don't know if the application has been deployed when the error occured).
		LOG.debug("Error while killing YARN application", e);
	}
	yarnClient.stop();
}
 
Example 19
Source Project: Flink-CEPplus   Source File: YarnClusterDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
public YarnClusterDescriptor(
		Configuration flinkConfiguration,
		YarnConfiguration yarnConfiguration,
		String configurationDirectory,
		YarnClient yarnClient,
		boolean sharedYarnClient) {
	super(
		flinkConfiguration,
		yarnConfiguration,
		configurationDirectory,
		yarnClient,
		sharedYarnClient);
}
 
Example 20
Source Project: flink   Source File: YARNHighAvailabilityITCase.java    License: Apache License 2.0 5 votes vote down vote up
private void waitForApplicationAttempt(final ApplicationId applicationId, final int attemptId) throws Exception {
	final YarnClient yarnClient = getYarnClient();
	checkState(yarnClient != null, "yarnClient must be initialized");

	CommonTestUtils.waitUntilCondition(() -> {
		final ApplicationReport applicationReport = yarnClient.getApplicationReport(applicationId);
		return applicationReport.getCurrentApplicationAttemptId().getAttemptId() >= attemptId;
	}, Deadline.fromNow(TIMEOUT));
}
 
Example 21
Source Project: jstorm   Source File: JstormOnYarn.java    License: Apache License 2.0 5 votes vote down vote up
JstormOnYarn(String appMasterMainClass, Configuration conf) {
    this.jstormClientContext.conf = conf;
    this.appMasterMainClass = appMasterMainClass;
    jstormClientContext.yarnClient = YarnClient.createYarnClient();
    jstormClientContext.yarnClient.init(conf);
    jstormClientContext.opts = JstormYarnUtils.initClientOptions();
}
 
Example 22
Source Project: big-c   Source File: ResourceMgrDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Delegate responsible for communicating with the Resource Manager's
 * {@link ApplicationClientProtocol}.
 * @param conf the configuration object.
 */
public ResourceMgrDelegate(YarnConfiguration conf) {
  super(ResourceMgrDelegate.class.getName());
  this.conf = conf;
  this.client = YarnClient.createYarnClient();
  init(conf);
  start();
}
 
Example 23
Source Project: Flink-CEPplus   Source File: CliFrontendRunWithYarnTest.java    License: Apache License 2.0 5 votes vote down vote up
NonDeployingDetachedYarnClusterDescriptor(
	Configuration flinkConfiguration,
	YarnConfiguration yarnConfiguration, String configurationDirectory,
	YarnClient yarnClient,
	ClusterClient<ApplicationId> clusterClient) {
	super(flinkConfiguration, yarnConfiguration, configurationDirectory, yarnClient,
		clusterClient);
}
 
Example 24
Source Project: hadoop   Source File: TestYarnClient.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 25
public NonDeployingYarnClusterDescriptor(
		Configuration flinkConfiguration,
		YarnConfiguration yarnConfiguration,
		String configurationDirectory,
		YarnClient yarnClient,
		ClusterClient<ApplicationId> clusterClient) {
	super(flinkConfiguration, yarnConfiguration, configurationDirectory, yarnClient, true);

	//noinspection unchecked
	this.clusterClient = Preconditions.checkNotNull(clusterClient);
}
 
Example 26
Source Project: tez   Source File: TestTezJobs.java    License: Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testInvalidQueueSubmission() throws Exception {

  TezConfiguration tezConf = new TezConfiguration(mrrTezCluster.getConfig());
  YarnClient yarnClient = YarnClient.createYarnClient();
  try {

    yarnClient.init(mrrTezCluster.getConfig());
    yarnClient.start();

    SimpleSessionExample job = new SimpleSessionExample();
    tezConf.setBoolean(TezConfiguration.TEZ_AM_SESSION_MODE, false);
    tezConf.set(TezConfiguration.TEZ_QUEUE_NAME, "nonexistent");

    String[] inputPaths = new String[1];
    String[] outputPaths = new String[1];
    String inputDirStr = "/tmp/owc-input";
    inputPaths[0] = inputDirStr;
    Path inputDir = new Path(inputDirStr);
    remoteFs.mkdirs(inputDir);
    String outputDirStr = "/tmp/owc-output";
    outputPaths[0] = outputDirStr;
    int result = job.run(tezConf, new String[] { StringUtils.join(",", inputPaths),
        StringUtils.join(",", outputPaths), "2" }, null);
    Assert.assertTrue("Job should have failed", result != 0);
  } catch (TezException e) {
    Assert.assertTrue(e.getMessage().contains("Failed to submit application"));
  } finally {
    if (yarnClient != null) {
      yarnClient.stop();
    }
  }
}
 
Example 27
Source Project: flink   Source File: YarnClusterDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
public YarnClusterDescriptor(
		Configuration flinkConfiguration,
		YarnConfiguration yarnConfiguration,
		String configurationDirectory,
		YarnClient yarnClient,
		boolean sharedYarnClient) {
	super(
		flinkConfiguration,
		yarnConfiguration,
		configurationDirectory,
		yarnClient,
		sharedYarnClient);
}
 
Example 28
Source Project: hadoop   Source File: TestLogsCLI.java    License: Apache License 2.0 5 votes vote down vote up
@Test(timeout = 5000l)
public void testInvalidApplicationId() throws Exception {
  Configuration conf = new YarnConfiguration();
  YarnClient mockYarnClient = createMockYarnClient(YarnApplicationState.FINISHED);
  LogsCLI cli = new LogsCLIForTest(mockYarnClient);
  cli.setConf(conf);
  
  int exitCode = cli.run( new String[] { "-applicationId", "not_an_app_id"});
  assertTrue(exitCode == -1);
  assertTrue(sysErrStream.toString().startsWith("Invalid ApplicationId specified"));
}
 
Example 29
Source Project: twill   Source File: Hadoop21YarnAppClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void cancel() {
  YarnClient yarnClient = createYarnClient();
  try {
    yarnClient.killApplication(appId);
  } catch (YarnException | IOException e) {
    throw new RuntimeException("Failed to kill application " + appId, e);
  } finally {
    yarnClient.stop();
  }
}
 
Example 30
Source Project: flink   Source File: YarnTestBase.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setupYarnClient() {
	if (yarnClient == null) {
		yarnClient = YarnClient.createYarnClient();
		yarnClient.init(getYarnConfiguration());
		yarnClient.start();
	}

	flinkConfiguration = new org.apache.flink.configuration.Configuration(globalConfiguration);
}