Example usage for org.apache.hadoop.fs Path SEPARATOR

List of usage examples for org.apache.hadoop.fs Path SEPARATOR

Introduction

In this page you can find the example usage for org.apache.hadoop.fs Path SEPARATOR.

Prototype

String SEPARATOR

To view the source code for org.apache.hadoop.fs Path SEPARATOR.

Click Source Link

Document

The directory separator, a slash.

Usage

From source file:org.apache.sentry.hdfs.TestHMSPaths.java

License:Apache License

@Test
public void testRootEntry() {
    HMSPaths.Entry root = HMSPaths.Entry.createRoot(false);
    root.toString();/*from  w  ww .  j  a  va  2 s .c o  m*/
    Assert.assertNull(root.getParent());
    Assert.assertEquals(HMSPaths.EntryType.DIR, root.getType());
    Assert.assertTrue(root.getAuthzObjsSize() == 0);
    Assert.assertTrue(root.isAuthzObjsEmpty());
    // getAuthzObjs().size() is not recommended, but let's check that it works correctly
    Assert.assertTrue(root.getAuthzObjs().size() == 0);
    Assert.assertEquals(Path.SEPARATOR, root.getFullPath());
    Assert.assertFalse(root.hasChildren());
    root.delete();
    try {
        root.find(null, true);
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }
    try {
        root.find(new String[0], true);
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }
    try {
        root.find(null, false);
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }
    try {
        root.find(new String[0], false);
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }
    Assert.assertNull(root.find(new String[] { "a" }, true));
    Assert.assertNull(root.find(new String[] { "a" }, false));
    Assert.assertNull(root.findPrefixEntry(Lists.newArrayList("a")));

    root.delete();
}

From source file:org.apache.sentry.hdfs.TestHMSPaths.java

License:Apache License

@Test
public void testImmediatePrefixEntry() {
    HMSPaths.Entry root = HMSPaths.Entry.createRoot(false);
    HMSPaths.Entry entry = root.createPrefix(Lists.newArrayList("a"));
    entry.toString();/*from   w  ww .  j  a  v  a 2  s.co m*/

    Assert.assertEquals(1, root.childrenValues().size());

    Assert.assertEquals(root, entry.getParent());
    Assert.assertEquals(HMSPaths.EntryType.PREFIX, entry.getType());
    Assert.assertEquals("a", entry.getPathElement());
    Assert.assertEquals(0, entry.getAuthzObjsSize());
    Assert.assertTrue(entry.isAuthzObjsEmpty());
    // getAuthzObjs().size() is not recommended, but let's check that it works correctly
    Assert.assertEquals(0, entry.getAuthzObjs().size());
    Assert.assertEquals(Path.SEPARATOR + "a", entry.getFullPath());
    Assert.assertFalse(entry.hasChildren());

    Assert.assertEquals(entry, root.findPrefixEntry(Lists.newArrayList("a")));
    Assert.assertEquals(entry, root.findPrefixEntry(Lists.newArrayList("a", "b")));

    Assert.assertNull(root.find(new String[] { "a", "b" }, false));

    Assert.assertNull(root.find(new String[] { "b" }, false));
    Assert.assertNull(root.findPrefixEntry(Lists.newArrayList("b")));

    try {
        root.createPrefix(Lists.newArrayList("a", "b"));
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }

    try {
        root.createPrefix(Lists.newArrayList("a", "b", "c"));
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }

    entry.delete();
    Assert.assertFalse(root.hasChildren());
}

From source file:org.apache.sentry.hdfs.TestHMSPaths.java

License:Apache License

@Test
public void testFurtherPrefixEntry() {
    HMSPaths.Entry root = HMSPaths.Entry.createRoot(false);
    HMSPaths.Entry entry = root.createPrefix(Lists.newArrayList("a", "b"));
    entry.toString();//from  w ww. j av a2s.  c  om

    Assert.assertEquals(1, root.childrenValues().size());

    Assert.assertEquals(root, entry.getParent().getParent());
    Assert.assertEquals(HMSPaths.EntryType.PREFIX, entry.getType());
    Assert.assertEquals(HMSPaths.EntryType.DIR, entry.getParent().getType());
    Assert.assertEquals("b", entry.getPathElement());
    Assert.assertEquals("a", entry.getParent().getPathElement());
    Assert.assertTrue(entry.getAuthzObjsSize() == 0);
    Assert.assertTrue(entry.isAuthzObjsEmpty());
    Assert.assertTrue(entry.getParent().getAuthzObjsSize() == 0);
    // getAuthzObjs().size() is not recommended, but let's check that it works correctly
    Assert.assertTrue(entry.getAuthzObjs().size() == 0);
    Assert.assertTrue(entry.getParent().getAuthzObjs().size() == 0);
    Assert.assertEquals(Path.SEPARATOR + "a" + Path.SEPARATOR + "b", entry.getFullPath());
    Assert.assertEquals(Path.SEPARATOR + "a", entry.getParent().getFullPath());
    Assert.assertFalse(entry.hasChildren());
    Assert.assertEquals(1, entry.getParent().childrenValues().size());

    Assert.assertEquals(entry, root.findPrefixEntry(Lists.newArrayList("a", "b")));
    Assert.assertNull(root.findPrefixEntry(Lists.newArrayList("a")));

    Assert.assertNull(root.find(new String[] { "a", "b", "c" }, false));

    try {
        root.createPrefix(Lists.newArrayList("a", "b"));
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }

    try {
        root.createPrefix(Lists.newArrayList("a", "b", "c"));
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }

    entry.delete();
    Assert.assertFalse(root.hasChildren());
}

