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-10095: Support Build Parameters specifying in triggering builds
Date Mon, 06 May 2019 13:13:37 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit be32ce96d59ac1fc1cbc2621ca37d78281140947
Author: Dmitriy Pavlov <dpavlov@apache.org>
AuthorDate: Mon May 6 16:11:34 2019 +0300

    IGNITE-10095: Support Build Parameters specifying in triggering builds
---
 .../apache/ignite/ci/IgnitePersistentTeamcity.java |  7 +-
 .../apache/ignite/ci/IgniteTeamcityConnection.java | 87 ++++++++++++++--------
 .../org/apache/ignite/ci/jobs/CheckQueueJob.java   |  3 +-
 .../runners/IgniteTeamcityHelperRunnerExample.java |  5 +-
 .../ignite/ci/tcbot/conf/BuildParameter.java       | 53 +++++++++++++
 .../ignite/ci/tcbot/conf/ChainAtServerTracked.java | 38 +++++++++-
 .../tcbot/visa/TcBotTriggerAndSignOffService.java  |  2 +-
 .../ci/teamcity/ignited/ITeamcityIgnited.java      |  7 +-
 .../ci/teamcity/ignited/TeamcityIgnitedImpl.java   |  5 +-
 .../ignite/ci/teamcity/pure/ITeamcityConn.java     | 10 ++-
 10 files changed, 170 insertions(+), 47 deletions(-)

diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
index b297196..770e532 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
@@ -19,11 +19,11 @@ package org.apache.ignite.ci;
 
 import java.io.File;
 import java.util.List;
+import java.util.Map;
 import java.util.SortedSet;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Function;
 import javax.annotation.Nullable;
@@ -210,8 +210,9 @@ public class IgnitePersistentTeamcity implements IAnalyticsEnabledTeamcity,
ITea
 
     /** {@inheritDoc} */
     @AutoProfiling
