Search in sources :

Example 1 with DebugSessionDto

use of org.eclipse.che.api.debug.shared.dto.DebugSessionDto in project che by eclipse.

the class DebuggerService method getDebugSession.

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public DebugSessionDto getDebugSession(@PathParam("id") String sessionId) throws DebuggerException {
    DebuggerInfo debuggerInfo = debuggerManager.getDebugger(sessionId).getInfo();
    DebugSessionDto debugSessionDto = newDto(DebugSessionDto.class);
    debugSessionDto.setDebuggerInfo(asDto(debuggerInfo));
    debugSessionDto.setId(sessionId);
    debugSessionDto.setType(debuggerManager.getDebuggerType(sessionId));
    return debugSessionDto;
}
Also used : DebuggerInfo(org.eclipse.che.api.debug.shared.model.DebuggerInfo) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) Path(javax.ws.rs.Path) VariablePath(org.eclipse.che.api.debug.shared.model.VariablePath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with DebugSessionDto

use of org.eclipse.che.api.debug.shared.dto.DebugSessionDto in project che by eclipse.

the class AbstractDebugger method addHandlers.

private void addHandlers(final MessageBusProvider messageBusProvider) {
    eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {

        @Override
        public void onWsAgentStarted(WsAgentStateEvent event) {
            messageBus = messageBusProvider.getMachineMessageBus();
            if (!isConnected()) {
                return;
            }
            Promise<DebugSessionDto> promise = service.getSessionInfo(debugSessionDto.getId());
            promise.then(new Operation<DebugSessionDto>() {

                @Override
                public void apply(DebugSessionDto arg) throws OperationException {
                    debuggerManager.setActiveDebugger(AbstractDebugger.this);
                    setDebugSession(arg);
                    DebuggerInfo debuggerInfo = arg.getDebuggerInfo();
                    String info = debuggerInfo.getName() + " " + debuggerInfo.getVersion();
                    String address = debuggerInfo.getHost() + ":" + debuggerInfo.getPort();
                    DebuggerDescriptor debuggerDescriptor = new DebuggerDescriptor(info, address);
                    JsPromise<Void> promise = Promises.resolve(null);
                    for (DebuggerObserver observer : observers) {
                        observer.onDebuggerAttached(debuggerDescriptor, promise);
                    }
                    startCheckingEvents();
                }
            }).catchError(new Operation<PromiseError>() {

                @Override
                public void apply(PromiseError arg) throws OperationException {
                    if (!isConnected()) {
                        invalidateDebugSession();
                    }
                }
            });
        }

        @Override
        public void onWsAgentStopped(WsAgentStateEvent event) {
        }
    });
    this.debuggerEventsHandler = new SubscriptionHandler<DebuggerEventDto>(new DebuggerEventUnmarshaller(dtoFactory)) {

        @Override
        public void onMessageReceived(DebuggerEventDto result) {
            if (!isConnected()) {
                return;
            }
            onEventListReceived(result);
        }

        @Override
        public void onErrorReceived(Throwable exception) {
            if (!isConnected()) {
                return;
            }
            try {
                messageBus.unsubscribe(eventChannel, this);
            } catch (WebSocketException e) {
                Log.error(AbstractDebugger.class, e);
            }
            if (exception instanceof ServerException) {
                ServerException serverException = (ServerException) exception;
                if (HTTPStatus.INTERNAL_ERROR == serverException.getHTTPStatus() && serverException.getMessage() != null && serverException.getMessage().contains("not found")) {
                    disconnect();
                }
            }
        }
    };
}
Also used : DebuggerInfo(org.eclipse.che.api.debug.shared.model.DebuggerInfo) ServerException(org.eclipse.che.ide.websocket.rest.exceptions.ServerException) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) WsAgentStateHandler(org.eclipse.che.ide.api.machine.events.WsAgentStateHandler) DebuggerDescriptor(org.eclipse.che.ide.debug.DebuggerDescriptor) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Operation(org.eclipse.che.api.promises.client.Operation) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Promise(org.eclipse.che.api.promises.client.Promise) DebuggerEventDto(org.eclipse.che.api.debug.shared.dto.event.DebuggerEventDto) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) DebuggerObserver(org.eclipse.che.ide.debug.DebuggerObserver) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with DebugSessionDto

use of org.eclipse.che.api.debug.shared.dto.DebugSessionDto in project che by eclipse.

the class AbstractDebugger method restoreDebuggerState.

/**
     * Loads debugger information from the local storage.
     */
protected void restoreDebuggerState() {
    invalidateDebugSession();
    LocalStorage localStorage = localStorageProvider.get();
    if (localStorage == null) {
        return;
    }
    String data = localStorage.getItem(LOCAL_STORAGE_DEBUGGER_SESSION_KEY);
    if (data != null && !data.isEmpty()) {
        DebugSessionDto debugSessionDto = dtoFactory.createDtoFromJson(data, DebugSessionDto.class);
        if (!debugSessionDto.getType().equals(getDebuggerType())) {
            return;
        }
        setDebugSession(debugSessionDto);
    }
    data = localStorage.getItem(LOCAL_STORAGE_DEBUGGER_STATE_KEY);
    if (data != null && !data.isEmpty()) {
        currentLocation = dtoFactory.createDtoFromJson(data, LocationDto.class);
    }
}
Also used : LocalStorage(org.eclipse.che.ide.util.storage.LocalStorage) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) LocationDto(org.eclipse.che.api.debug.shared.dto.LocationDto)

Example 4 with DebugSessionDto

