Ejemplo n.º 1
0
    def _setup_services(
        bootstrap_options: OptionValueContainer,
        graph_scheduler: GraphScheduler,
    ):
        """Initialize pantsd services.

        :returns: A PantsServices instance.
        """
        build_root = get_buildroot()

        invalidation_globs = GlobalOptions.compute_pantsd_invalidation_globs(
            build_root,
            bootstrap_options,
        )

        scheduler_service = SchedulerService(
            graph_scheduler=graph_scheduler,
            build_root=build_root,
            invalidation_globs=invalidation_globs,
            pidfile=PantsDaemon.metadata_file_path(
                "pantsd", "pid", bootstrap_options.pants_subprocessdir),
            pid=os.getpid(),
            max_memory_usage_in_bytes=bootstrap_options.
            pantsd_max_memory_usage,
        )

        store_gc_service = StoreGCService(graph_scheduler.scheduler)
        return PantsServices(services=(scheduler_service, store_gc_service))
Ejemplo n.º 2
0
        def _setup_services(build_root, bootstrap_options, legacy_graph_helper,
                            watchman):
            """Initialize pantsd services.

      :returns: A tuple of (`tuple` service_instances, `dict` port_map).
      """
            fs_event_service = FSEventService(
                watchman, build_root,
                bootstrap_options.pantsd_fs_event_workers)

            scheduler_service = SchedulerService(
                fs_event_service, legacy_graph_helper, build_root,
                bootstrap_options.pantsd_invalidation_globs)

            pailgun_service = PailgunService(
                bind_addr=(bootstrap_options.pantsd_pailgun_host,
                           bootstrap_options.pantsd_pailgun_port),
                exiter_class=DaemonExiter,
                runner_class=DaemonPantsRunner,
                target_roots_calculator=TargetRootsCalculator,
                scheduler_service=scheduler_service)

            store_gc_service = StoreGCService(legacy_graph_helper.scheduler)

            return (
                # Services.
                (fs_event_service, scheduler_service, pailgun_service,
                 store_gc_service),
                # Port map.
                dict(pailgun=pailgun_service.pailgun_port))
Ejemplo n.º 3
0
        def _setup_services(
            build_root,
            bootstrap_options,
            legacy_graph_scheduler,
            watchman,
            union_membership: UnionMembership,
        ):
            """Initialize pantsd services.

            :returns: A PantsServices instance.
            """
            should_shutdown_after_run = bootstrap_options.shutdown_pantsd_after_run
            fs_event_service = (FSEventService(
                watchman,
                build_root,
            ) if bootstrap_options.watchman_enable else None)

            pidfile_absolute = PantsDaemon.metadata_file_path(
                "pantsd", "pid", bootstrap_options.pants_subprocessdir)
            if pidfile_absolute.startswith(build_root):
                pidfile = os.path.relpath(pidfile_absolute, build_root)
            else:
                pidfile = None
                logging.getLogger(__name__).warning(
                    "Not watching pantsd pidfile because subprocessdir is outside of buildroot. Having "
                    "subprocessdir be a child of buildroot (as it is by default) may help avoid stray "
                    "pantsd processes.")

            # TODO make SchedulerService handle fs_event_service_being None
            scheduler_service = SchedulerService(
                fs_event_service=fs_event_service,
                legacy_graph_scheduler=legacy_graph_scheduler,
                build_root=build_root,
                invalidation_globs=OptionsInitializer.
                compute_pantsd_invalidation_globs(build_root,
                                                  bootstrap_options),
                pantsd_pidfile=pidfile,
                union_membership=union_membership,
            )

            pailgun_service = PailgunService(
                (bootstrap_options.pantsd_pailgun_host,
                 bootstrap_options.pantsd_pailgun_port),
                DaemonPantsRunner,
                scheduler_service,
                should_shutdown_after_run,
            )

            store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

            return PantsServices(
                services=tuple(service for service in (
                    fs_event_service,
                    scheduler_service,
                    pailgun_service,
                    store_gc_service,
                ) if service is not None),
                port_map=dict(pailgun=pailgun_service.pailgun_port),
            )
Ejemplo n.º 4
0
        def _setup_services(
            build_root,
            bootstrap_options,
            legacy_graph_scheduler,
            native,
            watchman,
            union_membership: UnionMembership,
        ):
            """Initialize pantsd services.

            :returns: A PantsServices instance.
            """
            native.override_thread_logging_destination_to_just_pantsd()
            fs_event_service = (
                FSEventService(
                    watchman, scheduler=legacy_graph_scheduler.scheduler, build_root=build_root
                )
                if bootstrap_options.watchman_enable
                else None
            )

            invalidation_globs = OptionsInitializer.compute_pantsd_invalidation_globs(
                build_root, bootstrap_options
            )

            scheduler_service = SchedulerService(
                fs_event_service=fs_event_service,
                legacy_graph_scheduler=legacy_graph_scheduler,
                build_root=build_root,
                invalidation_globs=invalidation_globs,
                union_membership=union_membership,
            )

            pailgun_service = PailgunService(
                bootstrap_options.pantsd_pailgun_port,
                DaemonPantsRunner(scheduler_service),
                scheduler_service,
            )

            store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

            return PantsServices(
                services=tuple(
                    service
                    for service in (
                        fs_event_service,
                        scheduler_service,
                        pailgun_service,
                        store_gc_service,
                    )
                    if service is not None
                ),
                port_map=dict(pailgun=pailgun_service.pailgun_port()),
            )
