Skip to content

Commit 73c14ec

Browse files
author
Yevhenii Voevodin
authored
Get rid of recover from snapshot dialog (eclipse-che#4328)
1 parent ab1821f commit 73c14ec

13 files changed

Lines changed: 151 additions & 180 deletions

File tree

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/workspace/WorkspaceServiceClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,8 @@ public interface WorkspaceServiceClient {
124124
* if <code>false</code> workspace will not be restored from snapshot
125125
* even if auto-restore is enabled and snapshot exists
126126
* @return a promise that resolves to the {@link WorkspaceDto}, or rejects with an error
127-
* @see WorkspaceService#startById(String, String, Boolean, String)
128127
*/
129-
Promise<WorkspaceDto> startById(String id, String envName, boolean restore);
128+
Promise<WorkspaceDto> startById(String id, String envName, Boolean restore);
130129

131130
/**
132131
* Stops running workspace.
@@ -273,6 +272,7 @@ public interface WorkspaceServiceClient {
273272
* @return a promise that will provide a list of {@link SnapshotDto}s, or rejects with an error
274273
* @see WorkspaceService#getSnapshot(String)
275274
*/
275+
@Deprecated
276276
Promise<List<SnapshotDto>> getSnapshot(String workspaceId);
277277

278278
/**
@@ -283,6 +283,7 @@ public interface WorkspaceServiceClient {
283283
* @return a promise that will resolve when the snapshot has been created, or rejects with an error
284284
* @see WorkspaceService#createSnapshot(String)
285285
*/
286+
@Deprecated
286287
Promise<Void> createSnapshot(String workspaceId);
287288

288289
/**

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/actions/WorkspaceSnapshotCreator.java renamed to ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/actions/WorkspaceSnapshotNotifier.java

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
import com.google.inject.Inject;
1414
import com.google.inject.Singleton;
1515

16-
import org.eclipse.che.api.promises.client.Operation;
17-
import org.eclipse.che.api.promises.client.OperationException;
18-
import org.eclipse.che.api.promises.client.PromiseError;
19-
import org.eclipse.che.ide.api.workspace.WorkspaceServiceClient;
2016
import org.eclipse.che.ide.CoreLocalizationConstant;
2117
import org.eclipse.che.ide.api.notification.NotificationManager;
2218
import org.eclipse.che.ide.api.notification.StatusNotification;
@@ -27,30 +23,35 @@
2723
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS;
2824

2925
/**
30-
* Creates snapshot of the workspace using {@link WorkspaceServiceClient}.
31-
*
32-
* <p>This component is for managing notifications which are related to creating snapshot process.
26+
* Shows notifications about workspace snapshotting progress.
27+
* Each call to {@link #creationStarted()} must be eventually followed by
28+
* either call to {@link #creationError(String)} or {@link #successfullyCreated()}.
3329
*
3430
* @author Yevhenii Voevodin
3531
*/
3632
@Singleton
37-
public class WorkspaceSnapshotCreator {
33+
public class WorkspaceSnapshotNotifier {
3834

39-
private final WorkspaceServiceClient workspaceService;
4035
private final NotificationManager notificationManager;
4136
private final CoreLocalizationConstant locale;
4237

4338
private StatusNotification notification;
4439

4540
@Inject
46-
public WorkspaceSnapshotCreator(WorkspaceServiceClient workspaceService,
47-
NotificationManager notificationManager,
48-
CoreLocalizationConstant locale) {
49-
this.workspaceService = workspaceService;
41+
public WorkspaceSnapshotNotifier(NotificationManager notificationManager, CoreLocalizationConstant locale) {
5042
this.notificationManager = notificationManager;
5143
this.locale = locale;
5244
}
5345

46+
/**
47+
* Starts showing snapshotting notification.
48+
* The notification is shown until either {@link #creationError(String)}
49+
* or {@link #successfullyCreated()} is called.
50+
*/
51+
public void creationStarted() {
52+
notification = notificationManager.notify(locale.createSnapshotProgress(), PROGRESS, FLOAT_MODE);
53+
}
54+
5455
/**
5556
* Changes notification state to finished with an error.
5657
*/
@@ -71,28 +72,4 @@ public void successfullyCreated() {
7172
notification.setTitle(locale.createSnapshotSuccess());
7273
}
7374
}
74-
75-
/**
76-
* Returns true if workspace creation process is not done, otherwise when it is done - returns false
77-
*/
78-
public boolean isInProgress() {
79-
return notification != null && notification.getStatus() == PROGRESS;
80-
}
81-
82-
/**
83-
* Creates snapshot from workspace with given id and shows appropriate notification.
84-
*
85-
* @param workspaceId
86-
* id of the workspace to create snapshot from.
87-
*/
88-
public void createSnapshot(String workspaceId) {
89-
notification = notificationManager.notify(locale.createSnapshotProgress(), PROGRESS, FLOAT_MODE);
90-
workspaceService.createSnapshot(workspaceId)
91-
.catchError(new Operation<PromiseError>() {
92-
@Override
93-
public void apply(PromiseError error) throws OperationException {
94-
creationError(error.getMessage());
95-
}
96-
});
97-
}
9875
}

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/DefaultWorkspaceComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void start(final Callback<Component, Exception> callback) {
8484
new Operation<WorkspaceDto>() {
8585
@Override
8686
public void apply(WorkspaceDto workspaceDto) throws OperationException {
87-
handleWorkspaceEvents(workspaceDto, callback, true, false);
87+
handleWorkspaceEvents(workspaceDto, callback, null);
8888
}
8989
}).catchError(new Operation<PromiseError>() {
9090
@Override

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceComponent.java

Lines changed: 6 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import org.eclipse.che.api.core.model.workspace.Workspace;
1818
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
19-
import org.eclipse.che.api.machine.shared.dto.SnapshotDto;
2019
import org.eclipse.che.api.promises.client.Function;
2120
import org.eclipse.che.api.promises.client.FunctionException;
2221
import org.eclipse.che.api.promises.client.Operation;
@@ -26,8 +25,6 @@
2625
import org.eclipse.che.ide.CoreLocalizationConstant;
2726
import org.eclipse.che.ide.api.app.AppContext;
2827
import org.eclipse.che.ide.api.component.Component;
29-
import org.eclipse.che.ide.api.dialogs.CancelCallback;
30-
import org.eclipse.che.ide.api.dialogs.ConfirmCallback;
3128
import org.eclipse.che.ide.api.dialogs.DialogFactory;
3229
import org.eclipse.che.ide.api.machine.events.WsAgentStateEvent;
3330
import org.eclipse.che.ide.api.machine.events.WsAgentStateHandler;
@@ -48,7 +45,6 @@
4845
import org.eclipse.che.ide.workspace.create.CreateWorkspacePresenter;
4946
import org.eclipse.che.ide.workspace.start.StartWorkspacePresenter;
5047

51-
import java.util.List;
5248
import java.util.Map;
5349

5450
import static org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_START;
@@ -165,13 +161,11 @@ public void setCurrentWorkspace(Workspace workspace) {
165161
* workspace to listen
166162
* @param callback
167163
* callback
168-
* @param checkForShapshots
169-
* whether is needed checking workspace for snapshots
170164
* @param restoreFromSnapshot
171165
* restore or not the workspace from snapshot
172166
*/
173167
public void handleWorkspaceEvents(final WorkspaceDto workspace, final Callback<Component, Exception> callback,
174-
final boolean checkForShapshots, final boolean restoreFromSnapshot) {
168+
final Boolean restoreFromSnapshot) {
175169
this.callback = callback;
176170
if (messageBus != null) {
177171
messageBus.cancelReconnection();
@@ -211,12 +205,7 @@ public void execute() {
211205
@Override
212206
public Map<String, String> apply(Map<String, String> settings) throws FunctionException {
213207
if (Boolean.parseBoolean(settings.getOrDefault(CHE_WORKSPACE_AUTO_START, "true"))) {
214-
if (checkForShapshots) {
215-
checkWorkspaceForSnapshots(workspace);
216-
} else {
217-
startWorkspaceById(workspace.getId(), workspace.getConfig().getDefaultEnv(),
218-
restoreFromSnapshot);
219-
}
208+
startWorkspaceById(workspace.getId(), workspace.getConfig().getDefaultEnv(), restoreFromSnapshot);
220209
} else {
221210
loader.show(WORKSPACE_STOPPED);
222211
}
@@ -235,17 +224,15 @@ public Map<String, String> apply(Map<String, String> settings) throws FunctionEx
235224
* workspace ID to start
236225
* @param callback
237226
* callback
238-
* @param checkForShapshots
239-
* whether is needed checking workspace for snapshots
240227
* @param restoreFromSnapshot
241228
* restore or not the workspace from snapshot
242229
*/
243230
public void startWorkspace(final String workspaceID, final Callback<Component, Exception> callback,
244-
final boolean checkForShapshots, final boolean restoreFromSnapshot) {
231+
final Boolean restoreFromSnapshot) {
245232
workspaceServiceClient.getWorkspace(workspaceID).then(new Operation<WorkspaceDto>() {
246233
@Override
247234
public void apply(WorkspaceDto workspace) throws OperationException {
248-
handleWorkspaceEvents(workspace, callback, checkForShapshots, restoreFromSnapshot);
235+
handleWorkspaceEvents(workspace, callback, restoreFromSnapshot);
249236
}
250237
});
251238
}
@@ -259,26 +246,7 @@ public void apply(WorkspaceDto workspace) throws OperationException {
259246
* callback to be executed
260247
*/
261248
public void startWorkspace(final Workspace workspace, final Callback<Component, Exception> callback) {
262-
startWorkspace(workspace.getId(), callback, true, false);
263-
}
264-
265-
/**
266-
* Checks workspace for snapshots and asks the uses for an action.
267-
*
268-
* @param workspace
269-
* workspace
270-
*/
271-
private void checkWorkspaceForSnapshots(final Workspace workspace) {
272-
workspaceServiceClient.getSnapshot(workspace.getId()).then(new Operation<List<SnapshotDto>>() {
273-
@Override
274-
public void apply(List<SnapshotDto> snapshots) throws OperationException {
275-
if (snapshots.isEmpty()) {
276-
startWorkspaceById(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
277-
} else {
278-
showRecoverWorkspaceConfirmDialog(workspace);
279-
}
280-
}
281-
});
249+
startWorkspace(workspace.getId(), callback, null);
282250
}
283251

284252
/**
@@ -288,30 +256,6 @@ private native void notifyShowIDE() /*-{
288256
$wnd.parent.postMessage("show-ide", "*");
289257
}-*/;
290258

291-
/**
292-
* Shows workspace recovering confirm dialog.
293-
*/
294-
private void showRecoverWorkspaceConfirmDialog(final Workspace workspace) {
295-
dialogFactory.createConfirmDialog(locale.workspaceRecoveringDialogTitle(),
296-
locale.workspaceRecoveringDialogText(),
297-
locale.yesButtonTitle(),
298-
locale.noButtonTitle(),
299-
new ConfirmCallback() {
300-
@Override
301-
public void accepted() {
302-
startWorkspaceById(workspace.getId(), workspace.getConfig().getDefaultEnv(), true);
303-
}
304-
},
305-
new CancelCallback() {
306-
@Override
307-
public void cancelled() {
308-
startWorkspaceById(workspace.getId(), workspace.getConfig().getDefaultEnv(), false);
309-
}
310-
}).show();
311-
312-
notifyShowIDE();
313-
}
314-
315259
/**
316260
* Starts specified workspace if it's {@link WorkspaceStatus} different of {@code RUNNING}
317261
*/
@@ -326,7 +270,7 @@ public void apply(WorkspaceDto workspaceToStart) throws OperationException {
326270

327271
abstract void tryStartWorkspace();
328272

329-
private void startWorkspaceById(String workspaceId, String defaultEnvironment, boolean restoreFromSnapshot) {
273+
private void startWorkspaceById(String workspaceId, String defaultEnvironment, Boolean restoreFromSnapshot) {
330274
loader.show(STARTING_WORKSPACE_RUNTIME);
331275
workspaceServiceClient.startById(workspaceId, defaultEnvironment, restoreFromSnapshot).catchError(new Operation<PromiseError>() {
332276
@Override

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceEventsHandler.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent;
3535
import org.eclipse.che.ide.CoreLocalizationConstant;
3636
import org.eclipse.che.ide.DelayedTask;
37-
import org.eclipse.che.ide.actions.WorkspaceSnapshotCreator;
37+
import org.eclipse.che.ide.actions.WorkspaceSnapshotNotifier;
3838
import org.eclipse.che.ide.api.component.Component;
3939
import org.eclipse.che.ide.api.dialogs.ConfirmCallback;
4040
import org.eclipse.che.ide.api.dialogs.DialogFactory;
@@ -92,7 +92,7 @@ public class WorkspaceEventsHandler {
9292
private final DtoUnmarshallerFactory dtoUnmarshallerFactory;
9393
private final Provider<DefaultWorkspaceComponent> wsComponentProvider;
9494
private final AsyncRequestFactory asyncRequestFactory;
95-
private final WorkspaceSnapshotCreator snapshotCreator;
95+
private final WorkspaceSnapshotNotifier snapshotNotifier;
9696
private final WorkspaceServiceClient workspaceServiceClient;
9797
private final StartWorkspaceNotification startWorkspaceNotification;
9898
private final ExecAgentCommandManager execAgentCommandManager;
@@ -124,7 +124,7 @@ public class WorkspaceEventsHandler {
124124
final DtoUnmarshallerFactory dtoUnmarshallerFactory,
125125
final NotificationManager notificationManager,
126126
final MessageBusProvider messageBusProvider,
127-
final WorkspaceSnapshotCreator snapshotCreator,
127+
final WorkspaceSnapshotNotifier snapshotNotifier,
128128
final WorkspaceServiceClient workspaceServiceClient,
129129
final StartWorkspaceNotification startWorkspaceNotification,
130130
final Provider<DefaultWorkspaceComponent> wsComponentProvider,
@@ -134,7 +134,7 @@ public class WorkspaceEventsHandler {
134134
this.eventBus = eventBus;
135135
this.locale = locale;
136136
this.messageBusProvider = messageBusProvider;
137-
this.snapshotCreator = snapshotCreator;
137+
this.snapshotNotifier = snapshotNotifier;
138138
this.notificationManager = notificationManager;
139139
this.dialogFactory = dialogFactory;
140140
this.dtoUnmarshallerFactory = dtoUnmarshallerFactory;
@@ -417,11 +417,12 @@ protected void onMessageReceived(WorkspaceStatusEvent statusEvent) {
417417

418418
case SNAPSHOT_CREATING:
419419
loader.show(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
420+
snapshotNotifier.creationStarted();
420421
break;
421422

422423
case SNAPSHOT_CREATED:
423424
loader.setSuccess(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
424-
snapshotCreator.successfullyCreated();
425+
snapshotNotifier.successfullyCreated();
425426

426427
wsStartedNotification = new DelayedTask() {
427428
@Override
@@ -442,7 +443,7 @@ public void onExecute() {
442443

443444
case SNAPSHOT_CREATION_ERROR:
444445
loader.setError(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
445-
snapshotCreator.creationError("Snapshot creation error: " + statusEvent.getError());
446+
snapshotNotifier.creationError("Snapshot creation error: " + statusEvent.getError());
446447
break;
447448
}
448449
}

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/WorkspaceServiceClientImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ public Promise<WorkspaceDto> startFromConfig(final WorkspaceConfigDto cfg, final
142142
}
143143

144144
@Override
145-
public Promise<WorkspaceDto> startById(@NotNull final String id, final String envName, final boolean restore) {
146-
String url = baseHttpUrl + "/" + id + "/runtime?restore=" + restore;
145+
public Promise<WorkspaceDto> startById(@NotNull final String id, final String envName, final Boolean restore) {
146+
String url = baseHttpUrl + "/" + id + "/runtime";
147+
if (restore != null) {
148+
url += "?restore=" + restore;
149+
}
147150
if (envName != null) {
148-
url += "&environment=" + envName;
151+
url += (url.contains("?") ? '&' : '?') + "environment=" + envName;
149152
}
150153
return asyncRequestFactory.createPostRequest(url, null)
151154
.header(ACCEPT, APPLICATION_JSON)

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/workspace/start/StartWorkspaceNotification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void onSuccess(Component result) {
107107
@Override
108108
public void onFailure(Exception reason) {
109109
}
110-
}, false, restore.getValue().booleanValue());
110+
}, restore.getValue());
111111
}
112112

113113
}

0 commit comments

Comments
 (0)