328 lines
8.5 KiB
Java
328 lines
8.5 KiB
Java
package org.gcube.portlets.widgets.wstaskexecutor.client.view;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.common.workspacetaskexecutor.shared.TaskStatus;
|
|
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskComputation;
|
|
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
|
|
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskExecutionStatus;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.TaskCompletedNotification.TaskCompletedNotificationListner;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.WsTaskExecutorWidget;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.PerformRunTaskEvent;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.view.binder.AbstractViewDialogBox;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.view.binder.CreateTaskConfigurationView;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.view.binder.MonitorFolderTaskExecutionStatusView;
|
|
import org.gcube.portlets.widgets.wstaskexecutor.shared.WsFolder;
|
|
|
|
import com.github.gwtbootstrap.client.ui.Modal;
|
|
import com.google.gwt.core.shared.GWT;
|
|
import com.google.gwt.user.client.Command;
|
|
import com.google.gwt.user.client.Timer;
|
|
import com.google.gwt.user.client.Window;
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
|
|
/**
|
|
* The Class WsTaskExecutorWidgetViewManager.
|
|
*
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
* May 4, 2018
|
|
*/
|
|
public class WsTaskExecutorWidgetViewManager {
|
|
|
|
private Map<String, MonitorFolderTaskExecutionStatusView> mapMonitor = new HashMap<String, MonitorFolderTaskExecutionStatusView>();
|
|
|
|
|
|
/**
|
|
* Cancel scheduler.
|
|
*
|
|
* @param folder the folder
|
|
* @return the monitor folder task execution status view
|
|
*/
|
|
private MonitorFolderTaskExecutionStatusView cancelScheduler(final WsFolder folder) {
|
|
|
|
MonitorFolderTaskExecutionStatusView monitor = getMonitor(folder);
|
|
if(monitor.getSchedulerTime()!=null) {
|
|
GWT.log("Cancelling scheduler time on folder: "+folder.getFolderId());
|
|
monitor.getSchedulerTime().cancel();
|
|
}
|
|
|
|
return monitor;
|
|
|
|
}
|
|
|
|
/**
|
|
* Cancel monitor.
|
|
*
|
|
* @param folder the folder
|
|
*/
|
|
public void cancelMonitor(WsFolder folder) {
|
|
try {
|
|
MonitorFolderTaskExecutionStatusView monitor = cancelScheduler(folder);
|
|
if(monitor!=null) {
|
|
GWT.log("Removed monitor for folder: "+folder.getFolderId());
|
|
mapMonitor.remove(folder.getFolderId());
|
|
}
|
|
}catch (Exception e) {
|
|
GWT.log("Error on removing map monitor for id: "+folder.getFolderId());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Gets the monitor.
|
|
*
|
|
* @param folder the folder
|
|
* @return the monitor
|
|
*/
|
|
public MonitorFolderTaskExecutionStatusView getMonitor(WsFolder folder){
|
|
|
|
if(folder==null)
|
|
return null;
|
|
|
|
return mapMonitor.get(folder.getFolderId());
|
|
}
|
|
|
|
/**
|
|
* Save monitor.
|
|
*
|
|
* @param folder the folder
|
|
* @param monitor the monitor
|
|
*/
|
|
private void saveMonitor(WsFolder folder, MonitorFolderTaskExecutionStatusView monitor) {
|
|
GWT.log("Saving monitor for folder: "+folder.getFolderId());
|
|
mapMonitor.put(folder.getFolderId(), monitor);
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Show monitor task status for.
|
|
*
|
|
* @param folder the folder
|
|
* @param configuration the configuration
|
|
* @param taskComputation the task computation
|
|
* @param taskEventsListeners the task events listeners
|
|
*/
|
|
public void showMonitorTaskStatusFor(
|
|
final WsFolder folder,
|
|
final TaskConfiguration configuration, final TaskComputation taskComputation, final List<TaskCompletedNotificationListner> taskEventsListeners) {
|
|
|
|
GWT.log("showMonitorSyncToFolder for folder: "+folder.getFolderId());
|
|
|
|
final Modal box = new Modal(true);
|
|
box.addStyleName("ws-thredds-modal-body");
|
|
box.setTitle("Monitor transferring of: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20));
|
|
box.setWidth(800);
|
|
box.hide(false);
|
|
|
|
MonitorFolderTaskExecutionStatusView monitorView = getMonitor(folder);
|
|
GWT.log("monitorView is: "+monitorView);
|
|
|
|
final AbstractViewDialogBox panelView = new AbstractViewDialogBox() {
|
|
|
|
@Override
|
|
public void closeHandler() {
|
|
//cancelScheduler(folder);
|
|
box.hide();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void confirmHanlder(CONFIRM_VALUE confirm, Command command) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
};
|
|
|
|
if(monitorView==null) {
|
|
|
|
monitorView = new MonitorFolderTaskExecutionStatusView(configuration, taskComputation) {
|
|
|
|
@Override
|
|
public void closetHandler() {
|
|
//TODO CLIENT SIDE?
|
|
//cancelMonitor(folder);
|
|
panelView.closeHandler();
|
|
}
|
|
|
|
@Override
|
|
public void setError(boolean visible, String error) {
|
|
panelView.setError(visible, error);
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
if(monitorView.getSchedulerTime()==null) {
|
|
|
|
//Removing old monitor
|
|
//cancelMonitor(folder);
|
|
//Creating new one
|
|
final MonitorFolderTaskExecutionStatusView currentMonitor = monitorView;
|
|
|
|
Timer schedulingTimer = new Timer() {
|
|
|
|
@Override
|
|
public void run() {
|
|
|
|
WsTaskExecutorWidget.wsTaskService.monitorTaskExecutionStatus(configuration, taskComputation, new AsyncCallback<TaskExecutionStatus>() {
|
|
|
|
@Override
|
|
public void onFailure(Throwable caught) {
|
|
cancelMonitor(folder);
|
|
Window.alert(caught.getMessage());
|
|
|
|
//CALLING METHOD ON SYNC ERROR TO THE LISTENERS
|
|
for (TaskCompletedNotificationListner listener : taskEventsListeners) {
|
|
listener.onTaskComputationError(folder);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(TaskExecutionStatus status) {
|
|
GWT.log("monitorSyncStatus: "+status);
|
|
if(status==null) {
|
|
GWT.log("The status is null server-side, cancelling polling");
|
|
cancelMonitor(folder);
|
|
}
|
|
|
|
currentMonitor.updateStatusView(folder, status);
|
|
|
|
if(status!=null) {
|
|
|
|
if(status.getStatus().equals(TaskStatus.COMPLETED)) {
|
|
GWT.log("Sync completed cancel the polling: "+status);
|
|
cancelMonitor(folder);
|
|
|
|
//CALLING METHOD ON SYNC COMPLETED TO THE LISTENERS
|
|
for (TaskCompletedNotificationListner listener : taskEventsListeners) {
|
|
listener.onTaskComputationCompleted(folder);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
schedulingTimer.scheduleRepeating(2000);
|
|
currentMonitor.setScheduler(schedulingTimer);
|
|
saveMonitor(folder, currentMonitor);
|
|
|
|
}
|
|
|
|
panelView.addViewAsWidget(monitorView);
|
|
box.add(panelView);
|
|
box.show();
|
|
|
|
}
|
|
|
|
/**
|
|
* Show task configurations folder info.
|
|
*
|
|
* @param folder the folder
|
|
* @param result the result
|
|
* @param taskEventsListeners the task events listeners
|
|
*/
|
|
public void showTaskConfigurationsFolderInfo(WsFolder folder, final List<TaskConfiguration> result, final List<TaskCompletedNotificationListner> taskEventsListeners) {
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Show create task configuration for folder.
|
|
*
|
|
* @param folder the folder
|
|
* @param conf the conf
|
|
*/
|
|
public void showCreateTaskConfigurationForFolder(final WsFolder folder, TaskConfiguration conf){
|
|
|
|
final Modal box = new Modal(true);
|
|
box.setWidth(AbstractViewDialogBox.DEFAULT_WIDTH+20+"px");
|
|
box.setTitle("Create Task Configuration for: "+FormatUtil.getFolderTitle(folder.getFoderName(), 20));
|
|
//box.getElement().getStyle().setZIndex(10000);
|
|
|
|
final AbstractViewDialogBox panelView = new AbstractViewDialogBox() {
|
|
|
|
@Override
|
|
public void closeHandler() {
|
|
box.hide();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void confirmHanlder(CONFIRM_VALUE confirm, Command command) {
|
|
|
|
if(confirm.equals(CONFIRM_VALUE.YES)){
|
|
box.hide();
|
|
}
|
|
|
|
if(command!=null)
|
|
command.execute();
|
|
|
|
}
|
|
};
|
|
|
|
CreateTaskConfigurationView createTaskConfiguration = new CreateTaskConfigurationView(folder) {
|
|
|
|
@Override
|
|
public void submitHandler() {
|
|
panelView.closeHandler();
|
|
TaskConfiguration conf = new TaskConfiguration();
|
|
conf.setScope(getSelectedScope().getScopeName());
|
|
conf.setTaskId(getTaskId());
|
|
conf.setTaskDescription("");
|
|
conf.setWorkspaceItemId(folder.getFolderId());
|
|
conf.setListParameters(getParameters());
|
|
|
|
WsTaskExecutorWidget.eventBus.fireEvent(new PerformRunTaskEvent(folder, conf));
|
|
}
|
|
|
|
@Override
|
|
public void setError(boolean visible, String error) {
|
|
panelView.setError(visible, error);
|
|
|
|
}
|
|
|
|
@Override
|
|
public void setConfirm(boolean visible, String msg) {
|
|
|
|
Command yes = new Command() {
|
|
|
|
@Override
|
|
public void execute() {
|
|
|
|
submitHandler();
|
|
}
|
|
};
|
|
|
|
Command no = new Command() {
|
|
|
|
@Override
|
|
public void execute() {
|
|
|
|
panelView.setConfirm(false, "", null, null);
|
|
}
|
|
};
|
|
|
|
panelView.setConfirm(visible, msg, yes, no);
|
|
|
|
}
|
|
};
|
|
|
|
panelView.addViewAsWidget(createTaskConfiguration);
|
|
box.add(panelView);
|
|
box.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|