public AnalysisRequestsController()
     : base()
 {
     entityService  = new AnalysisRequestService(base.db, base.identityDB);
     sampleService  = new SampleService(base.db, base.identityDB);
     accountService = new AccountService(base.db);
 }
示例#2
0
        private static void MarkAnalysisAsFailed(AnalysisRequestService analysisRequestService, GNAnalysisRequest analysisRequest)
        {
            if (MARK_ANALYSIS_IN_ERROR_FEATURE_ACTIVE)
            {
                try
                {
                    //get analysis request from db
                    GNAnalysisRequest ar = analysisRequestService.db.GNAnalysisRequests
                                           .Include(a => a.AnalysisType)
                                           .Include(a => a.AnalysisStatus)
                                           .Include(a => a.AnalysisResult)
                                           .Where(a => a.Id == analysisRequest.Id)
                                           .FirstOrDefault();

                    //mark analysis as failed
                    if (!ar.IsFailedRequest)
                    {
                        LogUtil.Info(logger, "Mark Analysis As Failed for AR ID [" + ar.Id + "]...");
                        System.Console.WriteLine("\nMark Analysis As Failed for AR ID [" + ar.Id + "]...");

                        analysisRequestService.MarkAnalysisAsFailed(analysisRequestService, ar);
                    }
                }
                catch (Exception e)
                {
                    LogUtil.Error(logger, "Unable to Process Failure of Analysis " + analysisRequest.Id + " : " + e.Message, e);
                }
            }
        }
示例#3
0
        public async Task <bool> AutostartAnalysis(GNAnalysisRequest analysis)
        {
            AnalysisRequestService analysisService = new AnalysisRequestService(db);
            GNContact userContact = db.GNContacts.Find(Guid.Parse("0750f896-e7d6-48d4-a1b9-007059f62784"));
            await analysisService.StartAnalysis(userContact, analysis.Id);

            return(true);
        }
        private void InitCloudServices()
        {
            AnalysisRequestService arService = (AnalysisRequestService)entityService;

            if (arService.analysisRequestPendingCloudMessageService == null || arService.cloudStorageService == null)
            {
                arService.InitCloudServices(UserContact.GNOrganization.AWSConfigId);
            }
        }
        public AWSComputeEnvironmentService(GNEntityModelContainer db)
            : base(db)
        {
            base.db = db;

            AWSConfig awsConfig = db.AWSConfigs.FirstOrDefault();

            cloudComputeService    = new GNCloudComputeService(awsConfig.Id);
            analysisRequestService = new AnalysisRequestService(db, new Data.IdentityModel.IdentityModelContainer());
        }
示例#6
0
        static void Main(string[] args)
        {
            try {
                var analysisRequestSerivce = new AnalysisRequestService();
                analysisRequestSerivce.SendExpiringPeriodToSendDocumentsNotification(log);

                var analysisRequestMonthlyControl = new AnalysisRequestMonthlyControlService();
                analysisRequestMonthlyControl.GenerateMonthlyControl(log);
            } catch (Exception ex) {
                log.Error("Main Error", ex);
            }
        }