From source file:org.apache.sentry.hdfs.TestHMSPaths.java

License:Apache License

@Test
public void testImmediateAuthzEntry() {
    HMSPaths.Entry root = HMSPaths.Entry.createRoot(false);
    HMSPaths.Entry prefix = root.createPrefix(Lists.newArrayList("a", "b"));

    HMSPaths.Entry entry = root.createAuthzObjPath(Lists.newArrayList("a", "b", "p1"), "A");
    Assert.assertEquals(prefix, entry.getParent());
    Assert.assertEquals(HMSPaths.EntryType.AUTHZ_OBJECT, entry.getType());
    Assert.assertEquals("p1", entry.getPathElement());
    Assert.assertTrue(entry.getAuthzObjs().contains("A"));
    Assert.assertEquals(Path.SEPARATOR + "a" + Path.SEPARATOR + "b" + Path.SEPARATOR + "p1",
            entry.getFullPath());// w  w w .  ja v a  2 s . c o m

    try {
        root.createPrefix(Lists.newArrayList("a", "b", "p1", "c"));
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }

    Assert.assertEquals(entry, root.find(new String[] { "a", "b", "p1" }, true));
    Assert.assertEquals(entry, root.find(new String[] { "a", "b", "p1" }, false));
    Assert.assertEquals(entry, root.find(new String[] { "a", "b", "p1", "c" }, true));
    Assert.assertNull(root.find(new String[] { "a", "b", "p1", "c" }, false));
    Assert.assertEquals(prefix, root.findPrefixEntry(Lists.newArrayList("a", "b", "p1")));

    root.find(new String[] { "a", "b", "p1" }, true).delete();
    Assert.assertNull(root.find(new String[] { "a", "b", "p1" }, false));
    Assert.assertNull(root.find(new String[] { "a", "b" }, false));
    Assert.assertEquals(prefix, root.findPrefixEntry(Lists.newArrayList("a", "b", "p1")));

}

From source file:org.apache.sentry.hdfs.TestHMSPaths.java

License:Apache License

