[ 
https://issues.apache.org/jira/browse/IGNITE-9901?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16662051#comment-16662051
 ] 

ASF GitHub Bot commented on IGNITE-9901:
----------------------------------------

asfgit closed pull request #39: IGNITE-9901 Persistent queue for visas added
URL: https://github.com/apache/ignite-teamcity-bot/pull/39
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITcHelper.java 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITcHelper.java
index 00623f7..356b633 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITcHelper.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITcHelper.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.ci;
 
+import java.util.Collection;
 import java.util.List;
 import org.apache.ignite.ci.issue.IssueDetector;
 import org.apache.ignite.ci.issue.IssuesStorage;
@@ -24,8 +25,6 @@
 import org.apache.ignite.ci.user.ICredentialsProv;
 import org.apache.ignite.ci.user.UserAndSessionsStorage;
 
-import java.util.Collection;
-
 /**
  * Teamcity Bot main interface
  */
@@ -52,6 +51,15 @@
 
     List<String> getTrackedBranchesIds();
 
+    /** */
+    void setServerAuthorizerCreds(ICredentialsProv creds);
+
+    /** */
+    ICredentialsProv getServerAuthorizerCreds();
+
+    /** */
+    boolean isServerAuthorized();
+
     /**
      * @param srvId Server id.
      * @param prov Credentials.
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/TcHelper.java 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/TcHelper.java
index 5e0422d..1bd64e9 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/TcHelper.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/TcHelper.java
@@ -54,6 +54,9 @@
     /** Stop guard. */
     private AtomicBoolean stop = new AtomicBoolean();
 
+    /** Server authorizer credentials. */
+    private ICredentialsProv serverAuthorizerCreds;
+
     @Inject private IssuesStorage issuesStorage;
 
     @Inject private ITcServerProvider serverProvider;
@@ -67,6 +70,21 @@
     public TcHelper() {
     }
 
