org.apache.hadoop.fs.shell.PathData Java Examples

The following examples show how to use org.apache.hadoop.fs.shell.PathData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestAnd.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testStopSecond() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.PASS);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.STOP);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.STOP, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verify(second).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #2
Source File: TestAnd.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testFailBoth() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.FAIL);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.FAIL);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.FAIL, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #3
Source File: TestAnd.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testFailFirst() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.FAIL);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.PASS);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.FAIL, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #4
Source File: TestAnd.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testFailSecond() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.PASS);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.FAIL);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.FAIL, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verify(second).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #5
Source File: TestAnd.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testPass() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.PASS);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.PASS);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.PASS, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verify(second).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #6
Source File: TestFsShellReturnCode.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Tests valid and invalid group arguments to chgrp.
 */
@Test
public void testChgrpGroupValidity() {
  // This test only covers argument parsing, so override to skip processing.
  FsCommand chgrp = new FsShellPermissions.Chgrp() {
    @Override
    protected void processArgument(PathData item) {
    }
  };
  chgrp.setConf(new Configuration());

  // The following are valid (no exception expected).
  chgrp.run("group", "/path");

  // The following are valid only on Windows.
  assertValidArgumentsOnWindows(chgrp, "Group With Spaces", "/path");

  // The following are invalid (exception expected).
  assertIllegalArguments(chgrp, ":gr#oup", "/path");
  assertIllegalArguments(chgrp, ":gr%oup", "/path");
}
 
Example #7
Source File: FsShellPermissions.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void processPath(PathData item) throws IOException {
  //Should we do case insensitive match?
  String newOwner = (owner == null || owner.equals(item.stat.getOwner())) ?
                    null : owner;
  String newGroup = (group == null || group.equals(item.stat.getGroup())) ?
                    null : group;

  if (newOwner != null || newGroup != null) {
    try {
      item.fs.setOwner(item.path, newOwner, newGroup);
    } catch (IOException e) {
      LOG.debug("Error changing ownership of " + item, e);
      throw new IOException(
          "changing ownership of '" + item + "': " + e.getMessage());
    }
  }
}
 
Example #8
Source File: TestFsShellReturnCode.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Tests valid and invalid group arguments to chgrp.
 */
@Test
public void testChgrpGroupValidity() {
  // This test only covers argument parsing, so override to skip processing.
  FsCommand chgrp = new FsShellPermissions.Chgrp() {
    @Override
    protected void processArgument(PathData item) {
    }
  };
  chgrp.setConf(new Configuration());

  // The following are valid (no exception expected).
  chgrp.run("group", "/path");

  // The following are valid only on Windows.
  assertValidArgumentsOnWindows(chgrp, "Group With Spaces", "/path");

  // The following are invalid (exception expected).
  assertIllegalArguments(chgrp, ":gr#oup", "/path");
  assertIllegalArguments(chgrp, ":gr%oup", "/path");
}
 
Example #9
Source File: TestAnd.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testFailSecond() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.PASS);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.FAIL);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.FAIL, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verify(second).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #10
Source File: TestAnd.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testStopFirst() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.STOP);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.PASS);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.STOP, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verify(second).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #11
Source File: TestAnd.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testStopFail() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.STOP);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.FAIL);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.STOP.combine(Result.FAIL), and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verify(second).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #12
Source File: TestAnd.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testFailBoth() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.FAIL);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.FAIL);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.FAIL, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #13
Source File: Find.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean isPathRecursable(PathData item) throws IOException {
  if (item.stat.isDirectory()) {
    return true;
  }
  if (item.stat.isSymlink()) {
    PathData linkedItem =
        new PathData(item.fs.resolvePath(item.stat.getSymlink()).toString(),
            getConf());
    if (linkedItem.stat.isDirectory()) {
      if (getOptions().isFollowLink()) {
        return true;
      }
      if (getOptions().isFollowArgLink() && (getDepth() == 0)) {
        return true;
      }
    }
  }
  return false;
}
 
