Updated Background Monitor
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@99735 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
68b93ff45d
commit
f2f89d01fe
|
@ -13,6 +13,7 @@ public class SessionConstants {
|
||||||
protected static final String TABULAR_RESOURCE_LIST = "TABULAR_RESOURCE_LIST";
|
protected static final String TABULAR_RESOURCE_LIST = "TABULAR_RESOURCE_LIST";
|
||||||
|
|
||||||
protected static final String OPERATIONS_TASKS_STARTED="OPERATION_TASKS_STARTED";
|
protected static final String OPERATIONS_TASKS_STARTED="OPERATION_TASKS_STARTED";
|
||||||
|
protected static final String OPERATIONS_TASKS_IN_BACKGROUND="OPERATION_TASKS_IN_BACKGROUND";
|
||||||
protected static final String FILE_UPLOAD_MONITOR = "FILE_UPLOAD_MONITOR";
|
protected static final String FILE_UPLOAD_MONITOR = "FILE_UPLOAD_MONITOR";
|
||||||
|
|
||||||
protected static final String TR_TASK_MANAGER = "TR_TASK_MANAGER";
|
protected static final String TR_TASK_MANAGER = "TR_TASK_MANAGER";
|
||||||
|
|
|
@ -1250,6 +1250,39 @@ public class SessionUtil {
|
||||||
}
|
}
|
||||||
return taskWrapper;
|
return taskWrapper;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
public static void removeTaskStarted(HttpSession httpSession,
|
||||||
|
TaskWrapper taskWrapper) {
|
||||||
|
if (taskWrapper == null) {
|
||||||
|
logger.error("TaskWrapper is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskWrapper.getTask().getId() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue().isEmpty()) {
|
||||||
|
logger.error("TaskWrapper contains Task with invalid task id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
HashMap<String, TaskWrapper> tasksStarted = ((HashMap<String, TaskWrapper>) httpSession
|
||||||
|
.getAttribute(SessionConstants.OPERATIONS_TASKS_STARTED));
|
||||||
|
if (tasksStarted == null) {
|
||||||
|
tasksStarted = new HashMap<String, TaskWrapper>();
|
||||||
|
} else {
|
||||||
|
httpSession
|
||||||
|
.removeAttribute(SessionConstants.OPERATIONS_TASKS_STARTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tasksStarted.remove(taskWrapper.getTask().getId().getValue());
|
||||||
|
httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_STARTED,
|
||||||
|
tasksStarted);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setTaskStarted(HttpSession httpSession,
|
public static void setTaskStarted(HttpSession httpSession,
|
||||||
TaskWrapper taskWrapper) {
|
TaskWrapper taskWrapper) {
|
||||||
|
@ -1274,11 +1307,79 @@ public class SessionUtil {
|
||||||
httpSession
|
httpSession
|
||||||
.removeAttribute(SessionConstants.OPERATIONS_TASKS_STARTED);
|
.removeAttribute(SessionConstants.OPERATIONS_TASKS_STARTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tasksStarted.put(taskWrapper.getTask().getId().getValue(), taskWrapper);
|
tasksStarted.put(taskWrapper.getTask().getId().getValue(), taskWrapper);
|
||||||
httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_STARTED,
|
httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_STARTED,
|
||||||
tasksStarted);
|
tasksStarted);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HashMap<String,TaskWrapper> getTaskInBackgroundMap(HttpSession httpSession) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
HashMap<String, TaskWrapper> tasksInBackground = (HashMap<String, TaskWrapper>) httpSession
|
||||||
|
.getAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND);
|
||||||
|
return tasksInBackground;
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void setTaskInBackground(HttpSession httpSession,
|
||||||
|
TaskWrapper taskWrapper) {
|
||||||
|
if (taskWrapper == null) {
|
||||||
|
logger.error("TaskWrapper is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskWrapper.getTask().getId() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue().isEmpty()) {
|
||||||
|
logger.error("TaskWrapper contains Task with invalid task id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
HashMap<String, TaskWrapper> tasksInBackground = ((HashMap<String, TaskWrapper>) httpSession
|
||||||
|
.getAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND));
|
||||||
|
if (tasksInBackground == null) {
|
||||||
|
tasksInBackground = new HashMap<String, TaskWrapper>();
|
||||||
|
} else {
|
||||||
|
httpSession
|
||||||
|
.removeAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND);
|
||||||
|
}
|
||||||
|
tasksInBackground.put(taskWrapper.getTask().getId().getValue(), taskWrapper);
|
||||||
|
httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND,
|
||||||
|
tasksInBackground);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeTaskInBackground(HttpSession httpSession,
|
||||||
|
TaskWrapper taskWrapper) {
|
||||||
|
if (taskWrapper == null) {
|
||||||
|
logger.error("TaskWrapper is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taskWrapper.getTask().getId() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue().isEmpty()) {
|
||||||
|
logger.error("TaskWrapper contains Task with invalid task id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
HashMap<String, TaskWrapper> tasksInBackground = ((HashMap<String, TaskWrapper>) httpSession
|
||||||
|
.getAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND));
|
||||||
|
if (tasksInBackground == null) {
|
||||||
|
tasksInBackground = new HashMap<String, TaskWrapper>();
|
||||||
|
} else {
|
||||||
|
httpSession
|
||||||
|
.removeAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND);
|
||||||
|
}
|
||||||
|
tasksInBackground.remove(taskWrapper.getTask().getId().getValue());
|
||||||
|
httpSession.setAttribute(SessionConstants.OPERATIONS_TASKS_IN_BACKGROUND,
|
||||||
|
tasksInBackground);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
public static FileUploadMonitor getFileUploadMonitor(HttpSession httpSession) {
|
public static FileUploadMonitor getFileUploadMonitor(HttpSession httpSession) {
|
||||||
|
|
|
@ -152,6 +152,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.file.HeaderPresence;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory;
|
import org.gcube.portlets.user.td.gwtservice.shared.history.OpHistory;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession;
|
import org.gcube.portlets.user.td.gwtservice.shared.history.RollBackSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData;
|
import org.gcube.portlets.user.td.gwtservice.shared.licenses.LicenceData;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorCreator;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession;
|
import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationMonitorSession;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor;
|
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor;
|
||||||
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorCreator;
|
import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorCreator;
|
||||||
|
@ -5309,8 +5310,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
ArrayList<TaskS> taskSList = new ArrayList<TaskS>();
|
ArrayList<TaskS> taskSList = new ArrayList<TaskS>();
|
||||||
List<Task> tasks = service.getTasks(tabularResourceId);
|
List<Task> tasks = service.getTasks(tabularResourceId);
|
||||||
if(tasks.size()>0) {
|
if (tasks.size() > 0) {
|
||||||
Task task=tasks.get(0);
|
Task task = tasks.get(0);
|
||||||
ArrayList<JobS> jobSList = new ArrayList<JobS>();
|
ArrayList<JobS> jobSList = new ArrayList<JobS>();
|
||||||
int j = 1;
|
int j = 1;
|
||||||
for (Job job : task.getTaskJobs()) {
|
for (Job job : task.getTaskJobs()) {
|
||||||
|
@ -6097,7 +6098,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
aslSession.getUsername(), aslSession.getScope()));
|
aslSession.getUsername(), aslSession.getScope()));
|
||||||
TabularDataService service = TabularDataServiceFactory.getService();
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
checkTabularResourceLocked(service, groupBySession.getTrId());
|
checkTabularResourceLocked(service, groupBySession.getTrId());
|
||||||
|
|
||||||
OpExecution4GroupBy opEx = new OpExecution4GroupBy(service,
|
OpExecution4GroupBy opEx = new OpExecution4GroupBy(service,
|
||||||
groupBySession);
|
groupBySession);
|
||||||
OpExecutionDirector director = new OpExecutionDirector();
|
OpExecutionDirector director = new OpExecutionDirector();
|
||||||
|
@ -6151,7 +6152,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
aslSession.getUsername(), aslSession.getScope()));
|
aslSession.getUsername(), aslSession.getScope()));
|
||||||
TabularDataService service = TabularDataServiceFactory.getService();
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
checkTabularResourceLocked(service, normalizationSession.getTrId());
|
checkTabularResourceLocked(service, normalizationSession.getTrId());
|
||||||
|
|
||||||
OpExecution4Normalization opEx = new OpExecution4Normalization(
|
OpExecution4Normalization opEx = new OpExecution4Normalization(
|
||||||
service, normalizationSession);
|
service, normalizationSession);
|
||||||
OpExecutionDirector director = new OpExecutionDirector();
|
OpExecutionDirector director = new OpExecutionDirector();
|
||||||
|
@ -6209,8 +6210,9 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
AuthorizationProvider.instance.set(new AuthorizationToken(
|
AuthorizationProvider.instance.set(new AuthorizationToken(
|
||||||
aslSession.getUsername(), aslSession.getScope()));
|
aslSession.getUsername(), aslSession.getScope()));
|
||||||
TabularDataService service = TabularDataServiceFactory.getService();
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
checkTabularResourceLocked(service, denormalizationSession.getTrId());
|
checkTabularResourceLocked(service,
|
||||||
|
denormalizationSession.getTrId());
|
||||||
|
|
||||||
OpExecution4Denormalization opEx = new OpExecution4Denormalization(
|
OpExecution4Denormalization opEx = new OpExecution4Denormalization(
|
||||||
service, denormalizationSession);
|
service, denormalizationSession);
|
||||||
OpExecutionDirector director = new OpExecutionDirector();
|
OpExecutionDirector director = new OpExecutionDirector();
|
||||||
|
@ -6265,7 +6267,7 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
aslSession.getUsername(), aslSession.getScope()));
|
aslSession.getUsername(), aslSession.getScope()));
|
||||||
TabularDataService service = TabularDataServiceFactory.getService();
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
checkTabularResourceLocked(service, unionSession.getTrId());
|
checkTabularResourceLocked(service, unionSession.getTrId());
|
||||||
|
|
||||||
OpExecution4Union opEx = new OpExecution4Union(service,
|
OpExecution4Union opEx = new OpExecution4Union(service,
|
||||||
unionSession);
|
unionSession);
|
||||||
OpExecutionDirector director = new OpExecutionDirector();
|
OpExecutionDirector director = new OpExecutionDirector();
|
||||||
|
@ -6372,13 +6374,60 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO
|
||||||
@Override
|
@Override
|
||||||
public ArrayList<OperationMonitor> getBackgroundOperationMonitor(
|
public ArrayList<OperationMonitor> getBackgroundOperationMonitor(
|
||||||
BackgroundOperationMonitorSession backgroundOperationMonitorSession)
|
BackgroundOperationMonitorSession backgroundOperationMonitorSession)
|
||||||
throws TDGWTServiceException {
|
throws TDGWTServiceException {
|
||||||
// TODO Auto-generated method stub
|
try {
|
||||||
ArrayList<OperationMonitor> backgroundOperationMonitorList= new ArrayList<OperationMonitor>();
|
HttpSession session = this.getThreadLocalRequest().getSession();
|
||||||
return backgroundOperationMonitorList;
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||||
|
|
||||||
|
ArrayList<OperationMonitor> backgroundOperationMonitorList = new ArrayList<OperationMonitor>();
|
||||||
|
|
||||||
|
HashMap<String, TaskWrapper> taskInBackgroundMap = SessionUtil
|
||||||
|
.getTaskInBackgroundMap(session);
|
||||||
|
|
||||||
|
OperationMonitorSession operationMonitorSession;
|
||||||
|
for (Map.Entry<String, TaskWrapper> taskInBackground : taskInBackgroundMap
|
||||||
|
.entrySet()) {
|
||||||
|
operationMonitorSession=new OperationMonitorSession(taskInBackground.getKey());
|
||||||
|
operationMonitorSession.setInBackground(true);
|
||||||
|
if(backgroundOperationMonitorSession!=null){
|
||||||
|
ArrayList<OperationMonitorSession> operationMonitorSessionList=backgroundOperationMonitorSession.getOperationMonitorSessionList();
|
||||||
|
for(OperationMonitorSession opMonitorSession:operationMonitorSessionList){
|
||||||
|
if(opMonitorSession.getTaskId().compareTo(taskInBackground.getKey())==0){
|
||||||
|
operationMonitorSession=opMonitorSession;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BackgroundOperationMonitorCreator backgroundOperationMonitorCreator = new BackgroundOperationMonitorCreator(
|
||||||
|
session, aslSession, taskInBackground.getValue(),
|
||||||
|
operationMonitorSession);
|
||||||
|
OperationMonitor operationMonitor = backgroundOperationMonitorCreator
|
||||||
|
.create();
|
||||||
|
logger.debug("OperationMonitor(): " + operationMonitor);
|
||||||
|
backgroundOperationMonitorList.add(operationMonitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return backgroundOperationMonitorList;
|
||||||
|
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (TDGWTServiceException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in Background Operation Monitor: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,373 @@
|
||||||
|
package org.gcube.portlets.user.td.gwtservice.shared.monitor;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
|
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationProvider;
|
||||||
|
import org.gcube.data.analysis.tabulardata.commons.utils.AuthorizationToken;
|
||||||
|
import org.gcube.data.analysis.tabulardata.commons.webservice.types.TaskStatus;
|
||||||
|
import org.gcube.data.analysis.tabulardata.model.metadata.table.DatasetViewTableMetadata;
|
||||||
|
import org.gcube.data.analysis.tabulardata.model.metadata.table.ExportMetadata;
|
||||||
|
import org.gcube.data.analysis.tabulardata.model.table.Table;
|
||||||
|
import org.gcube.data.analysis.tabulardata.service.TabularDataService;
|
||||||
|
import org.gcube.data.analysis.tabulardata.service.impl.TabularDataServiceFactory;
|
||||||
|
import org.gcube.data.analysis.tabulardata.service.operation.Job;
|
||||||
|
import org.gcube.data.analysis.tabulardata.service.operation.Task;
|
||||||
|
import org.gcube.data.analysis.tabulardata.service.operation.ValidationJob;
|
||||||
|
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResource;
|
||||||
|
import org.gcube.data.analysis.tabulardata.service.tabular.TabularResourceId;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.server.SessionUtil;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.server.storage.FilesStorage;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.server.trservice.TaskStateMap;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.server.trservice.WorkerStateMap;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.task.JobS;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.task.State;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.task.TaskS;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.task.TaskWrapper;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.task.ValidationsJobS;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource;
|
||||||
|
import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabExportMetadata;
|
||||||
|
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author "Giancarlo Panichi" email: <a
|
||||||
|
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class BackgroundOperationMonitorCreator {
|
||||||
|
protected static Logger logger = LoggerFactory
|
||||||
|
.getLogger(BackgroundOperationMonitorCreator.class);
|
||||||
|
|
||||||
|
protected static SimpleDateFormat sdf = new SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
|
protected static SimpleDateFormat sdfDate = new SimpleDateFormat(
|
||||||
|
"yyyy-MM-dd");
|
||||||
|
|
||||||
|
protected HttpSession session;
|
||||||
|
protected TaskWrapper taskWrapper;
|
||||||
|
protected OperationMonitorSession operationMonitorSession;
|
||||||
|
protected ASLSession aslSession;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param task
|
||||||
|
* @param startTRId
|
||||||
|
* @param operationMonitorSession
|
||||||
|
*/
|
||||||
|
public BackgroundOperationMonitorCreator(HttpSession session, ASLSession aslSession,
|
||||||
|
TaskWrapper taskWrapper,
|
||||||
|
OperationMonitorSession operationMonitorSession) {
|
||||||
|
this.session = session;
|
||||||
|
this.aslSession = aslSession;
|
||||||
|
this.taskWrapper = taskWrapper;
|
||||||
|
this.operationMonitorSession = operationMonitorSession;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* @throws TDGWTServiceException
|
||||||
|
*/
|
||||||
|
public OperationMonitor create() throws TDGWTServiceException {
|
||||||
|
OperationMonitor operationMonitor = new OperationMonitor(
|
||||||
|
operationMonitorSession.getTaskId(),
|
||||||
|
taskWrapper.getOperationId());
|
||||||
|
|
||||||
|
if (taskWrapper == null || taskWrapper.getTask() == null
|
||||||
|
|| taskWrapper.getTask().getId() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue() == null
|
||||||
|
|| taskWrapper.getTask().getId().getValue().isEmpty()) {
|
||||||
|
logger.debug("Task is null");
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in Operation Monitor task is null");
|
||||||
|
} else {
|
||||||
|
operationMonitor
|
||||||
|
.setTaskId(taskWrapper.getTask().getId().getValue());
|
||||||
|
|
||||||
|
if (operationMonitorSession.isAbort()) {
|
||||||
|
Task task = taskWrapper.getTask();
|
||||||
|
task.abort();
|
||||||
|
TaskS taskS = createTaskS();
|
||||||
|
taskS.setState(State.ABORTED);
|
||||||
|
operationMonitor.setTask(taskS);
|
||||||
|
operationMonitor.setAbort(true);
|
||||||
|
SessionUtil.setTaskInBackground(session, taskWrapper);
|
||||||
|
postOperation(operationMonitor);
|
||||||
|
} else {
|
||||||
|
if (!operationMonitorSession.isInBackground()) {
|
||||||
|
TaskS taskS = createTaskS();
|
||||||
|
operationMonitor.setTask(taskS);
|
||||||
|
operationMonitor.setInBackground(false);
|
||||||
|
SessionUtil.removeTaskInBackground(session, taskWrapper);
|
||||||
|
SessionUtil.setTaskStarted(session, taskWrapper);
|
||||||
|
postOperation(operationMonitor);
|
||||||
|
} else {
|
||||||
|
TaskStatus status = taskWrapper.getTask().getStatus();
|
||||||
|
if (status == null) {
|
||||||
|
logger.debug("Services TaskStatus : null");
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in OperationMonitor Status is null");
|
||||||
|
} else {
|
||||||
|
TaskS taskS = createTaskS();
|
||||||
|
operationMonitor.setTask(taskS);
|
||||||
|
}
|
||||||
|
SessionUtil.setTaskInBackground(session, taskWrapper);
|
||||||
|
postOperation(operationMonitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return operationMonitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TaskS createTaskS() {
|
||||||
|
TaskS taskS = new TaskS();
|
||||||
|
|
||||||
|
ArrayList<JobS> jobSList = new ArrayList<JobS>();
|
||||||
|
int i = 1;
|
||||||
|
for (Job job : taskWrapper.getTask().getTaskJobs()) {
|
||||||
|
|
||||||
|
ArrayList<ValidationsJobS> validationsJobS = new ArrayList<ValidationsJobS>();
|
||||||
|
int j = 1;
|
||||||
|
for (ValidationJob valJob : job.getValidationJobs()) {
|
||||||
|
ValidationsJobS validationJ = new ValidationsJobS(
|
||||||
|
String.valueOf(j), WorkerStateMap.map(valJob
|
||||||
|
.getStatus()), valJob.getProgress(),
|
||||||
|
valJob.getDescription(), valJob.getErrorMessage(),
|
||||||
|
valJob.getHumaReadableStatus());
|
||||||
|
validationsJobS.add(validationJ);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
JobS jobS = new JobS(String.valueOf(i), job.getProgress(),
|
||||||
|
job.getHumaReadableStatus(), job.getDescription(),
|
||||||
|
WorkerStateMap.map(job.getStatus()), job.getErrorMessage(),
|
||||||
|
validationsJobS);
|
||||||
|
|
||||||
|
jobSList.add(jobS);
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
taskS = new TaskS(taskWrapper.getTask().getId().getValue(), taskWrapper
|
||||||
|
.getTask().getProgress(), TaskStateMap.map(taskWrapper
|
||||||
|
.getTask().getStatus()), taskWrapper.getTask().getErrorCause(),
|
||||||
|
taskWrapper.getTask().getSubmitter(), taskWrapper.getTask()
|
||||||
|
.getStartTime(), taskWrapper.getTask().getEndTime(),
|
||||||
|
jobSList);
|
||||||
|
|
||||||
|
logger.debug("Retrieved task information");
|
||||||
|
return taskS;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void postOperation(OperationMonitor operationMonitor)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
|
||||||
|
switch (operationMonitor.getTask().getState()) {
|
||||||
|
case FAILED:
|
||||||
|
Throwable errorCause = taskWrapper.getTask().getErrorCause();
|
||||||
|
if (errorCause == null) {
|
||||||
|
logger.error("Task Exception: task is failed");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
logger.error("Task exception: "
|
||||||
|
+ errorCause.getLocalizedMessage());
|
||||||
|
errorCause.printStackTrace();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SUCCEDED:
|
||||||
|
logger.debug("Task Result:" + taskWrapper.getTask().getResult());
|
||||||
|
updateInformations(operationMonitor);
|
||||||
|
break;
|
||||||
|
case IN_PROGRESS:
|
||||||
|
break;
|
||||||
|
case VALIDATING_RULES:
|
||||||
|
break;
|
||||||
|
case GENERATING_VIEW:
|
||||||
|
break;
|
||||||
|
case ABORTED:
|
||||||
|
break;
|
||||||
|
case STOPPED:
|
||||||
|
logger.debug("Task Result:" + taskWrapper.getTask().getResult());
|
||||||
|
updateInformations(operationMonitor);
|
||||||
|
break;
|
||||||
|
case INITIALIZING:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateInformations(OperationMonitor operationMonitor)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
TRId trId;
|
||||||
|
TabResource tabResource;
|
||||||
|
Table table;
|
||||||
|
ExportMetadata exportMetadata;
|
||||||
|
|
||||||
|
switch (taskWrapper.getOperationId()) {
|
||||||
|
case CSVExport:
|
||||||
|
table = taskWrapper.getTask().getResult().getPrimaryTable();
|
||||||
|
logger.debug("Table retrived: " + table.toString());
|
||||||
|
exportMetadata = table.getMetadata(ExportMetadata.class);
|
||||||
|
logger.debug("ExportMetadata: " + exportMetadata);
|
||||||
|
|
||||||
|
operationMonitor.setTrId(SessionUtil.getTRId(session));
|
||||||
|
|
||||||
|
TabExportMetadata trExportMetadata;
|
||||||
|
trExportMetadata = new TabExportMetadata();
|
||||||
|
trExportMetadata.setUrl(exportMetadata.getUri());
|
||||||
|
trExportMetadata.setDestinationType(exportMetadata
|
||||||
|
.getDestinationType());
|
||||||
|
trExportMetadata.setExportDate(sdf.format(exportMetadata
|
||||||
|
.getExportDate()));
|
||||||
|
|
||||||
|
saveCSVExportInDestination(exportMetadata);
|
||||||
|
break;
|
||||||
|
case SDMXExport:
|
||||||
|
table = taskWrapper.getTask().getResult().getPrimaryTable();
|
||||||
|
logger.debug("Table retrived: " + table.toString());
|
||||||
|
exportMetadata = table.getMetadata(ExportMetadata.class);
|
||||||
|
logger.debug("ExportMetadata: " + exportMetadata);
|
||||||
|
operationMonitor.setTrId(SessionUtil.getTRId(session));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
trId = new TRId();
|
||||||
|
trId.setId(taskWrapper.getTrId().getId());
|
||||||
|
trId = retrieveTabularResourceBasicData(trId);
|
||||||
|
|
||||||
|
operationMonitor.setTrId(trId);
|
||||||
|
tabResource = SessionUtil.getTabResource(session);
|
||||||
|
logger.debug("CurrentTabResource :" + tabResource);
|
||||||
|
if (tabResource != null) {
|
||||||
|
tabResource.setTrId(trId);
|
||||||
|
SessionUtil.setTabResource(session, tabResource);
|
||||||
|
} else {
|
||||||
|
tabResource = new TabResource();
|
||||||
|
tabResource.setTrId(trId);
|
||||||
|
SessionUtil.setTabResource(session, tabResource);
|
||||||
|
}
|
||||||
|
SessionUtil.setTRId(session, trId);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TRId retrieveTabularResourceBasicData(TRId trId)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
try {
|
||||||
|
ASLSession aslSession = SessionUtil.getAslSession(session);
|
||||||
|
|
||||||
|
AuthorizationProvider.instance.set(new AuthorizationToken(
|
||||||
|
aslSession.getUsername(), aslSession.getScope()));
|
||||||
|
TabularDataService service = TabularDataServiceFactory.getService();
|
||||||
|
TabularResourceId tabularResourceId = new TabularResourceId(
|
||||||
|
new Long(trId.getId()));
|
||||||
|
|
||||||
|
TabularResource tr = service.getTabularResource(tabularResourceId);
|
||||||
|
Table table = service.getLastTable(tabularResourceId);
|
||||||
|
|
||||||
|
Table viewTable = null;
|
||||||
|
|
||||||
|
if (table.contains(DatasetViewTableMetadata.class)) {
|
||||||
|
DatasetViewTableMetadata dwm = table
|
||||||
|
.getMetadata(DatasetViewTableMetadata.class);
|
||||||
|
try {
|
||||||
|
viewTable = service.getTable(dwm
|
||||||
|
.getTargetDatasetViewTableId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("view table not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TRId newTRId;
|
||||||
|
if (viewTable == null) {
|
||||||
|
newTRId = new TRId(String.valueOf(tr.getId().getValue()),
|
||||||
|
tr.getTableType(), String.valueOf(table.getId()
|
||||||
|
.getValue()), table.getTableType().getName());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
newTRId = new TRId(String.valueOf(tr.getId().getValue()),
|
||||||
|
tr.getTableType(), String.valueOf(viewTable.getId()
|
||||||
|
.getValue()), viewTable.getTableType()
|
||||||
|
.getName(), String.valueOf(table.getId()
|
||||||
|
.getValue()), true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("Retrieved TRId basic info:" + newTRId.toString());
|
||||||
|
return newTRId;
|
||||||
|
|
||||||
|
} catch (TDGWTSessionExpiredException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Security exception, you haven't rights!");
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new TDGWTServiceException("Error in Client Library Request: "
|
||||||
|
+ e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save export data on Workspace
|
||||||
|
*
|
||||||
|
* @param session
|
||||||
|
* @param user
|
||||||
|
* @param exportMetadata
|
||||||
|
* @param exportSession
|
||||||
|
* @throws TDGWTServiceException
|
||||||
|
*/
|
||||||
|
protected void saveCSVExportInDestination(ExportMetadata exportMetadata)
|
||||||
|
throws TDGWTServiceException {
|
||||||
|
CSVExportSession exportSession = SessionUtil
|
||||||
|
.getCSVExportSession(session);
|
||||||
|
String user = aslSession.getUsername();
|
||||||
|
|
||||||
|
logger.debug("Save Export In Destination");
|
||||||
|
logger.debug("Destination: " + exportSession.getDestination().getId());
|
||||||
|
|
||||||
|
if (exportSession.getDestination().getId().compareTo("Workspace") == 0) {
|
||||||
|
logger.debug("Save on Workspace");
|
||||||
|
boolean end = SessionUtil.getCSVExportEnd(session);
|
||||||
|
if (end == false) {
|
||||||
|
SessionUtil.setCSVExportEnd(session, true);
|
||||||
|
FilesStorage storage = new FilesStorage();
|
||||||
|
logger.debug("Create Item On Workspace: [ uri: "
|
||||||
|
+ exportMetadata.getUri() + " ,user: " + user
|
||||||
|
+ " ,fileName: " + exportSession.getFileName()
|
||||||
|
+ " ,fileDescription: "
|
||||||
|
+ exportSession.getFileDescription()
|
||||||
|
+ " ,mimetype: text/csv" + " ,folder: "
|
||||||
|
+ exportSession.getItemId() + "]");
|
||||||
|
storage.createItemOnWorkspace(exportMetadata.getUri(), user,
|
||||||
|
exportSession.getFileName(),
|
||||||
|
exportSession.getFileDescription(), "text/csv",
|
||||||
|
exportSession.getItemId());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
logger.debug("getCSVExportEnd(): true");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.error("Destination No Present");
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in exportCSV CSVExportMonitor: no destination present");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -83,7 +83,7 @@ public class OperationMonitorCreator {
|
||||||
OperationMonitor operationMonitor = new OperationMonitor(
|
OperationMonitor operationMonitor = new OperationMonitor(
|
||||||
operationMonitorSession.getTaskId(),
|
operationMonitorSession.getTaskId(),
|
||||||
taskWrapper.getOperationId());
|
taskWrapper.getOperationId());
|
||||||
|
|
||||||
if (taskWrapper == null || taskWrapper.getTask() == null
|
if (taskWrapper == null || taskWrapper.getTask() == null
|
||||||
|| taskWrapper.getTask().getId() == null
|
|| taskWrapper.getTask().getId() == null
|
||||||
|| taskWrapper.getTask().getId().getValue() == null
|
|| taskWrapper.getTask().getId().getValue() == null
|
||||||
|
@ -92,29 +92,41 @@ public class OperationMonitorCreator {
|
||||||
throw new TDGWTServiceException(
|
throw new TDGWTServiceException(
|
||||||
"Error in Operation Monitor task is null");
|
"Error in Operation Monitor task is null");
|
||||||
} else {
|
} else {
|
||||||
operationMonitor.setTaskId(taskWrapper.getTask().getId()
|
operationMonitor
|
||||||
.getValue());
|
.setTaskId(taskWrapper.getTask().getId().getValue());
|
||||||
|
|
||||||
if (operationMonitorSession.isAbort()) {
|
if (operationMonitorSession.isAbort()) {
|
||||||
Task task = taskWrapper.getTask();
|
Task task = taskWrapper.getTask();
|
||||||
task.abort();
|
task.abort();
|
||||||
TaskS taskS = createTaskS();
|
TaskS taskS = createTaskS();
|
||||||
taskS.setState(State.ABORTED);
|
taskS.setState(State.ABORTED);
|
||||||
operationMonitor.setTask(taskS);
|
operationMonitor.setTask(taskS);
|
||||||
} else {
|
operationMonitor.setAbort(true);
|
||||||
TaskStatus status = taskWrapper.getTask().getStatus();
|
SessionUtil.setTaskStarted(session, taskWrapper);
|
||||||
if (status == null) {
|
postOperation(operationMonitor);
|
||||||
logger.debug("Services TaskStatus : null");
|
} else {
|
||||||
throw new TDGWTServiceException(
|
if (operationMonitorSession.isInBackground()) {
|
||||||
"Error in OperationMonitor Status is null");
|
|
||||||
} else {
|
|
||||||
TaskS taskS = createTaskS();
|
TaskS taskS = createTaskS();
|
||||||
operationMonitor.setTask(taskS);
|
operationMonitor.setTask(taskS);
|
||||||
|
operationMonitor.setInBackground(true);
|
||||||
|
SessionUtil.setTaskInBackground(session, taskWrapper);
|
||||||
|
SessionUtil.removeTaskStarted(session, taskWrapper);
|
||||||
|
postOperation(operationMonitor);
|
||||||
|
} else {
|
||||||
|
TaskStatus status = taskWrapper.getTask().getStatus();
|
||||||
|
if (status == null) {
|
||||||
|
logger.debug("Services TaskStatus : null");
|
||||||
|
throw new TDGWTServiceException(
|
||||||
|
"Error in OperationMonitor Status is null");
|
||||||
|
} else {
|
||||||
|
TaskS taskS = createTaskS();
|
||||||
|
operationMonitor.setTask(taskS);
|
||||||
|
}
|
||||||
|
SessionUtil.setTaskStarted(session, taskWrapper);
|
||||||
|
postOperation(operationMonitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
SessionUtil.setTaskStarted(session, taskWrapper);
|
|
||||||
postOperation(operationMonitor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return operationMonitor;
|
return operationMonitor;
|
||||||
|
|
Loading…
Reference in New Issue