Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix for immutable property handling #549

Merged
merged 3 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading