Client enhancements

This commit is contained in:
Fabio Sinibaldi 2020-12-01 13:24:54 +01:00
parent 1ef145d815
commit 44411ec195
5 changed files with 105 additions and 34 deletions

View File

@ -2,6 +2,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for org.gcube.data.transfer.data-transfer-library
##[v1.2.3-SNAPSHOT] 2020-12-01
* Deletion method
* GetInfo method
* GetStream method
##[v1.2.2] 2020-07-16
### Fixes

28
pom.xml
View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>data-transfer-library</artifactId>
<version>1.2.2</version>
<version>1.2.3-SNAPSHOT</version>
<name>DataTransfer-library</name>
<description>Data Transfer Service client library</description>
@ -53,19 +53,19 @@
<dependency>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>data-transfer-model</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<version>[1.0.0,2.0.0)</version>
</dependency>
<!-- STORAGE -->
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<version>[2.0.0, 3.0.0)</version>
</dependency>
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<version>[2.0.0, 3.0.0)</version>
</dependency>
@ -94,26 +94,6 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.fasterxml.jackson.core</groupId> -->
<!-- <artifactId>jackson-core</artifactId> -->
<!-- <version>2.8.4</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>com.fasterxml.jackson.core</groupId> -->
<!-- <artifactId>jackson-annotations</artifactId> -->
<!-- <version>2.8.4</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>com.fasterxml.jackson.core</groupId> -->
<!-- <artifactId>jackson-databind</artifactId> -->
<!-- <version>2.8.4</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<!-- TEST -->
<dependency>

View File

@ -1,5 +1,7 @@
package org.gcube.data.transfer.library.client;
import java.io.InputStream;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
@ -9,6 +11,7 @@ import javax.ws.rs.core.Response;
import org.gcube.data.transfer.library.faults.CommunicationException;
import org.gcube.data.transfer.library.faults.RemoteServiceException;
import org.gcube.data.transfer.library.faults.ServiceNotFoundException;
import org.gcube.data.transfer.model.RemoteFileDescriptor;
import org.gcube.data.transfer.model.ServiceConstants;
import org.gcube.data.transfer.model.TransferCapabilities;
import org.gcube.data.transfer.model.TransferRequest;
@ -87,11 +90,57 @@ public class Client {
}
}
protected void checkResponse(Response toCheck) throws Exception{
switch(toCheck.getStatusInfo().getFamily()){
case SUCCESSFUL : break;
default : throw new Exception("Unexpected Response code : "+toCheck.getStatus());
}
}
public void delete(RemoteFileDescriptor remote) throws RemoteServiceException {
delete(remote.getPersistenceId()+"/"+remote.getPath());
}
public RemoteFileDescriptor getInfo(RemoteFileDescriptor remote) throws RemoteServiceException {
return getInfo(remote.getPersistenceId()+"/"+remote.getPath());
}
public InputStream getInputStream(RemoteFileDescriptor remote) throws RemoteServiceException {
return getInputStream(remote.getPersistenceId()+"/"+remote.getPath());
}
public void delete(String path) throws RemoteServiceException {
log.debug("Deleting {} at []",path,endpoint);
try {
Response resp=rootTarget.path(ServiceConstants.REST_SERVLET_NAME).path(path).request().delete();
checkResponse(resp);
}catch(Exception e){
throw new RemoteServiceException(e);
}
}
public RemoteFileDescriptor getInfo(String path) throws RemoteServiceException {
log.debug("GetInfo of {} at []",path,endpoint);
try {
Response resp= rootTarget.path(ServiceConstants.REST_SERVLET_NAME).path(path).queryParam("descriptor",true).request(MediaType.APPLICATION_JSON_TYPE).get();
checkResponse(resp);
return resp.readEntity(RemoteFileDescriptor.class);
}catch(Exception e){
throw new RemoteServiceException(e);
}
}
public InputStream getInputStream(String path) throws RemoteServiceException {
log.debug("Get InputStream of {} at []",path,endpoint);
try {
Response resp=rootTarget.path(ServiceConstants.REST_SERVLET_NAME).path(path).queryParam("descriptor",true).request().get();
checkResponse(resp);
return resp.readEntity(InputStream.class);
}catch(Exception e){
throw new RemoteServiceException(e);
}
}
}

View File

