Exemplo n.º 1
0
 static void Main(string[] args)
 {
     args      = new string[] { "-c", System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "cfg", "slave.cfg") };
     execution = (ExecutionEnvironment)ExecutionEnvironment.GetExecutionEnvironment(args);
     TestSlaveClient();
     Console.ReadLine();
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            config = new ProducerConfig
            {
                BootstrapServers = string.Join(',', KafkaConf.Instance.MQHosts) //BootstrapServers属性为以逗号隔开的多个代理地址
            };
            Task.Run(() => Produce());
            if (System.IO.File.Exists(Path))
            {
                try
                {
                    TaskCount = int.Parse(System.IO.File.ReadAllText(Path).Trim());
                }
                catch (Exception ex)
                {
                    Logger.Log.Error(true, "读TaskCount异常:", ex);
                }
            }

            executionEnvironment = ExecutionEnvironment.GetExecutionEnvironment(args);

            for (int i = 0; i < TaskCount; i++)
            {
                string key = i.ToString("0000");
                if (!executionEnvironment.TaskManager.ContainsWindow(key))
                {
                    _windowInterval = Calc.GetRandomWindowInterval();
                    _calculate      = Calc.GetAggRandomCalculate(key + "_result");
                    executionEnvironment.TaskManager.AddOrUpdateWindowTask(key, $"窗口{key}", true, _windowInterval, _delayWindowCount, new List <ICalculate>()
                    {
                        _calculate
                    });
                }
            }

            executionEnvironment.AddSource(new SourceFunctionFromKafka(string.Join(',', KafkaConf.Instance.MQHosts), KafkaConf.Instance.GroupID, KafkaConf.Instance.TopicName));
            executionEnvironment.AddSink(new SinkFunction());
            executionEnvironment.ExcuteSource();

            //while (true)
            //{
            //    var line = Console.ReadLine();
            //    if (line == "exit")
            //    {
            //        executionEnvironment.Stop();
            //        break;
            //    }
            //}
            Console.ReadKey();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                ExecutionEnvironment env = (ExecutionEnvironment)ExecutionEnvironment.GetExecutionEnvironment(args);

                bool wait = false;
                if (args.Length > 0)
                {
                    if (args[0] == "-h")
                    {
                        Helper.PrintHelper();
                    }
                    else
                    {
                        wait = true;
                        env.TaskAssembly.ExcuteMain(args);
                    }
                }
                else
                {
                    wait = true;
                    env.TaskAssembly.ExcuteMain(args);
                }

                env.ExcuteSource();

                if (wait)
                {
                    while (true)
                    {
                        string cmd = Console.ReadLine().ToLowerInvariant();
                        if (cmd == "exit" ||
                            cmd == "quit" ||
                            cmd == "stop")
                        {
                            env.Stop();
                            env = null;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Info(true, "", ex);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            rpcContexts = new List <RpcContext>();
            if (System.IO.File.Exists(Path))
            {
                try
                {
                    TaskCount = int.Parse(System.IO.File.ReadAllText(Path).Trim());
                }
                catch (Exception ex)
                {
                    Logger.Log.Error(true, "读TaskCount异常:", ex);
                }
            }

            executionEnvironment = ExecutionEnvironment.GetExecutionEnvironment(args);

            rpcClient = new RpcClient(GlobalConfig.Config.RpcIp, GlobalConfig.Config.RpcListenPort);

            ClientTaskAdd();

            executionEnvironment.AddSource(new RandomSourceFunction(rpcClient));

            executionEnvironment.AddSink(new SinkFunction());

            executionEnvironment.ExcuteSource();

            ClientTaskRemove();

            while (true)
            {
                var line = Console.ReadLine();
                if (line == "exit")
                {
                    ((ExecutionEnvironment)executionEnvironment).Stop();
                    break;
                }
            }
        }
Exemplo n.º 5
0
        public CalculateContext(string name, string desc, DateTime leftTime, DateTime rightTime, CalculateType calculateType, ICalculateInpute inpute, ICalculateOutput output, ICalculate calculateOperator)
        {
            Name              = name;
            Desc              = desc;
            LeftTime          = leftTime;
            RightTime         = rightTime;
            CalculateType     = calculateType;
            CalculateInpute   = inpute;
            CalculateOutput   = output;
            CalculateOperator = calculateOperator;

            IExecutionEnvironment env = ExecutionEnvironment.GetExecutionEnvironment(null);

            if (env == null)
            {
                Sinks = new List <SinkFunction>();
            }
            else
            {
                Sinks = new List <SinkFunction>(((ExecutionEnvironment)env).Sinks);
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            if (System.IO.File.Exists(Path))
            {
                try
                {
                    TaskCount = int.Parse(System.IO.File.ReadAllText(Path).Trim());
                }
                catch (Exception ex)
                {
                    Logger.Log.Error(true, "读TaskCount异常:", ex);
                }
            }

            executionEnvironment = ExecutionEnvironment.GetExecutionEnvironment(args);

            List <string> tasks = new List <string>();

            for (int i = 0; i < TaskCount; i++)
            {
                string key = i.ToString("0000");
                if (!executionEnvironment.TaskManager.ContainsWindow(key))
                {
                    _windowInterval = Calc.GetRandomWindowInterval();
                    _windowInterval = 5;
                    _calculates     = Calc.GetAggRandomCalculateList(new string[] { key + "_result1", key + "_result2" });

                    executionEnvironment.TaskManager.AddOrUpdateWindowTask(key, $"窗口{key}", true, _windowInterval, _delayWindowCount, _calculates);

                    string t = String.Format("{0},{1},{2}", key, _windowInterval, _calculates.Count.ToString());

                    tasks.Add(t);
                }
            }

            List <string> arr = new List <string>();

            arr.Add(Environment.NewLine);
            var cls = tasks.GroupBy(t => t.Split(",")[2]).Select(t => (new { Key = t.Key, Count = t.Count() }));

            foreach (var ele in cls)
            {
                arr.Add("计算统计:" + ele.Key + ":" + ele.Count.ToString());
            }

            var wls = tasks.GroupBy(t => t.Split(",")[1]).Select(t => (new { Key = t.Key, Count = t.Count() }));

            foreach (var ele in wls)
            {
                arr.Add("窗口统计:" + ele.Key + ":" + ele.Count.ToString());
            }

            tasks.AddRange(arr);

            string path = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "tasks", "current_tasks.txt");

            if (System.IO.File.Exists(path))
            {
                System.IO.File.Delete(path);
            }

            System.IO.File.AppendAllLines(path, tasks.ToArray());

            executionEnvironment.AddSource(new RandomSourceFunction());

            executionEnvironment.AddSink(new SinkFunction());

            executionEnvironment.ExcuteSource();

            while (true)
            {
                var line = Console.ReadLine();
                if (line == "exit")
                {
                    ((ExecutionEnvironment)executionEnvironment).Stop();
                    break;
                }
            }
        }