类org.apache.hadoop.fs.shell.PathData源码实例Demo

下面列出了怎么用org.apache.hadoop.fs.shell.PathData的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: FsShellPermissions.java
@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());
    }
  }
}
 
源代码2 项目: hadoop   文件: TestFsShellReturnCode.java
/**
 * 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");
}
 
源代码3 项目: hadoop   文件: TestAnd.java
@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);
}
 
源代码4 项目: hadoop   文件: TestAnd.java
@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);
}
 
源代码5 项目: hadoop   文件: TestAnd.java
@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);
}
 
源代码6 项目: big-c   文件: TestAnd.java
@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);
}
 
源代码7 项目: big-c   文件: TestAnd.java
@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);
}
 
源代码8 项目: big-c   文件: TestAnd.java
@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);
}
 
源代码9 项目: big-c   文件: Find.java
@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;
}
 
源代码10 项目: big-c   文件: TestAnd.java
@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);
}
 
源代码11 项目: big-c   文件: TestFsShellReturnCode.java
/**
 * 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");
}
 
源代码12 项目: big-c   文件: TestAnd.java
@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);
}
 
源代码13 项目: big-c   文件: TestAnd.java
@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);
}
 
源代码14 项目: big-c   文件: TestAnd.java
@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);
}
 
源代码15 项目: hadoop   文件: Find.java
/** 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;
}
 
源代码16 项目: hadoop   文件: Find.java
@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);
  }
}
 
源代码17 项目: hadoop   文件: Find.java
@Override
protected void processPath(PathData item) throws IOException {
  if (getOptions().isDepthFirst()) {
    // depth first so leave until post processing
    return;
  }
  applyItem(item);
}
 
源代码18 项目: hadoop   文件: Find.java
@Override
protected void postProcessPath(PathData item) throws IOException {
  if (!getOptions().isDepthFirst()) {
    // not depth first so already processed
    return;
  }
  applyItem(item);
}
 
源代码19 项目: hadoop   文件: Find.java
private void applyItem(PathData item) throws IOException {
  if (getDepth() >= getOptions().getMinDepth()) {
    Result result = getRootExpression().apply(item, getDepth());
    if (Result.STOP.equals(result)) {
      addStop(item);
    }
  }
}
 
源代码20 项目: hadoop   文件: Find.java
@Override
protected void processArguments(LinkedList<PathData> args)
    throws IOException {
  Expression expr = getRootExpression();
  expr.setOptions(getOptions());
  expr.prepare();
  super.processArguments(args);
  expr.finish();
}
 
源代码21 项目: big-c   文件: TestFilterExpression.java
@Test(timeout = 1000)
public void apply() throws IOException {
  PathData item = mock(PathData.class);
  when(expr.apply(item, -1)).thenReturn(Result.PASS).thenReturn(Result.FAIL);
  assertEquals(Result.PASS, test.apply(item, -1));
  assertEquals(Result.FAIL, test.apply(item, -1));
  verify(expr, times(2)).apply(item, -1);
  verifyNoMoreInteractions(expr);
}
 
源代码22 项目: hadoop   文件: And.java
/**
 * 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;
}
 
源代码23 项目: hadoop   文件: FilterExpression.java
@Override
public Result apply(PathData item, int depth) throws IOException {
  if (expression != null) {
    return expression.apply(item, -1);
  }
  return Result.PASS;
}
 
源代码24 项目: hadoop   文件: Name.java
@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;
  }
}
 
源代码25 项目: hadoop   文件: FsShellPermissions.java
@Override
protected void processPath(PathData item) throws IOException {
  short newperms = pp.applyNewPermission(item.stat);
  if (item.stat.getPermission().toShort() != newperms) {
    try {
      item.fs.setPermission(item.path, new FsPermission(newperms));
    } catch (IOException e) {
      LOG.debug("Error changing permissions of " + item, e);
      throw new IOException(
          "changing permissions of '" + item + "': " + e.getMessage());
    }
  }
}
 
源代码26 项目: hadoop   文件: TestFsShellReturnCode.java
/**
 * Tests combinations of valid and invalid user and group arguments to chown.
 */
@Test
public void testChownUserAndGroupValidity() {
  // This test only covers argument parsing, so override to skip processing.
  FsCommand chown = new FsShellPermissions.Chown() {
    @Override
    protected void processArgument(PathData item) {
    }
  };
  chown.setConf(new Configuration());

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

  // The following are valid only on Windows.
  assertValidArgumentsOnWindows(chown, "User With Spaces", "/path");
  assertValidArgumentsOnWindows(chown, "User With Spaces:group", "/path");
  assertValidArgumentsOnWindows(chown, "User With Spaces:Group With Spaces",
    "/path");
  assertValidArgumentsOnWindows(chown, "user:Group With Spaces", "/path");
  assertValidArgumentsOnWindows(chown, ":Group With Spaces", "/path");

  // The following are invalid (exception expected).
  assertIllegalArguments(chown, "us!er", "/path");
  assertIllegalArguments(chown, "us^er", "/path");
  assertIllegalArguments(chown, "user:gr#oup", "/path");
  assertIllegalArguments(chown, "user:gr%oup", "/path");
  assertIllegalArguments(chown, ":gr#oup", "/path");
  assertIllegalArguments(chown, ":gr%oup", "/path");
}
 
源代码27 项目: big-c   文件: TestPrint.java
@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);
}
 
源代码28 项目: big-c   文件: TestFind.java
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;
}
 
源代码29 项目: hadoop   文件: TestPrint.java
@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);
}
 
源代码30 项目: hadoop   文件: TestFind.java
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;
}
 
 类所在包
 同包方法