示例#7
0
        private static void ReStartFailedAnalysis(AnalysisRequestService analysisRequestService, GNAnalysisRequest analysisRequest)
        {
            if (RESTART_ANALYSIS_FEATURE_ACTIVE)
            {
                try
                {
                    //get analysis request from db
                    GNAnalysisRequest ar = analysisRequestService.db.GNAnalysisRequests
                                           .Include(a => a.AnalysisType)
                                           .Include(a => a.GNAnalysisRequestGNSamples.Select(s => s.GNSample).Select(s => s.CloudFiles))
                                           .Include(a => a.AnalysisStatus)
                                           .Include(a => a.AnalysisResult)
                                           .Where(a => a.Id == analysisRequest.Id)
                                           .FirstOrDefault();

                    //determine if analysis re-start is allowed
                    ar = analysisRequestService.IsValidSampleSet(ar);
                    ar.CanReStartAnalysis = analysisRequestService.IsAnalysisRestartAllowed(ar, FORCE_RESTART_ANALYSIS);

                    //restart analysis
                    if (ar.CanReStartAnalysis && ar.IsFailedRequest)
                    {
                        LogUtil.Info(logger, "Restart Analysis for AR ID [" + ar.Id + "]...");
                        System.Console.WriteLine("\nRestart Analysis for AR ID [" + ar.Id + "]...");

                        var t = Task.Run(async delegate
                        {
                            var arService = new AnalysisRequestService(new GNEntityModelContainer(), new IdentityModelContainer());

                            //get user contact
                            GNContact userContact = arService.db.GNContacts.Find(ar.CreatedBy);

                            if (arService.analysisRequestPendingCloudMessageService == null || arService.cloudStorageService == null)
                            {
                                arService.InitCloudServices(userContact.GNOrganization.AWSConfigId);
                            }

                            await arService.StartAnalysis(userContact, ar.Id);
                        });
                    }
                    else
                    {
                        LogUtil.Info(logger, "UNABLE to Restart Analysis for AR ID [" + ar.Id + "]...");
                        System.Console.WriteLine("\nUNABLE to Restart Analysis for AR ID [" + ar.Id + "]...");
                    }
                }
                catch (Exception e)
                {
                    LogUtil.Error(logger, "Unable to Process Failure of Analysis " + analysisRequest.Id + " : " + e.Message, e);
                }
            }
        }
