Skip to content

Commit

Permalink
Cleanup fixes, and throw appropriate Exception for quota exceeding.
Browse files Browse the repository at this point in the history
  • Loading branch information
at88mph committed May 24, 2024
1 parent 55ba2c7 commit 03429a6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 19 additions & 11 deletions cavern/src/main/java/org/opencadc/cavern/files/PutAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
import ca.nrc.cadc.io.ByteCountOutputStream;
import ca.nrc.cadc.io.ByteLimitExceededException;
import ca.nrc.cadc.io.MultiBufferIO;
import ca.nrc.cadc.io.WriteException;
import ca.nrc.cadc.net.ResourceNotFoundException;
import ca.nrc.cadc.net.TransientException;
import ca.nrc.cadc.rest.InlineContentException;
import ca.nrc.cadc.rest.InlineContentHandler;
import ca.nrc.cadc.util.HexUtil;
Expand All @@ -92,6 +94,7 @@
import org.opencadc.vospace.ContainerNode;
import org.opencadc.vospace.DataNode;
import org.opencadc.vospace.Node;
import org.opencadc.vospace.NodeNotSupportedException;
import org.opencadc.vospace.NodeProperty;
import org.opencadc.vospace.VOS;
import org.opencadc.vospace.VOSURI;
Expand Down Expand Up @@ -277,19 +280,17 @@ public void doAction() throws Exception {
log.debug("403 error with PUT: ", e);
throw new AccessControlException(e.getLocalizedMessage());

} catch (IOException ex) {
String msg = ex.getMessage();
if (msg != null && msg.contains("quota")) {
} catch (WriteException ex) {
final Throwable cause = ex.getCause();
if (cause != null && cause.getMessage().contains("quota")) {
final Long limit = PutAction.getLimit(node);
if (limit == null) {
// VOS.PROPERTY_URI_QUOTA attribute is not set on any parent node
msg = "VOS.PROPERTY_URI_QUOTA attribute not set, " + ex.getMessage();
log.warn(msg);
} else if (limit <= 0) {
throw new ByteLimitExceededException(ex.getMessage(), limit);
log.warn("VOS.PROPERTY_URI_QUOTA attribute not set, " + ex.getMessage());
} else {
throw new ByteLimitExceededException(cause.getMessage().trim(), limit);
}
}

throw ex;
} finally {
if (bytesWritten > 0L) {
Expand All @@ -298,7 +299,7 @@ public void doAction() throws Exception {
if (successful) {
log.debug("put: done " + nodeURI.getURI().toASCIIString());
} else if (putStarted) {
cleanupOnFailure(target);
cleanupOnFailure(target, node);
}
}
}
Expand All @@ -323,8 +324,15 @@ private static Long getLimit(DataNode node) {
}
}

private void cleanupOnFailure(Path target) {
throw new UnsupportedOperationException();
private void cleanupOnFailure(Path target, DataNode node) {
log.debug("clean up on put failure " + target);
if (node != null) {
try {
nodePersistence.delete(node);
} catch (TransientException bug) {
log.error("Unable to clean up " + target + "\n" + bug.getMessage(), bug);
}
}
}

/*
Expand Down
2 changes: 2 additions & 0 deletions cavern/src/main/java/org/opencadc/cavern/nodes/NodeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ Node pathToNode(Path p, boolean getAttrs)

Long quota = quotaImpl.getQuota(p);
if (quota != null) {
// This quota takes precedence.
ret.getProperties().remove(new NodeProperty(VOS.PROPERTY_URI_QUOTA));
ret.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_QUOTA, quota.toString()));
}

Expand Down

0 comments on commit 03429a6

Please sign in to comment.