From 243ba7e000802024857b797fa2e90eba2e34a62b Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Wed, 20 Dec 2023 16:01:46 -0800 Subject: [PATCH 1/2] added NodeDAO(boolean origin) ctor --- .../src/main/java/org/opencadc/vospace/db/NodeDAO.java | 5 +++++ vault/build.gradle | 5 +++-- .../java/org/opencadc/vault/NodePersistenceImpl.java | 10 ++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cadc-inventory-db/src/main/java/org/opencadc/vospace/db/NodeDAO.java b/cadc-inventory-db/src/main/java/org/opencadc/vospace/db/NodeDAO.java index acf81b96..58033b79 100644 --- a/cadc-inventory-db/src/main/java/org/opencadc/vospace/db/NodeDAO.java +++ b/cadc-inventory-db/src/main/java/org/opencadc/vospace/db/NodeDAO.java @@ -87,6 +87,11 @@ public class NodeDAO extends AbstractDAO { public NodeDAO() { super(true); } + + // needed by vault migration tool: untested + public NodeDAO(boolean origin) { + super(origin); + } @Override public void put(Node val) { diff --git a/vault/build.gradle b/vault/build.gradle index ce2424e2..bba3646d 100644 --- a/vault/build.gradle +++ b/vault/build.gradle @@ -24,8 +24,9 @@ war { include 'VERSION' } } -description = 'OpenCADC VOSpace server' -def git_url = 'https://github.com/opencadc/vos' + +description = 'OpenCADC vault service' +def git_url = 'https://github.com/opencadc/storage-inventory' dependencies { compile 'javax.servlet:javax.servlet-api:[3.1,4.0)' diff --git a/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java b/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java index 968d6eb3..d8ce9ef6 100644 --- a/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java +++ b/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java @@ -161,6 +161,10 @@ public class NodePersistenceImpl implements NodePersistence { private URI resourceID; private final boolean preventNotFound; + // possibly temporary hack so migration tool can set this to false and + // preserve lastModified timestamps on nodes + public boolean nodeOrigin = true; + public NodePersistenceImpl(URI resourceID) { if (resourceID == null) { throw new IllegalArgumentException("resource ID required"); @@ -225,7 +229,7 @@ public TransferGenerator getTransferGenerator() { } private NodeDAO getDAO() { - NodeDAO instance = new NodeDAO(); + NodeDAO instance = new NodeDAO(nodeOrigin); instance.setConfig(nodeDaoConfig); return instance; } @@ -302,10 +306,12 @@ public Node get(ContainerNode parent, String name) throws TransientException { Artifact a = artifactDAO.get(dn.storageID); if (a != null) { DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC); + ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DATE, df.format(a.getContentLastModified()))); + ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTLENGTH, a.getContentLength().toString())); // assume MD5 ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTMD5, a.getContentChecksum().getSchemeSpecificPart())); - ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DATE, df.format(a.getContentLastModified()))); + if (a.contentEncoding != null) { ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTENCODING, a.contentEncoding)); } From 17587ca10f8538b38d89d58b63b5afc708fa63da Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Fri, 12 Jan 2024 12:52:37 -0800 Subject: [PATCH 2/2] vault: fix date related node properties fix bug in remove artifact node props --- .../opencadc/vault/NodePersistenceImpl.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java b/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java index d8ce9ef6..995270e1 100644 --- a/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java +++ b/vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java @@ -83,6 +83,7 @@ import java.text.DateFormat; import java.util.Arrays; import java.util.Collections; +import java.util.Date; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; @@ -110,6 +111,7 @@ import org.opencadc.vospace.VOS; import org.opencadc.vospace.VOSURI; import org.opencadc.vospace.db.NodeDAO; +import org.opencadc.vospace.io.NodeWriter; import org.opencadc.vospace.server.LocalServiceURI; import org.opencadc.vospace.server.NodePersistence; import org.opencadc.vospace.server.Views; @@ -134,7 +136,7 @@ public class NodePersistenceImpl implements NodePersistence { VOS.PROPERTY_URI_AVAILABLESPACE, VOS.PROPERTY_URI_CONTENTLENGTH, VOS.PROPERTY_URI_CONTENTMD5, - VOS.PROPERTY_URI_CREATION_DATE, + VOS.PROPERTY_URI_CONTENTDATE, VOS.PROPERTY_URI_DATE, VOS.PROPERTY_URI_CREATOR, VOS.PROPERTY_URI_QUOTA @@ -145,7 +147,7 @@ public class NodePersistenceImpl implements NodePersistence { Arrays.asList( VOS.PROPERTY_URI_CONTENTLENGTH, VOS.PROPERTY_URI_CONTENTMD5, - VOS.PROPERTY_URI_CREATION_DATE, + VOS.PROPERTY_URI_CONTENTDATE, VOS.PROPERTY_URI_DATE, // mutable VOS.PROPERTY_URI_CONTENTENCODING, @@ -305,8 +307,23 @@ public Node get(ContainerNode parent, String name) throws TransientException { ArtifactDAO artifactDAO = getArtifactDAO(); Artifact a = artifactDAO.get(dn.storageID); if (a != null) { - DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC); - ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DATE, df.format(a.getContentLastModified()))); + DateFormat df = NodeWriter.getDateFormat(); + + Date d = ret.getLastModified(); + Date cd = null; + if (ret.getLastModified().before(a.getLastModified())) { + d = a.getLastModified(); + } + if (d.before(a.getContentLastModified())) { + // probably not possible + d = a.getContentLastModified(); + } else { + cd = a.getContentLastModified(); + } + ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DATE, df.format(d))); + if (cd != null) { + ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTDATE, df.format(cd))); + } ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_CONTENTLENGTH, a.getContentLength().toString())); // assume MD5 @@ -500,20 +517,17 @@ public Node put(Node node) throws NodeNotSupportedException, TransientException if (contentType != null || contentEncoding != null) { // optimization ArtifactDAO artifactDAO = getArtifactDAO(); Artifact a = artifactDAO.get(dn.storageID); + log.warn("put: " + contentType + " " + contentEncoding + " -> " + a); if (a != null) { - if (contentType != null) { - if (contentType.isMarkedForDeletion()) { - a.contentType = null; - } else { - a.contentType = contentType.getValue(); - } + if (contentType == null) { + a.contentType = null; + } else { + a.contentType = contentType.getValue(); } - if (contentEncoding != null) { - if (contentEncoding.isMarkedForDeletion()) { - a.contentEncoding = null; - } else { - a.contentEncoding = contentEncoding.getValue(); - } + if (contentEncoding == null) { + a.contentEncoding = null; + } else { + a.contentEncoding = contentEncoding.getValue(); } artifactDAO.put(a); }