Example usage for org.apache.hadoop.yarn.api.records ApplicationId newInstance

List of usage examples for org.apache.hadoop.yarn.api.records ApplicationId newInstance

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ApplicationId newInstance.

Prototype

@Public
    @Unstable
    public static ApplicationId newInstance(long clusterTimestamp, int id) 

Source Link

Usage

From source file:org.apache.gobblin.yarn.GobblinYarnAppLauncherTest.java

License:Apache License

/**
 * Test that the dynamic config is added to the config specified when the {@link GobblinApplicationMaster}
 * is instantiated.//ww  w  .  j ava 2s .com
 */
@Test
public void testDynamicConfig() throws Exception {
    Config config = this.config.withFallback(ConfigFactory.parseMap(ImmutableMap.of(
            ConfigurationKeys.DYNAMIC_CONFIG_GENERATOR_CLASS_KEY, TestDynamicConfigGenerator.class.getName())));

    ContainerId containerId = ContainerId
            .newInstance(ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 0), 0), 0);
    TestApplicationMaster appMaster = new TestApplicationMaster("testApp", containerId, config,
            new YarnConfiguration());

    Assert.assertEquals(appMaster.getConfig().getString("dynamicKey1"), "dynamicValue1");
    Assert.assertEquals(appMaster.getConfig().getString(ConfigurationKeys.DYNAMIC_CONFIG_GENERATOR_CLASS_KEY),
            TestDynamicConfigGenerator.class.getName());

    ServiceBasedAppLauncher appLauncher = appMaster.getAppLauncher();
    Field servicesField = ServiceBasedAppLauncher.class.getDeclaredField("services");
    servicesField.setAccessible(true);

    List<Service> services = (List<Service>) servicesField.get(appLauncher);

    Optional<Service> yarnServiceOptional = services.stream().filter(e -> e instanceof YarnService).findFirst();

    Assert.assertTrue(yarnServiceOptional.isPresent());

    YarnService yarnService = (YarnService) yarnServiceOptional.get();
    Field configField = YarnService.class.getDeclaredField("config");
    configField.setAccessible(true);
    Config yarnServiceConfig = (Config) configField.get(yarnService);

    Assert.assertEquals(yarnServiceConfig.getString("dynamicKey1"), "dynamicValue1");
    Assert.assertEquals(yarnServiceConfig.getString(ConfigurationKeys.DYNAMIC_CONFIG_GENERATOR_CLASS_KEY),
            TestDynamicConfigGenerator.class.getName());
}

From source file:org.apache.gobblin.yarn.GobblinYarnAppLauncherTest.java

License:Apache License

/**
 * Test that the job cleanup call is called
 *///from ww w . j  a v  a2  s  .  c o  m
@Test
public void testJobCleanup() throws Exception {
    ContainerId containerId = ContainerId
            .newInstance(ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 0), 0), 0);
    TestApplicationMaster appMaster = Mockito
            .spy(new TestApplicationMaster("testApp", containerId, config, new YarnConfiguration()));

    GobblinHelixMultiManager mockMultiManager = Mockito.mock(GobblinHelixMultiManager.class);

    appMaster.setMultiManager(mockMultiManager);
    appMaster.start();

    Mockito.verify(mockMultiManager, times(1)).cleanUpJobs();
}

From source file:org.apache.gobblin.yarn.YarnServiceTest.java

License:Apache License

@Test(groups = { "gobblin.yarn", "disabledOnTravis" }, dependsOnMethods = "testScaleDown")
public void testReleasedContainerCache() throws Exception {
    Config modifiedConfig = this.config.withValue(
            GobblinYarnConfigurationKeys.RELEASED_CONTAINERS_CACHE_EXPIRY_SECS,
            ConfigValueFactory.fromAnyRef("2"));
    TestYarnService yarnService = new TestYarnService(modifiedConfig, "testApp1", "appId1", this.clusterConf,
            FileSystem.getLocal(new Configuration()), this.eventBus);

    ContainerId containerId1 = ContainerId
            .newInstance(ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 0), 0), 0);

    yarnService.getReleasedContainerCache().put(containerId1, "");

    Assert.assertTrue(yarnService.getReleasedContainerCache().getIfPresent(containerId1) != null);

    // give some time for element to expire
    Thread.sleep(4000);/*from w  w w . ja v a 2 s  .c o m*/
    Assert.assertTrue(yarnService.getReleasedContainerCache().getIfPresent(containerId1) == null);
}

From source file:org.apache.gobblin.yarn.YarnServiceTest.java

License:Apache License

