Skip to content

Commit

Permalink
Merge pull request #549 from pdowler/vos2
Browse files Browse the repository at this point in the history
bug fix for immutable property handling
  • Loading branch information
pdowler authored Jan 16, 2024
2 parents c890930 + d6e9d12 commit 240fff8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
81 changes: 41 additions & 40 deletions vault/src/main/java/org/opencadc/vault/NodePersistenceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
******************* CANADIAN ASTRONOMY DATA CENTRE *******************
************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES **************
*
* (c) 2023. (c) 2023.
* (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
Expand Down Expand Up @@ -70,7 +70,6 @@
import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.auth.HttpPrincipal;
import ca.nrc.cadc.auth.IdentityManager;
import ca.nrc.cadc.date.DateUtil;
import ca.nrc.cadc.db.TransactionManager;
import ca.nrc.cadc.io.ResourceIterator;
import ca.nrc.cadc.net.TransientException;
Expand Down Expand Up @@ -124,27 +123,28 @@
public class NodePersistenceImpl implements NodePersistence {
private static final Logger log = Logger.getLogger(NodePersistenceImpl.class);

static final Set<URI> ADMIN_PROPS = new TreeSet<>(
private static final Set<URI> ADMIN_PROPS = new TreeSet<>(
Arrays.asList(
VOS.PROPERTY_URI_CREATOR,
VOS.PROPERTY_URI_QUOTA
)
);

static final Set<URI> IMMUTABLE_PROPS = new TreeSet<>(
private static final Set<URI> IMMUTABLE_PROPS = new TreeSet<>(
Arrays.asList(
VOS.PROPERTY_URI_AVAILABLESPACE,
VOS.PROPERTY_URI_CONTENTLENGTH,
VOS.PROPERTY_URI_CONTENTMD5,
VOS.PROPERTY_URI_CONTENTDATE,
VOS.PROPERTY_URI_DATE,
VOS.PROPERTY_URI_CREATOR,
VOS.PROPERTY_URI_DATE,
VOS.PROPERTY_URI_QUOTA
)
);

private static final Set<URI> ARTIFACT_PROPS = new TreeSet<>(
Arrays.asList(
// immutable
VOS.PROPERTY_URI_CONTENTLENGTH,
VOS.PROPERTY_URI_CONTENTMD5,
VOS.PROPERTY_URI_CONTENTDATE,
Expand Down Expand Up @@ -482,6 +482,7 @@ public Node put(Node node) throws NodeNotSupportedException, TransientException

if (node instanceof DataNode) {
DataNode dn = (DataNode) node;
boolean knownNoArtifact = false;
if (dn.storageID == null) {
// new data node? if lastModified is assigned, this looks sketchy
if (dn.getLastModified() != null) {
Expand All @@ -493,44 +494,44 @@ public Node put(Node node) throws NodeNotSupportedException, TransientException
// once someone puts the file to minoc, so Node.storageID == Artifact.uri
// but the artifact may or may not exist
dn.storageID = generateStorageID();
knownNoArtifact = true;
}

// need to remove all artifact props from the node.getProperties()
// and use artifactDAO to set the mutable ones
NodeProperty contentType = null;
NodeProperty contentEncoding = null;
Iterator<NodeProperty> i = dn.getProperties().iterator();
while (i.hasNext()) {
NodeProperty np = i.next();
if (VOS.PROPERTY_URI_TYPE.equals(np.getKey())) {
contentType = np;
} else if (VOS.PROPERTY_URI_CONTENTENCODING.equals(np.getKey())) {
contentEncoding = np;
}

} else {
// update existing data node
// need to remove all artifact props from the node.getProperties()
// and use artifactDAO to set the mutable ones
NodeProperty contentType = null;
NodeProperty contentEncoding = null;

Iterator<NodeProperty> i = dn.getProperties().iterator();
while (i.hasNext()) {
NodeProperty np = i.next();
if (VOS.PROPERTY_URI_TYPE.equals(np.getKey())) {
contentType = np;
} else if (VOS.PROPERTY_URI_CONTENTENCODING.equals(np.getKey())) {
contentEncoding = np;
}

if (ARTIFACT_PROPS.contains(np.getKey())) {
i.remove();
}
if (ARTIFACT_PROPS.contains(np.getKey())) {
i.remove();
}
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) {
a.contentType = null;
} else {
a.contentType = contentType.getValue();
}
if (contentEncoding == null) {
a.contentEncoding = null;
} else {
a.contentEncoding = contentEncoding.getValue();
}
artifactDAO.put(a);
}
// optimization: avoid query when we know artifact doesn't exist
// and: avoid query if we don't need to update it
if (!knownNoArtifact && (contentType != null || contentEncoding != null)) {
ArtifactDAO artifactDAO = getArtifactDAO();
Artifact a = artifactDAO.get(dn.storageID);
log.warn("put: " + contentType + " " + contentEncoding + " -> " + a);
if (a != null) {
if (contentType == null) {
a.contentType = null;
} else {
a.contentType = contentType.getValue();
}
if (contentEncoding == null) {
a.contentEncoding = null;
} else {
a.contentEncoding = contentEncoding.getValue();
}
artifactDAO.put(a);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
******************* CANADIAN ASTRONOMY DATA CENTRE *******************
************** CENTRE CANADIEN DE DONNÉES ASTRONOMIQUES **************
*
* (c) 2023. (c) 2023.
* (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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public class VaultTransferGenerator implements TransferGenerator {
private Map<URI, StorageSiteRule> siteRules = new HashMap<>();
private Map<URI, Availability> siteAvailabilities;

@SuppressWarnings("unchecked")
public VaultTransferGenerator(NodePersistenceImpl nodePersistence, ArtifactDAO artifactDAO, TokenTool tokenTool, boolean preventNotFound) {
this.nodePersistence = nodePersistence;
this.authorizer = new VOSpaceAuthorizer(nodePersistence);
Expand Down

0 comments on commit 240fff8

Please sign in to comment.