Example usage for org.apache.hadoop.yarn.api.records LocalResourceType ARCHIVE

List of usage examples for org.apache.hadoop.yarn.api.records LocalResourceType ARCHIVE

Introduction

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

Prototype

LocalResourceType ARCHIVE

To view the source code for org.apache.hadoop.yarn.api.records LocalResourceType ARCHIVE.

Click Source Link

Document

Archive, which is automatically unarchived by the NodeManager.

Usage

From source file:org.springframework.yarn.config.LocalresourcesNamespaceTest.java

License:Apache License

@Test
public void testGlobalDefaults() throws Exception {
    assertNotNull(resourcesWithGlobal);/*from ww  w  .jav  a2 s  .c om*/
    assertNotNull(localResourcesFactoryBeanWithGlobal);
    Configuration configuration = TestUtils.readField("configuration", localResourcesFactoryBeanWithGlobal);
    assertNotNull(configuration);

    Collection<TransferEntry> hdfsEntries = TestUtils.readField("hdfsEntries",
            localResourcesFactoryBeanWithGlobal);
    assertNotNull(hdfsEntries);
    assertThat(hdfsEntries.size(), is(1));

    TransferEntry entry = (TransferEntry) hdfsEntries.toArray()[0];
    String path = TestUtils.readField("path", entry);
    assertThat(path, is("/tmp/foo.jar"));
    LocalResourceType type = TestUtils.readField("type", entry);
    assertThat(type, is(LocalResourceType.ARCHIVE));
    LocalResourceVisibility visibility = TestUtils.readField("visibility", entry);
    assertThat(visibility, is(LocalResourceVisibility.PRIVATE));
    String local = TestUtils.readField("local", entry);
    assertThat(local, is("hdfs://0.0.0.0:9000"));
    String remote = TestUtils.readField("remote", entry);
    assertThat(remote, is("hdfs://192.168.223.139:9000"));
}

From source file:org.springframework.yarn.config.LocalresourcesNamespaceTest.java

License:Apache License

@Test
public void testGlobalLocalMixed() throws Exception {
    assertNotNull(resourcesWithMixed);/*from  w  w w . j  a  v a 2 s.  c  o m*/
    assertNotNull(localResourcesFactoryBeanWithMixed);
    Configuration configuration = TestUtils.readField("configuration", localResourcesFactoryBeanWithMixed);
    assertNotNull(configuration);

    Collection<TransferEntry> hdfsEntries = TestUtils.readField("hdfsEntries",
            localResourcesFactoryBeanWithMixed);
    assertNotNull(hdfsEntries);
    assertThat(hdfsEntries.size(), is(3));

    TransferEntry entry = (TransferEntry) hdfsEntries.toArray()[0];
    String path = TestUtils.readField("path", entry);
    assertThat(path, is("/tmp/foo.jar"));
    LocalResourceType type = TestUtils.readField("type", entry);
    assertThat(type, is(LocalResourceType.FILE));
    LocalResourceVisibility visibility = TestUtils.readField("visibility", entry);
    assertThat(visibility, is(LocalResourceVisibility.PUBLIC));
    String local = TestUtils.readField("local", entry);
    assertThat(local, is("hdfs://0.0.0.0:9001"));
    String remote = TestUtils.readField("remote", entry);
    assertThat(remote, is("hdfs://192.168.223.139:9000"));

    entry = (TransferEntry) hdfsEntries.toArray()[1];
    path = TestUtils.readField("path", entry);
    assertThat(path, is("/tmp/jee.jar"));
    type = TestUtils.readField("type", entry);
    assertThat(type, is(LocalResourceType.FILE));
    visibility = TestUtils.readField("visibility", entry);
    assertThat(visibility, is(LocalResourceVisibility.PUBLIC));
    local = TestUtils.readField("local", entry);
    assertThat(local, is("hdfs://0.0.0.0:9000"));
    remote = TestUtils.readField("remote", entry);
    assertThat(remote, is("hdfs://192.168.223.139:9001"));

    entry = (TransferEntry) hdfsEntries.toArray()[2];
    path = TestUtils.readField("path", entry);
    assertThat(path, is("/tmp/bar.jar"));
    type = TestUtils.readField("type", entry);
    assertThat(type, is(LocalResourceType.ARCHIVE));
    visibility = TestUtils.readField("visibility", entry);
    assertThat(visibility, is(LocalResourceVisibility.PRIVATE));
    local = TestUtils.readField("local", entry);
    assertThat(local, is("hdfs://0.0.0.0:9000"));
    remote = TestUtils.readField("remote", entry);
    assertThat(remote, is("hdfs://192.168.223.139:9000"));
}