Example #14
Source File: TestAnd.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 1000)
public void testStopFirst() throws IOException {
  And and = new And();

  PathData pathData = mock(PathData.class);

  Expression first = mock(Expression.class);
  when(first.apply(pathData, -1)).thenReturn(Result.STOP);

  Expression second = mock(Expression.class);
  when(second.apply(pathData, -1)).thenReturn(Result.PASS);

  Deque<Expression> children = new LinkedList<Expression>();
  children.add(second);
  children.add(first);
  and.addChildren(children);

  assertEquals(Result.STOP, and.apply(pathData, -1));
  verify(first).apply(pathData, -1);
  verify(second).apply(pathData, -1);
  verifyNoMoreInteractions(first);
  verifyNoMoreInteractions(second);
}
 
Example #15
Source File: TestPrint.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 1000)
public void testPrint() throws IOException {
  Print print = new Print();
  PrintStream out = mock(PrintStream.class);
  FindOptions options = new FindOptions();
  options.setOut(out);
  print.setOptions(options);

  String filename = "/one/two/test";
  PathData item = new PathData(filename, mockFs.getConf());
  assertEquals(Result.PASS, print.apply(item, -1));
  verify(out).print(filename + '\n');
  verifyNoMoreInteractions(out);
}
 
Example #16
Source File: Name.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public Result apply(PathData item, int depth) throws IOException {
  String name = getPath(item).getName();
  if (!caseSensitive) {
    name = StringUtils.toLowerCase(name);
  }
  if (globPattern.matches(name)) {
    return Result.PASS;
  } else {
    return Result.FAIL;
  }
}
 
Example #17
Source File: FilterExpression.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public Result apply(PathData item, int depth) throws IOException {
  if (expression != null) {
    return expression.apply(item, -1);
  }
  return Result.PASS;
}
 
Example #18
Source File: And.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Applies child expressions to the {@link PathData} item. If all pass then
 * returns {@link Result#PASS} else returns the result of the first
 * non-passing expression.
 */
@Override
public Result apply(PathData item, int depth) throws IOException {
  Result result = Result.PASS;
  for (Expression child : getChildren()) {
    Result childResult = child.apply(item, -1);
    result = result.combine(childResult);
    if (!result.isPass()) {
      return result;
    }
  }
  return result;
}
 
Example #19
Source File: BaseExpression.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link FileStatus} from the {@link PathData} item. If the
 * current options require links to be followed then the returned file status
 * is that of the linked file.
 *
 * @param item
 *          PathData
 * @param depth
 *          current depth in the process directories
 * @return FileStatus
 */
protected FileStatus getFileStatus(PathData item, int depth)
    throws IOException {
  FileStatus fileStatus = item.stat;
  if (fileStatus.isSymlink()) {
    if (options.isFollowLink() || (options.isFollowArgLink() &&
        (depth == 0))) {
      Path linkedFile = item.fs.resolvePath(fileStatus.getSymlink());
      fileStatus = getFileSystem(item).getFileStatus(linkedFile);
    }
  }
  return fileStatus;
}
 
Example #20
Source File: Find.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected void processArguments(LinkedList<PathData> args)
    throws IOException {
  Expression expr = getRootExpression();
  expr.setOptions(getOptions());
  expr.prepare();
  super.processArguments(args);
  expr.finish();
}
 
Example #21
Source File: Find.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void applyItem(PathData item) throws IOException {
  if (getDepth() >= getOptions().getMinDepth()) {
    Result result = getRootExpression().apply(item, getDepth());
    if (Result.STOP.equals(result)) {
      addStop(item);
    }
  }
}
 
Example #22
Source File: Find.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected void processPath(PathData item) throws IOException {
  if (getOptions().isDepthFirst()) {
    // depth first so leave until post processing
    return;
  }
  applyItem(item);
}
 
