Ejemplo n.º 1
0
        /// <summary>
        /// Return all the work stacks
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public MessageTO getWorkStacksResponse(MessageTO request)
        {
            MessageTO response = new MessageTO();

            response.MessageType = MessageTypeTO.WorkStacksResponse;

            //LOG.Debug(WorkStack.Count() + " jobs on the workstack");
            //LOG.Debug(ActiveExtractions.Count() + " active jobs");
            //LOG.Debug(ErroredExtractions.Count() + " errored jobs");
            //LOG.Debug(CompletedExtractions.Count() + " completed jobs");

            response.Configurations = new Dictionary <string, IList <ExtractorConfiguration> >();
            response.Configurations.Add("Queued", new List <ExtractorConfiguration>());
            response.Configurations.Add("Active", new List <ExtractorConfiguration>());
            response.Configurations.Add("Errored", new List <ExtractorConfiguration>());
            response.Configurations.Add("Completed", new List <ExtractorConfiguration>());

            if (WorkStack != null && WorkStack.Count() > 0)
            {
                WorkStack.CopyTo(response.Configurations["Queued"]);
            }

            if (ActiveExtractions != null && ActiveExtractions.Count() > 0)
            {
                response.Configurations["Active"] = ActiveExtractions.CopyTo(response.Configurations["Active"]);
            }

            if (ErroredExtractions != null && ErroredExtractions.Count() > 0)
            {
                response.Configurations["Errored"] = ErroredExtractions.CopyTo(response.Configurations["Errored"]);
            }

            if (CompletedExtractions != null && CompletedExtractions.Count() > 0)
            {
                response.Configurations["Completed"] = CompletedExtractions.CopyTo(response.Configurations["Completed"]);
            }

            response.Message = gov.va.medora.utils.JsonUtils.Serialize <TaggedExtractorConfigArrays>
                                   (new TaggedExtractorConfigArrays(response.Configurations));

            response.Configurations = null; // null this since we serialized the results to a JSON string

            return(response);
        }
Ejemplo n.º 2
0
        public MessageTO getJobErrorResponse(MessageTO request)
        {
            MessageTO response = new MessageTO();

            response.MessageType = MessageTypeTO.JobErrorResponse;
            if (request == null || request.Configuration == null || !request.Configuration.isCompleteConfiguration())
            {
                response.MessageType = MessageTypeTO.Error;
                response.Error       = "Incomplete ExtractorConfiguration parameter on request";
                logging.Log.LOG("The ExtractorConfiguration object sent to the job error request handler is incomplete! Unable to process request");
                //LOG.Error("The ExtractorConfiguration object sent to the job error request handler is incomplete! Unable to process request: " + request.Configuration.ToString());
                return(response);
            }
            if (WorkStack == null)
            {
                logging.Log.LOG("The work stack is null for the job error request. Was everything setup correctly?");
                //LOG.Debug("The work stack is null - was everything set up correctly?");
                response.MessageType = MessageTypeTO.Error;
                response.Error       = "WorkStack has not been initialized";
                return(response);
            }

            // the remove function keys off the site code and vista file - those are the only params we need
            Extractors.Remove(new Extractor("", 0, request.Configuration.SiteCode, request.Configuration.QueryConfigurations.RootNode.Value.File, DateTime.Now));
            ActiveExtractions.Remove(request.Configuration);
            ErroredExtractions.Push(request.Configuration);

            // bug fix: some edge cases will allow duplicate configs to be added to stack - need to check not already there
            //bool alreadyOnStack = false;
            //if (WorkStack.Contains(request.Configuration))
            //{
            //    //LOG.Debug("It looks like this job was already on the stack - no need to add it again");
            //    alreadyOnStack = true;
            //}
            // decided to temporarily stop adding errored jobs back to the stack to check for patterns in error site codes
            //if (!alreadyOnStack)
            //{
            //    LOG.Debug("Adding a job back to the work stack since the client reported an error while processing");
            //    ErroredExtractions.Push(request.Configuration);
            //    ActiveExtractions.Remove(request.Configuration);
            //    WorkStack.Push(request.Configuration);
            //}
            // end bug fix

            try
            {
                String  sqlProvider      = ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.SqlProvider];
                String  connectionString = ConfigurationManager.AppSettings[config.AppConfigSettingsConstants.SqlConnectionString];
                ISqlDao sqlDao           = new SqlDaoFactory().getSqlDao(new SqlConnectionFactory().getConnection(sqlProvider, connectionString));
                if (request.ExtractorReport != null)
                {
                    try
                    {
                        logging.Log.LOG("Saving error report...");
                        sqlDao.saveReport(request.ExtractorReport);
                    }
                    catch (Exception exc)
                    {
                        //LOG.Error("Unable to save an extractor's report!", exc);
                    }
                }
                sqlDao.unlockSite(request.Configuration.SiteCode, request.Configuration.QueryConfigurations.RootNode.Value.File);
                //LOG.Debug("Successfully unlocked job so another client can process");

                // should check site completion on job error reports too
                try
                {
                    checkSiteCompleteAndTrigger(request.ExtractorReport.BatchId, request.Configuration.SiteCode, request.Configuration.QueryConfigurations.RootNode.Value.File);
                }
                catch (Exception te)
                { /* problems with trigger file shouldn't effect extractor */
                    logging.Log.LOG("An error occured when checking trigger file creation criteria: " + te.ToString());
                }
            }
            catch (Exception exc)
            {
                logging.Log.LOG("The call to unlock the extraction job for site " + request.Configuration.SiteCode +
                                ", file " + request.Configuration.QueryConfigurations.RootNode.Value.File + " has failed unexpectedly");
                logging.Log.LOG(exc.Message);

                response.MessageType = MessageTypeTO.Error;
                response.Error       = exc.ToString();
                return(response);
            }
            return(response);
        }