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 d419ebc IGNITE-10498: Fix for handling conflict error returned by
TeamCity for some build problem
d419ebc is described below
commit d419ebc43ed88c1ffcc3a9e92bdd0613c77de78a
Author: Dmitriy Pavlov <[email protected]>
AuthorDate: Wed May 29 19:52:24 2019 +0300
IGNITE-10498: Fix for handling conflict error returned by TeamCity for some
build problem
---
.../main/java/org/apache/ignite/ci/ITeamcity.java | 4 ++++
.../apache/ignite/ci/IgniteTeamcityConnection.java | 15 +++++++++++++++
.../ci/tcbot/common/StringFieldCompacted.java | 2 +-
.../ignited/fatbuild/ProactiveFatBuildSync.java | 7 +++++--
.../teamcity/ignited/fatbuild/TestCompacted.java | 2 +-
.../ignite/ci/teamcity/pure/ITeamcityConn.java | 22 +++++++++++++++++++++-
.../ci/teamcity/pure/ITeamcityHttpConnection.java | 5 +++++
.../teamcity/pure/TeamcityRecordingConnection.java | 3 +++
.../java/org/apache/ignite/ci/util/HttpUtil.java | 21 ++++++++++++++++-----
.../org/apache/ignite/ci/web/model/Version.java | 2 +-
.../rest/exception/ConflictException.java} | 19 +++++++++++--------
.../exception/ServiceUnauthorizedException.java | 3 +++
12 files changed, 86 insertions(+), 19 deletions(-)
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 6f933c8..d935bb4 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
@@ -81,5 +81,9 @@ public interface ITeamcity extends ITeamcityConn {
Base64Util.encodeUtf8String(user + ":" + pwd));
}
+ /**
+ * @param username Username.
+ * @throws RuntimeException in case loading failed, see details in {@link
ITeamcityConn}.
+ */
User getUserByUsername(String username);
}
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 6f5574f..314a923 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
@@ -73,11 +73,13 @@ import org.apache.ignite.ci.tcmodel.result.stat.Statistics;
import org.apache.ignite.ci.tcmodel.result.tests.TestOccurrencesFull;
import org.apache.ignite.ci.tcmodel.user.User;
import org.apache.ignite.ci.tcmodel.user.Users;
+import org.apache.ignite.ci.teamcity.pure.ITeamcityConn;
import org.apache.ignite.ci.teamcity.pure.ITeamcityHttpConnection;
import org.apache.ignite.ci.util.ExceptionUtil;
import org.apache.ignite.ci.util.HttpUtil;
import org.apache.ignite.ci.util.XmlUtil;
import org.apache.ignite.ci.util.ZipUtil;
+import org.apache.ignite.ci.web.rest.exception.ConflictException;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -324,6 +326,15 @@ public class IgniteTeamcityConnection implements ITeamcity
{
.getBuildTypesNonNull();
}
+ /**
+ * @param url Url.
+ * @param rootElem Root elem.
+ *
+ * @throws UncheckedIOException caused by FileNotFoundException - If not
found (404) was returned from service.
+ * @throws ConflictException If conflict (409) was returned from service.
+ * @throws IllegalStateException if some unexpected HTTP error returned.
+ * @throws UncheckedIOException in case communication failed.
+ */
private <T> T sendGetXmlParseJaxb(String url, Class<T> rootElem) {
try {
try (InputStream inputStream =
teamcityHttpConn.sendGet(basicAuthTok, url)) {
@@ -417,6 +428,10 @@ public class IgniteTeamcityConnection implements ITeamcity
{
this.executor = executor;
}
+ /**
+ *
+ * @throws RuntimeException in case loading failed. See details in {@link
ITeamcityConn}.
+ */
@AutoProfiling
public Users getUsers() {
return getJaxbUsingHref("app/rest/latest/users", Users.class);
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/common/StringFieldCompacted.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/common/StringFieldCompacted.java
index 9a2dfd3..739b471 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/common/StringFieldCompacted.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/tcbot/common/StringFieldCompacted.java
@@ -129,7 +129,7 @@ public class StringFieldCompacted {
data = gzip;
}
- logger.info("U " + uncompressed.length + " S " + snappyLen + " Z " +
gzipLen + ": F (" +
+ logger.debug("U " + uncompressed.length + " S " + snappyLen + " Z " +
gzipLen + ": F (" +
flag + ")");
}
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/ProactiveFatBuildSync.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/ProactiveFatBuildSync.java
index 826ee4a..8c72f3e 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/ProactiveFatBuildSync.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/ProactiveFatBuildSync.java
@@ -36,6 +36,7 @@ import
org.apache.ignite.ci.teamcity.ignited.change.ChangeSync;
import org.apache.ignite.ci.teamcity.ignited.runhist.RunHistSync;
import org.apache.ignite.ci.teamcity.pure.ITeamcityConn;
import org.apache.ignite.ci.util.ExceptionUtil;
+import org.apache.ignite.ci.web.rest.exception.ConflictException;
import org.apache.ignite.internal.util.GridConcurrentHashSet;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@@ -323,7 +324,7 @@ public class ProactiveFatBuildSync {
* @param conn
* @param buildId
* @param existingBuild
- * @return new build if it was updated or null if no updates detected
+ * @return new build if it was updated or <code>null</code> if no updates
detected
*/
@SuppressWarnings({"WeakerAccess"})
@AutoProfiling
@@ -382,7 +383,9 @@ public class ProactiveFatBuildSync {
}
}
catch (Exception e) {
- if (Throwables.getRootCause(e) instanceof FileNotFoundException) {
+ Throwable cause = Throwables.getRootCause(e);
+
+ if (cause instanceof FileNotFoundException || cause instanceof
ConflictException) {
logger.info("Loading build [" + buildId + "] for server [" +
srvName + "] failed:" + e.getMessage(), e);
if (existingBuild != null) {
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/TestCompacted.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/TestCompacted.java
index cf5fca5..b0060ee 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/TestCompacted.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ignited/fatbuild/TestCompacted.java
@@ -263,7 +263,7 @@ public class TestCompacted {
}
- logger.info("U " + uncompressed.length + " S " + snappyLen + " Z " +
gzipLen + ": F (" +
+ logger.debug("U " + uncompressed.length + " S " + snappyLen + " Z " +
gzipLen + ": F (" +
flags.get(COMPRESS_TYPE_FLAG1) + ", " +
flags.get(COMPRESS_TYPE_FLAG2) +")");
}
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
index bdf7885..934b58f 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityConn.java
@@ -17,6 +17,8 @@
package org.apache.ignite.ci.teamcity.pure;
+import java.io.FileNotFoundException;
+import java.io.UncheckedIOException;
import java.util.List;
import java.util.Map;
import java.util.SortedSet;
@@ -36,10 +38,18 @@ import org.apache.ignite.ci.tcmodel.result.Build;
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.TestOccurrencesFull;
+import org.apache.ignite.ci.web.rest.exception.ConflictException;
/**
* Pure Teamcity Connection API for calling methods from REST service: <br>
- * https://confluence.jetbrains.com/display/TCD10/REST+API
+ * https://confluence.jetbrains.com/display/TCD10/REST+API.<br><br>
+ *
+ *
+ * HTTP methods return following errors in case HTTP communication failures:
+ * <ul><li>{@link UncheckedIOException} caused by {@link
FileNotFoundException} - If not found (404) was returned from service.</li>
+ * <li>{@link ConflictException} If conflict (409) was returned from
service.</li>
+ * <li>{@link IllegalStateException} if some unexpected HTTP error
returned.</li>
+ * <li>{@link UncheckedIOException} in case communication failed.</ul>
*/
public interface ITeamcityConn {
/**
@@ -62,6 +72,8 @@ public interface ITeamcityConn {
/**
* @param buildId Build id.
+ *
+ * @throws RuntimeException in case loading failed, see details in {@link
ITeamcityConn}.
*/
public Build getBuild(int buildId);
@@ -102,21 +114,29 @@ public interface ITeamcityConn {
/**
* @param buildId Build id.
+ *
+ * @throws RuntimeException in case loading failed, see details in {@link
ITeamcityConn}.
*/
public ProblemOccurrences getProblems(int buildId);
/**
* @param buildId Build id.
+ *
+ * @throws RuntimeException in case loading failed, see details in {@link
ITeamcityConn}.
*/
public Statistics getStatistics(int buildId);
/**
* @param buildId Build id.
+ *
+ * @throws RuntimeException in case loading failed, see details in {@link
ITeamcityConn}.
*/
public ChangesList getChangesList(int buildId);
/**
* @param changeId Change id.
+ *
+ * @throws RuntimeException in case loading failed, see details in {@link
ITeamcityConn}.
*/
public Change getChange(int changeId);
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityHttpConnection.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityHttpConnection.java
index 8f26955..950f7a5 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityHttpConnection.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityHttpConnection.java
@@ -17,13 +17,18 @@
package org.apache.ignite.ci.teamcity.pure;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.ignite.ci.web.rest.exception.ConflictException;
public interface ITeamcityHttpConnection {
/**
* @param basicAuthTok Basic auth token.
* @param url Url.
+ * @throws FileNotFoundException If not found (404) was returned from
service.
+ * @throws ConflictException If conflict (409) was returned from service.
+ * @throws IllegalStateException if some unexpected HTTP error returned.
*/
public InputStream sendGet(String basicAuthTok, String url) throws
IOException;
}
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TeamcityRecordingConnection.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TeamcityRecordingConnection.java
index b5125d7..4b0306c 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TeamcityRecordingConnection.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/TeamcityRecordingConnection.java
@@ -22,6 +22,9 @@ import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
+/**
+ *
+ */
public class TeamcityRecordingConnection implements ITeamcityHttpConnection {
/** Recorder. */
@Inject private TeamcityRecorder recorder;
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java
index a7e047a..b39a4b4 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/util/HttpUtil.java
@@ -33,6 +33,7 @@ import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import org.apache.ignite.ci.web.rest.exception.ConflictException;
import org.apache.ignite.ci.web.rest.exception.ServiceUnauthorizedException;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@@ -73,6 +74,9 @@ public class HttpUtil {
* @param url URL.
* @return Input stream from connection.
* @throws IOException If failed.
+ * @throws FileNotFoundException If not found (404) was returned from
service.
+ * @throws ConflictException If conflict (409) was returned from service.
+ * @throws IllegalStateException if some unexpected HTTP error returned.
*/
public static InputStream sendGetWithBasicAuth(String basicAuthTok, String
url) throws IOException {
final Stopwatch started = Stopwatch.createStarted();
@@ -171,7 +175,10 @@ public class HttpUtil {
*
* @param con Http connection.
* @return Input stream from connection.
- * @throws IOException If failed.
+ * @throws IOException If communication failed.
+ * @throws FileNotFoundException If not found (404) was returned from
service.
+ * @throws ConflictException If conflict (409) was returned from service.
+ * @throws IllegalStateException if some unexpected HTTP error returned.
*/
private static InputStream getInputStream(HttpURLConnection con) throws
IOException {
int resCode = con.getResponseCode();
@@ -180,18 +187,22 @@ public class HttpUtil {
if (resCode / 100 == 2)
return con.getInputStream();
+ String detailsFromResponeText = readIsToString(con.getErrorStream());
+
if (resCode == 400)
- throw new
BadRequestException(readIsToString(con.getErrorStream()));
+ throw new BadRequestException(detailsFromResponeText);
if (resCode == 401)
throw new ServiceUnauthorizedException("Service " + con.getURL() +
" returned forbidden error.");
if (resCode == 404)
- throw new FileNotFoundException("Service " + con.getURL() + "
returned not found error."
- + readIsToString(con.getErrorStream()));
+ throw new FileNotFoundException("Service " + con.getURL() + "
returned not found error. " + detailsFromResponeText);
+
+ if (resCode == 409)
+ throw new ConflictException("Service " + con.getURL() + " returned
Conflict Response Code :\n" + detailsFromResponeText);
throw new IllegalStateException("Service " + con.getURL() + " returned
Invalid Response Code : " + resCode + ":\n"
- + readIsToString(con.getErrorStream()));
+ + detailsFromResponeText);
}
/**
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
index 25a6ec6..49c0d72 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/model/Version.java
@@ -28,7 +28,7 @@ package org.apache.ignite.ci.web.model;
public static final String GITHUB_REF =
"https://github.com/apache/ignite-teamcity-bot";
/** TC Bot Version. */
- public static final String VERSION = "20190516";
+ public static final String VERSION = "20190529";
/** Java version, where Web App is running. */
public String javaVer;
diff --git
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityHttpConnection.java
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/exception/ConflictException.java
similarity index 68%
copy from
ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityHttpConnection.java
copy to
ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/exception/ConflictException.java
index 8f26955..f46b3f7 100644
---
a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/pure/ITeamcityHttpConnection.java
+++
b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/rest/exception/ConflictException.java
@@ -15,15 +15,18 @@
* limitations under the License.
*/
-package org.apache.ignite.ci.teamcity.pure;
+package org.apache.ignite.ci.web.rest.exception;
-import java.io.IOException;
-import java.io.InputStream;
-
-public interface ITeamcityHttpConnection {
+/**
+ * The request could not be completed due to a conflict with the current state
of the target resource.
+ *
+ * This exception is thrown in case HTTP 409-Conflict is returned.
+ */
+public class ConflictException extends RuntimeException {
/**
- * @param basicAuthTok Basic auth token.
- * @param url Url.
+ * @param msg Message.
*/
- public InputStream sendGet(String basicAuthTok, String url) throws
IOException;
+ public ConflictException(String msg) {
+ super(msg);
+ }
}
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 80e4b5a..2978e6a 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
@@ -21,6 +21,9 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
+/**
+ * Exception is thrown if 3rd party service returned 401 - unauthorized.
+ */
@Provider
public class ServiceUnauthorizedException extends RuntimeException
implements ExceptionMapper<ServiceUnauthorizedException> {