Search in sources :

Example 6 with Debugger

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger in project beam by apache.

the class DataflowRunner method registerDebuggee.

private Debuggee registerDebuggee(CloudDebugger debuggerClient, String uniquifier) {
    RegisterDebuggeeRequest registerReq = new RegisterDebuggeeRequest();
    registerReq.setDebuggee(new Debuggee().setProject(options.getProject()).setUniquifier(uniquifier).setDescription(uniquifier).setAgentVersion("google.com/cloud-dataflow-java/v1"));
    try {
        RegisterDebuggeeResponse registerResponse = debuggerClient.controller().debuggees().register(registerReq).execute();
        Debuggee debuggee = registerResponse.getDebuggee();
        if (debuggee.getStatus() != null && debuggee.getStatus().getIsError()) {
            throw new RuntimeException("Unable to register with the debugger: " + debuggee.getStatus().getDescription().getFormat());
        }
        return debuggee;
    } catch (IOException e) {
        throw new RuntimeException("Unable to register with the debugger: ", e);
    }
}
Also used : RegisterDebuggeeResponse(com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeResponse) Debuggee(com.google.api.services.clouddebugger.v2.model.Debuggee) RegisterDebuggeeRequest(com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeRequest) IOException(java.io.IOException)

Example 7 with Debugger

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger in project beam by apache.

the class DataflowRunner method registerDebuggee.

private Debuggee registerDebuggee(Clouddebugger debuggerClient, String uniquifier) {
    RegisterDebuggeeRequest registerReq = new RegisterDebuggeeRequest();
    registerReq.setDebuggee(new Debuggee().setProject(options.getProject()).setUniquifier(uniquifier).setDescription(uniquifier).setAgentVersion("google.com/cloud-dataflow-java/v1"));
    try {
        RegisterDebuggeeResponse registerResponse = debuggerClient.controller().debuggees().register(registerReq).execute();
        Debuggee debuggee = registerResponse.getDebuggee();
        if (debuggee.getStatus() != null && debuggee.getStatus().getIsError()) {
            throw new RuntimeException("Unable to register with the debugger: " + debuggee.getStatus().getDescription().getFormat());
        }
        return debuggee;
    } catch (IOException e) {
        throw new RuntimeException("Unable to register with the debugger: ", e);
    }
}
Also used : RegisterDebuggeeResponse(com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeResponse) Debuggee(com.google.api.services.clouddebugger.v2.model.Debuggee) RegisterDebuggeeRequest(com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeRequest) IOException(java.io.IOException)

Example 8 with Debugger

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

the class CloudBreakpointHandler method registerBreakpoint.

/**
 * Called by IntelliJ when the user has enabled or created a new breakpoint. Creates the server
 * breakpoint.
 *
 * @param ideBreakpoint breakpoint to register
 */
