From ac00d6003edf8ef92abe551f72ce801d186cfbd3 Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Wed, 8 May 2024 13:31:12 -0700 Subject: [PATCH] cavern: add QuotaPlugin API added a no-op impl to use as default augmented ExtendedFileAttributes API to include other attr namespaces but not yet implemented --- cadc-util-fs/build.gradle | 2 +- .../util/fs/ExtendedFileAttributes.java | 128 +++++++++++----- .../util/fs/ExtendedFileAttributesTest.java | 144 ++++++++++++++++++ cavern/VERSION | 2 +- .../nodes/FileSystemNodePersistence.java | 11 +- .../opencadc/cavern/nodes/NoQuotaPlugin.java | 93 +++++++++++ .../org/opencadc/cavern/nodes/NodeUtil.java | 77 ++++------ .../opencadc/cavern/nodes/QuotaPlugin.java | 95 ++++++++++++ 8 files changed, 458 insertions(+), 94 deletions(-) create mode 100644 cadc-util-fs/src/test/java/org/opencadc/util/fs/ExtendedFileAttributesTest.java create mode 100644 cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java create mode 100644 cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java diff --git a/cadc-util-fs/build.gradle b/cadc-util-fs/build.gradle index b71abd05..743dcf56 100644 --- a/cadc-util-fs/build.gradle +++ b/cadc-util-fs/build.gradle @@ -16,7 +16,7 @@ sourceCompatibility = 1.8 group = 'org.opencadc' -version = '1.1.0' +version = '1.1.1' description = 'OpenCADC file system utility library' def git_url = 'https://github.com/opencadc/vos' diff --git a/cadc-util-fs/src/main/java/org/opencadc/util/fs/ExtendedFileAttributes.java b/cadc-util-fs/src/main/java/org/opencadc/util/fs/ExtendedFileAttributes.java index a8505730..4e35aa25 100644 --- a/cadc-util-fs/src/main/java/org/opencadc/util/fs/ExtendedFileAttributes.java +++ b/cadc-util-fs/src/main/java/org/opencadc/util/fs/ExtendedFileAttributes.java @@ -90,63 +90,115 @@ public class ExtendedFileAttributes { private static final Logger log = Logger.getLogger(ExtendedFileAttributes.class); /** - * Set the attribute for the current path. If attributeValue is null, the attribute will be deleted. + * Set the attribute for the specified path. This method defaults to the "user" namespace. + * + * @param path The path where the attribute will be set. Must not be null + * @param attrName The name of the attribute to be set. Must not be null + * @param attrValue The value of the attribute to be set. A null value means the attribute is to be deleted + * + * @throws IOException if setting attribute failed + * @see #setFileAttribute(java.nio.file.Path, java.lang.String, java.lang.String, java.lang.String) + */ + public static void setFileAttribute(Path path, String attrName, String attrValue) throws IOException { + setFileAttribute(path, attrName, attrValue, null); + } + + /** + * Set an attribute on a path in the specified namespace. + * If attributeValue is null, the attribute will be deleted. + * If the specified namespace is null, it defaults to the "user" namespace. + * The specified attribyteKey should not include the namespace; the namespace will be set by this method. + * + * @param path The path where the attribute will be set. Must not be null + * @param attrName The name of the attribute to be set. Must not be null + * @param attrValue The value of the attribute to be set. A null value means the attribute is to be deleted + * @param namespace attribute namespace, null defaults to the user namespace * - * @param path The path where the attribute will be set. Must not be null. - * @param attributeKey The name of the attribute to be set. Must not be null. - * @param attributeValue The value of the attribute to be set. A null value means the attribute is to be deleted. * @throws IOException if setting attribute failed */ - public static void setFileAttribute(Path path, String attributeKey, String attributeValue) throws IOException { - if (path == null || attributeKey == null) { + public static void setFileAttribute(Path path, String attrName, String attrValue, String namespace) + throws IOException { + if (path == null || attrName == null) { throw new IllegalArgumentException("path or attributeKey cannot be null"); } - - log.debug("setFileAttribute: " + path); - UserDefinedFileAttributeView udv = Files.getFileAttributeView(path, - UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); - if (attributeValue != null) { - attributeValue = attributeValue.trim(); - log.debug("attribute: " + attributeKey + " = " + attributeValue); - ByteBuffer buf = ByteBuffer.wrap(attributeValue.getBytes(Charset.forName("UTF-8"))); - udv.write(attributeKey, buf); - } else { - try { - log.debug("attribute: " + attributeKey + " (delete)"); - udv.delete(attributeKey); - } catch (FileSystemException ex) { - log.debug("assume no such attr: " + ex); + + if (namespace == null || "user".equals(namespace)) { + log.debug("setFileAttribute: " + path); + UserDefinedFileAttributeView udv = Files.getFileAttributeView(path, + UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); + if (attrValue != null) { + attrValue = attrValue.trim(); + log.debug("attribute: " + attrName + " = " + attrValue); + ByteBuffer buf = ByteBuffer.wrap(attrValue.getBytes(Charset.forName("UTF-8"))); + udv.write(attrName, buf); + } else { + try { + log.debug("attribute: " + attrName + " (delete)"); + udv.delete(attrName); + } catch (FileSystemException ex) { + log.debug("assume no such attr: " + ex); + } } + return; } + + // TODO: support non-user space attrs by execing setfattr + String key = namespace + "." + attrName; + // setfattr -n $key -v $attrValue $path + throw new UnsupportedOperationException("attribute namespace '" + namespace + "' not supported"); } - + /** - * Get the value of specified attribute for the current path. + * Get the value of specified attribute for the current path. This method defaults to the "user" namespace. + * + * @param path The path where the attribute resides in. Must not be null + * @param attrName The name of the attribute to get. Must not be null * - * @param path The path where the attribute resides in. Must not be null. - * @param attributeName The name of the attribute to get. Must not be null. * @return attribute value or null if not set + * @throws IOException if reading attribute failed + * @see #getFileAttribute(java.nio.file.Path, java.lang.String, java.lang.String) + */ + public static String getFileAttribute(Path path, String attrName) throws IOException { + return getFileAttribute(path, attrName, null); + } + + /** + * Get the value of specified attribute for the current path from the specified attribute namespace. + * + * @param path The path where the attribute resides in. Must not be null + * @param attrName The name of the attribute to get. Must not be null + * @param namespace attribute namespace, null defaults to the user namespace + * + * @return attribute value or null if not set + * * @throws IOException if reading attribute failed */ - public static String getFileAttribute(Path path, String attributeName) throws IOException { - if (path == null || attributeName == null) { + public static String getFileAttribute(Path path, String attrName, String namespace) throws IOException { + if (path == null || attrName == null) { throw new IllegalArgumentException("path or attributeName cannot be null"); } - try { - UserDefinedFileAttributeView udv = Files.getFileAttributeView(path, - UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); + if (namespace == null || "user".equals(namespace)) { + try { + UserDefinedFileAttributeView udv = Files.getFileAttributeView(path, + UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); - int sz = udv.size(attributeName); - ByteBuffer buf = ByteBuffer.allocate(2 * sz); - udv.read(attributeName, buf); - return new String(buf.array(), Charset.forName("UTF-8")).trim(); - } catch (FileSystemException ex) { - log.debug("assume no such attr: " + ex); - return null; + int sz = udv.size(attrName); + ByteBuffer buf = ByteBuffer.allocate(2 * sz); + udv.read(attrName, buf); + return new String(buf.array(), Charset.forName("UTF-8")).trim(); + } catch (FileSystemException ex) { + log.debug("assume no such attr: " + ex); + return null; + } } + + // TODO: support non-user space attrs by execing setfattr + String key = namespace + "." + attrName; + // getfattr -n $key $path + throw new UnsupportedOperationException("attribute namespace '" + namespace + "' not supported"); } - + /** * Get all user-defined attributes. * diff --git a/cadc-util-fs/src/test/java/org/opencadc/util/fs/ExtendedFileAttributesTest.java b/cadc-util-fs/src/test/java/org/opencadc/util/fs/ExtendedFileAttributesTest.java new file mode 100644 index 00000000..ecc8e3b6 --- /dev/null +++ b/cadc-util-fs/src/test/java/org/opencadc/util/fs/ExtendedFileAttributesTest.java @@ -0,0 +1,144 @@ +/* +************************************************************************ +******************* CANADIAN ASTRONOMY DATA CENTRE ******************* +************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** +* +* (c) 2024. (c) 2024. +* Government of Canada Gouvernement du Canada +* National Research Council Conseil national de recherches +* Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 +* All rights reserved Tous droits réservés +* +* NRC disclaims any warranties, Le CNRC dénie toute garantie +* expressed, implied, or énoncée, implicite ou légale, +* statutory, of any kind with de quelque nature que ce +* respect to the software, soit, concernant le logiciel, +* including without limitation y compris sans restriction +* any warranty of merchantability toute garantie de valeur +* or fitness for a particular marchande ou de pertinence +* purpose. NRC shall not be pour un usage particulier. +* liable in any event for any Le CNRC ne pourra en aucun cas +* damages, whether direct or être tenu responsable de tout +* indirect, special or general, dommage, direct ou indirect, +* consequential or incidental, particulier ou général, +* arising from the use of the accessoire ou fortuit, résultant +* software. Neither the name de l'utilisation du logiciel. Ni +* of the National Research le nom du Conseil National de +* Council of Canada nor the Recherches du Canada ni les noms +* names of its contributors may de ses participants ne peuvent +* be used to endorse or promote être utilisés pour approuver ou +* products derived from this promouvoir les produits dérivés +* software without specific prior de ce logiciel sans autorisation +* written permission. préalable et particulière +* par écrit. +* +* This file is part of the Ce fichier fait partie du projet +* OpenCADC project. OpenCADC. +* +* OpenCADC is free software: OpenCADC est un logiciel libre ; +* you can redistribute it and/or vous pouvez le redistribuer ou le +* modify it under the terms of modifier suivant les termes de +* the GNU Affero General Public la “GNU Affero General Public +* License as published by the License” telle que publiée +* Free Software Foundation, par la Free Software Foundation +* either version 3 of the : soit la version 3 de cette +* License, or (at your option) licence, soit (à votre gré) +* any later version. toute version ultérieure. +* +* OpenCADC is distributed in the OpenCADC est distribué +* hope that it will be useful, dans l’espoir qu’il vous +* but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE +* without even the implied GARANTIE : sans même la garantie +* warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ +* or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF +* PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence +* General Public License for Générale Publique GNU Affero +* more details. pour plus de détails. +* +* You should have received Vous devriez avoir reçu une +* a copy of the GNU Affero copie de la Licence Générale +* General Public License along Publique GNU Affero avec +* with OpenCADC. If not, see OpenCADC ; si ce n’est +* . pas le cas, consultez : +* . +* +************************************************************************ +*/ + +package org.opencadc.util.fs; + +import ca.nrc.cadc.util.Log4jInit; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author pdowler + */ +public class ExtendedFileAttributesTest { + private static final Logger log = Logger.getLogger(ExtendedFileAttributesTest.class); + + static { + Log4jInit.setLevel("org.opencadc.util.fs", Level.DEBUG); + Log4jInit.setLevel("ca.nrc.cadc.exec", Level.DEBUG); + } + + static final String ROOT = "build/tmp/attr-tests"; + + static { + try { + Path root = FileSystems.getDefault().getPath(ROOT); + if (!Files.exists(root)) { + Files.createDirectory(root); + } + } catch (IOException ex) { + throw new RuntimeException("TEST SETUP: failed to create test dir: " + ROOT, ex); + } + } + + public ExtendedFileAttributesTest() { + } + + @Test + public void testSimpleAttrs() throws Exception { + Path root = FileSystems.getDefault().getPath(ROOT); + Set perms = new HashSet<>(); + perms.add(PosixFilePermission.OWNER_READ); + perms.add(PosixFilePermission.OWNER_WRITE); + perms.add(PosixFilePermission.GROUP_READ); + perms.add(PosixFilePermission.GROUP_WRITE); + perms.add(PosixFilePermission.OWNER_EXECUTE); + perms.add(PosixFilePermission.GROUP_EXECUTE); + Path target = root.resolve("simple-test"); + if (Files.exists(target, LinkOption.NOFOLLOW_LINKS)) { + Files.delete(target); + } + Files.createDirectory(target, PosixFilePermissions.asFileAttribute(perms)); + + Map attrs = ExtendedFileAttributes.getAttributes(target); + Assert.assertTrue(attrs.isEmpty()); + + log.info("** simple **"); + String key = "foo"; + String val = "foo-val"; + ExtendedFileAttributes.setFileAttribute(target, key, val); + attrs = ExtendedFileAttributes.getAttributes(target); + for (Map.Entry me : attrs.entrySet()) { + log.info(me.getKey() + " = " + me.getValue()); + } + Assert.assertEquals(1, attrs.size()); + Assert.assertEquals(val, attrs.get(key)); + } +} diff --git a/cavern/VERSION b/cavern/VERSION index 2ee2a863..adfab8ef 100644 --- a/cavern/VERSION +++ b/cavern/VERSION @@ -1,6 +1,6 @@ ## deployable containers have a semantic and build tag # semantic version tag: major.minor # build version tag: timestamp -VER=0.7.5 +VER=0.7.6 TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")" unset VER diff --git a/cavern/src/main/java/org/opencadc/cavern/nodes/FileSystemNodePersistence.java b/cavern/src/main/java/org/opencadc/cavern/nodes/FileSystemNodePersistence.java index e67c22ad..6f47a56f 100644 --- a/cavern/src/main/java/org/opencadc/cavern/nodes/FileSystemNodePersistence.java +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/FileSystemNodePersistence.java @@ -137,6 +137,7 @@ public class FileSystemNodePersistence implements NodePersistence { private final PosixIdentityManager identityManager; private final PosixMapperClient posixMapper; private final GroupCache groupCache; + private final QuotaPlugin quotaImpl = new NoQuotaPlugin(); // TODO: configurable private final ContainerNode root; private final Set allocationParents = new TreeSet<>(); @@ -285,7 +286,7 @@ public TransferGenerator getTransferGenerator() { public Node get(ContainerNode parent, String name) throws TransientException { identityManager.addToCache(AuthenticationUtil.getCurrentSubject()); try { - NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache); + NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache, quotaImpl); Node ret = nut.get(parent, name); if (ret == null) { return null; @@ -313,7 +314,7 @@ public ResourceIterator iterator(ContainerNode parent, Integer limit, Stri } try { - NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache); + NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache, quotaImpl); // this is a complicated way to get the Path LocalServiceURI loc = new LocalServiceURI(getResourceID()); VOSURI vu = loc.getURI(parent); @@ -431,7 +432,7 @@ public Node put(Node node) throws NodeNotSupportedException, TransientException } } - NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache); + NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache, quotaImpl); if (node instanceof LinkNode) { LinkNode ln = (LinkNode) node; @@ -463,7 +464,7 @@ public void move(Node node, ContainerNode dest, String newName) { throw new IllegalArgumentException("args must both be peristent nodes before move"); } - NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache); + NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache, quotaImpl); Subject caller = AuthenticationUtil.getCurrentSubject(); PosixPrincipal owner = identityManager.addToCache(caller); @@ -480,7 +481,7 @@ public void move(Node node, ContainerNode dest, String newName) { @Override public void delete(Node node) throws TransientException { - NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache); + NodeUtil nut = new NodeUtil(rootPath, rootURI, groupCache, quotaImpl); Subject caller = AuthenticationUtil.getCurrentSubject(); identityManager.addToCache(caller); try { diff --git a/cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java b/cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java new file mode 100644 index 00000000..d99feb0e --- /dev/null +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/NoQuotaPlugin.java @@ -0,0 +1,93 @@ +/* +************************************************************************ +******************* CANADIAN ASTRONOMY DATA CENTRE ******************* +************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** +* +* (c) 2024. (c) 2024. +* Government of Canada Gouvernement du Canada +* National Research Council Conseil national de recherches +* Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 +* All rights reserved Tous droits réservés +* +* NRC disclaims any warranties, Le CNRC dénie toute garantie +* expressed, implied, or énoncée, implicite ou légale, +* statutory, of any kind with de quelque nature que ce +* respect to the software, soit, concernant le logiciel, +* including without limitation y compris sans restriction +* any warranty of merchantability toute garantie de valeur +* or fitness for a particular marchande ou de pertinence +* purpose. NRC shall not be pour un usage particulier. +* liable in any event for any Le CNRC ne pourra en aucun cas +* damages, whether direct or être tenu responsable de tout +* indirect, special or general, dommage, direct ou indirect, +* consequential or incidental, particulier ou général, +* arising from the use of the accessoire ou fortuit, résultant +* software. Neither the name de l'utilisation du logiciel. Ni +* of the National Research le nom du Conseil National de +* Council of Canada nor the Recherches du Canada ni les noms +* names of its contributors may de ses participants ne peuvent +* be used to endorse or promote être utilisés pour approuver ou +* products derived from this promouvoir les produits dérivés +* software without specific prior de ce logiciel sans autorisation +* written permission. préalable et particulière +* par écrit. +* +* This file is part of the Ce fichier fait partie du projet +* OpenCADC project. OpenCADC. +* +* OpenCADC is free software: OpenCADC est un logiciel libre ; +* you can redistribute it and/or vous pouvez le redistribuer ou le +* modify it under the terms of modifier suivant les termes de +* the GNU Affero General Public la “GNU Affero General Public +* License as published by the License” telle que publiée +* Free Software Foundation, par la Free Software Foundation +* either version 3 of the : soit la version 3 de cette +* License, or (at your option) licence, soit (à votre gré) +* any later version. toute version ultérieure. +* +* OpenCADC is distributed in the OpenCADC est distribué +* hope that it will be useful, dans l’espoir qu’il vous +* but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE +* without even the implied GARANTIE : sans même la garantie +* warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ +* or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF +* PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence +* General Public License for Générale Publique GNU Affero +* more details. pour plus de détails. +* +* You should have received Vous devriez avoir reçu une +* a copy of the GNU Affero copie de la Licence Générale +* General Public License along Publique GNU Affero avec +* with OpenCADC. If not, see OpenCADC ; si ce n’est +* . pas le cas, consultez : +* . +* +************************************************************************ +*/ + +package org.opencadc.cavern.nodes; + +import java.nio.file.Path; +import org.apache.log4j.Logger; + +/** + * + * @author pdowler + */ +public class NoQuotaPlugin implements QuotaPlugin { + private static final Logger log = Logger.getLogger(NoQuotaPlugin.class); + + public NoQuotaPlugin() { + } + + @Override + public Long getQuota(Path directory) { + log.debug("getQuota: " + directory + " IGNORED"); + return null; + } + + @Override + public void setQuota(Path directory, Long quota) { + log.debug("setQuota: " + directory + " -> " + quota + " IGNORED"); + } +} diff --git a/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java b/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java index 5456a00d..1fcef78a 100644 --- a/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java @@ -72,8 +72,6 @@ import ca.nrc.cadc.io.ResourceIterator; import ca.nrc.cadc.net.ResourceAlreadyExistsException; import ca.nrc.cadc.net.ResourceNotFoundException; -import ca.nrc.cadc.reg.Standards; -import ca.nrc.cadc.reg.client.LocalAuthority; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -99,7 +97,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Set; import java.util.TreeSet; import javax.security.auth.Subject; @@ -138,18 +135,21 @@ class NodeUtil { VOS.PROPERTY_URI_GROUPREAD, VOS.PROPERTY_URI_GROUPWRITE, VOS.PROPERTY_URI_ISLOCKED, // but not supported - VOS.PROPERTY_URI_ISPUBLIC + VOS.PROPERTY_URI_ISPUBLIC, + VOS.PROPERTY_URI_QUOTA ) ); private final Path root; private final VOSURI rootURI; private final GroupCache groupCache; + private final QuotaPlugin quotaImpl; - public NodeUtil(Path root, VOSURI rootURI, GroupCache groupCache) { + public NodeUtil(Path root, VOSURI rootURI, GroupCache groupCache, QuotaPlugin quotaImpl) { this.root = root; this.rootURI = rootURI; this.groupCache = groupCache; + this.quotaImpl = quotaImpl; } /** @@ -209,7 +209,7 @@ public void put(Node node, VOSURI uri) assertNotNull("group", group); Path ret = null; - Set perms = new HashSet(); + Set perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.GROUP_READ); @@ -284,6 +284,28 @@ private void setNodeProperties(Path path, Node node) throws IOException, Interru ExtendedFileAttributes.setFileAttribute(path, prop.getKey().toASCIIString(), prop.getValue()); } } + + NodeProperty prop = node.getProperty(VOS.PROPERTY_URI_QUOTA); + if (prop != null) { + if (prop.isMarkedForDeletion()) { + quotaImpl.setQuota(path, null); + node.getProperties().remove(prop); + } else { + try { + Long quota = Long.valueOf(prop.getValue()); + quotaImpl.setQuota(path, quota); + Long actual = quotaImpl.getQuota(path); + if (actual != null) { + prop.setValue(actual.toString()); + } else { + node.getProperties().remove(prop); + } + } catch (NumberFormatException ex) { + throw new IllegalArgumentException("invalid quota: " + prop.getValue(), ex); + } + } + + } final boolean isDir = (node instanceof ContainerNode); boolean inherit = false; @@ -567,49 +589,6 @@ public void delete(VOSURI uri) throws IOException { Files.delete(p); } - /* - // magic recursive delete is obsolete - private static void delete(Path path) throws IOException { - if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) { - Files.walkFileTree(path, new DeleteVisitor()); - } else { - Files.delete(path); - } - } - - private static class DeleteVisitor implements FileVisitor { - - @Override - public FileVisitResult preVisitDirectory(Path t, - BasicFileAttributes bfa) throws IOException { - log.debug("enter: " + t); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFile(Path t, BasicFileAttributes bfa) - throws IOException { - log.debug("delete: " + t); - Files.delete(t); - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult visitFileFailed(Path t, IOException ioe) - throws IOException { - return FileVisitResult.CONTINUE; - } - - @Override - public FileVisitResult postVisitDirectory(Path t, IOException ioe) - throws IOException { - Files.delete(t); - log.debug("delete: " + t); - return FileVisitResult.CONTINUE; - } - } - */ - private static class CopyVisitor implements FileVisitor { PosixPrincipal owner; diff --git a/cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java b/cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java new file mode 100644 index 00000000..3cbdd14b --- /dev/null +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/QuotaPlugin.java @@ -0,0 +1,95 @@ +/* +************************************************************************ +******************* CANADIAN ASTRONOMY DATA CENTRE ******************* +************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES ************** +* +* (c) 2024. (c) 2024. +* Government of Canada Gouvernement du Canada +* National Research Council Conseil national de recherches +* Ottawa, Canada, K1A 0R6 Ottawa, Canada, K1A 0R6 +* All rights reserved Tous droits réservés +* +* NRC disclaims any warranties, Le CNRC dénie toute garantie +* expressed, implied, or énoncée, implicite ou légale, +* statutory, of any kind with de quelque nature que ce +* respect to the software, soit, concernant le logiciel, +* including without limitation y compris sans restriction +* any warranty of merchantability toute garantie de valeur +* or fitness for a particular marchande ou de pertinence +* purpose. NRC shall not be pour un usage particulier. +* liable in any event for any Le CNRC ne pourra en aucun cas +* damages, whether direct or être tenu responsable de tout +* indirect, special or general, dommage, direct ou indirect, +* consequential or incidental, particulier ou général, +* arising from the use of the accessoire ou fortuit, résultant +* software. Neither the name de l'utilisation du logiciel. Ni +* of the National Research le nom du Conseil National de +* Council of Canada nor the Recherches du Canada ni les noms +* names of its contributors may de ses participants ne peuvent +* be used to endorse or promote être utilisés pour approuver ou +* products derived from this promouvoir les produits dérivés +* software without specific prior de ce logiciel sans autorisation +* written permission. préalable et particulière +* par écrit. +* +* This file is part of the Ce fichier fait partie du projet +* OpenCADC project. OpenCADC. +* +* OpenCADC is free software: OpenCADC est un logiciel libre ; +* you can redistribute it and/or vous pouvez le redistribuer ou le +* modify it under the terms of modifier suivant les termes de +* the GNU Affero General Public la “GNU Affero General Public +* License as published by the License” telle que publiée +* Free Software Foundation, par la Free Software Foundation +* either version 3 of the : soit la version 3 de cette +* License, or (at your option) licence, soit (à votre gré) +* any later version. toute version ultérieure. +* +* OpenCADC is distributed in the OpenCADC est distribué +* hope that it will be useful, dans l’espoir qu’il vous +* but WITHOUT ANY WARRANTY; sera utile, mais SANS AUCUNE +* without even the implied GARANTIE : sans même la garantie +* warranty of MERCHANTABILITY implicite de COMMERCIALISABILITÉ +* or FITNESS FOR A PARTICULAR ni d’ADÉQUATION À UN OBJECTIF +* PURPOSE. See the GNU Affero PARTICULIER. Consultez la Licence +* General Public License for Générale Publique GNU Affero +* more details. pour plus de détails. +* +* You should have received Vous devriez avoir reçu une +* a copy of the GNU Affero copie de la Licence Générale +* General Public License along Publique GNU Affero avec +* with OpenCADC. If not, see OpenCADC ; si ce n’est +* . pas le cas, consultez : +* . +* +************************************************************************ +*/ + +package org.opencadc.cavern.nodes; + +import java.nio.file.Path; + +/** + * Prototype plugin to get and set storage quota on a container node. This plugin + * only makes sense when quotas are a property of container nodes aka directories + * and is not intended to be a general purpose quota plugin mechanism. + * + * @author pdowler + */ +public interface QuotaPlugin { + /** + * Get the current quota in bytes. + * + * @param directory directory to check + * @return current quota in bytes + */ + public Long getQuota(Path directory); + + /** + * Set or clear the byte quota on a directory. + * + * @param directory the target directory + * @param quota the new quota, null to clear the current quota + */ + public void setQuota(Path directory, Long quota); +}