From 0b7fd994a45cbffb9b5b6583f12b2c53ff9d002f Mon Sep 17 00:00:00 2001 From: "fabio.sinibaldi" Date: Tue, 22 Nov 2016 11:29:05 +0000 Subject: [PATCH] release 4.2 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-model/1.2@134512 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 36 +++ .project | 23 ++ .settings/org.eclipse.core.resources.prefs | 6 + .settings/org.eclipse.jdt.core.prefs | 5 + .settings/org.eclipse.m2e.core.prefs | 4 + distro/LICENSE | 1 + distro/README | 65 ++++++ distro/changelog.xml | 12 + distro/descriptor.xml | 30 +++ distro/profile.xml | 29 +++ pom.xml | 114 ++++++++++ .../data/transfer/model/Destination.java | 50 ++++ .../model/DestinationClashPolicy.java | 10 + .../transfer/model/PluginDescription.java | 61 +++++ .../data/transfer/model/PluginInvocation.java | 33 +++ .../data/transfer/model/ServiceConstants.java | 18 ++ .../transfer/model/TransferCapabilities.java | 148 ++++++++++++ .../data/transfer/model/TransferRequest.java | 111 +++++++++ .../data/transfer/model/TransferTicket.java | 90 ++++++++ .../model/options/DirectTransferOptions.java | 44 ++++ .../model/options/HttpDownloadOptions.java | 50 ++++ .../data/transfer/model/options/Range.java | 31 +++ .../model/options/TransferOptions.java | 41 ++++ .../settings/DirectTransferSettings.java | 49 ++++ .../model/settings/HttpDownloadSettings.java | 57 +++++ .../model/settings/TransferSettings.java | 28 +++ .../model/utils/CapabilitiesUtils.java | 19 ++ .../model/utils/DateFormatterAdapter.java | 29 +++ .../transfer/model/utils/DateWrapper.java | 93 ++++++++ .../transfer/test/MarshallUnmarshalTest.java | 215 ++++++++++++++++++ 30 files changed, 1502 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.core.resources.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 distro/LICENSE create mode 100644 distro/README create mode 100644 distro/changelog.xml create mode 100644 distro/descriptor.xml create mode 100644 distro/profile.xml create mode 100644 pom.xml create mode 100644 src/main/java/org/gcube/data/transfer/model/Destination.java create mode 100644 src/main/java/org/gcube/data/transfer/model/DestinationClashPolicy.java create mode 100644 src/main/java/org/gcube/data/transfer/model/PluginDescription.java create mode 100644 src/main/java/org/gcube/data/transfer/model/PluginInvocation.java create mode 100644 src/main/java/org/gcube/data/transfer/model/ServiceConstants.java create mode 100644 src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java create mode 100644 src/main/java/org/gcube/data/transfer/model/TransferRequest.java create mode 100644 src/main/java/org/gcube/data/transfer/model/TransferTicket.java create mode 100644 src/main/java/org/gcube/data/transfer/model/options/DirectTransferOptions.java create mode 100644 src/main/java/org/gcube/data/transfer/model/options/HttpDownloadOptions.java create mode 100644 src/main/java/org/gcube/data/transfer/model/options/Range.java create mode 100644 src/main/java/org/gcube/data/transfer/model/options/TransferOptions.java create mode 100644 src/main/java/org/gcube/data/transfer/model/settings/DirectTransferSettings.java create mode 100644 src/main/java/org/gcube/data/transfer/model/settings/HttpDownloadSettings.java create mode 100644 src/main/java/org/gcube/data/transfer/model/settings/TransferSettings.java create mode 100644 src/main/java/org/gcube/data/transfer/model/utils/CapabilitiesUtils.java create mode 100644 src/main/java/org/gcube/data/transfer/model/utils/DateFormatterAdapter.java create mode 100644 src/main/java/org/gcube/data/transfer/model/utils/DateWrapper.java create mode 100644 src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e43402f --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..3e92996 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + data-transfer-model + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..29abf99 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,6 @@ +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ec4300d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..ff7698f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=false +version=1 diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..2d9616a --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1 @@ +${gcube.license} \ No newline at end of file diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..12bcf19 --- /dev/null +++ b/distro/README @@ -0,0 +1,65 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + + +Authors +-------------------------------------------------- + +* Fabio Sinibaldi (fabio.sinibaldi-AT-isti.cnr.it) Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + +Maintainers +----------- + +* Fabio Sinibaldi (fabio.sinibaldi-AT-isti.cnr.it) Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy). + + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + +Installation +-------------------------------------------------- + +Installation documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot}/Data_Transfer_2 + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot}/Data_Transfer_2 + ${gcube.wikiRoot}/How_to_use_Data_Transfer_2 + + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. \ No newline at end of file diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..c152524 --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,12 @@ + + + First Release + + + Added Destination + Added Plugin + + + Improved Plugin handling + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..dc46ade --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,30 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + changelog.xml + + 755 + true + + + + + target/${build.finalName}.${project.packaging} + /${artifactId} + + + \ No newline at end of file diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..429a22e --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,29 @@ + + + + Service + + ${description} + DataTransfer + ${artifactId} + 1.0.0 + + + ${description} + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + library + + ${build.finalName}.jar + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2c17fa9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,114 @@ + + 4.0.0 + + org.gcube.tools + maven-parent + LATEST + + org.gcube.data.transfer + data-transfer-model + 1.2.0-SNAPSHOT + Data Transfer Model + Common model used by Data Transfer Service facilities + + + ${project.basedir}/distro + http://svn.research-infrastructures.eu/d4science/gcube/trunk/data-transfer/${project.artifactId} + + + + + scm:svn:${svnBaseUrl}/${project.artifactId} + scm:svn:${svnBaseUrl}/${project.artifactId} + ${svnBaseUrl}/${project.artifactId} + + + + + + + org.gcube.distribution + gcube-bom + LATEST + pom + import + + + + + + + junit + junit + 4.10 + test + + + + + org.projectlombok + lombok + 1.14.8 + + + org.slf4j + slf4j-api + + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + * + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/data/transfer/model/Destination.java b/src/main/java/org/gcube/data/transfer/model/Destination.java new file mode 100644 index 0000000..7383a6b --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/Destination.java @@ -0,0 +1,50 @@ +package org.gcube.data.transfer.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class Destination { + + public static final String DEFAULT_PERSISTENCE_ID="DEFAULT"; + + + @XmlElement + private String persistenceId=DEFAULT_PERSISTENCE_ID; + @XmlElement + private String subFolder=null; + @NonNull + @XmlElement + private String destinationFileName=null; + @XmlElement + private Boolean createSubfolders=false; + @XmlElement + private DestinationClashPolicy onExistingFileName=DestinationClashPolicy.ADD_SUFFIX; + @XmlElement + private DestinationClashPolicy onExistingSubFolder=DestinationClashPolicy.APPEND; + + public Destination(String destinationFileName) { + super(); + this.destinationFileName = destinationFileName; + } + + public Destination(String subFolder, String destinationFileName) { + super(); + this.subFolder = subFolder; + this.destinationFileName = destinationFileName; + this.createSubfolders=true; + } + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/DestinationClashPolicy.java b/src/main/java/org/gcube/data/transfer/model/DestinationClashPolicy.java new file mode 100644 index 0000000..a3c83bc --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/DestinationClashPolicy.java @@ -0,0 +1,10 @@ +package org.gcube.data.transfer.model; + +public enum DestinationClashPolicy { + + FAIL, + REWRITE, + ADD_SUFFIX, + APPEND + +} diff --git a/src/main/java/org/gcube/data/transfer/model/PluginDescription.java b/src/main/java/org/gcube/data/transfer/model/PluginDescription.java new file mode 100644 index 0000000..17c1ee3 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/PluginDescription.java @@ -0,0 +1,61 @@ +package org.gcube.data.transfer.model; + +import java.util.Map; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlID; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class PluginDescription { + + @XmlID + private String id; + @XmlElement + private String description; + @XmlElement + private Map parameters; + + + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PluginDescription other = (PluginDescription) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/PluginInvocation.java b/src/main/java/org/gcube/data/transfer/model/PluginInvocation.java new file mode 100644 index 0000000..3850f8e --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/PluginInvocation.java @@ -0,0 +1,33 @@ +package org.gcube.data.transfer.model; + +import java.util.Map; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlID; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class PluginInvocation { + + + public static final String DESTINATION_FILE_PATH="*******USE_DESTINATION_FILE_PATH*********"; + + @XmlID + private String pluginId; + @XmlElement + private Map parameters; +} diff --git a/src/main/java/org/gcube/data/transfer/model/ServiceConstants.java b/src/main/java/org/gcube/data/transfer/model/ServiceConstants.java new file mode 100644 index 0000000..7702a9e --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/ServiceConstants.java @@ -0,0 +1,18 @@ +package org.gcube.data.transfer.model; + +public class ServiceConstants { + + public static final String APPLICATION_PATH="/gcube/service/"; + + //Servlets + public static final String CAPABILTIES_SERVLET_NAME="Capabilities"; + public static final String REQUESTS_SERVLET_NAME="Requests"; + public static final String STATUS_SERVLET_NAME="TransferStatus"; + + //Params + public static final String TRANSFER_REQUEST_OBJECT="request-object"; + public static final String TRANSFER_ID="transfer-id"; + + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java b/src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java new file mode 100644 index 0000000..d2c5b11 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java @@ -0,0 +1,148 @@ +package org.gcube.data.transfer.model; + +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlID; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.Synchronized; +import lombok.ToString; + +import org.gcube.data.transfer.model.options.DirectTransferOptions; +import org.gcube.data.transfer.model.options.HttpDownloadOptions; +import org.gcube.data.transfer.model.options.TransferOptions; + + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class TransferCapabilities { + + @XmlID + private String nodeId; + @XmlElement + private String hostName; + @XmlElement + private Integer port; + + @XmlElementWrapper + @XmlElementRefs({ + @XmlElementRef(type = DirectTransferOptions.class), + @XmlElementRef(type = HttpDownloadOptions.class), + }) + private Set availableMeans; + + @XmlElementWrapper + private Set availablePlugins; + + @XmlElementWrapper + private Set availablePersistenceIds; + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + if(availableMeans!=null){ + for(TransferOptions opt:availableMeans) + result=prime*result+((opt==null)?0:opt.hashCode()); + } + + if(availablePlugins!=null){ + for(PluginDescription opt:availablePlugins) + result=prime*result+((opt==null)?0:opt.hashCode()); + } + + result = prime * result + + ((nodeId == null) ? 0 : nodeId.hashCode()); + result = prime * result + + ((hostName == null) ? 0 : hostName.hashCode()); + result = prime * result + + ((port == null) ? 0 : port.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TransferCapabilities other = (TransferCapabilities) obj; + + + //Check capabilities + if ((availableMeans == null || availableMeans.isEmpty())) + if(other.availableMeans!=null&& (!other.availableMeans.isEmpty())) + return false; + else if(availableMeans!=null && (!availableMeans.isEmpty())) + if(other.availableMeans==null || other.availableMeans.isEmpty()) + return false; + else if(availableMeans.size()!=other.availableMeans.size()) + return false; + else for(TransferOptions opt:availableMeans) + if(!other.availableMeans.contains(opt)) + return false; + + + //Check plugins + if ((availablePlugins == null || availablePlugins.isEmpty())) + if(other.availablePlugins!=null&& (!other.availablePlugins.isEmpty())) + return false; + else if(availablePlugins!=null && (!availablePlugins.isEmpty())) + if(other.availablePlugins==null || other.availablePlugins.isEmpty()) + return false; + else if(availablePlugins.size()!=other.availablePlugins.size()) + return false; + else for(PluginDescription opt:availablePlugins) + if(!other.availablePlugins.contains(opt)) + return false; + + + + if (nodeId == null) { + if (other.nodeId != null) + return false; + } else if (!nodeId.equals(other.nodeId)) + return false; + + if (hostName == null) { + if (other.hostName != null) + return false; + } else if (!hostName.equals(other.hostName)) + return false; + + if (port == null) { + if (other.port != null) + return false; + } else if (!port.equals(other.port)) + return false; + + + return true; + } + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/TransferRequest.java b/src/main/java/org/gcube/data/transfer/model/TransferRequest.java new file mode 100644 index 0000000..4afef4a --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/TransferRequest.java @@ -0,0 +1,111 @@ +package org.gcube.data.transfer.model; + +import java.util.Collections; +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlElementRefs; +import javax.xml.bind.annotation.XmlElementWrapper; +import javax.xml.bind.annotation.XmlID; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gcube.data.transfer.model.options.TransferOptions; +import org.gcube.data.transfer.model.settings.DirectTransferSettings; +import org.gcube.data.transfer.model.settings.HttpDownloadSettings; +import org.gcube.data.transfer.model.settings.TransferSettings; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class TransferRequest{ + + + @XmlID + private String id; + @XmlElementRefs({ + @XmlElementRef(type = DirectTransferSettings.class), + @XmlElementRef(type = HttpDownloadSettings.class), + }) + private TransferSettings settings; + + @XmlElement + private Destination destinationSettings; + + @XmlElementWrapper + private Set pluginInvocations; + + + public TransferRequest(String id, TransferSettings settings, Destination destinationSettings) { + super(); + this.id = id; + this.settings = settings; + this.destinationSettings = destinationSettings; + this.pluginInvocations=Collections.emptySet(); + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TransferRequest other = (TransferRequest) obj; + if (destinationSettings == null) { + if (other.destinationSettings != null) + return false; + } else if (!destinationSettings.equals(other.destinationSettings)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + + + //Check plugins + if ((pluginInvocations == null || pluginInvocations.isEmpty())) + if(other.pluginInvocations!=null&& (!other.pluginInvocations.isEmpty())) + return false; + else if(pluginInvocations!=null && (!pluginInvocations.isEmpty())) + if(other.pluginInvocations==null || other.pluginInvocations.isEmpty()) + return false; + else if(pluginInvocations.size()!=other.pluginInvocations.size()) + return false; + else for(PluginInvocation opt:pluginInvocations) + if(!other.pluginInvocations.contains(opt)) + return false; + return true; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((destinationSettings == null) ? 0 : destinationSettings.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + if(pluginInvocations!=null){ + for(PluginInvocation opt:pluginInvocations) + result=prime*result+((opt==null)?0:opt.hashCode()); + } + result = prime * result + ((settings == null) ? 0 : settings.hashCode()); + return result; + } + + + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/TransferTicket.java b/src/main/java/org/gcube/data/transfer/model/TransferTicket.java new file mode 100644 index 0000000..f1f917f --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/TransferTicket.java @@ -0,0 +1,90 @@ +package org.gcube.data.transfer.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import org.gcube.data.transfer.model.utils.DateWrapper; + +@Data +@EqualsAndHashCode(callSuper=false) +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class TransferTicket extends TransferRequest{ + + + @XmlEnum + public static enum Status{ + PENDING, + WAITING, // transfer ready, waiting for sender + TRANSFERRING, + SUCCESS, + ERROR, + STOPPED, + PLUGIN_EXECUTION + } + + @XmlElement + private Status status; + @XmlElement + private long transferredBytes; + @XmlElement + private double percent; + @XmlElement + private long averageTransferSpeed; + @XmlElement + private DateWrapper submissionTime; + @XmlElement + private String destinationFileName; + @XmlElement + private String message; + +// +// public TransferTicket(String id, TransferOptions options, Status status, +// long transferredBytes, double percent, long averageTransferSpeed, +// DateWrapper submissionTime,String destinationFileName) { +// super(id, options); +// this.status = status; +// this.transferredBytes = transferredBytes; +// this.percent = percent; +// this.averageTransferSpeed = averageTransferSpeed; +// this.submissionTime = submissionTime; +// this.destinationFileName=destinationFileName; +// } + + public TransferTicket(TransferRequest request, Status status, + long transferredBytes, double percent, long averageTransferSpeed, + DateWrapper submissionTime,String destinationFileName,String message) { + super(request.getId(), request.getSettings(),request.getDestinationSettings(),request.getPluginInvocations()); + this.status = status; + this.transferredBytes = transferredBytes; + this.percent = percent; + this.averageTransferSpeed = averageTransferSpeed; + this.submissionTime = submissionTime; + this.destinationFileName=destinationFileName; + } + + + public TransferTicket(TransferRequest request){ + super(request.getId(),request.getSettings(),request.getDestinationSettings(),request.getPluginInvocations()); + this.status=Status.PENDING; + this.transferredBytes=0l; + this.averageTransferSpeed=0l; + this.destinationFileName="/dev/null"; + this.percent=0d; + this.submissionTime=DateWrapper.getInstance(); + this.message=""; + } + + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/options/DirectTransferOptions.java b/src/main/java/org/gcube/data/transfer/model/options/DirectTransferOptions.java new file mode 100644 index 0000000..0a5ba48 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/options/DirectTransferOptions.java @@ -0,0 +1,44 @@ +package org.gcube.data.transfer.model.options; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Data +@EqualsAndHashCode(callSuper=false) +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class DirectTransferOptions extends TransferOptions { + + @XmlElement + private String source; + + @Override + public List getAvailableProtocols() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Range getAvailableRange() { + // TODO Auto-generated method stub + return null; + } + + + @Override + public TransferMethod getMethod() { + return TransferMethod.DirectTransfer; + } + +} diff --git a/src/main/java/org/gcube/data/transfer/model/options/HttpDownloadOptions.java b/src/main/java/org/gcube/data/transfer/model/options/HttpDownloadOptions.java new file mode 100644 index 0000000..b374993 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/options/HttpDownloadOptions.java @@ -0,0 +1,50 @@ +package org.gcube.data.transfer.model.options; + +import java.util.Arrays; +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Data +@EqualsAndHashCode(callSuper=false) +@AllArgsConstructor +@NoArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class HttpDownloadOptions extends TransferOptions { + + + public static final HttpDownloadOptions DEFAULT=new HttpDownloadOptions(Range.ONLY_80); + + @XmlElement + private Range range; + + @Override + public TransferMethod getMethod() { + return TransferOptions.TransferMethod.HTTPDownload; + } + + + @Override + public List getAvailableProtocols() { + return Arrays.asList(new Protocol[]{ + Protocol.HTTP + }); + } + + + + @Override + public Range getAvailableRange() { + return range; + } + +} diff --git a/src/main/java/org/gcube/data/transfer/model/options/Range.java b/src/main/java/org/gcube/data/transfer/model/options/Range.java new file mode 100644 index 0000000..0d93d35 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/options/Range.java @@ -0,0 +1,31 @@ +package org.gcube.data.transfer.model.options; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Data +@EqualsAndHashCode(callSuper=false) +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class Range { + + public final static Range ONLY_80=new Range(80,80); + + + @XmlElement + private int min; + @XmlElement + private int max; + + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/options/TransferOptions.java b/src/main/java/org/gcube/data/transfer/model/options/TransferOptions.java new file mode 100644 index 0000000..e234cba --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/options/TransferOptions.java @@ -0,0 +1,41 @@ +package org.gcube.data.transfer.model.options; + +import java.util.List; + +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode +@XmlRootElement +@XmlSeeAlso({HttpDownloadOptions.class,DirectTransferOptions.class}) +public abstract class TransferOptions { + + public static enum TransferMethod{ + HTTPDownload, + DirectTransfer + } + + public static enum Protocol{ + HTTP, + TCP, + UDP, + SMP + } + + + public abstract TransferMethod getMethod(); + + + public abstract List getAvailableProtocols(); + + + + public abstract Range getAvailableRange(); + + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/settings/DirectTransferSettings.java b/src/main/java/org/gcube/data/transfer/model/settings/DirectTransferSettings.java new file mode 100644 index 0000000..490d3b3 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/settings/DirectTransferSettings.java @@ -0,0 +1,49 @@ +package org.gcube.data.transfer.model.settings; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import org.gcube.data.transfer.model.options.DirectTransferOptions; +import org.gcube.data.transfer.model.options.Range; +import org.gcube.data.transfer.model.options.TransferOptions.Protocol; + + +@Data +@EqualsAndHashCode(callSuper=false) +@AllArgsConstructor +@NoArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class DirectTransferSettings extends TransferSettings { + + + + @XmlElement + private DirectTransferOptions options; + + + @Override + public Range getToUseRange() { + return Range.ONLY_80; + } + + @Override + public DirectTransferOptions getOptions() { + return options; + } + + @Override + public Protocol getToUseProtocol() { + // TODO Auto-generated method stub + return null; + } + + +} diff --git a/src/main/java/org/gcube/data/transfer/model/settings/HttpDownloadSettings.java b/src/main/java/org/gcube/data/transfer/model/settings/HttpDownloadSettings.java new file mode 100644 index 0000000..498075c --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/settings/HttpDownloadSettings.java @@ -0,0 +1,57 @@ +package org.gcube.data.transfer.model.settings; + +import java.net.URL; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import org.gcube.data.transfer.model.options.HttpDownloadOptions; +import org.gcube.data.transfer.model.options.Range; +import org.gcube.data.transfer.model.options.TransferOptions.Protocol; + + +@Data +@EqualsAndHashCode(callSuper=false) +@AllArgsConstructor +@NoArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class HttpDownloadSettings extends TransferSettings { + + + + @XmlElement + private URL source; + + @XmlElement + private HttpDownloadOptions options; + + + + @Override + public Protocol getToUseProtocol() { + return Protocol.HTTP; + } + + + @Override + public HttpDownloadOptions getOptions() { + return options; + } + + + + + @Override + public Range getToUseRange() { + return Range.ONLY_80; + } + +} diff --git a/src/main/java/org/gcube/data/transfer/model/settings/TransferSettings.java b/src/main/java/org/gcube/data/transfer/model/settings/TransferSettings.java new file mode 100644 index 0000000..ec4e260 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/settings/TransferSettings.java @@ -0,0 +1,28 @@ +package org.gcube.data.transfer.model.settings; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSeeAlso; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import org.gcube.data.transfer.model.options.Range; +import org.gcube.data.transfer.model.options.TransferOptions; +import org.gcube.data.transfer.model.options.TransferOptions.Protocol; + +@Data +@EqualsAndHashCode +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +@XmlSeeAlso({HttpDownloadSettings.class,DirectTransferSettings.class}) +public abstract class TransferSettings { + + public abstract T getOptions(); + + public abstract Protocol getToUseProtocol(); + + public abstract Range getToUseRange(); + +} diff --git a/src/main/java/org/gcube/data/transfer/model/utils/CapabilitiesUtils.java b/src/main/java/org/gcube/data/transfer/model/utils/CapabilitiesUtils.java new file mode 100644 index 0000000..db4083c --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/utils/CapabilitiesUtils.java @@ -0,0 +1,19 @@ +package org.gcube.data.transfer.model.utils; + +import java.util.HashSet; +import java.util.Set; + +import org.gcube.data.transfer.model.options.HttpDownloadOptions; +import org.gcube.data.transfer.model.options.TransferOptions; + +public class CapabilitiesUtils { + + + + + public static Set scanSystem(){ + Set availableMeans=new HashSet<>(); + availableMeans.add(HttpDownloadOptions.DEFAULT); + return availableMeans; + } +} diff --git a/src/main/java/org/gcube/data/transfer/model/utils/DateFormatterAdapter.java b/src/main/java/org/gcube/data/transfer/model/utils/DateFormatterAdapter.java new file mode 100644 index 0000000..2da956f --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/utils/DateFormatterAdapter.java @@ -0,0 +1,29 @@ +package org.gcube.data.transfer.model.utils; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +public class DateFormatterAdapter extends XmlAdapter { + + @Override + public String marshal(Calendar cal) throws Exception { + GregorianCalendar c = new GregorianCalendar(); + c.setTime(cal.getTime()); + XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); + return date2.toXMLFormat(); + } + + @Override + public Calendar unmarshal(String date) throws Exception { + XMLGregorianCalendar gregorianDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(date); + Calendar cal = Calendar.getInstance(); + cal.setTime(gregorianDate.toGregorianCalendar().getTime()); + return cal; + + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/data/transfer/model/utils/DateWrapper.java b/src/main/java/org/gcube/data/transfer/model/utils/DateWrapper.java new file mode 100644 index 0000000..5095b31 --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/utils/DateWrapper.java @@ -0,0 +1,93 @@ +package org.gcube.data.transfer.model.utils; + +import java.util.Calendar; +import java.util.GregorianCalendar; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + + + +@XmlAccessorType(XmlAccessType.NONE) +@AllArgsConstructor +@NoArgsConstructor +@Setter +@Getter +@Slf4j +public class DateWrapper { + + static DatatypeFactory factory=null; + + static { + try{ + factory=DatatypeFactory.newInstance(); + }catch(Exception e){ + log.error("Unexpected exception ",e); + } + + + } + + public static DateWrapper getInstance(){ + return new DateWrapper(Calendar.getInstance()); + } + + +// static SimpleDateFormat dateFormat = new SimpleDateFormat(); + + + @XmlJavaTypeAdapter(DateFormatterAdapter.class) + @XmlElement + public Calendar value; + + + @Override + public String toString() { + // not all the date are mandatory, if a date is optional the value is null + if(value != null){ + GregorianCalendar c = new GregorianCalendar(); + c.setTime(value.getTime()); + XMLGregorianCalendar date2 = factory.newXMLGregorianCalendar(c); + return date2.toXMLFormat(); + } + else + return ""; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DateWrapper other = (DateWrapper) obj; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + +} diff --git a/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java new file mode 100644 index 0000000..a261a25 --- /dev/null +++ b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java @@ -0,0 +1,215 @@ +package org.gcube.data.transfer.test; + +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Collections; +import java.util.HashMap; +import java.util.UUID; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; + +import org.gcube.data.transfer.model.Destination; +import org.gcube.data.transfer.model.PluginDescription; +import org.gcube.data.transfer.model.PluginInvocation; +import org.gcube.data.transfer.model.TransferCapabilities; +import org.gcube.data.transfer.model.TransferRequest; +import org.gcube.data.transfer.model.TransferTicket; +import org.gcube.data.transfer.model.TransferTicket.Status; +import org.gcube.data.transfer.model.options.DirectTransferOptions; +import org.gcube.data.transfer.model.options.HttpDownloadOptions; +import org.gcube.data.transfer.model.options.TransferOptions; +import org.gcube.data.transfer.model.options.TransferOptions.TransferMethod; +import org.gcube.data.transfer.model.settings.DirectTransferSettings; +import org.gcube.data.transfer.model.settings.HttpDownloadSettings; +import org.gcube.data.transfer.model.utils.DateWrapper; +import org.junit.BeforeClass; +import org.junit.Test; + +public class MarshallUnmarshalTest { + + static JAXBContext ctx =null; + + @BeforeClass + public static void init() throws JAXBException{ + ctx = JAXBContext.newInstance( + TransferRequest.class, + TransferTicket.class, + TransferCapabilities.class); + } + + + + @Test + public void Marshall() throws MalformedURLException{ + print(createRequest(TransferMethod.HTTPDownload)); + print(createRequest(TransferMethod.DirectTransfer)); + print(createTransferCapabilities()); + print(createTicket(createRequest(TransferMethod.HTTPDownload))); + print(createTicket(createRequest(TransferMethod.DirectTransfer))); + } + + @Test + public void UnMarshall() throws MalformedURLException{ + assertTrue(roundTrip(createRequest(TransferMethod.HTTPDownload))); + assertTrue(roundTrip(createRequest(TransferMethod.DirectTransfer))); + assertTrue(roundTrip(createTransferCapabilities())); + assertTrue(roundTrip(createTicket(createRequest(TransferMethod.HTTPDownload)))); + assertTrue(roundTrip(createTicket(createRequest(TransferMethod.DirectTransfer)))); + } + + + @Test + public void toStringTest() throws MalformedURLException{ + System.out.println(createRequest(TransferMethod.HTTPDownload)); + System.out.println(createRequest(TransferMethod.DirectTransfer)); + System.out.println(createTransferCapabilities()); + System.out.println(createTicket(createRequest(TransferMethod.HTTPDownload))); + System.out.println(createTicket(createRequest(TransferMethod.DirectTransfer))); + } + + + public static boolean roundTrip(Object obj){ + Object roundTripResult=unmarshal(obj.getClass(), new StringReader(marshal(obj,new StringWriter()).toString())); + return obj.equals(roundTripResult); + } + + /** + * Write the serialisation of a given resource to a {@link Result}. + * @param resource the resource + * @param stream the result + * @return the result in input + */ + public static T marshal(Object resource,T result) { + + + try { + JAXBContext context = ctx; + Marshaller m = context.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + + m.marshal(resource,result); + + return result; + } + catch(Exception e) { + throw new RuntimeException("serialisation error",e); + } + + } + + public static void print(Object resource) { + + marshal(resource,new OutputStreamWriter(System.out)); + } + + /** + * Write the serialisation of a given resource to a given character stream. + * @param resource the resource + * @param stream the stream in input + */ + public static T marshal(Object resource,T stream) { + + marshal(resource,new StreamResult(stream)); + return stream; + } + + + + /** + * Creates a resource of given class from its serialisation in a given {@link Reader}. + * @param resourceClass the class of the resource + * @param reader the reader + * @return the resource + */ + public static T unmarshal(Class resourceClass, Reader reader) { + return unmarshal(resourceClass,new StreamSource(reader)); + } + + /** + * Creates a resource of given class from its serialisation in a given {@link InputStream}. + * @param resourceClass the class of the resource + * @param stream the stream + * @return the resource + */ + public static T unmarshal(Class resourceClass, InputStream stream) { + return unmarshal(resourceClass,new StreamSource(stream)); + } + + /** + * Creates a resource of given class from its serialisation in a given {@link Source}. + * @param resourceClass the class of the resource + * @param source the source + * @return the resource + */ + public static T unmarshal(Class resourceClass,Source source) { + try { + Unmarshaller um = ctx.createUnmarshaller(); + return resourceClass.cast(um.unmarshal(source)); + } + catch(Exception e) { + throw new RuntimeException("deserialisation error",e); + } + } + + private HttpDownloadSettings createHttpSettings()throws MalformedURLException{ + return new HttpDownloadSettings(new URL("http://some.where.com"),createHttpOptions()); + } + + private HttpDownloadOptions createHttpOptions() { + return HttpDownloadOptions.DEFAULT; + } + + private DirectTransferSettings createDirectTransferSettings(){ + return new DirectTransferSettings(createDirectTransferOptions()); + } + + private DirectTransferOptions createDirectTransferOptions(){ + return new DirectTransferOptions("mySource"); + } + + + private TransferCapabilities createTransferCapabilities(){ + return new TransferCapabilities("12345", "localhost", 80, + Collections.singleton((TransferOptions)createHttpOptions()),Collections.singleton(createPluginDescriptor()),Collections.singleton("DT DUMMY")); + } + + private TransferRequest createRequest(TransferOptions.TransferMethod toUseMethod) throws MalformedURLException{ + switch(toUseMethod){ + case HTTPDownload : return new TransferRequest(UUID.randomUUID().toString(), createHttpSettings(),new Destination("myImportedFile")); + case DirectTransfer : return new TransferRequest(UUID.randomUUID().toString(), createDirectTransferSettings(),new Destination("myImportedFile")); + default : return null; + } + } + + + private PluginInvocation createPluginInvocation(){ + HashMap params=new HashMap<>(); + params.put("First param", PluginInvocation.DESTINATION_FILE_PATH); + return new PluginInvocation("Dummy Plugin", params); + } + + private TransferTicket createTicket(TransferRequest request){ + return new TransferTicket(request, Status.STOPPED, 1005467l, .57d, 123345, DateWrapper.getInstance(),"/dev/null","bona"); + } + + private PluginDescription createPluginDescriptor(){ + HashMap params=new HashMap<>(); + params.put("First param", "Useful param for a no op plugin"); + return new PluginDescription("Dummy plugin","This thing does nothing",params); + } +}