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 Arpit Agarwal
parent bbf711c030
commit 54be36a6d6
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"); + " 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. * 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); }.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. * Query the effective storage policy ID for the given file or directory.
* *

View File

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

View File

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

View File

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

View File

@ -749,6 +749,14 @@ public void setStoragePolicy(final Path path, final String policyName)
res.targetFileSystem.setStoragePolicy(res.remainingPath, 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. * 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); dfs.setStoragePolicy(getUriPath(path), policyName);
} }
@Override
public void unsetStoragePolicy(final Path src) throws IOException {
dfs.unsetStoragePolicy(getUriPath(src));
}
@Override @Override
public BlockStoragePolicySpi getStoragePolicy(Path src) throws IOException { public BlockStoragePolicySpi getStoragePolicy(Path src) throws IOException {
return dfs.getStoragePolicy(getUriPath(src)); return dfs.getStoragePolicy(getUriPath(src));