Beispiel #1
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var buffer = message as IByteBuffer;

            if (buffer != null)
            {
                Action <string> sender = (s) =>
                {
                    IByteBuffer byteBuffer = Unpooled.Buffer(256);
                    byte[]      byteArray  = Encoding.UTF8.GetBytes(s);
                    byteBuffer.WriteBytes(byteArray);
                    context.WriteAndFlushAsync(byteBuffer);
                };

                string m = buffer.ToString(Encoding.UTF8);
                Console.WriteLine(m);

                BuildRunRequest request = Newtonsoft.Json.JsonConvert.DeserializeObject <BuildRunRequest>(m);

                BuildRunner buildRunner = new BuildRunner(request, sender);

                //https://github.com/Azure/DotNetty/issues/265
                Task.Run(() =>
                {
                    buildRunner.StartBuild();
                });
            }
        }
Beispiel #2
0
        public BuildRunner(BuildRunRequest request, Action <string> send)
        {
            _send         = send;
            this._request = request;

            _queueServer   = ConfigurationManager.AppSettings["queueServer"];
            _queueVhost    = ConfigurationManager.AppSettings["queueVhost"];
            _queueUsername = ConfigurationManager.AppSettings["queueUsername"];
            _queuePassword = ConfigurationManager.AppSettings["queuePassword"];
        }
Beispiel #3
0
        public SocketClientHandler(BuildRunRequest request)
        {
            string processInfo = $"Socket CLient running PID: {Process.GetCurrentProcess().Id}";

            OutputMessage(processInfo);

            string mess = JsonConvert.SerializeObject(request);

            this.byteBuffer = Unpooled.Buffer(256);
            byte[] byteArray = Encoding.UTF8.GetBytes(mess);
            this.byteBuffer.WriteBytes(byteArray);
        }
Beispiel #4
0
        static async Task RunClientAsync(BuildRunRequest request)
        {
            var group = new MultithreadEventLoopGroup();

            string targetHost = null;

            try
            {
                SocketClientHandler.OutputMessage("Pre bootstrap");
                var bootstrap = new Bootstrap();
                bootstrap
                .Group(group)
                .Channel <TcpSocketChannel>()
                .Option(ChannelOption.TcpNodelay, true)
                .Handler(new ActionChannelInitializer <ISocketChannel>(channel =>
                {
                    SocketClientHandler.OutputMessage("In handler");
                    IChannelPipeline pipeline = channel.Pipeline;

                    pipeline.AddLast(new LoggingHandler());
                    pipeline.AddLast("framing-enc", new LengthFieldPrepender(2));
                    pipeline.AddLast("framing-dec", new LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));

                    pipeline.AddLast("echo", new SocketClientHandler(request));

                    SocketClientHandler.OutputMessage("Handlers added");
                }));

                SocketClientHandler.OutputMessage("Pre channel connect");
                IChannel clientChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(_host), _port));

                SocketClientHandler.OutputMessage("Post channel connect");

                string s = Console.ReadLine();
                while (string.IsNullOrEmpty(s))
                {
                    Console.ReadLine();
                }
                SocketClientHandler.OutputMessage("Post inner readline");

                await clientChannel.CloseAsync();
            }
            finally
            {
                await group.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
            }
        }
Beispiel #5
0
        static async Task Main(string[] args)
        {
            XmlConfigurator.Configure();

            if (args.Length == 0)
            {
                throw new ArgumentException("Usage: reactiveclient host build");
            }

            var host = args[0];

            var port = 1055;

            var build            = args[1];
            var image            = args[2];
            var yamlFileLocation = args[3];

            string yaml = File.ReadAllText(yamlFileLocation);

            BuildRunRequest request = new BuildRunRequest
            {
                Build = build,
                Yaml  = yaml
            };

            try
            {
                SocketClientHandler.OutputMessage("Starting wait");
                await RunClientAsync(request).ConfigureAwait(true);

                for (int i = 0; i < 1000; i++)
                {
                    Thread.Sleep(1000);
                }
            }
            catch (Exception e)
            {
                SocketClientHandler.OutputException(e);
                SocketClientHandler.ShutDown(1);
            }

            SocketClientHandler.OutputMessage("Before Readline");
            Console.ReadLine();
            SocketClientHandler.OutputMessage("Exiting");
        }
