Search in sources :

Example 1 with Breakpoints

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugGlobalPoller method pollForChanges.

/**
 * pollForChanges sends a synchronous, hanging query to the server and compares the result to see
 * if there are changes from the current state. Explanation of <a
 * href="https://en.wikipedia.org/wiki/Push_technology#Long_polling">hanging query (a.k.a. long
 * poll)</a>
 *
 * @param state represents the target debuggee to query
 */
void pollForChanges(@NotNull final CloudDebugProcessState state) {
    final Debugger client = CloudDebuggerClient.getShortTimeoutClient(state);
    if (client == null) {
        if (state.isListenInBackground()) {
            // state is supposed to listen, but does not have access to the backend
            LOG.warn("CloudDebugProcessState is listening in the background but no debugger client " + "could be retrieved => stop listening");
            handleBreakpointQueryError(state, GctBundle.message("clouddebug.background.listener.access.error.message", state.getProject().getName()));
            return;
        } else {
            // We should poll only states that listen in the background, reaching this branch is
            // unexpected
            LOG.error("Polling changes for a debug state that is not set to listen in the background");
            return;
        }
    }
    boolean changed = false;
    try {
        String oldToken = state.getWaitToken();
        queryServerForBreakpoints(state, client);
        String responseWaitToken = state.getWaitToken();
        if (!Strings.isNullOrEmpty(responseWaitToken)) {
            changed = oldToken == null || !responseWaitToken.equals(oldToken);
        } else {
            changed = !Strings.isNullOrEmpty(oldToken);
        }
    } catch (SocketTimeoutException ex) {
    // noop, this is expected behavior.
    } catch (GoogleJsonResponseException ex) {
        // a result is available (which will be retrieved via the subsequent query)
        if (ex.getStatusCode() != HttpURLConnection.HTTP_CONFLICT) {
            handleBreakpointQueryError(state, ex);
        }
    } catch (IOException ex) {
        LOG.warn("exception listing breakpoints", ex);
        handleBreakpointQueryError(state, ex);
        return;
    } catch (Exception ex) {
        LOG.error("exception listing breakpoints", ex);
        handleBreakpointQueryError(state, ex);
        return;
    }
    if (changed) {
        fireBreakpointsChanged(state);
    }
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 2 with Breakpoints

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugProcessStateController method waitForChanges.

/**
 * Package protected for test purposes only.
 */
void waitForChanges() {
    if (state == null) {
        LOG.error("no state available attempting to checkForChanges");
        return;
    }
    final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
    if (client == null) {
        LOG.info("no client available attempting to checkForChanges");
        return;
    }
    String tokenToSend = state.getWaitToken();
    List<Breakpoint> currentList;
    try {
        currentList = queryServerForBreakpoints(state, client, tokenToSend);
    } catch (SocketTimeoutException ex) {
        // Timeout is expected on a hanging get.
        return;
    } catch (GoogleJsonResponseException ex) {
        // we need to requery.
        if (ex.getDetails().getCode() == 409) {
            try {
                currentList = queryServerForBreakpoints(state, client, tokenToSend);
            } catch (IOException ioException) {
                LOG.warn("exception listing breakpoints", ioException);
                return;
            }
        } else {
            LOG.warn("exception listing breakpoints", ex);
            return;
        }
    } catch (IOException ex) {
        LOG.warn("exception listing breakpoints", ex);
        return;
    }
    if (!isBackgroundListening()) {
        return;
    }
    // to do pruning.
    if (!Strings.isNullOrEmpty(tokenToSend)) {
        pruneBreakpointCache(currentList);
        fireBreakpointsChanged();
    }
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 3 with Breakpoints

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandler method cloneToNewBreakpoints.

/**
 * Called when the user "reactivates" an existing snapshot to create a new breakpoint, this clones
 * state into a new breakpoint. It is different from "createIdeRepresentationsIfNecessary" in the
 * following respects:
 *
 * <p>
 *
 * <ul>
 *   <li>It only operates on final state breakpoints.
 *   <li>It always clones them into a new IDE breakpoint.
 *   <li>It does not set "created by server = true", so when control flow comes back into
 *       register, it will register with the server.
 * </ul>
 */
public void cloneToNewBreakpoints(@NotNull final List<Breakpoint> serverBreakpoints) {
    for (Breakpoint serverBreakpoint : serverBreakpoints) {
        if (!Boolean.TRUE.equals(serverBreakpoint.getIsFinalState())) {
            continue;
        }
        Project currentProject = process.getXDebugSession().getProject();
        final XBreakpointManager manager = XDebuggerManager.getInstance(process.getXDebugSession().getProject()).getBreakpointManager();
        if (serverBreakpoint.getLocation() == null) {
            LOG.warn("attempted to clone a breakpoint without a source location: " + StringUtil.notNullize(serverBreakpoint.getId()));
            continue;
        }
        String path = serverBreakpoint.getLocation().getPath();
        if (Strings.isNullOrEmpty(path)) {
            continue;
        }
        final VirtualFile file = fileResolver.getFileFromPath(currentProject, path);
        final int line = serverBreakpoint.getLocation().getLine() - 1;
        if (file == null) {
            LOG.warn("attempted to clone a breakpoint whose file doesn't exist locally: " + StringUtil.notNullize(serverBreakpoint.getLocation().getPath()));
            continue;
        }
        final XLineBreakpoint existing = manager.findBreakpointAtLine(CloudLineBreakpointType.getInstance(), file, line);
        if (existing != null) {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    manager.removeBreakpoint(existing);
                }
            });
        }
        final CloudLineBreakpointProperties properties = new CloudLineBreakpointProperties();
        final Breakpoint finalserverBreakpoint = serverBreakpoint;
        ApplicationManager.getApplication().runWriteAction(new Runnable() {

            @Override
            public void run() {
                if (finalserverBreakpoint.getExpressions() != null && finalserverBreakpoint.getExpressions().size() > 0) {
                    properties.setWatchExpressions(finalserverBreakpoint.getExpressions().toArray(new String[finalserverBreakpoint.getExpressions().size()]));
                }
                XLineBreakpoint<CloudLineBreakpointProperties> newxIdeBreakpoint = manager.addLineBreakpoint(CloudLineBreakpointType.getInstance(), file.getUrl(), line, properties);
                // Condition, watches.
                if (!Strings.isNullOrEmpty(finalserverBreakpoint.getCondition())) {
                    newxIdeBreakpoint.setCondition(finalserverBreakpoint.getCondition());
                }
            }
        });
    }
    UsageTrackerProvider.getInstance().trackEvent(GctTracking.CLOUD_DEBUGGER_CLONE_BREAKPOINTS).ping();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Project(com.intellij.openapi.project.Project) XBreakpointManager(com.intellij.xdebugger.breakpoints.XBreakpointManager) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Example 4 with Breakpoints

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudDebugGlobalPollerTest method setupCloudDebuggerBackendMockWithException.

