From a616101ae690f09a66a448ab3439cf0e0cdbfe6e Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Tue, 26 Sep 2023 14:15:45 -0700 Subject: [PATCH] cavern: tweaks for PosixMapperClient exceptions --- .../cavern/FileSystemNodePersistence.java | 8 +-- .../org/opencadc/cavern/nodes/NodeUtil.java | 66 +++++++++++++------ .../cavern/probe/FileSystemProbe.java | 24 +++---- 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/cavern/src/main/java/org/opencadc/cavern/FileSystemNodePersistence.java b/cavern/src/main/java/org/opencadc/cavern/FileSystemNodePersistence.java index c5fdf8e7..240f7e8f 100644 --- a/cavern/src/main/java/org/opencadc/cavern/FileSystemNodePersistence.java +++ b/cavern/src/main/java/org/opencadc/cavern/FileSystemNodePersistence.java @@ -148,7 +148,7 @@ public Node get(VOSURI uri, boolean allowPartialPath, boolean resolveMetadata) t } log.debug("[get] " + ret); return ret; - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { throw new RuntimeException("oops", ex); } } @@ -184,7 +184,7 @@ public void getChildren(ContainerNode cn, VOSURI start, Integer limit, boolean b cn.getNodes().add(cur); log.debug("[getChildren] " + cur); } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { throw new RuntimeException("oops", ex); } } @@ -243,7 +243,7 @@ public Node put(Node node) throws NodeNotSupportedException, TransientException NodeUtil.setOwner(node, new NodeID(null, caller, owner)); nut.create(node); return nut.get(node.getUri()); - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { throw new RuntimeException("oops", ex); } } @@ -283,7 +283,7 @@ public Node updateProperties(Node node, List properties) throws Tr iter.remove(); } } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { throw new RuntimeException("oops", ex); } return node; 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 d1c4b744..94417e55 100644 --- a/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java +++ b/cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java @@ -69,6 +69,8 @@ import ca.nrc.cadc.auth.PosixPrincipal; import ca.nrc.cadc.date.DateUtil; +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 ca.nrc.cadc.vos.ContainerNode; @@ -208,7 +210,7 @@ public static VOSURI pathToURI(Path root, Path p, VOSURI rootURI) { } public Path create(Node node) - throws IOException { + throws IOException, InterruptedException { Path np = nodeToPath(root, node); log.debug("[create] path: " + node.getUri() + " -> " + np); @@ -283,7 +285,7 @@ public static void setPosixOwnerGroup(Path p, Integer owner, Integer group) thro * @param node The VOSpace Node input. * @throws IOException If any I/O errors occur. */ - public void setNodeProperties(Path path, Node node) throws IOException { + public void setNodeProperties(Path path, Node node) throws IOException, InterruptedException { log.debug("setNodeProperties: " + node); if (!node.getProperties().isEmpty() && !(node instanceof LinkNode)) { @@ -311,6 +313,7 @@ public void setNodeProperties(Path path, Node node) throws IOException { } else { // ugh: raw multi-valued node prop is space-separated String val = rop.getPropertyValue(); + log.warn("raw read-only prop: " + val); if (val != null) { String[] vals = val.split(" "); if (vals.length > 0) { @@ -321,10 +324,15 @@ public void setNodeProperties(Path path, Node node) throws IOException { guris.add(guri); } if (!guris.isEmpty()) { - List pgs = posixMapper.getGID(guris); - // TODO: check if any input groups were not resolved/acceptable and do what?? - for (PosixGroup pg : pgs) { - readGroupPrincipals.add(pg.getGID()); + try { + List pgs = posixMapper.getGID(guris); + // TODO: check if any input groups were not resolved/acceptable and do what?? + for (PosixGroup pg : pgs) { + readGroupPrincipals.add(pg.getGID()); + } + } catch (ResourceNotFoundException | ResourceAlreadyExistsException ex) { + throw new RuntimeException("failed to map GroupURI(s) to numeric GID(s): " + + ex.toString(), ex); } } } else { @@ -344,6 +352,7 @@ public void setNodeProperties(Path path, Node node) throws IOException { } else { // ugh: raw multi-valued node prop is space-separated String val = rwp.getPropertyValue(); + log.warn("raw read-write prop: " + val); if (val != null) { String[] vals = val.split(" "); if (vals.length > 0) { @@ -354,10 +363,15 @@ public void setNodeProperties(Path path, Node node) throws IOException { guris.add(guri); } if (!guris.isEmpty()) { - List pgs = posixMapper.getGID(guris); - // TODO: check if any input groups were not resolved/acceptable and do what?? - for (PosixGroup pg : pgs) { - writeGroupPrincipals.add(pg.getGID()); + try { + List pgs = posixMapper.getGID(guris); + // TODO: check if any input groups were not resolved/acceptable and do what?? + for (PosixGroup pg : pgs) { + writeGroupPrincipals.add(pg.getGID()); + } + } catch (ResourceNotFoundException | ResourceAlreadyExistsException ex) { + throw new RuntimeException("failed to map GroupURI(s) to numeric GID(s): " + + ex.toString(), ex); } } } else { @@ -415,11 +429,12 @@ public Path update(Path root, Node node) throws IOException { throw new UnsupportedOperationException(); } - public Node get(VOSURI uri) throws IOException { + public Node get(VOSURI uri) throws IOException, InterruptedException { return get(uri, false); } - public Node get(VOSURI uri, boolean allowPartialPath) throws IOException { + public Node get(VOSURI uri, boolean allowPartialPath) + throws IOException, InterruptedException { LinkedList nodeNames = new LinkedList(); nodeNames.add(uri.getName()); VOSURI parent = uri.getParentURI(); @@ -506,14 +521,14 @@ public void copy(VOSURI source, VOSURI destDir, PosixPrincipal owner) throws IOE } Node pathToNode(Path p, VOSURI rootURI) - throws IOException, NoSuchFileException { + throws IOException, InterruptedException, NoSuchFileException { boolean getAttrs = System.getProperty(NodeUtil.class.getName() + ".disable-get-attrs") == null; return pathToNode(p, rootURI, getAttrs); } // getAttrs == false needed in MountedContainerTest Node pathToNode(Path p, VOSURI rootURI, boolean getAttrs) - throws IOException, NoSuchFileException { + throws IOException, InterruptedException, NoSuchFileException { Node ret = null; VOSURI nuri = pathToURI(root, p, rootURI); PosixFileAttributes attrs = Files.readAttributes(p, @@ -575,9 +590,13 @@ Node pathToNode(Path p, VOSURI rootURI, boolean getAttrs) StringBuilder sb = new StringBuilder(); List rogids = acl.getReadOnlyACL(attrs.isDirectory()); if (!rogids.isEmpty()) { - List pgs = posixMapper.getURI(rogids); - for (PosixGroup pg : pgs) { - sb.append(pg.getGroupURI().getURI().toASCIIString()).append(" "); + try { + List pgs = posixMapper.getURI(rogids); + for (PosixGroup pg : pgs) { + sb.append(pg.getGroupURI().getURI().toASCIIString()).append(" "); + } + } catch (ResourceNotFoundException | ResourceAlreadyExistsException ex) { + throw new RuntimeException("failed to map numeric GID(s) to GroupURI(s): " + ex.toString(), ex); } } sb.trimToSize(); @@ -589,9 +608,13 @@ Node pathToNode(Path p, VOSURI rootURI, boolean getAttrs) List rwgids = acl.getReadWriteACL(attrs.isDirectory()); if (!rwgids.isEmpty()) { - List pgs = posixMapper.getURI(rwgids); - for (PosixGroup pg : pgs) { - sb.append(pg.getGroupURI().getURI().toASCIIString()).append(" "); + try { + List pgs = posixMapper.getURI(rwgids); + for (PosixGroup pg : pgs) { + sb.append(pg.getGroupURI().getURI().toASCIIString()).append(" "); + } + } catch (ResourceNotFoundException | ResourceAlreadyExistsException ex) { + throw new RuntimeException("failed to map numeric GID(s) to GroupURI(s): " + ex.toString(), ex); } } sb.trimToSize(); @@ -718,7 +741,8 @@ public FileVisitResult postVisitDirectory(Path t, IOException ioe) } } - public Iterator list(ContainerNode node, VOSURI start, Integer limit) throws IOException { + public Iterator list(ContainerNode node, VOSURI start, Integer limit) + throws IOException, InterruptedException { Path np = nodeToPath(root, node); log.debug("[list] " + node.getUri() + " -> " + np); VOSURI rootURI = node.getUri(); diff --git a/cavern/src/main/java/org/opencadc/cavern/probe/FileSystemProbe.java b/cavern/src/main/java/org/opencadc/cavern/probe/FileSystemProbe.java index 5499bad2..7f3dbd3c 100644 --- a/cavern/src/main/java/org/opencadc/cavern/probe/FileSystemProbe.java +++ b/cavern/src/main/java/org/opencadc/cavern/probe/FileSystemProbe.java @@ -332,7 +332,7 @@ public boolean doCreateDir(boolean depth) { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -401,7 +401,7 @@ public boolean doCreateFile(boolean depth) { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -497,7 +497,7 @@ public boolean doCreateSymlink() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -559,7 +559,7 @@ public boolean doSetAttribute() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -633,7 +633,7 @@ public boolean doCopyFile() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -700,7 +700,7 @@ public boolean doMoveFile() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -749,7 +749,7 @@ public boolean doRenameFile() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -823,7 +823,7 @@ public boolean doCopyDir() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -892,7 +892,7 @@ public boolean doMoveDir() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -941,7 +941,7 @@ public boolean doRenameDir() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -1026,7 +1026,7 @@ public boolean doCopySymlink() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; } @@ -1104,7 +1104,7 @@ public boolean doMoveSymlink() { log.error(sb.toString()); return false; } - } catch (IOException ex) { + } catch (IOException | InterruptedException ex) { log.error("FAIL", ex); return false; }