Commits

Anonymous committed 0903262

show number of seeded torrents

Comments (0)

Files changed (5)

common/src/jetbrains/buildServer/artifactsMirror/seeder/TorrentsDirectorySeeder.java

   public boolean isStopped() {
     return myStopped;
   }
+
+  public int getNumberOfSeededTorrents() {
+    return myTorrentSeeder.getNumberOfSeededTorrents();
+  }
 }
 

server/resources/torrentTracker.jsp

 <jsp:useBean id="torrentConfigurator" type="jetbrains.buildServer.artifactsMirror.TorrentConfigurator" scope="request"/>
 <jsp:useBean id="announcedTorrentsNum" type="java.lang.Integer" scope="request"/>
 <jsp:useBean id="connectedClientsNum" type="java.lang.Integer" scope="request"/>
+<jsp:useBean id="seededTorrentsNum" type="java.lang.Integer" scope="request"/>
 <form method="post" action="<c:url value='/admin/torrentTrackerSettings.html'/>">
 <table class="runnerFormTable">
 <tr>
 </tr>
 <tr>
   <th><label for="seederEnabled">Torrent seeder:</label></th>
-  <td><forms:checkbox name="seederEnabled" checked="${torrentConfigurator.seederEnabled}"/><label for="seederEnabled"> enable torrent seeder</label></td>
+  <td>
+    <forms:checkbox name="seederEnabled" checked="${torrentConfigurator.seederEnabled}"/><label for="seederEnabled"> enable torrent seeder</label>
+    <c:if test="${torrentConfigurator.seederEnabled}">
+    <ul style="margin-top:0; padding-left: 1em;">
+      <li>seeded torrents: <strong>${seededTorrentsNum}</strong></li>
+    </ul>
+    </c:if>
+  </td>
 </tr>
 <tr>
   <th><label for="fileSizeThresholdMb">Artifact size threshold:</label></th>

server/src/jetbrains/buildServer/artifactsMirror/ServerTorrentsDirectorySeeder.java

     return new File(getTorrentFilesBaseDir(build), torrentPath);
   }
 
+  public int getNumberOfSeededTorrents() {
+    return myTorrentsDirectorySeeder.getNumberOfSeededTorrents();
+  }
+
   private void announceBuildArtifacts(@NotNull final SBuild build) {
     final File artifactsDirectory = build.getArtifactsDirectory();
 

server/src/jetbrains/buildServer/artifactsMirror/web/TrackerAdminPage.java

  */
 package jetbrains.buildServer.artifactsMirror.web;
 
+import jetbrains.buildServer.artifactsMirror.ServerTorrentsDirectorySeeder;
 import jetbrains.buildServer.artifactsMirror.TorrentConfigurator;
 import jetbrains.buildServer.artifactsMirror.TorrentTrackerManager;
 import jetbrains.buildServer.controllers.BaseController;
   private static final String TAB_ID = "torrentTracker";
   private final TorrentTrackerManager myTorrentTrackerManager;
   private final TorrentConfigurator myTorrentConfigurator;
+  private final ServerTorrentsDirectorySeeder myTorrentSeeder;
 
   protected TrackerAdminPage(@NotNull PagePlaces pagePlaces,
                              @NotNull WebControllerManager controllerManager,
                              @NotNull PluginDescriptor descriptor,
                              @NotNull TorrentTrackerManager torrentTrackerManager,
-                             @NotNull TorrentConfigurator torrentConfigurator) {
+                             @NotNull TorrentConfigurator torrentConfigurator,
+                             @NotNull ServerTorrentsDirectorySeeder torrentSeeder) {
     super(pagePlaces, TAB_ID, descriptor.getPluginResourcesPath("torrentTracker.jsp"), "Torrent Tracker");
     myTorrentTrackerManager = torrentTrackerManager;
     myTorrentConfigurator = torrentConfigurator;
+    myTorrentSeeder = torrentSeeder;
     register();
 
     controllerManager.registerController("/admin/torrentTrackerSettings.html", new BaseController() {
     model.put("torrentConfigurator", myTorrentConfigurator);
     model.put("announcedTorrentsNum", myTorrentTrackerManager.getAnnouncedTorrentsNum());
     model.put("connectedClientsNum", myTorrentTrackerManager.getConnectedClientsNum());
+    model.put("seededTorrentsNum", myTorrentSeeder.getNumberOfSeededTorrents());
   }
 
   @NotNull

torrent/src/jetbrains/buildServer/artifactsMirror/torrent/TorrentSeeder.java

 import com.intellij.openapi.diagnostic.Logger;
 import com.turn.ttorrent.client.Client;
 import com.turn.ttorrent.client.SharedTorrent;
-import com.turn.ttorrent.client.peer.SharingPeer;
 import com.turn.ttorrent.common.Torrent;
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
 import java.io.File;
 import java.io.IOException;
 import java.net.InetAddress;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.UnknownHostException;
 import java.security.NoSuchAlgorithmException;
 
 public class TorrentSeeder {
     }
   }
 
-  public void start(@NotNull String rootUrl) {
-    try {
-      start(InetAddress.getByName(getClientHost(rootUrl)));
-    } catch (UnknownHostException e) {
-      LOG.warn("Failed to start torrent client: " + e.toString());
-    }
-  }
-
-  @Nullable
-  private String getClientHost(@NotNull String rootUrl) {
-    try {
-      return new URI(rootUrl).getHost();
-    } catch (URISyntaxException e) {
-      return null;
-    }
-  }
-
   public void stop() {
     myClient.stop(true);
   }
 
-  public int getConnectedClientsNum() {
-    int num = 0;
-    for (SharingPeer peer: myClient.getPeers()) {
-      if (peer.isDownloading() || peer.isConnected()) num++;
-    }
-
-    return num;
-  }
-
   public boolean seedTorrent(@NotNull File torrentFile, @NotNull File srcFile) {
     if (myClient == null) return false;
     try {
     }
     return false;
   }
+
+  public int getNumberOfSeededTorrents() {
+    return myClient.getTorrents().size();
+  }
 }