use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method deleteBreakpoint.
/**
* Called from the {@link CloudBreakpointHandler} to remove breakpoints from the server.
*
* @param breakpointId the {@link Breakpoint} Id to delete
*/
@SuppressWarnings("FutureReturnValueIgnored")
private void deleteBreakpoint(@NotNull final String breakpointId, boolean performAsync) {
if (state == null) {
throw new IllegalStateException();
}
final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
if (client == null) {
LOG.warn("no client available attempting to setBreakpoint");
Messages.showErrorDialog(state.getProject(), GctBundle.getString("clouddebug.bad.login.message"), GctBundle.getString("clouddebug.message.title"));
return;
}
final String debuggeeId = state.getDebuggeeId();
assert debuggeeId != null;
Runnable performDelete = () -> {
try {
client.debuggees().breakpoints().delete(debuggeeId, breakpointId).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
} catch (IOException ex) {
LOG.warn("exception deleting breakpoint " + breakpointId, ex);
}
};
if (performAsync) {
ApplicationManager.getApplication().executeOnPooledThread(performDelete);
} else {
performDelete.run();
}
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method resolveBreakpointAsync.
/**
* Returns a fully realized {@link Breakpoint} with all results possibly asynchronously.
*/
@SuppressWarnings("FutureReturnValueIgnored")
public void resolveBreakpointAsync(@NotNull final String id, @NotNull final ResolveBreakpointHandler handler) {
if (fullFinalBreakpoints.containsKey(id)) {
handler.onSuccess(fullFinalBreakpoints.get(id));
return;
}
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 resolveBreakpointAsync");
handler.onError(GctBundle.getString("clouddebug.bad.login.message"));
return;
}
List<Breakpoint> currentList = state.getCurrentServerBreakpointList();
for (Breakpoint serverBreakpointCandidate : currentList) {
if (serverBreakpointCandidate.getId().equals(id) && !Boolean.TRUE.equals(serverBreakpointCandidate.getIsFinalState())) {
handler.onSuccess(serverBreakpointCandidate);
return;
}
}
ApplicationManager.getApplication().executeOnPooledThread(() -> {
// At this point, the user has selected a final state breakpoint which is not yet
// hydrated.
// So we query the server to get this final on a worker thread and then run the
// runnable
// back on ui
GetBreakpointResponse response;
try {
response = client.debuggees().breakpoints().get(state.getDebuggeeId(), id).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
Breakpoint result = response.getBreakpoint();
if (result != null) {
fullFinalBreakpoints.put(id, result);
handler.onSuccess(result);
} else {
handler.onError(GctBundle.getString("clouddebug.no.response"));
}
} catch (IOException ex) {
LOG.warn("IOException hydrating a snapshot. User may have deleted the snapshot", ex);
handler.onError(ex.toString());
}
});
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method queryServerForBreakpoints.
private List<Breakpoint> queryServerForBreakpoints(CloudDebugProcessState state, Debugger client, String tokenToSend) throws IOException {
List<Breakpoint> currentList = null;
String responseWaitToken = tokenToSend;
while (tokenToSend == null || tokenToSend.equals(responseWaitToken)) {
if (tokenToSend != null && !isBackgroundListening()) {
return null;
}
ListBreakpointsResponse response = client.debuggees().breakpoints().list(state.getDebuggeeId()).setIncludeInactive(Boolean.TRUE).setActionValue("CAPTURE").setStripResults(Boolean.TRUE).setWaitToken(CloudDebugConfigType.useWaitToken() ? tokenToSend : null).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
// up the background watcher.
if (tokenToSend != null && !isBackgroundListening()) {
return null;
}
currentList = response.getBreakpoints();
responseWaitToken = response.getNextWaitToken();
if (tokenToSend == null) {
break;
}
if (!CloudDebugConfigType.useWaitToken() && tokenToSend.equals(responseWaitToken)) {
try {
// our fallback polling mode has a 1 second loop.
Thread.currentThread().sleep(1000);
} catch (InterruptedException ex) {
return null;
}
}
}
state.setWaitToken(responseWaitToken);
if (currentList != null) {
Collections.sort(currentList, BreakpointComparer.getDefaultInstance());
}
state.setCurrentServerBreakpointList(currentList != null ? ContainerUtil.immutableList(currentList) : ContainerUtil.immutableList(new ArrayList<>()));
return currentList;
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebuggerClient method getClient.
/**
* Returns a cloud debugger connection given a user email to indicate the credentials to use. The
* function may return null if the user is not logged in.
*/
@Nullable
private static Debugger getClient(@Nullable final String userEmail, final int timeout) {
if (Strings.isNullOrEmpty(userEmail)) {
LOG.warn("unexpected null email in controller initialize.");
return null;
}
final String hashkey = userEmail + timeout;
Debugger cloudDebuggerClient = debuggerClientsFromUserEmail.get(hashkey);
if (cloudDebuggerClient == null) {
try {
final CredentialedUser user = Services.getLoginService().getAllUsers().get(userEmail);
final Credential credential = (user != null ? user.getCredential() : null);
if (credential != null) {
user.getGoogleLoginState().addLoginListener(new LoginListener() {
@Override
public void statusChanged(boolean login) {
if (!login) {
// aggressively remove the cached item on any status change.
debuggerClientsFromUserEmail.remove(hashkey);
} else {
// NOPMD
// user logged in, should we do something?
}
}
});
HttpRequestInitializer initializer = new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
HttpHeaders headers = new HttpHeaders();
httpRequest.setConnectTimeout(timeout);
httpRequest.setReadTimeout(timeout);
httpRequest.setHeaders(headers);
credential.initialize(httpRequest);
}
};
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
String userAgent = ServiceManager.getService(PluginInfoService.class).getUserAgent();
cloudDebuggerClient = new Builder(httpTransport, JSON_FACTORY, initializer).setRootUrl(ROOT_URL).setApplicationName(userAgent).build().debugger();
}
} catch (IOException ex) {
LOG.warn("Error connecting to Cloud Debugger API", ex);
} catch (GeneralSecurityException ex) {
LOG.warn("Error connecting to Cloud Debugger API", ex);
}
if (cloudDebuggerClient != null) {
debuggerClientsFromUserEmail.put(hashkey, cloudDebuggerClient);
}
}
return cloudDebuggerClient;
}
use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateTest method createMockClient.
private Debugger createMockClient(final List<Breakpoint> returnedBreakpoints) throws IOException {
Debugger client = Mockito.mock(Debugger.class);
Debugger.Debuggees debuggees = Mockito.mock(Debugger.Debuggees.class);
Debugger.Debuggees.Breakpoints breakpoints = Mockito.mock(Debugger.Debuggees.Breakpoints.class);
Debugger.Debuggees.Breakpoints.List list = Mockito.mock(Debugger.Debuggees.Breakpoints.List.class);
when(client.debuggees()).thenReturn(debuggees);
when(debuggees.breakpoints()).thenReturn(breakpoints);
when(breakpoints.list(DEBUGEE_ID)).thenReturn(list);
when(list.setIncludeInactive(Boolean.TRUE)).thenReturn(list);
when(list.setActionValue("CAPTURE")).thenReturn(list);
when(list.setStripResults(Boolean.TRUE)).thenReturn(list);
when(list.setWaitToken(null)).thenReturn(list);
when(list.setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger())).thenReturn(list);
when(list.execute()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
ListBreakpointsResponse response = new ListBreakpointsResponse();
List<Breakpoint> copy = new ArrayList<Breakpoint>(returnedBreakpoints);
response.setBreakpoints(copy);
return response;
}
});
return client;
}
Aggregations