2016-04-06 18:28:32 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-04-22 15:49:49 +02:00
|
|
|
package org.gcube.portlets.user.dataminermanager.client.experiments;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
import org.gcube.portlets.user.dataminermanager.client.common.EventBusProvider;
|
2016-05-04 20:24:07 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.custom.progress.GreenProgressBar;
|
2016-05-24 16:16:41 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.custom.progress.OrangeProgressBar;
|
2016-05-04 20:24:07 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.custom.progress.RedProgressBar;
|
2016-04-22 15:49:49 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.events.CancelComputationExecutionRequestEvent;
|
2016-04-21 21:42:53 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.rpc.DataMinerPortletServiceAsync;
|
2016-04-06 18:28:32 +02:00
|
|
|
import org.gcube.portlets.user.dataminermanager.client.util.UtilsGXT3;
|
|
|
|
import org.gcube.portlets.user.dataminermanager.shared.Constants;
|
2018-05-03 16:24:26 +02:00
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.data.computations.ComputationId;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus;
|
|
|
|
import org.gcube.data.analysis.dataminermanagercl.shared.process.ComputationStatus.Status;
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
import com.allen_sauer.gwt.log.client.Log;
|
|
|
|
import com.google.gwt.dom.client.Style.Unit;
|
|
|
|
import com.google.gwt.user.client.Timer;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
2016-04-12 18:01:14 +02:00
|
|
|
import com.sencha.gxt.core.client.util.Margins;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.ProgressBar;
|
|
|
|
import com.sencha.gxt.widget.core.client.button.TextButton;
|
2016-04-12 18:01:14 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.HtmlLayoutContainer;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
|
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
2016-04-12 18:01:14 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
|
|
|
import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
2016-05-16 15:23:40 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.form.FieldLabel;
|
2016-04-06 18:28:32 +02:00
|
|
|
import com.sencha.gxt.widget.core.client.info.Info;
|
|
|
|
|
|
|
|
/**
|
2016-04-12 18:01:14 +02:00
|
|
|
*
|
2017-05-12 11:58:15 +02:00
|
|
|
* @author Giancarlo Panichi
|
|
|
|
*
|
2016-04-06 18:28:32 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ComputationStatusPanel extends SimpleContainer {
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
private ProgressBar progressBar;
|
2016-04-06 18:28:32 +02:00
|
|
|
private ComputationId computationId;
|
2016-05-09 18:57:18 +02:00
|
|
|
private String operatorName;
|
|
|
|
private boolean terminated = false;
|
|
|
|
private ComputationTimer timer = new ComputationTimer();
|
2016-04-12 18:01:14 +02:00
|
|
|
private TextButton cancelComputationBtn;
|
2016-04-06 18:28:32 +02:00
|
|
|
private VerticalLayoutContainer vert;
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
/**
|
|
|
|
*
|
2017-05-12 11:58:15 +02:00
|
|
|
* @param operatorName operator name
|
2016-04-06 18:28:32 +02:00
|
|
|
*/
|
2016-05-09 18:57:18 +02:00
|
|
|
public ComputationStatusPanel(String operatorName) {
|
2016-04-06 18:28:32 +02:00
|
|
|
super();
|
2016-05-09 18:57:18 +02:00
|
|
|
this.operatorName = operatorName;
|
2016-04-06 18:28:32 +02:00
|
|
|
init();
|
2016-04-12 18:01:14 +02:00
|
|
|
create();
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
private void init() {
|
2016-04-12 18:01:14 +02:00
|
|
|
setStylePrimaryName("computationStatusPanel");
|
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
|
|
|
private void create() {
|
|
|
|
vert = new VerticalLayoutContainer();
|
|
|
|
HtmlLayoutContainer title = new HtmlLayoutContainer(
|
|
|
|
"<div class='computationStatusTitle'><p>Computation of <b>"
|
|
|
|
+ operatorName + "</b></p></div>");
|
2016-04-12 18:01:14 +02:00
|
|
|
vert.add(title, new VerticalLayoutData(-1, -1, new Margins(0)));
|
2016-04-06 18:28:32 +02:00
|
|
|
add(vert);
|
|
|
|
forceLayout();
|
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
/**
|
2016-05-09 18:57:18 +02:00
|
|
|
* @param computationId
|
|
|
|
* the computationId to set
|
2016-04-06 18:28:32 +02:00
|
|
|
*/
|
|
|
|
public void computationStarted(ComputationId computationId) {
|
|
|
|
this.computationId = computationId;
|
2016-05-10 17:58:09 +02:00
|
|
|
/*
|
|
|
|
* HtmlLayoutContainer date = new HtmlLayoutContainer(
|
|
|
|
* "<div class='computationStatusDate'><p>" + new Date().toString() +
|
|
|
|
* "</p></div>");
|
|
|
|
*/
|
|
|
|
// vert.add(date, new VerticalLayoutData(-1, -1, new Margins(0)));
|
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
vert.add(new HtmlLayoutContainer("<p>Created, the id is "
|
|
|
|
+ computationId.getId() + " [<a href='"
|
|
|
|
+ computationId.getUrlId() + "' >link</a>]</p>"));
|
2016-05-24 16:16:41 +02:00
|
|
|
|
|
|
|
TextButton equivalentRequestBtn = new TextButton();
|
2016-05-16 15:23:40 +02:00
|
|
|
equivalentRequestBtn.setText("Show");
|
|
|
|
equivalentRequestBtn.addSelectHandler(new SelectHandler() {
|
2016-05-24 16:16:41 +02:00
|
|
|
|
2016-05-16 15:23:40 +02:00
|
|
|
@Override
|
|
|
|
public void onSelect(SelectEvent event) {
|
|
|
|
showEquivalentRequestDialog();
|
2016-05-24 16:16:41 +02:00
|
|
|
|
2016-05-16 15:23:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2016-05-24 16:16:41 +02:00
|
|
|
|
|
|
|
FieldLabel equivalentRequestLabel = new FieldLabel(
|
|
|
|
equivalentRequestBtn, "Equivalent Get Request");
|
2016-05-16 15:23:40 +02:00
|
|
|
equivalentRequestLabel.setLabelWidth(140);
|
2016-05-24 16:16:41 +02:00
|
|
|
vert.add(equivalentRequestLabel, new VerticalLayoutData(-1, -1,
|
|
|
|
new Margins(0)));
|
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
progressBar = new ProgressBar();
|
2016-05-09 18:57:18 +02:00
|
|
|
progressBar.updateProgress(0, "Starting...");
|
|
|
|
vert.add(progressBar, new VerticalLayoutData(1, -1, new Margins(20)));
|
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
cancelComputationBtn = new TextButton("Cancel");
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-12 18:01:14 +02:00
|
|
|
cancelComputationBtn.addSelectHandler(new SelectHandler() {
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
@Override
|
|
|
|
public void onSelect(SelectEvent event) {
|
2016-04-12 18:01:14 +02:00
|
|
|
cancelComputationBtn.disable();
|
2016-04-06 18:28:32 +02:00
|
|
|
cancelComputation();
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
});
|
2016-04-12 18:01:14 +02:00
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
cancelComputationBtn.getElement().getStyle()
|
|
|
|
.setMarginBottom(36, Unit.PX);
|
|
|
|
|
|
|
|
vert.add(cancelComputationBtn, new VerticalLayoutData(-1, -1,
|
|
|
|
new Margins(0)));
|
2016-04-06 18:28:32 +02:00
|
|
|
forceLayout();
|
|
|
|
timer.scheduleRepeating(Constants.TIME_UPDATE_COMPUTATION_STATUS_PANEL);
|
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-05-16 15:23:40 +02:00
|
|
|
private void showEquivalentRequestDialog() {
|
2016-05-24 16:16:41 +02:00
|
|
|
EquivalentRequestDialog equivalentRequestDialog = new EquivalentRequestDialog(
|
|
|
|
computationId);
|
|
|
|
equivalentRequestDialog.show();
|
2016-05-16 15:23:40 +02:00
|
|
|
}
|
2016-05-10 17:58:09 +02:00
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
private void cancelComputation() {
|
|
|
|
CancelComputationExecutionRequestEvent event = new CancelComputationExecutionRequestEvent(
|
|
|
|
computationId);
|
2016-04-21 21:42:53 +02:00
|
|
|
EventBusProvider.INSTANCE.fireEvent(event);
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-09 18:57:18 +02:00
|
|
|
* @param computationId
|
|
|
|
* @param operator
|
2016-04-06 18:28:32 +02:00
|
|
|
*
|
|
|
|
*/
|
2016-05-10 17:58:09 +02:00
|
|
|
private void computationTerminated(ComputationId computationId,
|
2016-05-09 18:57:18 +02:00
|
|
|
ComputationStatus computationStatus) {
|
2016-04-06 18:28:32 +02:00
|
|
|
Log.debug("Computation Terminated");
|
2016-05-09 18:57:18 +02:00
|
|
|
Log.debug("Computation Status:" + computationStatus);
|
2016-04-06 18:28:32 +02:00
|
|
|
if (terminated == false) {
|
|
|
|
terminated = true;
|
2016-04-12 18:01:14 +02:00
|
|
|
cancelComputationBtn.setVisible(false);
|
2016-04-06 18:28:32 +02:00
|
|
|
if (computationStatus.isComplete()) {
|
|
|
|
Log.debug("Computation is Complete");
|
2016-05-09 18:57:18 +02:00
|
|
|
Info.display("Terminated",
|
|
|
|
"The computation " + computationId.getId() + " of "
|
|
|
|
+ computationId.getOperatorName()
|
|
|
|
+ " is terminated correctly.");
|
|
|
|
int index = vert.getWidgetIndex(progressBar);
|
2016-04-26 18:27:28 +02:00
|
|
|
vert.remove(index);
|
2016-05-09 18:57:18 +02:00
|
|
|
// TODO
|
|
|
|
progressBar = new GreenProgressBar();
|
2016-04-06 18:28:32 +02:00
|
|
|
progressBar.updateProgress(1, "Computation Complete");
|
2016-05-09 18:57:18 +02:00
|
|
|
vert.insert(progressBar, index, new VerticalLayoutData(1, -1,
|
|
|
|
new Margins(20)));
|
2016-05-10 17:58:09 +02:00
|
|
|
showComputationCompletedOutput();
|
2016-04-06 18:28:32 +02:00
|
|
|
} else if (computationStatus.isFailed()) {
|
|
|
|
Log.debug("Computation is Failed");
|
|
|
|
String errorMessage;
|
2016-05-13 18:55:07 +02:00
|
|
|
if (computationStatus.getError() == null) {
|
2016-05-09 18:57:18 +02:00
|
|
|
errorMessage = new String("Computation Failed!");
|
2016-04-06 18:28:32 +02:00
|
|
|
} else {
|
2016-05-24 16:16:41 +02:00
|
|
|
errorMessage = computationStatus.getError()
|
|
|
|
.getLocalizedMessage();
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
Info.display("Failed",
|
|
|
|
"The computation " + computationId.getId() + " of "
|
|
|
|
+ computationId.getOperatorName()
|
|
|
|
+ " is failed.");
|
|
|
|
UtilsGXT3.alert("Failed",
|
|
|
|
"The computation " + computationId.getId() + " of "
|
|
|
|
+ computationId.getOperatorName()
|
2016-05-10 17:58:09 +02:00
|
|
|
+ " has failed.</br>" + errorMessage);
|
2016-05-09 18:57:18 +02:00
|
|
|
int index = vert.getWidgetIndex(progressBar);
|
2016-04-26 18:27:28 +02:00
|
|
|
vert.remove(index);
|
2016-05-09 18:57:18 +02:00
|
|
|
// TODO
|
|
|
|
progressBar = new RedProgressBar();
|
2016-04-06 18:28:32 +02:00
|
|
|
progressBar.updateProgress(1, "Computation Fail");
|
2016-05-09 18:57:18 +02:00
|
|
|
progressBar.getElement().getStyle()
|
|
|
|
.setMarginBottom(36, Unit.PX);
|
|
|
|
vert.insert(progressBar, index, new VerticalLayoutData(1, -1,
|
|
|
|
new Margins(20)));
|
2016-05-24 16:16:41 +02:00
|
|
|
} else if (computationStatus.isCancelled()) {
|
|
|
|
Log.debug("Computation Cancelled");
|
|
|
|
String errorMessage;
|
|
|
|
errorMessage = new String("Computation Cancelled!");
|
|
|
|
Info.display("Info", "The computation " + computationId.getId()
|
|
|
|
+ " of " + computationId.getOperatorName()
|
|
|
|
+ " has been cancelled.");
|
|
|
|
UtilsGXT3.info("Info",
|
|
|
|
"The computation " + computationId.getId() + " of "
|
|
|
|
+ computationId.getOperatorName()
|
|
|
|
+ " has been cancelled.</br>" + errorMessage);
|
|
|
|
int index = vert.getWidgetIndex(progressBar);
|
|
|
|
vert.remove(index);
|
|
|
|
// TODO
|
|
|
|
progressBar = new OrangeProgressBar();
|
|
|
|
progressBar.updateProgress(1, "Computation Cancelled");
|
|
|
|
progressBar.getElement().getStyle()
|
|
|
|
.setMarginBottom(36, Unit.PX);
|
|
|
|
vert.insert(progressBar, index, new VerticalLayoutData(1, -1,
|
|
|
|
new Margins(20)));
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
forceLayout();
|
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-05-10 17:58:09 +02:00
|
|
|
private void showComputationCompletedOutput() {
|
2016-05-09 18:57:18 +02:00
|
|
|
HtmlLayoutContainer computationEndMessage = new HtmlLayoutContainer(
|
|
|
|
"<p>The computation <b>" + computationId.getOperatorName()
|
|
|
|
+ "</b> finished.</p>");
|
|
|
|
vert.add(computationEndMessage, new VerticalLayoutData(-1, -1,
|
|
|
|
new Margins(0)));
|
|
|
|
ComputationOutputPanel computationOutputPanel = new ComputationOutputPanel(
|
|
|
|
computationId);
|
|
|
|
computationOutputPanel.getElement().getStyle()
|
|
|
|
.setMarginBottom(36, Unit.PX);
|
|
|
|
vert.add(computationOutputPanel, new VerticalLayoutData(1, -1,
|
|
|
|
new Margins(0)));
|
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param computationStatus
|
|
|
|
*/
|
2016-05-10 17:58:09 +02:00
|
|
|
private void updateStatus(ComputationStatus computationStatus) {
|
2016-05-24 16:16:41 +02:00
|
|
|
Log.debug("Conputation Status Panel ::Update Status "
|
|
|
|
+ computationStatus);
|
|
|
|
if (computationStatus.getStatus().compareTo(Status.ACCEPTED) == 0)
|
2016-05-13 18:55:07 +02:00
|
|
|
progressBar.updateText("Accepted...");
|
2016-04-06 18:28:32 +02:00
|
|
|
else {
|
|
|
|
double percentage = computationStatus.getPercentage();
|
2016-05-24 16:16:41 +02:00
|
|
|
if (percentage == 0) {
|
2016-05-23 17:25:00 +02:00
|
|
|
progressBar.updateText("Running, 0% Complete");
|
|
|
|
} else {
|
2016-05-24 16:16:41 +02:00
|
|
|
progressBar.updateProgress(percentage / 100, "Running, "
|
|
|
|
+ percentage + "% Complete");
|
2016-05-23 17:25:00 +02:00
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
2016-05-13 18:55:07 +02:00
|
|
|
forceLayout();
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private class ComputationTimer extends Timer {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2016-05-09 18:57:18 +02:00
|
|
|
Log.debug("Timer run .....");
|
|
|
|
DataMinerPortletServiceAsync.INSTANCE.getComputationStatus(
|
|
|
|
computationId, new AsyncCallback<ComputationStatus>() {
|
2016-04-06 18:28:32 +02:00
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
int index = vert.getWidgetIndex(progressBar);
|
|
|
|
vert.remove(index);
|
|
|
|
// TODO
|
|
|
|
progressBar = new RedProgressBar();
|
|
|
|
progressBar.updateProgress(1,
|
|
|
|
"Failed to get the status");
|
|
|
|
progressBar.getElement().getStyle()
|
|
|
|
.setMarginBottom(36, Unit.PX);
|
|
|
|
vert.insert(progressBar, index,
|
|
|
|
new VerticalLayoutData(1, -1, new Margins(
|
|
|
|
20)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(
|
|
|
|
ComputationStatus computationStatus) {
|
2016-05-24 16:16:41 +02:00
|
|
|
Log.debug("ComputationStatus: "+computationStatus);
|
|
|
|
if (computationStatus != null) {
|
|
|
|
if (computationStatus.isTerminated()) {
|
|
|
|
ComputationTimer.this.cancel();
|
|
|
|
computationTerminated(computationId,
|
|
|
|
computationStatus);
|
|
|
|
} else
|
|
|
|
updateStatus(computationStatus);
|
|
|
|
}
|
2016-05-09 18:57:18 +02:00
|
|
|
}
|
|
|
|
});
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 18:57:18 +02:00
|
|
|
}
|
2016-04-06 18:28:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public void stopTimer() {
|
|
|
|
try {
|
|
|
|
timer.cancel();
|
2016-05-09 18:57:18 +02:00
|
|
|
} catch (Exception e) {
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
vert.clear();
|
2016-05-09 18:57:18 +02:00
|
|
|
|
2016-04-06 18:28:32 +02:00
|
|
|
}
|
|
|
|
}
|