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/01/28 15:04:59 UTC
[ignite-teamcity-bot] branch ignite-11105-alias updated:
IGNITE-11105 Support Teamcity servers aliases: Aliased service started ok
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 1041cb3 IGNITE-11105 Support Teamcity servers aliases: Aliased service started ok
1041cb3 is described below
commit 1041cb350cbd98e089a6be2917271e571f8142bd
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Mon Jan 28 18:04:55 2019 +0300
IGNITE-11105 Support Teamcity servers aliases: Aliased service started ok
---
.../java/org/apache/ignite/ci/HelperConfig.java | 2 +-
.../org/apache/ignite/ci/conf/BranchesTracked.java | 2 +-
.../ci/tcbot/conf/LocalFilesBasedConfig.java | 20 +++++++++----------
.../teamcity/ignited/ITeamcityIgnitedProvider.java | 9 +++++++++
.../teamcity/ignited/TcIgnitedCachingProvider.java | 15 ++++++++++++--
.../ignite/ci/web/rest/GetTrackedBranches.java | 23 ++++++++++++++++------
.../exception/ServiceUnauthorizedException.java | 4 ++--
.../org/apache/ignite/ci/web/rest/login/Login.java | 3 +--
.../ignite/ci/web/rest/visa/TcBotVisaService.java | 19 ++++++++++--------
ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js | 2 +-
ignite-tc-helper-web/src/main/webapp/prs.html | 13 ++++++++----
.../ignited/TeamcityIgnitedProviderMock.java | 11 +++++++++--
12 files changed, 83 insertions(+), 40 deletions(-)
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java
index e0a0c76..bf5a2ef 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/HelperConfig.java
@@ -92,7 +92,7 @@ public class HelperConfig {
writer.write(USERNAME + "=" + ENDL);
writer.write(ENCODED_PASSWORD + "=" + ENDL);
}
- throw new IllegalStateException("Please setup username and encodedPassword in config file [" +
+ throw new IllegalStateException("Please setup parameters for service in config file [" +
file.getCanonicalPath() + "]");
}
return loadProps(file);
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 9f64b05..98a0817 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
@@ -87,6 +87,6 @@ public class BranchesTracked {
}
public Optional<TcServerConfig> getServer(String name) {
- return servers.stream().filter(s->name.equals(s.getName())).findAny();
+ return servers.stream().filter(s -> name.equals(s.getName())).findAny();
}
}
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 aa00b50..d24600b 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
@@ -35,24 +35,22 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
/** {@inheritDoc} */
@Override public ITcServerConfig getTeamcityConfig(String srvName) {
- File workDir = HelperConfig.resolveWorkDir();
-
- String cfgName = HelperConfig.prepareConfigName(srvName);
-
- Properties props = HelperConfig.loadAuthProperties(workDir, cfgName);
-
- TcServerConfig cfg = getTrackedBranches().getServer(srvName)
+ return getTrackedBranches().getServer(srvName)
.orElseGet(() -> {
TcServerConfig tcCfg = new TcServerConfig();
tcCfg.name = srvName;
- return tcCfg;
- });
+ File workDir = HelperConfig.resolveWorkDir();
- cfg.properties(props);
+ String cfgName = HelperConfig.prepareConfigName(srvName);
- return cfg;
+ Properties props = HelperConfig.loadAuthProperties(workDir, cfgName);
+
+ tcCfg.properties(props);
+
+ return tcCfg;
+ });
}
/** {@inheritDoc} */
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnitedProvider.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnitedProvider.java
index 4c0fb56..34e5b4b 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnitedProvider.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/ITeamcityIgnitedProvider.java
@@ -17,15 +17,24 @@
package org.apache.ignite.ci.teamcity.ignited;
import javax.annotation.Nullable;
+import javax.ws.rs.QueryParam;
import org.apache.ignite.ci.user.ICredentialsProv;
+import org.apache.ignite.ci.web.rest.exception.ServiceUnauthorizedException;
/**
* Provides instance of particular cache-based teamcity connection.
*/
public interface ITeamcityIgnitedProvider {
+ public boolean hasAccess(String srvId, @Nullable ICredentialsProv prov);
+
/**
* @param srvId Server id.
* @param prov Prov.
*/
public ITeamcityIgnited server(String srvId, @Nullable ICredentialsProv prov);
+
+ default void checkAccess(@Nullable String srvId, ICredentialsProv credsProv) {
+ if (!hasAccess(srvId, credsProv))
+ throw ServiceUnauthorizedException.noCreds(srvId);
+ }
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TcIgnitedCachingProvider.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TcIgnitedCachingProvider.java
index 5891f81..227b99e 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TcIgnitedCachingProvider.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/TcIgnitedCachingProvider.java
@@ -39,7 +39,8 @@ class TcIgnitedCachingProvider implements ITeamcityIgnitedProvider {
@Inject
private ITcServerProvider srvFactory;
- @Inject private ITcBotConfig config;
+ /** Config. */
+ @Inject private ITcBotConfig cfg;
@Inject private Provider<TeamcityIgnitedImpl> provider;
@@ -51,8 +52,18 @@ class TcIgnitedCachingProvider implements ITeamcityIgnitedProvider {
.build();
/** {@inheritDoc} */
+ @Override public boolean hasAccess(String srvId, @Nullable ICredentialsProv prov) {
+ String ref = cfg.getTeamcityConfig(srvId).reference();
+
+ if (!Strings.isNullOrEmpty(ref))
+ return prov.hasAccess(ref);
+
+ return prov.hasAccess(srvId);
+ }
+
+ /** {@inheritDoc} */
@Override public ITeamcityIgnited server(String srvIdReq, @Nullable ICredentialsProv prov) {
- ITcServerConfig cfg = config.getTeamcityConfig(srvIdReq);
+ ITcServerConfig cfg = this.cfg.getTeamcityConfig(srvIdReq);
String ref = cfg.reference();
String realSrvId = !Strings.isNullOrEmpty(ref) && !srvIdReq.equals(ref) ? ref : srvIdReq;
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 691a86f..ea62194 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
@@ -18,6 +18,7 @@
package org.apache.ignite.ci.web.rest;
import com.google.common.base.Strings;
+import com.google.inject.Injector;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@@ -34,6 +35,7 @@ import javax.ws.rs.core.MediaType;
import org.apache.ignite.ci.conf.ChainAtServer;
import org.apache.ignite.ci.tcbot.TcBotGeneralService;
import org.apache.ignite.ci.tcbot.conf.ITcBotConfig;
+import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnitedProvider;
import org.apache.ignite.ci.user.ICredentialsProv;
import org.apache.ignite.ci.web.CtxListener;
import org.apache.ignite.ci.web.model.Version;
@@ -75,7 +77,9 @@ public class GetTrackedBranches {
public Set<ChainAtServer> getSuites(@Nullable @QueryParam("server") String srvId) {
final ICredentialsProv prov = ICredentialsProv.get(req);
- return CtxListener.getInjector(ctx).getInstance(ITcBotConfig.class).getTrackedBranches()
+ Injector injector = CtxListener.getInjector(ctx);
+ ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class);
+ return cfg.getTrackedBranches()
.getSuitesUnique()
.stream()
.filter(chainAtSrv ->
@@ -93,11 +97,18 @@ public class GetTrackedBranches {
public Set<String> getServerIds() {
final ICredentialsProv prov = ICredentialsProv.get(req);
- return CtxListener.getInjector(ctx).getInstance(ITcBotConfig.class)
- .getServerIds()
- .stream()
- .filter(prov::hasAccess)
- .collect(Collectors.toSet());
+ Injector injector = CtxListener.getInjector(ctx);
+ ITcBotConfig cfg = injector.getInstance(ITcBotConfig.class);
+
+ ITeamcityIgnitedProvider tcProv = injector.getInstance(ITeamcityIgnitedProvider.class);
+ return cfg.getServerIds()
+ .stream()
+ .filter(srvId ->
+ {
+ return tcProv.hasAccess(srvId, prov);
+
+ })
+ .collect(Collectors.toSet());
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/exception/ServiceUnauthorizedException.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/exception/ServiceUnauthorizedException.java
index f59be5d..80e4b5a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/exception/ServiceUnauthorizedException.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/exception/ServiceUnauthorizedException.java
@@ -32,8 +32,8 @@ public class ServiceUnauthorizedException extends RuntimeException
public ServiceUnauthorizedException() {
}
- public static ServiceUnauthorizedException noCreds(String serverId) {
- return new ServiceUnauthorizedException("Service [" + serverId + "] is not available for current user");
+ public static ServiceUnauthorizedException noCreds(String srvId) {
+ return new ServiceUnauthorizedException("Service [" + srvId + "] is not available for current user");
}
@Override
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 f6f62d1..58aab62 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
@@ -79,8 +79,7 @@ public class Login {
String primarySrvId = cfg.primaryServerId();
try {
- return doLogin(username, pwd, users, primarySrvId,
- cfg.getServerIds(), tcLogin);
+ return doLogin(username, pwd, users, primarySrvId, 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/visa/TcBotVisaService.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/visa/TcBotVisaService.java
index f7bfa78..a3d94cb 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/visa/TcBotVisaService.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/visa/TcBotVisaService.java
@@ -16,6 +16,7 @@
*/
package org.apache.ignite.ci.web.rest.visa;
+import com.google.inject.Injector;
import java.util.Collection;
import java.util.List;
import java.util.Set;
@@ -34,6 +35,7 @@ import org.apache.ignite.ci.tcbot.visa.ContributionToCheck;
import org.apache.ignite.ci.tcbot.visa.CurrentVisaStatus;
import org.apache.ignite.ci.tcbot.visa.TcBotTriggerAndSignOffService;
import org.apache.ignite.ci.tcbot.visa.VisaStatus;
+import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnitedProvider;
import org.apache.ignite.ci.user.ICredentialsProv;
import org.apache.ignite.ci.web.CtxListener;
import org.apache.ignite.ci.web.model.ContributionKey;
@@ -82,11 +84,11 @@ public class TcBotVisaService {
public List<ContributionToCheck> contributions(@Nullable @QueryParam("serverId") String srvId) {
ICredentialsProv credsProv = ICredentialsProv.get(req);
- if (!credsProv.hasAccess(srvId))
- throw ServiceUnauthorizedException.noCreds(srvId);
+ Injector injector = CtxListener.getInjector(ctx);
- return CtxListener.getInjector(ctx)
- .getInstance(TcBotTriggerAndSignOffService.class).getContributionsToCheck(srvId, credsProv);
+ injector.getInstance(ITeamcityIgnitedProvider.class).checkAccess(srvId, credsProv);
+
+ return injector.getInstance(TcBotTriggerAndSignOffService.class).getContributionsToCheck(srvId, credsProv);
}
@GET
@@ -94,11 +96,12 @@ public class TcBotVisaService {
public Set<ContributionCheckStatus> contributionStatus(@Nullable @QueryParam("serverId") String srvId,
@QueryParam("prId") String prId) {
ICredentialsProv prov = ICredentialsProv.get(req);
- if (!prov.hasAccess(srvId))
- throw ServiceUnauthorizedException.noCreds(srvId);
- return CtxListener.getInjector(ctx)
- .getInstance(TcBotTriggerAndSignOffService.class).contributionStatuses(srvId, prov, prId);
+ Injector injector = CtxListener.getInjector(ctx);
+
+ injector.getInstance(ITeamcityIgnitedProvider.class).checkAccess(srvId, prov);
+
+ return injector.getInstance(TcBotTriggerAndSignOffService.class).contributionStatuses(srvId, prov, prId);
}
@GET
diff --git a/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js b/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js
index 2ecb6fc..1328764 100644
--- a/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js
+++ b/ignite-tc-helper-web/src/main/webapp/js/prs-1.1.js
@@ -17,7 +17,7 @@ function drawTable(srvId, element) {
" </table>\n");
}
-function requestTableForServer(srvId, suiteIdIgnored, element) {
+function requestTableForServer(srvId, element) {
let tableId = "serverContributions-" + srvId;
diff --git a/ignite-tc-helper-web/src/main/webapp/prs.html b/ignite-tc-helper-web/src/main/webapp/prs.html
index 1eabc89..6989a00 100644
--- a/ignite-tc-helper-web/src/main/webapp/prs.html
+++ b/ignite-tc-helper-web/src/main/webapp/prs.html
@@ -61,9 +61,7 @@
function showServerContribTabs(result) {
const processed = new Set();
- for (let chainAtServer of result) {
- let serverId = chainAtServer.serverId;
-
+ for (let serverId of result) {
if (processed.has(serverId))
continue;
@@ -82,7 +80,7 @@
tabsInsertion.after("<div id=\"" + tabId + "\">" + "</div>");
- requestTableForServer(serverId, chainAtServer.suiteId, $(tabRef));
+ requestTableForServer(serverId, $(tabRef));
}
showTabs();
@@ -104,7 +102,14 @@
showSuitesForTeamCityRunData(result);
showFormAndSuitesForPrCheck(result);
showCommentJiraForm(result);
+ },
+ error: showErrInLoadStatus
+ });
+ $.ajax({
+ url: "rest/branches/getServerIds",
+ success: function(result) {
+ $("#loadStatus").html("");
showServerContribTabs(result);
},
error: showErrInLoadStatus
diff --git a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedProviderMock.java b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedProviderMock.java
index f9f0eca..d484a13 100644
--- a/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedProviderMock.java
+++ b/ignite-tc-helper-web/src/test/java/org/apache/ignite/ci/teamcity/ignited/TeamcityIgnitedProviderMock.java
@@ -17,6 +17,7 @@
package org.apache.ignite.ci.teamcity.ignited;
+import javax.annotation.Nullable;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
import org.apache.ignite.ci.user.ICredentialsProv;
@@ -25,6 +26,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TeamcityIgnitedProviderMock implements ITeamcityIgnitedProvider {
+ /** Compactor. */
@Inject IStringCompactor compactor;
private Map<String, Map<Integer, FatBuildCompacted>> tcBuildsData = new ConcurrentHashMap<>();
@@ -33,8 +35,13 @@ public class TeamcityIgnitedProviderMock implements ITeamcityIgnitedProvider {
tcBuildsData.put(srvId, apacheBuilds);
}
- @Override
- public ITeamcityIgnited server(String srvId, ICredentialsProv prov) {
+ /** {@inheritDoc} */
+ @Override public boolean hasAccess(String srvId, @Nullable ICredentialsProv prov) {
+ return prov.hasAccess(srvId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public ITeamcityIgnited server(String srvId, ICredentialsProv prov) {
final Map<Integer, FatBuildCompacted> integerFatBuildCompactedMap = tcBuildsData.get(srvId);
return TeamcityIgnitedMock.getMutableMapTeamcityIgnited(integerFatBuildCompactedMap, compactor);