();
/**
* 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());
}
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 Id: "+dcEvent.getTaskConf().getTaskId() +"
removed correctly";
new DialogResult(null, "Delete performed!",msg).center();
}
showTaskConfigurations(dcEvent.getWsItem());
}
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);
}else {
viewManager.showCreateTaskConfigurationForFolder(event.getWsItem(), event.getTaskConfiguration());
}
}
}
});
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());
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
});
}
/**
* 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 configuration...");
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(), taskEventsListeners);
}
});
box.show();
}
/**
* Show task configurations.
*
* @param wsItem the ws item
* @throws Exception the exception
*/
public void showTaskConfigurations(final WSItem wsItem) throws Exception {
if(wsItem==null || wsItem.getItemId()==null)
throw new Exception("Invalid parameter workpace item or its id is null");
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(), taskEventsListeners);
return;
}
final Modal box = new Modal(true);
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);
}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();
}
}