protected override void OnProcess(Model.ServiceLock item)
        {
            ServiceLockSettings settings = ServiceLockSettings.Default;

            ServerFilesystemInfo archiveFilesystem = null;

            if (item.FilesystemKey != null)
            {
                archiveFilesystem = FilesystemMonitor.Instance.GetFilesystemInfo(item.FilesystemKey);
                if (archiveFilesystem == null)
                {
                    Platform.Log(LogLevel.Warn, "Filesystem for archiving alerts is no longer valid.  Assigning new filesystem.");
                    item.FilesystemKey = null;
                    UpdateFilesystemKey(item);
                }
            }

            if (archiveFilesystem == null)
            {
                ServerFilesystemInfo selectedFs = null;
                foreach (ServerFilesystemInfo fs in FilesystemMonitor.Instance.GetFilesystems())
                {
                    if (selectedFs == null)
                    {
                        selectedFs = fs;
                    }
                    else if (fs.Filesystem.FilesystemTierEnum.Enum > selectedFs.Filesystem.FilesystemTierEnum.Enum)
                    {
                        selectedFs = fs;                         // Lower tier
                    }
                    else if ((fs.Filesystem.FilesystemTierEnum.Enum == selectedFs.Filesystem.FilesystemTierEnum.Enum) &&
                             (fs.FreeBytes > selectedFs.FreeBytes))
                    {
                        selectedFs = fs;                         // same tier
                    }
                }
                if (selectedFs == null)
                {
                    Platform.Log(LogLevel.Info, "No writable filesystems for archiving Alerts, delaying archival.");
                    UnlockServiceLock(item, true, Platform.Time.AddHours(2));
                    return;
                }
                item.FilesystemKey = selectedFs.Filesystem.Key;
                archiveFilesystem  = selectedFs;
                UpdateFilesystemKey(item);

                Platform.Log(LogLevel.Info, "Selecting Filesystem {0} for archiving of Alerts",
                             selectedFs.Filesystem.Description);
            }


            DateTime scheduledTime;

            if (!archiveFilesystem.Writeable)
            {
                Platform.Log(LogLevel.Info, "Filesystem {0} is not writeable. Unable to archive Alert log files.", archiveFilesystem.Filesystem.Description);
                scheduledTime = Platform.Time.AddMinutes(settings.AlertRecheckDelay);
            }
            else
            {
                Platform.Log(LogLevel.Info, "Checking for Alert logs to purge to: {0}",
                             archiveFilesystem.Filesystem.Description);
                if (!ArchiveLogs(archiveFilesystem))
                {
                    scheduledTime = Platform.Time.AddMinutes(settings.AlertRecheckDelay);
                }
                else
                {
                    DateTime tomorrow = Platform.Time.Date.AddDays(1);
                    // Set for 12:01 tomorrow morning
                    scheduledTime = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 0, 1, 0);
                    Platform.Log(LogLevel.Info, "Completed archival of Alert logs, rescheduling log archive for {0}",
                                 scheduledTime.ToLongTimeString());
                }
            }

            UnlockServiceLock(item, true, scheduledTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Main <see cref="ServiceLock"/> processing routine.
        /// </summary>
        /// <param name="item">The <see cref="ServiceLock"/> item to process.</param>
        protected override void OnProcess(Model.ServiceLock item)
        {
            ServiceLockSettings  settings = ServiceLockSettings.Default;
            ServerFilesystemInfo fs       = FilesystemMonitor.Instance.GetFilesystemInfo(item.FilesystemKey);

            UpdateState(item, fs);

            DateTime scheduledTime;

            if (!fs.Online)
            {
                Platform.Log(LogLevel.Info, "Filesystem {0} is not online. Watermark is not checked at this point.", fs.Filesystem.Description);
                scheduledTime = Platform.Time.AddMinutes(settings.FilesystemDeleteRecheckDelay);
            }
            else
            {
                _bytesToRemove = FilesystemMonitor.Instance.CheckFilesystemBytesToRemove(item.FilesystemKey);

                if (fs.AboveHighWatermark)
                {
                    int count = CheckWorkQueueCount(item);
                    if (count > 0)
                    {
                        // delay to avoid overshoot

                        Platform.Log(LogLevel.Info,
                                     "Delaying Filesystem ServiceLock check, {0} StudyDelete, StudyPurge or MigrateStudy items still in the WorkQueue for Filesystem: {1} (Current: {2}, High Watermark: {3})",
                                     count, fs.Filesystem.Description, fs.UsedSpacePercentage, fs.Filesystem.HighWatermark);

                        scheduledTime = Platform.Time.AddMinutes(settings.FilesystemDeleteRecheckDelay);
                    }
                    else
                    {
                        Platform.Log(LogLevel.Info, "Filesystem above high watermark: {0} (Current: {1}, High Watermark: {2}",
                                     fs.Filesystem.Description, fs.UsedSpacePercentage, fs.Filesystem.HighWatermark);

                        MigrateStudies(item, fs);

                        if (_bytesToRemove > 0 && !CancelPending)
                        {
                            DeleteStudies(item, fs);
                        }

                        if (_bytesToRemove > 0 && !CancelPending)
                        {
                            PurgeStudies(item, fs);
                        }


                        if (_studiesDeleted + _studiesMigrated + _studiesPurged == 0)
                        {
                            Platform.Log(LogLevel.Warn, "Fileystem '{0}' is above high watermark but no studies can be deleted, migrated or purged at this point", fs.Filesystem.Description);
                        }

                        scheduledTime = Platform.Time.AddMinutes(settings.FilesystemDeleteRecheckDelay);
                    }
                }
                else
                {
                    scheduledTime = Platform.Time.AddMinutes(settings.FilesystemDeleteCheckInterval);
                }
            }

            UnlockServiceLock(item, true, scheduledTime);
        }