Example #1
0
        private static BackgroundVerificationService CreateVerificationService(
            IBackgroundVerificationInputs backgroundVerificationInputs,
            ConcurrentBag <IssueMsg> issueCollection,
            Action <VerificationResponse> writeAction, ITrackCancel trackCancel)
        {
            var qaService = new BackgroundVerificationService(
                backgroundVerificationInputs.DomainTransactions,
                backgroundVerificationInputs.DatasetLookup)
            {
                CustomErrorFilter = backgroundVerificationInputs.CustomErrorFilter
            };

            var currentProgress = new VerificationProgressMsg();

            qaService.IssueFound +=
                (sender, args) =>
                issueCollection.Add(CreateIssueProto(args, backgroundVerificationInputs));

            qaService.Progress += (sender, args) =>
                                  SendProgress(
                sender, args, issueCollection,
                currentProgress, writeAction, trackCancel);

            return(qaService);
        }
Example #2
0
        private ServiceCallStatus VerifyQualityCore(
            VerificationRequest request,
            IServerStreamWriter <VerificationResponse> responseStream,
            ITrackCancel trackCancel)
        {
            SetupUserNameProvider(request);

            void SendResponse(VerificationResponse r) => responseStream.WriteAsync(r);

            BackgroundVerificationService qaService = null;
            List <GdbObjRefMsg>           deletableAllowedErrorRefs = new List <GdbObjRefMsg>();
            QualityVerification           verification = null;
            var    issueCollection     = new ConcurrentBag <IssueMsg>();
            string cancellationMessage = null;

            try
            {
                // TODO: Separate long-lived objects, such as datasetLookup, domainTransactions (add to this class) from
                // short-term objects (request) -> add to background verification inputs
                IBackgroundVerificationInputs backgroundVerificationInputs =
                    _verificationInputsFactoryMethod(request);

                qaService = CreateVerificationService(backgroundVerificationInputs, issueCollection,
                                                      SendResponse, trackCancel);

                int maxParallelRequested = request.MaxParallelProcessing;

                if (backgroundVerificationInputs.WorkerClient != null &&
                    maxParallelRequested > 1)
                {
                    // allow directly adding issues found by client processes:
                    qaService.DistributedTestRunner = new DistributedTestRunner(
                        backgroundVerificationInputs.WorkerClient, request, issueCollection);
                }

                verification = qaService.Verify(backgroundVerificationInputs, trackCancel);

                deletableAllowedErrorRefs.AddRange(
                    GetDeletableAllowedErrorRefs(request.Parameters, qaService));
            }
            catch (Exception e)
            {
                _msg.Error($"Error checking quality for request {request}", e);
                cancellationMessage = $"Server error: {e.Message}";

                if (!EnvironmentUtils.GetBooleanEnvironmentVariableValue(
                        "PROSUITE_QA_SERVER_KEEP_SERVING_ON_ERROR"))
                {
                    SetUnhealthy();
                }
            }

            ServiceCallStatus result = SendFinalResponse(
                verification, cancellationMessage ?? qaService.CancellationMessage, issueCollection,
                deletableAllowedErrorRefs, qaService?.VerifiedPerimeter, SendResponse);

            return(result);
        }
Example #3
0
        private static IEnumerable <GdbObjRefMsg> GetDeletableAllowedErrorRefs(
            VerificationParametersMsg requestParameters,
            BackgroundVerificationService qaService)
        {
            // Add invalidated allowed errors to be deleted
            if (requestParameters.ReportInvalidExceptions)
            {
                foreach (AllowedError allowedError in qaService.GetInvalidatedAllowedErrors())
                {
                    yield return(GetGdbObjRefMsg(allowedError));
                }
            }

            if (requestParameters.ReportUnusedExceptions)
            {
                foreach (AllowedError allowedError in qaService.GetUnusedAllowedErrors())
                {
                    yield return(GetGdbObjRefMsg(allowedError));
                }
            }
        }
Example #4
0
        private ServiceCallStatus VerifyDataQualityCore(
            [NotNull] DataVerificationRequest initialRequest,
            Func <DataVerificationResponse, DataVerificationRequest> moreDataRequest,
            IServerStreamWriter <DataVerificationResponse> responseStream,
            ITrackCancel trackCancel)
        {
            var request = initialRequest.Request;

            SetupUserNameProvider(request);

            void SendResponse(VerificationResponse r) => responseStream.WriteAsync(
                new DataVerificationResponse {
                Response = r
            });

            BackgroundVerificationService qaService = null;
            List <GdbObjRefMsg>           deletableAllowedErrorRefs = new List <GdbObjRefMsg>();
            QualityVerification           verification = null;
            var    issueCollection     = new ConcurrentBag <IssueMsg>();
            string cancellationMessage = null;

            try
            {
                // TODO: Separate long-lived objects, such as datasetLookup, domainTransactions (add to this class) from
                // short-term objects (request) -> add to background verification inputs
                IBackgroundVerificationInputs backgroundVerificationInputs =
                    _verificationInputsFactoryMethod(request);

                if (initialRequest.Schema != null)
                {
                    backgroundVerificationInputs.SetGdbSchema(
                        ProtobufConversionUtils.CreateSchema(initialRequest.Schema.ClassDefinitions,
                                                             initialRequest
                                                             .Schema.RelclassDefinitions,
                                                             moreDataRequest));
                }
                else if (moreDataRequest != null)
                {
                    backgroundVerificationInputs.SetRemoteDataAccess(moreDataRequest);
                }

                qaService = CreateVerificationService(backgroundVerificationInputs, issueCollection,
                                                      SendResponse, trackCancel);

                verification = qaService.Verify(backgroundVerificationInputs, trackCancel);

                deletableAllowedErrorRefs.AddRange(
                    GetDeletableAllowedErrorRefs(request.Parameters, qaService));
            }
            catch (Exception e)
            {
                _msg.Error($"Error checking quality for request {request}", e);
                cancellationMessage = $"Server error: {e.Message}";

                SetUnhealthy();
            }

            ServiceCallStatus result = SendFinalResponse(
                verification, cancellationMessage ?? qaService.CancellationMessage, issueCollection,
                deletableAllowedErrorRefs, qaService?.VerifiedPerimeter, SendResponse);

            return(result);
        }