@ -14,6 +14,7 @@ import org.gcube.data.transfer.library.faults.RemoteServiceException;
import org.gcube.data.transfer.library.faults.ServiceNotFoundException;
import org.gcube.data.transfer.model.Destination;
import org.gcube.data.transfer.model.DestinationClashPolicy;
import org.gcube.data.transfer.model.RemoteFileDescriptor;
import org.gcube.data.transfer.model.ServiceConstants;
import org.gcube.data.transfer.model.TransferCapabilities;
import org.gcube.data.transfer.model.TransferRequest;
@ -28,11 +29,10 @@ import org.junit.Test;
public class TestClientCalls {
// static String hostname="http://thredds-d-d4s.d4science.org:80";
static String hostname="https://geoserver1.dev.d4science.org";
// static String hostname="https://geoserver1-spatial-dev.d4science.org";
static String scope="/gcube/devNext/NextNext";
// static String scope="/pred4s/preprod/preVRE";
// static String hostname="https://thredds-pre-d4s.d4science.org";
static String hostname="https://geoserver1.dev.d4science.org";
static String scope="/gcube/devsec/devVRE";
static Client client;
@ -48,15 +48,25 @@ public class TestClientCalls {
System.out.println(client.getCapabilties());
}
// @Test
// public void list() throws RemoteServiceException, CommunicationException {
// for(String persistanceID:client.getCapabilties().getAvailablePersistenceIds())
// System.out.println(client.getInfo(persistanceID));
// }
@Test
public void doTheTransfer() throws MalformedURLException, RemoteServiceException{
Destination dest=new Destination("outputFile");
System.out.println("Transferred "+transfer());
}
private RemoteFileDescriptor transfer() throws RemoteServiceException, MalformedURLException {
Destination dest=new Destination("readme.md");
dest.setCreateSubfolders(true);
dest.setSubFolder("bla/bla/bllaaa");
dest.setOnExistingFileName(DestinationClashPolicy.ADD_SUFFIX);
dest.setOnExistingSubFolder(DestinationClashPolicy.APPEND);
TransferRequest request= new TransferRequest("", new HttpDownloadSettings(new URL("http://no.com"), HttpDownloadOptions.DEFAULT),dest);
TransferRequest request= new TransferRequest("", new HttpDownloadSettings(new URL("https://code-repo.d4science.org/gCubeSystem/data-transfer-library/raw/branch/master/README.md"), HttpDownloadOptions.DEFAULT),dest);
System.out.println("Submitting "+request);
TransferTicket ticket=client.submit(request);
System.out.println("Ticket is "+ticket);
@ -70,9 +80,11 @@ public class TestClientCalls {
Thread.sleep(1000);
}catch(InterruptedException e){}
}while(continuePolling);
Destination result=ticket.getDestinationSettings();
return client.getInfo(result.getPersistenceId()+"/"+dest.getSubFolder()+ticket.getDestinationFileName().substring(ticket.getDestinationFileName().lastIndexOf("/")));
}
@Test
public void directCall(){
@ -89,4 +101,28 @@ public class TestClientCalls {
System.out.println(cap.getAvailablePersistenceIds());
}
@Test
public void delete() throws RemoteServiceException, MalformedURLException {
RemoteFileDescriptor remote=transfer();
client.delete(remote);
// try to delete parent
client.delete(remote.getPersistenceId()+"/"+remote.getPath());
}
@Test
public void openStream() throws RemoteServiceException, MalformedURLException {
RemoteFileDescriptor remote=transfer();
client.getInputStream(remote);
//try stream parent
client.getInputStream(remote.getPersistenceId()+"/"+remote.getPath());
}
@Test
public void inspect() throws RemoteServiceException, MalformedURLException {
transfer();
RemoteFileDescriptor remote=transfer();
System.out.println("Remote folder children are : "+client.getInfo(remote.getPersistenceId()+"/"+remote.getPath()));
client.getInfo(remote);
}
}

View File

@ -32,9 +32,9 @@ import org.junit.Test;
public class TransfererTest {
static String hostname="http://geoserver1.dev.d4science.org:80";
static String hostname="http://geoserver1.dev.d4science.org";
// static String nodeId="462b68c5-463f-4295-86da-37d6c0abc7ea";
static String scope="/gcube/devsec/devVRE";
static String scope="/gcube/devNext/NextNext";
static DataTransferClient client;