Updated retrieveOutput

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/workspace-task-executor-library@167911 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2018-06-07 09:42:20 +00:00
parent 321ecc49d1
commit 0ca4b15c3d
4 changed files with 36 additions and 38 deletions

View File

@ -260,46 +260,39 @@ public class DMConverter {
/** /**
* Append output. * Gets the output message.
* *
* @param builder the builder
* @param key the key * @param key the key
* @param res the res * @param res the res
* @return the output message
*/ */
public static void appendOutput(StringBuilder builder, String key, Resource res){ public static String getOutputMessage(String key, Resource res){
switch (res.getResourceType()) { switch (res.getResourceType()) {
case FILE: case FILE:
FileResource fileResource = (FileResource) res; FileResource fileResource = (FileResource) res;
String fileName=retrieveFileName(fileResource.getUrl()); String fileName=retrieveFileName(fileResource.getUrl());
logger.debug("Entry: " + key + " = "+ fileResource+", FileName="+fileName); logger.debug("Entry: " + key + " = "+ fileResource+", FileName="+fileName);
builder.append("Entry: " + key + " = "+fileResource+", FileName="+fileName); return "Entry: " + key + " = "+fileResource+", FileName="+fileName;
break;
case IMAGE: case IMAGE:
ImageResource imageResource = (ImageResource) res; ImageResource imageResource = (ImageResource) res;
String imageName=retrieveFileName(imageResource.getLink()); String imageName=retrieveFileName(imageResource.getLink());
logger.debug("Entry: " + key + " = "+ imageResource+", ImageName="+imageName); logger.debug("Entry: " + key + " = "+ imageResource+", ImageName="+imageName);
builder.append("Entry: " + key + " = "+ imageResource+", ImageName="+imageName); return "Entry: " + key + " = "+ imageResource+", ImageName="+imageName;
break;
case MAP: case MAP:
logger.debug("Entry: " + key + " = "+ res); logger.debug("Entry: " + key + " = "+ res);
builder.append("Entry: " + key + " = "+ res); return "Entry: " + key + " = "+ res;
break;
case OBJECT: case OBJECT:
logger.debug("Entry: " + key + " = "+ res); logger.debug("Entry: " + key + " = "+ res);
builder.append("Entry: " + key + " = "+ res); return "Entry: " + key + " = "+ res;
break;
case TABULAR: case TABULAR:
TableResource tableResource = (TableResource) res; TableResource tableResource = (TableResource) res;
String tableName=retrieveFileName(tableResource.getResourceId()); String tableName=retrieveFileName(tableResource.getResourceId());
logger.debug("Entry: " + key + " = "+ tableResource+", TableName="+tableName); logger.debug("Entry: " + key + " = "+ tableResource+", TableName="+tableName);
builder.append("Entry: " + key + " = "+tableResource+", TableName="+tableName); return "Entry: " + key + " = "+ tableResource+", TableName="+tableName;
break;
default: default:
logger.debug("Entry: " + key + " = "+ res); logger.debug("Entry: " + key + " = "+ res);
builder.append("Entry: " + key + " = "+ res); return "Entry: " + key + " = "+ res;
break;
} }
} }

View File

@ -323,7 +323,7 @@ public class DataMinerAccessPoint {
throw new TaskErrorException("Error on getting DataMiner client, Try later"); throw new TaskErrorException("Error on getting DataMiner client, Try later");
} }
String outputMessage = retrieveOutput(computationId, sClient); List<String> outputMessages = retrieveOutput(computationId, sClient);
//REMOVING THE TASK FROM MEMORY //REMOVING THE TASK FROM MEMORY
switch (tes.getStatus()) { switch (tes.getStatus()) {
@ -337,21 +337,21 @@ public class DataMinerAccessPoint {
break; break;
} }
return new TaskOutput(tes, outputMessage); return new TaskOutput(tes, outputMessages);
} }
/** /**
* Retrieve output. * Retrieve output.
* provided by Giancarlo
* *
* @param computationId the computation id * @param computationId the computation id
* @param sClient the s client * @param sClient the s client
* @return the string * @return the list
* @throws TaskErrorException the task error exception * @throws TaskErrorException the task error exception
*/ */
private String retrieveOutput(ComputationId computationId, SClient sClient) throws TaskErrorException { private List<String> retrieveOutput(ComputationId computationId, SClient sClient) throws TaskErrorException {
try { try {
StringBuilder builder = new StringBuilder(); List<String> outputMessages = new ArrayList<String>();
OutputData output = sClient.getOutputDataByComputationId(computationId); OutputData output = sClient.getOutputDataByComputationId(computationId);
logger.debug("Output: " + output); logger.debug("Output: " + output);
Resource resource = output.getResource(); Resource resource = output.getResource();
@ -360,13 +360,13 @@ public class DataMinerAccessPoint {
MapResource mapResource = (MapResource) resource; MapResource mapResource = (MapResource) resource;
for (String key : mapResource.getMap().keySet()) { for (String key : mapResource.getMap().keySet()) {
Resource res = mapResource.getMap().get(key); Resource res = mapResource.getMap().get(key);
DMConverter.appendOutput(builder, key, res); outputMessages.add(DMConverter.getOutputMessage(key, res));
} }
}else{ }else{
DMConverter.appendOutput(builder, "", resource); outputMessages.add(DMConverter.getOutputMessage("", resource));
} }
return builder.toString(); return outputMessages;
} catch (Exception e) { } catch (Exception e) {
logger.error("Error on retrieve the output for computationId: "+computationId, e); logger.error("Error on retrieve the output for computationId: "+computationId, e);
throw new TaskErrorException("Error on retrieve the output for computationId: "+computationId); throw new TaskErrorException("Error on retrieve the output for computationId: "+computationId);

View File

@ -3,6 +3,8 @@
*/ */
package org.gcube.common.workspacetaskexecutor.shared; package org.gcube.common.workspacetaskexecutor.shared;
import java.util.List;
/** /**
* The Interface BaseTaskOutput. * The Interface BaseTaskOutput.
@ -26,7 +28,7 @@ public interface BaseTaskOutput {
* *
* @return the outputMessage * @return the outputMessage
*/ */
public String getOutputMessage(); public List<String> getOutputMessages();
} }

View File

@ -4,6 +4,7 @@
package org.gcube.common.workspacetaskexecutor.shared; package org.gcube.common.workspacetaskexecutor.shared;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
@ -20,7 +21,7 @@ public class TaskOutput implements BaseTaskOutput, Serializable{
*/ */
private static final long serialVersionUID = 4243040464402882775L; private static final long serialVersionUID = 4243040464402882775L;
private BaseTaskExecutionStatus taskExecutionStatus; private BaseTaskExecutionStatus taskExecutionStatus;
private String outputMessage; private List<String> outputMessages;
/** /**
* Instantiates a new task parameter. * Instantiates a new task parameter.
@ -34,11 +35,11 @@ public class TaskOutput implements BaseTaskOutput, Serializable{
* Instantiates a new task output. * Instantiates a new task output.
* *
* @param taskExecutionstatus the task executionstatus * @param taskExecutionstatus the task executionstatus
* @param outputMessage the output message * @param outputMessages the output messages
*/ */
public TaskOutput(BaseTaskExecutionStatus taskExecutionstatus, String outputMessage) { public TaskOutput(BaseTaskExecutionStatus taskExecutionstatus, List<String> outputMessages) {
this.taskExecutionStatus = taskExecutionstatus; this.taskExecutionStatus = taskExecutionstatus;
this.outputMessage = outputMessage; this.outputMessages = outputMessages;
} }
@ -54,11 +55,11 @@ public class TaskOutput implements BaseTaskOutput, Serializable{
/** /**
* @return the outputMessage * @return the outputMessages
*/ */
public String getOutputMessage() { public List<String> getOutputMessages() {
return outputMessage; return outputMessages;
} }
@ -74,11 +75,11 @@ public class TaskOutput implements BaseTaskOutput, Serializable{
/** /**
* @param outputMessage the outputMessage to set * @param outputMessages the outputMessages to set
*/ */
public void setOutputMessage(String outputMessage) { public void setOutputMessages(List<String> outputMessages) {
this.outputMessage = outputMessage; this.outputMessages = outputMessages;
} }
@ -91,11 +92,13 @@ public class TaskOutput implements BaseTaskOutput, Serializable{
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("TaskOutput [taskExecutionStatus="); builder.append("TaskOutput [taskExecutionStatus=");
builder.append(taskExecutionStatus); builder.append(taskExecutionStatus);
builder.append(", outputMessage="); builder.append(", outputMessages=");
builder.append(outputMessage); builder.append(outputMessages);
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }