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/09/29 15:12:00 UTC
[ignite-teamcity-bot] branch master updated: TC_Recorder
implemented for tests and debug
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 f8f2c4e TC_Recorder implemented for tests and debug
f8f2c4e is described below
commit f8f2c4e75de50a65b34045bf77e0e29e5f8cc719
Author: Dmitriy Pavlov <dp...@apache.org>
AuthorDate: Sat Sep 29 18:11:57 2018 +0300
TC_Recorder implemented for tests and debug
---
.../ci/chain/TrackedBranchChainsProcessor.java | 2 +-
.../org/apache/ignite/ci/di/IgniteTcBotModule.java | 4 +-
.../ci/teamcity/FileRecordingInputStream.java | 90 ++++++++++++++++++++++
...ordingConnection.java => TeamcityRecorder.java} | 37 +++++++--
.../ci/teamcity/TeamcityRecordingConnection.java | 19 +----
.../java/org/apache/ignite/ci/web/CtxListener.java | 8 ++
.../ci/web/rest/monitoring/MonitoringService.java | 13 +---
7 files changed, 139 insertions(+), 34 deletions(-)
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/chain/TrackedBranchChainsProcessor.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/chain/TrackedBranchChainsProcessor.java
index f5bcfb0..05ed543 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/chain/TrackedBranchChainsProcessor.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/chain/TrackedBranchChainsProcessor.java
@@ -62,7 +62,7 @@ public class TrackedBranchChainsProcessor {
final BranchTracked tracked = HelperConfig.getTrackedBranches().getBranchMandatory(branchNn);
res.setTrackedBranch(branchNn);
- tracked.chains.stream().parallel()
+ tracked.chains.stream()
.filter(chainTracked -> creds.hasAccess(chainTracked.serverId))
.map(chainTracked -> {
final String srvId = chainTracked.serverId;
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 4ba758c..f50c25c 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
@@ -30,6 +30,7 @@ import org.apache.ignite.ci.jira.IJiraIntegration;
import org.apache.ignite.ci.observer.BuildObserver;
import org.apache.ignite.ci.observer.ObserverTask;
import org.apache.ignite.ci.teamcity.ITeamcityHttpConnection;
+import org.apache.ignite.ci.teamcity.TeamcityRecorder;
import org.apache.ignite.ci.teamcity.TeamcityRecordingConnection;
import org.apache.ignite.ci.user.ICredentialsProv;
import org.apache.ignite.ci.util.ExceptionUtil;
@@ -76,7 +77,8 @@ public class IgniteTcBotModule extends AbstractModule {
bind(ITcHelper.class).to(TcHelper.class).in(new SingletonScope());
bind(IJiraIntegration.class).to(Jira.class).in(new SingletonScope());
- bind(ITeamcityHttpConnection.class).to(TeamcityRecordingConnection.class).in(new SingletonScope());
+ bind(ITeamcityHttpConnection.class).to(TeamcityRecordingConnection.class);
+ bind(TeamcityRecorder.class).in(new SingletonScope());
}
//todo fallback to TC big class
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
new file mode 100644
index 0000000..0d136eb
--- /dev/null
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/FileRecordingInputStream.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ci.teamcity;
+
+import com.google.common.base.Charsets;
+import com.google.common.base.Preconditions;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
+
+public class FileRecordingInputStream extends FilterInputStream {
+
+ private final OutputStream file;
+ private final ReentrantLock lock;
+ private final AtomicBoolean closeGuard = new AtomicBoolean();
+
+ protected FileRecordingInputStream(InputStream in,
+ OutputStream file,
+ ReentrantLock lock) {
+ super(in);
+ this.file = file;
+ this.lock = lock;
+ }
+
+ @Override
+ public int read() throws IOException {
+ Preconditions.checkState(!closeGuard.get());
+
+ int readByte = super.read();
+
+ processByte(readByte);
+
+ return readByte;
+ }
+
+ @Override
+ public int read(@NotNull byte[] buffer, int offset, int count) throws IOException {
+ Preconditions.checkState(!closeGuard.get());
+
+ int readBytes = super.read(buffer, offset, count);
+
+ if (readBytes < 0)
+ return readBytes;
+
+ processBytes(buffer, offset, readBytes);
+
+ return readBytes;
+ }
+
+ private void processBytes(byte[] buffer, int offset, int readBytes) throws IOException {
+ file.write(buffer, offset, readBytes);
+ }
+
+ private void processByte(int readByte) throws IOException {
+ file.write(new byte[]{(byte) readByte});
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+
+ if (closeGuard.compareAndSet(false, true)) {
+ file.write("\n".getBytes(Charsets.UTF_8));
+
+ lock.unlock();
+
+ file.flush();
+ }
+ }
+}
\ No newline at end of file
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/TeamcityRecorder.java
similarity index 56%
copy from ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecordingConnection.java
copy to ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/teamcity/TeamcityRecorder.java
index 455a42f..62c20d1 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/TeamcityRecorder.java
@@ -14,25 +14,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.ignite.ci.teamcity;
-import org.apache.ignite.ci.util.HttpUtil;
+import com.google.common.base.Charsets;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.locks.ReentrantLock;
-public class TeamcityRecordingConnection implements ITeamcityHttpConnection {
+public class TeamcityRecorder {
private ConcurrentLinkedQueue<String> urls = new ConcurrentLinkedQueue<>();
+ private ReentrantLock lock = new ReentrantLock();
+
+ private OutputStream file;
- public InputStream sendGet(String basicAuthTok, String url) throws IOException {
+ public InputStream onGet(InputStream inputStream, String url) throws IOException {
urls.add(url);
- if(urls.size()>100)
+
+ if (urls.size() > 100)
urls.remove();
- return HttpUtil.sendGetWithBasicAuth(basicAuthTok, url);
+ if (Boolean.valueOf(System.getProperty("teamcity.bot.recorder"))) {
+ lock.lock();
+
+ if (file == null)
+ file = new FileOutputStream("tcrecorder.txt");
+
+ final String newUrlStartString =
+ "===HTTP=RECORDER=== GET " + url + "\n";
+ file.write(newUrlStartString.getBytes(Charsets.UTF_8));
+
+ return new FileRecordingInputStream(inputStream, file, lock);
+ }
+
+ return inputStream;
}
public List<String> getUrls() {
@@ -40,4 +58,9 @@ public class TeamcityRecordingConnection implements ITeamcityHttpConnection {
return list;
}
+
+ 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 455a42f..01e9bee 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
@@ -18,26 +18,15 @@ package org.apache.ignite.ci.teamcity;
import org.apache.ignite.ci.util.HttpUtil;
+import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ConcurrentLinkedQueue;
public class TeamcityRecordingConnection implements ITeamcityHttpConnection {
- private ConcurrentLinkedQueue<String> urls = new ConcurrentLinkedQueue<>();
+ @Inject
+ private TeamcityRecorder recorder;
public InputStream sendGet(String basicAuthTok, String url) throws IOException {
- urls.add(url);
- if(urls.size()>100)
- urls.remove();
-
- return HttpUtil.sendGetWithBasicAuth(basicAuthTok, url);
- }
-
- public List<String> getUrls() {
- final ArrayList<String> list = new ArrayList<>(urls);
-
- return list;
+ return recorder.onGet(HttpUtil.sendGetWithBasicAuth(basicAuthTok, url), url);
}
}
diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
index fa60de9..adb05a1 100644
--- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
+++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/web/CtxListener.java
@@ -17,6 +17,7 @@
package org.apache.ignite.ci.web;
+import java.io.IOException;
import java.util.concurrent.ExecutorService;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
@@ -35,6 +36,7 @@ import org.apache.ignite.ci.TcHelper;
import org.apache.ignite.ci.db.TcHelperDb;
import org.apache.ignite.ci.di.IgniteTcBotModule;
import org.apache.ignite.ci.observer.BuildObserver;
+import org.apache.ignite.ci.teamcity.TeamcityRecorder;
import org.apache.ignite.ci.user.ICredentialsProv;
import org.jetbrains.annotations.Nullable;
@@ -117,6 +119,12 @@ public class CtxListener implements ServletContextListener {
catch (Exception e) {
e.printStackTrace();
}
+
+ try {
+ injector.getInstance(TeamcityRecorder.class).stop();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
}
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 6a6257c..18750de 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
@@ -23,6 +23,7 @@ import org.apache.ignite.cache.affinity.Affinity;
import org.apache.ignite.ci.di.AutoProfilingInterceptor;
import org.apache.ignite.ci.di.MonitoredTaskInterceptor;
import org.apache.ignite.ci.teamcity.ITeamcityHttpConnection;
+import org.apache.ignite.ci.teamcity.TeamcityRecorder;
import org.apache.ignite.ci.teamcity.TeamcityRecordingConnection;
import org.apache.ignite.ci.web.CtxListener;
@@ -125,22 +126,14 @@ public class MonitoringService {
@PermitAll
@Path("urlsUsed")
public List<UrlUsed> getUrlsUsed() {
- final ITeamcityHttpConnection tcConn = CtxListener.getInjector(ctx).getInstance(ITeamcityHttpConnection.class);
+ final TeamcityRecorder recorder = CtxListener.getInjector(ctx).getInstance(TeamcityRecorder.class);
- if (!(tcConn instanceof TeamcityRecordingConnection)) {
- return Collections.emptyList();
- }
-
- final TeamcityRecordingConnection tcConn1 = (TeamcityRecordingConnection) tcConn;
-
- final List<String> urls = tcConn1.getUrls();
+ final List<String> urls = recorder.getUrls();
return urls.stream().map(s -> {
final UrlUsed urlRequested = new UrlUsed();
urlRequested.url = s;
return urlRequested;
}).collect(Collectors.toList());
-
-
}
}