Example #23
Source File: Find.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected void recursePath(PathData item) throws IOException {
  if (isStop(item)) {
    // this item returned a stop result so don't recurse any further
    return;
  }
  if (getDepth() >= getOptions().getMaxDepth()) {
    // reached the maximum depth so don't got any further.
    return;
  }
  if (item.stat.isSymlink() && getOptions().isFollowLink()) {
    PathData linkedItem =
        new PathData(item.stat.getSymlink().toString(), getConf());
    if (isAncestor(item, linkedItem)) {
      getOptions().getErr().println(
          "Infinite loop ignored: " + item.toString() + " -> "
              + linkedItem.toString());
      return;
    }
    if (linkedItem.exists) {
      item = linkedItem;
    }
  }
  if (item.stat.isDirectory()) {
    super.recursePath(item);
  }
}
 
Example #24
Source File: Find.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected void recursePath(PathData item) throws IOException {
  if (isStop(item)) {
    // this item returned a stop result so don't recurse any further
    return;
  }
  if (getDepth() >= getOptions().getMaxDepth()) {
    // reached the maximum depth so don't got any further.
    return;
  }
  if (item.stat.isSymlink() && getOptions().isFollowLink()) {
    PathData linkedItem =
        new PathData(item.stat.getSymlink().toString(), getConf());
    if (isAncestor(item, linkedItem)) {
      getOptions().getErr().println(
          "Infinite loop ignored: " + item.toString() + " -> "
              + linkedItem.toString());
      return;
    }
    if (linkedItem.exists) {
      item = linkedItem;
    }
  }
  if (item.stat.isDirectory()) {
    super.recursePath(item);
  }
}
 
Example #25
Source File: Find.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Returns true if the target is an ancestor of the source. */
private boolean isAncestor(PathData source, PathData target) {
  for (Path parent = source.path; (parent != null) && !parent.isRoot();
      parent = parent.getParent()) {
    if (parent.equals(target.path)) {
      return true;
    }
  }
  return false;
}
 
Example #26
Source File: TestPrint.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 1000)
public void testPrint() throws IOException {
  Print print = new Print();
  PrintStream out = mock(PrintStream.class);
  FindOptions options = new FindOptions();
  options.setOut(out);
  print.setOptions(options);

  String filename = "/one/two/test";
  PathData item = new PathData(filename, mockFs.getConf());
  assertEquals(Result.PASS, print.apply(item, -1));
  verify(out).print(filename + '\n');
  verifyNoMoreInteractions(out);
}
 
Example #27
Source File: TestFind.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private PathData createPathData(String name) throws IOException {
  Path path = new Path(name);
  FileStatus fstat = mock(FileStatus.class);
  when(fstat.getPath()).thenReturn(path);
  when(fstat.toString()).thenReturn("fileStatus:" + name);

  when(mockFs.getFileStatus(eq(path))).thenReturn(fstat);
  PathData item = new PathData(path.toString(), conf);
  return item;
}
 
Example #28
Source File: Find.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Returns true if the target is an ancestor of the source. */
private boolean isAncestor(PathData source, PathData target) {
  for (Path parent = source.path; (parent != null) && !parent.isRoot();
      parent = parent.getParent()) {
    if (parent.equals(target.path)) {
      return true;
    }
  }
  return false;
}
 
Example #29
Source File: TestPrint0.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 1000)
public void testPrint() throws IOException {
  Print.Print0 print = new Print.Print0();
  PrintStream out = mock(PrintStream.class);
  FindOptions options = new FindOptions();
  options.setOut(out);
  print.setOptions(options);

  String filename = "/one/two/test";
  PathData item = new PathData(filename, mockFs.getConf());
  assertEquals(Result.PASS, print.apply(item, -1));
  verify(out).print(filename + '\0');
  verifyNoMoreInteractions(out);
}
 
Example #30
Source File: FilterExpression.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public Result apply(PathData item, int depth) throws IOException {
  if (expression != null) {
    return expression.apply(item, -1);
  }
  return Result.PASS;
}