private void setupCloudDebuggerBackendMockWithException(String userEmail, IOException e) throws IOException {
    Breakpoints breakpoints = mock(Breakpoints.class);
    when(breakpoints.list(anyString())).thenThrow(e);
    Debuggees debuggees = mock(Debuggees.class);
    when(debuggees.breakpoints()).thenReturn(breakpoints);
    Debugger debugger = mock(Debugger.class);
    when(debugger.debuggees()).thenReturn(debuggees);
    CloudDebuggerClient.setClient(userEmail + CloudDebuggerClient.SHORT_CONNECTION_TIMEOUT_MS, debugger);
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoints(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints) Debuggees(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees)

Example 5 with Breakpoints

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints in project google-cloud-intellij by GoogleCloudPlatform.

the class CloudBreakpointHandlerTest method testCreateIdeRepresentationsIfNecessary.

public void testCreateIdeRepresentationsIfNecessary() {
    List<Breakpoint> breakpoints = ImmutableList.of(new Breakpoint().setId("expected_path").setLocation(new SourceLocation().setLine(1).setPath("app/mod/src/main/java/b/f/pkg/Class.java")), new Breakpoint().setId("unexpected_path").setLocation(new SourceLocation().setLine(2).setPath("app/mod/src/m/j/a/b/c/Class.java")), new Breakpoint().setId("unexpected_path_2").setLocation(new SourceLocation().setLine(3).setPath("b/f/pkg/Class.java")));
    when(breakpointManager.findBreakpointAtLine(isA(XLineBreakpointType.class), isA(VirtualFile.class), anyInt())).thenReturn(null);
    XLineBreakpoint mockLineBreakpoint = mock(XLineBreakpoint.class);
    when(breakpointManager.addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(CloudLineBreakpointProperties.class))).thenReturn(mockLineBreakpoint);
    when(mockLineBreakpoint.getProperties()).thenReturn(new CloudLineBreakpointProperties());
    VirtualFile projectDir = mock(VirtualFile.class);
    when(projectDir.getPath()).thenReturn("/project/dir");
    project.setBaseDir(projectDir);
    VirtualFile classFile = mock(VirtualFile.class);
    when(classFile.getUrl()).thenReturn("file:///URL");
    when(fileResolver.getFileFromPath(isA(Project.class), eq("app/mod/src/main/java/b/f/pkg/Class.java"))).thenReturn(classFile);
    handler.createIdeRepresentationsIfNecessary(breakpoints);
    verify(breakpointManager, times(1)).addLineBreakpoint(isA(XLineBreakpointType.class), anyString(), anyInt(), isA(XBreakpointProperties.class));
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XBreakpointProperties(com.intellij.xdebugger.breakpoints.XBreakpointProperties) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Project(com.intellij.openapi.project.Project) XLineBreakpointType(com.intellij.xdebugger.breakpoints.XLineBreakpointType) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint)

Aggregations

Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)13 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)9 IOException (java.io.IOException)5 CloudLineBreakpoint (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint)4 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)4 ArrayList (java.util.ArrayList)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)3 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)3 Project (com.intellij.openapi.project.Project)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 XBreakpoint (com.intellij.xdebugger.breakpoints.XBreakpoint)3 XBreakpointManager (com.intellij.xdebugger.breakpoints.XBreakpointManager)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 Debuggees (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees)2 Breakpoints (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Test (org.junit.Test)2 GetBreakpointResponse (com.google.api.services.clouddebugger.v2.model.GetBreakpointResponse)1 SetBreakpointResponse (com.google.api.services.clouddebugger.v2.model.SetBreakpointResponse)1