public OrchestratorService() { Int32.TryParse(ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.DashboardCleanupTime], out _dashboardCleanupTime); Int32.TryParse(ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.CronSchedule], out _cronSchedule); // Set up _allConfigs = new ThreadSafeWorkStack(); _extractors = new ThreadSafeExtractorList(); _workStack = new ThreadSafeWorkStack(); _activeExtractions = new ThreadSafeWorkStack(); _completedExtractions = new ThreadSafeWorkStack(); _erroredExtractions = new ThreadSafeWorkStack(); _myHostName = ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.OrchestratorHostName]; _report.OrchestratorHostName = _myHostName; _listeningPort = Convert.ToInt32(ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.OrchestratorListeningPort]); _myIp = IPv4Helper.getIPv4Address(); // Determine what type of SQL database we are using String sqlProvider = ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.SqlProvider]; String connectionString = ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.SqlConnectionString]; _sqlDao = new SqlDaoFactory().getSqlDao(new SqlConnectionFactory().getConnection(sqlProvider, connectionString)); // make own unique list of sitecodes VistaDao vistaDao = new VistaDao(); string[] sitecode = new string[vistaDao.SiteCodes.Count]; vistaDao.SiteCodes.CopyTo(sitecode, 0); _vhaSites = new List <string>(sitecode); if (_vhaSites == null || _vhaSites.Count == 0) { _report.addException(new ApplicationException("Failed to open the VHA site file!")); throw new ApplicationException("Failed to open the VHA site file!"); } }
public ThreadSafeWorkStack setWorkList() { _allConfigs = new ThreadSafeWorkStack(); getConfigs(); // cleanup from last batch - delete IEN tracking table records since IEN would be counted otherwise cleanupFromLastRun(); ISqlDao sqlDao = _sqlDao; Dictionary <String, String> lastIenTable = _sqlDao.getLastIenTable(); // grab the whole table - much better performance than a query per config/per site // loop through sites and jobs - see if job was already reported as started by database foreach (ExtractorConfiguration ec in _configurations) { QueryConfiguration qc = ec.QueryConfigurations.RootNode.Value; foreach (string sitecode in _vhaSites) { ec.SiteCode = sitecode; string currentKey = sitecode + "_" + qc.File; if (!String.IsNullOrEmpty(ec.Sites)) { bool included = false; string[] configSites = ec.Sites.Split(new char[] { ';' }); if (configSites != null && configSites.Length > 0) { foreach (string s in configSites) { if (sitecode == s) { ExtractorConfiguration cloned = ec.Clone(); cloned.BatchId = this.Report.BatchId; _allConfigs.Push(cloned); included = true; } } } if (!included) { continue; } } else { ExtractorConfiguration cloned = ec.Clone(); cloned.BatchId = this.Report.BatchId; _allConfigs.Push(cloned); } // we will give the start point to the extractor for incremental extractions so we need to fetch it ExtractorConfiguration newConfig = ec.Clone(); newConfig.BatchId = this.Report.BatchId; if (ec.ExtractMode == ExtractorMode.INCREMENTAL) { try { String lastSqlIen = "0"; if (lastIenTable.ContainsKey(currentKey)) { lastSqlIen = lastIenTable[currentKey]; // if we found this config/site key, use last IEN from last IEN table _report.addDebug("Found incremental IEN in tracking table for key: " + currentKey + " - IEN: " + lastSqlIen); } //string lastSqlIen = _sqlDao.getLastIen(sitecode, config.File); string fromConfig = newConfig.QueryConfigurations.RootNode.Value.From; if (lastSqlIen.Equals("0") && !String.IsNullOrEmpty(fromConfig)) { newConfig.StartIen = fromConfig; } else { if (String.IsNullOrEmpty(fromConfig)) // fromConfig == null || fromConfig.Equals(String.Empty)) { newConfig.StartIen = lastSqlIen; } else { decimal incIen = Convert.ToDecimal(lastSqlIen); decimal fromIen = Convert.ToDecimal(fromConfig); if (incIen > fromIen) { newConfig.StartIen = lastSqlIen; newConfig.QueryConfigurations.RootNode.Value.From = lastSqlIen; } else { // _report.addInfo(String.Format("The current configuration specified a start IEN ({0}) that is greater than the last IEN in the tracking table ({1}) - Site: {2}, File: {3}", fromConfig, lastSqlIen, sitecode, qc.File)); newConfig.StartIen = fromConfig; newConfig.QueryConfigurations.RootNode.Value.From = fromConfig; } } } // do this at the end so we don't disturb any of the above code - don't care what's in IEN tracking table for these files, always start at beginning if (String.Equals(newConfig.QueryConfigurations.RootNode.Value.File, "63") || String.Equals(newConfig.QueryConfigurations.RootNode.Value.File, "55")) // not crazy about this hard coding but at least it's just the Orchestrator handling it... { // logging.Log.LOG("Found a special config that requires a full Vista file traversal - setting start IEN to '0'"); // _report.addInfo("Found a special config that requires a full Vista file traversal - setting start IEN to '0'"); newConfig.StartIen = newConfig.QueryConfigurations.RootNode.Value.From = "0"; } if (String.Equals(newConfig.QueryConfigurations.RootNode.Value.File, "69")) { // logging.Log.LOG("Updated file 69 config - set config start IEN to " + _file69From); newConfig.StartIen = newConfig.QueryConfigurations.RootNode.Value.From = _file69From; } } catch (Exception exc) { _report.addError("Unable to retrieve the last SQL IEN for the extractor!", exc); _report.HasError = "T"; continue; } } else if (ec.ExtractMode == ExtractorMode.DIFF) { newConfig.SqlIens = setParamsForDiff(sitecode, ec); } _report.addDebug("Adding a new job to the workstack: " + newConfig.ToString()); _workStack.PushOrUpdate(newConfig); } } _report.addInfo(_workStack.Count() + " total jobs are on the work stack"); _report.addDebug(_workStack.Count() + " total jobs on the work stack"); preProcess(_configurations); _workStack.SortBySiteCode(); // we want jobs for a site to run as a group RequestHandler.getInstance().WorkStack = _workStack; return(_workStack); }
void startListenerAndMonitor(object workStack) { _workStack = (ThreadSafeWorkStack)workStack; startListenerAndMonitor(); }