use of com.google.api.services.clouddebugger.v2.model.Debuggee in project google-cloud-intellij by GoogleCloudPlatform.
the class ProjectRepositoryValidator method checkSyncStashState.
/**
* Compares the current source tree with the state described by the Cloud Debugger api. Only local
* and cloud repo Git repositories are supported.
*/
@NotNull
@Transient
public SyncResult checkSyncStashState() {
if (processState.getProject() == null) {
return new SyncResult(/*isInvalid*/
true, /*needsStash*/
false, /*needsSync*/
false, /*target SHA*/
null, /*target repo*/
null, /* cloud repo */
false, /* repoType */
null);
}
GitRepositoryManager manager = GitUtil.getRepositoryManager(processState.getProject());
List<GitRepository> repositories = manager.getRepositories();
CloudRepoSourceContext cloudRepo = null;
GerritSourceContext gerritRepo = null;
GitSourceContext otherGitRepo = null;
String repoType = null;
boolean foundDebuggee = false;
if (getCloudDebuggerClient() != null && !com.google.common.base.Strings.isNullOrEmpty(processState.getProjectNumber())) {
ListDebuggeesResponse debuggees;
try {
debuggees = getCloudDebuggerClient().debuggees().list().setProject(processState.getProjectNumber()).setClientVersion(ServiceManager.getService(PluginInfoService.class).getClientVersionForCloudDebugger()).execute();
for (Debuggee debuggee : debuggees.getDebuggees()) {
if (processState.getDebuggeeId() != null && processState.getDebuggeeId().equals(debuggee.getId())) {
// implicit assumption this doesn't happen more than once
foundDebuggee = true;
List<SourceContext> contexts = debuggee.getSourceContexts();
if (contexts != null) {
for (SourceContext sourceContext : contexts) {
cloudRepo = sourceContext.getCloudRepo();
gerritRepo = sourceContext.getGerrit();
otherGitRepo = sourceContext.getGit();
if (cloudRepo != null) {
// shouldn't be more than one repo but if there is, we'll prefer cloud repos
break;
} else if (sourceContext.getCloudWorkspace() != null) {
repoType = GctBundle.getString("clouddebug.workspace");
}
}
}
}
}
} catch (IOException ex) {
LOG.warn("Error detecting server side source context", ex);
}
}
if (!foundDebuggee) {
return new SyncResult(/*isinvalid*/
true, /*needsstash*/
false, /*needssync*/
false, /*target SHA*/
null, /*target repo*/
null, /* hasCloudRepository */
false, /* repoType */
GctBundle.getString("clouddebug.unknown.repository.type"));
}
GitRepository targetLocalRepo = null;
String revisionId = null;
// shouldn't be more than one repo but if there is, we pick cloud repos
if (cloudRepo != null) {
revisionId = cloudRepo.getRevisionId();
repoType = GctBundle.getString("clouddebug.cloud.repository");
} else if (gerritRepo != null) {
revisionId = gerritRepo.getRevisionId();
repoType = GctBundle.getString("clouddebug.gerrit");
} else if (otherGitRepo != null) {
revisionId = otherGitRepo.getRevisionId();
repoType = GctBundle.getString("clouddebug.nongoogle.git");
}
if (revisionId != null) {
for (GitRepository repository : repositories) {
try {
GitChangeUtils.resolveReference(processState.getProject(), repository.getRoot(), revisionId);
targetLocalRepo = repository;
break;
} catch (VcsException ex) {
LOG.warn("cloud revision not found in local repo. continuing search...");
}
}
}
boolean needsStash = false;
boolean needsSync = false;
String syncSha = null;
if (targetLocalRepo != null) {
// check for local changes.
try {
if (GitUtil.hasLocalChanges(true, processState.getProject(), targetLocalRepo.getRoot()) || GitUtil.hasLocalChanges(false, processState.getProject(), targetLocalRepo.getRoot())) {
needsStash = true;
}
if (!Strings.isNullOrEmpty(targetLocalRepo.getCurrentRevision()) && !Strings.isNullOrEmpty(revisionId) && targetLocalRepo.getCurrentRevision() != null && !targetLocalRepo.getCurrentRevision().equals(revisionId)) {
syncSha = revisionId;
needsSync = true;
}
} catch (VcsException vcsException) {
LOG.error("Error detecting local changes during attach", vcsException);
}
}
boolean hasRemoteRepository = cloudRepo != null || gerritRepo != null || otherGitRepo != null;
return new SyncResult(/*isinvalid*/
false, needsStash, needsSync, syncSha, targetLocalRepo, hasRemoteRepository, repoType);
}
use of com.google.api.services.clouddebugger.v2.model.Debuggee 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);
}
}
use of com.google.api.services.clouddebugger.v2.model.Debuggee in project google-cloud-intellij by GoogleCloudPlatform.
the class DebugTargetTest method createDebuggee.
private Debuggee createDebuggee(String module, String version) {
Debuggee defaultDebuggee = new Debuggee();
Map<String, String> labels = new HashMap<String, String>();
if (module != null) {
labels.put(MODULE, module);
}
labels.put(VERSION, version);
defaultDebuggee.setLabels(labels);
return defaultDebuggee;
}
use of com.google.api.services.clouddebugger.v2.model.Debuggee in project beam by apache.
the class DataflowRunner method maybeRegisterDebuggee.
private void maybeRegisterDebuggee(DataflowPipelineOptions options, String uniquifier) {
if (!options.getEnableCloudDebugger()) {
return;
}
if (options.getDebuggee() != null) {
throw new RuntimeException("Should not specify the debuggee");
}
Clouddebugger debuggerClient = DataflowTransport.newClouddebuggerClient(options).build();
Debuggee debuggee = registerDebuggee(debuggerClient, uniquifier);
options.setDebuggee(debuggee);
System.out.println(debuggerMessage(options.getProject(), debuggee.getUniquifier()));
}
use of com.google.api.services.clouddebugger.v2.model.Debuggee 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);
}
}
Aggregations