From 09a2b343410bbf8f562dfe21fe8a33d5e821cbaa Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Wed, 8 Dec 2021 18:00:54 +0300 Subject: [PATCH 1/9] IGNITE-16086: skeleton for configurable branches --- .../apache/ignite/ci/jobs/CheckQueueJob.java | 9 ++-- .../ignite/ci/tcbot/TcBotWebAppModule.java | 5 ++ .../MixedFilesAndDbTrackedBranchesConfig.java | 48 +++++++++++++++++++ .../engine/conf/BranchTrackedPersisted.java | 18 +++++++ .../engine/conf/ChainAtServerTracked.java | 19 ++++++++ 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java create mode 100644 tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java 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 d5c1d4996..df454a6e0 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 @@ -40,10 +40,7 @@ import org.apache.ignite.tcbot.common.exeption.ExceptionUtil; import org.apache.ignite.tcbot.common.interceptor.AutoProfiling; import org.apache.ignite.tcbot.common.interceptor.MonitoredTask; -import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; -import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; -import org.apache.ignite.tcbot.engine.conf.ITrackedChain; -import org.apache.ignite.tcbot.engine.conf.NotificationsConfig; +import org.apache.ignite.tcbot.engine.conf.*; import org.apache.ignite.tcbot.notify.ISlackSender; import org.apache.ignite.tcbot.persistence.IStringCompactor; import org.apache.ignite.tcignited.ITeamcityIgnited; @@ -92,6 +89,8 @@ public class CheckQueueJob implements Runnable { /** */ @Inject private ITcBotConfig cfg; + @Inject private ITrackedBranchesConfig trackedBranchesConfig; + /** */ @Inject private ISlackSender slackSender; @@ -146,7 +145,7 @@ protected String runEx() { return msg; } - Stream tracked = cfg.getTrackedBranches().branchesStream(); + Stream tracked = trackedBranchesConfig.branchesStream(); int srvsChecked = 0, chainsChecked = 0; diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java index 29ef04bda..833d51266 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java @@ -29,6 +29,7 @@ import org.apache.ignite.ci.observer.BuildObserver; import org.apache.ignite.ci.observer.ObserverTask; import org.apache.ignite.ci.tcbot.conf.LocalFilesBasedConfig; +import org.apache.ignite.ci.tcbot.conf.MixedFilesAndDbTrackedBranchesConfig; import org.apache.ignite.ci.tcbot.issue.IssueDetector; import org.apache.ignite.ci.tcbot.trends.MasterTrendsService; import org.apache.ignite.ci.web.model.hist.VisasHistoryStorage; @@ -40,6 +41,7 @@ import org.apache.ignite.tcbot.engine.TcBotEngineModule; import org.apache.ignite.tcbot.engine.cleaner.Cleaner; import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.pool.TcUpdatePool; import org.apache.ignite.tcbot.notify.TcBotNotificationsModule; import org.apache.ignite.tcbot.persistence.TcBotPersistenceModule; @@ -93,6 +95,9 @@ public class TcBotWebAppModule extends AbstractModule { bind(ITcBotConfig.class).to(LocalFilesBasedConfig.class).in(new SingletonScope()); //todo remove duplication of instances for base and for overriden class bind(IDataSourcesConfigSupplier.class).to(LocalFilesBasedConfig.class).in(new SingletonScope()); + bind(ITrackedBranchesConfig.class).to(MixedFilesAndDbTrackedBranchesConfig.class).in(new SingletonScope()); + bind(LocalFilesBasedConfig.class).in(new SingletonScope()); + bind(MasterTrendsService.class).in(new SingletonScope()); bind(ITcBotBgAuth.class).to(TcBotBgAuthImpl.class).in(new SingletonScope()); } diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java new file mode 100644 index 000000000..30687dd80 --- /dev/null +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java @@ -0,0 +1,48 @@ +package org.apache.ignite.ci.tcbot.conf; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.tcbot.engine.conf.BranchTrackedPersisted; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; +import org.apache.ignite.tcbot.persistence.CacheConfigs; + +import javax.inject.Inject; +import javax.inject.Provider; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public class MixedFilesAndDbTrackedBranchesConfig implements ITrackedBranchesConfig { + public static final String TRACKED_BRANCHES = "trackedBranches"; + @Inject + private LocalFilesBasedConfig filesBasedCfg; + + /** Ignite provider. */ + @Inject private Provider igniteProvider; + + + + + @Override + public Stream branchesStream() { + + Stream fileBasedBranches = filesBasedCfg.getTrackedBranches().branchesStream(); + + IgniteCache cache = igniteProvider.get().getOrCreateCache(CacheConfigs.getCacheV2Config(TRACKED_BRANCHES)); + + Map res = new HashMap<>(); + fileBasedBranches.map(b -> BranchTrackedPersisted.initFrom(b)).forEach(btp -> { + res.put(btp.name(), btp); + }); + + + return res.values().stream().map(v -> v); + } + + @Override + public Collection getServerIds() { + return filesBasedCfg.getTrackedBranches().getServerIds(); + } +} diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java new file mode 100644 index 000000000..1580c534a --- /dev/null +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java @@ -0,0 +1,18 @@ +package org.apache.ignite.tcbot.engine.conf; + +import javax.annotation.Nullable; + +public class BranchTrackedPersisted extends BranchTracked { + @Nullable Boolean softDeleted; + + public static BranchTrackedPersisted initFrom(ITrackedBranch b) { + BranchTrackedPersisted bp = new BranchTrackedPersisted(); + + b.chainsStream().map(ChainAtServerTracked::initFrom).forEach(ct -> { + bp.chains.add(ct); + }); + + return bp; + } + +} diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java index c77b77fef..a5ee57bd0 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java @@ -51,6 +51,25 @@ public class ChainAtServerTracked extends ChainAtServer implements ITrackedChain /** Build parameters for Triggering. */ @Nullable private List triggerParameters; + static ChainAtServerTracked initFrom(ITrackedChain c) { + ChainAtServerTracked ct = new ChainAtServerTracked(); + ct.serverId = c.serverCode(); + ct.branchForRest = c.tcBranch(); + ct.baseBranchForTc = c.tcBaseBranch().orElse(null); + ct.suiteId = c.tcSuiteId(); + + + //@Nullable private Boolean triggerBuild; + //@Nullable private Integer triggerBuildQuietPeriod; + //@Nullable private List triggerParameters; + ct.triggerBuild= c.triggerBuild(); + ct.triggerBuildQuietPeriod = c.triggerBuildQuietPeriod(); + + //todo support copying trigger parms: ct.triggerParameters = c.generateBuildParameters();//todo + + return ct; + } + /** @return {@link #suiteId} */ @Nonnull public String getSuiteIdMandatory() { checkState(!isNullOrEmpty(suiteId), "Invalid config: suiteId should be filled " + this); From 6b2d39ff0811aeaf89f83a51cdd57b2832ee93a2 Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Wed, 8 Dec 2021 18:57:38 +0300 Subject: [PATCH 2/9] IGNITE-16086: skeleton for configurable branches --- .../tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java | 4 ++-- .../org/apache/ignite/ci/tcbot/issue/IssueDetector.java | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java index 30687dd80..7ddb06ff7 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java @@ -28,7 +28,7 @@ public class MixedFilesAndDbTrackedBranchesConfig implements ITrackedBranchesCon @Override public Stream branchesStream() { - Stream fileBasedBranches = filesBasedCfg.getTrackedBranches().branchesStream(); + Stream fileBasedBranches = filesBasedCfg.getConfig().branchesStream(); IgniteCache cache = igniteProvider.get().getOrCreateCache(CacheConfigs.getCacheV2Config(TRACKED_BRANCHES)); @@ -43,6 +43,6 @@ public Stream branchesStream() { @Override public Collection getServerIds() { - return filesBasedCfg.getTrackedBranches().getServerIds(); + return filesBasedCfg.getConfig().getServerIds(); } } diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java index 19b0c26f3..1df6e0a1e 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java @@ -37,6 +37,7 @@ import org.apache.ignite.ci.issue.Issue; import org.apache.ignite.ci.issue.IssueKey; import org.apache.ignite.ci.teamcity.ignited.runhist.Invocation; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.issue.IIssuesStorage; import org.apache.ignite.tcbot.engine.issue.IssueType; import org.apache.ignite.ci.jobs.CheckQueueJob; @@ -107,6 +108,10 @@ public class IssueDetector { /** Config. */ @Inject private ITcBotConfig cfg; + + /** Config. */ + @Inject private ITrackedBranchesConfig trackedBranchesConfig; + /** Email sender. */ @Inject private IEmailSender emailSender; @@ -198,7 +203,7 @@ protected String sendNewNotificationsEx() { }) .peek(issue -> filteredBuildTs.incrementAndGet()) .filter(issue -> { - return cfg.getTrackedBranches() + return trackedBranchesConfig .get(issue.trackedBranchName) .filter(tb -> !tb.disableIssueTypes().contains(issue.type())) .isPresent(); From 2f7c3d05b933d3e6129d63fec306f7c0c474cf95 Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Wed, 8 Dec 2021 19:42:36 +0300 Subject: [PATCH 3/9] IGNITE-16086 Removal of tracked branch server code specification (only branch.json) is now source of codes. --- .../ignite/ci/tcbot/TcBotWebAppModule.java | 4 +-- .../ci/tcbot/conf/LocalFilesBasedConfig.java | 16 +++++++--- .../MixedFilesAndDbTrackedBranchesConfig.java | 22 +++++++------ .../ignite/ci/tcbot/issue/IssueDetector.java | 7 ++--- .../visa/TcBotTriggerAndSignOffService.java | 6 ++-- .../ci/web/rest/GetTrackedBranches.java | 14 ++++----- .../ignite/ci/web/rest/login/Login.java | 10 +++--- .../ignite/ci/web/rest/login/UserService.java | 5 +-- .../tracked/GetTrackedBranchTestResults.java | 5 +-- .../ci/tcbot/chain/MockBasedTcBotModule.java | 9 ++++-- .../IgnitedTcInMemoryIntegrationTest.java | 1 - .../conf/IDataSourcesConfigSupplier.java | 3 +- .../tcbot/common/conf/ITcServerConfig.java | 1 + .../common/conf/ITcServerConfigSupplier.java | 13 ++++++++ .../engine/buildtime/BuildTimeService.java | 12 +++---- .../ignite/tcbot/engine/cleaner/Cleaner.java | 2 +- .../tcbot/engine/conf/BranchTracked.java | 10 +----- .../engine/conf/BranchTrackedPersisted.java | 17 +++++++--- .../tcbot/engine/conf/ChainAtServer.java | 2 +- .../engine/conf/ChainAtServerTracked.java | 31 ++----------------- .../tcbot/engine/conf/ITcBotConfig.java | 18 ----------- .../engine/conf/ITrackedBranchesConfig.java | 6 +--- .../tcbot/engine/conf/TcBotJsonConfig.java | 21 ++++++------- .../tcbot/engine/conf/TcServerConfig.java | 2 +- .../tcbot/engine/pr/PrChainsProcessor.java | 5 ++- .../tracked/TrackedBranchChainsProcessor.java | 14 ++++----- 26 files changed, 119 insertions(+), 137 deletions(-) create mode 100644 tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java index 833d51266..940609456 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java @@ -92,11 +92,11 @@ public class TcBotWebAppModule extends AbstractModule { // common services install(new TcBotEngineModule()); + + bind(LocalFilesBasedConfig.class).in(new SingletonScope()); bind(ITcBotConfig.class).to(LocalFilesBasedConfig.class).in(new SingletonScope()); - //todo remove duplication of instances for base and for overriden class bind(IDataSourcesConfigSupplier.class).to(LocalFilesBasedConfig.class).in(new SingletonScope()); bind(ITrackedBranchesConfig.class).to(MixedFilesAndDbTrackedBranchesConfig.class).in(new SingletonScope()); - bind(LocalFilesBasedConfig.class).in(new SingletonScope()); bind(MasterTrendsService.class).in(new SingletonScope()); bind(ITcBotBgAuth.class).to(TcBotBgAuthImpl.class).in(new SingletonScope()); 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 d6ff6ec1c..7b5e212be 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 @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.Collection; import java.util.Objects; import java.util.Properties; @@ -46,6 +47,11 @@ * */ public class LocalFilesBasedConfig implements ITcBotConfig { + + public LocalFilesBasedConfig() { + System.out.println("LocalFilesBasedConfig"); + } + private static TcBotJsonConfig reloadConfig() { final File workDir = TcBotWorkDir.resolveWorkDir(); final File file = new File(workDir, "branches.json"); @@ -64,6 +70,11 @@ protected TcBotJsonConfig getConfig() { return reloadConfig(); } + @Override + public Collection getConfiguredServerIds() { + return getConfig().getConfiguredServerIds(); + } + /** {@inheritDoc} */ @Override public ITcServerConfig getTeamcityConfig(String srvCode) { return getConfig().getTcConfig(srvCode) @@ -130,11 +141,6 @@ protected TcBotJsonConfig getConfig() { return confidence == null || confidence < 0 || confidence > 1 ? ITcBotConfig.DEFAULT_CONFIDENCE : confidence; } - @Override - public ITrackedBranchesConfig getTrackedBranches() { - return getConfig(); - } - @GuavaCached(softValues = true, expireAfterWriteSecs = 3 * 60) protected Properties loadOldAuthProps(String srvCode) { File workDir = TcBotWorkDir.resolveWorkDir(); diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java index 7ddb06ff7..38fc08f33 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java @@ -2,6 +2,7 @@ import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; +import org.apache.ignite.tcbot.common.interceptor.GuavaCached; import org.apache.ignite.tcbot.engine.conf.BranchTrackedPersisted; import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; @@ -23,26 +24,27 @@ public class MixedFilesAndDbTrackedBranchesConfig implements ITrackedBranchesCon @Inject private Provider igniteProvider; - - @Override public Stream branchesStream() { - + //todo internal cached version, + // @GuavaCached(softValues = true, expireAfterWriteSecs = 3 * 60) Stream fileBasedBranches = filesBasedCfg.getConfig().branchesStream(); - IgniteCache cache = igniteProvider.get().getOrCreateCache(CacheConfigs.getCacheV2Config(TRACKED_BRANCHES)); + IgniteCache cache = igniteProvider.get().getOrCreateCache(CacheConfigs.getCache8PartsConfig(TRACKED_BRANCHES)); Map res = new HashMap<>(); - fileBasedBranches.map(b -> BranchTrackedPersisted.initFrom(b)).forEach(btp -> { + fileBasedBranches.map(BranchTrackedPersisted::initFrom).forEach(btp -> { res.put(btp.name(), btp); }); + Map dbValues = new HashMap<>(); + cache.forEach((entry) -> { + String key = entry.getKey(); + dbValues.put(key, entry.getValue()); + }); - return res.values().stream().map(v -> v); - } + res.putAll(dbValues); // override config all values by values from DB, enforcing soft del as a priority - @Override - public Collection getServerIds() { - return filesBasedCfg.getConfig().getServerIds(); + return res.values().stream().filter(BranchTrackedPersisted::isAlive).map(v -> v); } } diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java index 1df6e0a1e..0b8e5c76e 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/issue/IssueDetector.java @@ -108,8 +108,6 @@ public class IssueDetector { /** Config. */ @Inject private ITcBotConfig cfg; - - /** Config. */ @Inject private ITrackedBranchesConfig trackedBranchesConfig; /** Email sender. */ @@ -203,8 +201,7 @@ protected String sendNewNotificationsEx() { }) .peek(issue -> filteredBuildTs.incrementAndGet()) .filter(issue -> { - return trackedBranchesConfig - .get(issue.trackedBranchName) + return trackedBranchesConfig.get(issue.trackedBranchName) .filter(tb -> !tb.disableIssueTypes().contains(issue.type())) .isPresent(); }) @@ -599,7 +596,7 @@ public void startBackgroundCheck(ITcBotUserCreds prov) { * */ private void checkFailures() { - cfg.getTrackedBranches().branchesStream().forEach(tb -> { + trackedBranchesConfig.branchesStream().forEach(tb -> { try { checkFailuresEx(tb.name()); } catch (Exception e) { 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 ff4f5e816..c804c001c 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 @@ -66,6 +66,7 @@ import org.apache.ignite.tcbot.common.conf.IJiraServerConfig; import org.apache.ignite.tcbot.common.conf.ITcServerConfig; import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.pr.BranchTicketMatcher; import org.apache.ignite.tcbot.engine.pr.PrChainsProcessor; import org.apache.ignite.tcbot.engine.ui.ShortSuiteUi; @@ -134,6 +135,8 @@ public class TcBotTriggerAndSignOffService { /** Config. */ @Inject ITcBotConfig cfg; + @Inject ITrackedBranchesConfig trackedBranchesConfig; + @Inject BranchTicketMatcher ticketMatcher; @@ -686,8 +689,7 @@ private String findDefaultBuildType(String srvIdOrAlias) { String realTcId = Strings.isNullOrEmpty(tcCfg.reference()) ? srvIdOrAlias : tcCfg.reference(); - cfg.getTrackedBranches() - .get(trBranch) + trackedBranchesConfig.get(trBranch) .ifPresent( b -> b.chainsStream() .filter(c -> Objects.equals(realTcId, c.serverCode())) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java index cdb687f5c..65ab6de5b 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java @@ -34,9 +34,9 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import org.apache.ignite.tcbot.common.conf.ITcServerConfigSupplier; import org.apache.ignite.tcbot.engine.conf.ChainAtServer; import org.apache.ignite.ci.tcbot.TcBotGeneralService; -import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.conf.ITrackedChain; @@ -80,10 +80,10 @@ public List getIdsIfAccessible() { @NotNull public Stream accessibleTrackedBranches() { ITcBotUserCreds prov = ITcBotUserCreds.get(req); Injector injector = CtxListener.getInjector(ctx); - ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class); + ITrackedBranchesConfig trackedBranchesConfig = injector.getInstance(ITrackedBranchesConfig.class); ITeamcityIgnitedProvider tcProv = injector.getInstance(ITeamcityIgnitedProvider.class); - return cfg.getTrackedBranches().branchesStream() + return trackedBranchesConfig.branchesStream() .filter(bt -> bt.chainsStream().anyMatch(chain -> tcProv.hasAccess(chain.serverCode(), prov))); } @@ -109,10 +109,10 @@ public Set getSuitesUnique(ITrackedBranchesConfig trackedBranches public Set getSuites(@Nullable @QueryParam("server") String srvId) { ITcBotUserCreds prov = ITcBotUserCreds.get(req); Injector injector = CtxListener.getInjector(ctx); - ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class); + ITrackedBranchesConfig trackedBranchesConfig = injector.getInstance(ITrackedBranchesConfig.class); ITeamcityIgnitedProvider tcProv = injector.getInstance(ITeamcityIgnitedProvider.class); - return getSuitesUnique(cfg.getTrackedBranches()) + return getSuitesUnique(trackedBranchesConfig) .stream() .filter(chainAtSrv -> Strings.isNullOrEmpty(srvId) @@ -129,10 +129,10 @@ public Set getSuites(@Nullable @QueryParam("server") String srvId public Set getServerIds() { ITcBotUserCreds prov = ITcBotUserCreds.get(req); Injector injector = CtxListener.getInjector(ctx); - ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class); + ITcServerConfigSupplier tcServerConfigSupplier = injector.getInstance(ITcServerConfigSupplier.class); ITeamcityIgnitedProvider tcProv = injector.getInstance(ITeamcityIgnitedProvider.class); - return cfg.getServerIds() + return tcServerConfigSupplier.getConfiguredServerIds() .stream() .filter(srvId -> tcProv.hasAccess(srvId, prov)) .collect(Collectors.toSet()); 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 8a238278b..e3b420bb3 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 @@ -19,6 +19,7 @@ import com.google.common.base.Preconditions; import com.google.inject.Injector; +import org.apache.ignite.tcbot.common.conf.ITcServerConfigSupplier; import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; import org.apache.ignite.tcbot.engine.user.IUserStorage; import org.apache.ignite.tcservice.model.user.User; @@ -72,14 +73,15 @@ public LoginResponse login(@FormParam("uname") String username, Preconditions.checkNotNull(pwd); final Injector injector = CtxListener.getInjector(ctx); - ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class); + final ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class); final ITcLogin tcLogin = injector.getInstance(ITcLogin.class); - IUserStorage users = injector.getInstance(IUserStorage.class); + final IUserStorage users = injector.getInstance(IUserStorage.class); + final ITcServerConfigSupplier tcConfigSupplier = injector.getInstance(ITcServerConfigSupplier.class); String primarySrvCode = cfg.primaryServerCode(); try { - return doLogin(username, pwd, users, primarySrvCode, cfg.getServerIds(), tcLogin); + return doLogin(username, pwd, users, primarySrvCode, tcConfigSupplier.getConfiguredServerIds(), tcLogin); } catch (Exception e) { e.printStackTrace(); throw e; @@ -88,7 +90,7 @@ public LoginResponse login(@FormParam("uname") String username, public LoginResponse doLogin(@FormParam("uname") String username, @FormParam("psw") String pwd, - IUserStorage users, + IUserStorage users, String primarySrvId, Collection srvIds, ITcLogin tcLogin) { diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/UserService.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/UserService.java index b6864149c..7912b5d59 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/UserService.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/login/UserService.java @@ -35,6 +35,7 @@ import org.apache.ignite.tcbot.engine.cleaner.Cleaner; import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; import org.apache.ignite.ci.tcbot.issue.IssueDetector; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.user.IUserStorage; import org.apache.ignite.ci.tcbot.visa.TcBotTriggerAndSignOffService; import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; @@ -120,14 +121,14 @@ public TcHelperUserUi getUserData(@Nullable @QueryParam("login") final String lo final String currUserLogin = ITcBotUserCreds.get(req).getPrincipalId(); final String login = Strings.isNullOrEmpty(loginParm) ? currUserLogin : loginParm; Injector injector = CtxListener.getInjector(ctx); - ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class); + ITrackedBranchesConfig trackedBranchesConfig = injector.getInstance(ITrackedBranchesConfig.class); IUserStorage users = injector.getInstance(IUserStorage.class); final TcHelperUser user = users.getUser(login); //todo can filter accessibliity final TcHelperUserUi tcHelperUserUi = new TcHelperUserUi(user, - cfg.getTrackedBranches().branchesStream() + trackedBranchesConfig.branchesStream() .map(ITrackedBranch::name) .collect(Collectors.toList()) ); 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 f5cd3a450..b11a4c57b 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 @@ -38,6 +38,7 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.tcbot.engine.chain.SortOption; import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.tracked.DisplayMode; import org.apache.ignite.tcbot.engine.tracked.IDetailedStatusForTrackedBranch; import org.apache.ignite.tcbot.engine.tracked.TrackedBranchChainsProcessor; @@ -245,10 +246,10 @@ public Set mutes( public List getIdsIfAccessible() { ITcBotUserCreds prov = ITcBotUserCreds.get(req); Injector injector = CtxListener.getInjector(ctx); - ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class); + ITrackedBranchesConfig trackedBranchesConfig = injector.getInstance(ITrackedBranchesConfig.class); IDetailedStatusForTrackedBranch status = injector.getInstance(IDetailedStatusForTrackedBranch.class); - return cfg.getTrackedBranches().branchesStream() + return trackedBranchesConfig.branchesStream() .map(bt -> status.getBranchSummary(bt.name(), prov)).filter(Objects::nonNull) .collect(Collectors.toList()); } 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 7f778bb70..8d1a6478a 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,6 +17,7 @@ package org.apache.ignite.ci.tcbot.chain; +import com.google.common.collect.Sets; import com.google.inject.AbstractModule; import com.google.inject.internal.SingletonScope; import org.apache.ignite.Ignite; @@ -52,6 +53,8 @@ import org.apache.ignite.tcignited.buildlog.IBuildLogProcessor; import org.mockito.Mockito; +import java.util.Collection; + import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -102,8 +105,9 @@ public MockBasedTcBotModule() { return DEFAULT_CONFIDENCE; } - @Override public ITrackedBranchesConfig getTrackedBranches() { - return tracked; + @Override + public Collection getConfiguredServerIds() { + return Sets.newHashSet(DEFAULT_SERVER_CODE); } /** {@inheritDoc} */ @@ -128,6 +132,7 @@ public MockBasedTcBotModule() { } }; bind(ITcBotConfig.class).toInstance(cfg); + bind(ITrackedBranchesConfig.class).toInstance(tracked); bind(IDataSourcesConfigSupplier.class).toInstance(cfg); bind(IIssuesStorage.class).toInstance(Mockito.mock(IIssuesStorage.class)); diff --git a/ignite-tc-helper-web/src/test/java/org/apache/ignite/tcignited/IgnitedTcInMemoryIntegrationTest.java b/ignite-tc-helper-web/src/test/java/org/apache/ignite/tcignited/IgnitedTcInMemoryIntegrationTest.java index 875627cc9..bcb75d88a 100644 --- a/ignite-tc-helper-web/src/test/java/org/apache/ignite/tcignited/IgnitedTcInMemoryIntegrationTest.java +++ b/ignite-tc-helper-web/src/test/java/org/apache/ignite/tcignited/IgnitedTcInMemoryIntegrationTest.java @@ -915,7 +915,6 @@ private static class IgniteAndSchedulerTestModule extends AbstractModule { when(tcCfg.host()).thenReturn("http://ci.ignite.apache.org/"); when(tcCfg.trustedSuites()).thenReturn(new ArrayList<>()); when(cfg.getTeamcityConfig(anyString())).thenReturn(tcCfg); - when(cfg.getTrackedBranches()).thenReturn(new TcBotJsonConfig()); bind(ITcBotConfig.class).toInstance(cfg); bind(IDataSourcesConfigSupplier.class).toInstance(cfg); diff --git a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IDataSourcesConfigSupplier.java b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IDataSourcesConfigSupplier.java index 68873ad65..99966bbfe 100644 --- a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IDataSourcesConfigSupplier.java +++ b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IDataSourcesConfigSupplier.java @@ -20,8 +20,7 @@ /** * 3rd party data sources (services/servers) configurations. */ -public interface IDataSourcesConfigSupplier { - public ITcServerConfig getTeamcityConfig(String srvCode); +public interface IDataSourcesConfigSupplier extends ITcServerConfigSupplier { public IGitHubConfig getGitConfig(String srvCode); diff --git a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java index d35f33cc1..5e813b98b 100644 --- a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java +++ b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfig.java @@ -53,6 +53,7 @@ public interface ITcServerConfig { @NonNull public String logsDirectory(); /** + * TC Bot's identification tracked branch name to be used for this server for PRs check. * @return internal naming of default tracked branch for this server. */ @NonNull public String defaultTrackedBranch(); diff --git a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java new file mode 100644 index 000000000..d50486107 --- /dev/null +++ b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java @@ -0,0 +1,13 @@ +package org.apache.ignite.tcbot.common.conf; + +import java.util.Collection; + +public interface ITcServerConfigSupplier { + /** + * @return all configured server identifiers, without relation to current user access. + */ + public Collection getConfiguredServerIds(); + + public ITcServerConfig getTeamcityConfig(String srvCode); + +} diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/buildtime/BuildTimeService.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/buildtime/BuildTimeService.java index 86c1dfd98..49b1ab632 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/buildtime/BuildTimeService.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/buildtime/BuildTimeService.java @@ -17,9 +17,9 @@ package org.apache.ignite.tcbot.engine.buildtime; +import org.apache.ignite.tcbot.common.conf.ITcServerConfigSupplier; import org.apache.ignite.tcbot.common.interceptor.MonitoredTask; import org.apache.ignite.tcbot.common.util.TimeUtil; -import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; import org.apache.ignite.tcbot.engine.ui.BuildTimeRecordUi; import org.apache.ignite.tcbot.engine.ui.BuildTimeResultUi; import org.apache.ignite.tcbot.persistence.IStringCompactor; @@ -46,7 +46,7 @@ */ public class BuildTimeService { /** Config. */ - @Inject private ITcBotConfig cfg; + @Inject private ITcServerConfigSupplier tcServerConfigSupplier; @Inject private FatBuildDao fatBuildDao; @@ -64,7 +64,7 @@ public BuildTimeResultUi analytics(ICredentialsProv prov) { if (buildRefDao.buildRefsCache() == null) return new BuildTimeResultUi(); - Collection allSrvs = cfg.getServerIds(); + Collection allSrvs = tcServerConfigSupplier.getConfiguredServerIds(); scheduler.sheduleNamed("BuildTimeService.loadAnalytics", this::loadAnalytics, 15, TimeUnit.MINUTES); @@ -111,10 +111,8 @@ public BuildTimeRecordUi convertToUi(Map.Entry e) { protected void loadAnalytics() { int days = 1; - List idsToCheck = historyCollector.findAllRecentBuilds(days, cfg.getServerIds()); + List idsToCheck = historyCollector.findAllRecentBuilds(days, tcServerConfigSupplier.getConfiguredServerIds()); - BuildTimeResult res = fatBuildDao.loadBuildTimeResult(days, idsToCheck); - - lastRes1d = res; + lastRes1d = fatBuildDao.loadBuildTimeResult(days, idsToCheck); } } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/cleaner/Cleaner.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/cleaner/Cleaner.java index 387293c9c..4a2682505 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/cleaner/Cleaner.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/cleaner/Cleaner.java @@ -142,7 +142,7 @@ private void removeLogFiles(ZonedDateTime thresholdDate, int numOfItemsToDel) { final File workDir = TcBotWorkDir.resolveWorkDir(); - for (String srvId : cfg.getServerIds()) { + for (String srvId : cfg.getConfiguredServerIds()) { File srvIdLogDir = new File(workDir, cfg.getTeamcityConfig(srvId).logsDirectory()); removeFiles(srvIdLogDir, thresholdEpochMilli, numOfItemsToDel); diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTracked.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTracked.java index 67a8dd7f2..00f21f1c9 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTracked.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTracked.java @@ -31,12 +31,10 @@ public class BranchTracked implements ITrackedBranch { /** ID for internal REST and for config file. */ public String id; - /** */ public List chains = new ArrayList<>(); /** Disable notifications for the following issue types. See IssueType#code() */ - @Nullable private List disableIssueTypes = new ArrayList<>(); - + @Nullable protected List disableIssueTypes = new ArrayList<>(); /** * @return internal identifier of the branch. @@ -45,12 +43,6 @@ public String name() { return id; } - /** */ - public List getChains() { - return Collections.unmodifiableList(chains); - } - - /** */ public Stream chainsStream() { return chains.stream().map(t->t); } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java index 1580c534a..0496ba6af 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java @@ -3,16 +3,25 @@ import javax.annotation.Nullable; public class BranchTrackedPersisted extends BranchTracked { - @Nullable Boolean softDeleted; + @Nullable protected Boolean softDeleted; public static BranchTrackedPersisted initFrom(ITrackedBranch b) { BranchTrackedPersisted bp = new BranchTrackedPersisted(); - b.chainsStream().map(ChainAtServerTracked::initFrom).forEach(ct -> { - bp.chains.add(ct); - }); + b.chainsStream().map(ChainAtServerTracked::initFrom).forEach(bp.chains::add); + + bp.disableIssueTypes = b.disableIssueTypes(); + bp.softDeleted = false; return bp; } + public boolean isDeleted() { + return softDeleted != null && softDeleted; + } + + public boolean isAlive() { + return !isDeleted(); + } + } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServer.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServer.java index 99944738e..4114901a9 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServer.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServer.java @@ -22,7 +22,7 @@ import javax.annotation.Nullable; /** - * Pair of serverId and suiteId. + * Pair of serverId and suiteId. Identifies build configuration at TC. */ @SuppressWarnings("PublicField") public class ChainAtServer { diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java index a5ee57bd0..c7087f1f0 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java @@ -54,15 +54,12 @@ public class ChainAtServerTracked extends ChainAtServer implements ITrackedChain static ChainAtServerTracked initFrom(ITrackedChain c) { ChainAtServerTracked ct = new ChainAtServerTracked(); ct.serverId = c.serverCode(); - ct.branchForRest = c.tcBranch(); - ct.baseBranchForTc = c.tcBaseBranch().orElse(null); ct.suiteId = c.tcSuiteId(); + ct.branchForRest = c.tcBranch(); + ct.baseBranchForTc = c.tcBaseBranch().orElse(null); + ct.triggerBuild = c.triggerBuild(); - //@Nullable private Boolean triggerBuild; - //@Nullable private Integer triggerBuildQuietPeriod; - //@Nullable private List triggerParameters; - ct.triggerBuild= c.triggerBuild(); ct.triggerBuildQuietPeriod = c.triggerBuildQuietPeriod(); //todo support copying trigger parms: ct.triggerParameters = c.generateBuildParameters();//todo @@ -70,21 +67,6 @@ static ChainAtServerTracked initFrom(ITrackedChain c) { return ct; } - /** @return {@link #suiteId} */ - @Nonnull public String getSuiteIdMandatory() { - checkState(!isNullOrEmpty(suiteId), "Invalid config: suiteId should be filled " + this); - return suiteId; - } - - /** - * @return branch in TC indentification to queue build results. - */ - @Nonnull public String getBranchForRestMandatory() { - checkState(!isNullOrEmpty(branchForRest), "Invalid config: branchForRest should be filled " + this); - - return branchForRest; - } - /** * @return base (etalon) branch in TC identification t builds */ @@ -153,13 +135,6 @@ static ChainAtServerTracked initFrom(ITrackedChain c) { return values; } - public Stream buildParametersKeys() { - if (triggerParameters == null || triggerParameters.isEmpty()) - return Stream.empty(); - - return triggerParameters.stream().map(BuildParameterSpec::name); - } - /** {@inheritDoc} */ @Override public String tcBranch() { return branchForRest; diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITcBotConfig.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITcBotConfig.java index 63e144850..a5f78719d 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITcBotConfig.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITcBotConfig.java @@ -45,24 +45,6 @@ public interface ITcBotConfig extends IDataSourcesConfigSupplier { /** */ public Double confidence(); - /** - * @return Tracked branches configuration for TC Bot. - */ - public ITrackedBranchesConfig getTrackedBranches(); - - /** - * @return list of servers (services) identifiers involved into tracked branches processing. - */ - public default Collection getServerIds() { - return getTrackedBranches().getServerIds(); - } - - public ITcServerConfig getTeamcityConfig(String srvCode); - - public IJiraServerConfig getJiraConfig(String srvCode); - - public IGitHubConfig getGitConfig(String srvCode); - /** * @return notification settings config. */ diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedBranchesConfig.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedBranchesConfig.java index 46d3287e6..21484ffac 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedBranchesConfig.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedBranchesConfig.java @@ -16,19 +16,16 @@ */ package org.apache.ignite.tcbot.engine.conf; -import java.util.Collection; import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; /** - * + * Tracked branches configuration for TC Bot. */ public interface ITrackedBranchesConfig { Stream branchesStream(); - Collection getServerIds(); - public default Optional get(String branch) { return branchesStream().filter(b -> Objects.equals(branch, b.name())).findAny(); } @@ -37,5 +34,4 @@ public default Optional get(String branch) { public default ITrackedBranch getBranchMandatory(String branch) { return get(branch).orElseThrow(() -> new RuntimeException("Branch not found: " + branch)); } - } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java index be76dbc7f..acf5002fd 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java @@ -17,6 +17,8 @@ package org.apache.ignite.tcbot.engine.conf; +import com.google.common.base.Strings; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -63,17 +65,14 @@ public Stream branchesStream() { return branches.stream().map(t->t); } - /** - * - */ - public Set getServerIds() { - Stream srvsInTracked = branchesStream() - .flatMap(ITrackedBranch::chainsStream) - .map(ITrackedChain::serverCode); - - return Stream.concat(srvsInTracked, - tcServers.stream().map(TcServerConfig::getCode)) - .collect(Collectors.toSet()); + public Set getConfiguredServerIds() { + Set collect = tcServers.stream().map(TcServerConfig::getCode).collect(Collectors.toSet()); + + String e = primaryServerCode(); + if(Strings.isNullOrEmpty(e)) + collect.add(e); + + return collect; } public List getBranches() { diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java index 3726c17d8..1a3e359e0 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcServerConfig.java @@ -127,7 +127,7 @@ private String hostConfigured() { } /** - * @return tracked branch name to be used for this server for PRs check + * @inheritDoc */ @Nonnull @Override public String defaultTrackedBranch() { if (!Strings.isNullOrEmpty(defaultTrackedBranch)) diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/pr/PrChainsProcessor.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/pr/PrChainsProcessor.java index 5f197e0c5..fa22692d0 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/pr/PrChainsProcessor.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/pr/PrChainsProcessor.java @@ -43,6 +43,7 @@ import org.apache.ignite.tcbot.engine.chain.ProcessLogsMode; import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.conf.ITrackedChain; import org.apache.ignite.tcbot.engine.newtests.NewTestsStorage; import org.apache.ignite.tcbot.engine.ui.DsChainUi; @@ -90,6 +91,8 @@ private static class Action { /** Config. */ @Inject private ITcBotConfig cfg; + @Inject private ITrackedBranchesConfig trackedBranchesConfig; + @Inject private BranchEquivalence branchEquivalence; @Inject private UpdateCountersStorage countersStorage; @@ -196,7 +199,7 @@ public String dfltBaseTcBranch(String srvCodeOrAlias) { String tcRealSvc = tcCfg.reference(); - Optional branch = cfg.getTrackedBranches().get(dfltTrackedBranch); + Optional branch = trackedBranchesConfig.get(dfltTrackedBranch); if (!branch.isPresent()) return ITeamcity.DEFAULT; diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/tracked/TrackedBranchChainsProcessor.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/tracked/TrackedBranchChainsProcessor.java index 71ab3f43d..9956d4dda 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/tracked/TrackedBranchChainsProcessor.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/tracked/TrackedBranchChainsProcessor.java @@ -42,6 +42,7 @@ import org.apache.ignite.tcbot.engine.chain.SortOption; import org.apache.ignite.tcbot.engine.conf.ITcBotConfig; import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; import org.apache.ignite.tcbot.engine.conf.ITrackedChain; import org.apache.ignite.tcbot.engine.ui.DsChainUi; import org.apache.ignite.tcbot.engine.ui.DsSummaryUi; @@ -67,6 +68,8 @@ public class TrackedBranchChainsProcessor implements IDetailedStatusForTrackedBr /** Tc Bot config. */ @Inject private ITcBotConfig tcBotCfg; + @Inject private ITrackedBranchesConfig trackedBranchesConfig; + /** Chains processor. */ @Inject private BuildChainProcessor chainProc; @@ -100,7 +103,7 @@ public class TrackedBranchChainsProcessor implements IDetailedStatusForTrackedBr final String branchNn = isNullOrEmpty(branch) ? ITcServerConfig.DEFAULT_TRACKED_BRANCH_NAME : branch; res.setTrackedBranch(branchNn); - final ITrackedBranch tracked = tcBotCfg.getTrackedBranches().getBranchMandatory(branchNn); + final ITrackedBranch tracked = trackedBranchesConfig.getBranchMandatory(branchNn); tracked.chainsStream() .filter(chainTracked -> tcIgnitedProv.hasAccess(chainTracked.serverCode(), creds)) @@ -192,15 +195,12 @@ public Map reverseTagToParametersRequired(@Nullable String tag } @Override public GuardBranchStatusUi getBranchSummary(String name, ICredentialsProv prov) { - ITrackedBranch tb = tcBotCfg.getTrackedBranches().getBranchMandatory(name); + ITrackedBranch tb = trackedBranchesConfig.getBranchMandatory(name); List accessibleChains = tb.chainsStream() .filter(chain -> tcIgnitedProv.hasAccess(chain.serverCode(), prov)) .collect(Collectors.toList()); - if (accessibleChains == null) - return null; - int ageDays = 1; long minStartTime = System.currentTimeMillis() - Duration.ofDays(ageDays).toMillis(); @@ -250,7 +250,7 @@ else if (ref.isQueued(compactor)) @Nonnull ICredentialsProv creds) { final String branchNn = isNullOrEmpty(branch) ? ITcServerConfig.DEFAULT_TRACKED_BRANCH_NAME : branch; - final ITrackedBranch tracked = tcBotCfg.getTrackedBranches().getBranchMandatory(branchNn); + final ITrackedBranch tracked = trackedBranchesConfig.getBranchMandatory(branchNn); Set allBranches = new HashSet<>(); tracked.chainsStream() @@ -282,7 +282,7 @@ public LrTestsFullSummaryUi getTrackedBranchLongRunningTestsSummary(@Nullable St LrTestsFullSummaryUi summary = new LrTestsFullSummaryUi(); final String branchNn = isNullOrEmpty(branch) ? ITcServerConfig.DEFAULT_TRACKED_BRANCH_NAME : branch; - final ITrackedBranch tracked = tcBotCfg.getTrackedBranches().getBranchMandatory(branchNn); + final ITrackedBranch tracked = trackedBranchesConfig.getBranchMandatory(branchNn); tracked.chainsStream() .filter(chainTracked -> tcIgnitedProv.hasAccess(chainTracked.serverCode(), creds)) From fb52ef2b01272d576500036a6bde246594a08bb5 Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Wed, 8 Dec 2021 20:02:15 +0300 Subject: [PATCH 4/9] IGNITE-16086 Fix for tracked branches naming and ctx configs --- .../ignite/ci/tcbot/TcBotWebAppModule.java | 4 +- .../ci/tcbot/conf/MemoryTrackedBranches.java | 29 +++++++++++++ .../MixedFilesAndDbTrackedBranchesConfig.java | 7 ++-- .../ci/tcbot/chain/MockBasedTcBotModule.java | 5 ++- .../chain/TrackedBranchProcessorTest.java | 41 ++++++++----------- .../ci/tcbot/issue/IssueDetectorTest.java | 3 +- .../engine/conf/BranchTrackedPersisted.java | 4 +- .../tcbot/engine/conf/TcBotJsonConfig.java | 11 +---- 8 files changed, 62 insertions(+), 42 deletions(-) create mode 100644 ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java index 940609456..e0170f398 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/TcBotWebAppModule.java @@ -36,6 +36,7 @@ import org.apache.ignite.githubignited.GitHubIgnitedModule; import org.apache.ignite.jiraignited.JiraIgnitedModule; import org.apache.ignite.tcbot.common.conf.IDataSourcesConfigSupplier; +import org.apache.ignite.tcbot.common.conf.ITcServerConfigSupplier; import org.apache.ignite.tcbot.common.exeption.ExceptionUtil; import org.apache.ignite.tcbot.common.exeption.ServicesStartingException; import org.apache.ignite.tcbot.engine.TcBotEngineModule; @@ -95,7 +96,8 @@ public class TcBotWebAppModule extends AbstractModule { bind(LocalFilesBasedConfig.class).in(new SingletonScope()); bind(ITcBotConfig.class).to(LocalFilesBasedConfig.class).in(new SingletonScope()); - bind(IDataSourcesConfigSupplier.class).to(LocalFilesBasedConfig.class).in(new SingletonScope()); + bind(IDataSourcesConfigSupplier.class).to(ITcBotConfig.class).in(new SingletonScope()); + bind(ITcServerConfigSupplier.class).to(IDataSourcesConfigSupplier.class).in(new SingletonScope()); bind(ITrackedBranchesConfig.class).to(MixedFilesAndDbTrackedBranchesConfig.class).in(new SingletonScope()); bind(MasterTrendsService.class).in(new SingletonScope()); diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java new file mode 100644 index 000000000..0740c6f67 --- /dev/null +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java @@ -0,0 +1,29 @@ +package org.apache.ignite.ci.tcbot.conf; + +import org.apache.ignite.tcbot.engine.conf.BranchTracked; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranch; +import org.apache.ignite.tcbot.engine.conf.ITrackedBranchesConfig; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +/** + * Inmem only implementation for tests + */ +public class MemoryTrackedBranches implements ITrackedBranchesConfig { + /** + * Branches. + */ + private List branches = new ArrayList<>(); + + @Override + public Stream branchesStream() { + return branches.stream().map(t -> t); + } + + + public void addBranch(BranchTracked branch) { + branches.add(branch); + } +} diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java index 38fc08f33..7fbd2b228 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java @@ -28,12 +28,13 @@ public class MixedFilesAndDbTrackedBranchesConfig implements ITrackedBranchesCon public Stream branchesStream() { //todo internal cached version, // @GuavaCached(softValues = true, expireAfterWriteSecs = 3 * 60) - Stream fileBasedBranches = filesBasedCfg.getConfig().branchesStream(); - IgniteCache cache = igniteProvider.get().getOrCreateCache(CacheConfigs.getCache8PartsConfig(TRACKED_BRANCHES)); Map res = new HashMap<>(); - fileBasedBranches.map(BranchTrackedPersisted::initFrom).forEach(btp -> { + filesBasedCfg.getConfig() + .getBranches() + .stream() + .map(BranchTrackedPersisted::initFrom).forEach(btp -> { res.put(btp.name(), btp); }); 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 8d1a6478a..e4ef6c4f2 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 @@ -22,6 +22,7 @@ import com.google.inject.internal.SingletonScope; import org.apache.ignite.Ignite; import org.apache.ignite.ci.github.PullRequest; +import org.apache.ignite.ci.tcbot.conf.MemoryTrackedBranches; import org.apache.ignite.githubignited.IGitHubConnIgnited; import org.apache.ignite.githubignited.IGitHubConnIgnitedProvider; import org.apache.ignite.jiraignited.IJiraIgnited; @@ -64,9 +65,9 @@ * Setup TC bot context with Ignited services mocks: - TC: {@link TeamcityIgnitedProviderMock} */ public class MockBasedTcBotModule extends AbstractModule { - private TcBotJsonConfig tracked = new TcBotJsonConfig(); + private MemoryTrackedBranches tracked = new MemoryTrackedBranches(); - public MockBasedTcBotModule(TcBotJsonConfig tracked) { + public MockBasedTcBotModule(MemoryTrackedBranches tracked) { this.tracked = tracked; } diff --git a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/TrackedBranchProcessorTest.java b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/TrackedBranchProcessorTest.java index 492654ffc..c4bed6e48 100644 --- a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/TrackedBranchProcessorTest.java +++ b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/chain/TrackedBranchProcessorTest.java @@ -22,39 +22,32 @@ import com.google.gson.GsonBuilder; import com.google.inject.Guice; import com.google.inject.Injector; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.ignite.tcbot.engine.tracked.DisplayMode; -import org.apache.ignite.tcbot.engine.tracked.TrackedBranchChainsProcessor; -import org.apache.ignite.tcservice.ITeamcity; -import org.apache.ignite.tcbot.engine.conf.BranchTracked; -import org.apache.ignite.tcbot.engine.conf.ChainAtServerTracked; -import org.apache.ignite.tcbot.engine.conf.TcBotJsonConfig; -import org.apache.ignite.tcbot.persistence.IStringCompactor; -import org.apache.ignite.tcignited.ITeamcityIgnitedProvider; -import org.apache.ignite.tcignited.SyncMode; +import org.apache.ignite.ci.tcbot.conf.MemoryTrackedBranches; import org.apache.ignite.ci.teamcity.ignited.TeamcityIgnitedProviderMock; import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted; import org.apache.ignite.ci.user.ITcBotUserCreds; +import org.apache.ignite.tcbot.engine.conf.BranchTracked; +import org.apache.ignite.tcbot.engine.conf.ChainAtServerTracked; +import org.apache.ignite.tcbot.engine.tracked.DisplayMode; +import org.apache.ignite.tcbot.engine.tracked.TrackedBranchChainsProcessor; import org.apache.ignite.tcbot.engine.ui.DsChainUi; import org.apache.ignite.tcbot.engine.ui.DsSuiteUi; -import org.apache.ignite.tcbot.engine.ui.DsTestFailureUi; import org.apache.ignite.tcbot.engine.ui.DsSummaryUi; +import org.apache.ignite.tcbot.engine.ui.DsTestFailureUi; +import org.apache.ignite.tcbot.persistence.IStringCompactor; +import org.apache.ignite.tcignited.ITeamcityIgnitedProvider; +import org.apache.ignite.tcignited.SyncMode; +import org.apache.ignite.tcservice.ITeamcity; import org.jetbrains.annotations.NotNull; import org.junit.Before; import org.junit.Test; -import static org.apache.ignite.ci.tcbot.chain.PrChainsProcessorTest.CACHE_9; -import static org.apache.ignite.ci.tcbot.chain.PrChainsProcessorTest.TEST_RARE_FAILED_WITHOUT_CHANGES; -import static org.apache.ignite.ci.tcbot.chain.PrChainsProcessorTest.TEST_RARE_FAILED_WITH_CHANGES; -import static org.apache.ignite.ci.tcbot.chain.PrChainsProcessorTest.createFatBuild; -import static org.apache.ignite.ci.tcbot.chain.PrChainsProcessorTest.createTest; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + +import static org.apache.ignite.ci.tcbot.chain.PrChainsProcessorTest.*; +import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -69,7 +62,7 @@ public class TrackedBranchProcessorTest { private Map apacheBuilds = new ConcurrentHashMap<>(); /** Branches tracked. */ - private TcBotJsonConfig branchesTracked = new TcBotJsonConfig(); + private MemoryTrackedBranches branchesTracked = new MemoryTrackedBranches(); /** * Injector. */ diff --git a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/issue/IssueDetectorTest.java b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/issue/IssueDetectorTest.java index aeb07fcae..e4fa24bbb 100644 --- a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/issue/IssueDetectorTest.java +++ b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/tcbot/issue/IssueDetectorTest.java @@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Stream; import org.apache.ignite.ci.tcbot.chain.MockBasedTcBotModule; +import org.apache.ignite.ci.tcbot.conf.MemoryTrackedBranches; import org.apache.ignite.ci.teamcity.ignited.TeamcityIgnitedProviderMock; import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted; import org.apache.ignite.ci.user.ITcBotUserCreds; @@ -63,7 +64,7 @@ public class IssueDetectorTest { private Map apacheBuilds = new ConcurrentHashMap<>(); /** Config Branches tracked. */ - private TcBotJsonConfig branchesTracked = new TcBotJsonConfig(); + private MemoryTrackedBranches branchesTracked = new MemoryTrackedBranches(); /** * Injector. */ diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java index 0496ba6af..4727d7725 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java @@ -3,13 +3,15 @@ import javax.annotation.Nullable; public class BranchTrackedPersisted extends BranchTracked { - @Nullable protected Boolean softDeleted; + @Nullable + protected Boolean softDeleted; public static BranchTrackedPersisted initFrom(ITrackedBranch b) { BranchTrackedPersisted bp = new BranchTrackedPersisted(); b.chainsStream().map(ChainAtServerTracked::initFrom).forEach(bp.chains::add); + bp.id = b.name(); bp.disableIssueTypes = b.disableIssueTypes(); bp.softDeleted = false; diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java index acf5002fd..c1a1c5598 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/TcBotJsonConfig.java @@ -33,7 +33,7 @@ * TC Bot main JSON config file, Historically. * Config file for tracked branches. */ -public class TcBotJsonConfig implements ITrackedBranchesConfig { +public class TcBotJsonConfig { /** Branches. */ private List branches = new ArrayList<>(); @@ -60,11 +60,6 @@ public class TcBotJsonConfig implements ITrackedBranchesConfig { /** Notifications settings & tokens. */ private NotificationsConfig notifications = new NotificationsConfig(); - @Override - public Stream branchesStream() { - return branches.stream().map(t->t); - } - public Set getConfiguredServerIds() { Set collect = tcServers.stream().map(TcServerConfig::getCode).collect(Collectors.toSet()); @@ -79,10 +74,6 @@ public List getBranches() { return Collections.unmodifiableList(branches); } - public void addBranch(BranchTracked branch) { - branches.add(branch); - } - /** * @return Primary server code. */ From 39dbab2205529cd1f7e97f051c010a6edcb1b3ba Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Wed, 8 Dec 2021 20:12:43 +0300 Subject: [PATCH 5/9] IGNITE-16086 Fix for licenses --- .../ci/tcbot/conf/MemoryTrackedBranches.java | 16 ++++++++++++++++ .../MixedFilesAndDbTrackedBranchesConfig.java | 16 ++++++++++++++++ .../common/conf/ITcServerConfigSupplier.java | 16 ++++++++++++++++ .../engine/conf/BranchTrackedPersisted.java | 16 ++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java index 0740c6f67..2c589c2e6 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MemoryTrackedBranches.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.ignite.tcbot.engine.conf.BranchTracked; diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java index 7fbd2b228..6133e683a 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.ignite.Ignite; diff --git a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java index d50486107..abcbd6d67 100644 --- a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java +++ b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/ITcServerConfigSupplier.java @@ -1,3 +1,19 @@ +/* + * 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.tcbot.common.conf; import java.util.Collection; diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java index 4727d7725..1e2262417 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java @@ -1,3 +1,19 @@ +/* + * 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.tcbot.engine.conf; import javax.annotation.Nullable; From 20067e308407bd0caad043982c53540cb261b7f7 Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Wed, 8 Dec 2021 21:50:30 +0300 Subject: [PATCH 6/9] IGNITE-16086 Fix parameter values copying --- .../MixedFilesAndDbTrackedBranchesConfig.java | 2 +- .../common/conf/IBuildParameterSpec.java | 6 ++++ .../engine/conf/BranchTrackedPersisted.java | 16 +++++----- .../tcbot/engine/conf/BuildParameterSpec.java | 31 ++++++++++++++++-- .../engine/conf/ChainAtServerTracked.java | 32 ++++++++++++------- .../tcbot/engine/conf/ITrackedChain.java | 5 +++ .../tcbot/engine/conf/ParameterValueSpec.java | 10 ++++++ 7 files changed, 79 insertions(+), 23 deletions(-) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java index 6133e683a..8647a0c13 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/conf/MixedFilesAndDbTrackedBranchesConfig.java @@ -50,7 +50,7 @@ public Stream branchesStream() { filesBasedCfg.getConfig() .getBranches() .stream() - .map(BranchTrackedPersisted::initFrom).forEach(btp -> { + .map(BranchTrackedPersisted::new).forEach(btp -> { res.put(btp.name(), btp); }); diff --git a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IBuildParameterSpec.java b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IBuildParameterSpec.java index 6d1223ee8..e05abcf52 100644 --- a/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IBuildParameterSpec.java +++ b/tcbot-common/src/main/java/org/apache/ignite/tcbot/common/conf/IBuildParameterSpec.java @@ -16,6 +16,7 @@ */ package org.apache.ignite.tcbot.common.conf; +import javax.annotation.Nullable; import java.util.Collection; /** @@ -27,4 +28,9 @@ public interface IBuildParameterSpec { boolean isFilled(); Collection selection(); + + boolean useRandomValue(); + + /** Fixed value (if any) */ + @Nullable String value(); } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java index 1e2262417..83194135b 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BranchTrackedPersisted.java @@ -22,16 +22,16 @@ public class BranchTrackedPersisted extends BranchTracked { @Nullable protected Boolean softDeleted; - public static BranchTrackedPersisted initFrom(ITrackedBranch b) { - BranchTrackedPersisted bp = new BranchTrackedPersisted(); - - b.chainsStream().map(ChainAtServerTracked::initFrom).forEach(bp.chains::add); + @SuppressWarnings("unused") + public BranchTrackedPersisted() { + } - bp.id = b.name(); - bp.disableIssueTypes = b.disableIssueTypes(); - bp.softDeleted = false; + public BranchTrackedPersisted(ITrackedBranch b) { + b.chainsStream().map(ChainAtServerTracked::new).forEach(chains::add); - return bp; + this.id = b.name(); + this.disableIssueTypes = b.disableIssueTypes(); + this.softDeleted = false; } public boolean isDeleted() { diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BuildParameterSpec.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BuildParameterSpec.java index 4ed9ba397..fe72551b5 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BuildParameterSpec.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/BuildParameterSpec.java @@ -23,6 +23,7 @@ import org.apache.ignite.tcbot.common.conf.IParameterValueSpec; import java.util.*; +import java.util.stream.Collectors; public class BuildParameterSpec implements IBuildParameterSpec { /** Parameter (property) Name. */ @@ -40,8 +41,23 @@ public class BuildParameterSpec implements IBuildParameterSpec { */ @Nullable private List selection = new ArrayList<>(); - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { + + @SuppressWarnings("unused") + public BuildParameterSpec() { + } + + BuildParameterSpec(IBuildParameterSpec spec) { + name = spec.name(); + randomValue = spec.useRandomValue(); + value = spec.value(); + selection = spec.selection().stream().map(ParameterValueSpec::new).collect(Collectors.toList()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -69,7 +85,7 @@ public String name() { * @return some valid value for property or null. */ public Object generateValue() { - if (!Boolean.TRUE.equals(randomValue)) + if (!useRandomValue()) return value; if (selection == null || selection.isEmpty()) @@ -82,6 +98,15 @@ public Object generateValue() { return spec.value(); } + public boolean useRandomValue() { + return Boolean.TRUE.equals(randomValue); + } + + @Override + public String value() { + return value; + } + public boolean isFilled() { return !Strings.isNullOrEmpty(name); } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java index c7087f1f0..56eef8a0e 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java @@ -18,18 +18,20 @@ package org.apache.ignite.tcbot.engine.conf; import com.google.common.base.Strings; +import org.apache.ignite.tcbot.common.conf.IBuildParameterSpec; + import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Nonnull; import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Strings.isNullOrEmpty; /** * Chain on particular TC server, which is tracked by the Bot. @@ -51,20 +53,21 @@ public class ChainAtServerTracked extends ChainAtServer implements ITrackedChain /** Build parameters for Triggering. */ @Nullable private List triggerParameters; - static ChainAtServerTracked initFrom(ITrackedChain c) { - ChainAtServerTracked ct = new ChainAtServerTracked(); - ct.serverId = c.serverCode(); - ct.suiteId = c.tcSuiteId(); + @SuppressWarnings("unused") + public ChainAtServerTracked() {} - ct.branchForRest = c.tcBranch(); - ct.baseBranchForTc = c.tcBaseBranch().orElse(null); - ct.triggerBuild = c.triggerBuild(); + ChainAtServerTracked(ITrackedChain c) { + serverId = c.serverCode(); + suiteId = c.tcSuiteId(); - ct.triggerBuildQuietPeriod = c.triggerBuildQuietPeriod(); + branchForRest = c.tcBranch(); + baseBranchForTc = c.tcBaseBranch().orElse(null); + triggerBuild = c.triggerBuild(); - //todo support copying trigger parms: ct.triggerParameters = c.generateBuildParameters();//todo + triggerBuildQuietPeriod = c.triggerBuildQuietPeriod(); - return ct; + triggerParameters = + c.triggerParameterSpecs().map(BuildParameterSpec::new).collect(Collectors.toList()); } /** @@ -103,6 +106,13 @@ static ChainAtServerTracked initFrom(ITrackedChain c) { return triggerBuild == null ? false : triggerBuild; } + @Override + public Stream triggerParameterSpecs() { + return triggerParameters == null + ? Stream.empty() + : triggerParameters.stream().map(p -> p); + } + /** {@inheritDoc} */ @Override public int triggerBuildQuietPeriod() { return triggerBuildQuietPeriod == null ? 0 : triggerBuildQuietPeriod; diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedChain.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedChain.java index 2e3d3cb7b..749c9dc7c 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedChain.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ITrackedChain.java @@ -16,9 +16,12 @@ */ package org.apache.ignite.tcbot.engine.conf; +import org.apache.ignite.tcbot.common.conf.IBuildParameterSpec; + import javax.annotation.Nonnull; import java.util.Map; import java.util.Optional; +import java.util.stream.Stream; /** * @@ -47,4 +50,6 @@ public interface ITrackedChain { * @return {@code True} If automatic build triggering enabled. */ public boolean triggerBuild(); + + Stream triggerParameterSpecs(); } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java index 1c1e4c855..7a1f6c01a 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java @@ -29,6 +29,16 @@ public class ParameterValueSpec implements IParameterValueSpec { private String label; private String valueRegExp; + @SuppressWarnings("unused") + public ParameterValueSpec() { + } + + public ParameterValueSpec(IParameterValueSpec spec) { + this.value = spec.value(); + this.valueRegExp = spec.valueRegExp(); + this.label = spec.label(); + } + /** * Exact value, which can be present in a build. */ From ed81d658cb0a5079a5f4f1b6ec7881e3a7202518 Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Fri, 10 Dec 2021 15:43:26 +0300 Subject: [PATCH 7/9] IGNITE-16086 Prepare get service for tracked branch --- .../ci/web/rest/GetTrackedBranches.java | 22 ++++++++++++++++++- .../engine/conf/ChainAtServerTracked.java | 4 +--- .../tcbot/engine/conf/ParameterValueSpec.java | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java index 65ab6de5b..3b32fc03f 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java @@ -20,6 +20,7 @@ import com.google.common.base.Strings; import com.google.inject.Injector; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -34,6 +35,7 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import org.apache.ignite.tcbot.common.conf.ITcServerConfig; import org.apache.ignite.tcbot.common.conf.ITcServerConfigSupplier; import org.apache.ignite.tcbot.engine.conf.ChainAtServer; import org.apache.ignite.ci.tcbot.TcBotGeneralService; @@ -140,7 +142,7 @@ public Set getServerIds() { /** - * Finds all registere unique teamcity branches. + * Finds all registered unique teamcity branches. * @param srvCodeOrAlias Server code or its alisas. */ @GET @@ -160,4 +162,22 @@ public Set tcBranches(@Nullable @QueryParam("srvCode") String srvCodeOrA }) .map(ITrackedChain::tcBranch).collect(Collectors.toSet()); } + + /** + * Finds all registered unique teamcity branches. + * @param branch TC Bot's branch name + */ + @GET + @Path("get") + public ITrackedBranch get(@Nullable @QueryParam("branch") String branch) { + ITeamcityIgnitedProvider instance = CtxListener.getInjector(ctx) + .getInstance(ITeamcityIgnitedProvider.class); + String branchId = Strings.isNullOrEmpty(branch) ? ITcServerConfig.DEFAULT_TRACKED_BRANCH_NAME : branch; + + Stream branchStream = accessibleTrackedBranches(); + Optional any = branchStream.filter( + tb -> branchId.equals(tb.name()) + ).findAny(); + return any.orElse(null); + } } diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java index 56eef8a0e..3a949d31b 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ChainAtServerTracked.java @@ -63,11 +63,9 @@ public ChainAtServerTracked() {} branchForRest = c.tcBranch(); baseBranchForTc = c.tcBaseBranch().orElse(null); triggerBuild = c.triggerBuild(); - triggerBuildQuietPeriod = c.triggerBuildQuietPeriod(); - triggerParameters = - c.triggerParameterSpecs().map(BuildParameterSpec::new).collect(Collectors.toList()); + triggerParameters = c.triggerParameterSpecs().map(BuildParameterSpec::new).collect(Collectors.toList()); } /** diff --git a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java index 7a1f6c01a..cdcd524eb 100644 --- a/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java +++ b/tcbot-engine/src/main/java/org/apache/ignite/tcbot/engine/conf/ParameterValueSpec.java @@ -33,7 +33,7 @@ public class ParameterValueSpec implements IParameterValueSpec { public ParameterValueSpec() { } - public ParameterValueSpec(IParameterValueSpec spec) { + ParameterValueSpec(IParameterValueSpec spec) { this.value = spec.value(); this.valueRegExp = spec.valueRegExp(); this.label = spec.label(); From 1ae78da6647c746680c2b411da7601cd6438efbc Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Fri, 10 Dec 2021 20:10:39 +0300 Subject: [PATCH 8/9] IGNITE-16086 dummy tracked branch edit page --- .../src/main/webapp/branches/index.html | 349 ++++++++++++++++++ 1 file changed, 349 insertions(+) create mode 100644 ignite-tc-helper-web/src/main/webapp/branches/index.html diff --git a/ignite-tc-helper-web/src/main/webapp/branches/index.html b/ignite-tc-helper-web/src/main/webapp/branches/index.html new file mode 100644 index 000000000..115ede302 --- /dev/null +++ b/ignite-tc-helper-web/src/main/webapp/branches/index.html @@ -0,0 +1,349 @@ + + + Apache Ignite Teamcity Bot - Tracked branch - Edit + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+ + + + + +
+
+ +
+ Branch: + +
+ + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + From 56b868aa32eff967483a5272178ad3093cf5fada Mon Sep 17 00:00:00 2001 From: Dmitriy Pavlov Date: Mon, 13 Dec 2021 18:22:57 +0300 Subject: [PATCH 9/9] IGNITE-16086 dummy tracked branch edit page: updating parameters --- .../ci/web/rest/GetTrackedBranches.java | 19 ++++++++----------- .../src/main/webapp/branches/index.html | 6 +++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java index 3b32fc03f..d98622fe5 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/GetTrackedBranches.java @@ -165,19 +165,16 @@ public Set tcBranches(@Nullable @QueryParam("srvCode") String srvCodeOrA /** * Finds all registered unique teamcity branches. - * @param branch TC Bot's branch name + * @param code TC Bot's branch code */ @GET @Path("get") - public ITrackedBranch get(@Nullable @QueryParam("branch") String branch) { - ITeamcityIgnitedProvider instance = CtxListener.getInjector(ctx) - .getInstance(ITeamcityIgnitedProvider.class); - String branchId = Strings.isNullOrEmpty(branch) ? ITcServerConfig.DEFAULT_TRACKED_BRANCH_NAME : branch; - - Stream branchStream = accessibleTrackedBranches(); - Optional any = branchStream.filter( - tb -> branchId.equals(tb.name()) - ).findAny(); - return any.orElse(null); + public ITrackedBranch get(@Nullable @QueryParam("code") String code) { + String branchCode = Strings.isNullOrEmpty(code) ? ITcServerConfig.DEFAULT_TRACKED_BRANCH_NAME : code; + + return accessibleTrackedBranches() + .filter(tb -> branchCode.equals(tb.name())) + .findAny() + .orElse(null); } } diff --git a/ignite-tc-helper-web/src/main/webapp/branches/index.html b/ignite-tc-helper-web/src/main/webapp/branches/index.html index 115ede302..fbef04e24 100644 --- a/ignite-tc-helper-web/src/main/webapp/branches/index.html +++ b/ignite-tc-helper-web/src/main/webapp/branches/index.html @@ -164,9 +164,9 @@ function parmsForRest() { var curReqParms = ""; - var branch = findGetParameter("branch"); - if (branch != null) { - curReqParms += "?branch=" + branch; + var branchCode = findGetParameter("code"); + if (branchCode != null) { + curReqParms += "?code=" + branchCode; } return curReqParms;