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:probos.TestKittenUtils2.java

License:Open Source License

@Test
public void testLuaSimpleJob() throws Exception {
    String jobName = "testHostname";
    PBSJob job = UtilsForTest.getSimpleJob(jobName, "hostname");

    //test the client aspect
    LuaYarnClientParameters c1 = testJobCompilesClient(job);
    ContainerLaunchParameters clpM = c1// w ww  . java  2 s  . c  o  m
            .getApplicationMasterParameters(ApplicationId.newInstance(System.currentTimeMillis(), 1));
    assertTrue(clpM.getEnvironment().containsKey("CLASSPATH"));
    assertTrue(clpM.getEnvironment().containsKey("PBS_CONTROLLER"));
    assertTrue(clpM.getEnvironment().containsKey("PBS_JOBID"));

    //test the master aspect
    LuaApplicationMasterParameters c2 = testJobCompilesMaster(job);
    List<ContainerLaunchParameters> clpI = c2.getContainerLaunchParameters();
    for (ContainerLaunchParameters clp : clpI) {
        for (String mapped : new String[] { "PATH", "HOME", "TZ", "LANG", "MAIL", "SHELL" }) {
            if (System.getenv(mapped) != null)
                assertEquals("Bad job env for " + mapped, System.getenv(mapped),
                        clp.getEnvironment().get("PBS_O_" + mapped));
        }
        assertEquals("1", clp.getEnvironment().get("PBS_JOBID"));
        assertEquals(JobUtils.DEFAULT_QUEUE, clp.getEnvironment().get("PBS_O_QUEUE"));
        assertEquals(Utils.getHostname(), clp.getEnvironment().get("PBS_O_HOST"));
        assertEquals("PBS_BATCH", clp.getEnvironment().get("PBS_ENVIRONMENT"));
        assertEquals("1", clp.getEnvironment().get("PBS_CORES"));
        assertEquals("512", clp.getEnvironment().get("PBS_VMEM"));
        assertEquals("$(pwd)/tmp", clp.getEnvironment().get("TMP"));

        //now check that resources are generated properly
        Map<String, LocalResource> resources = clp.getLocalResources();
        assertNotNull(resources);
        assertTrue(resources.containsKey("job.SC"));
        LocalResource r = resources.get("job.SC");
        assertNotNull(r);
        //         System.err.println(r.getResource());
        //         System.err.println(resources);
    }
}

From source file:yrun.commands.Ykill.java

License:Apache License

public static void main(String[] args) throws IOException {
    YarnClient yarnClient = YarnClient.createYarnClient();
    YarnConfiguration yarnConfiguration = new YarnConfiguration();
    yarnClient.init(yarnConfiguration);/*w  ww  .j ava  2 s  . c  o m*/
    yarnClient.start();
    boolean debug = false;
    try {
        Splitter splitter = Splitter.on('_');
        for (String arg : args) {
            List<String> list = toList(splitter.split(arg));
            if (list.size() != 3) {
                System.err.println("Application Id " + arg + " is not a valid application id.");
            } else {
                String prefix = list.get(0);
                if (!prefix.equals("application")) {
                    System.err.println("Application Id " + arg + " is not a valid application id.");
                } else {
                    try {
                        long clusterTimestamp = Long.parseLong(list.get(1));
                        int id = Integer.parseInt(list.get(2));
                        ApplicationId applicationId = ApplicationId.newInstance(clusterTimestamp, id);
                        yarnClient.killApplication(applicationId);
                        System.out.println("Killed\t" + arg + "");
                    } catch (Exception e) {
                        if (debug) {
                            e.printStackTrace();
                        }
                        System.err.println("Error while trying to kill " + arg + ".");
                    }
                }
            }
        }
    } finally {
        yarnClient.stop();
        yarnClient.close();
    }
}