You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by dp...@apache.org on 2019/02/02 10:12:14 UTC

[ignite-teamcity-bot] branch ignite-11105-alias updated: IGNITE-11105: TC servers aliases support, configuration of server code implementation.

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/ignite-11105-alias by this push:
     new 1a66a77  IGNITE-11105: TC servers aliases support, configuration of server code implementation.
1a66a77 is described below

commit 1a66a7709c563fa9b77b55f9c1b108c3ad69137d
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Sat Feb 2 13:12:09 2019 +0300

    IGNITE-11105: TC servers aliases support, configuration of server code implementation.
---
 conf/branches.json                                 |  6 ++++
 .../org/apache/ignite/ci/conf/BranchesTracked.java | 21 +++++++-----
 .../apache/ignite/ci/tcbot/conf/ITcBotConfig.java  | 10 +++---
 .../ignite/ci/tcbot/conf/JiraServerConfig.java     | 18 +++++-----
 .../ci/tcbot/conf/LocalFilesBasedConfig.java       | 40 ++++++++++++----------
 .../ignite/ci/tcbot/conf/TcServerConfig.java       | 30 +++++++++++-----
 .../org/apache/ignite/ci/web/rest/login/Login.java |  6 ++--
 .../rest/tracked/GetTrackedBranchTestResults.java  |  4 +--
 .../ci/tcbot/chain/MockBasedTcBotModule.java       | 19 +++++-----
 9 files changed, 88 insertions(+), 66 deletions(-)

