public void Check(ICheckNotifier notifier) { var catalogues = _loadMetadata.GetAllCatalogues().ToArray(); //if there are no logging tasks defined on any Catalogues if (catalogues.Any() && catalogues.All(c => string.IsNullOrWhiteSpace(c.LoggingDataTask))) { string proposedName; bool fix; if (catalogues.Length == 1) { proposedName = "Loading '" + catalogues[0] + "'"; fix = notifier.OnCheckPerformed( new CheckEventArgs( "Catalogue " + catalogues[0] + " does not have a logging task specified", CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?")); } else { proposedName = _loadMetadata.Name; fix = notifier.OnCheckPerformed( new CheckEventArgs( "Catalogues " + string.Join(",", catalogues.Select(c => c.Name)) + " do not have a logging task specified", CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?")); } if (fix) { CreateNewLoggingTaskFor(notifier, catalogues, proposedName); } else { return; } } string distinctLoggingTask = null; try { distinctLoggingTask = _loadMetadata.GetDistinctLoggingTask(); notifier.OnCheckPerformed(new CheckEventArgs("All Catalogues agreed on a single Logging Task:" + distinctLoggingTask, CheckResult.Success, null)); } catch (Exception e) { notifier.OnCheckPerformed(new CheckEventArgs("Catalogues could not agreed on a single Logging Task", CheckResult.Fail, e)); } try { var settings = _loadMetadata.GetDistinctLoggingDatabase(); settings.TestConnection(); notifier.OnCheckPerformed(new CheckEventArgs("Connected to logging architecture successfully", CheckResult.Success, null)); if (distinctLoggingTask != null) { LogManager lm = new LogManager(settings); string[] dataTasks = lm.ListDataTasks(); if (dataTasks.Contains(distinctLoggingTask)) { notifier.OnCheckPerformed(new CheckEventArgs("Found Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Success, null)); } else { var fix = notifier.OnCheckPerformed(new CheckEventArgs("Could not find Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Fail, null, "Create Logging Task '" + distinctLoggingTask + "'")); if (fix) { lm.CreateNewLoggingTaskIfNotExists(distinctLoggingTask); } } } } catch (Exception e) { notifier.OnCheckPerformed(new CheckEventArgs("Could reach default logging server", CheckResult.Fail, e)); } }
public void Check(ICheckNotifier notifier) { var catalogues = _loadMetadata.GetAllCatalogues().ToArray(); //if there are no logging tasks defined on any Catalogues if (catalogues.Any() && catalogues.All(c => string.IsNullOrWhiteSpace(c.LoggingDataTask))) { string proposedName; bool fix; if (catalogues.Length == 1) { proposedName = "Loading '" + catalogues[0] + "'"; fix = notifier.OnCheckPerformed( new CheckEventArgs( "Catalogue " + catalogues[0] + " does not have a logging task specified", CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?")); } else { proposedName = _loadMetadata.Name; fix = notifier.OnCheckPerformed( new CheckEventArgs( "Catalogues " + string.Join(",", catalogues.Select(c => c.Name)) + " do not have a logging task specified", CheckResult.Fail, null, "Create a new Logging Task called '" + proposedName + "'?")); } if (fix) { CreateNewLoggingTaskFor(notifier, catalogues, proposedName); } else { return; } } #region Fix missing LoggingDataTask var missingTasks = catalogues.Where(c => string.IsNullOrWhiteSpace(c.LoggingDataTask)).ToArray(); var potentialTasks = catalogues.Except(missingTasks).Select(c => c.LoggingDataTask).Distinct().ToArray(); //If any Catalogues are missing tasks if (missingTasks.Any()) { //but there is consensus for those that are not missing tasks if (potentialTasks.Length == 1) { var fix = notifier.OnCheckPerformed(new CheckEventArgs("Some catalogues have NULL LoggingDataTasks", CheckResult.Fail, null, $"Set task to {potentialTasks.Single()}")); if (fix) { foreach (var cata in missingTasks) { cata.LoggingDataTask = potentialTasks.Single(); cata.SaveToDatabase(); } } } } #endregion #region Fix missing LiveLoggingServer_ID var missingServer = catalogues.Where(c => c.LiveLoggingServer_ID == null).ToArray(); var potentialServer = catalogues.Except(missingServer).Select(c => c.LiveLoggingServer_ID).Distinct().ToArray(); if (missingServer.Any()) { if (potentialServer.Length == 1) { var fix = notifier.OnCheckPerformed(new CheckEventArgs("Some catalogues have NULL LiveLoggingServer_ID", CheckResult.Fail, null, $"Set LiveLoggingServer_ID to {potentialServer.Single()}")); if (fix) { foreach (var cata in missingServer) { cata.LiveLoggingServer_ID = potentialServer.Single(); cata.SaveToDatabase(); } } } else { var defaults = _loadMetadata.CatalogueRepository.GetServerDefaults(); var defaultLoggingServer = defaults.GetDefaultFor(PermissableDefaults.LiveLoggingServer_ID); if (defaultLoggingServer != null) { var fix = notifier.OnCheckPerformed(new CheckEventArgs("Some catalogues have NULL LiveLoggingServer_ID", CheckResult.Fail, null, $"Set LiveLoggingServer_ID to '{defaultLoggingServer}' (the default)")); if (fix) { foreach (var cata in missingServer) { cata.LiveLoggingServer_ID = defaultLoggingServer.ID; cata.SaveToDatabase(); } } } } } #endregion string distinctLoggingTask = null; try { distinctLoggingTask = _loadMetadata.GetDistinctLoggingTask(); notifier.OnCheckPerformed(new CheckEventArgs("All Catalogues agreed on a single Logging Task:" + distinctLoggingTask, CheckResult.Success, null)); } catch (Exception e) { notifier.OnCheckPerformed(new CheckEventArgs("Catalogues could not agreed on a single Logging Task", CheckResult.Fail, e)); } try { var settings = _loadMetadata.GetDistinctLoggingDatabase(); settings.TestConnection(); notifier.OnCheckPerformed(new CheckEventArgs("Connected to logging architecture successfully", CheckResult.Success, null)); if (distinctLoggingTask != null) { LogManager lm = new LogManager(settings); string[] dataTasks = lm.ListDataTasks(); if (dataTasks.Contains(distinctLoggingTask)) { notifier.OnCheckPerformed(new CheckEventArgs("Found Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Success, null)); } else { var fix = notifier.OnCheckPerformed(new CheckEventArgs("Could not find Logging Task " + distinctLoggingTask + " in Logging database", CheckResult.Fail, null, "Create Logging Task '" + distinctLoggingTask + "'")); if (fix) { lm.CreateNewLoggingTaskIfNotExists(distinctLoggingTask); } } } } catch (Exception e) { notifier.OnCheckPerformed(new CheckEventArgs("Could reach default logging server", CheckResult.Fail, e)); } }
public int Run(IRDMPPlatformRepositoryServiceLocator locator, IDataLoadEventListener listener, ICheckNotifier checkNotifier, GracefulCancellationToken token) { ILoadProgress loadProgress = locator.CatalogueRepository.GetObjectByID <LoadProgress>(_options.LoadProgress); ILoadMetadata loadMetadata = locator.CatalogueRepository.GetObjectByID <LoadMetadata>(_options.LoadMetadata); if (loadMetadata == null && loadProgress != null) { loadMetadata = loadProgress.LoadMetadata; } if (loadMetadata == null) { throw new ArgumentException("No Load Metadata specified"); } if (loadProgress != null && loadProgress.LoadMetadata_ID != loadMetadata.ID) { throw new ArgumentException("The supplied LoadProgress does not belong to the supplied LoadMetadata load"); } var databaseConfiguration = new HICDatabaseConfiguration(loadMetadata); var flags = new HICLoadConfigurationFlags(); flags.ArchiveData = !_options.DoNotArchiveData; flags.DoLoadToStaging = !_options.StopAfterRAW; flags.DoMigrateFromStagingToLive = !_options.StopAfterSTAGING; var checkable = new CheckEntireDataLoadProcess(loadMetadata, databaseConfiguration, flags, locator.CatalogueRepository.MEF); switch (_options.Command) { case CommandLineActivity.run: var loggingServer = loadMetadata.GetDistinctLoggingDatabase(); var logManager = new LogManager(loggingServer); // Create the pipeline to pass into the DataLoadProcess object var dataLoadFactory = new HICDataLoadFactory(loadMetadata, databaseConfiguration, flags, locator.CatalogueRepository, logManager); IDataLoadExecution execution = dataLoadFactory.Create(listener); IDataLoadProcess dataLoadProcess; if (loadMetadata.LoadProgresses.Any()) { //Then the load is designed to run X days of source data at a time //Load Progress ILoadProgressSelectionStrategy whichLoadProgress = loadProgress != null ? (ILoadProgressSelectionStrategy) new SingleLoadProgressSelectionStrategy(loadProgress) : new AnyAvailableLoadProgressSelectionStrategy(loadMetadata); var jobDateFactory = new JobDateGenerationStrategyFactory(whichLoadProgress); dataLoadProcess = _options.Iterative ? (IDataLoadProcess) new IterativeScheduledDataLoadProcess(locator, loadMetadata, checkable, execution, jobDateFactory, whichLoadProgress, _options.DaysToLoad, logManager, listener, databaseConfiguration) : new SingleJobScheduledDataLoadProcess(locator, loadMetadata, checkable, execution, jobDateFactory, whichLoadProgress, _options.DaysToLoad, logManager, listener, databaseConfiguration); } else { //OnDemand dataLoadProcess = new DataLoadProcess(locator, loadMetadata, checkable, logManager, listener, execution, databaseConfiguration); } var exitCode = dataLoadProcess.Run(token); //return 0 for success or load not required otherwise return the exit code (which will be non zero so error) return(exitCode == ExitCodeType.Success || exitCode == ExitCodeType.OperationNotRequired? 0: (int)exitCode); case CommandLineActivity.check: checkable.Check(checkNotifier); return(0); default: throw new ArgumentOutOfRangeException(); } }