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);
}
}
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);
}
}
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);
}
});
}
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>()));
}
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());
}
});
}
Aggregations