2018-05-04 11:37:46 +02:00
|
|
|
|
2018-05-04 11:35:17 +02:00
|
|
|
package org.gcube.portlets.widgets.wstaskexecutor.client;
|
|
|
|
|
2018-05-04 16:16:28 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.common.workspacetaskexecutor.shared.dataminer.TaskConfiguration;
|
|
|
|
import org.gcube.common.workspacetaskexecutor.shared.exception.ItemNotConfiguredException;
|
2018-05-04 17:41:01 +02:00
|
|
|
import org.gcube.common.workspacetaskexecutor.shared.exception.WorkspaceFolderLocked;
|
2018-05-04 16:16:28 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.TaskCompletedNotification.TaskCompletedNotificationListner;
|
2018-05-09 12:36:54 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.CreateTaskConfigurationEvent;
|
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.CreateTaskConfigurationEventHandler;
|
2018-05-04 17:41:01 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.PerformRunTaskEvent;
|
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.PerformRunTaskEventHandler;
|
2018-05-09 16:19:41 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.ShowCreateTaskConfigurationEvent;
|
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.event.ShowCreateTaskConfigurationEventHandler;
|
2018-05-04 16:16:28 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.rpc.WsTaskExecutorWidgetServiceAsync;
|
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.view.LoaderIcon;
|
2018-05-04 12:46:29 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.view.WsTaskExecutorWidgetViewManager;
|
2018-05-04 16:16:28 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.client.view.binder.MonitorFolderTaskExecutionStatusView;
|
2018-05-09 16:19:41 +02:00
|
|
|
import org.gcube.portlets.widgets.wstaskexecutor.shared.WSItem;
|
2018-05-04 12:46:29 +02:00
|
|
|
|
2018-05-04 17:41:01 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Alert;
|
2018-05-04 16:16:28 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.Modal;
|
2018-05-04 17:41:01 +02:00
|
|
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
2018-05-04 16:16:28 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2018-05-04 17:41:01 +02:00
|
|
|
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
|
import com.google.gwt.event.dom.client.ClickHandler;
|
2018-05-04 12:46:29 +02:00
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2018-05-04 17:41:01 +02:00
|
|
|
import com.google.gwt.user.client.Window;
|
2018-05-04 16:16:28 +02:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2018-05-04 17:41:01 +02:00
|
|
|
import com.google.gwt.user.client.ui.Button;
|
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
2018-05-04 12:46:29 +02:00
|
|
|
|
2018-05-04 11:35:17 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Entry point classes define <code>onModuleLoad()</code>.
|
2018-05-04 16:16:28 +02:00
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* May 4, 2018
|
2018-05-04 11:35:17 +02:00
|
|
|
*/
|
2018-05-04 11:37:46 +02:00
|
|
|
public class WsTaskExecutorWidget {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The message displayed to the user when the server cannot be reached or
|
|
|
|
* returns an error.
|
|
|
|
*/
|
|
|
|
private static final String SERVER_ERROR = "An error occurred while "
|
|
|
|
+ "attempting to contact the server. Please check your network "
|
|
|
|
+ "connection and try again.";
|
|
|
|
/**
|
|
|
|
* Create a remote service proxy to talk to the server-side Greeting
|
|
|
|
* service.
|
|
|
|
*/
|
2018-05-04 17:32:34 +02:00
|
|
|
public static final WsTaskExecutorWidgetServiceAsync wsTaskService = WsTaskExecutorWidgetServiceAsync.Util.getInstance();
|
2018-05-04 11:35:17 +02:00
|
|
|
|
2018-05-04 12:46:29 +02:00
|
|
|
/** The Constant eventBus. */
|
|
|
|
public final static HandlerManager eventBus = new HandlerManager(null);
|
|
|
|
|
|
|
|
private WsTaskExecutorWidgetViewManager viewManager = new WsTaskExecutorWidgetViewManager();
|
|
|
|
|
2018-05-04 16:16:28 +02:00
|
|
|
private final List<TaskCompletedNotificationListner> taskEventsListeners = new ArrayList<TaskCompletedNotificationListner>();
|
|
|
|
|
2018-05-04 11:37:46 +02:00
|
|
|
/**
|
2018-05-04 16:16:28 +02:00
|
|
|
* Instantiates a new ws task executor widget.
|
|
|
|
*/
|
2018-05-04 11:37:46 +02:00
|
|
|
public WsTaskExecutorWidget() {
|
2018-05-04 16:16:28 +02:00
|
|
|
bindEvents();
|
2018-05-04 11:37:46 +02:00
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
}
|
2018-05-04 16:16:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind events.
|
|
|
|
*/
|
|
|
|
private void bindEvents() {
|
|
|
|
|
2018-05-04 17:41:01 +02:00
|
|
|
eventBus.addHandler(PerformRunTaskEvent.TYPE, new PerformRunTaskEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPerformRunTask(PerformRunTaskEvent perforRunTaskEvent) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
performRunTask(perforRunTaskEvent.getFolder(), perforRunTaskEvent.getConf());
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
Window.alert(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
eventBus.addHandler(ShowCreateTaskConfigurationEvent.TYPE, new ShowCreateTaskConfigurationEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onShowCreateConfiguration(
|
|
|
|
ShowCreateTaskConfigurationEvent showCreateTaskConfigurationEvent) {
|
|
|
|
|
|
|
|
if(showCreateTaskConfigurationEvent.getFolder()!=null)
|
|
|
|
viewManager.showCreateTaskConfigurationForFolder(showCreateTaskConfigurationEvent.getFolder(), null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-09 12:36:54 +02:00
|
|
|
eventBus.addHandler(CreateTaskConfigurationEvent.TYPE, new CreateTaskConfigurationEventHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateConfiguration(
|
|
|
|
final CreateTaskConfigurationEvent createTCE) {
|
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
if(createTCE.getWsItem()!=null && createTCE.getConf()!=null){
|
|
|
|
GWT.log("Creating the configuration: "+createTCE.getConf());
|
|
|
|
|
|
|
|
WsTaskExecutorWidget.wsTaskService.createTaskConfiguration(createTCE.getWsItem().getItemId(), createTCE.getConf(), createTCE.isUpdate(), new AsyncCallback<Boolean>() {
|
2018-05-09 12:36:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
|
|
|
|
Window.alert(caught.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
|
|
|
|
try {
|
2018-05-09 16:19:41 +02:00
|
|
|
showTaskConfigurationsForFolder(createTCE.getWsItem());
|
2018-05-09 12:36:54 +02:00
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-04 16:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-04 17:41:01 +02:00
|
|
|
/**
|
2018-05-08 12:25:54 +02:00
|
|
|
* Perform run task.
|
|
|
|
*
|
2018-05-09 16:19:41 +02:00
|
|
|
* @param wsItem the folder
|
2018-05-08 12:25:54 +02:00
|
|
|
* @param conf the conf
|
|
|
|
* @throws Exception the exception
|
2018-05-04 17:41:01 +02:00
|
|
|
*/
|
2018-05-09 16:19:41 +02:00
|
|
|
public void performRunTask(WSItem wsItem, TaskConfiguration conf) throws Exception {
|
2018-05-04 17:41:01 +02:00
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
if(wsItem==null || wsItem.getItemId()==null)
|
|
|
|
throw new Exception("Invalid parameter workpace item or its id is null");
|
2018-05-04 17:41:01 +02:00
|
|
|
|
|
|
|
if(conf==null)
|
|
|
|
throw new Exception("Invalid parameter the configuration is null");
|
|
|
|
|
|
|
|
|
|
|
|
//WsTaskExecutorWidget.wsTaskService.runTask()
|
|
|
|
}
|
|
|
|
|
2018-05-08 12:25:54 +02:00
|
|
|
|
2018-05-04 16:16:28 +02:00
|
|
|
/**
|
2018-05-08 12:25:54 +02:00
|
|
|
* Show task configurations for folder.
|
2018-05-04 16:16:28 +02:00
|
|
|
*
|
2018-05-09 16:19:41 +02:00
|
|
|
* @param wsItem the folder
|
2018-05-04 16:16:28 +02:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2018-05-09 16:19:41 +02:00
|
|
|
public void showTaskConfigurationsForFolder(final WSItem wsItem) throws Exception {
|
2018-05-04 16:16:28 +02:00
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
if(wsItem==null || wsItem.getItemId()==null)
|
|
|
|
throw new Exception("Invalid parameter workpace item or its id is null");
|
2018-05-04 16:16:28 +02:00
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
MonitorFolderTaskExecutionStatusView monitor = viewManager.getMonitor(wsItem);
|
2018-05-04 16:16:28 +02:00
|
|
|
|
|
|
|
//SHOWING CURRENT ACTIVE MONITOR
|
|
|
|
if(monitor!=null) {
|
2018-05-09 16:19:41 +02:00
|
|
|
GWT.log("Monitor for workpace item: "+wsItem.getItemId() +" exists showing it..");
|
|
|
|
viewManager.showMonitorTaskStatusFor(wsItem, monitor.getTaskConfiguration(), monitor.getTaskComputation(), taskEventsListeners);
|
2018-05-04 16:16:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Modal box = new Modal(true);
|
|
|
|
box.setTitle("Checking configurations...");
|
|
|
|
LoaderIcon loader = new LoaderIcon("Checking folder configurations...");
|
|
|
|
box.add(loader);
|
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
GWT.log("Performing checkItemTaskConfigurations: "+wsItem.getItemId());
|
2018-05-04 16:16:28 +02:00
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
WsTaskExecutorWidget.wsTaskService.checkItemTaskConfigurations(wsItem.getItemId(), new AsyncCallback<List<TaskConfiguration>>() {
|
2018-05-04 16:16:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<TaskConfiguration> result) {
|
2018-05-08 18:11:29 +02:00
|
|
|
box.hide();
|
2018-05-04 16:16:28 +02:00
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
viewManager.showTaskConfigurationsFolderInfo(wsItem, result, taskEventsListeners);
|
2018-05-04 16:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2018-05-08 18:11:29 +02:00
|
|
|
box.hide();
|
2018-05-04 16:16:28 +02:00
|
|
|
|
|
|
|
if(caught instanceof ItemNotConfiguredException){
|
2018-05-04 17:41:01 +02:00
|
|
|
|
2018-05-09 16:19:41 +02:00
|
|
|
viewManager.showCreateTaskConfigurationForFolder(wsItem, null);
|
2018-05-04 17:41:01 +02:00
|
|
|
|
|
|
|
}else if(caught instanceof WorkspaceFolderLocked){
|
|
|
|
VerticalPanel v = new VerticalPanel();
|
|
|
|
Alert alert = new Alert("Current Folder is locked by another proccess. Do you want see Task status?");
|
|
|
|
alert.setClose(true);
|
|
|
|
alert.setType(AlertType.INFO);
|
|
|
|
|
|
|
|
Button butt = new Button("Show Status");
|
|
|
|
butt.addClickHandler(new ClickHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(ClickEvent event) {
|
|
|
|
//WsThreddsWidget.eventBus.fireEvent(new ShowMonitorSyncStatusEvent(folder));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
v.add(alert);
|
|
|
|
v.add(butt);
|
|
|
|
box.add(v);
|
2018-05-04 16:16:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
box.show();
|
|
|
|
|
|
|
|
}
|
2018-05-04 11:35:17 +02:00
|
|
|
}
|