@Override
public void registerBreakpoint(@NotNull final XLineBreakpoint<CloudLineBreakpointProperties> ideBreakpoint) {
    if (ideBreakpoint.getSourcePosition() == null || !ideBreakpoint.isEnabled() || !(ideBreakpoint.getType() instanceof CloudLineBreakpointType)) {
        return;
    }
    com.intellij.debugger.ui.breakpoints.Breakpoint cloudIdeBreakpoint = BreakpointManager.getJavaBreakpoint(ideBreakpoint);
    if (!(cloudIdeBreakpoint instanceof CloudLineBreakpointType.CloudLineBreakpoint)) {
        LOG.error("breakpoint was not of the correct type to create on the cloud.  It was not a " + "CloudLineBreakpoint");
        return;
    }
    final CloudLineBreakpointType.CloudLineBreakpoint cloudIdeLineBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) cloudIdeBreakpoint;
    if (ideBreakpoint.getProperties().isCreatedByServer()) {
        // gets called during construction.
        return;
    }
    if (ideBreakpoint.getProperties().isAddedOnServer() && !ideBreakpoint.getProperties().isDisabledByServer()) {
        // disabled breakpoint
        return;
    }
    PsiFile javaFile = psiManager.findFile(ideBreakpoint.getSourcePosition().getFile());
    if (!(javaFile instanceof PsiJavaFile)) {
        return;
    }
    SourceLocation location = new SourceLocation();
    // Sending the file as com/package/example/Class.java to Cloud Debugger because it plays nice
    // with the CDB plugin. See ServerToIdeFileResolver.
    location.setPath(ServerToIdeFileResolver.getCloudPathFromJavaFile((PsiJavaFile) javaFile));
    location.setLine(ideBreakpoint.getSourcePosition().getLine() + 1);
    Breakpoint serverNewBreakpoint = new Breakpoint();
    serverNewBreakpoint.setLocation(location);
    if (ideBreakpoint.getConditionExpression() != null) {
        serverNewBreakpoint.setCondition(ideBreakpoint.getConditionExpression().getExpression());
    }
    List<String> watches = cloudIdeLineBreakpoint.getWatchExpressions();
    if (watches != null) {
        serverNewBreakpoint.setExpressions(watches);
    }
    // The breakpoint will enter error state asynchronously.  For now, we state that its verified.
    process.getStateController().setBreakpointAsync(serverNewBreakpoint, new SetBreakpointHandler() {

        @Override
        public void onSuccess(@NotNull final String id) {
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    if (!Strings.isNullOrEmpty(id)) {
                        if (!cloudIdeLineBreakpoint.isEnabled()) {
                            process.getStateController().deleteBreakpointAsync(// race condition
                            id);
                        } else {
                            // Success.
                            // Mark as added so we don't add it again.
                            ideBreakpoint.getProperties().setAddedOnServer(true);
                            cloudIdeLineBreakpoint.setErrorMessage(null);
                            process.updateBreakpointPresentation(cloudIdeLineBreakpoint);
                        }
                    } else {
                        // TODO(joaomartins): Why couldn't the breakpoint be set? Improve this
                        // message.
                        cloudIdeLineBreakpoint.setErrorMessage(GctBundle.getString("clouddebug.errorset"));
                        process.updateBreakpointPresentation(cloudIdeLineBreakpoint);
                    }
                    if (!Strings.isNullOrEmpty(id)) {
                        ideBreakpoint.getProperties().setDisabledByServer(false);
                        String oldId = ideBreakpoint.getUserData(CLOUD_ID);
                        if (!Strings.isNullOrEmpty(oldId)) {
                            ideBreakpoints.remove(oldId);
                        }
                        ideBreakpoint.putUserData(CLOUD_ID, id);
                        ideBreakpoints.put(id, ideBreakpoint);
                    }
                }
            };
            if (ApplicationManager.getApplication().isUnitTestMode()) {
                runnable.run();
            } else {
                SwingUtilities.invokeLater(runnable);
            }
        }

        @Override
        public void onError(String errorMessage) {
            cloudIdeLineBreakpoint.setErrorMessage(errorMessage);
            process.updateBreakpointPresentation(cloudIdeLineBreakpoint);
        }
    });
}
Also used : SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) 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) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) CloudLineBreakpoint(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType.CloudLineBreakpoint) SetBreakpointHandler(com.google.cloud.tools.intellij.debugger.CloudDebugProcessStateController.SetBreakpointHandler) PsiJavaFile(com.intellij.psi.PsiJavaFile) PsiFile(com.intellij.psi.PsiFile)

Example 9 with Debugger

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

the class CloudDebugGlobalPoller method queryServerForBreakpoints.

