public async Task <bool> RefreshJobGroupOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); var socRequest = context.GetInput <SocRequestModel>(); await context.CallActivityAsync(nameof(PurgeSocActivity), socRequest.SocId).ConfigureAwait(true); var upsertResult = await context.CallActivityAsync <HttpStatusCode>(nameof(TransformItemActivity), socRequest.Url).ConfigureAwait(true); if (upsertResult == HttpStatusCode.OK || upsertResult == HttpStatusCode.Created) { var eventGridPostRequest = new EventGridPostRequestModel { ItemId = socRequest.SocId, Api = $"{eventGridClientOptions.ApiEndpoint}/{socRequest.SocId}", DisplayText = $"LMI transformed into job-group from {socRequest.Url}", EventType = socRequest.IsDraftEnvironment ? EventTypeForDraft : EventTypeForPublished, }; await context.CallActivityAsync(nameof(PostTransformationEventActivity), eventGridPostRequest).ConfigureAwait(true); return(true); } return(false); }
public async Task <HttpStatusCode> GraphRefreshOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); logger.LogInformation("Start importing of LMI data from API"); var orchestratorRequestModel = context.GetInput <OrchestratorRequestModel>(); var socJobProfileMappings = await context.CallActivityAsync <IList <SocJobProfileMappingModel>?>(nameof(GetJobProfileSocMappingsActivity), null).ConfigureAwait(true); if (socJobProfileMappings != null && socJobProfileMappings.Any()) { await context.CallActivityAsync(nameof(GraphPurgeActivity), null).ConfigureAwait(true); logger.LogInformation($"Importing {socJobProfileMappings.Count} SOC mappings"); var parallelTasks = new List <Task <Guid?> >(); foreach (var socJobProfileMapping in socJobProfileMappings) { parallelTasks.Add(context.CallActivityAsync <Guid?>(nameof(ImportSocItemActivity), socJobProfileMapping)); } await Task.WhenAll(parallelTasks).ConfigureAwait(true); decimal importedToGraphCount = parallelTasks.Count(t => t.Result != null); var successPercentage = decimal.Divide(importedToGraphCount, socJobProfileMappings.Count) * 100; logger.LogInformation($"Imported to Graph {importedToGraphCount} of {socJobProfileMappings.Count} SOC mappings = {successPercentage:0.0}% success"); if (successPercentage >= orchestratorRequestModel.SuccessRelayPercent) { var eventGridPostRequest = new EventGridPostRequestModel { ItemId = Guid.NewGuid(), Api = $"{eventGridClientOptions.ApiEndpoint}", DisplayText = "LMI Import refreshed", EventType = orchestratorRequestModel.IsDraftEnvironment ? EventTypeForDraft : EventTypeForPublished, }; await context.CallActivityAsync(nameof(PostGraphEventActivity), eventGridPostRequest).ConfigureAwait(true); return(HttpStatusCode.OK); } return(HttpStatusCode.BadRequest); } else { logger.LogWarning("No data available from JOB profile SOC mappings - no data imported"); return(HttpStatusCode.NoContent); } }
public async Task LmiOrchestrationTriggerPostGraphEventActivityIsSuccessful() { // Arrange var eventGridPostRequest = new EventGridPostRequestModel { ItemId = Guid.NewGuid(), DisplayText = "Display text", EventType = "published", }; // Act await lmiOrchestrationTrigger.PostTransformationEventActivity(eventGridPostRequest).ConfigureAwait(false); // Assert A.CallTo(() => fakeEventGridService.SendEventAsync(A <EventGridEventData> .Ignored, A <string> .Ignored, A <string> .Ignored)).MustHaveHappenedOnceExactly(); }
public async Task PurgeOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); await context.CallActivityAsync(nameof(PurgeActivity), null).ConfigureAwait(true); var eventGridPostRequest = new EventGridPostRequestModel { ItemId = context.NewGuid(), Api = $"{eventGridClientOptions.ApiEndpoint}", DisplayText = "LMI purged all job-group ", EventType = EventTypeForDraftDiscarded, }; await context.CallActivityAsync(nameof(PostTransformationEventActivity), eventGridPostRequest).ConfigureAwait(true); }
public async Task GraphPurgeOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); var orchestratorRequestModel = context.GetInput <OrchestratorRequestModel>(); await context.CallActivityAsync(nameof(GraphPurgeActivity), null).ConfigureAwait(true); var eventGridPostRequest = new EventGridPostRequestModel { ItemId = Guid.NewGuid(), Api = $"{eventGridClientOptions.ApiEndpoint}", DisplayText = "LMI Import purged", EventType = orchestratorRequestModel.IsDraftEnvironment ? EventTypeForDraftDiscarded : EventTypeForDeleted, }; await context.CallActivityAsync(nameof(PostGraphEventActivity), eventGridPostRequest).ConfigureAwait(true); }
public async Task <HttpStatusCode> GraphRefreshSocOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); var socRequest = context.GetInput <SocRequestModel>(); if (socJobProfilesMappingsCachedModel.SocJobProfileMappings == null || !socJobProfilesMappingsCachedModel.SocJobProfileMappings.Any()) { socJobProfilesMappingsCachedModel.SocJobProfileMappings = await context.CallActivityAsync <IList <SocJobProfileMappingModel>?>(nameof(GetJobProfileSocMappingsActivity), null).ConfigureAwait(true); } var socJobProfileMapping = new SocJobProfileMappingModel { Soc = socRequest.Soc, JobProfiles = socJobProfilesMappingsCachedModel.SocJobProfileMappings.FirstOrDefault(f => f.Soc == socRequest.Soc)?.JobProfiles }; await context.CallActivityAsync(nameof(GraphPurgeSocActivity), socRequest.Soc).ConfigureAwait(true); var eventGridPostPurgeRequest = new EventGridPostRequestModel { ItemId = socRequest.SocId, Api = $"{eventGridClientOptions.ApiEndpoint}/{socRequest.SocId}", DisplayText = $"LMI SOC purged: {socRequest.Soc}", EventType = socRequest.IsDraftEnvironment ? EventTypeForDraftDiscarded : EventTypeForDeleted, }; await context.CallActivityAsync(nameof(PostGraphEventActivity), eventGridPostPurgeRequest).ConfigureAwait(true); var itemId = await context.CallActivityAsync <Guid?>(nameof(ImportSocItemActivity), socJobProfileMapping).ConfigureAwait(true); if (itemId != null) { var eventGridPostRequest = new EventGridPostRequestModel { ItemId = itemId, Api = $"{eventGridClientOptions.ApiEndpoint}/{itemId}", DisplayText = $"LMI SOC refreshed: {socRequest.Soc}", EventType = socRequest.IsDraftEnvironment ? EventTypeForDraft : EventTypeForPublished, }; await context.CallActivityAsync(nameof(PostGraphEventActivity), eventGridPostRequest).ConfigureAwait(true); return(HttpStatusCode.OK); } return(HttpStatusCode.NoContent); }
public async Task PurgeJobGroupOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); var socRequest = context.GetInput <SocRequestModel>(); await context.CallActivityAsync(nameof(PurgeSocActivity), socRequest.SocId).ConfigureAwait(true); var eventGridPostRequest = new EventGridPostRequestModel { ItemId = socRequest.SocId, Api = $"{eventGridClientOptions.ApiEndpoint}/{socRequest.SocId}", DisplayText = $"LMI purged job-group for {socRequest.SocId}", EventType = socRequest.IsDraftEnvironment ? EventTypeForDraftDiscarded : EventTypeForDeleted, }; await context.CallActivityAsync(nameof(PostTransformationEventActivity), eventGridPostRequest).ConfigureAwait(true); }
public async Task RefreshOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context) { _ = context ?? throw new ArgumentNullException(nameof(context)); var socRequest = context.GetInput <SocRequestModel>(); var summaryItems = await context.CallActivityAsync <IList <SocDatasetSummaryItemModel>?>(nameof(GetSummaryItemsActivity), socRequest.Uri).ConfigureAwait(true); if (summaryItems != null && summaryItems.Any()) { await context.CallActivityAsync(nameof(PurgeActivity), null).ConfigureAwait(true); logger.LogInformation($"Transforming {summaryItems.Count} LMI data items"); var parallelTasks = new List <Task <HttpStatusCode> >(); foreach (var summaryItem in summaryItems.OrderBy(o => o.Soc)) { var uri = new Uri($"{socRequest.Uri}/{summaryItem.Id}", UriKind.Absolute); parallelTasks.Add(context.CallActivityAsync <HttpStatusCode>(nameof(TransformItemActivity), uri)); } await Task.WhenAll(parallelTasks).ConfigureAwait(true); var eventGridPostRequest = new EventGridPostRequestModel { ItemId = context.NewGuid(), Api = $"{eventGridClientOptions.ApiEndpoint}", DisplayText = $"LMI transformed all job-groups from {socRequest.Uri}", EventType = EventTypeForDraft, }; await context.CallActivityAsync(nameof(PostTransformationEventActivity), eventGridPostRequest).ConfigureAwait(true); int transformedToJobGroupCount = parallelTasks.Count(t => t.Result == HttpStatusCode.OK || t.Result == HttpStatusCode.Created); logger.LogInformation($"Transformed to Job-group {transformedToJobGroupCount} of {summaryItems.Count} SOCs"); } else { logger.LogWarning("No data available LMI Import data - no data transformed"); } }