Example usage for org.apache.hadoop.util Shell getSymlinkCommand

List of usage examples for org.apache.hadoop.util Shell getSymlinkCommand

Introduction

In this page you can find the example usage for org.apache.hadoop.util Shell getSymlinkCommand.

Prototype

public static String[] getSymlinkCommand(String target, String link) 

Source Link

Document

Return a command to create symbolic links.

Usage

From source file:org.apache.solr.hadoop.hack.MiniYARNCluster.java

License:Apache License

/**
 * @param testName name of the test/* w w w.  jav a2s. com*/
 * @param noOfNodeManagers the number of node managers in the cluster
 * @param numLocalDirs the number of nm-local-dirs per nodemanager
 * @param numLogDirs the number of nm-log-dirs per nodemanager
 */
public MiniYARNCluster(String testName, int noOfNodeManagers, int numLocalDirs, int numLogDirs,
        File testWorkDir) {
    super(testName.replace("$", ""));
    this.numLocalDirs = numLocalDirs;
    this.numLogDirs = numLogDirs;
    String testSubDir = testName.replace("$", "");
    File targetWorkDir = new File(testWorkDir, testSubDir);
    try {
        FileContext.getLocalFSFileContext().delete(new Path(targetWorkDir.getAbsolutePath()), true);
    } catch (Exception e) {
        LOG.warn("COULD NOT CLEANUP", e);
        throw new YarnRuntimeException("could not cleanup test dir: " + e, e);
    }

    if (Shell.WINDOWS) {
        // The test working directory can exceed the maximum path length supported
        // by some Windows APIs and cmd.exe (260 characters).  To work around this,
        // create a symlink in temporary storage with a much shorter path,
        // targeting the full path to the test working directory.  Then, use the
        // symlink as the test working directory.
        String targetPath = targetWorkDir.getAbsolutePath();
        File link = new File(System.getProperty("java.io.tmpdir"), String.valueOf(System.currentTimeMillis()));
        String linkPath = link.getAbsolutePath();

        try {
            FileContext.getLocalFSFileContext().delete(new Path(linkPath), true);
        } catch (IOException e) {
            throw new YarnRuntimeException("could not cleanup symlink: " + linkPath, e);
        }

        // Guarantee target exists before creating symlink.
        targetWorkDir.mkdirs();

        ShellCommandExecutor shexec = new ShellCommandExecutor(Shell.getSymlinkCommand(targetPath, linkPath));
        try {
            shexec.execute();
        } catch (IOException e) {
            throw new YarnRuntimeException(
                    String.format(Locale.ENGLISH, "failed to create symlink from %s to %s, shell output: %s",
                            linkPath, targetPath, shexec.getOutput()),
                    e);
        }

        this.testWorkDir = link;
    } else {
        this.testWorkDir = targetWorkDir;
    }

    resourceManagerWrapper = new ResourceManagerWrapper();
    addService(resourceManagerWrapper);
    nodeManagers = new CustomNodeManager[noOfNodeManagers];
    for (int index = 0; index < noOfNodeManagers; index++) {
        addService(new NodeManagerWrapper(index));
        nodeManagers[index] = new CustomNodeManager();
    }
}

From source file:org.apache.tez.service.MiniTezTestServiceCluster.java

License:Apache License

