Search in sources :

Example 1 with TorrentConfigurator

use of jetbrains.buildServer.torrent.TorrentConfigurator in project teamcity-torrent-plugin by JetBrains.

the class TorrentSettingsAdminPage method fillModel.

@Override
public void fillModel(@NotNull Map<String, Object> model, @NotNull HttpServletRequest request) {
    super.fillModel(model, request);
    model.put("torrentConfigurator", myTorrentConfigurator);
    model.put("announcedTorrentsNum", myTorrentTrackerManager.getAnnouncedTorrentsNum());
    model.put("connectedClientsNum", myTorrentTrackerManager.getConnectedClientsNum());
    model.put("seededTorrentsNum", myTorrentSeeder.getNumberOfSeededTorrents());
    model.put("activePeersCount", myTorrentSeeder.getPeers().size());
    final double speedBytesPerSecond = myTorrentSeeder.getPeers().stream().mapToDouble(it -> it.getULRate().get()).sum();
    final DecimalFormat decimalFormat = new DecimalFormat("#.###");
    model.put("totalSpeedMegabytesPerSecond", decimalFormat.format(speedBytesPerSecond / (1024 * 1024)));
}
Also used : PagePlaces(jetbrains.buildServer.web.openapi.PagePlaces) TorrentTrackerManager(jetbrains.buildServer.torrent.TorrentTrackerManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) DecimalFormat(java.text.DecimalFormat) BaseController(jetbrains.buildServer.controllers.BaseController) AdminPage(jetbrains.buildServer.controllers.admin.AdminPage) PluginDescriptor(jetbrains.buildServer.web.openapi.PluginDescriptor) ServerTorrentsDirectorySeeder(jetbrains.buildServer.torrent.ServerTorrentsDirectorySeeder) AuthorizationInterceptor(jetbrains.buildServer.controllers.AuthorizationInterceptor) ModelAndView(org.springframework.web.servlet.ModelAndView) HttpServletRequest(javax.servlet.http.HttpServletRequest) AccessDeniedException(jetbrains.buildServer.serverSide.auth.AccessDeniedException) RedirectView(org.springframework.web.servlet.view.RedirectView) Permission(jetbrains.buildServer.serverSide.auth.Permission) TorrentConfigurator(jetbrains.buildServer.torrent.TorrentConfigurator) Map(java.util.Map) SecurityContext(jetbrains.buildServer.serverSide.auth.SecurityContext) WebControllerManager(jetbrains.buildServer.web.openapi.WebControllerManager) NotNull(org.jetbrains.annotations.NotNull) DecimalFormat(java.text.DecimalFormat)

Example 2 with TorrentConfigurator

use of jetbrains.buildServer.torrent.TorrentConfigurator in project teamcity-torrent-plugin by JetBrains.

the class TrackerControllerTest method createController.

@Override
@SuppressWarnings("unchecked")
protected TrackerController createController() throws IOException {
    Mockery m = new Mockery();
    final XmlRpcHandlerManager rpcHandlerManager = m.mock(XmlRpcHandlerManager.class);
    final AddressChecker addressChecker = m.mock(AddressChecker.class);
    AuthorizationInterceptor interceptor = m.mock(AuthorizationInterceptor.class);
    m.checking(new Expectations() {

        {
            allowing(rpcHandlerManager).addHandler(with(any(String.class)), with(any(Object.class)));
            allowing(interceptor).addPathNotRequiringAuth(with(any(String.class)));
            allowing(addressChecker).isBadAddress(with(any(String.class)));
            will(returnValue(false));
        }
    });
    final TorrentConfigurator configurator = new TorrentConfigurator(new ServerPaths(createTempDir().getAbsolutePath()), myFixture.getSingletonService(RootUrlHolder.class), rpcHandlerManager);
    myTorrentTrackerManager = new TorrentTrackerManager(configurator, myFixture.getSingletonService(ExecutorServices.class), myFixture.getSingletonService(EventDispatcher.class), addressChecker);
    myTorrentTrackerManager.startTracker();
    return new TrackerController(myWebManager, myTorrentTrackerManager, interceptor);
}
Also used : XmlRpcHandlerManager(jetbrains.buildServer.XmlRpcHandlerManager) Expectations(org.jmock.Expectations) AddressChecker(com.turn.ttorrent.tracker.AddressChecker) RootUrlHolder(jetbrains.buildServer.RootUrlHolder) AuthorizationInterceptor(jetbrains.buildServer.controllers.AuthorizationInterceptor) TorrentConfigurator(jetbrains.buildServer.torrent.TorrentConfigurator) Mockery(org.jmock.Mockery) ServerPaths(jetbrains.buildServer.serverSide.ServerPaths) TorrentTrackerManager(jetbrains.buildServer.torrent.TorrentTrackerManager)

Aggregations

AuthorizationInterceptor (jetbrains.buildServer.controllers.AuthorizationInterceptor)2 TorrentConfigurator (jetbrains.buildServer.torrent.TorrentConfigurator)2 TorrentTrackerManager (jetbrains.buildServer.torrent.TorrentTrackerManager)2 AddressChecker (com.turn.ttorrent.tracker.AddressChecker)1 DecimalFormat (java.text.DecimalFormat)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 RootUrlHolder (jetbrains.buildServer.RootUrlHolder)1 XmlRpcHandlerManager (jetbrains.buildServer.XmlRpcHandlerManager)1 BaseController (jetbrains.buildServer.controllers.BaseController)1 AdminPage (jetbrains.buildServer.controllers.admin.AdminPage)1 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)1 AccessDeniedException (jetbrains.buildServer.serverSide.auth.AccessDeniedException)1 Permission (jetbrains.buildServer.serverSide.auth.Permission)1 SecurityContext (jetbrains.buildServer.serverSide.auth.SecurityContext)1 ServerTorrentsDirectorySeeder (jetbrains.buildServer.torrent.ServerTorrentsDirectorySeeder)1 PagePlaces (jetbrains.buildServer.web.openapi.PagePlaces)1 PluginDescriptor (jetbrains.buildServer.web.openapi.PluginDescriptor)1 WebControllerManager (jetbrains.buildServer.web.openapi.WebControllerManager)1