@Test
public void testFurtherAuthzEntry() {
    HMSPaths.Entry root = HMSPaths.Entry.createRoot(false);
    HMSPaths.Entry prefix = root.createPrefix(Lists.newArrayList("a", "b"));

    HMSPaths.Entry entry = root.createAuthzObjPath(Lists.newArrayList("a", "b", "t", "p1"), "A");
    Assert.assertEquals(prefix, entry.getParent().getParent());
    Assert.assertEquals(HMSPaths.EntryType.AUTHZ_OBJECT, entry.getType());
    Assert.assertEquals("p1", entry.getPathElement());
    Assert.assertTrue(entry.getAuthzObjs().contains("A"));
    Assert.assertEquals(/*from  ww  w . j  a v  a 2  s.com*/
            Path.SEPARATOR + "a" + Path.SEPARATOR + "b" + Path.SEPARATOR + "t" + Path.SEPARATOR + "p1",
            entry.getFullPath());

    try {
        root.createPrefix(Lists.newArrayList("a", "b", "p1", "t", "c"));
        Assert.fail();
    } catch (IllegalArgumentException ex) {
        //NOP
    }

    HMSPaths.Entry ep2 = root.createAuthzObjPath(Lists.newArrayList("a", "b", "t", "p1", "p2"), "A");

    Assert.assertEquals(HMSPaths.EntryType.AUTHZ_OBJECT, entry.getType());
    Assert.assertEquals("p1", entry.getPathElement());
    Assert.assertTrue(entry.getAuthzObjs().contains("A"));

    Assert.assertEquals(HMSPaths.EntryType.AUTHZ_OBJECT, ep2.getType());
    Assert.assertEquals("p2", ep2.getPathElement());
    Assert.assertTrue(entry.getAuthzObjs().contains("A"));

    Assert.assertEquals(entry, root.find(new String[] { "a", "b", "t", "p1" }, true));
    Assert.assertEquals(entry, root.find(new String[] { "a", "b", "t", "p1" }, false));
    Assert.assertEquals(entry, root.find(new String[] { "a", "b", "t", "p1", "c" }, true));
    Assert.assertNull(root.find(new String[] { "a", "b", "t", "p1", "c" }, false));
    Assert.assertEquals(prefix, root.findPrefixEntry(Lists.newArrayList("a", "b", "t", "p1")));

    Assert.assertEquals(ep2, root.find(new String[] { "a", "b", "t", "p1", "p2" }, true));
    Assert.assertEquals(ep2, root.find(new String[] { "a", "b", "t", "p1", "p2" }, false));
    Assert.assertEquals(ep2, root.find(new String[] { "a", "b", "t", "p1", "p2", "c" }, true));
    Assert.assertNull(root.find(new String[] { "a", "b", "t", "p1", "p2", "c" }, false));
    Assert.assertEquals(prefix, root.findPrefixEntry(Lists.newArrayList("a", "b", "t", "p1", "p2")));

    root.find(new String[] { "a", "b", "t", "p1" }, false).delete();

    Assert.assertNull(root.find(new String[] { "a", "b", "t", "p1" }, true));
    Assert.assertEquals(HMSPaths.EntryType.DIR, entry.getType());
    Assert.assertEquals(entry.getAuthzObjsSize(), 0);
    Assert.assertTrue(entry.isAuthzObjsEmpty());
    // getAuthzObjs().size() is not recommended, but let's check that it works correctly
    Assert.assertEquals(entry.getAuthzObjs().size(), 0);

    Assert.assertNull(root.find(new String[] { "a", "b", "t", "p1" }, false));
    Assert.assertNull(root.find(new String[] { "a", "b", "t" }, false));
    Assert.assertNull(root.find(new String[] { "a", "b" }, false));
    Assert.assertEquals(prefix, root.findPrefixEntry(Lists.newArrayList("a", "b", "t", "p1")));

    Assert.assertNotNull(root.find(new String[] { "a", "b", "t", "p1", "p2" }, false));
    root.find(new String[] { "a", "b", "t", "p1", "p2" }, false).delete();
    Assert.assertNull(root.find(new String[] { "a", "b", "t", "p1" }, false));
    Assert.assertNull(root.find(new String[] { "a", "b", "t" }, false));
    Assert.assertNull(root.find(new String[] { "a", "b" }, false));
    Assert.assertEquals(prefix, root.findPrefixEntry(Lists.newArrayList("a", "b", "t", "p1")));

}

From source file:org.apache.solr.handler.admin.ConfigSetsHandler.java

License:Apache License

private void handleConfigUploadRequest(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    String configSetName = req.getParams().get(NAME);
    if (StringUtils.isBlank(configSetName)) {
        throw new SolrException(ErrorCode.BAD_REQUEST,
                "The configuration name should be provided in the \"name\" parameter");
    }//from   w  w  w.j  av  a  2  s .c o m

    SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
    String configPathInZk = ZkConfigManager.CONFIGS_ZKNODE + Path.SEPARATOR + configSetName;

    if (zkClient.exists(configPathInZk, true)) {
        throw new SolrException(ErrorCode.BAD_REQUEST,
                "The configuration " + configSetName + " already exists in zookeeper");
    }

    Iterator<ContentStream> contentStreamsIterator = req.getContentStreams().iterator();

    if (!contentStreamsIterator.hasNext()) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "No stream found for the config data to be uploaded");
    }

    InputStream inputStream = contentStreamsIterator.next().getStream();

    // Create a node for the configuration in zookeeper
    boolean trusted = getTrusted(req);
    zkClient.makePath(configPathInZk,
            ("{\"trusted\": " + Boolean.toString(trusted) + "}").getBytes(StandardCharsets.UTF_8), true);

    ZipInputStream zis = new ZipInputStream(inputStream, StandardCharsets.UTF_8);
    ZipEntry zipEntry = null;
    while ((zipEntry = zis.getNextEntry()) != null) {
        String filePathInZk = configPathInZk + "/" + zipEntry.getName();
        if (zipEntry.isDirectory()) {
            zkClient.makePath(filePathInZk, true);
        } else {
            createZkNodeIfNotExistsAndSetData(zkClient, filePathInZk, IOUtils.toByteArray(zis));
        }
    }
    zis.close();
}

From source file:org.apache.sqoop.util.AppendUtils.java

License:Apache License