-    @Override public Build triggerBuild(String buildTypeId, @NotNull String branchName, boolean
cleanRebuild, boolean queueAtTop) {
-        return teamcity.triggerBuild(buildTypeId, branchName, cleanRebuild, queueAtTop);
+    @Override public Build triggerBuild(String buildTypeId, @NotNull String branchName, boolean
cleanRebuild,
+        boolean queueAtTop, Map<String, Object> buildParms) {
+        return teamcity.triggerBuild(buildTypeId, branchName, cleanRebuild, queueAtTop, buildParms);
     }
 
     /** {@inheritDoc} */
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
index da570d6..efafbf1 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
@@ -21,6 +21,32 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Stopwatch;
 import com.google.common.base.Strings;
 import com.google.common.util.concurrent.MoreExecutors;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.UncheckedIOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.SortedSet;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import javax.inject.Inject;
+import javax.xml.bind.JAXBException;
 import org.apache.ignite.ci.analysis.ISuiteResults;
 import org.apache.ignite.ci.analysis.LogCheckResult;
 import org.apache.ignite.ci.analysis.LogCheckTask;
@@ -56,20 +82,6 @@ import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import javax.inject.Inject;
-import javax.xml.bind.JAXBException;
-import java.io.*;
-import java.util.SortedSet;
-import java.util.List;
-import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicReference;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
 import static java.util.concurrent.CompletableFuture.supplyAsync;
 import static org.apache.ignite.ci.HelperConfig.ensureDirExist;
 import static org.apache.ignite.ci.util.XmlUtil.xmlEscapeText;
@@ -200,10 +212,11 @@ public class IgniteTeamcityConnection implements ITeamcity {
     /** {@inheritDoc} */
     @AutoProfiling
     @Override public Build triggerBuild(
-            String buildTypeId,
-            @NotNull @Nonnull String branchName,
-            boolean cleanRebuild,
-            boolean queueAtTop
+        String buildTypeId,
+        @NotNull @Nonnull String branchName,
+        boolean cleanRebuild,
+        boolean queueAtTop,
+        @Nullable Map<String, Object> buildParms
     ) {
         String triggeringOptions =
             " <triggeringOptions" +
@@ -215,25 +228,35 @@ public class IgniteTeamcityConnection implements ITeamcity {
         String comments = " <comment><text>Build triggered from Ignite TC Bot"
+
             " [cleanRebuild=" + cleanRebuild + ", top=" + queueAtTop + "]</text></comment>\n";
 
-        String param = "<build branchName=\"" + xmlEscapeText(branchName) + "\">\n"
+
-            "    <buildType id=\"" +
-            buildTypeId + "\"/>\n" +
-            comments +
-            triggeringOptions +
-            //some fake property to avoid merging build in queue
-            "    <properties>\n" +
-            "        <property name=\"build.query.loginTs\" value=\"" + System.currentTimeMillis()
+ "\"/>\n" +
-            // "        <property name=\"testSuite\" value=\"org.apache.ignite.spi.discovery.tcp.ipfinder.elb.TcpDiscoveryElbIpFinderSelfTest\"/>\n"
+
-            "    </properties>\n" +
-            "</build>";
+        Map<String, Object> props = new HashMap<>();
+
+        if (buildParms != null)
+            props.putAll(buildParms);
+
+        props.put("tcbot.triggerTime", System.currentTimeMillis()); // some fake property
to avoid merging build in queue
+
+        StringBuilder sb = new StringBuilder();
+        sb.append("<build branchName=\"").append(xmlEscapeText(branchName)).append("\">\n");
+        sb.append(" <buildType id=\"").append(buildTypeId).append("\"/>\n");
+        sb.append(comments);
+        sb.append(triggeringOptions);
+        sb.append(" <properties>\n");
+
+        props.forEach((k, v) -> {
+            sb.append("  <property name=\"").append(k).append("\"");
+            sb.append(" value=\"").append(xmlEscapeText(Objects.toString(v))).append("\"/>\n");
+        });
+
+        sb.append(" </properties>\n");
+        sb.append("</build>");
 
         String url = host() + "app/rest/buildQueue";
 
         try {
-            logger.info("Triggering build: buildTypeId={}, branchName={}, cleanRebuild={},
queueAtTop={}",
-                buildTypeId, branchName, cleanRebuild, queueAtTop);
+            logger.info("Triggering build: buildTypeId={}, branchName={}, cleanRebuild={},
queueAtTop={}, buildParms={}",
+                buildTypeId, branchName, cleanRebuild, queueAtTop, props);
 
-            try (StringReader reader = new StringReader(HttpUtil.sendPostAsString(basicAuthTok,
url, param))) {
+            try (StringReader reader = new StringReader(HttpUtil.sendPostAsString(basicAuthTok,
url, sb.toString()))) {
                 return XmlUtil.load(Build.class, reader);
             }
             catch (JAXBException e) {
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 21b6048..d513e26 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
@@ -257,7 +257,8 @@ public class CheckQueueJob implements Runnable {
 
             startTimes.put(chain, curr);
 
-            tcIgn.triggerBuild(chain.suiteId, chain.branchForRest, true, false);
+            Map<String, Object> parms = chain.buildParameters();
+            tcIgn.triggerBuild(chain.suiteId, chain.branchForRest(), true, false, parms);
 
             res.append(chain.branchForRest).append(" ").append(chain.suiteId).append(" triggered;
");
         }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/IgniteTeamcityHelperRunnerExample.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/IgniteTeamcityHelperRunnerExample.java
index fc6b3f9..85118e0 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/IgniteTeamcityHelperRunnerExample.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/runners/IgniteTeamcityHelperRunnerExample.java
@@ -17,6 +17,9 @@
 
 package org.apache.ignite.ci.runners;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -61,7 +64,7 @@ public class IgniteTeamcityHelperRunnerExample {
             String buildTypeIdAllP = "id8xIgniteGridGainTestsJava8_RunAll";
             //  buildTypeIdAll="IgniteTests24Java8_Queries1";
 
-            helper.triggerBuild(buildTypeIdAll, branchName, true, false);
+            helper.triggerBuild(buildTypeIdAll, branchName, true, false, Collections.emptyMap());
         }
     }
 
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/BuildParameter.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/BuildParameter.java
new file mode 100644
index 0000000..c4709b1
--- /dev/null
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/BuildParameter.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ci.tcbot.conf;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+
+public class BuildParameter {
+    private String name;
+    private String value;
+    private List<String> randomValues = new LinkedList<>();
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+        if (o == null || getClass() != o.getClass())
+            return false;
+        BuildParameter param = (BuildParameter)o;
+        return Objects.equals(name, param.name) &&
+            Objects.equals(value, param.value) &&
+            Objects.equals(randomValues, param.randomValues);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return Objects.hash(name, value, randomValues);
+    }
+
+    public String name() {
+        return name;
+    }
+
+    public Object generateValue() {
+        return value;
+    }
+}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ChainAtServerTracked.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ChainAtServerTracked.java
index b4cd6a0..0892445 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ChainAtServerTracked.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ChainAtServerTracked.java
@@ -18,6 +18,9 @@
 package org.apache.ignite.ci.tcbot.conf;
 
 import com.google.common.base.Strings;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
 import javax.annotation.Nonnull;
@@ -31,7 +34,7 @@ import static com.google.common.base.Strings.isNullOrEmpty;
  */
 @SuppressWarnings("PublicField")
 public class ChainAtServerTracked extends ChainAtServer {
-    /** Branch identifier by TC identification for REST api */
+    /** Branch identifier by TC identification for REST API. */
     @Nonnull public String branchForRest;
 
     /** TC identified base branch: null means the same as &lt;default>, master. For
not tracked branches. */
@@ -43,6 +46,9 @@ public class ChainAtServerTracked extends ChainAtServer {
     /** Automatic build triggering quiet period in minutes. */
     @Nullable private Integer triggerBuildQuietPeriod;
 
+    /** Build parameters for Triggerring. */
+    @Nullable private List<BuildParameter> triggerParameters;
+
     /** @return {@link #suiteId} */
     @Nonnull public String getSuiteIdMandatory() {
         checkState(!isNullOrEmpty(suiteId), "Invalid config: suiteId should be filled " +
this);
@@ -72,8 +78,7 @@ public class ChainAtServerTracked extends ChainAtServer {
     /**
      * {@inheritDoc}
      */
-    @Override
-    public boolean equals(Object o) {
+    @Override public boolean equals(Object o) {
         if (this == o)
             return true;
 
@@ -108,4 +113,31 @@ public class ChainAtServerTracked extends ChainAtServer {
     public int getTriggerBuildQuietPeriod() {
         return triggerBuildQuietPeriod == null ? 0 : triggerBuildQuietPeriod;
     }
+
+    /**
+     * @return Map with parameter values for current run.
+     */
+    public Map<String, Object> buildParameters() {
+        Map<String, Object> values = new HashMap<>();
+
+        if (triggerParameters != null) {
+
+            triggerParameters.forEach(
+                p -> {
+                    String name = p.name();
+                    Object val = p.generateValue();
+
+                    if (!Strings.isNullOrEmpty(name) && val != null)
+                        values.put(name, val);
+                }
+            );
+        }
+
+        return values;
+    }
+
+    /** */
+    public String branchForRest() {
+        return branchForRest;
+    }
 }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java
index c8bc647..00299bc 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/visa/TcBotTriggerAndSignOffService.java
@@ -266,7 +266,7 @@ public class TcBotTriggerAndSignOffService {
         Build[] builds = new Build[suiteIds.length];
 
         for (int i = 0; i < suiteIds.length; i++)
-            builds[i] = teamcity.triggerBuild(suiteIds[i], branchForTc, false, top != null
&& top);
+            builds[i] = teamcity.triggerBuild(suiteIds[i], branchForTc, false, top != null
&& top, new HashMap<String, Object>());
 
         if (observe != null && observe)
             jiraRes += observeJira(srvId, branchForTc, ticketId, prov, parentSuiteId, builds);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnited.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnited.java
index 276facc..ea764bf 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnited.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnited.java
@@ -19,6 +19,7 @@ package org.apache.ignite.ci.teamcity.ignited;
 import com.google.common.base.Strings;
 import java.util.Collection;
 import java.util.Date;
+import java.util.Map;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
@@ -99,8 +100,12 @@ public interface ITeamcityIgnited {
      * @param branchName Branch name.
      * @param cleanRebuild Rebuild all dependencies.
      * @param queueAtTop Put at the top of the build queue.
+     * @param buildParms addtitional build parameters, for example Java home or test suite.
Use
+     *      * <code>put("testSuite", "org.apache.ignite.spi.discovery.tcp.ipfinder.elb.TcpDiscoveryElbIpFinderSelfTest");</code>
+     *      * to specify test suite to run.
      */
-    public Build triggerBuild(String buildTypeId, String branchName, boolean cleanRebuild,
boolean queueAtTop);
+    public Build triggerBuild(String buildTypeId, String branchName, boolean cleanRebuild,
boolean queueAtTop,
+        Map<String, Object> buildParms);
 
     /**
      * @param srvId Server id.
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedImpl.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedImpl.java
index 1825b2d..9a4c0aa 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedImpl.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedImpl.java
@@ -472,8 +472,9 @@ public class TeamcityIgnitedImpl implements ITeamcityIgnited {
     }
 
     /** {@inheritDoc} */
-    @Override public Build triggerBuild(String buildTypeId, String branchName, boolean cleanRebuild,
boolean queueAtTop) {
-        Build build = conn.triggerBuild(buildTypeId, branchName, cleanRebuild, queueAtTop);
+    @Override public Build triggerBuild(String buildTypeId, String branchName, boolean cleanRebuild,
boolean queueAtTop,
+        Map<String, Object> buildParms) {
+        Build build = conn.triggerBuild(buildTypeId, branchName, cleanRebuild, queueAtTop,
buildParms);
 
         //todo may add additional parameter: load builds into DB in sync/async fashion
         buildRefSync.runActualizeBuildRefs(srvCode, false, Sets.newHashSet(build.getId()),
conn);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
index d0e38dd..1adfb07 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.ci.teamcity.pure;
 
 import java.util.List;
+import java.util.Map;
 import java.util.SortedSet;
 import java.util.concurrent.atomic.AtomicReference;
 import javax.annotation.Nonnull;
@@ -81,13 +82,16 @@ public interface ITeamcityConn {
 
     /**
      * Trigger build.
-     *
-     * @param buildTypeId Build identifier.
+     * @param buildTypeId Build type (suite) identifier.
      * @param branchName Branch name.
      * @param cleanRebuild Rebuild all dependencies.
      * @param queueAtTop Put at the top of the build queue.
+     * @param buildParms addtitional build parameters, for example Java home or test suite.
Use
+     * <code>put("testSuite", "org.apache.ignite.spi.discovery.tcp.ipfinder.elb.TcpDiscoveryElbIpFinderSelfTest");</code>
+     * to specify test suite to run.
      */
-    public Build triggerBuild(String buildTypeId, @Nonnull String branchName, boolean cleanRebuild,
boolean queueAtTop);
+    public Build triggerBuild(String buildTypeId, @Nonnull String branchName, boolean cleanRebuild,
boolean queueAtTop,
+        @Nullable Map<String, Object> buildParms);
 
     /**
      * @param buildId Build id.


Mime
View raw message