Skip to content

Commit

Permalink
Merge pull request #220 from pdowler/master
Browse files Browse the repository at this point in the history
cadc-vos: update to use new Entity metaChecksum algorithm flags
  • Loading branch information
pdowler authored Feb 16, 2024
2 parents 8bf22e7 + cd89187 commit b19ecd2
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cadc-vos/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '2.0.3'
version = '2.0.4'

description = 'OpenCADC VOSpace client library'
def git_url = 'https://github.com/opencadc/vos'

dependencies {
// xml and jxon dependencies controlled by cadc-util
compile 'org.opencadc:cadc-util:[1.10.1,2.0)'
compile 'org.opencadc:cadc-util:[1.10.6,2.0)'
compile 'org.opencadc:cadc-uws:[1.0,2.0)'
compile 'org.opencadc:cadc-registry:[1.7,2.0)'
compile 'org.opencadc:cadc-gms:[1.0.5,)'
Expand Down
17 changes: 7 additions & 10 deletions cadc-vos/src/main/java/org/opencadc/vospace/DeletedNodeEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,19 @@ public class DeletedNodeEvent extends Entity {
private static final Logger log = Logger.getLogger(DeletedNodeEvent.class);

private final String nodeType;
private final URI storageID;
public URI storageID;

public DeletedNodeEvent(UUID id, Class nodeType, URI storageID) {
super(id, false);
public DeletedNodeEvent(UUID id, Class nodeType) {
super(id, Node.ENTITY_TRUNCATE_DATES, Node.ENTITY_DIGEST_FIELD_NAMES);
NodeUtil.assertNotNull(DeletedNodeEvent.class, "nodeType", nodeType);
this.nodeType = nodeType.getSimpleName();

// storageID may be null
this.storageID = storageID;
this.storageID = null;
}

/**
* @return simple class name for the node type
*/
public String getNodeType() {
return nodeType;
}

public URI getStorageID() {
return storageID;
}
}
10 changes: 7 additions & 3 deletions cadc-vos/src/main/java/org/opencadc/vospace/Node.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 @@ -89,6 +89,10 @@
*/
public abstract class Node extends Entity implements Comparable<Node> {
private static final Logger log = Logger.getLogger(Node.class);

// Entity metaChecksum algorithm setup: DO NOT CHANGE
static final boolean ENTITY_TRUNCATE_DATES = false;
static final boolean ENTITY_DIGEST_FIELD_NAMES = true;

/**
* Server-side support for connecting a node to a parent container node.
Expand Down Expand Up @@ -137,13 +141,13 @@ public abstract class Node extends Entity implements Comparable<Node> {
private final Set<NodeProperty> properties = new TreeSet<>();

protected Node(String name) {
super(false);
super(ENTITY_TRUNCATE_DATES, ENTITY_DIGEST_FIELD_NAMES);
NodeUtil.assertNotNull(Node.class, "name", "name");
this.name = name;
}

protected Node(UUID id, String name) {
super(id, false);
super(id, ENTITY_TRUNCATE_DATES, ENTITY_DIGEST_FIELD_NAMES);
NodeUtil.assertNotNull(Node.class, "name", "name");
this.name = name;
}
Expand Down
60 changes: 59 additions & 1 deletion cadc-vos/src/test/java/org/opencadc/vospace/NodeEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.junit.Assert;
import org.junit.Test;
import org.opencadc.gms.GroupURI;
import org.opencadc.persist.Entity;

/**
*
Expand All @@ -88,7 +89,7 @@ public class NodeEntityTest {
private static final Logger log = Logger.getLogger(NodeEntityTest.class);

static {
Log4jInit.setLevel("org.opencadc.persist", Level.INFO);
Log4jInit.setLevel("org.opencadc.persist", Level.DEBUG);
Log4jInit.setLevel("org.opencadc.vospace", Level.INFO);
}

Expand Down Expand Up @@ -277,4 +278,61 @@ public void testDataNode() {
Assert.fail("unexpected exception: " + unexpected);
}
}

@Test
public void testShiftValues() {
try {
Entity.MCS_DEBUG = true;

final UUID rootID = new UUID(0L, 0L);
final ContainerNode root = new ContainerNode(rootID, "root");

ContainerNode n = new ContainerNode("foo");
n.parent = root;
URI mcs1 = n.computeMetaChecksum(MessageDigest.getInstance("MD5"));
log.info("base metaChecksum: " + mcs1);

// shift same value to another field
n.inheritPermissions = true;
URI b0 = n.computeMetaChecksum(MessageDigest.getInstance("MD5"));
log.info("inheritPermissions metaChecksum: " + b0);
Assert.assertNotEquals(mcs1, b0);

n.inheritPermissions = null;
n.isLocked = true;
URI b1 = n.computeMetaChecksum(MessageDigest.getInstance("MD5"));
log.info("isLocked metaChecksum: " + b1);
Assert.assertNotEquals(b0, b1);

n.isLocked = null;
n.isPublic = true;
URI b2 = n.computeMetaChecksum(MessageDigest.getInstance("MD5"));
log.info("isLocked metaChecksum: " + b2);
Assert.assertNotEquals("shift boolean", b1, b2);
n.isPublic = null;
n.inheritPermissions = true;

// shift same value to an adjacent field
GroupURI guri = new GroupURI(URI.create("ivo://opencadc.org/gms?FOO"));
n.getReadOnlyGroup().add(guri);
URI rog = n.computeMetaChecksum(MessageDigest.getInstance("MD5"));
log.info("read-only group metaChecksum: " + rog);
Assert.assertNotEquals(mcs1, rog);

n.getReadOnlyGroup().clear();
n.getReadWriteGroup().add(guri);
URI rwg = n.computeMetaChecksum(MessageDigest.getInstance("MD5"));
log.info("read-write group metaChecksum: " + rwg);
Assert.assertNotEquals(mcs1, rog);
Assert.assertNotEquals("shift group", rog, rwg);
n.getReadWriteGroup().clear();


} catch (Exception unexpected) {
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
} finally {
Entity.MCS_DEBUG = false;
}
}
}

0 comments on commit b19ecd2

Please sign in to comment.