/**
 * Creates a unique path object inside the sqoop temporary directory.
 *
 * @param salt Salt that will be appended at the end of the generated directory.
 *             Can be arbitrary string, for example table name or query checksum.
 * @return a path pointing to the temporary directory
 *//*from w w  w .  ja  v  a2  s.  co  m*/
public static Path getTempAppendDir(String salt) {
    String timeId = DATE_FORM.format(new Date(System.currentTimeMillis()));
    String jvmName = ManagementFactory.getRuntimeMXBean().getName().replaceAll("@", "_");
    String tempDir = TEMP_IMPORT_ROOT + Path.SEPARATOR + timeId + "_" + jvmName + "_" + salt;
    return new Path(tempDir);
}

From source file:org.apache.storm.hdfs.bolt.TestHdfsBolt.java

License:Apache License

@Test
public void testPartitionedOutput() throws IOException {
    HdfsBolt bolt = makeHdfsBolt(hdfsURI, 1, 1000f);

    Partitioner partitoner = new Partitioner() {
        @Override/*  ww  w  .  jav  a 2 s  .c o m*/
        public String getPartitionPath(Tuple tuple) {
            return Path.SEPARATOR + tuple.getStringByField("city");
        }
    };

    bolt.prepare(new Config(), topologyContext, collector);
    bolt.withPartitioner(partitoner);

    bolt.execute(tuple1);
    bolt.execute(tuple2);

    verify(collector).ack(tuple1);
    verify(collector).ack(tuple2);

    Assert.assertEquals(1, countNonZeroLengthFiles(testRoot + "/SFO"));
    Assert.assertEquals(1, countNonZeroLengthFiles(testRoot + "/SJO"));
}

From source file:org.apache.storm.hdfs.spout.TestDirLock.java

License:Apache License

@Test
public void testConcurrentLocking() throws Exception {
    DirLockingThread[] thds = startThreads(100, locksDir);
    for (DirLockingThread thd : thds) {
        thd.join();// ww w. java2s .com
        if (!thd.cleanExit) {
            System.err.println(thd.getName() + " did not exit cleanly");
        }
        Assert.assertTrue(thd.cleanExit);
    }

    Path lockFile = new Path(locksDir + Path.SEPARATOR + DirLock.DIR_LOCK_FILE);
    Assert.assertFalse(fs.exists(lockFile));
}

From source file:org.apache.storm.hdfs.spout.TestFileLock.java

License:Apache License

@Test
public void testBasicLocking() throws Exception {
    // create empty files in filesDir
    Path file1 = new Path(filesDir + Path.SEPARATOR + "file1");
    Path file2 = new Path(filesDir + Path.SEPARATOR + "file2");
    fs.create(file1).close();/* ww w.j  a  va  2  s . c om*/
    fs.create(file2).close(); // create empty file

    // acquire lock on file1 and verify if worked
    FileLock lock1a = FileLock.tryLock(fs, file1, locksDir, "spout1");
    Assert.assertNotNull(lock1a);
    Assert.assertTrue(fs.exists(lock1a.getLockFile()));
    Assert.assertEquals(lock1a.getLockFile().getParent(), locksDir); // verify lock file location
    Assert.assertEquals(lock1a.getLockFile().getName(), file1.getName()); // verify lock filename

    // acquire another lock on file1 and verify it failed
    FileLock lock1b = FileLock.tryLock(fs, file1, locksDir, "spout1");
    Assert.assertNull(lock1b);

    // release lock on file1 and check
    lock1a.release();
    Assert.assertFalse(fs.exists(lock1a.getLockFile()));

    // Retry locking and verify
    FileLock lock1c = FileLock.tryLock(fs, file1, locksDir, "spout1");
    Assert.assertNotNull(lock1c);
    Assert.assertTrue(fs.exists(lock1c.getLockFile()));
    Assert.assertEquals(lock1c.getLockFile().getParent(), locksDir); // verify lock file location
    Assert.assertEquals(lock1c.getLockFile().getName(), file1.getName()); // verify lock filename

    // try locking another file2 at the same time
    FileLock lock2a = FileLock.tryLock(fs, file2, locksDir, "spout1");
    Assert.assertNotNull(lock2a);
    Assert.assertTrue(fs.exists(lock2a.getLockFile()));
    Assert.assertEquals(lock2a.getLockFile().getParent(), locksDir); // verify lock file location
    Assert.assertEquals(lock2a.getLockFile().getName(), file2.getName()); // verify lock filename

    // release both locks
    lock2a.release();
    Assert.assertFalse(fs.exists(lock2a.getLockFile()));
    lock1c.release();
    Assert.assertFalse(fs.exists(lock1c.getLockFile()));
}