diff --git a/conf/branches.json b/conf/branches.json
index 0b0d9bf..05087a4 100644
--- a/conf/branches.json
+++ b/conf/branches.json
@@ -1,4 +1,10 @@
 {
+  "primaryServerCode": "apache",
+  "tcServers": [
+  ],
+  "jiraServers": [
+    {}
+  ],
   "branches": [
     {
       "id": "master",
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 7097951..1980fe4 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
@@ -32,10 +32,10 @@ public class BranchesTracked {
     private List<BranchTracked> branches = new ArrayList<>();
 
     /** Primary server ID. */
-    @Nullable private String primaryServerId;
+    @Nullable private String primaryServerCode;
 
     /** Additional list Servers to be used for validation of PRs, but not for tracking any branches. */
-    private List<TcServerConfig> servers = new ArrayList<>();
+    private List<TcServerConfig> tcServers = new ArrayList<>();
 
     /** JIRA config to be used . */
     private List<JiraServerConfig> jiraServers = new ArrayList<>();
@@ -74,7 +74,7 @@ public class BranchesTracked {
             .map(ChainAtServer::getServerId);
 
         return Stream.concat(srvsInTracked,
-            servers.stream().map(TcServerConfig::getName))
+            tcServers.stream().map(TcServerConfig::getCode))
             .collect(Collectors.toSet());
     }
 
@@ -86,15 +86,18 @@ public class BranchesTracked {
         branches.add(branch);
     }
 
-    @Nullable public String primaryServerId() {
-        return primaryServerId;
+    /**
+     * @return Primary server code.
+     */
+    @Nullable public String primaryServerCode() {
+        return primaryServerCode;
     }
 
-    public Optional<TcServerConfig> getServer(String name) {
-        return servers.stream().filter(s -> name.equals(s.getName())).findAny();
+    public Optional<TcServerConfig> getServer(String code) {
+        return tcServers.stream().filter(s -> code.equals(s.getCode())).findAny();
     }
 
-    public Optional<JiraServerConfig> getJiraServer(String name) {
-        return jiraServers.stream().filter(s -> name.equals(s.getName())).findAny();
+    public Optional<JiraServerConfig> getJiraServer(String code) {
+        return jiraServers.stream().filter(s -> code.equals(s.getCode())).findAny();
     }
 }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java
index d4b422e..020d276 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/ITcBotConfig.java
@@ -25,10 +25,10 @@ import org.apache.ignite.ci.conf.BranchesTracked;
  * Teamcity Bot configuration access inteface.
  */
 public interface ITcBotConfig {
-    /** Default server id. */
-    String DEFAULT_SERVER_ID = "apache";
+    /** Default server code. */
+    String DEFAULT_SERVER_CODE = "apache";
 
-    public String primaryServerId();
+    public String primaryServerCode();
 
     /**
      * @return Tracked branches configuration for TC Bot.
@@ -49,7 +49,7 @@ public interface ITcBotConfig {
         return getTrackedBranches().getServerIds();
     }
 
-    public ITcServerConfig getTeamcityConfig(String srvName);
+    public ITcServerConfig getTeamcityConfig(String srvCode);
 
-    public IJiraServerConfig getJiraConfig(String srvName);
+    public IJiraServerConfig getJiraConfig(String srvCode);
 }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java
index 3fa5463..7c52361 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/JiraServerConfig.java
@@ -28,10 +28,10 @@ import org.jetbrains.annotations.Nullable;
  */
 public class JiraServerConfig implements IJiraServerConfig {
     /** Service (server) Name. */
-    private String name;
+    private String code;
 
     /**
-     * Tickets for commenting in JIRA and finding out PA tickets.
+     * Tickets for commenting in JIRA and finding out PA tickets. Default project is "IGNITE".
      */
     private String projectCode;
 
@@ -63,13 +63,13 @@ public class JiraServerConfig implements IJiraServerConfig {
     public JiraServerConfig() {
     }
 
-    public JiraServerConfig(String name, Properties props) {
-        this.name = name;
+    public JiraServerConfig(String code, Properties props) {
+        this.code = code;
         this.props = props;
     }
 
-    public String getName() {
-        return name;
+    public String getCode() {
+        return code;
     }
 
     /**
@@ -80,10 +80,10 @@ public class JiraServerConfig implements IJiraServerConfig {
     }
 
     /**
-     * @param name Name.
+     * @param code Name.
      */
-    public void name(String name) {
-        this.name = name;
+    public void code(String code) {
+        this.code = code;
     }
 
     /** {@inheritDoc} */
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java
index 919f8a2..270ea3b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/LocalFilesBasedConfig.java
@@ -34,18 +34,14 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
     }
 
     /** {@inheritDoc} */
-    @Override public ITcServerConfig getTeamcityConfig(String srvName) {
-        return getTrackedBranches().getServer(srvName)
+    @Override public ITcServerConfig getTeamcityConfig(String srvCode) {
+        return getTrackedBranches().getServer(srvCode)
             .orElseGet(() -> {
                 TcServerConfig tcCfg = new TcServerConfig();
 
-                tcCfg.name = srvName;
+                tcCfg.code(srvCode);
 
-                File workDir = HelperConfig.resolveWorkDir();
-
-                String cfgName = HelperConfig.prepareConfigName(srvName);
-
-                Properties props = HelperConfig.loadAuthProperties(workDir, cfgName);
+                Properties props = loadOldAuthProps(srvCode);
 
                 tcCfg.properties(props);
 
@@ -53,18 +49,14 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
             });
     }
 
-    @Override public IJiraServerConfig getJiraConfig(String srvName) {
-        return getTrackedBranches().getJiraServer(srvName)
+    @Override public IJiraServerConfig getJiraConfig(String srvCode) {
+        return getTrackedBranches().getJiraServer(srvCode)
             .orElseGet(() -> {
                 JiraServerConfig jCfg = new JiraServerConfig();
 
-                jCfg.name(srvName);
-
-                File workDir = HelperConfig.resolveWorkDir();
+                jCfg.code(srvCode);
 
-                String cfgName = HelperConfig.prepareConfigName(srvName);
-
-                Properties props = HelperConfig.loadAuthProperties(workDir, cfgName);
+                Properties props = loadOldAuthProps(srvCode);
 
                 jCfg.properties(props);
 
@@ -73,9 +65,19 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
     }
 
     /** {@inheritDoc} */
-    @Override public String primaryServerId() {
-        String srvId = getTrackedBranches().primaryServerId();
+    @Override public String primaryServerCode() {
+        String srvCode = getTrackedBranches().primaryServerCode();
+
+        return Strings.isNullOrEmpty(srvCode) ? ITcBotConfig.DEFAULT_SERVER_CODE : srvCode;
+    }
+
+
+    private Properties loadOldAuthProps(String srvCode) {
+        File workDir = HelperConfig.resolveWorkDir();
 
-        return Strings.isNullOrEmpty(srvId) ? ITcBotConfig.DEFAULT_SERVER_ID : srvId;
+        String cfgName = HelperConfig.prepareConfigName(srvCode);
+
+        return HelperConfig.loadAuthProperties(workDir, cfgName);
     }
+
 }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java
index a3d4fb9..49756ec 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/TcServerConfig.java
@@ -27,13 +27,17 @@ import org.jetbrains.annotations.Nullable;
  * Teamcity connection configuration or reference to another config.
  */
 public class TcServerConfig implements ITcServerConfig {
+    private static final String DEFAULT_HOST = "https://ci.ignite.apache.org/";
+
     /** TC server name. */
-    @Nonnull String name;
+    @Nonnull private String code;
 
     /** Name of server this config points to. This config is just an alias for TC Server. */
-    @Nullable String reference;
+    @Nullable
+    private String reference;
 
     @Nullable private Properties props;
+
     /** Host. */
     @Nullable private String host;
 
@@ -41,13 +45,13 @@ public class TcServerConfig implements ITcServerConfig {
 
     }
 
-    public TcServerConfig(String name, Properties properties) {
-        this.name = name;
+    public TcServerConfig(String code, Properties properties) {
+        this.code = code;
         this.props = properties;
     }
 
-    public String getName() {
-        return name;
+    public String getCode() {
+        return code;
     }
 
     /** {@inheritDoc} */
@@ -74,9 +78,13 @@ public class TcServerConfig implements ITcServerConfig {
      * Configured value for host.
      */
     @NotNull
-    public String hostConfigured() {
-        if (Strings.isNullOrEmpty(host))
-            return props.getProperty(HelperConfig.HOST, "https://ci.ignite.apache.org/");
+    private String hostConfigured() {
+        if (Strings.isNullOrEmpty(host)) {
+            if (props != null)
+                return props.getProperty(HelperConfig.HOST, DEFAULT_HOST);
+        } else {
+            return DEFAULT_HOST;
+        }
 
         return host;
     }
@@ -87,4 +95,8 @@ public class TcServerConfig implements ITcServerConfig {
     public void properties(Properties props) {
         this.props = props;
     }
+
+    public void code(String srvCode) {
+        this.code = srvCode;
+    }
 }
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/Login.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/Login.java
index 58aab62..f508aeb 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/Login.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/Login.java
@@ -58,7 +58,7 @@ public class Login {
         Injector injector = CtxListener.getInjector(ctx);
 
         ITcBotConfig tcBotCfg = injector.getInstance(ITcBotConfig.class);
-        String srvId = tcBotCfg.primaryServerId();
+        String srvId = tcBotCfg.primaryServerCode();
         String host = injector.getInstance(ITeamcityIgnitedProvider.class).server(srvId, null).host();
         return new ServerDataResponse(host);
     }
@@ -76,10 +76,10 @@ public class Login {
         final ITcLogin tcLogin = injector.getInstance(ITcLogin.class);
         IUserStorage users = injector.getInstance(IUserStorage.class);
 
-        String primarySrvId = cfg.primaryServerId();
+        String primarySrvCode = cfg.primaryServerCode();
 
         try {
-            return doLogin(username, pwd, users, primarySrvId, cfg.getServerIds(), tcLogin);
+            return doLogin(username, pwd, users, primarySrvCode, cfg.getServerIds(), tcLogin);
         } catch (Exception e) {
             e.printStackTrace();
             throw e;
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/tracked/GetTrackedBranchTestResults.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/tracked/GetTrackedBranchTestResults.java
index de1d0a8..5f12530 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/tracked/GetTrackedBranchTestResults.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/tracked/GetTrackedBranchTestResults.java
@@ -42,7 +42,7 @@ import org.apache.ignite.internal.util.typedef.F;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import static org.apache.ignite.ci.tcbot.conf.ITcBotConfig.DEFAULT_SERVER_ID;
+import static org.apache.ignite.ci.tcbot.conf.ITcBotConfig.DEFAULT_SERVER_CODE;
 import static org.apache.ignite.ci.teamcity.ignited.TeamcityIgnitedImpl.DEFAULT_PROJECT_ID;
 
 @Path(GetTrackedBranchTestResults.TRACKED)
@@ -156,7 +156,7 @@ public class GetTrackedBranchTestResults {
         ITcBotConfig cfg = CtxListener.getInjector(ctx).getInstance(ITcBotConfig.class);
 
         if (F.isEmpty(srvId))
-            srvId = DEFAULT_SERVER_ID;
+            srvId = DEFAULT_SERVER_CODE;
 
         if (F.isEmpty(projectId))
             projectId = DEFAULT_PROJECT_ID;
diff --git a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java
index 8f63ce4..a79c249 100644
--- a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java
+++ b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/MockBasedTcBotModule.java
@@ -17,11 +17,10 @@
 
 package org.apache.ignite.ci.tcbot.chain;
 
-import com.google.common.base.Preconditions;
 import com.google.inject.AbstractModule;
 import com.google.inject.internal.SingletonScope;
 import java.io.File;
-import java.util.Properties;
+
 import org.apache.ignite.ci.HelperConfig;
 import org.apache.ignite.ci.IAnalyticsEnabledTeamcity;
 import org.apache.ignite.ci.conf.BranchesTracked;
@@ -105,8 +104,8 @@ public class MockBasedTcBotModule extends AbstractModule {
         bind(ITcServerProvider.class).toInstance(tcSrvOldProv);
 
         bind(ITcBotConfig.class).toInstance(new ITcBotConfig() {
-            @Override public String primaryServerId() {
-                return ITcBotConfig.DEFAULT_SERVER_ID;
+            @Override public String primaryServerCode() {
+                return ITcBotConfig.DEFAULT_SERVER_CODE;
             }
 
             @Override public BranchesTracked getTrackedBranches() {
@@ -114,20 +113,20 @@ public class MockBasedTcBotModule extends AbstractModule {
             }
 
             /** {@inheritDoc} */
-            @Override public ITcServerConfig getTeamcityConfig(String srvName) {
+            @Override public ITcServerConfig getTeamcityConfig(String srvCode) {
                 File workDir = HelperConfig.resolveWorkDir();
 
-                String cfgName = HelperConfig.prepareConfigName(srvName);
+                String cfgName = HelperConfig.prepareConfigName(srvCode);
 
-                return new TcServerConfig(srvName, HelperConfig.loadAuthProperties(workDir, cfgName));
+                return new TcServerConfig(srvCode, HelperConfig.loadAuthProperties(workDir, cfgName));
             }
 
-            @Override public IJiraServerConfig getJiraConfig(String srvName) {
+            @Override public IJiraServerConfig getJiraConfig(String srvCode) {
                 File workDir = HelperConfig.resolveWorkDir();
 
-                String cfgName = HelperConfig.prepareConfigName(srvName);
+                String cfgName = HelperConfig.prepareConfigName(srvCode);
 
-                return new JiraServerConfig(srvName, HelperConfig.loadAuthProperties(workDir, cfgName));
+                return new JiraServerConfig(srvCode, HelperConfig.loadAuthProperties(workDir, cfgName));
             }
         });