private MiniTezTestServiceCluster(String clusterName, int numExecutorsPerService, long availableMemory,
        int numLocalDirs) {
    super(clusterName + "_TezTestServerCluster");
    Preconditions.checkArgument(numExecutorsPerService > 0);
    Preconditions.checkArgument(availableMemory > 0);
    Preconditions.checkArgument(numLocalDirs > 0);
    String clusterNameTrimmed = clusterName.replace("$", "") + "_TezTestServerCluster";
    File targetWorkDir = new File("target", clusterNameTrimmed);
    try {/*  w  ww . j  ava  2s  . co  m*/
        FileContext.getLocalFSFileContext().delete(new Path(targetWorkDir.getAbsolutePath()), true);
    } catch (Exception e) {
        LOG.warn("Could not cleanup test workDir: " + targetWorkDir, e);
        throw new RuntimeException("Could not cleanup test workDir: " + targetWorkDir, e);
    }

    if (Shell.WINDOWS) {
        // The test working directory can exceed the maximum path length supported
        // by some Windows APIs and cmd.exe (260 characters).  To work around this,
        // create a symlink in temporary storage with a much shorter path,
        // targeting the full path to the test working directory.  Then, use the
        // symlink as the test working directory.
        String targetPath = targetWorkDir.getAbsolutePath();
        File link = new File(System.getProperty("java.io.tmpdir"), String.valueOf(System.currentTimeMillis()));
        String linkPath = link.getAbsolutePath();

        try {
            FileContext.getLocalFSFileContext().delete(new Path(linkPath), true);
        } catch (IOException e) {
            throw new YarnRuntimeException("could not cleanup symlink: " + linkPath, e);
        }

        // Guarantee target exists before creating symlink.
        targetWorkDir.mkdirs();

        Shell.ShellCommandExecutor shexec = new Shell.ShellCommandExecutor(
                Shell.getSymlinkCommand(targetPath, linkPath));
        try {
            shexec.execute();
        } catch (IOException e) {
            throw new YarnRuntimeException(
                    String.format("failed to create symlink from %s to %s, shell output: %s", linkPath,
                            targetPath, shexec.getOutput()),
                    e);
        }

        this.testWorkDir = link;
    } else {
        this.testWorkDir = targetWorkDir;
    }
    this.numExecutorsPerService = numExecutorsPerService;
    this.availableMemory = availableMemory;

    // Setup Local Dirs
    localDirs = new String[numLocalDirs];
    for (int i = 0; i < numLocalDirs; i++) {
        File f = new File(testWorkDir, "localDir");
        f.mkdirs();
        LOG.info("Created localDir: " + f.getAbsolutePath());
        localDirs[i] = f.getAbsolutePath();
    }
}

From source file:oz.hadoop.yarn.test.cluster.MiniYarnCluster.java

License:Apache License

/**
 *
 * @param clusterName// ww w . jav  a2  s.co  m
 */
private void prepareScriptExecutionEnv(String clusterName) {
    String testSubDir = clusterName.replace("$", "");
    File targetWorkDir = new File("target", testSubDir);
    try {
        FileContext.getLocalFSFileContext().delete(new Path(targetWorkDir.getAbsolutePath()), true);
    } catch (Exception e) {
        logger.warn("COULD NOT CLEANUP", e);
        throw new YarnRuntimeException("could not cleanup test dir: " + e, e);
    }
    if (Shell.WINDOWS) {
        // The test working directory can exceed the maximum path length
        // supported
        // by some Windows APIs and cmd.exe (260 characters). To work around
        // this,
        // create a symlink in temporary storage with a much shorter path,
        // targeting the full path to the test working directory. Then, use
        // the
        // symlink as the test working directory.
        String targetPath = targetWorkDir.getAbsolutePath();
        File link = new File(System.getProperty("java.io.tmpdir"), String.valueOf(System.currentTimeMillis()));
        String linkPath = link.getAbsolutePath();

        try {
            FileContext.getLocalFSFileContext().delete(new Path(linkPath), true);
        } catch (IOException e) {
            throw new YarnRuntimeException("could not cleanup symlink: " + linkPath, e);
        }

        // Guarantee target exists before creating symlink.
        targetWorkDir.mkdirs();

        ShellCommandExecutor shexec = new ShellCommandExecutor(Shell.getSymlinkCommand(targetPath, linkPath));
        try {
            shexec.execute();
        } catch (IOException e) {
            throw new YarnRuntimeException(
                    String.format("failed to create symlink from %s to %s, shell output: %s", linkPath,
                            targetPath, shexec.getOutput()),
                    e);
        }
        this.testWorkDir = link;
    } else {
        this.testWorkDir = targetWorkDir;
    }
}