HDFS-9894. Add unsetStoragePolicy API to FileContext/AbstractFileSystem and derivatives. Contributed by Xiaobing Zhou.

(cherry picked from commit 7149cdb3c2d9dd390cd8668883cbe5db94090e0a)
This commit is contained in:
Jing Zhao 2016-04-21 18:07:35 -07:00 committed by Owen O'Malley
parent a96ea528cc
commit 5353289c8c
7 changed files with 54 additions and 1 deletions

View File

@ -1236,6 +1236,17 @@ public void setStoragePolicy(final Path path, final String policyName)
+ " doesn't support setStoragePolicy");
}
/**
* Unset the storage policy set for a given file or directory.
* @param src file or directory path.
* @throws IOException
*/
public void unsetStoragePolicy(final Path src) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support unsetStoragePolicy");
}
/**
* Retrieve the storage policy for a given file or directory.
*

View File

@ -2705,6 +2705,23 @@ public Void next(final AbstractFileSystem fs, final Path p)
}.resolve(this, absF);
}
/**
* Unset the storage policy set for a given file or directory.
* @param src file or directory path.
* @throws IOException
*/
public void unsetStoragePolicy(final Path src) throws IOException {
final Path absF = fixRelativePart(src);
new FSLinkResolver<Void>() {
@Override
public Void next(final AbstractFileSystem fs, final Path p)
throws IOException {
fs.unsetStoragePolicy(src);
return null;
}
}.resolve(this, absF);
}
/**
* Query the effective storage policy ID for the given file or directory.
*

View File

@ -2649,7 +2649,7 @@ public void setStoragePolicy(final Path src, final String policyName)
* @param src file or directory path.
* @throws IOException
*/
public void unsetStoragePolicy(Path src) throws IOException {
public void unsetStoragePolicy(final Path src) throws IOException {
throw new UnsupportedOperationException(getClass().getSimpleName()
+ " doesn't support unsetStoragePolicy");
}

View File

@ -405,6 +405,12 @@ public void setStoragePolicy(Path path, String policyName)
myFs.setStoragePolicy(path, policyName);
}
@Override
public void unsetStoragePolicy(final Path src)
throws IOException {
myFs.unsetStoragePolicy(src);
}
@Override
public BlockStoragePolicySpi getStoragePolicy(final Path src)
throws IOException {

View File

@ -385,6 +385,12 @@ public void setStoragePolicy(Path path, String policyName)
myFs.setStoragePolicy(fullPath(path), policyName);
}
@Override
public void unsetStoragePolicy(final Path src)
throws IOException {
myFs.unsetStoragePolicy(fullPath(src));
}
@Override
public BlockStoragePolicySpi getStoragePolicy(final Path src)
throws IOException {

View File

@ -749,6 +749,14 @@ public void setStoragePolicy(final Path path, final String policyName)
res.targetFileSystem.setStoragePolicy(res.remainingPath, policyName);
}
@Override
public void unsetStoragePolicy(final Path src)
throws IOException {
InodeTree.ResolveResult<AbstractFileSystem> res =
fsState.resolve(getUriPath(src), true);
res.targetFileSystem.unsetStoragePolicy(res.remainingPath);
}
/**
* Retrieve the storage policy for a given file or directory.
*

View File

@ -473,6 +473,11 @@ public void setStoragePolicy(Path path, String policyName) throws IOException {
dfs.setStoragePolicy(getUriPath(path), policyName);
}
@Override
public void unsetStoragePolicy(final Path src) throws IOException {
dfs.unsetStoragePolicy(getUriPath(src));
}
@Override
public BlockStoragePolicySpi getStoragePolicy(Path src) throws IOException {
return dfs.getStoragePolicy(getUriPath(src));