Skip to content

Commit

Permalink
Merge pull request #548 from pdowler/vos2
Browse files Browse the repository at this point in the history
DataNode date prop fix
  • Loading branch information
pdowler authored Jan 15, 2024
2 parents c61721d + 17587ca commit c890930
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public class NodeDAO extends AbstractDAO<Node> {
public NodeDAO() {
super(true);
}

// needed by vault migration tool: untested
public NodeDAO(boolean origin) {
super(origin);
}

@Override
public void put(Node val) {
Expand Down
5 changes: 3 additions & 2 deletions vault/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand Down
54 changes: 37 additions & 17 deletions vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -161,6 +163,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");
Expand Down Expand Up @@ -225,7 +231,7 @@ public TransferGenerator getTransferGenerator() {
}

private NodeDAO getDAO() {
NodeDAO instance = new NodeDAO();
NodeDAO instance = new NodeDAO(nodeOrigin);
instance.setConfig(nodeDaoConfig);
return instance;
}
Expand Down Expand Up @@ -301,11 +307,28 @@ 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);
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
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));
}
Expand Down Expand Up @@ -494,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);
}
Expand Down

0 comments on commit c890930

Please sign in to comment.