import { AvailabilityTestConfig , SerializableResponse , ServiceConfiguration } from 'common' ; import * as durableFunctions from 'durable-functions' ; import { IOrchestrationFunctionContext , Task , TaskSet } from 'durable-functions/lib/src/classes' ; import { TestContextData } from 'functional-tests' ; import { inject , injectable } from 'inversify' ; import { ContextAwareLogger } from 'logger' ; import { WebController } from 'service-library' ; import { finalizerTestGroupName } from '../e2e-test-group-names' ; import { createScenarioDrivers } from '../e2e-test-scenarios/create-scenarios' ; import { getTestIdentifiersForScenario } from '../e2e-test-scenarios/get-test-identifiers' ; import { ScanScenarioDriver } from '../e2e-test-scenarios/scan-scenario-driver' ; import { OrchestrationSteps } from '../orchestration/orchestration-steps' ; import { createOrchestrationSteps , OrchestrationStepsFactory } from '../orchestration/orchestration-steps-factory' ; @ injectable ( ) export class HealthMonitorOrchestrationController extends WebController { public readonly apiVersion = '1.0' ; public readonly apiName = 'health-monitor-orchestration' ; public constructor ( @ inject ( ServiceConfiguration ) protected readonly serviceConfig , @ inject ( ContextAwareLogger ) logger , private readonly df = durableFunctions , private readonly e2eScenarioFactory = createScenarioDrivers , private readonly orchestrationStepsProvider = createOrchestrationSteps , private readonly testIdentifiersProvider = getTestIdentifiersForScenario ) { super ( logger ) ; } protected async handleRequest ( ... args ) { this . logger . setCommonProperties ( { source : 'healthMonitorOrchestrationFunc' } ) ; this . logger . logInfo ( `Executing '${ this . context . executionContext . functionName }' function.` , { funcName : this . context . executionContext . functionName , invocationId : this . context . executionContext . invocationId , } ) ; await this . setContextGenerator ( ) ; this . invokeOrchestration ( ) ; } protected validateRequest ( ... args ) { return true ; } private invokeOrchestration ( ) { const orchestrationExecutor = this . getOrchestrationExecutor ( ) ; orchestrationExecutor ( < IOrchestrationFunctionContext > this . context ) ; } private getOrchestrationExecutor ( ) { return this . df . orchestrator ( function * ( context ) : Generator < Task | TaskSet , void , SerializableResponse & void > { const thisObj = context . bindingData . controller as HealthMonitorOrchestrationController ; const availabilityTestConfig = context . bindingData . availabilityTestConfig as AvailabilityTestConfig ; const orchestrationSteps = yield * thisObj . orchestrationStepsProvider ( context , availabilityTestConfig , thisObj . logger ) ; const scenarios = thisObj . e2eScenarioFactory ( orchestrationSteps , availabilityTestConfig ) ; yield * thisObj . beginE2ETestRun ( orchestrationSteps , scenarios ) ; yield * orchestrationSteps . invokeHealthCheckRestApi ( ) ; for ( const scenario of scenarios ) { yield * scenario . submitScanPhase ( ) ; } for ( const scenario of scenarios ) { yield * scenario . waitForScanCompletionPhase ( ) ; } for ( const scenario of scenarios ) { yield * scenario . afterScanCompletedPhase ( ) ; } yield * thisObj . finalizeE2ETestRun ( orchestrationSteps ) ; } ) ; } private async setContextGenerator ( ) { this . context . bindingData . controller = this ; this . context . bindingData . availabilityTestConfig = await this . serviceConfig . getConfigValue ( 'availabilityTestConfig' ) ; } private * beginE2ETestRun ( orchestrationSteps , scenarios ) { const testsToRun = scenarios . flatMap ( ( scenario ) => this . testIdentifiersProvider ( scenario . testDefinition ) ) ; yield * orchestrationSteps . logTestRunStart ( testsToRun ) ; } private * finalizeE2ETestRun ( orchestrationSteps ) { yield * orchestrationSteps . runFunctionalTestGroups ( 'Finalizer' , { } as TestContextData , [ finalizerTestGroupName ] ) ; } }