示例#1
0
        static void Main(string[] args)
        {
            var function = new MaintenanceHandler();
            var context  = new TestLambdaContext();

            context.RemainingTime = TimeSpan.FromHours(50);
            context.Logger        = new ConsoleLogger();

            var invokeAction = new LambdaInvokeAction
            {
                Action = CumulusConstants.MaintenanceAction.CalculateNumberOfTrades,
            };

            function.Invoke(invokeAction, context).Wait();

            //var function = new Handler();
            //var context = new TestLambdaContext();
            //context.RemainingTime = TimeSpan.FromHours(50);
            //context.Logger = new ConsoleLogger();

            //var lambdaInvokeAction = new LambdaInvokeAction
            //{
            //    Action = CumulusConstants.LambdaManagerAction.RoutePendingObjects
            //};

            //function.Invoke(lambdaInvokeAction, context).Wait();
            Console.WriteLine("DONE !!!!!!!!!!!!");
            Console.ReadLine();
        }
示例#2
0
        public async Task Invoke(LambdaInvokeAction invokeAction, ILambdaContext context)
        {
            if (invokeAction == null)
            {
                throw new ArgumentException("Unknown action");
            }

            context.Logger.LogLine($"maintenance middleware invoked with action request '{invokeAction.Action}'");

            var cancellationTokenSource = new CancellationTokenSource(context.RemainingTime);

            var cancellationToken = cancellationTokenSource.Token;

            if (serviceContext == null)
            {
                serviceContext = new ServiceContext();
                await serviceContext.InjectServiceAsync(context, cancellationToken);

                await serviceContext.InitializeAsync(cancellationToken);
            }

            var service = await serviceContext.GetServiceAsync <IMaintenanceService>(cancellationToken);

            switch (invokeAction.Action)
            {
            case CumulusConstants.MaintenanceAction.EnsureTableCreated:
                await service.EnsureAllTablesCreated(cancellationToken);

                break;

            case CumulusConstants.MaintenanceAction.ImportProductEurex:
                await service.ImportProduct(StockMarket.Eurex, cancellationToken);

                break;

            case CumulusConstants.MaintenanceAction.ImportProductXetra:
                await service.ImportProduct(StockMarket.Xetra, cancellationToken);

                break;

            case CumulusConstants.MaintenanceAction.CalculateNumberOfTrades:
                await service.CalculateNumberOfTrades(cancellationToken);

                break;

            case CumulusConstants.MaintenanceAction.RerouteEurexDeadMessages:
                await service.RerouteDeadMessages(StockMarket.Eurex, cancellationToken);

                break;

            case CumulusConstants.MaintenanceAction.RerouteXetraDeadMessages:
                await service.RerouteDeadMessages(StockMarket.Xetra, cancellationToken);

                break;

            default: throw new ArgumentException("Unknown action");
            }

            context.Logger.LogLine($"maintenance middleware action '{invokeAction.Action}' completed successfully");
        }
示例#3
0
        public void TestToUpperFunction()
        {
            // Invoke the lambda function and confirm the string was upper cased.
            var function = new MaintenanceHandler();
            var context  = new TestLambdaContext();

            var invokeAction = new LambdaInvokeAction
            {
                Action = "",
            };

            function.Invoke(invokeAction, context).Wait();
        }
示例#4
0
        public void TestRerouteEurexDeadMessages()
        {
            var function = new MaintenanceHandler();
            var context  = new TestLambdaContext();

            context.RemainingTime = TimeSpan.FromMinutes(5);

            var invokeAction = new LambdaInvokeAction
            {
                Action = CumulusConstants.MaintenanceAction.RerouteEurexDeadMessages,
            };

            function.Invoke(invokeAction, context).Wait();
        }
示例#5
0
        public void TestImportProductsXetra()
        {
            var function = new MaintenanceHandler();
            var context  = new TestLambdaContext();

            context.RemainingTime = TimeSpan.FromMinutes(5);

            var invokeAction = new LambdaInvokeAction
            {
                Action = CumulusConstants.MaintenanceAction.ImportProductXetra,
            };

            function.Invoke(invokeAction, context).Wait();
        }