private void queryServerForBreakpoints(CloudDebugProcessState state, Debugger client) throws IOException {
    if (state.getDebuggeeId() == null) {
        throw new IllegalStateException("CloudDebugProcessState.getDebuggeeId() was null");
    }
    Debuggees debuggees = client.debuggees();
    Breakpoints breakpoints = debuggees.breakpoints();
    Breakpoints.List listRequest = breakpoints.list(state.getDebuggeeId()).setIncludeInactive(Boolean.TRUE).setActionValue("CAPTURE").setStripResults(Boolean.TRUE).setWaitToken(state.getWaitToken());
    ListBreakpointsResponse response = listRequest.setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
    List<Breakpoint> currentList = response.getBreakpoints();
    String responseWaitToken = response.getNextWaitToken();
    state.setWaitToken(responseWaitToken);
    if (currentList != null) {
        Collections.sort(currentList, BreakpointComparer.getDefaultInstance());
    }
    state.setCurrentServerBreakpointList(currentList != null ? ContainerUtil.immutableList(currentList) : ContainerUtil.immutableList(new ArrayList<Breakpoint>()));
}
Also used : Breakpoints(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ListBreakpointsResponse(com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse) Debuggees(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService)

Example 10 with Debugger

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

the class CloudDebugProcessStateController method setBreakpointAsync.

/**
 * Called from the {@link CloudDebugProcessHandler} to set a breakpoint.
 */
@SuppressWarnings("FutureReturnValueIgnored")
void setBreakpointAsync(@NotNull final Breakpoint serverBreakpoint, @NotNull final SetBreakpointHandler handler) {
    if (state == null) {
        handler.onError(GctBundle.getString("clouddebug.invalid.state"));
        return;
    }
    final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
    if (client == null) {
        LOG.warn("no client available attempting to setBreakpoint");
        handler.onError(GctBundle.getString("clouddebug.bad.login.message"));
        return;
    }
    final String debuggeeId = state.getDebuggeeId();
    assert debuggeeId != null;
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        try {
            // Delete old breakpoints at this location.
            List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
            SourceLocation location = serverBreakpoint.getLocation();
            for (Breakpoint serverBp : currentList) {
                if (!Boolean.TRUE.equals(serverBp.getIsFinalState()) && serverBp.getLocation().getLine() != null && serverBp.getLocation().getLine().equals(location.getLine()) && !Strings.isNullOrEmpty(serverBp.getLocation().getPath()) && serverBp.getLocation().getPath().equals(location.getPath())) {
                    // should not be async here.
                    deleteBreakpoint(serverBp.getId());
                }
            }
            SetBreakpointResponse addResponse = client.debuggees().breakpoints().set(debuggeeId, serverBreakpoint).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
            if (addResponse != null && addResponse.getBreakpoint() != null) {
                Breakpoint result = addResponse.getBreakpoint();
                if (result.getStatus() != null && Boolean.TRUE.equals(result.getStatus().getIsError()) && result.getStatus().getDescription() != null) {
                    handler.onError(BreakpointUtil.getUserErrorMessage(result.getStatus()));
                }
                handler.onSuccess(addResponse.getBreakpoint().getId());
            } else {
                handler.onError(GctBundle.getString("clouddebug.no.response"));
            }
        } catch (IOException ex) {
            LOG.error("exception setting a breakpoint", ex);
            handler.onError(ex.toString());
        }
    });
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) SourceLocation(com.google.api.services.clouddebugger.v2.model.SourceLocation) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) SetBreakpointResponse(com.google.api.services.clouddebugger.v2.model.SetBreakpointResponse) PluginInfoService(com.google.cloud.tools.intellij.service.PluginInfoService) IOException(java.io.IOException)

Aggregations

Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)12 IOException (java.io.IOException)10 Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)9 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)5 Debuggee (com.google.api.services.clouddebugger.v2.model.Debuggee)4 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)3 ArrayList (java.util.ArrayList)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 HttpHeaders (com.google.api.client.http.HttpHeaders)2 HttpRequest (com.google.api.client.http.HttpRequest)2 Debuggees (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees)2 Breakpoints (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints)2 ListDebuggeesResponse (com.google.api.services.clouddebugger.v2.model.ListDebuggeesResponse)2 RegisterDebuggeeRequest (com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeRequest)2 RegisterDebuggeeResponse (com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeResponse)2 SourceLocation (com.google.api.services.clouddebugger.v2.model.SourceLocation)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Test (org.junit.Test)2 Credential (com.google.api.client.auth.oauth2.Credential)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1