示例#8
0
        private void Monitor()
        {
            LogUtil.LogMethod(logger, MethodBase.GetCurrentMethod());

            LogUtil.Info(logger, GetType().Name + ".Monitor()...");
            System.Console.WriteLine("\n" + GetType().Name + ".Monitor()...");

            try
            {
                //init analysis service
                var analysisRequestService = new AnalysisRequestService(new GNEntityModelContainer(), new IdentityModelContainer());

                //fetch analyses With Errors But Not Marked In Error
                IQueryable <GNAnalysisRequest> analysesWithErrorsButNotMarkedInError =
                    analysisRequestService.FetchAnalysesWithErrorsButNotMarkedInError();
                if (analysesWithErrorsButNotMarkedInError != null && analysesWithErrorsButNotMarkedInError.Count() != 0)
                {
                    LogUtil.Info(logger, "analysesWithErrorsButNotMarkedInError count = " + analysesWithErrorsButNotMarkedInError.Count());
                    System.Console.WriteLine("analysesWithErrorsButNotMarkedInError count = " + analysesWithErrorsButNotMarkedInError.Count());

                    foreach (var analysisRequest in analysesWithErrorsButNotMarkedInError)
                    {
                        //handle analysis failure (mark as failed and initiate refund)
                        MarkAnalysisAsFailed(analysisRequestService, analysisRequest);
                    }
                }

                //fetch analyses Marked In Error
                IQueryable <GNAnalysisRequest> analysesMarkedInError = analysisRequestService.FetchAnalysesMarkedInError();
                if (analysesMarkedInError != null && analysesMarkedInError.Count() != 0)
                {
                    LogUtil.Info(logger, "analysesMarkedInError count = " + analysesMarkedInError.Count());
                    System.Console.WriteLine("analysesMarkedInError count = " + analysesMarkedInError.Count());

                    foreach (var analysisRequest in analysesMarkedInError)
                    {
                        //terminate AWS instance for analysis request in error
                        TerminateInstancesForAnalysis(analysisRequest);

                        //handle analysis failure (auto re-start)
                        ReStartFailedAnalysis(analysisRequestService, analysisRequest);
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.Warn(logger, ex.Message, ex);
                System.Console.WriteLine(ex.Message);
            }
        }
        public async Task <bool> ProcessQCMessage(NewSampleBatchStatus newSampleMessageStatus)
        {
            System.Console.WriteLine("QCQCQC " + newSampleMessageStatus.name);

            try
            {
                GNCloudFileCategory fileCategory = db.GNCloudFileCategories.Where(a => a.Id == 1).FirstOrDefault();

                string sampleName1 = newSampleMessageStatus.name;
                string sampleName  = sampleName1.Substring(0, sampleName1.IndexOf("_"));
                //s3://sanford-fastq/151204_SN7001383_0164_AC7Y91ACXX/FASTQ/fastqc/AAA076960/AAA076960_S6_R2_001/

                GNSample sample = db.GNSamples.Where(a => a.Name.Equals(sampleName) && a.IsReady == false).FirstOrDefault();

                GNCloudStorageService st = new GNCloudStorageService();
                string volume            = "dev-gn-s3-01";

                Guid   fileId        = Guid.NewGuid();
                string folderPath    = "fastq/" + sample.Id + "/" + fileId + "/";
                string fastqFileName = folderPath + newSampleMessageStatus.name + ".fastq.gz";
                string fileURL       = "https://dev-gn-s3-01.s3.amazonaws.com/" + fastqFileName;

                string originBucket = newSampleMessageStatus.filesBucket;
                originBucket = originBucket.Replace("s3://", "");
                originBucket = originBucket.Substring(0, originBucket.IndexOf("/")); //"sanford-fastq";

                string QcOriginKey = newSampleMessageStatus.filesBucket;
                QcOriginKey = QcOriginKey.Replace("s3://", "");
                QcOriginKey = QcOriginKey.Substring(originBucket.Length + 1);

                string FileDescription = newSampleMessageStatus.name + ".fastq.gz";
                string fastqOriginKey  = QcOriginKey.Substring(0, QcOriginKey.IndexOf("FASTQ/") + 5);
                fastqOriginKey = fastqOriginKey + "/" + FileDescription;

                QcOriginKey = QcOriginKey + "fastqc_report.html";


                string destinationBucket = "dev-gn-s3-01/" + folderPath;
                destinationBucket = "dev-gn-s3-01";
                string QcFileName       = folderPath + "fastqc_report.html";
                string QcDestinationURL = "https://dev-gn-s3-01.s3.amazonaws.com/" + QcFileName;

                st.CopyS3Object(originBucket, fastqOriginKey, destinationBucket, fastqFileName);
                st.CopyS3Object(originBucket, QcOriginKey, destinationBucket, QcFileName);


                GNCloudFile cloudFile = new GNCloudFile
                {
                    Id = fileId,
                    GNCloudFileCategoryId = fileCategory.Id, //FASTQ
                    CloudFileCategory     = fileCategory,
                    FileName            = folderPath + fastqFileName,
                    FileURL             = fileURL,
                    FolderPath          = folderPath,
                    Volume              = volume,
                    Description         = fastqFileName,
                    FileSize            = st.GetObjectSize(originBucket, fastqOriginKey),
                    AWSRegionSystemName = db.AWSRegions.FirstOrDefault().AWSRegionSystemName,
                    CreateDateTime      = DateTime.Now,
                    CreatedBy           = Guid.Parse("0750f896-e7d6-48d4-a1b9-007059f62784"),
                    SampleId            = sample.Id.ToString(),
                    PassedQC            = (newSampleMessageStatus.isError.Equals("false")),
                    QcReportLocation    = QcDestinationURL
                };
                db.GNCloudFiles.Add(cloudFile);
                sample.CloudFiles.Add(cloudFile);

                if (sample.CloudFiles.Count() == 2 && sample.CloudFiles.Where(a => a.PassedQC == false).Count() == 0)
                {
                    sample.IsReady = true;

                    if (sample.GNNewSampleBatchSample.GNNewSampleBatch.AutoStartAnalysis)
                    {
                        GNAnalysisRequest      analysis        = sample.GNAnalysisRequestGNSamples.FirstOrDefault().GNAnalysisRequest;
                        AnalysisRequestService analysisService = new AnalysisRequestService(db);
                        GNContact userContact = db.GNContacts.Find(Guid.Parse("0750f896-e7d6-48d4-a1b9-007059f62784"));
                        await analysisService.StartAnalysis(userContact, analysis.Id);
                    }
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                System.Console.WriteLine("***Unable to Update QC-COMPLETED status. " + e.Message + e.StackTrace + " **********************************");
                Exception e2 = new Exception("Unable to Update QC-COMPLETED status.", e);
                LogUtil.Warn(logger, e2.Message, e2);
                return(false);
            }


            return(true);
        }
示例#10
0
 public ReportsController()
     : base()
 {
     entityService = new AnalysisRequestService(base.db, base.identityDB);
     sampleService = new SampleService(base.db, base.identityDB);
 }