ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpav...@apache.org
Subject [ignite-teamcity-bot] branch master updated: added button for Slack notifications testing (#155)
Date Sun, 08 Dec 2019 13:54:30 GMT
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 b59744c  added button for Slack notifications testing (#155)
b59744c is described below

commit b59744c5561bce2450ac235d7f1d73d477ab4ddb
Author: Ivan Rakov <ivan.glukos@gmail.com>
AuthorDate: Sun Dec 8 16:54:21 2019 +0300

    added button for Slack notifications testing (#155)
---
 .../ci/web/rest/monitoring/MonitoringService.java  | 39 +++++++++++++++++++---
 .../src/main/webapp/monitoring.html                | 18 ++++++++++
 2 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/MonitoringService.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/MonitoringService.java
index b631639..b1f2712 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/MonitoringService.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/monitoring/MonitoringService.java
@@ -16,26 +16,34 @@
  */
 package org.apache.ignite.ci.web.rest.monitoring;
 
-import javax.ws.rs.POST;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.ci.web.CtxListener;
+import org.apache.ignite.ci.web.model.SimpleResult;
 import org.apache.ignite.tcbot.common.interceptor.AutoProfilingInterceptor;
 import org.apache.ignite.tcbot.common.interceptor.MonitoredTaskInterceptor;
-import org.apache.ignite.ci.web.CtxListener;
+import org.apache.ignite.tcbot.engine.conf.INotificationChannel;
+import org.apache.ignite.tcbot.engine.conf.ITcBotConfig;
+import org.apache.ignite.tcbot.engine.conf.NotificationsConfig;
+import org.apache.ignite.tcbot.notify.ISlackSender;
 
 import javax.annotation.security.PermitAll;
 import javax.servlet.ServletContext;
 import javax.ws.rs.GET;
+import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
-import java.util.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
-import org.apache.ignite.ci.web.model.SimpleResult;
 
 @Path("monitoring")
 @Produces(MediaType.APPLICATION_JSON)
@@ -96,6 +104,29 @@ public class MonitoringService {
         return new SimpleResult("Ok");
     }
 
+    @POST
+    @PermitAll
+    @Path("testSlackNotification")
+    public SimpleResult testSlackNotification() {
+        ISlackSender slackSender = CtxListener.getInjector(ctx).getInstance(ISlackSender.class);
+
+        ITcBotConfig tcBotConfig = CtxListener.getInjector(ctx).getInstance(ITcBotConfig.class);
+
+        try {
+            NotificationsConfig notifications = tcBotConfig.notifications();
+
+            for (INotificationChannel channel : notifications.channels()) {
+                if (channel.slack() != null)
+                    slackSender.sendMessage(channel.slack(), "Test Slack notification message!",
notifications);
+            }
+        }
+        catch (IOException e) {
+            return new SimpleResult("Failed to send test Slack message: " + e.getMessage());
+        }
+
+        return new SimpleResult("Ok");
+    }
+
 
     @GET
     @PermitAll
diff --git a/ignite-tc-helper-web/src/main/webapp/monitoring.html b/ignite-tc-helper-web/src/main/webapp/monitoring.html
index 3a45436..0ef9f44 100644
--- a/ignite-tc-helper-web/src/main/webapp/monitoring.html
+++ b/ignite-tc-helper-web/src/main/webapp/monitoring.html
@@ -146,6 +146,19 @@
         });
     }
 
+    function testSlackNotification() {
+        $.ajax({
+            url: "rest/monitoring/testSlackNotification",
+            method: "post",
+            success: function(result) {
+                alert(JSON.stringify(result));
+            },
+            error: function(result) {
+                alert(JSON.stringify(result));
+            }
+        });
+    }
+
 </script>
 
 Tasks Monitoring Data:
@@ -162,6 +175,11 @@ Tasks Monitoring Data:
 <div id="caches" style="font-family: monospace"></div>
 
 <br>
+
+<hr>
+<b>Test Slack notification:</b> <button onclick="testSlackNotification()">Send</button>
+<br>
+
 <div id="loadStatus"></div>
 <div id="version"></div>
 


Mime
View raw message