CODENVY-282 check permissions before trying to start any workspace (#1067)
parent
a76aba767a
commit
dcd85bf5d4
|
|
@ -15,7 +15,6 @@
|
|||
package org.eclipse.che.ide.util;
|
||||
|
||||
import org.eclipse.che.ide.commons.exception.ServerException;
|
||||
import org.eclipse.che.ide.dto.DtoFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
|
@ -23,8 +22,6 @@ import java.util.Map;
|
|||
/** Utility class for common Exception related operations. */
|
||||
public class ExceptionUtils {
|
||||
|
||||
private static DtoFactory dtoFactory = new DtoFactory();
|
||||
|
||||
public static final int MAX_CAUSE = 10;
|
||||
|
||||
public static String getStackTraceAsString(Throwable e) {
|
||||
|
|
@ -37,7 +34,7 @@ public class ExceptionUtils {
|
|||
}
|
||||
// For each cause, print the requested number of entries of its stack
|
||||
// trace, being careful to avoid getting stuck in an infinite loop.
|
||||
StringBuffer s = new StringBuffer(newline);
|
||||
StringBuilder s = new StringBuilder(newline);
|
||||
Throwable currentCause = e;
|
||||
String causedBy = "";
|
||||
|
||||
|
|
@ -50,11 +47,11 @@ public class ExceptionUtils {
|
|||
s.append(currentCause.getMessage());
|
||||
StackTraceElement[] stackElems = currentCause.getStackTrace();
|
||||
if (stackElems != null) {
|
||||
for (int i = 0; i < stackElems.length; ++i) {
|
||||
for (StackTraceElement stackElem : stackElems) {
|
||||
s.append(newline);
|
||||
s.append(indent);
|
||||
s.append("at ");
|
||||
s.append(stackElems[i].toString());
|
||||
s.append(stackElem.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +67,7 @@ public class ExceptionUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns error code of the exception if it is of type {@clink ServerException} and has error code set, or -1 otherwise.
|
||||
* Returns error code of the exception if it is of type {@link ServerException} and has error code set, or -1 otherwise.
|
||||
*
|
||||
* @param exception
|
||||
* passed exception
|
||||
|
|
@ -87,7 +84,7 @@ public class ExceptionUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns attributes of the exception if it is of type {@clink ServerException} and has attributes set, or empty map otherwise.
|
||||
* Returns attributes of the exception if it is of type {@link ServerException} and has attributes set, or empty map otherwise.
|
||||
*
|
||||
* @param exception
|
||||
* passed exception
|
||||
|
|
@ -102,4 +99,21 @@ public class ExceptionUtils {
|
|||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTTP status the exception if it is of type {@link ServerException} or -1 otherwise.
|
||||
*
|
||||
* @param exception
|
||||
* passed exception
|
||||
* @return status code
|
||||
*/
|
||||
public static int getStatusCode(Throwable exception) {
|
||||
if (exception instanceof ServerException) {
|
||||
return ((ServerException)exception).getHTTPStatus();
|
||||
} else if (exception instanceof org.eclipse.che.ide.websocket.rest.exceptions.ServerException) {
|
||||
return ((org.eclipse.che.ide.websocket.rest.exceptions.ServerException)exception).getHTTPStatus();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import org.eclipse.che.api.workspace.shared.dto.event.WorkspaceStatusEvent;
|
|||
import org.eclipse.che.ide.CoreLocalizationConstant;
|
||||
import org.eclipse.che.ide.actions.WorkspaceSnapshotCreator;
|
||||
import org.eclipse.che.ide.api.app.AppContext;
|
||||
import org.eclipse.che.ide.api.event.HttpSessionDestroyedEvent;
|
||||
import org.eclipse.che.ide.api.notification.NotificationManager;
|
||||
import org.eclipse.che.ide.api.notification.StatusNotification;
|
||||
import org.eclipse.che.ide.api.preferences.PreferencesManager;
|
||||
|
|
@ -41,11 +42,13 @@ import org.eclipse.che.ide.context.BrowserQueryFieldRenderer;
|
|||
import org.eclipse.che.ide.api.component.Component;
|
||||
import org.eclipse.che.ide.dto.DtoFactory;
|
||||
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
|
||||
import org.eclipse.che.ide.rest.HTTPStatus;
|
||||
import org.eclipse.che.ide.ui.dialogs.CancelCallback;
|
||||
import org.eclipse.che.ide.ui.dialogs.ConfirmCallback;
|
||||
import org.eclipse.che.ide.ui.dialogs.DialogFactory;
|
||||
import org.eclipse.che.ide.ui.loaders.initialization.InitialLoadingInfo;
|
||||
import org.eclipse.che.ide.ui.loaders.initialization.LoaderPresenter;
|
||||
import org.eclipse.che.ide.util.ExceptionUtils;
|
||||
import org.eclipse.che.ide.util.loging.Log;
|
||||
import org.eclipse.che.ide.websocket.MessageBus;
|
||||
import org.eclipse.che.ide.websocket.MessageBusProvider;
|
||||
|
|
@ -182,36 +185,49 @@ public abstract class WorkspaceComponent implements Component, WsAgentStateHandl
|
|||
*/
|
||||
public void startWorkspaceById(final WorkspaceDto workspace, final Callback<Component, Exception> callback) {
|
||||
this.callback = callback;
|
||||
loader.show(initialLoadingInfo);
|
||||
initialLoadingInfo.setOperationStatus(WORKSPACE_BOOTING.getValue(), IN_PROGRESS);
|
||||
|
||||
if (messageBus != null) {
|
||||
messageBus.cancelReconnection();
|
||||
}
|
||||
messageBus = messageBusProvider.createMessageBus(workspace.getId());
|
||||
|
||||
messageBus.addOnOpenHandler(new ConnectionOpenedHandler() {
|
||||
workspaceServiceClient.getWorkspace(workspace.getId()).then(new Operation<WorkspaceDto>() {
|
||||
@Override
|
||||
public void onOpen() {
|
||||
messageBus.removeOnOpenHandler(this);
|
||||
subscribeToWorkspaceStatusWebSocket(workspace);
|
||||
public void apply(WorkspaceDto arg) throws OperationException {
|
||||
loader.show(initialLoadingInfo);
|
||||
initialLoadingInfo.setOperationStatus(WORKSPACE_BOOTING.getValue(), IN_PROGRESS);
|
||||
|
||||
if (!RUNNING.equals(workspace.getStatus())) {
|
||||
workspaceServiceClient.getSnapshot(workspace.getId()).then(new Operation<List<SnapshotDto>>() {
|
||||
@Override
|
||||
public void apply(List<SnapshotDto> snapshots) throws OperationException {
|
||||
if (snapshots.isEmpty()) {
|
||||
handleWsStart(workspaceServiceClient.startById(workspace.getId(),
|
||||
workspace.getConfig().getDefaultEnv()));
|
||||
} else {
|
||||
showRecoverWorkspaceConfirmDialog(workspace);
|
||||
}
|
||||
if (messageBus != null) {
|
||||
messageBus.cancelReconnection();
|
||||
}
|
||||
messageBus = messageBusProvider.createMessageBus(workspace.getId());
|
||||
|
||||
messageBus.addOnOpenHandler(new ConnectionOpenedHandler() {
|
||||
@Override
|
||||
public void onOpen() {
|
||||
messageBus.removeOnOpenHandler(this);
|
||||
subscribeToWorkspaceStatusWebSocket(workspace);
|
||||
|
||||
if (!RUNNING.equals(workspace.getStatus())) {
|
||||
workspaceServiceClient.getSnapshot(workspace.getId()).then(new Operation<List<SnapshotDto>>() {
|
||||
@Override
|
||||
public void apply(List<SnapshotDto> snapshots) throws OperationException {
|
||||
if (snapshots.isEmpty()) {
|
||||
handleWsStart(workspaceServiceClient.startById(workspace.getId(),
|
||||
workspace.getConfig().getDefaultEnv()));
|
||||
} else {
|
||||
showRecoverWorkspaceConfirmDialog(workspace);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
initialLoadingInfo.setOperationStatus(WORKSPACE_BOOTING.getValue(), SUCCESS);
|
||||
setCurrentWorkspace(workspace);
|
||||
eventBus.fireEvent(new WorkspaceStartedEvent(workspace));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
initialLoadingInfo.setOperationStatus(WORKSPACE_BOOTING.getValue(), SUCCESS);
|
||||
setCurrentWorkspace(workspace);
|
||||
eventBus.fireEvent(new WorkspaceStartedEvent(workspace));
|
||||
}
|
||||
});
|
||||
}
|
||||
}).catchError(new Operation<PromiseError>() {
|
||||
@Override
|
||||
public void apply(PromiseError err) throws OperationException {
|
||||
Log.error(getClass(), err.getCause());
|
||||
if (ExceptionUtils.getStatusCode(err.getCause()) == HTTPStatus.FORBIDDEN) {
|
||||
eventBus.fireEvent(new HttpSessionDestroyedEvent());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue