Skip to content

Commit

Permalink
Merge pull request #535 from pdowler/master
Browse files Browse the repository at this point in the history
raven: implement prototype negotiate for resourceIDs that implement files API
  • Loading branch information
pdowler authored Oct 6, 2023
2 parents a654071 + dda67d4 commit 84d041c
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion raven/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# semantic version tag: major.minor[.patch]
# build version tag: timestamp
# tag: {semantic}-{build}
VER=0.7.8
VER=0.7.9
TAGS="${VER} ${VER}-$(date --utc +"%Y%m%dT%H%M%S")"
unset VER
91 changes: 91 additions & 0 deletions raven/src/intTest/java/org/opencadc/raven/NegotiationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -743,4 +743,95 @@ public Object run() throws Exception {

}

@Test
public void testGetSites() throws Exception {
// request the raw ivo resourceIDs of storage sites (files services) that
// can deliver the file
List<Protocol> requested = new ArrayList<>();

Protocol files = new Protocol(Standards.SI_FILES.toASCIIString());
requested.add(files);

try {
Subject.doAs(userSubject, new PrivilegedExceptionAction<Object>() {
public Object run() throws Exception {

URI resourceID1 = URI.create("ivo://negotiation-test-site1");
URI resourceID2 = URI.create("ivo://negotiation-test-site2");


StorageSite site1 = new StorageSite(resourceID1, "site1", true, true);
StorageSite site2 = new StorageSite(resourceID2, "site2", true, true);

URI artifactURI = URI.create("cadc:TEST/" + UUID.randomUUID() + ".fits");
URI checksum = URI.create("md5:d41d8cd98f00b204e9800998ecf8427e");
Artifact artifact = new Artifact(artifactURI, checksum, new Date(), 1L);

try {
siteDAO.put(site1);
siteDAO.put(site2);

final SiteLocation location1 = new SiteLocation(site1.getID());
final SiteLocation location2 = new SiteLocation(site2.getID());

Transfer transfer = new Transfer(artifactURI, Direction.pullFromVoSpace);
transfer.getProtocols().add(files);
transfer.version = VOS.VOSPACE_21;

artifactDAO.put(artifact);

// test that there are no copies available
try {
negotiate(transfer);
Assert.fail("should have received file not found exception");
} catch (ResourceNotFoundException e) {
log.info("caught expected: " + e);
}

log.info("add: " + location1);
artifactDAO.addSiteLocation(artifact, location1);
artifact = artifactDAO.get(artifact.getID());

// test that there's one copy
Transfer response = negotiate(transfer);
log.info("transfer: " + response);
Assert.assertEquals(1, response.getProtocols().size());
for (Protocol ap : response.getProtocols()) {
log.info("found: " + artifactURI + " -> " + ap.getEndpoint());
}
Assert.assertTrue(response.getAllEndpoints().contains(resourceID1.toASCIIString()));

Protocol actual = response.getProtocols().get(0);
Assert.assertNotNull(actual.getEndpoint());
Assert.assertEquals(files.getUri(), actual.getUri());
Assert.assertEquals(resourceID1.toASCIIString(), actual.getEndpoint());

log.info("add: " + location2);
artifactDAO.addSiteLocation(artifact, location2);
artifact = artifactDAO.get(artifact.getID());

// test that there are now two copies
response = negotiate(transfer);
Assert.assertEquals(2, response.getProtocols().size());
for (Protocol ap : response.getProtocols()) {
log.info("found: " + artifactURI + " -> " + ap.getEndpoint());
}
Assert.assertTrue(response.getAllEndpoints().contains(resourceID1.toASCIIString()));
Assert.assertTrue(response.getAllEndpoints().contains(resourceID2.toASCIIString()));

return null;

} finally {
// cleanup sites
siteDAO.delete(site1.getID());
siteDAO.delete(site2.getID());
artifactDAO.delete(artifact.getID());
}
}
});
} catch (Exception e) {
log.error("unexpected exception", e);
Assert.fail("unexpected exception: " + e);
}
}
}
14 changes: 14 additions & 0 deletions raven/src/main/java/org/opencadc/raven/ProtocolsGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,13 @@ List<Protocol> doPullFrom(URI artifactURI, Transfer transfer, String authToken)
if (filesCap != null) {
for (Protocol proto : transfer.getProtocols()) {
if (storageSite.getAllowRead()) {
// less generic request for service that implements an API
// HACK: this is filesCap specific in here
if (proto.getUri().equals(filesCap.getStandardID().toASCIIString())) {
Protocol p = new Protocol(proto.getUri());
p.setEndpoint(storageSite.getResourceID().toASCIIString());
protos.add(p);
}
URI sec = proto.getSecurityMethod();
if (sec == null) {
sec = Standards.SECURITY_METHOD_ANON;
Expand Down Expand Up @@ -444,6 +451,13 @@ private List<Protocol> doPushTo(URI artifactURI, Transfer transfer, String authT
for (Protocol proto : transfer.getProtocols()) {
//log.warn("PUT: " + storageSite + " proto: " + proto);
if (storageSite.getAllowWrite()) {
// less generic request for service that implements
// HACK: this is filesCap specific in here
if (proto.getUri().equals(filesCap.getStandardID().toASCIIString())) {
Protocol p = new Protocol(proto.getUri());
p.setEndpoint(storageSite.getResourceID().toASCIIString());
protos.add(p);
}
URI sec = proto.getSecurityMethod();
if (sec == null) {
sec = Standards.SECURITY_METHOD_ANON;
Expand Down

0 comments on commit 84d041c

Please sign in to comment.