コード例 #1
0
ファイル: Analyzer.cs プロジェクト: puneet-gupta/DaaS
        internal async Task <List <Report> > Analyze(Log log, string sessionId, string blobSasUri, CancellationToken ct)
        {
            // Get a lease to analzye this particular log
            Lease lease = Infrastructure.LeaseManager.TryGetLease(log.RelativePath, blobSasUri);

            if (!Lease.IsValid(lease))
            {
                return(null);
            }

            // Run the analyzer command
            var outputDir = CreateTemporaryReportDestinationFolder(log);

            await RunAnalyzerAsync(lease, log, outputDir, sessionId, ct);

            // Store the reports to blob storage
            var reports = MoveReportsToPermanentStorage(outputDir);

            if (reports == null || reports.Count == 0 || reports.Any(x => x.FileName.EndsWith(".err.diaglog")))
            {
                string analyzerException = string.Empty;
                if (reports.Any(x => x.FileName.EndsWith(".err.diaglog")))
                {
                    var    report        = reports.FirstOrDefault(x => x.FileName.EndsWith(".err.diaglog"));
                    string errorFileName = report.FullPermanentStoragePath;
                    if (System.IO.File.Exists(errorFileName))
                    {
                        analyzerException = System.IO.File.ReadAllText(errorFileName);
                    }
                }
                throw new DiagnosticToolHasNoOutputException(Name, analyzerException);
            }

            // Return the reports (we'll just let the lease expire on its own so that we can hold on to it until the reports have been logged in the session)
            return(reports.Where(x => !x.FileName.EndsWith(".diaglog")).ToList());
        }
コード例 #2
0
        private async Task SaveUpdatesAsync(bool waitForLease)
        {
            Logger.LogDiagnostic("Time to save a new update for session {0}", SessionId);
            // Grab a lease on the session
            Lease sessionLease;

            if (waitForLease)
            {
                sessionLease = Infrastructure.LeaseManager.GetLease(RelativePath, string.Empty);
            }
            else
            {
                sessionLease = Infrastructure.LeaseManager.TryGetLease(RelativePath, string.Empty);
            }

            Logger.LogDiagnostic("Do I have a lease?");
            if (!Lease.IsValid(sessionLease))
            {
                Console.WriteLine("Nope. Darn it");
                return;
            }
            Logger.LogDiagnostic("I do! Sweet!");

            int retryCount = 0;

retryLabel:

            if (retryCount > 2)
            {
                goto Finished;
            }

            try
            {
                Logger.LogSessionVerboseEvent($"About to save the new session with retryCount = {retryCount} and SessionId = {SessionId.ToString()}", SessionId.ToString());
                // Save the session
                Save(sessionLease);
                Logger.LogSessionVerboseEvent($"Session {SessionId.ToString()} saved successfully", SessionId.ToString());
            }
            catch (IOException ioException)
            {
                if (ioException.Message.StartsWith("The process cannot access the file", StringComparison.InvariantCultureIgnoreCase))
                {
                    Logger.LogSessionErrorEvent($"The Session is in use. Waiting for 5 seconds and retrying", ioException, SessionId.ToString());
                    await Task.Delay(5000);

                    ++retryCount;
                    LoadLatestUpdates(false);
                    goto retryLabel;
                }
            }
            catch (Exception e)
            {
                Logger.LogSessionErrorEvent("Couldn't save the updated session", e, SessionId.ToString());
            }

            try
            {
                MoveSessionToCorrectStorageFolderBasedOnStatus();
                Logger.LogDiagnostic("Saved the session");
            }
            catch (Exception e)
            {
                Logger.LogSessionErrorEvent("Couldn't move session to correct folders", e, SessionId.ToString());
            }

Finished:
            sessionLease.Release();
        }