public void When_DSLWithTwoTransformsAndSingleParameterUsed_Expect_SingleValidTransformPipelineBuilt()
        {
            // Build a string with some of the DSL in order to test
            string simpleTransformationPipeline = "CPUMAX->" + RemoveBaseNoiseActor.TRANSFORM_NAME +
                                                  ":" + RemoveSpikeActor.TRANSFORM_NAME + "{ " + RemoveSpikeActor.SPIKE_WINDOW_LENGTH + " = 3}";

            // Create the container for all the actors
            var sys = ActorSystem.Create("vmstats-lang-tests" /*, config*/);

            // Create some transform actors so that we can test the DSL
            //var actor1 = sys.ActorOf(Props.Create(() => new RemoveBaseNoiseActor()), "Transforms-" + RemoveBaseNoiseActor.TRANSFORM_NAME);
            //var actor2 = sys.ActorOf(Props.Create(() => new RemoveSpikeActor()), "Transforms-" + RemoveSpikeActor.TRANSFORM_NAME);

            // Pick one of the defined above pipelines to use in the test
            string cmd = simpleTransformationPipeline;

            // Create a collection to hold all of the transform_pipelines found by the listener when we
            // decode the DSL.
            Queue <Messages.BuildTransformSeries> result = new Queue <Messages.BuildTransformSeries>();

            // translate the DSL in the test text and execute the tranform pipeline it represents
            var tp = new TransformationLanguage(sys.Log);

            tp.DecodeAndExecute(cmd, result);

            // Generate the expected results
            var expectedResult = generateTestData_When_DSLWithTwoTransformsAndSingleParameterUsed_Expect_SingleValidTransformPipelineBuilt();

            // Check expected results match real results
            Assert.AreNotEqual(expectedResult.Peek().GroupID, result.Peek().GroupID,
                               "GroupID, Results and Expected values are equal.\nExpected values = {0}\nActual result values = {1}. ",
                               new object[] { JsonConvert.SerializeObject(expectedResult.Peek().GroupID),
                                              JsonConvert.SerializeObject(result.Peek().GroupID) });
            Assert.AreEqual(expectedResult.Peek().MetricName, result.Peek().MetricName,
                            "MetricName, Results and Expected values are different.\nExpected values = {0}\nActual result values = {1}. ",
                            new object[] { JsonConvert.SerializeObject(expectedResult), JsonConvert.SerializeObject(result) });
            var e = JsonConvert.SerializeObject(expectedResult.Peek().Transforms);
            var a = JsonConvert.SerializeObject(result.Peek().Transforms);

            Assert.AreEqual(e, a,
                            "Transforms, Results and Expected values are different.\nExpected values = {0}\nActual result values = {1}. ",
                            new object[] { e, a }
                            );
        }
        public void When_DSLIsInvlaid_Expect_Exception()
        {
            // Build a string containing errors in the DSL
            string errorTransformationPipeline = "CPUMAX && ^^ -> RBN : 'JON' {param-1=value$4}";

            // Pick one of the defined above pipelines to use in the test
            string cmd = errorTransformationPipeline;

            // Create the container for all the actors
            var sys = ActorSystem.Create("vmstats-lang-tests" /*, config*/);

            // Create a collection to hold all of the transform_pipelines found by the listener when we
            // decode the DSL.
            Queue <Messages.BuildTransformSeries> result = new Queue <Messages.BuildTransformSeries>();

            // translate the DSL in the test text and execute the tranform pipeline it represents
            var tp = new TransformationLanguage(sys.Log);
            VmstatsLangException ex = Assert.Throws <VmstatsLangException>(delegate { tp.DecodeAndExecute(cmd, result); },
                                                                           "Unexpected exceptiion thrown.");
        }
Example #3
0
        public ActionResult <CreatedAtRouteResult> Post([FromBody] Messages.ProcessCommand request)
        {
            var jsonRequest = JsonConvert.SerializeObject(request);

            _log.LogDebug($"Received request Post. Request is: {jsonRequest}");
            try
            {
                // Validate the dsl
                Queue <Messages.BuildTransformSeries> q = new Queue <Messages.BuildTransformSeries>();
                TransformationLanguage tl = new TransformationLanguage(startup._log);
                tl.DecodeAndExecute(request.Dsl, q);

                // Start the processing of the pipeline by telling the MetricAccumulatorDispatcherActor to route the request
                var actor = startup.vmstatsActorSystem.ActorSelection("/user/" + MetricAccumulatorDispatcherActor.ACTOR_NAME);
                actor.Tell(new Messages.StartProcessingTransformPipeline(request, q));
                startup.vmstatsActorSystem.Log.Debug("Starting the processing of the transforms specified in the dsl");
                Console.WriteLine("Starting the processing of the transforms specified in the dsl");
            }
            catch (VmstatsLangException e)
            {
                startup.vmstatsActorSystem.Log.Error($"Error processing DSL in request. Message is: {e.Message}");
                var errorMsg = $"Error processing DSL in request. Message: {e.Message}";
                _log.LogError(errorMsg);
                Console.WriteLine(errorMsg);
                return(BadRequest(errorMsg));
            } catch (Exception e)
            {
                startup.vmstatsActorSystem.Log.Error($"Error processing DSL in request. Message is: {e.Message}");
                var errorMsg = $"Error processing DSL in request. Message: {e.Message}";
                _log.LogError(errorMsg);
                Console.WriteLine(errorMsg);
                return(BadRequest(errorMsg));
            }

            return(Ok());
        }