Skip to content

Commit

Permalink
Make snapshots binaries removal asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhenii Voevodin committed Dec 16, 2016
1 parent 806febf commit 7741032
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 218 deletions.
6 changes: 3 additions & 3 deletions dashboard/src/app/ide/ide.service.ts
Expand Up @@ -159,7 +159,7 @@ class IdeSvc {
this.listeningChannels.push(statusChannel);
// for now, display log of status channel in case of errors
bus.subscribe(statusChannel, (message: any) => {
if (message.eventType === 'DESTROYED' && message.workspaceId === data.id && !(this.$rootScope as any).showIDE) {
if (message.status === 'DESTROYED' && message.workspaceId === data.id && !(this.$rootScope as any).showIDE) {
// need to show the error
this.$mdDialog.show(
this.$mdDialog.alert()
Expand All @@ -169,7 +169,7 @@ class IdeSvc {
.ok('OK')
);
}
if (message.eventType === 'ERROR' && message.workspaceId === data.id) {
if (message.status === 'STOPPED' && message.error && message.workspaceId === data.id) {
let errorMessage = 'Error when trying to start the workspace';
if (message.error) {
errorMessage += ': ' + message.error;
Expand All @@ -190,7 +190,7 @@ class IdeSvc {

this.listeningChannels.push(agentChannel);
bus.subscribe(agentChannel, (message: any) => {
if (message.eventType === 'ERROR' && message.workspaceId === data.id) {
if (message.status === 'STOPPED' && message.error && message.workspaceId === data.id) {
// need to show the error
this.$mdDialog.show(
this.$mdDialog.alert()
Expand Down
Expand Up @@ -481,7 +481,7 @@ export class CreateProjectController {
this.listeningChannels.push(statusChannel);
bus.subscribe(statusChannel, (message: any) => {
message = this.getDisplayMachineLog(message);
if (message.eventType === 'DESTROYED' && message.workspaceId === workspace.id) {
if (message.status === 'DESTROYED' && message.workspaceId === workspace.id) {
this.getCreationSteps()[this.getCurrentProgressStep()].hasError = true;

// need to show the error
Expand All @@ -493,7 +493,7 @@ export class CreateProjectController {
.ok('OK')
);
}
if (message.eventType === 'ERROR' && message.workspaceId === workspace.id) {
if (message.status === 'STOPPED' && message.error && message.workspaceId === workspace.id) {
this.getCreationSteps()[this.getCurrentProgressStep()].hasError = true;
let errorMessage = 'Error when trying to start the workspace';
if (message.error) {
Expand Down
23 changes: 6 additions & 17 deletions dashboard/src/components/api/che-workspace.factory.ts
Expand Up @@ -40,7 +40,6 @@ export class CheWorkspace {
$resource: ng.resource.IResourceService;
$q: ng.IQService;
listeners: Array<any>;
workspaceStatuses: Array<string>;
workspaces: Array<che.IWorkspace>;
subscribedWorkspacesIds: Array<string>;
workspaceAgents: Map<string, CheWorkspaceAgent>;
Expand All @@ -55,8 +54,6 @@ export class CheWorkspace {
* @ngInject for Dependency injection
*/
constructor($resource: ng.resource.IResourceService, $q: ng.IQService, cheWebsocket: CheWebsocket, lodash: any, cheEnvironmentRegistry: CheEnvironmentRegistry, $log: ng.ILogService) {
this.workspaceStatuses = ['RUNNING', 'STOPPED', 'PAUSED', 'STARTING', 'STOPPING', 'ERROR'];

// keep resource
this.$q = $q;
this.$resource = $resource;
Expand Down Expand Up @@ -409,7 +406,7 @@ export class CheWorkspace {
* @param workspaceId {string}
* @returns {ng.IPromise<any>} promise
*/
stopWorkspace(workspaceId: string): ng.IPromise<any> {
stopWorkspace(workspaceId: string, snapshot: boolean): ng.IPromise<any> {
return this.remoteWorkspaceAPI.stopWorkspace({workspaceId: workspaceId}, {}).$promise;
}

Expand Down Expand Up @@ -543,26 +540,18 @@ export class CheWorkspace {
this.subscribedWorkspacesIds.push(workspaceId);

bus.subscribe('workspace:' + workspaceId, (message: any) => {
let status = (message.status === 'STOPPED' && message.error) ? 'ERROR' : message.status;
this.getWorkspaceById(workspaceId).status = status;

// filter workspace events, which really indicate the status change:
if (this.workspaceStatuses.indexOf(message.eventType) >= 0) {
this.getWorkspaceById(workspaceId).status = message.eventType;
} else if (message.eventType === 'SNAPSHOT_CREATING') {
this.getWorkspaceById(workspaceId).status = 'SNAPSHOTTING';
} else if (message.eventType === 'SNAPSHOT_CREATED') {
// snapshot can be created for RUNNING workspace only.
this.getWorkspaceById(workspaceId).status = 'RUNNING';
}

if (!this.statusDefers[workspaceId] || !this.statusDefers[workspaceId][message.eventType]) {
if (!this.statusDefers[workspaceId] || !this.statusDefers[workspaceId][status]) {
return;
}

this.statusDefers[workspaceId][message.eventType].forEach((defer: any) => {
this.statusDefers[workspaceId][status].forEach((defer: any) => {
defer.resolve(message);
});

this.statusDefers[workspaceId][message.eventType].length = 0;
this.statusDefers[workspaceId][status].length = 0;
});
}
}
Expand Down
Expand Up @@ -73,7 +73,7 @@ export class CheRemoteWorkspace {
let bus = this.cheWebsocket.getRemoteBus(remoteWsURL);
// subscribe to workspace events
bus.subscribe('workspace:' + workspaceId, (message) => {
if (message.eventType === 'RUNNING' && message.workspaceId === workspaceId) {
if (message.status === 'RUNNING' && message.prevStatus === 'STARTING' && message.workspaceId === workspaceId) {
let promise = this.remoteWorkspaceAPI.getDetails({workspaceId: workspaceId}, {}).$promise;
promise.then((workspace) => {
deferred.resolve(workspace);
Expand Down
Expand Up @@ -23,9 +23,7 @@
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.api.core.rest.shared.dto.LinkParameter;
import org.eclipse.che.api.machine.shared.Constants;
import org.eclipse.che.api.machine.shared.dto.MachineLogMessageDto;
import org.eclipse.che.api.machine.shared.dto.MachineProcessDto;
import org.eclipse.che.api.machine.shared.dto.event.MachineStatusEvent;
import org.eclipse.che.api.machine.shared.dto.execagent.GetProcessLogsResponseDto;
import org.eclipse.che.api.machine.shared.dto.execagent.GetProcessesResponseDto;
Expand All @@ -42,7 +40,6 @@
import org.eclipse.che.ide.api.dialogs.DialogFactory;
import org.eclipse.che.ide.api.machine.ExecAgentCommandManager;
import org.eclipse.che.ide.api.machine.MachineManager;
import org.eclipse.che.ide.api.machine.MachineServiceClient;
import org.eclipse.che.ide.api.machine.OutputMessageUnmarshaller;
import org.eclipse.che.ide.api.machine.events.WsAgentStateEvent;
import org.eclipse.che.ide.api.notification.NotificationManager;
Expand All @@ -54,7 +51,6 @@
import org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent;
import org.eclipse.che.ide.rest.AsyncRequestFactory;
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
import org.eclipse.che.ide.rest.StringUnmarshaller;
import org.eclipse.che.ide.ui.loaders.LoaderPresenter;
import org.eclipse.che.ide.util.loging.Log;
import org.eclipse.che.ide.websocket.MessageBus;
Expand Down Expand Up @@ -105,13 +101,13 @@ public class WorkspaceEventsHandler {
private final ExecAgentCommandManager execAgentCommandManager;
private final LoaderPresenter loader;

private DefaultWorkspaceComponent workspaceComponent;
private MessageBus messageBus;
private MessageBusProvider messageBusProvider;
private String environmentStatusChannel;
private String environmentOutputChannel;
private String wsAgentLogChannel;
private String workspaceStatusChannel;
private DefaultWorkspaceComponent workspaceComponent;
private MessageBus messageBus;
private MessageBusProvider messageBusProvider;
private String environmentStatusChannel;
private String environmentOutputChannel;
private String wsAgentLogChannel;
private String workspaceStatusChannel;

@VisibleForTesting
WorkspaceStatusSubscriptionHandler workspaceStatusSubscriptionHandler;
Expand Down Expand Up @@ -198,7 +194,7 @@ public void apply(WorkspaceDto workspace) throws OperationException {
workspaceComponent.setCurrentWorkspace(workspace);
machineManagerProvider.get();

loader.show(LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME);
loader.show(LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME);
eventBus.fireEvent(new WorkspaceStartingEvent(workspace));
}
});
Expand Down Expand Up @@ -312,7 +308,7 @@ private void subscribeOnWsAgentOutputChannel(final WorkspaceDto workspace, final
}

restoreDevMachineLogs(workspace.getRuntime().getDevMachine()); //try to restore logs if workspace already started
// and dev machine provide some output
// and dev machine provide some output
wsAgentLogChannel = "workspace:" + workspace.getId() + ":ext-server:output";
wsAgentLogSubscriptionHandler = new WsAgentOutputSubscriptionHandler(wsMachineName);
subscribeToChannel(wsAgentLogChannel, wsAgentLogSubscriptionHandler);
Expand Down Expand Up @@ -391,51 +387,49 @@ public WorkspaceStatusSubscriptionHandler(final WorkspaceDto workspace) {
@Override
protected void onMessageReceived(WorkspaceStatusEvent statusEvent) {
final String workspaceId = statusEvent.getWorkspaceId();
switch (statusEvent.getEventType()) {
switch (statusEvent.getStatus()) {
case STARTING:
onWorkspaceStarting(workspaceId);
break;

case RUNNING:
if (statusEvent.getPrevStatus() == WorkspaceStatus.STARTING) {
onWorkspaceStarted(workspaceId);
} else if (statusEvent.getPrevStatus() == WorkspaceStatus.SNAPSHOTTING) {
if (statusEvent.getError() == null) {
loader.setSuccess(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
snapshotCreator.successfullyCreated();
} else {
loader.setError(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
snapshotCreator.creationError("Snapshot creation error: " + statusEvent.getError());
}
}
break;

case ERROR:
notificationManager.notify(locale.workspaceStartFailed(), FAIL, FLOAT_MODE);
loader.setError(LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME);
final String workspaceName = workspace.getConfig().getName();
final String error = statusEvent.getError();
workspaceServiceClient.getWorkspaces(SKIP_COUNT, MAX_COUNT).then(showErrorDialog(workspaceName, error));
eventBus.fireEvent(new WorkspaceStoppedEvent(workspace));
eventBus.fireEvent(WsAgentStateEvent.createWsAgentStoppedEvent());
break;

case STOPPING:
loader.show(LoaderPresenter.Phase.STOPPING_WORKSPACE);
break;

case STOPPED:
loader.setSuccess(LoaderPresenter.Phase.STOPPING_WORKSPACE);
startWorkspaceNotification.show(statusEvent.getWorkspaceId());
eventBus.fireEvent(new WorkspaceStoppedEvent(workspace));
eventBus.fireEvent(WsAgentStateEvent.createWsAgentStoppedEvent());
if (statusEvent.getError() == null) {
loader.setSuccess(LoaderPresenter.Phase.STOPPING_WORKSPACE);
startWorkspaceNotification.show(statusEvent.getWorkspaceId());
eventBus.fireEvent(new WorkspaceStoppedEvent(workspace));
eventBus.fireEvent(WsAgentStateEvent.createWsAgentStoppedEvent());
} else {
notificationManager.notify(locale.workspaceStartFailed(), FAIL, FLOAT_MODE);
loader.setError(LoaderPresenter.Phase.STARTING_WORKSPACE_RUNTIME);
final String workspaceName = workspace.getConfig().getName();
final String error = statusEvent.getError();
workspaceServiceClient.getWorkspaces(SKIP_COUNT, MAX_COUNT).then(showErrorDialog(workspaceName, error));
eventBus.fireEvent(new WorkspaceStoppedEvent(workspace));
eventBus.fireEvent(WsAgentStateEvent.createWsAgentStoppedEvent());
}
break;

case SNAPSHOT_CREATING:
case SNAPSHOTTING:
loader.show(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
break;

case SNAPSHOT_CREATED:
loader.setSuccess(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
snapshotCreator.successfullyCreated();
break;

case SNAPSHOT_CREATION_ERROR:
loader.setError(LoaderPresenter.Phase.CREATING_WORKSPACE_SNAPSHOT);
snapshotCreator.creationError("Snapshot creation error: " + statusEvent.getError());
break;
}
}

Expand Down
Expand Up @@ -14,7 +14,6 @@
import com.google.inject.Provider;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.api.core.rest.shared.dto.LinkParameter;
import org.eclipse.che.api.machine.shared.dto.MachineConfigDto;
Expand Down Expand Up @@ -69,13 +68,10 @@
import java.util.List;
import java.util.Map;

import static org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType.ERROR;
import static org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType.RUNNING;
import static org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType.SNAPSHOT_CREATED;
import static org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType.SNAPSHOT_CREATING;
import static org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType.SNAPSHOT_CREATION_ERROR;
import static org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType.STARTING;
import static org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent.EventType.STOPPED;
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.RUNNING;
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.SNAPSHOTTING;
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STARTING;
import static org.eclipse.che.api.core.model.workspace.WorkspaceStatus.STOPPED;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
Expand Down Expand Up @@ -198,7 +194,7 @@ public void setUp() {
public void shouldSubscribesOnWsAgentOutputWhenWorkspaceIsStarting() throws Exception {
WorkspaceRuntimeDto runtime = mock(WorkspaceRuntimeDto.class);
WorkspaceConfigDto workspaceConfig = mock(WorkspaceConfigDto.class);
when(workspaceStatusEvent.getEventType()).thenReturn(STARTING);
when(workspaceStatusEvent.getStatus()).thenReturn(STARTING);
when(workspace.getRuntime()).thenReturn(runtime);
when(runtime.getActiveEnv()).thenReturn(ACTIVE_ENV);
when(workspace.getConfig()).thenReturn(workspaceConfig);
Expand Down Expand Up @@ -243,7 +239,7 @@ public void shouldSubscribeOnWsAgentOutputWhenWorkspaceIsRunningAfterRefreshPage

// @Test disabled because of GWT timer usage
public void onWorkspaceStartingTest() throws Exception {
when(workspaceStatusEvent.getEventType()).thenReturn(STARTING);
when(workspaceStatusEvent.getStatus()).thenReturn(STARTING);

workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
Expand All @@ -262,8 +258,8 @@ public void onWorkspaceStartingTest() throws Exception {

@Test
public void onWorkspaceStartedTest() throws Exception {
when(workspaceStatusEvent.getEventType()).thenReturn(RUNNING);
when(workspaceStatusEvent.getPrevStatus()).thenReturn(WorkspaceStatus.STARTING);
when(workspaceStatusEvent.getStatus()).thenReturn(RUNNING);
when(workspaceStatusEvent.getPrevStatus()).thenReturn(STARTING);

workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
Expand All @@ -288,7 +284,8 @@ public void onErrorEventReceivedTest() throws Exception {
workspaces.add(workspace);
MessageDialog errorDialog = mock(MessageDialog.class);
when(dialogFactory.createMessageDialog(anyString(), anyString(), (ConfirmCallback)anyObject())).thenReturn(errorDialog);
when(workspaceStatusEvent.getEventType()).thenReturn(ERROR);
when(workspaceStatusEvent.getStatus()).thenReturn(STOPPED);
when(workspaceStatusEvent.getError()).thenReturn("error");

workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
Expand All @@ -307,7 +304,7 @@ public void onErrorEventReceivedTest() throws Exception {

@Test
public void onWorkspaceStoppedTest() throws Exception {
when(workspaceStatusEvent.getEventType()).thenReturn(STOPPED);
when(workspaceStatusEvent.getStatus()).thenReturn(STOPPED);

workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
Expand All @@ -318,7 +315,7 @@ public void onWorkspaceStoppedTest() throws Exception {

@Test
public void onSnapshotCreatingEventReceivedTest() throws Exception {
when(workspaceStatusEvent.getEventType()).thenReturn(SNAPSHOT_CREATING);
when(workspaceStatusEvent.getStatus()).thenReturn(SNAPSHOTTING);

workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
Expand All @@ -328,7 +325,8 @@ public void onSnapshotCreatingEventReceivedTest() throws Exception {

@Test
public void onSnapshotCreatedEventReceivedTest() throws Exception {
when(workspaceStatusEvent.getEventType()).thenReturn(SNAPSHOT_CREATED);
when(workspaceStatusEvent.getStatus()).thenReturn(RUNNING);
when(workspaceStatusEvent.getPrevStatus()).thenReturn(SNAPSHOTTING);

workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
Expand All @@ -339,7 +337,9 @@ public void onSnapshotCreatedEventReceivedTest() throws Exception {

@Test
public void onSnapshotCreationErrorEventReceivedTest() throws Exception {
when(workspaceStatusEvent.getEventType()).thenReturn(SNAPSHOT_CREATION_ERROR);
when(workspaceStatusEvent.getStatus()).thenReturn(RUNNING);
when(workspaceStatusEvent.getPrevStatus()).thenReturn(SNAPSHOTTING);
when(workspaceStatusEvent.getError()).thenReturn("error");

workspaceEventsHandler.trackWorkspaceEvents(workspace, callback);
workspaceEventsHandler.workspaceStatusSubscriptionHandler.onMessageReceived(workspaceStatusEvent);
Expand Down

0 comments on commit 7741032

Please sign in to comment.