From dda67d4ae307f27407772f6e4971620d7d6b964c Mon Sep 17 00:00:00 2001 From: Patrick Dowler Date: Tue, 3 Oct 2023 13:30:02 -0700 Subject: [PATCH] raven: implement prototype negotiate for resourceIDs that implement files API --- raven/VERSION | 2 +- .../org/opencadc/raven/NegotiationTest.java | 91 +++++++++++++++++++ .../opencadc/raven/ProtocolsGenerator.java | 14 +++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/raven/VERSION b/raven/VERSION index 3765a6c6..bd72e5cf 100644 --- a/raven/VERSION +++ b/raven/VERSION @@ -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 diff --git a/raven/src/intTest/java/org/opencadc/raven/NegotiationTest.java b/raven/src/intTest/java/org/opencadc/raven/NegotiationTest.java index fd3c3723..d50c70d1 100644 --- a/raven/src/intTest/java/org/opencadc/raven/NegotiationTest.java +++ b/raven/src/intTest/java/org/opencadc/raven/NegotiationTest.java @@ -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 requested = new ArrayList<>(); + + Protocol files = new Protocol(Standards.SI_FILES.toASCIIString()); + requested.add(files); + + try { + Subject.doAs(userSubject, new PrivilegedExceptionAction() { + 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); + } + } } diff --git a/raven/src/main/java/org/opencadc/raven/ProtocolsGenerator.java b/raven/src/main/java/org/opencadc/raven/ProtocolsGenerator.java index 9e640815..2c4aa7e9 100644 --- a/raven/src/main/java/org/opencadc/raven/ProtocolsGenerator.java +++ b/raven/src/main/java/org/opencadc/raven/ProtocolsGenerator.java @@ -325,6 +325,13 @@ List 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; @@ -444,6 +451,13 @@ private List 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;