From 89457330b80a28ace195d64fa4416b354bd006bb Mon Sep 17 00:00:00 2001 From: "fabio.sinibaldi" Date: Thu, 25 May 2017 13:12:13 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/data-transfer/data-transfer-model/1.2@149075 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../data/transfer/model/ExecutionReport.java | 41 +++++++ .../transfer/model/TransferCapabilities.java | 2 +- .../data/transfer/model/TransferTicket.java | 111 ++++++++++++++++-- .../gcube/data/transfer/model/jaxb.properties | 1 + .../transfer/test/MarshallUnmarshalTest.java | 12 +- 5 files changed, 155 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/gcube/data/transfer/model/ExecutionReport.java create mode 100644 src/main/resources/org/gcube/data/transfer/model/jaxb.properties diff --git a/src/main/java/org/gcube/data/transfer/model/ExecutionReport.java b/src/main/java/org/gcube/data/transfer/model/ExecutionReport.java new file mode 100644 index 0000000..060836c --- /dev/null +++ b/src/main/java/org/gcube/data/transfer/model/ExecutionReport.java @@ -0,0 +1,41 @@ +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 org.gcube.data.transfer.model.TransferTicket.Status; +import org.gcube.data.transfer.model.utils.DateWrapper; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +@Data +@EqualsAndHashCode(callSuper=false) +@NoArgsConstructor +@AllArgsConstructor +@XmlRootElement +@XmlAccessorType(XmlAccessType.NONE) +public class ExecutionReport { + + @XmlEnum + public static enum ExecutionReportFlag{ + SUCCESS, + WRONG_PARAMETER, + UNABLE_TO_EXECUTE, + FAILED_EXECUTION, + FAILED_CLEANUP + } + + @XmlElement + private PluginInvocation invocation; + @XmlElement + private String message; + @XmlElement + private ExecutionReportFlag flag; + +} diff --git a/src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java b/src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java index a782e28..c82c379 100644 --- a/src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java +++ b/src/main/java/org/gcube/data/transfer/model/TransferCapabilities.java @@ -121,7 +121,7 @@ public class TransferCapabilities { if(!other.availablePlugins.contains(opt)) return false; - //TODO Check persistences + //Check persistence ids if ((availablePersistenceIds == null || availablePersistenceIds.isEmpty())) if(other.availablePersistenceIds!=null&& (!other.availablePersistenceIds.isEmpty())) return false; diff --git a/src/main/java/org/gcube/data/transfer/model/TransferTicket.java b/src/main/java/org/gcube/data/transfer/model/TransferTicket.java index f1f917f..f7bfb37 100644 --- a/src/main/java/org/gcube/data/transfer/model/TransferTicket.java +++ b/src/main/java/org/gcube/data/transfer/model/TransferTicket.java @@ -1,20 +1,26 @@ package org.gcube.data.transfer.model; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + 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) +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString @NoArgsConstructor @AllArgsConstructor @XmlRootElement @@ -48,6 +54,9 @@ public class TransferTicket extends TransferRequest{ @XmlElement private String message; + @XmlElement + private Map executionReports; + // // public TransferTicket(String id, TransferOptions options, Status status, // long transferredBytes, double percent, long averageTransferSpeed, @@ -63,7 +72,7 @@ public class TransferTicket extends TransferRequest{ public TransferTicket(TransferRequest request, Status status, long transferredBytes, double percent, long averageTransferSpeed, - DateWrapper submissionTime,String destinationFileName,String message) { + DateWrapper submissionTime,String destinationFileName,String message, Map executionReports) { super(request.getId(), request.getSettings(),request.getDestinationSettings(),request.getPluginInvocations()); this.status = status; this.transferredBytes = transferredBytes; @@ -71,6 +80,7 @@ public class TransferTicket extends TransferRequest{ this.averageTransferSpeed = averageTransferSpeed; this.submissionTime = submissionTime; this.destinationFileName=destinationFileName; + this.executionReports=executionReports; } @@ -83,8 +93,91 @@ public class TransferTicket extends TransferRequest{ this.percent=0d; this.submissionTime=DateWrapper.getInstance(); this.message=""; + this.executionReports=new HashMap(); + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + TransferTicket other = (TransferTicket) obj; + if (averageTransferSpeed != other.averageTransferSpeed) + return false; + if (destinationFileName == null) { + if (other.destinationFileName != null) + return false; + } else if (!destinationFileName.equals(other.destinationFileName)) + return false; + + + //Check reports map + if ((executionReports == null || executionReports.isEmpty())) + if(other.executionReports!=null&& (!other.executionReports.isEmpty())) + return false; + else if(executionReports!=null && (!executionReports.isEmpty())) + if(other.executionReports==null || other.executionReports.isEmpty()) + return false; + else if(executionReports.size()!=other.executionReports.size()) + return false; + else for(String key:executionReports.keySet()) + if(!other.executionReports.containsKey(key)|| + (!executionReports.get(key).equals(other.executionReports.get(key)))) + return false; + + + + + + + + if (message == null) { + if (other.message != null) + return false; + } else if (!message.equals(other.message)) + return false; + if (Double.doubleToLongBits(percent) != Double.doubleToLongBits(other.percent)) + return false; + if (status != other.status) + return false; + if (submissionTime == null) { + if (other.submissionTime != null) + return false; + } else if (!submissionTime.equals(other.submissionTime)) + return false; + if (transferredBytes != other.transferredBytes) + return false; + return true; + } + + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + (int) (averageTransferSpeed ^ (averageTransferSpeed >>> 32)); + result = prime * result + ((destinationFileName == null) ? 0 : destinationFileName.hashCode()); + + if(executionReports!=null){ + for(Entry entry:executionReports.entrySet()) + result=prime*result+(entry.getKey().hashCode()+entry.getValue().hashCode()); + } + + result = prime * result + ((executionReports == null) ? 0 : executionReports.hashCode()); + result = prime * result + ((message == null) ? 0 : message.hashCode()); + long temp; + temp = Double.doubleToLongBits(percent); + result = prime * result + (int) (temp ^ (temp >>> 32)); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((submissionTime == null) ? 0 : submissionTime.hashCode()); + result = prime * result + (int) (transferredBytes ^ (transferredBytes >>> 32)); + return result; } - + } diff --git a/src/main/resources/org/gcube/data/transfer/model/jaxb.properties b/src/main/resources/org/gcube/data/transfer/model/jaxb.properties new file mode 100644 index 0000000..5837a4c --- /dev/null +++ b/src/main/resources/org/gcube/data/transfer/model/jaxb.properties @@ -0,0 +1 @@ +javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory \ No newline at end of file diff --git a/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java index 203d5e8..503d434 100644 --- a/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java +++ b/src/test/java/org/gcube/data/transfer/test/MarshallUnmarshalTest.java @@ -24,11 +24,13 @@ 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.ExecutionReport; 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.ExecutionReport.ExecutionReportFlag; import org.gcube.data.transfer.model.TransferTicket.Status; import org.gcube.data.transfer.model.options.DirectTransferOptions; import org.gcube.data.transfer.model.options.FileUploadOptions; @@ -42,6 +44,8 @@ import org.gcube.data.transfer.model.utils.DateWrapper; import org.junit.BeforeClass; import org.junit.Test; +import junit.framework.Assert; + public class MarshallUnmarshalTest { static JAXBContext ctx =null; @@ -90,7 +94,6 @@ public class MarshallUnmarshalTest { System.out.println(createTicket(createRequest(TransferMethod.FileUpload))); } - public static boolean roundTrip(Object obj){ Object roundTripResult=unmarshal(obj.getClass(), new StringReader(marshal(obj,new StringWriter()).toString())); return obj.equals(roundTripResult); @@ -232,7 +235,8 @@ public class MarshallUnmarshalTest { } private TransferTicket createTicket(TransferRequest request){ - return new TransferTicket(request, Status.STOPPED, 1005467l, .57d, 123345, DateWrapper.getInstance(),"/dev/null","bona"); + ExecutionReport report=createExecutionReport(); + return new TransferTicket(request, Status.STOPPED, 1005467l, .57d, 123345, DateWrapper.getInstance(),"/dev/null","bona", Collections.singletonMap(report.getInvocation().getPluginId(), report)); } private PluginDescription createPluginDescriptor(){ @@ -240,4 +244,8 @@ public class MarshallUnmarshalTest { params.put("First param", "Useful param for a no op plugin"); return new PluginDescription("Dummy plugin","This thing does nothing",params); } + + private ExecutionReport createExecutionReport(){ + return new ExecutionReport(createPluginInvocation(), "Executed", ExecutionReportFlag.SUCCESS); + } }