From source file:org.springframework.yarn.fs.AbstractLocalResourcesSelector.java

License:Apache License

/**
 * Select internal./*  w ww  .j  a  v a  2  s  .co m*/
 *
 * @param dir the dir
 * @return the list
 * @see #select(String)
 */
protected List<Entry> selectInternal(String dir) {
    List<Entry> entries = new ArrayList<Entry>();
    for (String name : createNamesList(getPropertiesNames(), getPropertiesSuffixes())) {
        entries.add(new Entry(dir + name, null));
    }
    for (String pattern : getPatterns()) {
        entries.add(new Entry(dir + pattern, isZipArchive(pattern) ? LocalResourceType.ARCHIVE : null));
    }
    return entries;
}

From source file:org.springframework.yarn.fs.LocalResourcesSelectorTests.java

License:Apache License

@Test
public void testAddPatterns() {
    TestLocalResourcesSelector selector = new TestLocalResourcesSelector();
    selector.addPattern("foo.jar");
    selector.addPattern("foo.zip");
    List<Entry> entries = selector.select("");
    assertThat(entries, notNullValue());
    assertThat(entries.size(), is(4));//from  ww  w . j a va  2s  .  co m

    Entry entry = findEntry("application.yml", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), nullValue());

    entry = findEntry("application.properties", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), nullValue());

    entry = findEntry("foo.jar", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), nullValue());

    entry = findEntry("foo.zip", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), is(LocalResourceType.ARCHIVE));
}

From source file:org.springframework.yarn.fs.LocalResourcesSelectorTests.java

License:Apache License

@Test
public void testAddPatternsWithDir() {
    TestLocalResourcesSelector selector = new TestLocalResourcesSelector();
    selector.addPattern("foo.jar");
    selector.addPattern("foo.zip");
    List<Entry> entries = selector.select("/foo/");
    assertThat(entries, notNullValue());
    assertThat(entries.size(), is(4));//w  ww  .ja v a  2  s.c  o m

    Entry entry = findEntry("/foo/application.yml", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), nullValue());

    entry = findEntry("/foo/application.properties", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), nullValue());

    entry = findEntry("/foo/foo.jar", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), nullValue());

    entry = findEntry("/foo/foo.zip", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), is(LocalResourceType.ARCHIVE));
}

From source file:org.springframework.yarn.fs.LocalResourcesSelectorTests.java

License:Apache License

@Test
public void testChangedZipPattern() {
    TestLocalResourcesSelector selector = new TestLocalResourcesSelector();
    selector.addPattern("foo1.zip");
    selector.addPattern("foo2.zip");
    selector.setZipArchivePattern("*1.zip");
    List<Entry> entries = selector.select("");
    assertThat(entries, notNullValue());
    assertThat(entries.size(), is(4));//from   w w  w. jav  a2s  .c om

    Entry entry = findEntry("foo1.zip", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), is(LocalResourceType.ARCHIVE));

    entry = findEntry("foo2.zip", entries);
    assertThat(entry, notNullValue());
    assertThat(entry.getType(), nullValue());
}

From source file:org.starschema.hadoop.yarn.applications.distributedshell.Client.java

License:Apache License

