();
private SelectableOperator selectableOperators = null;
/**
* Instantiates a new ws task executor widget.
*/
public WsTaskExecutorWidget() {
bindEvents();
// TODO Auto-generated constructor stub
}
/**
* Bind events.
*/
private void bindEvents() {
eventBus.addHandler(PerformRunTaskEvent.TYPE, new PerformRunTaskEventHandler() {
@Override
public void onPerformRunTask(final PerformRunTaskEvent perforRunTaskEvent) {
try {
if(perforRunTaskEvent.getWsItem()!=null && perforRunTaskEvent.getConfiguration()!=null){
String msg = "Executing the task with configuration:
";
msg+="
";
msg+="Operator Id:
"+perforRunTaskEvent.getConfiguration().getTaskId();
int cParam = perforRunTaskEvent.getConfiguration().getListParameters().size();
msg+="
";
if(cParam>0){
msg+="With Input ";
msg+=cParam>1?"Parameters:":"Parameter:";
msg+="
";
int i = 0;
for (TaskParameter param : perforRunTaskEvent.getConfiguration().getListParameters()) {
msg+=++i+". Type: "+param.getType().getType() +" having "+param.getKey()+" = " +param.getValue();
msg+="
";
}
}
msg+="
";
msg+="
";
msg+="Confirm?
";
final DialogConfirm confirm = new DialogConfirm(null, "Run the task?", msg);
confirm.getYesButton().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
try {
performRunTask(perforRunTaskEvent.getWsItem(), perforRunTaskEvent.getConfiguration());
confirm.hide();
}
catch (Exception e) {
Window.alert(e.getMessage());
}
}
});
confirm.center();
}
}
catch (Exception e) {
Window.alert(e.getMessage());
}
}
});
eventBus.addHandler(ShowListOfTaskConfigurationsEvent.TYPE, new ShowListOfTaskConfigurationsEventHandler() {
@Override
public void onShowListOfTaskConfigurations(ShowListOfTaskConfigurationsEvent showListOfTaskConfigurationsEvent) {
if(showListOfTaskConfigurationsEvent.getWsItem()!=null)
try {
showTaskConfigurations(showListOfTaskConfigurationsEvent.getWsItem(), selectableOperators);
}
catch (Exception e) {
Window.alert(e.getMessage());
}
}
});
eventBus.addHandler(DeleteConfigurationEvent.TYPE, new DeleteConfigurationEventHandler() {
@Override
public void onRemoveConfiguration(final DeleteConfigurationEvent dcEvent) {
//GWT.log("qui remove");
if(dcEvent.getTaskConf()!=null && dcEvent.getWsItem()!=null){
WsTaskExecutorWidget.wsTaskService.removeTaskConfiguration(dcEvent.getTaskConf(), new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
new DialogResult(null, "Delete Error!", caught.getMessage()).center();
}
@Override
public void onSuccess(Boolean result) {
try {
if(result){
String msg = "Task configuration for Algorithm: "+dcEvent.getTaskConf().getTaskName() +"
removed correctly";
new DialogResult(null, "Delete performed!",msg).center();
}
showTaskConfigurations(dcEvent.getWsItem(), selectableOperators);
}
catch (Exception e) {
Window.alert(e.getMessage());
}
}
});
}
}
});
eventBus.addHandler(ShowCreateTaskConfigurationDialogEvent.TYPE, new ShowCreateTaskConfigurationDialogEventHandler() {
@Override
public void onShowCreateConfiguration(
ShowCreateTaskConfigurationDialogEvent event) {
if(event.getWsItem()!=null){
if(event.getOperation().equals(Operation.CREATE_NEW)){
viewManager.showCreateTaskConfigurationForFolder(event.getWsItem(), null, selectableOperators);
}else {
viewManager.showCreateTaskConfigurationForFolder(event.getWsItem(), event.getTaskConfiguration(), selectableOperators);
}
}
}
});
eventBus.addHandler(CreatedTaskConfigurationEvent.TYPE, new CreatedTaskConfigurationEventHandler() {
@Override
public void onCreatedConfiguration(
final CreatedTaskConfigurationEvent createTCE) {
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() {
@Override
public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(Boolean result) {
try {
showTaskConfigurations(createTCE.getWsItem(), selectableOperators);
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
});
eventBus.addHandler(TaskComputationFinishedEvent.TYPE, new TaskComputationFinishedEventHandler() {
@Override
public void onTaskFinished(
TaskComputationFinishedEvent taskComputationTerminatedEvent) {
if(taskComputationTerminatedEvent.getWsItem()!=null){
GWT.log("Task finished with status "+taskComputationTerminatedEvent.getTaskExecutionStatus()+" cancelling the polling");
viewManager.cancelMonitor(taskComputationTerminatedEvent.getWsItem());
if(taskComputationTerminatedEvent.getError()!=null){
//Exception occurred server-side no output to displaying
Window.alert(taskComputationTerminatedEvent.getError().getMessage());
return;
}
//CALLING METHOD ON SYNC COMPLETED TO THE LISTENERS
for (TaskCompletedNotificationListner listener : taskEventsListeners) {
listener.onTaskComputationCompleted(taskComputationTerminatedEvent.getWsItem());
}
//RETRIEVES A VALID STATUS IF THE OUTPUT IS COMPLETED BUT IT IS CALLED ON FAILED AND CANCELLED STATUS IN ORDER TO REMOVE SERVER SIDE CACHED COMPUATION
WsTaskExecutorWidget.wsTaskService.getOutput(taskComputationTerminatedEvent.getTaskExecutionStatus().getTaskConfiguration(), taskComputationTerminatedEvent.getTaskExecutionStatus().getTaskComputation(), new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
//Window.alert(caught.getMessage());
}
@Override
public void onSuccess(TaskOutput result) {
if(result==null)
return;
List listMessages = result.getOutputMessages();
String outMsg = "";
for (String msg : listMessages) {
outMsg+="
"+msg;
}
final DialogResult dResult = new DialogResult(null, "Computation results are:", outMsg);
dResult.center();
}
});
}
}
});
}
/**
* Perform run task.
*
* @param wsItem the folder
* @param conf the conf
* @throws Exception the exception
*/
public void performRunTask(final WSItem wsItem, final TaskConfiguration conf) throws Exception {
if(wsItem==null || wsItem.getItemId()==null)
throw new Exception("Invalid parameter workpace item or its id is null");
if(conf==null)
throw new Exception("Invalid parameter the configuration is null");
final Modal box = new Modal(true);
box.setTitle("Executing task...");
String algName = conf.getTaskId().substring(conf.getTaskId().lastIndexOf(".")+1, conf.getTaskId().length());
LoaderIcon loader = new LoaderIcon("Inizializing new run for: "+algName);
box.add(loader);
WsTaskExecutorWidget.wsTaskService.executeTheTask(conf, new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
box.hide();
new DialogResult(null, "Error on show Task Status for algorithm id:"+conf.getTaskId(), caught.getMessage()).center();
viewManager.cancelMonitor(wsItem);
}
@Override
public void onSuccess(TaskExecutionStatus result) {
box.hide();
viewManager.showMonitorTaskStatusFor(wsItem, result.getTaskConfiguration(), result.getTaskComputation());
}
});
box.show();
}
/**
* Show task configurations.
*
* @param wsItem the ws item
* @throws Exception the exception
*/
public void showTaskConfigurations(final WSItem wsItem, SelectableOperator selectableOperators) throws Exception {
this.selectableOperators = selectableOperators;
if(wsItem==null || wsItem.getItemId()==null)
throw new Exception("Invalid input parameter "+WSItem.class.getSimpleName()+". Its id or itself is null");
final Modal box = new Modal(true);
box.setTitle("Checking item configurations...");
String suffix = wsItem.getItemName()!=null || !wsItem.getItemName().isEmpty()?wsItem.getItemName():wsItem.getItemId();
LoaderIcon loader = new LoaderIcon("Checking task configurations for item: "+suffix);
box.add(loader);
WsTaskExecutorWidget.wsTaskService.loadItem(wsItem.getItemId(), new AsyncCallback() {
@Override
public void onFailure(Throwable caught) {
box.hide();
Window.alert(caught.getMessage());
}
@Override
public void onSuccess(WSItem result) {
//no hide monitor
handleShowMonitor(result,box);
}
});
box.show();
}
/**
* Handle show monitor.
*
* @param wsItem the ws item
*/
private void handleShowMonitor(final WSItem wsItem, final Modal box){
MonitorFolderTaskExecutionStatusView monitor = viewManager.getMonitor(wsItem);
//SHOWING CURRENT ACTIVE MONITOR
if(monitor!=null) {
GWT.log("Monitor for workpace item: "+wsItem.getItemId() +" exists showing it..");
viewManager.showMonitorTaskStatusFor(wsItem, monitor.getTaskConfiguration(), monitor.getTaskComputation());
return;
}
// box.clear();
// box.setTitle("Checking configurations...");
//
// String suffix = wsItem.getItemName()!=null || !wsItem.getItemName().isEmpty()?wsItem.getItemName():wsItem.getItemId();
// LoaderIcon loader = new LoaderIcon("Checking task configurations for item: "+suffix);
// box.add(loader);
GWT.log("Performing checkItemTaskConfigurations: "+wsItem.getItemId());
WsTaskExecutorWidget.wsTaskService.checkItemTaskConfigurations(wsItem.getItemId(), new AsyncCallback>() {
@Override
public void onSuccess(List result) {
box.hide();
viewManager.showTaskConfigurationsFolderInfo(wsItem, result, taskEventsListeners);
}
@Override
public void onFailure(Throwable caught) {
if(caught instanceof ItemNotConfiguredException){
box.hide();
viewManager.showCreateTaskConfigurationForFolder(wsItem, null, selectableOperators);
}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);
}
}
});
//box.show();
}
}