protected String runObserverTask()

in ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/ObserverTask.java [146:215]


    protected String runObserverTask() {
        observationLock.lock();

        try {
            if (!tcBotBgAuth.isServerAuthorized())
                return "Server authorization required.";

            ITcBotUserCreds creds = tcBotBgAuth.getServerAuthorizerCreds();

            int checkedBuilds = 0;
            int notFinishedBuilds = 0;
            Set<String> ticketsNotified = new HashSet<>();

            List<ContributionKey> rmv = new ArrayList<>();

            for (ContributionKey key : infos.keySet()) {
                BuildsInfo info = infos.get(key);

                ITeamcityIgnited teamcity = teamcityIgnitedProvider.server(info.srvId, creds);

                checkedBuilds += info.buildsCount();

                if (info.isCancelled(teamcity, strCompactor)) {
                    rmv.add(key);

                    logger.error("JIRA will not be commented." +
                        " [ticket: " + info.ticket + ", branch:" + info.branchForTc + "] : " +
                        "one or more re-runned blocker's builds finished with UNKNOWN status.");

                    continue;
                }

                if (!info.isFinished(teamcity, strCompactor)) {
                    notFinishedBuilds += info.buildsCount() - info.finishedBuildsCount(teamcity, strCompactor);

                    continue;
                }

                Visa visa = visasHistStorage.getLastVisaRequest(info.getContributionKey()).getResult();

                if (!visa.isSuccess()) {
                    String baseBranchForTc = info.baseBranchForTc;

                    Visa updatedVisa = visaIssuer.notifyJira(info.srvId, creds, info.buildTypeId,
                        info.branchForTc, info.ticket, baseBranchForTc);

                    visasHistStorage.updateLastVisaRequest(info.getContributionKey(), (req -> req.setResult(updatedVisa)));

                    if (updatedVisa.isSuccess())
                        ticketsNotified.add(info.ticket);

                    visa = updatedVisa;
                }

                if (visa.isSuccess())
                    rmv.add(key);
            }

            rmv.forEach(key -> {
                infos.remove(key);

                visasHistStorage.updateLastVisaRequest(key, req -> req.setObservingStatus(false));
            });

            return "Checked " + checkedBuilds + " not finished " + notFinishedBuilds + " notified: " + ticketsNotified;
        }
        finally {
            observationLock.unlock();
        }
    }