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

cadc-vos-client: move RecursiveSetNode to async pkg #236

Merged
merged 3 commits into from
May 3, 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
2 changes: 1 addition & 1 deletion cadc-test-vos/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '2.1.8'
version = '2.1.9'

description = 'OpenCADC VOSpace test library'
def git_url = 'https://github.com/opencadc/vos'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
import java.io.StringWriter;
import java.net.URI;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.security.auth.Subject;
Expand All @@ -108,6 +110,7 @@ public class FilesTest extends VOSTest {

protected final URL filesServiceURL;
protected Subject altSubject;
protected boolean enablePassthroughParamTest = false;

protected FilesTest(URI resourceID, File testCert) {
super(resourceID, testCert);
Expand All @@ -126,6 +129,10 @@ protected void enableTestDataNodePermission(File altCert) {
this.altSubject = SSLUtil.createSubject(altCert);
}

protected void enableTestPassthroughParams(boolean enable) {
this.enablePassthroughParamTest = enable;
}

@Test
public void fileTest() {
try {
Expand Down Expand Up @@ -210,6 +217,7 @@ public void fileTest() {
log.info("GET: " + fileURL);
out = new ByteArrayOutputStream();
HttpGet getFile = new HttpGet(fileURL, out);
getFile.setFollowRedirects(true);
Subject.doAs(authSubject, new RunnableAction(getFile));
log.info("GET response: " + getFile.getResponseCode() + " " + getFile.getThrowable());
Assert.assertEquals("expected GET response code = 200", 200, getFile.getResponseCode());
Expand All @@ -222,6 +230,35 @@ public void fileTest() {
Assert.assertTrue(System.currentTimeMillis() > headFile.getLastModified().getTime());
Assert.assertEquals(VOSTest.TEXT_CONTENT_TYPE, headFile.getContentType());

if (enablePassthroughParamTest) {
String query = "FOO=1&FOO=2&BAR=" + URLEncoder.encode("[3]", "UTF-8");
URL purl = new URL(fileURL.toExternalForm() + "?" + query);
getFile = new HttpGet(purl, false);
Subject.doAs(authSubject, new RunnableAction(getFile));
log.info("GET response: " + getFile.getResponseCode() + " " + getFile.getThrowable());
Assert.assertEquals("expected GET response code = 303", 303, getFile.getResponseCode());
Assert.assertNull("expected GET throwable == null", getFile.getThrowable());
URL redirect = getFile.getRedirectURL();
log.info("redirect: " + redirect);
Assert.assertNotNull(redirect);
String qstr = redirect.getQuery();
Assert.assertNotNull(qstr);
String[] parts = qstr.split("&");
Assert.assertEquals("3 params", 3, parts.length);
Assert.assertTrue(qstr.contains("FOO=1"));
Assert.assertTrue(qstr.contains("FOO=2"));
String barVal = null;
for (String s : parts) {
String[] kv = s.split("=");
if ("BAR".equals(kv[0])) {
barVal = kv[1];
}
}
String bvd = URLDecoder.decode(barVal, "UTF-8");
Assert.assertEquals("[3]", bvd);
}


String actual = out.toString();
log.debug("file content: " + actual);
Assert.assertEquals("expected file content to match", expected, actual);
Expand Down
2 changes: 1 addition & 1 deletion cadc-vos-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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'
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 Expand Up @@ -69,15 +69,13 @@

package org.opencadc.vospace.client;

import ca.nrc.cadc.auth.AuthenticationUtil;
import ca.nrc.cadc.net.ResourceAlreadyExistsException;
import ca.nrc.cadc.net.ResourceNotFoundException;
import ca.nrc.cadc.reg.Standards;
import ca.nrc.cadc.util.FileUtil;
import ca.nrc.cadc.util.Log4jInit;
import java.io.File;
import java.net.URI;
import java.security.AccessControlException;
import java.security.PrivilegedExceptionAction;
import javax.security.auth.Subject;
import org.apache.log4j.Level;
Expand All @@ -92,6 +90,8 @@
import org.opencadc.vospace.NodeProperty;
import org.opencadc.vospace.VOS;
import org.opencadc.vospace.VOSURI;
import org.opencadc.vospace.client.async.RecursiveDeleteNode;
import org.opencadc.vospace.client.async.RecursiveSetNode;
import org.opencadc.vospace.transfer.Direction;
import org.opencadc.vospace.transfer.Protocol;
import org.opencadc.vospace.transfer.Transfer;
Expand All @@ -112,14 +112,16 @@ public class VOSpaceClientTest extends VOSTest {
Log4jInit.setLevel("ca.nrc.cadc.net", Level.INFO);
}

private static URI RESOURCE_ID = URI.create("ivo://opencadc.org/cavern");
//private static URI RESOURCE_ID = URI.create("ivo://opencadc.org/cavern");
//private String baseURI = "vos://opencadc.org~cavern/client-int-tests";
//private boolean linksSupportProps = false;
private static URI RESOURCE_ID = URI.create("ivo://opencadc.org/vault");
private String baseURI = "vos://opencadc.org~vault/client-int-tests";
private boolean linksSupportProps = true;

private static File CERT = FileUtil.getFileFromResource(
System.getProperty("user.name") + ".pem", VOSpaceClientTest.class);

private String baseURI = "vos://opencadc.org~cavern/client-int-tests";


public VOSpaceClientTest() {
super(RESOURCE_ID, CERT);
super.rootTestFolderName = "client-int-tests";
Expand Down Expand Up @@ -320,12 +322,14 @@ public void linkNodeTest() throws Exception {
Assert.assertEquals(orig.getTarget(), actual.getTarget());

// failed update
orig.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DESCRIPTION, "the missing link"));
try {
mod = client.setNode(target, orig);
Assert.fail("expected IllegalArgumentException but got: " + mod);
} catch (IllegalArgumentException ex) {
log.info("caught expected: " + ex);
if (!linksSupportProps) {
orig.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DESCRIPTION, "the missing link"));
try {
mod = client.setNode(target, orig);
Assert.fail("expected IllegalArgumentException but got: " + mod);
} catch (IllegalArgumentException ex) {
log.info("caught expected: " + ex);
}
}

// delete
Expand Down Expand Up @@ -360,6 +364,7 @@ public void fileRountTripTest() throws Exception {
Protocol p = new Protocol(VOS.PROTOCOL_HTTPS_PUT);
p.setSecurityMethod(Standards.SECURITY_METHOD_CERT);
push.getProtocols().add(p);
push.getProtocols().add(new Protocol(VOS.PROTOCOL_HTTPS_PUT)); // anon for preauth
ClientTransfer putTrans = client.createTransfer(push);
putTrans.setFile(srcFile);
putTrans.run();
Expand Down Expand Up @@ -451,10 +456,10 @@ public void recursiveSetPropsTest() throws Exception {
// update
orig.isPublic = true;
orig.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_DESCRIPTION, "my stuff"));
ClientRecursiveSetNode rec = client.setNodeRecursive(target, orig);
RecursiveSetNode rec = client.createRecursiveSetNode(target, orig);
rec.setMonitor(true);
rec.run();
log.info("job result: " + rec.getPhase() + " " + rec.getThrowable());
log.info("job result: " + rec.getPhase() + " " + rec.getException());

// get
Node cn1 = client.getNode(t1.getPath());
Expand Down Expand Up @@ -482,4 +487,73 @@ public void recursiveSetPropsTest() throws Exception {
return null;
});
}

@Test
public void testRecursiveDelete() throws Exception {
VOSpaceClient client = new VOSpaceClient(resourceID);
ContainerNode orig = new ContainerNode("testRecursiveDelete");
VOSURI target = new VOSURI(baseURI + "/" + orig.getName());

ContainerNode c1 = new ContainerNode("c1");
VOSURI t1 = new VOSURI(baseURI + "/" + orig.getName() + "/" + c1.getName());
ContainerNode c2 = new ContainerNode("c2");
VOSURI t2 = new VOSURI(baseURI + "/" + orig.getName() + "/" + c2.getName());

Subject.doAs(authSubject, (PrivilegedExceptionAction<Void>) () -> {
// cleanup
try {
client.deleteNode(t1.getPath());
} catch (ResourceNotFoundException ignore) {
log.info("cleanup: " + ignore);
}
try {
client.deleteNode(t2.getPath());
} catch (ResourceNotFoundException ignore) {
log.info("cleanup: " + ignore);
}
try {
client.deleteNode(target.getPath());
} catch (ResourceNotFoundException ignore) {
log.info("cleanup: " + ignore);
}

// create
Node created = client.createNode(target, orig);
log.info("created: " + created);

// get
Node n1 = client.getNode(target.getPath());
log.info("found: " + n1);
Assert.assertNotNull(n1);
Assert.assertEquals(orig.getName(), n1.getName());
Assert.assertEquals(orig.getClass(), n1.getClass());

// create children
client.createNode(t1, c1);
client.createNode(t2, c2);

// get
Node cn1 = client.getNode(t1.getPath());
log.info("found: " + cn1 + " with public=" + cn1.isPublic);
Assert.assertNotNull(cn1);

Node cn2 = client.getNode(t1.getPath());
log.info("found: " + cn2 + " with public=" + cn2.isPublic);
Assert.assertNotNull(cn2);

// delete
RecursiveDeleteNode rec = client.createRecursiveDelete(target);
rec.setMonitor(true);
rec.run();
log.info("job result: " + rec.getPhase() + " " + rec.getException());

try {
client.getNode(target.getPath());
} catch (ResourceNotFoundException ex) {
log.info("caught expected: " + ex);
}

return null;
});
}
}
Loading
Loading