use of org.eclipse.che.api.debug.shared.dto.DebugSessionDto in project che by eclipse.

the class DebuggerTest method testAttachDebugger.

@Test
public void testAttachDebugger() throws Exception {
    debugger.setDebugSession(null);
    final String debugSessionJson = "debugSession";
    doReturn(debugSessionJson).when(dtoFactory).toJson(debugSessionDto);
    doReturn(mock(StartActionDto.class)).when(dtoFactory).createDto(StartActionDto.class);
    Map<String, String> connectionProperties = mock(Map.class);
    Promise<DebugSessionDto> promiseDebuggerInfo = mock(Promise.class);
    doReturn(promiseDebuggerInfo).when(service).connect("id", connectionProperties);
    doReturn(promiseVoid).when(promiseDebuggerInfo).then((Function<DebugSessionDto, Void>) any());
    doReturn(promiseVoid).when(promiseVoid).catchError((Operation<PromiseError>) any());
    Promise<Void> result = debugger.connect(connectionProperties);
    assertEquals(promiseVoid, result);
    verify(promiseDebuggerInfo).then(argumentCaptorFunctionJavaDebugSessionVoid.capture());
    argumentCaptorFunctionJavaDebugSessionVoid.getValue().apply(debugSessionDto);
    verify(promiseVoid).catchError(operationPromiseErrorCaptor.capture());
    try {
        operationPromiseErrorCaptor.getValue().apply(promiseError);
        fail("Operation Exception expected");
    } catch (OperationException e) {
        verify(promiseError).getMessage();
        verify(promiseError).getCause();
    }
    verify(observer).onDebuggerAttached(debuggerDescriptor, promiseVoid);
    assertTrue(debugger.isConnected());
    verify(localStorage).setItem(eq(AbstractDebugger.LOCAL_STORAGE_DEBUGGER_SESSION_KEY), eq(debugSessionJson));
    verify(messageBus).subscribe(eq("id:events:"), any(SubscriptionHandler.class));
}
Also used : SubscriptionHandler(org.eclipse.che.ide.websocket.rest.SubscriptionHandler) PromiseError(org.eclipse.che.api.promises.client.PromiseError) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) Matchers.anyString(org.mockito.Matchers.anyString) StartActionDto(org.eclipse.che.api.debug.shared.dto.action.StartActionDto) OperationException(org.eclipse.che.api.promises.client.OperationException) BaseTest(org.eclipse.che.plugin.debugger.ide.BaseTest) Test(org.junit.Test)

Example 5 with DebugSessionDto

use of org.eclipse.che.api.debug.shared.dto.DebugSessionDto in project che by eclipse.

the class AbstractDebugger method connect.

@Override
public Promise<Void> connect(Map<String, String> connectionProperties) {
    if (isConnected()) {
        return Promises.reject(JsPromiseError.create("Debugger already connected"));
    }
    Promise<DebugSessionDto> connect = service.connect(debuggerType, connectionProperties);
    final DebuggerDescriptor debuggerDescriptor = toDescriptor(connectionProperties);
    Promise<Void> promise = connect.then(new Function<DebugSessionDto, Void>() {

        @Override
        public Void apply(final DebugSessionDto arg) throws FunctionException {
            DebuggerInfo debuggerInfo = arg.getDebuggerInfo();
            debuggerDescriptor.setInfo(debuggerInfo.getName() + " " + debuggerInfo.getVersion());
            setDebugSession(arg);
            preserveDebuggerState();
            startCheckingEvents();
            startDebugger(arg);
            return null;
        }
    }).catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            Log.error(AbstractDebugger.class, arg.getMessage());
            throw new OperationException(arg.getCause());
        }
    });
    for (DebuggerObserver observer : observers) {
        observer.onDebuggerAttached(debuggerDescriptor, promise);
    }
    return promise;
}
Also used : DebuggerInfo(org.eclipse.che.api.debug.shared.model.DebuggerInfo) DebuggerDescriptor(org.eclipse.che.ide.debug.DebuggerDescriptor) Function(org.eclipse.che.api.promises.client.Function) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) DebuggerObserver(org.eclipse.che.ide.debug.DebuggerObserver) OperationException(org.eclipse.che.api.promises.client.OperationException)

Aggregations

DebugSessionDto (org.eclipse.che.api.debug.shared.dto.DebugSessionDto)6 DebuggerInfo (org.eclipse.che.api.debug.shared.model.DebuggerInfo)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 DebuggerDescriptor (org.eclipse.che.ide.debug.DebuggerDescriptor)3 Operation (org.eclipse.che.api.promises.client.Operation)2 JsPromiseError (org.eclipse.che.api.promises.client.js.JsPromiseError)2 DebuggerObserver (org.eclipse.che.ide.debug.DebuggerObserver)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 LocationDto (org.eclipse.che.api.debug.shared.dto.LocationDto)1 StartActionDto (org.eclipse.che.api.debug.shared.dto.action.StartActionDto)1 DebuggerEventDto (org.eclipse.che.api.debug.shared.dto.event.DebuggerEventDto)1 VariablePath (org.eclipse.che.api.debug.shared.model.VariablePath)1 Function (org.eclipse.che.api.promises.client.Function)1 Promise (org.eclipse.che.api.promises.client.Promise)1 JsPromise (org.eclipse.che.api.promises.client.js.JsPromise)1 FileType (org.eclipse.che.ide.api.filetypes.FileType)1 WsAgentStateEvent (org.eclipse.che.ide.api.machine.events.WsAgentStateEvent)1