private void addToLocalResourcesCompressed(FileSystem fs, String fileSrcPath, String fileDstPath, String appId,
        Map<String, LocalResource> localResources, String resources) throws IOException {
    String suffix = appName + "/" + appId + "/" + fileDstPath;
    Path dst = new Path(fs.getHomeDirectory(), suffix);
    if (fileSrcPath == null) {
        FSDataOutputStream ostream = null;
        try {//  w ww . j ava 2 s.c o  m
            ostream = FileSystem.create(fs, dst, new FsPermission((short) 0710));
            ostream.writeUTF(resources);
        } finally {
            IOUtils.closeQuietly(ostream);
        }
    } else {
        fs.copyFromLocalFile(new Path(fileSrcPath), dst);
    }
    FileStatus scFileStatus = fs.getFileStatus(dst);
    LocalResource scRsrc = LocalResource.newInstance(ConverterUtils.getYarnUrlFromURI(dst.toUri()),
            LocalResourceType.ARCHIVE, LocalResourceVisibility.APPLICATION, scFileStatus.getLen(),
            scFileStatus.getModificationTime());
    localResources.put(fileDstPath, scRsrc);
}

From source file:runtime.starter.MPJAppMaster.java

License:Open Source License

public void run() throws Exception {
    try {// w  w  w . jav a  2 s . co  m
        appMasterSock = new Socket(serverName, ioServerPort);

        //redirecting stdout and stderr
        System.setOut(new PrintStream(appMasterSock.getOutputStream(), true));
        System.setErr(new PrintStream(appMasterSock.getOutputStream(), true));
    } catch (Exception exp) {
        exp.printStackTrace();
    }

    FileSystem fs = FileSystem.get(conf);
    Path wrapperDest = new Path(wrapperPath);
    FileStatus destStatus = fs.getFileStatus(wrapperDest);

    Path userFileDest = new Path(userJarPath);
    FileStatus destStatusClass = fs.getFileStatus(userFileDest);

    // Initialize AM <--> RM communication protocol
    AMRMClient<ContainerRequest> rmClient = AMRMClient.createAMRMClient();
    rmClient.init(conf);
    rmClient.start();

    // Initialize AM <--> NM communication protocol
    NMClient nmClient = NMClient.createNMClient();
    nmClient.init(conf);
    nmClient.start();

    // Register with ResourceManager
    RegisterApplicationMasterResponse registerResponse = rmClient.registerApplicationMaster("", 0, "");
    // Priority for containers - priorities are intra-application
    Priority priority = Records.newRecord(Priority.class);
    priority.setPriority(mpjContainerPriority);

    maxMem = registerResponse.getMaximumResourceCapability().getMemory();

    if (debugYarn) {
        System.out.println("[MPJAppMaster]: Max memory capability resources " + "in cluster: " + maxMem);
    }

    if (containerMem > maxMem) {
        System.out.println("[MPJAppMaster]: container  memory specified above "
                + "threshold of cluster! Using maximum memory for " + "containers: " + containerMem);
        containerMem = maxMem;
    }

    maxCores = registerResponse.getMaximumResourceCapability().getVirtualCores();

    if (debugYarn) {
        System.out.println("[MPJAppMaster]: Max v-cores capability resources " + "in cluster: " + maxCores);
    }

    if (containerCores > maxCores) {
        System.out.println("[MPJAppMaster]: virtual cores specified above "
                + "threshold of cluster! Using maximum v-cores for " + "containers: " + containerCores);
        containerCores = maxCores;
    }

    // Resource requirements for containers
    Resource capability = Records.newRecord(Resource.class);
    capability.setMemory(containerMem);
    capability.setVirtualCores(containerCores);

    // Make container requests to ResourceManager
    for (int i = 0; i < np; ++i) {
        ContainerRequest containerReq = new ContainerRequest(capability, null, null, priority);

        rmClient.addContainerRequest(containerReq);
    }

    Map<String, LocalResource> localResources = new HashMap<String, LocalResource>();
    // Creating Local Resource for Wrapper   
    LocalResource wrapperJar = Records.newRecord(LocalResource.class);

    wrapperJar.setResource(ConverterUtils.getYarnUrlFromPath(wrapperDest));
    wrapperJar.setSize(destStatus.getLen());
    wrapperJar.setTimestamp(destStatus.getModificationTime());
    wrapperJar.setType(LocalResourceType.ARCHIVE);
    wrapperJar.setVisibility(LocalResourceVisibility.APPLICATION);

    // Creating Local Resource for UserClass
    LocalResource userClass = Records.newRecord(LocalResource.class);

    userClass.setResource(ConverterUtils.getYarnUrlFromPath(userFileDest));
    userClass.setSize(destStatusClass.getLen());
    userClass.setTimestamp(destStatusClass.getModificationTime());
    userClass.setType(LocalResourceType.ARCHIVE);
    userClass.setVisibility(LocalResourceVisibility.APPLICATION);

    localResources.put("mpj-yarn-wrapper.jar", wrapperJar);
    localResources.put("user-code.jar", userClass);

    while (allocatedContainers < np) {
        AllocateResponse response = rmClient.allocate(0);
        mpiContainers.addAll(response.getAllocatedContainers());
        allocatedContainers = mpiContainers.size();

        if (allocatedContainers != np) {
            Thread.sleep(100);
        }
    }

    if (debugYarn) {
        System.out.println("[MPJAppMaster]: launching " + allocatedContainers + " containers");
    }

    for (Container container : mpiContainers) {

        ContainerLaunchContext ctx = Records.newRecord(ContainerLaunchContext.class);

        List<String> commands = new ArrayList<String>();

        commands.add(" $JAVA_HOME/bin/java");
        commands.add(" -Xmx" + containerMem + "m");
        commands.add(" runtime.starter.MPJYarnWrapper");
        commands.add("--serverName");
        commands.add(serverName); // server name
        commands.add("--ioServerPort");
        commands.add(Integer.toString(ioServerPort)); // IO server port
        commands.add("--deviceName");
        commands.add(deviceName); // device name
        commands.add("--className");
        commands.add(className); // class name
        commands.add("--psl");
        commands.add(psl); // protocol switch limit
        commands.add("--np");
        commands.add(Integer.toString(np)); // no. of containers
        commands.add("--rank");
        commands.add(" " + Integer.toString(rank++)); // rank

        //temp sock port to share rank and ports
        commands.add("--wireUpPort");
        commands.add(wireUpPort);

        if (appArgs != null) {
            commands.add("--appArgs");
            for (int i = 0; i < appArgs.length; i++) {
                commands.add(appArgs[i]);
            }
        }

        ctx.setCommands(commands);

        // Set local resource for containers
        ctx.setLocalResources(localResources);

        // Set environment for container
        Map<String, String> containerEnv = new HashMap<String, String>();
        setupEnv(containerEnv);
        ctx.setEnvironment(containerEnv);

        // Time to start the container
        nmClient.startContainer(container, ctx);

    }

    while (completedContainers < np) {
        // argument to allocate() is the progress indicator
        AllocateResponse response = rmClient.allocate(completedContainers / np);

        for (ContainerStatus status : response.getCompletedContainersStatuses()) {
            if (debugYarn) {
                System.out.println("\n[MPJAppMaster]: Container Id - " + status.getContainerId());
                System.out.println("[MPJAppMaster]: Container State - " + status.getState().toString());
                System.out.println("[MPJAppMaster]: Container Diagnostics - " + status.getDiagnostics());

            }
            ++completedContainers;
        }

        if (completedContainers != np) {
            Thread.sleep(100);
        }
        ;
    }
    // Un-register with ResourceManager 
    rmClient.unregisterApplicationMaster(FinalApplicationStatus.SUCCEEDED, "", "");
    //shutDown AppMaster IO
    System.out.println("EXIT");
}

