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 2018/10/04 17:23:22 UTC
[ignite-teamcity-bot] branch master updated: Ctx migration to guice
This is an automated email from the ASF dual-hosted git repository.
dpavlov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite-teamcity-bot.git
The following commit(s) were added to refs/heads/master by this push:
new 6f90e35 Ctx migration to guice
6f90e35 is described below
commit 6f90e3579288439dbf9fbf147c4e494f2a3a600b
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Thu Oct 4 20:23:16 2018 +0300
Ctx migration to guice
---
.../org/apache/ignite/ci/di/IgniteTcBotModule.java | 2 ++
.../apache/ignite/ci/web/BackgroundUpdater.java | 27 +++++++++++-----------
.../java/org/apache/ignite/ci/web/CtxListener.java | 16 ++-----------
.../org/apache/ignite/ci/web/rest/Metrics.java | 18 +++++++--------
4 files changed, 27 insertions(+), 36 deletions(-)
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java
index b09ace1..5445dc0 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/di/IgniteTcBotModule.java
@@ -32,6 +32,7 @@ import org.apache.ignite.ci.observer.ObserverTask;
import org.apache.ignite.ci.teamcity.TcRealConnectionModule;
import org.apache.ignite.ci.user.ICredentialsProv;
import org.apache.ignite.ci.util.ExceptionUtil;
+import org.apache.ignite.ci.web.BackgroundUpdater;
import org.apache.ignite.ci.web.TcUpdatePool;
import org.apache.ignite.ci.web.rest.exception.ServiceStartingException;
@@ -78,6 +79,7 @@ public class IgniteTcBotModule extends AbstractModule {
bind(IJiraIntegration.class).to(Jira.class).in(new SingletonScope());
+ bind(BackgroundUpdater.class).in(new SingletonScope());
install(new TcRealConnectionModule());
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/BackgroundUpdater.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/BackgroundUpdater.java
index 12954d9..ce00f01 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/BackgroundUpdater.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/BackgroundUpdater.java
@@ -27,6 +27,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
+import javax.inject.Inject;
import org.apache.ignite.ci.ITcHelper;
import org.apache.ignite.ci.IgnitePersistentTeamcity;
import org.apache.ignite.ci.analysis.Expirable;
@@ -49,8 +50,10 @@ public class BackgroundUpdater {
/** Expire milliseconds, provide cached result with flag to update */
private static final long EXPIRE_MS = TimeUnit.MINUTES.toMillis(1);
+ /** Thread factory. */
private ThreadFactory threadFactory = Executors.defaultThreadFactory();
+ /** Scheduled updates. */
private final Cache<T2<String, ?>, Future<?>> scheduledUpdates
= CacheBuilder.<T2<String, ?>, Future<?>>newBuilder()
.maximumSize(100)
@@ -58,6 +61,7 @@ public class BackgroundUpdater {
.softValues()
.build();
+ /** Data loaded. */
private final Cache<T2<String, ?>, Expirable<?>> dataLoaded
= CacheBuilder.<T2<String, ?>, Expirable<?>>newBuilder()
.maximumSize(100)
@@ -65,7 +69,8 @@ public class BackgroundUpdater {
.softValues()
.build();
- private ExecutorService service = Executors.newFixedThreadPool(5, r -> {
+ /** Service. */
+ private ExecutorService svc = Executors.newFixedThreadPool(5, r -> {
Thread thread = threadFactory.newThread(r);
thread.setName("bgupd-" + thread.getName());
@@ -73,17 +78,13 @@ public class BackgroundUpdater {
return thread;
});
- private ITcHelper tcHelper;
-
- public BackgroundUpdater(ITcHelper tcHelper) {
- this.tcHelper = tcHelper;
- }
-
- public <K, V extends IBackgroundUpdatable> V get(String cacheName, K key, IgniteClosure<K, V> load) {
- return get(cacheName, key, load, false);
- }
+ /** Tc helper. */
+ @Inject private ITcHelper tcHelper;
+ /**
+ * @param prov Credentials Provoder.
+ */
@NotNull private String availServers(ICredentialsProv prov) {
StringBuffer sb = new StringBuffer();
sb.append("[");
@@ -166,7 +167,7 @@ public class BackgroundUpdater {
return computationKey;
};
- Callable<Future<?>> startingFunction = () -> service.submit(loadModified);
+ Callable<Future<?>> startingFunction = () -> svc.submit(loadModified);
try {
scheduledUpdates.get(computationKey, startingFunction);
@@ -199,10 +200,10 @@ public class BackgroundUpdater {
dataLoaded.cleanUp();
- service.shutdown();
+ svc.shutdown();
try {
- service.awaitTermination(10, TimeUnit.SECONDS);
+ svc.awaitTermination(10, TimeUnit.SECONDS);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
index 7089c9a..073b865 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
@@ -42,15 +42,11 @@ import org.jetbrains.annotations.Nullable;
/**
*/
public class CtxListener implements ServletContextListener {
- private static final String TC_HELPER = "tcHelper";
-
- public static final String UPDATER = "updater";
-
/** Javax.Injector property code for servlet context. */
public static final String INJECTOR = "injector";
public static ITcHelper getTcHelper(ServletContext ctx) {
- return (ITcHelper)ctx.getAttribute(TC_HELPER);
+ return getInjector(ctx).getInstance(ITcHelper.class);
}
public static Injector getInjector(ServletContext ctx) {
@@ -58,7 +54,7 @@ public class CtxListener implements ServletContextListener {
}
public static BackgroundUpdater getBackgroundUpdater(ServletContext ctx) {
- return (BackgroundUpdater)ctx.getAttribute(UPDATER);
+ return getInjector(ctx).getInstance(BackgroundUpdater.class);
}
public static IAnalyticsEnabledTeamcity server(@QueryParam("serverId") @Nullable String srvId,
@@ -83,14 +79,6 @@ public class CtxListener implements ServletContextListener {
final ServletContext ctx = sctxEvt.getServletContext();
ctx.setAttribute(INJECTOR, injector);
-
- final ITcHelper tcHelper = injector.getInstance(TcHelper.class);
-
- BackgroundUpdater backgroundUpdater = new BackgroundUpdater(tcHelper);
-
- ctx.setAttribute(UPDATER, backgroundUpdater);
-
- ctx.setAttribute(TC_HELPER, tcHelper);
}
/**
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/Metrics.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/Metrics.java
index 25e3c6a..97fad42 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/Metrics.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/Metrics.java
@@ -65,7 +65,7 @@ public class Metrics {
public static final String FAILURES_PUBLIC = "failures.public";
public static final String FAILURES_PRIVATE = "failures.private";
@Context
- private ServletContext context;
+ private ServletContext ctx;
@Context
private HttpServletRequest req;
@@ -73,7 +73,7 @@ public class Metrics {
public void collectHistory(BuildMetricsHistory history,
IAnalyticsEnabledTeamcity teamcity, String id, String branch) {
- BuildChainProcessor bcp = CtxListener.getInjector(context).getInstance(BuildChainProcessor.class);
+ BuildChainProcessor bcp = CtxListener.getInjector(ctx).getInstance(BuildChainProcessor.class);
final SuiteInBranch branchId = new SuiteInBranch(id, branch);
final BuildHistory suiteHist = history.history(branchId);
@@ -121,7 +121,7 @@ public class Metrics {
if (!prov.hasAccess(serverId))
throw ServiceUnauthorizedException.noCreds(serverId);
- IAnalyticsEnabledTeamcity teamcity = CtxListener.server(serverId, context, req);
+ IAnalyticsEnabledTeamcity teamcity = CtxListener.server(serverId, ctx, req);
collectHistory(history, teamcity, "IgniteTests24Java8_RunAll", "refs/heads/master");
@@ -131,16 +131,16 @@ public class Metrics {
@GET
@Path("failures")
public TestsMetrics getFailures() {
- final BackgroundUpdater updater = (BackgroundUpdater)context.getAttribute(CtxListener.UPDATER);
- return updater.get(FAILURES_PUBLIC, "", k -> getFailuresNoCache());
+ final BackgroundUpdater updater = CtxListener.getInjector(ctx).getInstance(BackgroundUpdater.class);
+ return updater.get(FAILURES_PUBLIC, null, "", k -> getFailuresNoCache(), false);
}
@GET
@Path("failuresPrivate")
- public TestsMetrics getFailuresPrivate(@Nullable @QueryParam("param") String msg) {
- final BackgroundUpdater updater = (BackgroundUpdater)context.getAttribute(CtxListener.UPDATER);
- return updater.get(FAILURES_PRIVATE, "", k -> getFailuresPrivateNoCache());
+ public TestsMetrics getFailuresPrivate(@Nullable @QueryParam("param") String msg) {
+ final BackgroundUpdater updater = CtxListener.getBackgroundUpdater(ctx);
+ return updater.get(FAILURES_PRIVATE, null, "", k -> getFailuresPrivateNoCache(), false);
}
@@ -156,7 +156,7 @@ public class Metrics {
if (!prov.hasAccess(srvId))
throw ServiceUnauthorizedException.noCreds(srvId);
- IAnalyticsEnabledTeamcity teamcity = CtxListener.server(srvId, context, req);
+ IAnalyticsEnabledTeamcity teamcity = CtxListener.server(srvId, ctx, req);
collectHistory(hist, teamcity, "id8xIgniteGridGainTestsJava8_RunAll", "refs/heads/master");