Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-7278 Properly handle restarting the workspace #8612

Merged
merged 6 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ public interface CoreLocalizationConstant extends Messages {
@Key("start.ws.title")
String startWsTitle();

@Key("start.ws.description")
String startWsDescription();

@Key("stop.ws.title")
String stopWsTitle();

Expand Down Expand Up @@ -1298,6 +1301,12 @@ String sshConnectInfo(
@Key("menu.loader.workspaceStarted")
String menuLoaderWorkspaceStarted();

@Key("menu.loader.workspaceStopping")
String menuLoaderWorkspaceStopping();

@Key("menu.loader.workspaceStopped")
String menuLoaderWorkspaceStopped();

@Key("menu.loader.waitingWorkspace")
String menuLoaderWaitingWorkspace();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
import org.eclipse.che.ide.ui.toolbar.ToolbarPresenter;
import org.eclipse.che.ide.util.browser.UserAgent;
import org.eclipse.che.ide.util.input.KeyCodeMap;
import org.eclipse.che.ide.workspace.StartWorkspaceAction;
import org.eclipse.che.ide.workspace.StopWorkspaceAction;
import org.vectomatic.dom.svg.ui.SVGImage;
import org.vectomatic.dom.svg.ui.SVGResource;
Expand Down Expand Up @@ -350,6 +351,8 @@ public interface ParserResource extends ClientBundle {

@Inject private SoftWrapAction softWrapAction;

@Inject private StartWorkspaceAction startWorkspaceAction;

@Inject private StopWorkspaceAction stopWorkspaceAction;

@Inject private ShowWorkspaceStatusAction showWorkspaceStatusAction;
Expand Down Expand Up @@ -526,6 +529,7 @@ public void initialize() {
workspaceGroup.add(downloadWsAction);

workspaceGroup.addSeparator();
workspaceGroup.add(startWorkspaceAction);
workspaceGroup.add(stopWorkspaceAction);
workspaceGroup.add(showWorkspaceStatusAction);

Expand Down Expand Up @@ -697,6 +701,7 @@ public void initialize() {
helpGroup.addSeparator();

// Processes panel actions
actionManager.registerAction("startWorkspace", startWorkspaceAction);
actionManager.registerAction("stopWorkspace", stopWorkspaceAction);
actionManager.registerAction("showWorkspaceStatus", showWorkspaceStatusAction);
actionManager.registerAction("runCommand", runCommandAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public class WsMasterJsonRpcInitializer {
private final SecurityTokenProvider securityTokenProvider;
private final WsAgentServerUtil wsAgentServerUtil;

private boolean initialized = false;

@Inject
public WsMasterJsonRpcInitializer(
JsonRpcInitializer initializer,
Expand All @@ -87,15 +89,13 @@ public WsMasterJsonRpcInitializer(

eventBus.addHandler(BasicIDEInitializedEvent.TYPE, e -> initialize());
eventBus.addHandler(WorkspaceStartingEvent.TYPE, e -> initialize());
eventBus.addHandler(
WorkspaceStoppedEvent.TYPE,
e -> {
unsubscribeFromEvents();
terminate();
});
}

private void initialize() {
if (initialized) {
return;
}

securityTokenProvider
.getSecurityToken()
.then(
Expand Down Expand Up @@ -128,6 +128,8 @@ private void initialize() {
initActions.add(this::checkStatuses);

initializer.initialize(WS_MASTER_JSON_RPC_ENDPOINT_ID, initProperties, initActions);

initialized = true;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.eclipse.che.ide.ui.smartTree.data.settings.NodeSettings;
import org.eclipse.che.ide.ui.smartTree.data.settings.SettingsProvider;
import org.eclipse.che.ide.ui.smartTree.presentation.HasPresentation;
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.providers.DynaObject;
import org.vectomatic.dom.svg.ui.SVGResource;

Expand Down Expand Up @@ -128,7 +129,7 @@ public ProjectExplorerPresenter(
eventBus.addHandler(ResourceChangedEvent.getType(), this);
eventBus.addHandler(MarkerChangedEvent.getType(), this);
eventBus.addHandler(SyntheticNodeUpdateEvent.getType(), this);
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, event -> getTree().getNodeStorage().clear());
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, event -> onWorkspaceStopped());
eventBus.addHandler(WorkspaceRunningEvent.TYPE, event -> view.showPlaceholder(false));
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, event -> view.showPlaceholder(true));
eventBus.addHandler(WorkspaceStartingEvent.TYPE, event -> view.showPlaceholder(true));
Expand Down Expand Up @@ -180,6 +181,14 @@ public ProjectExplorerPresenter(
});
}

private void onWorkspaceStopped() {
try {
getTree().getNodeStorage().clear();
} catch (Exception e) {
Log.error(getClass(), e.getMessage(), e);
}
}

public void addSelectionHandler(SelectionHandler<Node> handler) {
getTree().getSelectionModel().addSelectionHandler(handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,26 @@

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.Collections;
import javax.validation.constraints.NotNull;
import org.eclipse.che.ide.CoreLocalizationConstant;
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.part.perspectives.project.ProjectPerspective;
import org.eclipse.che.ide.api.action.BaseAction;

/** Action to show workspace status. */
@Singleton
public class ShowWorkspaceStatusAction extends AbstractPerspectiveAction {
public class ShowWorkspaceStatusAction extends BaseAction {

private WorkspaceLoadingTrackerImpl workspaceLoadingTracker;

@Inject
public ShowWorkspaceStatusAction(
CoreLocalizationConstant localizationConstant,
WorkspaceLoadingTrackerImpl workspaceLoadingTracker) {
super(
Collections.singletonList(ProjectPerspective.PROJECT_PERSPECTIVE_ID),
localizationConstant.workspaceStatusTitle());
super(localizationConstant.workspaceStatusTitle());
this.workspaceLoadingTracker = workspaceLoadingTracker;
}

@Override
public void actionPerformed(ActionEvent e) {
workspaceLoadingTracker.showPanel();
}

@Override
public void updateInPerspective(@NotNull ActionEvent event) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.che.ide.api.workspace.event.WorkspaceRunningEvent;
import org.eclipse.che.ide.api.workspace.event.WorkspaceStartingEvent;
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent;
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppingEvent;
import org.eclipse.che.ide.api.workspace.model.EnvironmentImpl;
import org.eclipse.che.ide.api.workspace.model.MachineConfigImpl;
import org.eclipse.che.ide.api.workspace.model.MachineImpl;
Expand All @@ -56,6 +57,7 @@ public class WorkspaceLoadingTrackerImpl
InstallerFailedEvent.Handler,
WorkspaceStartingEvent.Handler,
WorkspaceRunningEvent.Handler,
WorkspaceStoppingEvent.Handler,
WorkspaceStoppedEvent.Handler,
MachineStatusChangedEvent.Handler,
WorkspaceLoadingTrackerView.ActionDelegate {
Expand Down Expand Up @@ -99,6 +101,7 @@ public WorkspaceLoadingTrackerImpl(
eventBus.addHandler(WorkspaceStartingEvent.TYPE, this);
eventBus.addHandler(WorkspaceRunningEvent.TYPE, this);
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, this);
eventBus.addHandler(WorkspaceStoppingEvent.TYPE, this);

eventBus.addHandler(
MachineRunningEvent.TYPE,
Expand Down Expand Up @@ -259,6 +262,9 @@ public void onWorkspaceStarting(WorkspaceStartingEvent event) {

addMachines();
showInstallers();

processesListView.setLoadMode();
processesListView.setLoadingMessage(localizationConstant.menuLoaderWaitingWorkspace());
}

@Override
Expand All @@ -285,8 +291,24 @@ public void run() {
}.schedule(3000);
}

@Override
public void onWorkspaceStopping(WorkspaceStoppingEvent event) {
isWorkspaceStarting = false;

showPanel();
view.showWorkspaceStopping();

processesListView.setLoadMode();
processesListView.setLoadingMessage(localizationConstant.menuLoaderWorkspaceStopping());
processesListView.setLoadingProgress(100);
}

@Override
public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
processesListView.setLoadMode();
processesListView.setLoadingMessage(localizationConstant.menuLoaderWorkspaceStopped());
processesListView.setLoadingProgress(0);

if (isWorkspaceStarting) {
view.showWorkspaceFailed(null);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void addInstaller(
/** Shows workspace started section. */
void showWorkspaceStarted();

/** Shows workspace stopping section. */
void showWorkspaceStopping();

/** Shows workspace stopped section. */
void showWorkspaceStopped();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ interface WorkspaceLoadingTrackerViewImplUiBinder
@UiField TableRowElement installerFailedTemplate;
@UiField TableRowElement machinesDelimiterTemplate;

@UiField TableRowElement waitingWorkspaceSection;
@UiField TableRowElement workspaceStartingSection;

@UiField TableRowElement workspaceStartedSection;
@UiField TableRowElement workspaceStartedSectionFooter;

@UiField TableRowElement workspaceStoppingSection;
@UiField TableRowElement workspaceStoppedSection;

@UiField TableRowElement workspaceFailedSection;
Expand Down Expand Up @@ -503,17 +504,25 @@ public void setInstallerRunning(String machineName, String installerId) {
}
}

@Override
public void showWorkspaceStarting() {
waitingWorkspaceSection.getStyle().clearDisplay();
private void hideSections() {
workspaceStartingSection.getStyle().setDisplay(Style.Display.NONE);

workspaceStartedSection.getStyle().setDisplay(Style.Display.NONE);
workspaceStartedSectionFooter.getStyle().setDisplay(Style.Display.NONE);

workspaceStoppingSection.getStyle().setDisplay(Style.Display.NONE);

workspaceStoppedSection.getStyle().setDisplay(Style.Display.NONE);

workspaceFailedSection.getStyle().setDisplay(Style.Display.NONE);
workspaceFailedSectionFooter.getStyle().setDisplay(Style.Display.NONE);
}

@Override
public void showWorkspaceStarting() {
hideSections();

workspaceStartingSection.getStyle().clearDisplay();

for (Machine machine : machines.values()) {
machine.reset();
Expand All @@ -522,23 +531,30 @@ public void showWorkspaceStarting() {

@Override
public void showWorkspaceStarted() {
waitingWorkspaceSection.getStyle().setDisplay(Style.Display.NONE);
hideSections();

workspaceStartedSection.getStyle().clearDisplay();
workspaceStartedSectionFooter.getStyle().clearDisplay();
}

workspaceStoppedSection.getStyle().setDisplay(Style.Display.NONE);
@Override
public void showWorkspaceStopping() {
hideSections();

workspaceFailedSection.getStyle().setDisplay(Style.Display.NONE);
workspaceFailedSectionFooter.getStyle().setDisplay(Style.Display.NONE);
workspaceStoppingSection.getStyle().clearDisplay();

for (Machine machine : machines.values()) {
machine.setState("stopping");

for (Installer installer : machine.installers.values()) {
installer.reset();
}
}
}

@Override
public void showWorkspaceStopped() {
waitingWorkspaceSection.getStyle().setDisplay(Style.Display.NONE);

workspaceStartedSection.getStyle().setDisplay(Style.Display.NONE);
workspaceStartedSectionFooter.getStyle().setDisplay(Style.Display.NONE);
hideSections();

workspaceStoppedSection.getStyle().clearDisplay();

Expand All @@ -549,22 +565,13 @@ public void showWorkspaceStopped() {
installer.setStopped();
}
}

workspaceFailedSection.getStyle().setDisplay(Style.Display.NONE);
workspaceFailedSectionFooter.getStyle().setDisplay(Style.Display.NONE);
}

@Override
public void showWorkspaceFailed(String error) {
waitingWorkspaceSection.getStyle().setDisplay(Style.Display.NONE);

workspaceStartedSection.getStyle().setDisplay(Style.Display.NONE);
workspaceStartedSectionFooter.getStyle().setDisplay(Style.Display.NONE);

workspaceStoppedSection.getStyle().setDisplay(Style.Display.NONE);
hideSections();

workspaceFailedSection.getStyle().clearDisplay();

workspaceFailedSectionFooter.getStyle().clearDisplay();
}

Expand Down
Loading