From source file:runtime.starter.MPJYarnClient.java

License:Open Source License

public void run() throws Exception {

    Map<String, String> map = System.getenv();

    try {/*from   w ww.ja v  a 2s.c o  m*/
        mpjHomeDir = map.get("MPJ_HOME");

        if (mpjHomeDir == null) {
            throw new Exception("[MPJRun.java]:MPJ_HOME environment found..");
        }
    } catch (Exception exc) {
        System.out.println("[MPJRun.java]:" + exc.getMessage());
        exc.printStackTrace();
        return;
    }

    // Copy the application master jar to HDFS
    // Create a local resource to point to the destination jar path
    FileSystem fs = FileSystem.get(conf);
    /*
          Path dataset = new Path(fs.getHomeDirectory(),"/dataset");
          FileStatus datasetFile = fs.getFileStatus(dataset);
                 
          BlockLocation myBlocks [] = fs.getFileBlockLocations(datasetFile,0,datasetFile.getLen());
          for(BlockLocation b : myBlocks){
            System.out.println("\n--------------------");
            System.out.println("Length "+b.getLength());
            for(String host : b.getHosts()){
              System.out.println("host "+host);
            }
          }
    */
    Path source = new Path(mpjHomeDir + "/lib/mpj-app-master.jar");
    String pathSuffix = hdfsFolder + "mpj-app-master.jar";
    Path dest = new Path(fs.getHomeDirectory(), pathSuffix);

    if (debugYarn) {
        logger.info("Uploading mpj-app-master.jar to: " + dest.toString());
    }

    fs.copyFromLocalFile(false, true, source, dest);
    FileStatus destStatus = fs.getFileStatus(dest);

    Path wrapperSource = new Path(mpjHomeDir + "/lib/mpj-yarn-wrapper.jar");
    String wrapperSuffix = hdfsFolder + "mpj-yarn-wrapper.jar";
    Path wrapperDest = new Path(fs.getHomeDirectory(), wrapperSuffix);

    if (debugYarn) {
        logger.info("Uploading mpj-yarn-wrapper.jar to: " + wrapperDest.toString());
    }

    fs.copyFromLocalFile(false, true, wrapperSource, wrapperDest);

    Path userJar = new Path(jarPath);
    String userJarSuffix = hdfsFolder + "user-code.jar";
    Path userJarDest = new Path(fs.getHomeDirectory(), userJarSuffix);

    if (debugYarn) {
        logger.info("Uploading user-code.jar to: " + userJarDest.toString());
    }

    fs.copyFromLocalFile(false, true, userJar, userJarDest);

    YarnConfiguration conf = new YarnConfiguration();
    YarnClient yarnClient = YarnClient.createYarnClient();
    yarnClient.init(conf);
    yarnClient.start();

    if (debugYarn) {
        YarnClusterMetrics metrics = yarnClient.getYarnClusterMetrics();
        logger.info("\nNodes Information");
        logger.info("Number of NM: " + metrics.getNumNodeManagers() + "\n");

        List<NodeReport> nodeReports = yarnClient.getNodeReports(NodeState.RUNNING);
        for (NodeReport n : nodeReports) {
            logger.info("NodeId: " + n.getNodeId());
            logger.info("RackName: " + n.getRackName());
            logger.info("Total Memory: " + n.getCapability().getMemory());
            logger.info("Used Memory: " + n.getUsed().getMemory());
            logger.info("Total vCores: " + n.getCapability().getVirtualCores());
            logger.info("Used vCores: " + n.getUsed().getVirtualCores() + "\n");
        }
    }

    logger.info("Creating server socket at HOST " + serverName + " PORT " + serverPort + " \nWaiting for " + np
            + " processes to connect...");

    // Creating a server socket for incoming connections
    try {
        servSock = new ServerSocket(serverPort);
        infoSock = new ServerSocket();
        TEMP_PORT = findPort(infoSock);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Create application via yarnClient
    YarnClientApplication app = yarnClient.createApplication();
    GetNewApplicationResponse appResponse = app.getNewApplicationResponse();

    int maxMem = appResponse.getMaximumResourceCapability().getMemory();

    if (debugYarn) {
        logger.info("Max memory capability resources in cluster: " + maxMem);
    }

    if (amMem > maxMem) {
        amMem = maxMem;
        logger.info("AM memory specified above threshold of cluster "
                + "Using maximum memory for AM container: " + amMem);
    }
    int maxVcores = appResponse.getMaximumResourceCapability().getVirtualCores();

    if (debugYarn) {
        logger.info("Max vCores capability resources in cluster: " + maxVcores);
    }

    if (amCores > maxVcores) {
        amCores = maxVcores;
        logger.info("AM virtual cores specified above threshold of cluster "
                + "Using maximum virtual cores for AM container: " + amCores);
    }

    // Set up the container launch context for the application master
    ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);

    List<String> commands = new ArrayList<String>();
    commands.add("$JAVA_HOME/bin/java");
    commands.add("-Xmx" + amMem + "m");
    commands.add("runtime.starter.MPJAppMaster");
    commands.add("--np");
    commands.add(String.valueOf(np));
    commands.add("--serverName");
    commands.add(serverName); //server name
    commands.add("--ioServerPort");
    commands.add(Integer.toString(serverPort)); //server port
    commands.add("--deviceName");
    commands.add(deviceName); //device name
    commands.add("--className");
    commands.add(className); //class name
    commands.add("--wdir");
    commands.add(workingDirectory); //wdir
    commands.add("--psl");
    commands.add(Integer.toString(psl)); //protocol switch limit
    commands.add("--wireUpPort");
    commands.add(String.valueOf(TEMP_PORT)); //for sharing ports & rank
    commands.add("--wrapperPath");
    commands.add(wrapperDest.toString());//MPJYarnWrapper.jar HDFS path
    commands.add("--userJarPath");
    commands.add(userJarDest.toString());//User Jar File HDFS path
    commands.add("--mpjContainerPriority");
    commands.add(mpjContainerPriority);// priority for mpj containers 
    commands.add("--containerMem");
    commands.add(containerMem);
    commands.add("--containerCores");
    commands.add(containerCores);

    if (debugYarn) {
        commands.add("--debugYarn");
    }

    if (appArgs != null) {

        commands.add("--appArgs");

        for (int i = 0; i < appArgs.length; i++) {
            commands.add(appArgs[i]);
        }
    }

    amContainer.setCommands(commands); //set commands

    // Setup local Resource for ApplicationMaster
    LocalResource appMasterJar = Records.newRecord(LocalResource.class);

    appMasterJar.setResource(ConverterUtils.getYarnUrlFromPath(dest));
    appMasterJar.setSize(destStatus.getLen());
    appMasterJar.setTimestamp(destStatus.getModificationTime());
    appMasterJar.setType(LocalResourceType.ARCHIVE);
    appMasterJar.setVisibility(LocalResourceVisibility.APPLICATION);

    amContainer.setLocalResources(Collections.singletonMap("mpj-app-master.jar", appMasterJar));

    // Setup CLASSPATH for ApplicationMaster
    // Setting up the environment
    Map<String, String> appMasterEnv = new HashMap<String, String>();
    setupAppMasterEnv(appMasterEnv);
    amContainer.setEnvironment(appMasterEnv);

    // Set up resource type requirements for ApplicationMaster
    Resource capability = Records.newRecord(Resource.class);
    capability.setMemory(amMem);
    capability.setVirtualCores(amCores);

    // Finally, set-up ApplicationSubmissionContext for the application
    ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();

    appContext.setApplicationName(appName);
    appContext.setAMContainerSpec(amContainer);
    appContext.setResource(capability);
    appContext.setQueue(yarnQueue); // queue

    Priority priority = Priority.newInstance(amPriority);
    appContext.setPriority(priority);

    ApplicationId appId = appContext.getApplicationId();

    //Adding ShutDown Hook
    Runtime.getRuntime().addShutdownHook(new KillYarnApp(appId, yarnClient));

    // Submit application
    System.out.println("Submitting Application: " + appContext.getApplicationName() + "\n");

    try {
        isRunning = true;
        yarnClient.submitApplication(appContext);
    } catch (Exception exp) {
        System.err.println("Error Submitting Application");
        exp.printStackTrace();
    }

    // np = number of processes , + 1 for Application Master container
    IOMessagesThread[] ioThreads = new IOMessagesThread[np + 1];

    peers = new String[np];
    socketList = new Vector<Socket>();
    int wport = 0;
    int rport = 0;
    int rank = 0;

    // np + 1 IOThreads
    for (int i = 0; i < (np + 1); i++) {
        try {
            sock = servSock.accept();

            //start IO thread to read STDOUT and STDERR from wrappers
            IOMessagesThread io = new IOMessagesThread(sock);
            ioThreads[i] = io;
            ioThreads[i].start();
        } catch (Exception e) {
            System.err.println("Error accepting connection from peer socket..");
            e.printStackTrace();
        }
    }

    // Loop to read port numbers from Wrapper.java processes
    // and to create WRAPPER_INFO (containing all IPs and ports)
    String WRAPPER_INFO = "#Peer Information";
    for (int i = np; i > 0; i--) {
        try {
            sock = infoSock.accept();

            DataOutputStream out = new DataOutputStream(sock.getOutputStream());
            DataInputStream in = new DataInputStream(sock.getInputStream());
            if (in.readUTF().startsWith("Sending Info")) {
                wport = in.readInt();
                rport = in.readInt();
                rank = in.readInt();
                peers[rank] = ";" + sock.getInetAddress().getHostAddress() + "@" + rport + "@" + wport + "@"
                        + rank;
                socketList.add(sock);
            }
        } catch (Exception e) {
            System.err.println("[MPJYarnClient.java]: Error accepting" + " connection from peer socket!");
            e.printStackTrace();
        }
    }

    for (int i = 0; i < np; i++) {
        WRAPPER_INFO += peers[i];
    }
    // Loop to broadcast WRAPPER_INFO to all Wrappers
    for (int i = np; i > 0; i--) {
        try {
            sock = socketList.get(np - i);
            DataOutputStream out = new DataOutputStream(sock.getOutputStream());

            out.writeUTF(WRAPPER_INFO);
            out.flush();

            sock.close();
        } catch (Exception e) {
            System.err.println("[MPJYarnClient.java]: Error closing" + " connection from peer socket..");
            e.printStackTrace();
        }
    }

    try {
        infoSock.close();
    } catch (IOException exp) {
        exp.printStackTrace();
    }

    // wait for all IO Threads to complete 
    for (int i = 0; i < (np + 1); i++) {
        ioThreads[i].join();
    }
    isRunning = true;

    System.out.println("\nApplication Statistics!");
    while (true) {
        appReport = yarnClient.getApplicationReport(appId);
        appState = appReport.getYarnApplicationState();
        fStatus = appReport.getFinalApplicationStatus();
        if (appState == YarnApplicationState.FINISHED) {
            isRunning = false;
            if (fStatus == FinalApplicationStatus.SUCCEEDED) {
                System.out.println("State: " + fStatus);
            } else {
                System.out.println("State: " + fStatus);
            }
            break;
        } else if (appState == YarnApplicationState.KILLED) {
            isRunning = false;
            System.out.println("State: " + appState);
            break;
        } else if (appState == YarnApplicationState.FAILED) {
            isRunning = false;
            System.out.println("State: " + appState);
            break;
        }
        Thread.sleep(100);
    }

    try {

        if (debugYarn) {
            logger.info("Cleaning the files from hdfs: ");
            logger.info("1) " + dest.toString());
            logger.info("2) " + wrapperDest.toString());
            logger.info("3) " + userJarDest.toString());
        }

        fs.delete(dest);
        fs.delete(wrapperDest);
        fs.delete(userJarDest);
    } catch (IOException exp) {
        exp.printStackTrace();
    }
    System.out.println("Application ID: " + appId + "\n" + "Application User: " + appReport.getUser() + "\n"
            + "RM Queue: " + appReport.getQueue() + "\n" + "Start Time: " + appReport.getStartTime() + "\n"
            + "Finish Time: " + appReport.getFinishTime());
}

From source file:yarnkit.utils.YarnUtils.java

License:Apache License

@Nonnull
public static LocalResource createLocalResource(@Nonnull FileSystem fs, @Nonnull Path hdfsPath)
        throws IOException {
    LocalResource resource = Records.newRecord(LocalResource.class);
    FileStatus fileStat = fs.getFileStatus(hdfsPath);
    resource.setResource(ConverterUtils.getYarnUrlFromPath(hdfsPath));
    resource.setSize(fileStat.getLen());
    resource.setTimestamp(fileStat.getModificationTime());
    resource.setType(fileStat.isFile() ? LocalResourceType.FILE : LocalResourceType.ARCHIVE);
    resource.setVisibility(LocalResourceVisibility.APPLICATION);
    return resource;
}