public void Configuration(IAppBuilder app)
        {
            //app.UseErrorPage();

            //  search test console

            app.Use(async (context, next) =>
            {
                if (String.Equals(context.Request.Path.Value, "/console", StringComparison.OrdinalIgnoreCase))
                {
                    // Redirect to trailing slash to maintain relative links
                    context.Response.Redirect(context.Request.PathBase + context.Request.Path + "/");
                    context.Response.StatusCode = 301;
                    return;
                }
                else if (String.Equals(context.Request.Path.Value, "/console/", StringComparison.OrdinalIgnoreCase))
                {
                    context.Request.Path = new PathString("/console/Index.html");
                }
                await next();
            });

            app.UseStaticFiles(new StaticFileOptions(new SharedOptions
            {
                RequestPath = new PathString("/console"),
                FileSystem = new EmbeddedResourceFileSystem(typeof(Startup).Assembly, "NuGet.Services.BasicSearch.Console")
            }));

            //  start the service running - the Lucene index needs to be reopened regularly on a background thread
            string searchIndexRefresh = System.Configuration.ConfigurationManager.AppSettings.Get("Search.IndexRefresh") ?? "15";
            int seconds;
            if (!int.TryParse(searchIndexRefresh, out seconds))
            {
                seconds = 15;
            }

            _searcherManager = CreateSearcherManager();

            _searcherManager.Open();

            _gate = 0;
            _timer = new Timer(new TimerCallback(ReopenCallback), 0, 0, seconds * 1000);

            app.Run(Invoke);
        }
Example #2
0
        private bool InitializeSearcherManager(IndexingConfiguration config, Directory directory, ILoader loader, ILoggerFactory loggerFactory)
        {
            const int maxRetries = 10;

            try
            {
                Retry.Incremental(
                    () =>
                {
                    var stopwatch = Stopwatch.StartNew();

                    _searcherManager = NuGetSearcherManager.Create(config, loggerFactory, directory, loader);
                    _searcherManager.Open();

                    stopwatch.Stop();

                    _searchTelemetryClient.TrackMetric(
                        SearchTelemetryClient.MetricName.SearchIndexReopenDuration, stopwatch.Elapsed.TotalSeconds);

                    TrackIndexMetrics(_searcherManager, _searchTelemetryClient);
                },
                    shouldRetry: e =>
                {
                    // Retry on any exception (but log it)
                    _logger.LogError("Startup: An error occurred initializing searcher manager. Going to retry... Exception: {Exception}",
                                     e);
                    _searchTelemetryClient.TrackMetric(SearchTelemetryClient.MetricName.SearchIndexReopenFailed, 1);

                    return(true);
                },
                    maxRetries: maxRetries,
                    waitIncrement: TimeSpan.FromSeconds(1));

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogCritical("Startup: A critical error occurred initializing searcher manager. Number of retries exhausted. Exception: {Exception}", e);
                _searchTelemetryClient.TrackMetric(SearchTelemetryClient.MetricName.SearchIndexReopenFailed, maxRetries);

                return(false);
            }
        }
        public void Configuration(IAppBuilder app)
        {
            app.UseErrorPage();

            //  search test console

            app.Use(async(context, next) =>
            {
                if (String.Equals(context.Request.Path.Value, "/console", StringComparison.OrdinalIgnoreCase))
                {
                    // Redirect to trailing slash to maintain relative links
                    context.Response.Redirect(context.Request.PathBase + context.Request.Path + "/");
                    context.Response.StatusCode = 301;
                    return;
                }
                else if (String.Equals(context.Request.Path.Value, "/console/", StringComparison.OrdinalIgnoreCase))
                {
                    context.Request.Path = new PathString("/console/Index.html");
                }
                await next();
            });

            app.UseStaticFiles(new StaticFileOptions(new SharedOptions
            {
                RequestPath = new PathString("/console"),
                FileSystem  = new EmbeddedResourceFileSystem(typeof(Startup).Assembly, "NuGet.Services.BasicSearch.Console")
            }));

            //  start the service running - the Lucene index needs to be reopened regularly on a background thread

            _searcherManager = CreateSearcherManager();

            _searcherManager.Open();

            _gate  = 0;
            _timer = new Timer(new TimerCallback(ReopenCallback), 0, 0, 180 * 1000);

            app.Run(Invoke);
        }