Beispiel #6
0
        public async Task KickOffBuild(BuildRunRequest request, ITestRunObserver observer = null)
        {
            using (var processor = new BuildProcessor(_host, _vHost, _username, _password))
            {
                ToConsoleObserver consoleObserver = new ToConsoleObserver();
                ToLogObserver     logObserver     = new ToLogObserver("BuildManager");

                if (observer != null)
                {
                    processor.SubscribeTestResult(observer);
                    processor.SubscribeStatusMessage(observer);
                }

                processor.SubscribeTestResult(consoleObserver);
                processor.SubscribeStatusMessage(consoleObserver);

                processor.SubscribeTestResult(logObserver);
                processor.SubscribeStatusMessage(logObserver);

                await processor.StartBuild(request);
            }
        }
Beispiel #7
0
        private RunBuild CreateBuildInstruction(BuildRunRequest request)
        {
            ComposeFileParser composeFileParser = new ComposeFileParser(request.Yaml);

            RunBuild runBuild = new RunBuild
            {
                Yaml    = request.Yaml,
                Build   = request.Build,
                Image   = composeFileParser.GetTesterImageName(),
                Command = composeFileParser.GetTesterLocation(),
                EnvironmentVariables = new Dictionary <string, string>
                {
                    { "TESTER_SERVER", _host },
                    { "TESTER_VHOST", _vHost },
                    { "TESTER_USERNAME", _username },
                    { "TESTER_PASSWORD", _password },
                    { "TESTER_REQUEST_QUEUE", $"{request.Build}_request" },
                    { "TESTER_RESPONSE_QUEUE", $"{request.Build}_response" }
                }
            };

            return(runBuild);
        }
Beispiel #8
0
        public async Task StartBuild(BuildRunRequest request)
        {
            try
            {
                ReportStatus($"[{request.Build}] Staring");

                RunBuild buildInstruction = CreateBuildInstruction(request);

                string testOutput;

                using (DockerWrapper docker = new DockerWrapper())
                {
                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                    //cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(60));

                    Dictionary <string, string> environmentVariable = new Dictionary <string, string>
                    {
                        { "TESTER_LISTTESTS", "true" }
                    };

                    testOutput = await docker.Run(buildInstruction.Image, environmentVariables : environmentVariable,
                                                  command : buildInstruction.Command, cancellationToken : cancellationTokenSource.Token);
                }

                List <RunTest> tests = new List <RunTest>();

                string[] testNames = testOutput.Split('\n');

                foreach (string testName in testNames)
                {
                    if (!string.IsNullOrEmpty(testName))
                    {
                        RunTest item = new RunTest
                        {
                            Build    = request.Build,
                            FullName = testName.Trim()
                        };

                        tests.Add(item);
                    }
                }

                AddTestsToDictionary(_expectedTests, tests);

                // Configure receivers
                statusMessageReceiver = ConfigureReceiver(QueueNames.Status(request.Build));
                testResultReceiver    = ConfigureReceiver(QueueNames.TestResponse(request.Build));

                // Add all the tests to the queue
                ReportStatus($"[{request.Build}] Sending Test Instructions ...");
                testInstructionSender = ConfigureSender(QueueNames.TestRequest(request.Build));
                SendTestInstructions(testInstructionSender, tests);
                ReportStatus($"[{request.Build}] Test Instructions sent.");

                // Add the build instruction to the queue
                ReportStatus($"[{request.Build}] Sending Build Instruction ...");
                buildInstructionSender = ConfigureSender(QueueNames.Build());
                buildInstructionSender.Send(buildInstruction);
                ReportStatus($"[{request.Build}] Build Instruction sent.");

                // Subscribe to the test result queue until all the tests have been completed (notifying subscribers)
                testResultReceiver.Receive <TestResult>(TestResultReceived);
                statusMessageReceiver.Receive <StatusMessage>(StatusMessageReceived);

                // Wait for tests to complete
                await TestsStillRunning(_cancellationTokenSource.Token);

                ReportStatus($"DONE");

                // Notify cubscribers that the run is complete
                _testResultMonitor.notifyComplete();
                _statusMessageMonitor.notifyComplete();
            } catch (Exception ex)
            {
                ReportError(ex.Message);
            }
        }