/// <summary> /// Processes the GetProjectSettings request /// </summary> protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { ContractExecutionResult result = null; var projectSettingsRequest = CastRequestObjectTo <ProjectSettingsRequest>(item, errorCode: 68); if (projectSettingsRequest.ProjectSettingsType != ProjectSettingsType.Targets && projectSettingsRequest.ProjectSettingsType != ProjectSettingsType.Colors) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 77); } await ValidateProjectWithCustomer(customerUid, projectSettingsRequest.projectUid); try { var projectSettings = await projectRepo.GetProjectSettings(projectSettingsRequest.projectUid, userId, projectSettingsRequest.ProjectSettingsType).ConfigureAwait(false); result = projectSettings == null ? new ProjectSettingsResult(projectSettingsRequest.projectUid, null, projectSettingsRequest.ProjectSettingsType) : new ProjectSettingsResult(projectSettings.ProjectUid, JsonConvert.DeserializeObject <JObject>(projectSettings.Settings), projectSettings.ProjectSettingsType); } catch (Exception e) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 69, e.Message); } return(result); }
/// <summary> /// Notify TRex of updated DESIGN file /// </summary> public static async Task <ContractExecutionResult> NotifyTRexUpdateFile(Guid projectUid, ImportedFileType importedFileType, string filename, Guid importedFileUid, DateTime?surveyedUtc, ILogger log, IHeaderDictionary headers, IServiceExceptionHandler serviceExceptionHandler, ITRexImportFileProxy tRexImportFileProxy) { var result = new ContractExecutionResult(); string fullFileName = filename; if (importedFileType == ImportedFileType.SurveyedSurface && surveyedUtc != null) { fullFileName = fullFileName.IncludeSurveyedUtcInName(surveyedUtc.Value); } var request = new DesignRequest(projectUid, importedFileType, fullFileName, importedFileUid, surveyedUtc); try { result = await tRexImportFileProxy .UpdateFile(request, headers) .ConfigureAwait(false); } catch (Exception e) { log.LogError(e, $"NotifyTRexAddFile UpdateFile in Trex gateway failed with exception. request:{JsonConvert.SerializeObject(request)} filename: {fullFileName}"); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 57, "tRexImportFile.UpdateFile", e.Message); } return(result); }
public async Task TagFileSubmitter_TRex_Successful() { var projectUid = Guid.NewGuid(); var resolvedLegacyProjectId = 544; var tagFileContent = new byte[] { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9 }; var request = CompactionTagFileRequestExtended.CreateCompactionTagFileRequestExtended ( new CompactionTagFileRequest { ProjectId = resolvedLegacyProjectId, ProjectUid = projectUid, FileName = "Machine Name--whatever --161230235959", Data = tagFileContent, OrgId = string.Empty }, CreateAFence() ); // create the Trex mocks with successful result var mockConfigStore = new Mock <IConfigurationStore>(); var trexGatewayResult = new ContractExecutionResult(); var mockTRexTagFileProxy = new Mock <ITRexTagFileProxy>(); mockTRexTagFileProxy.Setup(s => s.SendTagFile(request, It.IsAny <IHeaderDictionary>())) .ReturnsAsync(trexGatewayResult); var submitter = RequestExecutorContainerFactory .Build <TagFileSubmissionExecutor>(_logger, mockConfigStore.Object, tRexTagFileProxy: mockTRexTagFileProxy.Object, customHeaders: _customHeaders); var result = await submitter.ProcessAsync(request); Assert.IsNotNull(result); Assert.IsTrue(result.Message == ContractExecutionResult.DefaultMessage); }
protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { if (!(item is CompactionTagFileRequest request)) { Logger.LogWarning($"{nameof(TagFileProcessExecutor)} Invalid Request passed in. Expected {typeof(CompactionTagFileRequest).Name} but got {(item == null ? "null" : item.GetType().Name)}"); return(ContractExecutionResult.ErrorResult("Invalid Request")); } request.Validate(); Logger.LogInformation($"{nameof(TagFileProcessExecutor)} Received Tag File with filename: {request.FileName}. TCC Org: {request.OrgId}. Data Length: {request.Data.Length}"); var result = ContractExecutionResult.ErrorResult("Not processed"); var internalProcessingError = false; try { result = await TRexTagFileProxy.SendTagFile(request); } catch (Exception e) { Logger.LogError(e, $"{nameof(TagFileProcessExecutor)} Failed to connect to TRex. Tag file {request.FileName}"); internalProcessingError = true; } internalProcessingError = IsInternalError(internalProcessingError, result.Code); // If we failed to connect to trex (or other retry-able error), // we want to either put it separate folder or not delete from SQS que // If the tag file was accepted, and not processed for a real reason (e.g no project found at seed position) // then we can to archive it, as it was successfully processed with no change to the datamodel await using (var data = new MemoryStream(request.Data)) { Logger.LogInformation($"{nameof(TagFileProcessExecutor)} Uploading Tag File {request.FileName}"); var path = GetS3Key(request.FileName); if (internalProcessingError) { path = $"{CONNECTION_ERROR_FOLDER}/{path}"; } if (!internalProcessingError || ArchiveOnInternalError) { TransferProxyFactory.NewProxy(TransferProxyType.TagFileGatewayArchive).Upload(data, path); Logger.LogInformation($"{nameof(TagFileProcessExecutor)} Successfully uploaded Tag File {request.FileName}"); } else { Logger.LogInformation($"{nameof(TagFileProcessExecutor)} No S3 upload as NoArchiveOnInternalError set. Tag File {request.FileName}"); } } if (internalProcessingError) { Logger.LogError($"{nameof(TagFileProcessExecutor)} InternalProcessingError {result.Code} {request.FileName} archiveFlag: {ArchiveOnInternalError}"); return(ContractExecutionResult.ErrorResult("Failed to connect to backend")); } return(result); }
/// <summary> /// Processes the request asynchronously. /// </summary> protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { var request = CastRequestObjectTo <TRexEditDataRequest>(item); var result = new ContractExecutionResult(); try { log.LogInformation($"#In# RemoveEditDataExecutor. Remove data edit {JsonConvert.SerializeObject(request)}"); var overrideRequest = new OverrideEventRequest(); var arg = new OverrideEventRequestArgument(true, request.ProjectUid, request.AssetUid, request.StartUtc, request.EndUtc, request.MachineDesignName, (ushort?)request.LiftNumber); var overrideResult = await overrideRequest.ExecuteAsync(arg); if (!overrideResult.Success) { log.LogInformation($"Failed to remove data edit: {overrideResult.Message}"); result = new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, overrideResult.Message); } } finally { log.LogInformation($"#Out# RemoveEditDataExecutor. Add data edit {JsonConvert.SerializeObject(request)}"); } return(result); }
private ContractExecutionResult ProcessTagFile(CompactionTagFileRequest request, string method) { if (request == null) { _logger.LogWarning("Empty request passed"); return(ContractExecutionResult.ErrorResult("Empty Request")); } request.Validate(); _logger.LogInformation($"Received Tag File (via {method}) with filename: {request.FileName}. TCC Org: {request.OrgId}. Data Length: {request.Data.Length}"); using (var data = new MemoryStream(request.Data)) { _logger.LogInformation($"Uploading Tag File {request.FileName}"); var path = GetS3Key(method, request.FileName, request.OrgId); // S3 needs a full path including file, but TCC needs a path and filename as two separate variables var s3FullPath = path + request.FileName; _transferProxyFactory.NewProxy(TransferProxyType.TagFileGatewayArchive).Upload(data, s3FullPath); _logger.LogInformation($"Successfully uploaded Tag File {request.FileName}"); } return(new ContractExecutionResult(0)); }
/// <summary> /// Processes the UpsertProjectSettings request /// </summary> protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { ContractExecutionResult result = null; var request = CastRequestObjectTo <ProjectSettingsRequest>(item, errorCode: 68); await ValidateProjectWithCustomer(customerUid, request?.projectUid); if (request.ProjectSettingsType == ProjectSettingsType.Targets || request.ProjectSettingsType == ProjectSettingsType.Colors) { await RaptorValidateProjectSettings(request); } var upsertProjectSettingsEvent = new UpdateProjectSettingsEvent() { ProjectUID = new Guid(request.projectUid), UserID = userId, ProjectSettingsType = request.ProjectSettingsType, Settings = request.Settings, ActionUTC = DateTime.UtcNow }; if (await projectRepo.StoreEvent(upsertProjectSettingsEvent).ConfigureAwait(false) < 1) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 52); } try { var projectSettings = await projectRepo.GetProjectSettings(request.projectUid, userId, request.ProjectSettingsType).ConfigureAwait(false); switch (request.ProjectSettingsType) { case ProjectSettingsType.Targets: case ProjectSettingsType.Colors: result = projectSettings == null ? new ProjectSettingsResult(request.projectUid, null, request.ProjectSettingsType) : new ProjectSettingsResult(request.projectUid, JsonConvert.DeserializeObject <JObject>(projectSettings.Settings), projectSettings.ProjectSettingsType); break; case ProjectSettingsType.ImportedFiles: var tempObj = JsonConvert.DeserializeObject <JArray>(projectSettings.Settings); var tempJObject = new JObject { ["importedFiles"] = tempObj }; result = new ProjectSettingsResult(request.projectUid, tempJObject, projectSettings.ProjectSettingsType); break; default: serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 77); break; } } catch (Exception e) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 69, e.Message); } return(result); }
/// <summary> /// Notify TRex of new DESIGN file /// </summary> /// <returns></returns> public static async Task <ContractExecutionResult> NotifyTRexAddFile(Guid projectUid, ImportedFileType importedFileType, string filename, Guid importedFileUid, DateTime?surveyedUtc, ILogger log, IHeaderDictionary headers, IServiceExceptionHandler serviceExceptionHandler, ITRexImportFileProxy tRexImportFileProxy, IProjectRepository projectRepo ) { var result = new ContractExecutionResult(); string fullFileName = filename; if (importedFileType == ImportedFileType.SurveyedSurface && surveyedUtc != null) { fullFileName = fullFileName.IncludeSurveyedUtcInName(surveyedUtc.Value); } var request = new DesignRequest(projectUid, importedFileType, fullFileName, importedFileUid, surveyedUtc); try { result = await tRexImportFileProxy .AddFile(request, headers) .ConfigureAwait(false); } catch (Exception e) { log.LogError(e, $"NotifyTRexAddFile AddFile in Trex gateway failed with exception. request:{JsonConvert.SerializeObject(request)} filename: {fullFileName}"); await ImportedFileRequestDatabaseHelper.DeleteImportedFileInDb (projectUid, importedFileUid, serviceExceptionHandler, projectRepo, true) .ConfigureAwait(false); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 57, "tRexImportFile.AddFile", e.Message); } log.LogDebug( $"NotifyTRexAddFile: projectUid: {projectUid}, filename: {filename} importedFileUid {importedFileUid}. TRex returned code: {result?.Code ?? -1}."); if (result != null && result.Code != 0) { log.LogError( $"NotifyTRexAddFile AddFile in Trex failed. projectUid: {projectUid}, filename: {filename} importedFileUid {importedFileUid}. Reason: {result?.Code ?? -1} {result?.Message ?? "null"}."); await ImportedFileRequestDatabaseHelper.DeleteImportedFileInDb(projectUid, importedFileUid, serviceExceptionHandler, projectRepo, true) .ConfigureAwait(false); serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 114, result.Code.ToString(), result.Message); } return(result); }
/// <summary> /// Runs a VSS job /// </summary> protected async Task <ContractExecutionResult> RunJob(JobRequest request, PerformContext context) { var result = new ContractExecutionResult(ContractExecutionStatesEnum.ExecutedSuccessfully); log.LogDebug($"About to run job with request {JsonConvert.SerializeObject(request)}"); var job = jobFactory.GetJob(request.JobUid); if (job == null) { result = errorCodesProvider.CreateErrorResult(environment, SchedulerErrorCodes.VSSJobCreationFailure, request.JobUid.ToString(), "Unable to create job"); } else { try { log.LogInformation($"Setting up job {request.JobUid}"); await job.Setup(request.SetupParameters, context); log.LogInformation($"Running job {request.JobUid}"); await job.Run(request.RunParameters, context); log.LogInformation($"Tearing down job {request.JobUid}"); await job.TearDown(request.TearDownParameters, context); log.LogInformation($"Job {request.JobUid} completed"); } catch (ServiceException se) { log.LogError(se, "ServiceException error during RunJob():"); result = errorCodesProvider.CreateErrorResult(environment, SchedulerErrorCodes.VSSJobExecutionFailure, request.JobUid.ToString(), se.GetFullContent); } catch (Exception e) { log.LogError(e, "Exception error during RunJob():"); result = errorCodesProvider.CreateErrorResult(environment, SchedulerErrorCodes.VSSJobExecutionFailure, request.JobUid.ToString(), e.Message); } } if (result.Code != ContractExecutionStatesEnum.ExecutedSuccessfully) { log.LogError(result.Message); throw new ServiceException(HttpStatusCode.InternalServerError, result); } log.LogInformation($"{nameof(RunJob)} completed with result: {JsonConvert.SerializeObject(result)}"); return(result); }
/// <summary> /// Process tagfile request /// </summary> protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { var request = item as CompactionTagFileRequest; var result = new ContractExecutionResult((int)TRexTagFileResultCode.TRexUnknownException, "TRex unknown result (TagFileExecutor.ProcessEx)"); try { log.LogInformation($"#In# TagFileExecutor. Process tag file:{request.FileName}, Project:{request.ProjectUid}, TCCOrgID:{request.OrgId}, TreatAsJohnDoe = {request.TreatAsJohnDoe}"); var submitRequest = new SubmitTAGFileRequest(); var arg = new SubmitTAGFileRequestArgument { ProjectID = request.ProjectUid, AssetID = null, // not available via TagFileController APIs TreatAsJohnDoe = request.TreatAsJohnDoe, TAGFileName = request.FileName, TagFileContent = request.Data, TCCOrgID = request.OrgId, SubmissionFlags = TAGFiles.Models.TAGFileSubmissionFlags.AddToArchive, OriginSource = request.OriginSource }; var res = await submitRequest.ExecuteAsync(arg); if (res.Success) { result = TagFileResult.Create(0, ContractExecutionResult.DefaultMessage); } else { result = TagFileResult.Create(res.Code, res.Message); } } finally { if (request != null) { log.LogInformation($"#Out# TagFileExecutor. Process tagfile:{request.FileName}, Project:{request.ProjectUid}, Submission Code: {result.Code}, Message:{result.Message}"); } else { log.LogInformation("#Out# TagFileExecutor. Invalid request"); } } return(result); }
/// <summary> /// /// </summary> public void OnStateElection(ElectStateContext context) { // the way Hangfire works is retrying a job X times (10 by default), //so this won't be called directly with a failed state sometimes. // To solve this we should look into TraversedStates for a failed state var failed = context.CandidateState as FailedState ?? context.TraversedStates.FirstOrDefault(x => x is FailedState) as FailedState; if (failed == null) { return; } //GracefulWebRequest gets a HttpWebResponse containing the ServiceException and formats it as the message of a System.Exception //e.g. "BadRequest {"Code":2002,"Message":"Failed to get requested export data with error: No data for export"}" var message = failed.Exception.Message; var httpStatusCode = HttpStatusCode.InternalServerError; ContractExecutionResult result = null; try { //Extract the HttpStatusCode httpStatusCode = (HttpStatusCode)Enum.Parse(typeof(HttpStatusCode), message.Split(' ')[0]); message = message.Substring(httpStatusCode.ToString().Length + 1); //See if it's a service exception result = JsonConvert.DeserializeObject <ContractExecutionResult>(message); } catch (Exception) { //Not a service exception therefore just use original exception message result = new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, message); } var failedDetails = new FailureDetails { Code = httpStatusCode, Result = result }; var additionalData = JsonConvert.SerializeObject(failedDetails); context.SetJobParameter <FailureDetails>(ExportFailedState.EXPORT_DETAILS_KEY, failedDetails); context.CandidateState = new ExportFailedState(failed.Exception, additionalData); }
/// <summary> /// ServiceException class constructor. /// </summary> public ServiceException(HttpStatusCode code, ContractExecutionResult result, Exception innerException) : base(result.Message) { GetResult = result; Code = code; InnerException = innerException; }
public static void LogResult(this ILogger log, string methodName, string request, ContractExecutionResult result) { if (result != null && result.Code == ContractExecutionStatesEnum.ExecutedSuccessfully) { var infoMessage = $"{methodName}: was successfully processed: Request {request} Result {JsonConvert.SerializeObject(result)}"; log.LogInformation(infoMessage); } else { var errorMessage = $"{methodName}: failed to be processed: Request {request} Result {JsonConvert.SerializeObject(result)}"; log.LogError(errorMessage); } }
public static int LogResult(this ILogger log, string methodName, string projectUid, ContractExecutionResult result) { if (result.Code == ContractExecutionStatesEnum.ExecutedSuccessfully) { var infoMessage = string.Format("{0}: was successfully processed: Request {1} Result {2}", methodName, projectUid, JsonConvert.SerializeObject(result)); log.LogInformation(infoMessage); } else { var errorMessage = string.Format("{0}: failed to be processed: Request {1} Result {2}", methodName, projectUid, JsonConvert.SerializeObject(result)); log.LogError(errorMessage); } return(0); }
/// <summary> /// Receive a TAG file to be processed, validate TAG File Authorization for the file, and add it to the /// queue to be processed. /// </summary> /// <param name="projectId">Project ID to be used as an override to any project ID that may be determined via TAG file authorization</param> /// <param name="assetId">Asset ID to be used as an override to any Asset ID that may be determined via TAG file authorization</param> /// <param name="tagFileName">Name of the physical tag file for archiving and logging</param> /// <param name="tagFileContent">The content of the TAG file to be processed, expressed as a byte array</param> /// <param name="tccOrgId">Used by TFA service to match VL customer to TCC org when looking for project if multiple projects and/or machine ID not in tag file</param> /// <param name="treatAsJohnDoe">The TAG file will be processed as if it were a john doe machine is projectId is also specified</param> /// <param name="tagFileSubmissionFlags">A flag set controlling how certain aspects of managing a submitted TAG file should be managed</param> /// <param name="originSource">Indictaes the system of origin this file came from</param> public async Task <SubmitTAGFileResponse> ExecuteAsync(Guid?projectId, Guid?assetId, string tagFileName, byte[] tagFileContent, string tccOrgId, bool treatAsJohnDoe, TAGFileSubmissionFlags tagFileSubmissionFlags, TAGFileOriginSource originSource) { if (OutputInformationalRequestLogging) { _log.LogInformation($"#In# SubmitTAGFileResponse. Processing {tagFileName} TAG file into ProjectUID:{projectId}, asset:{assetId}, John Doe?:{treatAsJohnDoe}, submission flags: {tagFileSubmissionFlags}, origin source:{originSource}"); } var response = new SubmitTAGFileResponse { FileName = tagFileName, Success = false, Message = "TRex unknown result (SubmitTAGFileResponse.Execute)", Code = (int)TRexTagFileResultCode.TRexUnknownException, }; try { try { // wrap up details into obj var td = new TagFileDetail { assetId = assetId, projectId = projectId, tagFileName = tagFileName, tagFileContent = tagFileContent, tccOrgId = tccOrgId, IsJohnDoe = treatAsJohnDoe }; ContractExecutionResult result; if (originSource == TAGFileOriginSource.LegacyTAGFileSource) { // Validate tag file submission result = TagfileValidator.PreScanTagFile(td, out var tagFilePreScan); if (result.Code == (int)TRexTagFileResultCode.Valid) { if (_isDeviceGatewayEnabled) { SendDeviceStatusToDeviceGateway(td, tagFilePreScan); } result = await TagfileValidator.ValidSubmission(td, tagFilePreScan); } } else { // For non legacy origins where we have no overt validation rules or need for device status notifications // note the presented file as valid for processing result = new ContractExecutionResult((int)TRexTagFileResultCode.Valid, "Success"); } response.Code = result.Code; response.Message = result.Message; if (result.Code == (int)TRexTagFileResultCode.Valid && td.projectId != null) // If OK add to process queue { // First archive the tag file if (_tagFileArchiving && tagFileSubmissionFlags.HasFlag(TAGFileSubmissionFlags.AddToArchive) // For now, GCS900/Earthworks style TAG files are the only ones archived && originSource == TAGFileOriginSource.LegacyTAGFileSource) { _log.LogInformation($"#Progress# SubmitTAGFileResponse. Archiving tag file:{tagFileName}, ProjectUID:{td.projectId}"); if (!await TagFileRepository.ArchiveTagfileS3(td)) { _log.LogError($"SubmitTAGFileResponse. Failed to archive tag file. Returning TRexQueueSubmissionError error. ProjectUID:{td.projectId}, AssetUID:{td.assetId}, Tagfile:{tagFileName}"); throw new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, $"SubmitTAGFileResponse. Failed to archive tag file {tagFileName} to S3")); } } // switch from nullable to not nullable var validProjectId = td.projectId ?? Guid.Empty; var validAssetId = td.assetId ?? Guid.Empty; if (OutputInformationalRequestLogging) { _log.LogInformation($"#Progress# SubmitTAGFileResponse. Submitting tag file to TagFileBufferQueue. ProjectUID:{validProjectId}, AssetUID:{validAssetId}, Tagfile:{tagFileName}, JohnDoe:{td.IsJohnDoe} "); } var tagKey = new TAGFileBufferQueueKey(tagFileName, validProjectId, validAssetId); var tagItem = new TAGFileBufferQueueItem { InsertUTC = DateTime.UtcNow, ProjectID = validProjectId, AssetID = validAssetId, FileName = tagFileName, Content = tagFileContent, IsJohnDoe = td.IsJohnDoe, SubmissionFlags = tagFileSubmissionFlags, OriginSource = originSource }; if (_queue == null) { throw new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, "SubmitTAGFileResponse. Processing queue not available")); } if (_queue.Add(tagKey, tagItem)) // Add tag file to queue { response.Success = true; response.Message = ""; response.Code = (int)TRexTagFileResultCode.Valid; // Commented out top reduce logging // Log.LogInformation($"Added TAG file {tagKey.FileName} representing asset {tagKey.AssetUID} within project {tagKey.ProjectUID} into the buffer queue"); } else { response.Success = false; response.Message = "SubmitTAGFileResponse. Failed to submit tag file to processing queue. Request already exists"; response.Code = (int)TRexTagFileResultCode.TRexQueueSubmissionError; _log.LogWarning(response.Message); } } else { response.Success = false; } } catch (Exception e) // catch all exceptions here { _log.LogError(e, $"#Exception# SubmitTAGFileResponse. Exception occured processing {tagFileName} Exception:"); throw new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, $"SubmitTAGFileResponse. Exception {e.Message}")); } } finally { if (OutputInformationalRequestLogging) { _log.LogInformation($"#Out# SubmitTAGFileResponse. Processed {tagFileName} Result: {response.Success}, Message:{response.Message} Code:{response.Code}"); } } return(response); }
public static int LogResult(this ILogger log, string methodName, Object request, ContractExecutionResult result) { var infoMessage = string.Format("{0}: was successfully processed: Request {1} Result {2}", methodName, JsonConvert.SerializeObject(request), JsonConvert.SerializeObject(result)); log.LogInformation(infoMessage); return(0); }
public TwoFiltersRequiredException(HttpStatusCode statusCode, ContractExecutionResult contractExecution) : base(statusCode, contractExecution) { }
public MissingDesignDescriptorException(HttpStatusCode statusCode, ContractExecutionResult contractExecution) : base(statusCode, contractExecution) { }
protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item) { if (!(item is SnsPayload payload)) { Logger.LogWarning($"{nameof(TagFileSnsProcessExecutor)} Invalid Request passed in. Expected {typeof(SnsPayload).Name} but got {(item == null ? "null" : item.GetType().Name)}"); return(ContractExecutionResult.ErrorResult("Invalid Request")); } Logger.LogInformation($"{nameof(TagFileSnsProcessExecutor)} Sns message type: {payload.Type}, topic: {payload.TopicArn}"); if (payload.Type == SnsPayload.SubscriptionType) { // Request for subscription Logger.LogInformation($"{nameof(TagFileSnsProcessExecutor)} SNS SUBSCRIPTION REQUEST: {payload.Message}, Subscription URL: '{payload.SubscribeURL}'"); return(new ContractExecutionResult()); } if (payload.IsNotification) { // Got a tag file SnsTagFile tagFile; try { tagFile = JsonConvert.DeserializeObject <SnsTagFile>(payload.Message); } catch (Exception e) { Logger.LogError(e, $"{nameof(TagFileSnsProcessExecutor)} Failed to deserialize SnsTagFile {payload.MessageId}"); tagFile = null; } if (tagFile == null) { // this will cause payload to be deleted from the SQS que Logger.LogWarning($"{nameof(TagFileSnsProcessExecutor)} Could not convert to Tag File Model. JSON: {payload.Message}"); return(new ContractExecutionResult(1, "Failed to parse tag file model")); } byte[] data; if (!string.IsNullOrEmpty(tagFile.DownloadUrl)) { Logger.LogInformation($"{nameof(TagFileSnsProcessExecutor)} Tag file {tagFile.FileName} needs to be downloaded from : {tagFile.DownloadUrl}"); var downloadTagFileData = await WebRequest.ExecuteRequestAsStreamContent(tagFile.DownloadUrl, HttpMethod.Get); await using var ms = new MemoryStream(); await downloadTagFileData.CopyToAsync(ms); data = ms.ToArray(); if (data.Length != tagFile.FileSize) { Logger.LogWarning($"{nameof(TagFileSnsProcessExecutor)} Downloaded data length {data.Length} is not equal to expected length {tagFile.FileSize}"); } Logger.LogInformation($"{nameof(TagFileSnsProcessExecutor)} Downloaded tag file {tagFile.FileName}, total bytes: {data.Length}"); } else { Logger.LogInformation($"{nameof(TagFileSnsProcessExecutor)} Tag file data is included in payload for file {tagFile.FileName}"); data = tagFile.Data; } var request = new CompactionTagFileRequest { Data = data, FileName = tagFile.FileName, OrgId = tagFile.OrgId, OriginSource = tagFile.originSource }; Logger.LogInformation($"{nameof(TagFileSnsProcessExecutor)} Attempting to process sns tag file {tagFile.FileName}"); var executor = Build <TagFileProcessExecutor>(); executor.ArchiveOnInternalError = false; var result = await executor.ProcessAsync(request); Logger.LogInformation($"{nameof(TagFileSnsProcessExecutor)} Got result {JsonConvert.SerializeObject(result)} for Tag file: {tagFile?.FileName}"); return(result); } Logger.LogWarning($"{nameof(TagFileSnsProcessExecutor)} Unknown SNS Type: {payload.Type} - not sure how to process"); return(new ContractExecutionResult(99, "Unknown SNS message")); }
public static void ShouldBe(this ContractExecutionResult contractExecutionResult, int returnCode, string message) { Assert.Equal(returnCode, contractExecutionResult.Code); Assert.Equal(message, contractExecutionResult.Message); }
public static void IsSuccessResponse(this ContractExecutionResult contractExecutionResult) => contractExecutionResult.ShouldBe(ContractExecutionStatesEnum.ExecutedSuccessfully, ContractExecutionResult.DefaultMessage);