Example #4
0
        async Task CreateLuceneIndex(Uri catalogIndex, Func <StorageHttpMessageHandler> handlerFunc, CancellationToken cancellationToken)
        {
            Lucene.Net.Store.Directory luceneDirectory = new RAMDirectory();

            var collector = new SearchIndexFromCatalogCollector(
                catalogIndex,
                luceneDirectory,
                null,
                handlerFunc);

            await collector.Run(
                new MemoryCursor(DateTime.MinValue.ToUniversalTime()),
                new MemoryCursor(DateTime.MaxValue.ToUniversalTime()),
                cancellationToken);

            ILogger logger = new DebugLogger("Lucene");
            ILoader loader = new AuxillaryIndexLoader();

            SearcherManager = new NuGetSearcherManager("memory", logger, luceneDirectory, loader);
            SearcherManager.RegistrationBaseAddress["http"]  = new Uri(_baseAddress, Registration);
            SearcherManager.RegistrationBaseAddress["https"] = new Uri(_baseAddress, Registration);
            SearcherManager.Open();
        }
Example #5
0
        private bool InitializeSearcherManager(IConfiguration configuration, Directory directory, ILoader loader, ILoggerFactory loggerFactory)
        {
            const int maxRetries = 10;

            try
            {
                Retry.Incremental(
                    () =>
                    {
                        var stopwatch = Stopwatch.StartNew();

                        _searcherManager = NuGetSearcherManager.Create(configuration, loggerFactory, directory, loader);
                        _searcherManager.Open();

                        stopwatch.Stop();

                        _searchTelemetryClient.TrackMetric(
                            SearchTelemetryClient.MetricName.SearchIndexReopenDuration, stopwatch.Elapsed.TotalSeconds);

                        TrackIndexMetrics(_searcherManager, _searchTelemetryClient);
                    },
                    shouldRetry: e =>
                    {
                        // Retry on any exception (but log it)
                        _logger.LogError("Startup: An error occurred initializing searcher manager. Going to retry...", e);
                        _searchTelemetryClient.TrackMetric(SearchTelemetryClient.MetricName.SearchIndexReopenFailed, 1);

                        return true;
                    },
                    maxRetries: maxRetries,
                    waitIncrement: TimeSpan.FromSeconds(1));

                return true;
            }
            catch (Exception e)
            {
                _logger.LogCritical("Startup: A critical error occurred initializing searcher manager. Number of retries exhausted.", e);
                _searchTelemetryClient.TrackMetric(SearchTelemetryClient.MetricName.SearchIndexReopenFailed, maxRetries);

                return false;
            }
        }
Example #6
0
        async Task CreateLuceneIndex(Uri catalogIndex, Func<StorageHttpMessageHandler> handlerFunc, CancellationToken cancellationToken)
        {
            Lucene.Net.Store.Directory luceneDirectory = new RAMDirectory();

            var collector = new SearchIndexFromCatalogCollector(
                catalogIndex,
                luceneDirectory,
                null,
                handlerFunc);

            await collector.Run(
                new MemoryCursor(DateTime.MinValue.ToUniversalTime()),
                new MemoryCursor(DateTime.MaxValue.ToUniversalTime()),
                cancellationToken);

            ILogger logger = new DebugLogger("Lucene");
            ILoader loader = new AuxillaryIndexLoader();

            SearcherManager = new NuGetSearcherManager("memory", logger, luceneDirectory, loader);
            SearcherManager.RegistrationBaseAddress["http"] = new Uri(_baseAddress, Registration);
            SearcherManager.RegistrationBaseAddress["https"] = new Uri(_baseAddress, Registration);
            SearcherManager.Open();
        }