Search in sources :

Example 1 with Debuggees

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees 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);
}
Also used : ListDebuggeesResponse(com.google.api.services.clouddebugger.v2.model.ListDebuggeesResponse) GitRepositoryManager(git4idea.repo.GitRepositoryManager) GitSourceContext(com.google.api.services.clouddebugger.v2.model.GitSourceContext) CloudRepoSourceContext(com.google.api.services.clouddebugger.v2.model.CloudRepoSourceContext) GerritSourceContext(com.google.api.services.clouddebugger.v2.model.GerritSourceContext) IOException(java.io.IOException) GerritSourceContext(com.google.api.services.clouddebugger.v2.model.GerritSourceContext) CloudRepoSourceContext(com.google.api.services.clouddebugger.v2.model.CloudRepoSourceContext) GitSourceContext(com.google.api.services.clouddebugger.v2.model.GitSourceContext) SourceContext(com.google.api.services.clouddebugger.v2.model.SourceContext) GitRepository(git4idea.repo.GitRepository) Debuggee(com.google.api.services.clouddebugger.v2.model.Debuggee) VcsException(com.intellij.openapi.vcs.VcsException) Transient(com.intellij.util.xmlb.annotations.Transient) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Debuggees

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees 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 3 with Debuggees

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees 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 4 with Debuggees

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees 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 5 with Debuggees

use of com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees 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;
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) ListBreakpointsResponse(com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Debuggee (com.google.api.services.clouddebugger.v2.model.Debuggee)3 IOException (java.io.IOException)3 Debugger (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger)2 Debuggees (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees)2 Breakpoints (com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger.Debuggees.Breakpoints)2 Breakpoint (com.google.api.services.clouddebugger.v2.model.Breakpoint)2 ListBreakpointsResponse (com.google.api.services.clouddebugger.v2.model.ListBreakpointsResponse)2 ListDebuggeesResponse (com.google.api.services.clouddebugger.v2.model.ListDebuggeesResponse)2 PluginInfoService (com.google.cloud.tools.intellij.service.PluginInfoService)2 CloudRepoSourceContext (com.google.api.services.clouddebugger.v2.model.CloudRepoSourceContext)1 GerritSourceContext (com.google.api.services.clouddebugger.v2.model.GerritSourceContext)1 GitSourceContext (com.google.api.services.clouddebugger.v2.model.GitSourceContext)1 RegisterDebuggeeRequest (com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeRequest)1 RegisterDebuggeeResponse (com.google.api.services.clouddebugger.v2.model.RegisterDebuggeeResponse)1 SourceContext (com.google.api.services.clouddebugger.v2.model.SourceContext)1 VcsException (com.intellij.openapi.vcs.VcsException)1 HashMap (com.intellij.util.containers.HashMap)1 Transient (com.intellij.util.xmlb.annotations.Transient)1 GitRepository (git4idea.repo.GitRepository)1 GitRepositoryManager (git4idea.repo.GitRepositoryManager)1