示例#6
0
        public void TestToUpperFunction()
        {
            // Invoke the lambda function and confirm the string was upper cased.
            var function = new Handler();
            var context  = new TestLambdaContext();

            context.RemainingTime = TimeSpan.FromMinutes(50);

            var lambdaInvokeAction = new LambdaInvokeAction
            {
                Action = CumulusConstants.LambdaManagerAction.RoutePendingObjects
            };

            function.Invoke(lambdaInvokeAction, context).Wait();
        }
        private LambdaInvokeAction CreateLambdaInvokeAction()
        {
            string ecsClusterArn = this.FormatArn(new ArnComponents
            {
                Service      = "ecs",
                Resource     = "cluster",
                ResourceName = this.settings.AppEcsClusterName
            });

            var lambdaInvokeAction = new LambdaInvokeAction(new LambdaInvokeActionProps
            {
                ActionName     = "Recycle-ECS-Cluster-Tasks",
                Lambda         = this.CreateLambdaForRestartingEcsApp(),
                UserParameters = new Dictionary <string, object>()
                {
                    { "clusterArn", ecsClusterArn }
                }
            });

            return(lambdaInvokeAction);
        }
示例#8
0
        public async Task Invoke(LambdaInvokeAction invokeAction, ILambdaContext context)
        {
            if (invokeAction == null)
            {
                throw new ArgumentException("Unknown action");
            }

            context.Logger.LogLine($"lambda manager invoked with action request '{invokeAction.Action}'");

            var cancellationTokenSource = new CancellationTokenSource(context.RemainingTime);

            var cancellationToken = cancellationTokenSource.Token;

            if (serviceContext == null)
            {
                serviceContext = new ServiceContext();
                await serviceContext.InjectServiceAsync(context, cancellationToken);

                await serviceContext.InitializeAsync(cancellationToken);
            }

            var service = await serviceContext.GetServiceAsync <IManagerService>(cancellationToken);

            switch (invokeAction.Action)
            {
            case CumulusConstants.LambdaManagerAction.RoutePendingObjects:
                await service.RoutePendingObjects(cancellationToken);

                break;

            case CumulusConstants.LambdaManagerAction.RouteUnQueuedObjects:
                await service.RouteUnQueuedObjects(cancellationToken);

                break;

            default: throw new ArgumentException("Unknown action");
            }

            context.Logger.LogLine($"lambda manager action '{invokeAction.Action}' completed successfully");
        }
        public ElasticbeanstalkBgPipelineStack(Construct scope, string id, IStackProps props = null) : base(scope, id)
        {
            var blueEnv  = this.Node.TryGetContext("blue_env");
            var greenEnv = this.Node.TryGetContext("green_env");
            var appName  = this.Node.TryGetContext("app_name");

            var bucket = new Bucket(this, "BlueGreenBucket", new BucketProps
            {
                // The default removal policy is RETAIN, which means that cdk destroy will not attempt to delete
                // the new bucket, and it will remain in your account until manually deleted. By setting the policy to
                // DESTROY, cdk destroy will attempt to delete the bucket, but will error if the bucket is not empty.
                RemovalPolicy = RemovalPolicy.DESTROY // NOT recommended for production code
            });

            var handler = new Function(this, "BlueGreenLambda", new FunctionProps
            {
                Runtime     = Runtime.PYTHON_3_7,
                Code        = Code.FromAsset("resources"),
                Handler     = "blue_green.lambda_handler",
                Environment = new Dictionary <string, string>
                {
                    ["BUCKET"] = bucket.BucketName
                }
            });

            bucket.GrantReadWrite(handler);

            var repo = new Repository(this, "Repository", new RepositoryProps
            {
                RepositoryName = "MyRepositoryName"
            });

            var pipeline = new Pipeline(this, "MyFirstPipeline");

            var sourceStage = pipeline.AddStage(new StageOptions
            {
                StageName = "Source"
            });

            var sourceArtifact = new Artifact_("Source");

            var sourceAction = new CodeCommitSourceAction(new CodeCommitSourceActionProps
            {
                ActionName = "CodeCommit",
                Repository = repo,
                Output     = sourceArtifact
            });

            sourceStage.AddAction(sourceAction);

            var deployStage = pipeline.AddStage(new StageOptions
            {
                StageName = "Deploy"
            });

            var lambdaAction = new LambdaInvokeAction(new LambdaInvokeActionProps
            {
                ActionName     = "InvokeAction",
                Lambda         = handler,
                UserParameters = new Dictionary <string, object>
                {
                    ["blueEnvironment"]  = blueEnv,
                    ["greenEnvironment"] = greenEnv,
                    ["application"]      = appName
                },
                Inputs = new Artifact_[] { sourceArtifact }
            });

            deployStage.AddAction(lambdaAction);
        }