+    /** {@inheritDoc} */
+    @Override public void setServerAuthorizerCreds(ICredentialsProv creds) {
+        this.serverAuthorizerCreds = creds;
+    }
+
+    /** {@inheritDoc} */
+    @Override public ICredentialsProv getServerAuthorizerCreds() {
+        return serverAuthorizerCreds;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isServerAuthorized() {
+        return !Objects.isNull(serverAuthorizerCreds);
+    }
+
     /** {@inheritDoc} */
     @Override public IssuesStorage issues() {
         return issuesStorage;
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildObserver.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildObserver.java
index f8a7ac3..1e08eb8 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildObserver.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildObserver.java
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.ci.observer;
 
+import java.util.Collection;
 import java.util.Objects;
-import java.util.Queue;
 import java.util.Timer;
 import javax.inject.Inject;
 import org.apache.ignite.ci.tcmodel.result.Build;
@@ -61,7 +61,7 @@ public void stop() {
      * @param ticket JIRA ticket name.
      */
     public void observe(String srvId, ICredentialsProv prov, String ticket, 
Build... builds) {
-        observerTask.builds.add(new BuildsInfo(srvId, prov, ticket, builds));
+        observerTask.addBuild(new BuildsInfo(srvId, prov, ticket, builds));
     }
 
     /**
@@ -70,7 +70,7 @@ public void observe(String srvId, ICredentialsProv prov, 
String ticket, Build...
      */
     public String getObservationStatus(String srvId, String branch) {
         StringBuilder sb = new StringBuilder();
-        Queue<BuildsInfo> builds = observerTask.builds;
+        Collection<BuildsInfo> builds = observerTask.getBuilds();
 
         for (BuildsInfo bi : builds) {
             if (Objects.equals(bi.branchName, branch)
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildsInfo.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildsInfo.java
index e318f19..ba8b48a 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildsInfo.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/BuildsInfo.java
@@ -37,9 +37,6 @@
     /** Branch name. */
     public final String branchName;
 
-    /** Credentials. */
-    public final ICredentialsProv prov;
-
     /** JIRA ticket full name. */
     public final String ticket;
 
@@ -54,7 +51,6 @@
      */
     public BuildsInfo(String srvId, ICredentialsProv prov, String ticket, 
Build[] builds) {
         this.srvId = srvId;
-        this.prov = prov;
         this.ticket = ticket;
         this.buildTypeId = builds.length > 1 ? "IgniteTests24Java8_RunAll" : 
builds[0].buildTypeId;
         this.branchName = builds[0].branchName;
@@ -104,13 +100,12 @@ public int finishedBuildsCount(){
         return Objects.equals(srvId, info.srvId) &&
             Objects.equals(buildTypeId, info.buildTypeId) &&
             Objects.equals(branchName, info.branchName) &&
-            Objects.equals(prov, info.prov) &&
             Objects.equals(ticket, info.ticket) &&
-            Objects.equals(finishedBuilds, info.finishedBuilds);
+            Objects.equals(finishedBuilds.keySet(), 
info.finishedBuilds.keySet());
     }
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        return Objects.hash(srvId, buildTypeId, branchName, prov, ticket, 
finishedBuilds);
+        return Objects.hash(srvId, buildTypeId, branchName, ticket, 
finishedBuilds.keySet());
     }
 }
diff --git 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/ObserverTask.java
 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/ObserverTask.java
index 5cbda2e..1e9fc76 100644
--- 
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/ObserverTask.java
+++ 
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/observer/ObserverTask.java
@@ -17,17 +17,21 @@
 
 package org.apache.ignite.ci.observer;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Queue;
 import java.util.Set;
 import java.util.TimerTask;
-import java.util.concurrent.ConcurrentLinkedQueue;
 import javax.inject.Inject;
+import org.apache.ignite.Ignite;
 import org.apache.ignite.ci.IAnalyticsEnabledTeamcity;
-import org.apache.ignite.ci.teamcity.pure.ITcServerProvider;
+import org.apache.ignite.ci.ITcHelper;
 import org.apache.ignite.ci.di.AutoProfiling;
 import org.apache.ignite.ci.di.MonitoredTask;
 import org.apache.ignite.ci.jira.IJiraIntegration;
+import org.apache.ignite.ci.user.ICredentialsProv;
+import org.apache.ignite.configuration.CollectionConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,18 +45,32 @@
     private static final Logger logger = 
LoggerFactory.getLogger(ObserverTask.class);
 
     /** Helper. */
-    @Inject private ITcServerProvider srvProvider;
+    @Inject private ITcHelper tcHelper;
 
     /** Helper. */
     @Inject private IJiraIntegration jiraIntegration;
 
-    /** Builds. */
-    final Queue<BuildsInfo> builds;
+    /** Ignite. */
+    @Inject private Ignite ignite;
 
     /**
      */
     ObserverTask() {
-        builds = new ConcurrentLinkedQueue<>();
+    }
+
+    /** */
+    private Queue<BuildsInfo> buildsQueue() {
+        return ignite.queue("buildsQueue", 0, new CollectionConfiguration());
+    }
+
+    /** */
+    public Collection<BuildsInfo> getBuilds() {
+        return Collections.unmodifiableCollection(buildsQueue());
+    }
+
+    /** */
+    public void addBuild(BuildsInfo build) {
+        buildsQueue().add(build);
     }
 
     /** {@inheritDoc} */
@@ -71,14 +89,19 @@
     @AutoProfiling
     @MonitoredTask(name = "Build Observer")
     protected String runObserverTask() {
+        if (!tcHelper.isServerAuthorized())
+            return "Server authorization required.";
+
         int checkedBuilds = 0;
         int notFinishedBuilds = 0;
         Set<String> ticketsNotified = new HashSet<>();
 
+        Queue<BuildsInfo> builds = buildsQueue();
+
         for (BuildsInfo info : builds) {
             checkedBuilds += info.buildsCount();
 
-            IAnalyticsEnabledTeamcity teamcity = 
srvProvider.server(info.srvId, info.prov);
+            IAnalyticsEnabledTeamcity teamcity = tcHelper.server(info.srvId, 
tcHelper.getServerAuthorizerCreds());
 
             if (!info.isFinished(teamcity)) {
                 notFinishedBuilds += info.buildsCount() - 
info.finishedBuildsCount();
@@ -86,7 +109,9 @@ protected String runObserverTask() {
                 continue;
             }
 
-            String jiraRes = jiraIntegration.notifyJira(info.srvId, info.prov, 
info.buildTypeId,
+            ICredentialsProv creds = tcHelper.getServerAuthorizerCreds();
+
+            String jiraRes = jiraIntegration.notifyJira(info.srvId, creds, 
info.buildTypeId,
                 info.branchName, info.ticket);
 
             if (JIRA_COMMENTED.equals(jiraRes)) {
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 e4c957e..26680ce 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
@@ -27,17 +27,18 @@
 import javax.annotation.Nonnull;
 import javax.inject.Inject;
 import javax.ws.rs.QueryParam;
-import org.apache.ignite.ci.tcmodel.hist.BuildRef;
-import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnited;
-import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnitedProvider;
+import org.apache.ignite.ci.ITcHelper;
 import org.apache.ignite.ci.github.GitHubUser;
+import org.apache.ignite.ci.github.PullRequest;
 import org.apache.ignite.ci.github.ignited.IGitHubConnIgnitedProvider;
 import org.apache.ignite.ci.github.pure.IGitHubConnection;
 import org.apache.ignite.ci.github.pure.IGitHubConnectionProvider;
-import org.apache.ignite.ci.github.PullRequest;
 import org.apache.ignite.ci.jira.IJiraIntegration;
 import org.apache.ignite.ci.observer.BuildObserver;
+import org.apache.ignite.ci.tcmodel.hist.BuildRef;
 import org.apache.ignite.ci.tcmodel.result.Build;
+import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnited;
+import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnitedProvider;
 import org.apache.ignite.ci.user.ICredentialsProv;
 import org.apache.ignite.ci.web.model.SimpleResult;
 import org.apache.ignite.internal.util.typedef.F;
@@ -65,6 +66,14 @@
 
     @Inject Provider<BuildObserver> observer;
 
+    /** Helper. */
+    @Inject ITcHelper tcHelper;
+
+    /** */
+    public void startObserver() {
+        buildObserverProvider.get();
+    }
+
     /**
      * @param pr Pull Request.
      * @return JIRA ticket full name or empty string.
@@ -154,7 +163,11 @@ private String observeJira(
 
         buildObserverProvider.get().observe(srvId, prov, ticketFullName, 
builds);
 
-        return "JIRA ticket IGNITE-" + ticketFullName + " will be notified 
after the tests are completed.";
+        if (!tcHelper.isServerAuthorized())
+            return "Ask server administrator to authorize the Bot to enable 
JIRA notifications.";
+
+        return "JIRA ticket IGNITE-" + ticketFullName +
+            " will be notified after the tests are completed.";
     }
 
     /**
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 43feeae..c257a7e 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
@@ -17,9 +17,9 @@
 
 package org.apache.ignite.ci.web.rest.login;
 
-
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
+import com.google.inject.Injector;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.FormParam;
@@ -31,10 +31,9 @@
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Form;
 import javax.ws.rs.core.MediaType;
-
-import com.google.inject.Injector;
 import org.apache.ignite.ci.ITcHelper;
 import org.apache.ignite.ci.issue.IssueDetector;
+import org.apache.ignite.ci.tcbot.visa.TcBotTriggerAndSignOffService;
 import org.apache.ignite.ci.tcmodel.user.User;
 import org.apache.ignite.ci.teamcity.pure.ITcLogin;
 import org.apache.ignite.ci.user.ICredentialsProv;
@@ -91,10 +90,14 @@ public SimpleResult setAuthorizedState() {
 
         final ITcHelper helper = CtxListener.getTcHelper(ctx);
 
+        helper.setServerAuthorizerCreds(prov);
+
         IssueDetector detector = helper.issueDetector();
 
         detector.startBackgroundCheck(helper, prov);
 
+        
CtxListener.getInjector(ctx).getInstance(TcBotTriggerAndSignOffService.class).startObserver();
+
         return userMenu(prov, helper);
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [TC Bot] Exclude losses of visa requests while TC Bot server reloading
> ----------------------------------------------------------------------
>
>                 Key: IGNITE-9901
>                 URL: https://issues.apache.org/jira/browse/IGNITE-9901
>             Project: Ignite
>          Issue Type: Task
>            Reporter: PetrovMikhail
>            Assignee: PetrovMikhail
>            Priority: Major
>
> Exclude losses of visa requests while TC Bot server reloading



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to