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/03 16:44:58 UTC
[ignite-teamcity-bot] 02/02: Cleanup code and version update
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
commit 4a8fdeb728e6e76757ec4b24215fe67750c69003
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Wed Oct 3 19:44:50 2018 +0300
Cleanup code and version update
---
.../apache/ignite/ci/IgniteTeamcityConnection.java | 34 +++++++++------
.../ci/teamcity/FileRecordingInputStream.java | 40 ++++++++++++-----
.../org/apache/ignite/ci/teamcity/ITcLogin.java | 12 ++++-
.../ci/teamcity/ITeamcityHttpConnection.java | 6 ++-
.../ci/teamcity/TcConnectionStaticLinker.java | 16 +++++--
.../org/apache/ignite/ci/teamcity/TcLoginImpl.java | 23 ++++++----
.../ignite/ci/teamcity/TcRealConnectionModule.java | 7 ++-
.../ignite/ci/teamcity/TeamcityRecorder.java | 51 +++++++++++++++++-----
.../ci/teamcity/TeamcityRecordingConnection.java | 6 +--
.../org/apache/ignite/ci/web/model/Version.java | 2 +-
10 files changed, 139 insertions(+), 58 deletions(-)
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 3d68ccb..4c873b1 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
@@ -86,17 +86,20 @@ public class IgniteTeamcityConnection implements ITeamcity {
/** Logger. */
private static final Logger logger = LoggerFactory.getLogger(IgniteTeamcityConnection.class);
+ /** Executor. */
private Executor executor;
+
+ /** Logs directory. */
private File logsDir;
+
/** Normalized Host address, ends with '/'. */
private String host;
/** TeamCity authorization token. */
private String basicAuthTok;
- @Inject
- private ITeamcityHttpConnection teamcityHttpConnection;
-
+ /** Teamcity http connection. */
+ @Inject private ITeamcityHttpConnection teamcityHttpConn;
/** GitHub authorization token. */
private String gitAuthTok;
@@ -113,6 +116,7 @@ public class IgniteTeamcityConnection implements ITeamcity {
private String configName; //main properties file name
private String tcName;
+ /** Build logger processing running. */
private ConcurrentHashMap<Integer, CompletableFuture<LogCheckTask>> buildLogProcessingRunning = new ConcurrentHashMap<>();
public void init(@Nullable String tcName) {
@@ -285,8 +289,8 @@ public class IgniteTeamcityConnection implements ITeamcity {
boolean archive = true;
Supplier<File> supplier = () -> {
String buildIdStr = Integer.toString(buildId);
- final File buildDirectory = ensureDirExist(new File(logsDir, "buildId" + buildIdStr));
- final File file = new File(buildDirectory,
+ final File buildDir = ensureDirExist(new File(logsDir, "buildId" + buildIdStr));
+ final File file = new File(buildDir,
"build.log" + (archive ? ".zip" : ""));
if (file.exists() && file.canRead() && file.length() > 0) {
logger.info("Nothing to do, file is cached locally: [" + file + "]");
@@ -311,13 +315,13 @@ public class IgniteTeamcityConnection implements ITeamcity {
@Override public CompletableFuture<LogCheckResult> analyzeBuildLog(Integer buildId, SingleBuildRunCtx ctx) {
final Stopwatch started = Stopwatch.createStarted();
- CompletableFuture<LogCheckTask> future = buildLogProcessingRunning.computeIfAbsent(buildId,
+ CompletableFuture<LogCheckTask> fut = buildLogProcessingRunning.computeIfAbsent(buildId,
k -> checkBuildLogNoCache(k, ctx)
);
- return future
+ return fut
.thenApply(task -> {
- buildLogProcessingRunning.remove(buildId, future);
+ buildLogProcessingRunning.remove(buildId, fut);
return task;
})
@@ -470,7 +474,7 @@ public class IgniteTeamcityConnection implements ITeamcity {
private <T> T sendGetXmlParseJaxb(String url, Class<T> rootElem) {
try {
- try (InputStream inputStream = teamcityHttpConnection.sendGet(basicAuthTok, url)) {
+ try (InputStream inputStream = teamcityHttpConn.sendGet(basicAuthTok, url)) {
final InputStreamReader reader = new InputStreamReader(inputStream);
return loadXml(rootElem, reader);
@@ -721,8 +725,9 @@ public class IgniteTeamcityConnection implements ITeamcity {
return task;
}
- @Override
- public void setExecutor(ExecutorService executor) {
+ /** {@inheritDoc} */
+ @AutoProfiling
+ @Override public void setExecutor(ExecutorService executor) {
this.executor = executor;
}
@@ -731,12 +736,13 @@ public class IgniteTeamcityConnection implements ITeamcity {
return getJaxbUsingHref("app/rest/latest/users", Users.class);
}
+ /** {@inheritDoc} */
@AutoProfiling
- public User getUserByUsername(String username) {
+ @Override public User getUserByUsername(String username) {
return getJaxbUsingHref("app/rest/latest/users/username:" + username, User.class);
}
- public void setHttpConn(ITeamcityHttpConnection teamcityRecordingConnection) {
- this.teamcityHttpConnection = teamcityRecordingConnection;
+ public void setHttpConn(ITeamcityHttpConnection teamcityHttpConn) {
+ this.teamcityHttpConn = teamcityHttpConn;
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/FileRecordingInputStream.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/FileRecordingInputStream.java
index 0d136eb..25e6854 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/FileRecordingInputStream.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/FileRecordingInputStream.java
@@ -28,12 +28,22 @@ import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
+/**
+ * Recording stream, which will copy all responses to a logging file.
+ */
public class FileRecordingInputStream extends FilterInputStream {
-
+ /** File. */
private final OutputStream file;
+ /** Lock to be held until stream is closed. */
private final ReentrantLock lock;
+ /** Close guard. */
private final AtomicBoolean closeGuard = new AtomicBoolean();
+ /**
+ * @param in In.
+ * @param file File.
+ * @param lock Lock.
+ */
protected FileRecordingInputStream(InputStream in,
OutputStream file,
ReentrantLock lock) {
@@ -42,8 +52,8 @@ public class FileRecordingInputStream extends FilterInputStream {
this.lock = lock;
}
- @Override
- public int read() throws IOException {
+ /** {@inheritDoc} */
+ @Override public int read() throws IOException {
Preconditions.checkState(!closeGuard.get());
int readByte = super.read();
@@ -53,30 +63,38 @@ public class FileRecordingInputStream extends FilterInputStream {
return readByte;
}
- @Override
- public int read(@NotNull byte[] buffer, int offset, int count) throws IOException {
+ /** {@inheritDoc} */
+ @Override public int read(@NotNull byte[] buf, int off, int cnt) throws IOException {
Preconditions.checkState(!closeGuard.get());
- int readBytes = super.read(buffer, offset, count);
+ int readBytes = super.read(buf, off, cnt);
if (readBytes < 0)
return readBytes;
- processBytes(buffer, offset, readBytes);
+ processBytes(buf, off, readBytes);
return readBytes;
}
- private void processBytes(byte[] buffer, int offset, int readBytes) throws IOException {
- file.write(buffer, offset, readBytes);
+ /**
+ * @param buf Buffer.
+ * @param off Offset.
+ * @param readBytes Read bytes.
+ */
+ private void processBytes(byte[] buf, int off, int readBytes) throws IOException {
+ file.write(buf, off, readBytes);
}
+ /**
+ * @param readByte Read byte.
+ */
private void processByte(int readByte) throws IOException {
file.write(new byte[]{(byte) readByte});
}
- @Override
- public void close() throws IOException {
+ /** {@inheritDoc} */
+ @Override public void close() throws IOException {
super.close();
if (closeGuard.compareAndSet(false, true)) {
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITcLogin.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITcLogin.java
index 76139bf..867da4a 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITcLogin.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITcLogin.java
@@ -18,6 +18,16 @@ package org.apache.ignite.ci.teamcity;
import org.apache.ignite.ci.tcmodel.user.User;
+/**
+ * Teamcity Login implementation.
+ */
public interface ITcLogin {
- User checkServiceUserAndPassword(String serverId, String username, String password);
+ /**
+ * Check if user has correct credentials to particular server.
+ * @param srvId Server id.
+ * @param username Username.
+ * @param pwd Password.
+ * @return user settings on this teamcity
+ */
+ public User checkServiceUserAndPassword(String srvId, String username, String pwd);
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITeamcityHttpConnection.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITeamcityHttpConnection.java
index 4a6dd3c..bfb0976 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITeamcityHttpConnection.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/ITeamcityHttpConnection.java
@@ -21,5 +21,9 @@ import java.io.IOException;
import java.io.InputStream;
public interface ITeamcityHttpConnection {
- InputStream sendGet(String basicAuthTok, String url) throws IOException;
+ /**
+ * @param basicAuthTok Basic auth token.
+ * @param url Url.
+ */
+ public InputStream sendGet(String basicAuthTok, String url) throws IOException;
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcConnectionStaticLinker.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcConnectionStaticLinker.java
index c8ece96..2decbb1 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcConnectionStaticLinker.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcConnectionStaticLinker.java
@@ -18,11 +18,19 @@ package org.apache.ignite.ci.teamcity;
import org.apache.ignite.ci.IgniteTeamcityConnection;
+/**
+ * Factory for non-guice creation of TC Connection instance.
+ */
public class TcConnectionStaticLinker {
+ /**
+ * @param srv Server ID.
+ */
public static IgniteTeamcityConnection create(String srv) {
- final IgniteTeamcityConnection connection = new IgniteTeamcityConnection();
- connection.setHttpConn(new TeamcityRecordingConnection());
- connection.init(srv);
- return connection;
+ final IgniteTeamcityConnection conn = new IgniteTeamcityConnection();
+
+ conn.setHttpConn(new TeamcityRecordingConnection());
+ conn.init(srv);
+
+ return conn;
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcLoginImpl.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcLoginImpl.java
index 68f4e09..590b6e8 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcLoginImpl.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcLoginImpl.java
@@ -17,7 +17,6 @@
package org.apache.ignite.ci.teamcity;
import org.apache.ignite.ci.ITeamcity;
-import org.apache.ignite.ci.IgniteTeamcityConnection;
import org.apache.ignite.ci.tcmodel.user.User;
import org.apache.ignite.ci.web.rest.exception.ServiceUnauthorizedException;
import org.slf4j.Logger;
@@ -26,19 +25,23 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
+/**
+ * Real implementation of login based on getting current user preferences from the server.
+ */
public class TcLoginImpl implements ITcLogin {
/** Logger. */
private static final Logger logger = LoggerFactory.getLogger(TcLoginImpl.class);
- @Inject
- private Provider<ITeamcity> tcFactory;
+ /** Teamcity connection non-caching factory. */
+ @Inject private Provider<ITeamcity> tcFactory;
- public User checkServiceUserAndPassword(String serverId, String username, String password) {
+ /** {@inheritDoc} */
+ @Override public User checkServiceUserAndPassword(String srvId, String username, String pwd) {
try {
ITeamcity tcConn = tcFactory.get();
- tcConn.init(serverId);
+ tcConn.init(srvId);
- tcConn.setAuthData(username, password);
+ tcConn.setAuthData(username, pwd);
final User tcUser = tcConn.getUserByUsername(username);
@@ -55,13 +58,15 @@ public class TcLoginImpl implements ITcLogin {
logger.info("TC user returned: " + tcUser);
return tcUser;
- } catch (ServiceUnauthorizedException e) {
- final String msg = "Service " + serverId + " rejected credentials from " + username;
+ }
+ catch (ServiceUnauthorizedException e) {
+ final String msg = "Service " + srvId + " rejected credentials from " + username;
System.err.println(msg);
logger.warn(msg, e);
return null;
- } catch (Exception e) {
+ }
+ catch (Exception e) {
e.printStackTrace();
logger.error("Unexpected login exception", e);
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcRealConnectionModule.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcRealConnectionModule.java
index c022a5a..e71c678 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcRealConnectionModule.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TcRealConnectionModule.java
@@ -19,9 +19,12 @@ package org.apache.ignite.ci.teamcity;
import com.google.inject.AbstractModule;
import com.google.inject.internal.SingletonScope;
+/**
+ * Guice module to setup real connected server and all related implementations.
+ */
public class TcRealConnectionModule extends AbstractModule {
- @Override
- protected void configure() {
+ /** {@inheritDoc} */
+ @Override protected void configure() {
bind(ITeamcityHttpConnection.class).to(TeamcityRecordingConnection.class);
bind(TeamcityRecorder.class).in(new SingletonScope());
bind(ITcLogin.class).to(TcLoginImpl.class).in(new SingletonScope());
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecorder.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecorder.java
index 62c20d1..40ec487 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecorder.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecorder.java
@@ -25,40 +25,67 @@ import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantLock;
+/**
+ *
+ */
public class TeamcityRecorder {
+ /** Urls. */
private ConcurrentLinkedQueue<String> urls = new ConcurrentLinkedQueue<>();
+
+ /** Lock. */
private ReentrantLock lock = new ReentrantLock();
+ /** File. */
private OutputStream file;
+ /**
+ * @param inputStream Input stream.
+ * @param url Url.
+ */
public InputStream onGet(InputStream inputStream, String url) throws IOException {
- urls.add(url);
+ if (Boolean.valueOf(System.getProperty("teamcity.bot.recorder.urls"))) {
+ urls.add(url);
- if (urls.size() > 100)
- urls.remove();
+ if (urls.size() > 100)
+ urls.remove();
+ }
if (Boolean.valueOf(System.getProperty("teamcity.bot.recorder"))) {
+ boolean success = false;
+
lock.lock();
+ try {
+ if (file == null)
+ file = new FileOutputStream("tcrecorder.txt");
+
+ final String newUrlStartStr = "===HTTP=RECORDER=== GET " + url + "\n";
+ file.write(newUrlStartStr.getBytes(Charsets.UTF_8));
- if (file == null)
- file = new FileOutputStream("tcrecorder.txt");
+ FileRecordingInputStream spyStream = new FileRecordingInputStream(inputStream, file, lock);
- final String newUrlStartString =
- "===HTTP=RECORDER=== GET " + url + "\n";
- file.write(newUrlStartString.getBytes(Charsets.UTF_8));
+ success = true;
- return new FileRecordingInputStream(inputStream, file, lock);
+ return spyStream;
+ }
+ finally {
+ if(!success)
+ lock.unlock();;
+ }
}
return inputStream;
}
+ /**
+ *
+ */
public List<String> getUrls() {
- final ArrayList<String> list = new ArrayList<>(urls);
-
- return list;
+ return new ArrayList<>(urls);
}
+ /**
+ *
+ */
public void stop() throws IOException {
if (file != null)
file.close();
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecordingConnection.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecordingConnection.java
index 01e9bee..4b41e1c 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecordingConnection.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecordingConnection.java
@@ -23,10 +23,10 @@ import java.io.IOException;
import java.io.InputStream;
public class TeamcityRecordingConnection implements ITeamcityHttpConnection {
- @Inject
- private TeamcityRecorder recorder;
+ @Inject private TeamcityRecorder recorder;
- public InputStream sendGet(String basicAuthTok, String url) throws IOException {
+ /** {@inheritDoc} */
+ @Override public InputStream sendGet(String basicAuthTok, String url) throws IOException {
return recorder.onGet(HttpUtil.sendGetWithBasicAuth(basicAuthTok, url), url);
}
}
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 20f983a..6b54c2f 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
@@ -21,7 +21,7 @@ package org.apache.ignite.ci.web.model;
/** Default contact. */
public static final String DEFAULT_CONTACT = "dev@ignite.apache.org";
public static final String GITHUB_REF = "https://github.com/apache/ignite-teamcity-bot";
- public static final String VERSION = "20180928";
+ public static final String VERSION = "20181003";
/** TC Helper Version. */
public String version = VERSION;