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 13:54:01 UTC
[ignite-teamcity-bot] branch master updated: improve exception
handling - Fixes #28.
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 05fe9ed improve exception handling - Fixes #28.
05fe9ed is described below
commit 05fe9edc917ed50e65dde6ef6a3e8de6320d18cf
Author: Dmitrii Ryabov <So...@gmail.com>
AuthorDate: Thu Oct 4 16:53:03 2018 +0300
improve exception handling - Fixes #28.
Signed-off-by: Dmitriy Pavlov <dp...@apache.org>
---
.../main/java/org/apache/ignite/ci/ITcHelper.java | 5 +-
.../main/java/org/apache/ignite/ci/ITeamcity.java | 7 ++-
.../apache/ignite/ci/IgnitePersistentTeamcity.java | 3 +-
.../apache/ignite/ci/IgniteTeamcityConnection.java | 24 ++------
.../main/java/org/apache/ignite/ci/TcHelper.java | 18 +++---
.../org/apache/ignite/ci/di/IgniteTcBotModule.java | 2 +-
.../apache/ignite/ci/jira/IJiraIntegration.java | 5 +-
.../apache/ignite/ci/observer/ObserverTask.java | 7 ++-
.../apache/ignite/ci/web/rest/TriggerBuild.java | 72 +++++++++++++---------
.../ignite/ci/web/rest/pr/GetPrTestFailures.java | 10 ++-
10 files changed, 89 insertions(+), 64 deletions(-)
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 5c25432..5d68ce9 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
@@ -18,13 +18,11 @@
package org.apache.ignite.ci;
import java.util.List;
-import org.apache.ignite.ci.observer.BuildObserver;
import org.apache.ignite.ci.issue.IssueDetector;
import org.apache.ignite.ci.issue.IssuesStorage;
import org.apache.ignite.ci.user.ICredentialsProv;
import org.apache.ignite.ci.user.UserAndSessionsStorage;
-import javax.annotation.Nullable;
import java.util.Collection;
/**
@@ -43,7 +41,6 @@ public interface ITcHelper extends ITcServerProvider {
IssueDetector issueDetector();
-
ITcAnalytics tcAnalytics(String serverId);
UserAndSessionsStorage users();
@@ -62,5 +59,5 @@ public interface ITcHelper extends ITcServerProvider {
* @param ticket JIRA ticket full name.
* @return {@code True} if JIRA was notified.
*/
- boolean notifyJira(String srvId, ICredentialsProv prov, String buildTypeId, String branchForTc, String ticket);
+ String notifyJira(String srvId, ICredentialsProv prov, String buildTypeId, String branchForTc, String ticket);
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java
index 4989b31..e404b70 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/ITeamcity.java
@@ -18,6 +18,7 @@
package org.apache.ignite.ci;
import java.io.File;
+import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -37,7 +38,6 @@ import org.apache.ignite.ci.tcmodel.conf.BuildType;
import org.apache.ignite.ci.tcmodel.hist.BuildRef;
import org.apache.ignite.ci.tcmodel.result.Build;
import org.apache.ignite.ci.tcmodel.result.issues.IssuesUsagesList;
-import org.apache.ignite.ci.tcmodel.result.problems.ProblemOccurrence;
import org.apache.ignite.ci.tcmodel.result.problems.ProblemOccurrences;
import org.apache.ignite.ci.tcmodel.result.stat.Statistics;
import org.apache.ignite.ci.tcmodel.result.tests.TestOccurrence;
@@ -314,8 +314,11 @@ public interface ITeamcity {
* @param ticket JIRA ticket full name.
* @param comment Comment to be placed in the ticket conversation.
* @return {@code True} if ticket was succesfully commented. Otherwise - {@code false}.
+ *
+ * @throws IOException If failed to comment JIRA ticket.
+ * @throws IllegalStateException If can't find URL to the JIRA.
*/
- boolean sendJiraComment(String ticket, String comment);
+ String sendJiraComment(String ticket, String comment) throws IOException;
/**
* @param url URL for git integration.
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
index 82bea6d..35e5d63 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgnitePersistentTeamcity.java
@@ -21,6 +21,7 @@ import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import java.io.File;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -1162,7 +1163,7 @@ public class IgnitePersistentTeamcity implements IAnalyticsEnabledTeamcity, ITea
}
/** {@inheritDoc} */
- @Override public boolean sendJiraComment(String ticket, String comment) {
+ @Override public String sendJiraComment(String ticket, String comment) throws IOException {
return teamcity.sendJiraComment(ticket, comment);
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
index 2b2d365..aa0e76c 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/IgniteTeamcityConnection.java
@@ -194,25 +194,13 @@ public class IgniteTeamcityConnection implements ITeamcity {
/** {@inheritDoc} */
@AutoProfiling
- @Override public boolean sendJiraComment(String ticket, String comment) {
- if (isNullOrEmpty(jiraApiUrl)) {
- logger.error("Failed to notify JIRA [errMsg=JIRA API URL is not configured for this server.]");
+ @Override public String sendJiraComment(String ticket, String comment) throws IOException {
+ if (isNullOrEmpty(jiraApiUrl))
+ throw new IllegalStateException("JIRA API URL is not configured for this server.");
- return false;
- }
-
- try {
- String url = jiraApiUrl + "issue/" + ticket + "/comment";
-
- HttpUtil.sendPostAsStringToJira(jiraBasicAuthTok, url, "{\"body\": \"" + comment + "\"}");
+ String url = jiraApiUrl + "issue/" + ticket + "/comment";
- return true;
- }
- catch (IOException e) {
- logger.error("Failed to notify JIRA [errMsg="+e.getMessage()+']');
-
- return false;
- }
+ return HttpUtil.sendPostAsStringToJira(jiraBasicAuthTok, url, "{\"body\": \"" + comment + "\"}");
}
/** {@inheritDoc} */
@@ -238,7 +226,7 @@ public class IgniteTeamcityConnection implements ITeamcity {
/** {@inheritDoc} */
@AutoProfiling
@Override public PullRequest getPullRequest(String branchForTc) {
- if (!isNullOrEmpty(gitApiUrl))
+ if (isNullOrEmpty(gitApiUrl))
throw new IllegalStateException("Git API URL is not configured for this server.");
String id = null;
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 a0e0efc..51484c6 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
@@ -112,7 +112,7 @@ public class TcHelper implements ITcHelper, IJiraIntegration {
}
/** {@inheritDoc} */
- @Override public boolean notifyJira(
+ @Override public String notifyJira(
String srvId,
ICredentialsProv prov,
String buildTypeId,
@@ -124,22 +124,26 @@ public class TcHelper implements ITcHelper, IJiraIntegration {
List<BuildRef> builds = teamcity.getFinishedBuildsIncludeSnDepFailed(buildTypeId, branchForTc);
if (builds.isEmpty())
- return false;
+ return "JIRA wasn't commented - no finished builds to analyze.";
BuildRef build = builds.get(builds.size() - 1);
String comment;
try {
comment = generateJiraComment(buildTypeId, build.branchName, srvId, prov, build.webUrl);
+
+ teamcity.sendJiraComment(ticket, comment);
}
- catch (RuntimeException e) {
- logger.error("Exception happened during generating comment for JIRA " +
- "[build=" + build.getId() + ", errMsg=" + e.getMessage() + ']');
+ catch (Exception e) {
+ String errMsg = "Exception happened during commenting JIRA ticket " +
+ "[build=" + build.getId() + ", errMsg=" + e.getMessage() + ']';
+
+ logger.error(errMsg);
- return false;
+ return "JIRA wasn't commented - " + errMsg;
}
- return teamcity.sendJiraComment(ticket, comment);
+ return JIRA_COMMENTED;
}
/**
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 5ee9e62..b09ace1 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
@@ -85,7 +85,7 @@ public class IgniteTcBotModule extends AbstractModule {
private static class Jira implements IJiraIntegration {
@Inject ITcHelper helper;
- @Override public boolean notifyJira(String srvId, ICredentialsProv prov, String buildTypeId, String branchForTc,
+ @Override public String notifyJira(String srvId, ICredentialsProv prov, String buildTypeId, String branchForTc,
String ticket) {
return helper.notifyJira(srvId, prov, buildTypeId, branchForTc, ticket);
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/IJiraIntegration.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/IJiraIntegration.java
index 919a679..633ab3a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/IJiraIntegration.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/jira/IJiraIntegration.java
@@ -23,6 +23,9 @@ import org.apache.ignite.ci.user.ICredentialsProv;
*
*/
public interface IJiraIntegration {
+ /** Message to show user when JIRA ticket was successfully commented by the Bot. */
+ public static String JIRA_COMMENTED = "JIRA commented.";
+
/**
* @param srvId TC Server ID to take information about token from.
* @param prov Credentials.
@@ -31,6 +34,6 @@ public interface IJiraIntegration {
* @param ticket JIRA ticket full name.
* @return {@code True} if JIRA was notified.
*/
- public boolean notifyJira(String srvId, ICredentialsProv prov, String buildTypeId, String branchForTc,
+ public String notifyJira(String srvId, ICredentialsProv prov, String buildTypeId, String branchForTc,
String ticket);
}
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 823cc07..374099b 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
@@ -32,6 +32,8 @@ import org.apache.ignite.ci.tcmodel.result.Build;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.ignite.ci.jira.IJiraIntegration.JIRA_COMMENTED;
+
/**
* Checks observed builds for finished status and comments JIRA ticket.
*/
@@ -86,7 +88,10 @@ public class ObserverTask extends TimerTask {
continue;
}
- if (jiraIntegration.notifyJira(info.srvId, info.prov, info.build.buildTypeId, info.build.branchName, info.ticket)) {
+ String jiraRes = jiraIntegration.notifyJira(info.srvId, info.prov, info.build.buildTypeId,
+ info.build.branchName, info.ticket);
+
+ if (JIRA_COMMENTED.equals(jiraRes)) {
ticketsNotified.add(info.ticket);
builds.remove(info);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java
index 6a0ce3a..83e7911 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/TriggerBuild.java
@@ -77,7 +77,7 @@ public class TriggerBuild {
Build build = teamcity.triggerBuild(suiteId, branchForTc, false, top != null && top);
if (observe != null && observe)
- jiraRes = observeJira(srvId, branchForTc, ticketId, helper, teamcity, build, prov);
+ jiraRes = observeJira(srvId, branchForTc, ticketId, teamcity, build, prov);
return new SimpleResult("Tests started." + (!jiraRes.isEmpty() ? "<br>" + jiraRes : ""));
}
@@ -102,7 +102,12 @@ public class TriggerBuild {
}
@NotNull
- public SimpleResult commentJiraEx(@QueryParam("serverId") @Nullable String srvId, @QueryParam("branchName") @Nullable String branchForTc, @QueryParam("suiteId") @Nullable String suiteId, @QueryParam("ticketId") @Nullable String ticketId) {
+ public SimpleResult commentJiraEx(
+ @QueryParam("serverId") @Nullable String srvId,
+ @QueryParam("branchName") @Nullable String branchForTc,
+ @QueryParam("suiteId") @Nullable String suiteId,
+ @QueryParam("ticketId") @Nullable String ticketId
+ ) {
final ICredentialsProv prov = ICredentialsProv.get(req);
if (!prov.hasAccess(srvId))
@@ -114,25 +119,31 @@ public class TriggerBuild {
final ITeamcity teamcity = helper.server(srvId, prov);
if (Strings.isNullOrEmpty(ticketId)) {
- PullRequest pr = teamcity.getPullRequest(branchForTc);
-
- ticketId = getTicketId(pr);
-
- if (ticketId.isEmpty()) {
- jiraRes = "JIRA ticket can't be commented - " +
- "PR title \"" + pr.getTitle() + "\" should starts with \"IGNITE-XXXX\"." +
- " Please, rename PR according to the" +
- " <a href='https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute" +
- "#HowtoContribute-1.CreateGitHubpull-request'>contributing guide</a>" +
- " or enter ticket id in the form.";
+ try {
+ PullRequest pr = teamcity.getPullRequest(branchForTc);
+
+ ticketId = getTicketId(pr);
+
+ if (ticketId.isEmpty()) {
+ jiraRes = "JIRA ticket can't be commented - " +
+ "PR title \"" + pr.getTitle() + "\" should starts with \"IGNITE-XXXX\"." +
+ " Please, rename PR according to the" +
+ " <a href='https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute" +
+ "#HowtoContribute-1.CreateGitHubpull-request'>contributing guide</a>" +
+ " or enter ticket id in the form.";
+ }
+ }
+ catch (RuntimeException e) {
+ jiraRes = "Exception happened when server tried to get ticket ID from Pull Request - " + e.getMessage();
}
-
}
- if (helper.notifyJira(srvId, prov, suiteId, branchForTc, "ignite-" + ticketId))
- return new SimpleResult("JIRA commented." + (!jiraRes.isEmpty() ? jiraRes : ""));
+ if (!Strings.isNullOrEmpty(ticketId)) {
+ jiraRes = helper.notifyJira(srvId, prov, suiteId, branchForTc, "ignite-" + ticketId);
+
+ return new SimpleResult(jiraRes);
+ }
else
- // TODO Write catched exceptions to the response.
return new SimpleResult("JIRA wasn't commented." + (!jiraRes.isEmpty() ? "<br>" + jiraRes : ""));
}
@@ -140,7 +151,6 @@ public class TriggerBuild {
* @param srvId Server id.
* @param branchForTc Branch for TeamCity.
* @param ticketId JIRA ticket number.
- * @param helper Helper.
* @param teamcity TeamCity.
* @param build Build.
* @param prov Credentials.
@@ -150,22 +160,28 @@ public class TriggerBuild {
String srvId,
String branchForTc,
@Nullable String ticketId,
- ITcHelper helper,
ITeamcity teamcity,
Build build,
ICredentialsProv prov
) {
if (F.isEmpty(ticketId)) {
- PullRequest pr = teamcity.getPullRequest(branchForTc);
-
- ticketId = getTicketId(pr);
-
- if (ticketId.isEmpty()) {
+ try {
+ PullRequest pr = teamcity.getPullRequest(branchForTc);
+
+ ticketId = getTicketId(pr);
+
+ if (ticketId.isEmpty()) {
+ return "JIRA ticket will not be notified after the tests are completed - " +
+ "PR title \"" + pr.getTitle() + "\" should starts with \"IGNITE-XXXX\"." +
+ " Please, rename PR according to the" +
+ " <a href='https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute" +
+ "#HowtoContribute-1.CreateGitHubpull-request'>contributing guide</a>.";
+ }
+ }
+ catch (Exception e) {
return "JIRA ticket will not be notified after the tests are completed - " +
- "PR title \"" + pr.getTitle() + "\" should starts with \"IGNITE-XXXX\"." +
- " Please, rename PR according to the" +
- " <a href='https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute" +
- "#HowtoContribute-1.CreateGitHubpull-request'>contributing guide</a>.";
+ "exception happened when server tried to get ticket ID from Pull Request [errMsg=" +
+ e.getMessage() + ']';
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java
index e05a6c5..e113b6a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/pr/GetPrTestFailures.java
@@ -134,7 +134,15 @@ public class GetPrTestFailures {
IAnalyticsEnabledTeamcity teamcity = CtxListener.server(srvId, ctx, req);
- PullRequest pr = teamcity.getPullRequest(branchForTc);
+ PullRequest pr;
+
+ try {
+ pr = teamcity.getPullRequest(branchForTc);
+ }
+ catch (RuntimeException e) {
+ return "Exception happened - " + e.getMessage();
+ }
+
String statusesUrl = pr.getStatusesUrl();
teamcity.notifyGit(statusesUrl, msg);