ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpav...@apache.org
Subject [ignite-teamcity-bot] 01/01: IGNITE-10211: Support triggering non-master branches
Date Sat, 10 Nov 2018 17:04:58 GMT
This is an automated email from the ASF dual-hosted git repository.

dpavlov pushed a commit to branch ignite-10211
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git

commit 1ca04f3828ec5636591b62055832efc9dae1013d
Author: Dmitriy Pavlov <dpavlov@apache.org>
AuthorDate: Sat Nov 10 20:02:55 2018 +0300

    IGNITE-10211: Support triggering non-master branches
---
 .../org/apache/ignite/ci/conf/BranchesTracked.java |  10 +-
 .../org/apache/ignite/ci/jobs/CheckQueueJob.java   | 104 ++++++++++++---------
 2 files changed, 67 insertions(+), 47 deletions(-)

diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/BranchesTracked.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/BranchesTracked.java
index af02282..94d1b25 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/BranchesTracked.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/conf/BranchesTracked.java
@@ -17,10 +17,7 @@
 
 package org.apache.ignite.ci.conf;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -30,6 +27,7 @@ public class BranchesTracked {
     /** Branches. */
     private List<BranchTracked> branches = new ArrayList<>();
 
+
     /**
      * @return list of internal identifiers of branch.
      */
@@ -55,4 +53,8 @@ public class BranchesTracked {
     public Set<String> getServerIds() {
         return branches.stream().flatMap(BranchTracked::getChainsStream).map(ChainAtServer::getServerId).collect(Collectors.toSet());
     }
+
+    public List<BranchTracked> getBranches() {
+        return Collections.unmodifiableList(branches);
+    }
 }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
index d7974e5..5f3a60e 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jobs/CheckQueueJob.java
@@ -25,6 +25,8 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import javax.inject.Inject;
 import jersey.repackaged.com.google.common.base.Throwables;
 import org.apache.ignite.ci.HelperConfig;
@@ -101,29 +103,31 @@ public class CheckQueueJob implements Runnable {
             return msg;
         }
 
-        String branch = FullQueryParams.DEFAULT_TRACKED_BRANCH_NAME;
-
         //todo support several branches
-        final BranchTracked tracked = HelperConfig.getTrackedBranches().getBranchMandatory(branch);
+        List<BranchTracked> tracked = HelperConfig.getTrackedBranches().getBranches();
 
-        if (tracked == null || tracked.getChains() == null || tracked.getChains().isEmpty())
{
-            final String msg = "Background check queue skipped - no config specified for
";
-            logger.info(msg + "\"{}\".", branch);
+        if (tracked == null || tracked.isEmpty()) {
+            final String msg = "Background check queue skipped - no config set for tracked
branches.";
+            logger.info(msg);
 
-            return msg + branch;
+            return msg;
         }
 
         int srvsChecked = 0, chainsChecked = 0;
 
-        Map<String, List<ChainAtServerTracked>> chainsBySrv = mapChainsByServer(tracked.getChains());
+        Map<String, List<ChainAtServerTracked>> chainsBySrv = mapChainsByServer(tracked);
 
         for (Map.Entry<String, List<ChainAtServerTracked>> entry : chainsBySrv.entrySet())
{
             String srvId = entry.getKey();
 
-            List<ChainAtServerTracked> chains = entry.getValue();
+            List<ChainAtServerTracked> chainsAll = entry.getValue();
+            List<ChainAtServerTracked> chains = chainsAll.stream()
+                    .filter(c -> Objects.equals(c.serverId, srvId))
+                    .collect(Collectors.toList());
 
             srvsChecked++;
-            chainsChecked += chains.stream().filter(c -> Objects.equals(c.serverId, srvId)).count();
+
+            chainsChecked += chainsAll.size();
 
             try {
                 checkQueue(srvId, chains);
@@ -180,32 +184,44 @@ public class CheckQueueJob implements Runnable {
 
         String selfLogin = creds.getUser(teamcity.serverId());
 
-        for (BuildRef ref : builds) {
-            Build build = teamcity.getBuild(ref.href);
+        StringBuilder res = new StringBuilder();
 
-            User user = build.getTriggered().getUser();
+        for (ChainAtServerTracked chain : chains) {
+            if(!Objects.equals(chain.serverId, teamcity.serverId()))
+                continue;
 
-            if (user == null) {
-                logger.info("Unable to get username for queued build {} (type={}).", ref.getId(),
ref.buildTypeId);
+            boolean trigger = true;
+            for (BuildRef ref : builds) {
+                Build build = teamcity.getBuild(ref.href);
 
-                continue;
-            }
+                User user = build.getTriggered().getUser();
 
-            String login = user.username;
+                if (user == null) {
+                    logger.info("Unable to get username for queued build {} (type={}).",
ref.getId(), ref.buildTypeId);
 
-            if (selfLogin.equalsIgnoreCase(login)) {
-                final String msg = MessageFormat.format("Queued build {0} was early triggered
by me (user {1}). Will not startIgnite build.", ref.getId(), login);
+                    continue;
+                }
 
-                logger.info(msg);
+                String login = user.username;
 
-                return msg;
-            }
-        }
+                if (selfLogin.equalsIgnoreCase(login)
+                        && Objects.equals(ref.branchName, chain.branchForRest)) {
+                    final String msg
+                            = MessageFormat.format("Queued build {0} was early triggered
" +
+                            "(user {1}, branch {2}, suite {3})." +
+                            " Will not startIgnite build.", ref.getId(), login, ref.branchName,
ref.buildTypeId);
 
-        StringBuilder res = new StringBuilder();
+                    logger.info(msg);
 
-        for (ChainAtServerTracked chain : chains) {
-            if(!Objects.equals(chain.serverId, teamcity.serverId()))
+                    res.append(msg).append("; ");
+
+                    trigger = false;
+
+                    break;
+                }
+            }
+
+            if (!trigger)
                 continue;
 
             long curr = System.currentTimeMillis();
@@ -244,32 +260,34 @@ public class CheckQueueJob implements Runnable {
     }
 
     /**
-     * @param chains chains.
+     * @param branchesTracked Tracked branches.
      * @return Mapped chains to server identifier.
      */
-    private Map<String, List<ChainAtServerTracked>> mapChainsByServer(List<ChainAtServerTracked>
chains) {
+    private Map<String, List<ChainAtServerTracked>> mapChainsByServer(List<BranchTracked>
branchesTracked) {
         Map<String, List<ChainAtServerTracked>> chainsBySrv = new HashMap<>();
 
-        for (ChainAtServerTracked chain : chains) {
-            String srv = chain.serverId;
+        for(BranchTracked branchTracked: branchesTracked) {
+            for (ChainAtServerTracked chain : branchTracked.getChains()) {
+                String srv = chain.serverId;
 
-            if (!creds.hasAccess(srv)) {
-                logger.warn("Background operations credentials does not grant access to server
\"{}\"," +
-                    " build queue trigger will not work.", srv);
+                if (!creds.hasAccess(srv)) {
+                    logger.warn("Background operations credentials does not grant access
to server \"{}\"," +
+                            " build queue trigger will not work.", srv);
 
-                continue;
-            }
+                    continue;
+                }
 
-            if (!chain.isTriggerBuild()) {
-                logger.info("Build triggering disabled for server={}, suite={}, branch={}",
-                    srv, chain.getSuiteIdMandatory(), chain.getBranchForRestMandatory());
+                if (!chain.isTriggerBuild()) {
+                    logger.info("Build triggering disabled for server={}, suite={}, branch={}",
+                            srv, chain.getSuiteIdMandatory(), chain.getBranchForRestMandatory());
 
-                continue;
-            }
+                    continue;
+                }
 
-            logger.info("Checking queue for server {}.", srv);
+                logger.info("Checking queue for server {}.", srv);
 
-            chainsBySrv.computeIfAbsent(srv, v -> new ArrayList<>()).add(chain);
+                chainsBySrv.computeIfAbsent(srv, v -> new ArrayList<>()).add(chain);
+            }
         }
 
         return chainsBySrv;


Mime
View raw message