@Test(groups = { "gobblin.yarn", "disabledOnTravis" }, dependsOnMethods = "testReleasedContainerCache")
public void testBuildContainerCommand() throws Exception {
    Config modifiedConfig = this.config
            .withValue(GobblinYarnConfigurationKeys.CONTAINER_JVM_MEMORY_OVERHEAD_MBS_KEY,
                    ConfigValueFactory.fromAnyRef("10"))
            .withValue(GobblinYarnConfigurationKeys.CONTAINER_JVM_MEMORY_XMX_RATIO_KEY,
                    ConfigValueFactory.fromAnyRef("0.8"));

    TestYarnService yarnService = new TestYarnService(modifiedConfig, "testApp2", "appId2", this.clusterConf,
            FileSystem.getLocal(new Configuration()), this.eventBus);

    ContainerId containerId = ContainerId
            .newInstance(ApplicationAttemptId.newInstance(ApplicationId.newInstance(1, 0), 0), 0);
    Resource resource = Resource.newInstance(2048, 1);
    Container container = Container.newInstance(containerId, null, null, resource, null, null);

    String command = yarnService.buildContainerCommand(container, "helixInstance1");

    // 1628 is from 2048 * 0.8 - 10
    Assert.assertTrue(command.contains("-Xmx1628"));
}

From source file:org.apache.ignite.yarn.IgniteApplicationMasterSelfTest.java

License:Apache License

/**
 * @param host Host.//from   w w w.j a v  a 2  s  . com
 * @param cpu Cpu count.
 * @param mem Memory.
 * @return Container.
 */
private Container createContainer(String host, int cpu, int mem) {
    return Container.newInstance(
            ContainerId.newContainerId(ApplicationAttemptId.newInstance(ApplicationId.newInstance(0l, 0), 0),
                    ThreadLocalRandom.current().nextLong()),
            NodeId.newInstance(host, 0), "example.com", new MockResource(mem, cpu), Priority.newInstance(0),
            null);
}

From source file:org.apache.myriad.scheduler.fgs.NMHeartBeatHandlerTest.java

License:Apache License

private ApplicationId getApplicationId(int id) {
    return ApplicationId.newInstance(System.currentTimeMillis(), id);
}

From source file:org.apache.myriad.state.MockRMApp.java

License:Apache License

public MockRMApp(int newId, long time, RMAppState state) {
    finish = time;/*from w ww  . j a  va2 s.  c  om*/
    id = ApplicationId.newInstance(System.currentTimeMillis(), newId);
    context = ApplicationSubmissionContext.newInstance(id, name, queue, Priority.newInstance(0), null, false,
            false, newId, null, applicationType);
    this.state = state;
}

From source file:org.apache.myriad.TestObjectFactory.java

License:Apache License

/**
 * Returns a new RMContainer corresponding to the RMNode and RMContext. The RMContainer is the 
 * ResourceManager's view of an application container per the Hadoop docs
 * /*w w  w  . j  a  va2  s .  c o m*/
 * @param node
 * @param context
 * @param appId
 * @param cores
 * @param memory
 * @return RMContainer
 */
public static RMContainer getRMContainer(RMNode node, RMContext context, int appId, int cores, int memory) {
    ContainerId containerId = ContainerId.newContainerId(
            ApplicationAttemptId.newInstance(ApplicationId.newInstance(123456789, 1), 1), appId);

    Container container = Container.newInstance(containerId, node.getNodeID(), node.getHttpAddress(),
            Resources.createResource(memory, cores), null, null);
    return new RMContainerImpl(container, containerId.getApplicationAttemptId(), node.getNodeID(), "user1",
            context);
}

From source file:org.apache.myriad.TestObjectFactory.java

License:Apache License

private static ApplicationId getApplicationId(int id) {
    return ApplicationId.newInstance(System.currentTimeMillis(), id);
}

From source file:org.apache.oozie.action.hadoop.TestLauncherMain.java

License:Apache License

@Test
public void testKillChildYarnJobs() throws Exception {
    YarnClient yc = Mockito.mock(YarnClient.class);
    ApplicationReport ar = Mockito.mock(ApplicationReport.class);
    Mockito.when(yc.getApplicationReport(Mockito.any(ApplicationId.class))).thenReturn(ar);

    Mockito.when(ar.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.UNDEFINED)
            .thenReturn(FinalApplicationStatus.FAILED).thenReturn(FinalApplicationStatus.KILLED);

    ApplicationId appz[] = { ApplicationId.newInstance(System.currentTimeMillis(), 1),
            ApplicationId.newInstance(System.currentTimeMillis(), 2),
            ApplicationId.newInstance(System.currentTimeMillis(), 3) };

    Collection<ApplicationId> result = LauncherMain.checkAndKillChildYarnJobs(yc, null, Arrays.asList(appz));

    assertEquals(1, result.size());/*from w w w. j a  v  a 2  s  . c  o m*/
    assertEquals(appz[0].getId(), result.iterator().next().getId());
}