Ejemplo n.º 5
0
    def test_run(self):
        interval_secs = 0.1
        # Start the service in another thread (`setup` is a required part of the service lifecycle, but
        # is unused in this case.)
        sgcs = StoreGCService(
            self.scheduler.scheduler,
            period_secs=(interval_secs / 4),
            lease_extension_interval_secs=interval_secs,
            gc_interval_secs=interval_secs,
        )
        sgcs.setup(services=None)
        t = threading.Thread(target=sgcs.run, name="sgcs")
        t.daemon = True
        t.start()

        # Ensure that the thread runs successfully for long enough to have run each step at least once.
        # TODO: This is a coverage test: although it could examine the internal details of the service
        # to validate correctness, we don't do that yet.
        time.sleep(interval_secs * 10)
        assert t.is_alive()

        # Exit the thread, and then join it.
        sgcs.terminate()
        t.join(timeout=interval_secs * 10)
        assert not t.is_alive()
Ejemplo n.º 6
0
        def _setup_services(build_root, bootstrap_options,
                            legacy_graph_scheduler, watchman):
            """Initialize pantsd services.

      :returns: A PantsServices instance.
      """
            should_shutdown_after_run = bootstrap_options.shutdown_pantsd_after_run
            fs_event_service = FSEventService(
                watchman,
                build_root,
            )

            pidfile_absolute = PantsDaemon.metadata_file_path(
                'pantsd', 'pid', bootstrap_options.pants_subprocessdir)
            if pidfile_absolute.startswith(build_root):
                pidfile = os.path.relpath(pidfile_absolute, build_root)
            else:
                pidfile = None
                logging.getLogger(__name__).warning(
                    'Not watching pantsd pidfile because subprocessdir is outside of buildroot. Having '
                    'subprocessdir be a child of buildroot (as it is by default) may help avoid stray '
                    'pantsd processes.')

            scheduler_service = SchedulerService(
                fs_event_service,
                legacy_graph_scheduler,
                build_root,
                OptionsInitializer.compute_pantsd_invalidation_globs(
                    build_root, bootstrap_options),
                pidfile,
            )

            pailgun_service = PailgunService(
                (bootstrap_options.pantsd_pailgun_host,
                 bootstrap_options.pantsd_pailgun_port),
                DaemonPantsRunner,
                scheduler_service,
                should_shutdown_after_run,
            )

            store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

            return PantsServices(
                services=(fs_event_service, scheduler_service, pailgun_service,
                          store_gc_service),
                port_map=dict(pailgun=pailgun_service.pailgun_port),
            )
Ejemplo n.º 7
0
    def _setup_services(build_root, bootstrap_options, legacy_graph_scheduler, watchman):
      """Initialize pantsd services.

      :returns: A tuple of (`tuple` service_instances, `dict` port_map).
      """
      fs_event_service = FSEventService(
        watchman,
        build_root,
        bootstrap_options.pantsd_fs_event_workers
      )

      pidfile_absolute = PantsDaemon.metadata_file_path('pantsd', 'pid', bootstrap_options.pants_subprocessdir)
      if pidfile_absolute.startswith(build_root):
        pidfile = os.path.relpath(pidfile_absolute, build_root)
      else:
        pidfile = None
        logging.getLogger(__name__).warning(
          'Not watching pantsd pidfile because subprocessdir is outside of buildroot. Having '
          'subprocessdir be a child of buildroot (as it is by default) may help avoid stray '
          'pantsd processes.'
        )

      scheduler_service = SchedulerService(
        fs_event_service,
        legacy_graph_scheduler,
        build_root,
        bootstrap_options.pantsd_invalidation_globs,
        pidfile,
      )

      pailgun_service = PailgunService(
        bind_addr=(bootstrap_options.pantsd_pailgun_host, bootstrap_options.pantsd_pailgun_port),
        exiter_class=DaemonExiter,
        runner_class=DaemonPantsRunner,
        target_roots_calculator=TargetRootsCalculator,
        scheduler_service=scheduler_service
      )

      store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

      return (
        # Services.
        (fs_event_service, scheduler_service, pailgun_service, store_gc_service),
        # Port map.
        dict(pailgun=pailgun_service.pailgun_port)
      )
Ejemplo n.º 8
0
    def _setup_services(
        bootstrap_options: OptionValueContainer,
        legacy_graph_scheduler: LegacyGraphScheduler,
    ):
        """Initialize pantsd services.

        :returns: A PantsServices instance.
        """
        build_root = get_buildroot()

        # TODO: https://github.com/pantsbuild/pants/issues/3479
        watchman_launcher = WatchmanLauncher.create(bootstrap_options)
        watchman_launcher.maybe_launch()
        watchman = watchman_launcher.watchman
        fs_event_service = (FSEventService(
            watchman,
            scheduler=legacy_graph_scheduler.scheduler,
            build_root=build_root)
                            if bootstrap_options.watchman_enable else None)

        invalidation_globs = OptionsInitializer.compute_pantsd_invalidation_globs(
            build_root,
            bootstrap_options,
            PantsDaemon.metadata_file_path(
                "pantsd", "pid", bootstrap_options.pants_subprocessdir),
        )

        scheduler_service = SchedulerService(
            fs_event_service=fs_event_service,
            legacy_graph_scheduler=legacy_graph_scheduler,
            build_root=build_root,
            invalidation_globs=invalidation_globs,
            max_memory_usage_pid=os.getpid(),
            max_memory_usage_in_bytes=bootstrap_options.
            pantsd_max_memory_usage,
        )

        store_gc_service = StoreGCService(legacy_graph_scheduler.scheduler)

        return PantsServices(services=tuple(service for service in (
            fs_event_service,
            scheduler_service,
            store_gc_service,
        ) if service is not None), )