예제 #1
0
        private void AddService(DeployArg arg)
        {
            var body = new V1Service
            {
                Metadata = new V1ObjectMeta
                {
                    Name   = GlobalSetting.LighthouseServiceName,
                    Labels = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.LighthouseServiceName }
                    }
                },
                Spec = new V1ServiceSpec
                {
                    Ports = new List <V1ServicePort>
                    {
                        new V1ServicePort(Port)
                    },
                    Selector = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.LighthouseName }
                    },
                    ClusterIP = "None"
                }
            };

            K8SRequestHelper.GetClient().CreateNamespacedService(body, arg.SideChainId);
        }
예제 #2
0
        public async Task <ApiEmptyResult> Post(string chainId, [FromBody] DeployArg arg)
        {
            arg.MainChainId = chainId;
            await _sideChainService.Deploy(arg);

            return(ApiEmptyResult.Default);
        }
예제 #3
0
 public ApiEmptyResult Post(string chainId, [FromBody] DeployArg arg)
 {
     Console.WriteLine(JsonSerializer.Instance.Serialize(arg));
     arg.MainChainId = chainId;
     _sideChainService.Deploy(arg);
     return(ApiEmptyResult.Default);
 }
예제 #4
0
        private string GetActorConfigJson(DeployArg arg)
        {
            var config = new ActorConfig
            {
                IsCluster        = arg.LighthouseArg.IsCluster,
                HostName         = "127.0.0.1",
                Port             = 0,
                ActorCount       = arg.WorkArg.ActorCount,
                ConcurrencyLevel = arg.WorkArg.ConcurrencyLevel,
                Seeds            = new List <SeedNode> {
                    new SeedNode {
                        HostName = "set-lighthouse-0.service-lighthouse", Port = 4053
                    }
                },
                SingleHoconFile     = "single.hocon",
                MasterHoconFile     = "master.hocon",
                WorkerHoconFile     = "worker.hocon",
                LighthouseHoconFile = "lighthouse.hocon",
                MonitorHoconFile    = "monitor.hocon"
            };

            var result = JsonSerializer.Instance.Serialize(config);

            return(result);
        }
예제 #5
0
        public async Task DeployMainChain(DeployArg arg)
        {
            if (string.IsNullOrWhiteSpace(arg.MainChainId))
            {
                arg.MainChainId = GenerateChainId();
            }

            arg.IsDeployMainChain = true;
            arg.SideChainId       = arg.MainChainId;

            var commands = new List <IDeployCommand>
            {
                new K8SAddNamespaceCommand(),
                new K8SAddRedisCommand(),
                new K8SAddLauncherServiceCommand(),
                new K8SAddAccountKeyCommand(),
                new K8SAddChainInfoCommand(),
                new K8SGrpcKeyCommand(),
                new K8SAddLighthouseCommand(),
                new K8SAddWorkerCommand(),
                new K8SAddLauncherCommand(),
                new K8SAddMonitorCommand()
            };

            foreach (var command in commands)
            {
                await command.Action(arg);
            }
        }
예제 #6
0
        public async Task DeployMainChain(DeployArg arg)
        {
            if (string.IsNullOrWhiteSpace(arg.MainChainId))
            {
                arg.MainChainId = GenerateChainId();
            }
            arg.IsDeployMainChain = true;
            arg.SideChainId       = arg.MainChainId;

            var commands = new List <IDeployCommand>
            {
                new K8SAddNamespaceCommand(),
                new K8SAddRedisCommand(),
                new K8SAddLauncherServiceCommand(),
                new K8SAddAccountKeyCommand(),
                new K8SAddConfigCommand(),
                new K8SAddChainInfoCommand(),
                new K8SGrpcKeyCommand(),
                new K8SAddLighthouseCommand(),
                new K8SAddWorkerCommand(),
                new K8SAddLauncherCommand(),
                new K8SAddMonitorCommand(),
                new SaveApiKeyCommand(),
                new AddMonitorDBCommand()
            };

            commands.ForEach(c => c.Action(arg));
        }
예제 #7
0
        private string GetMinersConfigJson(DeployArg arg)
        {
            var config = new MinersConfig();

            //Todo
            if (!arg.Miners.Contains(arg.ChainAccount))
            {
                arg.Miners.Add(arg.ChainAccount);
            }

            var i = 1;

            config.Producers = new Dictionary <string, Dictionary <string, string> >();
            foreach (var miner in arg.Miners)
            {
                config.Producers.Add(i.ToString(), new Dictionary <string, string> {
                    { "address", miner }
                });
                i++;
            }

            var result = JsonSerializer.Instance.Serialize(config);

            return(result);
        }
예제 #8
0
        public void Deploy(DeployArg arg)
        {
            if (string.IsNullOrWhiteSpace(arg.MainChainId))
            {
                throw new ArgumentException("main chain id is empty!");
            }
            if (string.IsNullOrWhiteSpace(arg.SideChainId))
            {
                arg.SideChainId = GenerateChainId();
            }
            arg.IsDeployMainChain = false;

            var commands = new List <IDeployCommand>
            {
                new K8SAddNamespaceCommand(),
                new K8SAddRedisCommand(),
                new K8SAddLauncherServiceCommand(),
                new K8SAddAccountKeyCommand(),
                new K8SAddConfigCommand(),
                new K8SAddChainInfoCommand(),
                new K8SGrpcKeyCommand(),
                new K8SAddLighthouseCommand(),
                new K8SAddWorkerCommand(),
                new K8SAddLauncherCommand(),
                new K8SAddMonitorCommand(),
                new SaveApiKeyCommand(),
                new AddMonitorDBCommand()
            };

            commands.ForEach(c => c.Action(arg));
        }
예제 #9
0
        private async Task AddService(DeployArg arg)
        {
            var body = new V1Service
            {
                Metadata = new V1ObjectMeta
                {
                    Name   = GlobalSetting.RedisServiceName,
                    Labels = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.RedisServiceName }
                    }
                },
                Spec = new V1ServiceSpec
                {
                    Ports = new List <V1ServicePort>
                    {
                        new V1ServicePort(arg.DBArg.Port)
                    },
                    Selector = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.RedisName }
                    },
                    ClusterIP = "None"
                }
            };

            await K8SRequestHelper.GetClient().CreateNamespacedServiceAsync(body, arg.SideChainId);
        }
예제 #10
0
        private async Task AddService(DeployArg arg)
        {
            var body = new V1Service
            {
                Metadata = new V1ObjectMeta
                {
                    Name   = GlobalSetting.MonitorServiceName,
                    Labels = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.MonitorServiceName }
                    }
                },
                Spec = new V1ServiceSpec
                {
                    Type  = "LoadBalancer",
                    Ports = new List <V1ServicePort>
                    {
                        new V1ServicePort(GlobalSetting.MonitorPort, "monitor-port", null, "TCP", GlobalSetting.MonitorPort)
                    },
                    Selector = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.MonitorName }
                    }
                }
            };

            await K8SRequestHelper.GetClient().CreateNamespacedServiceAsync(body, arg.SideChainId);
        }
예제 #11
0
        public void Action(DeployArg arg)
        {
            // Todo temp solution
            ApiKeyConfig.Instance.ChainKeys.Add(arg.SideChainId, arg.ApiKey);
            var configJson = JsonSerializer.Instance.Serialize(ApiKeyConfig.Instance);

            File.WriteAllText(Path.Combine(ApplicationHelpers.GetDefaultConfigPath(), "config", "api-key.json"), configJson);
        }
예제 #12
0
        public async Task Action(DeployArg arg)
        {
            var addDeployResult = await AddDeployment(arg);

            if (!addDeployResult)
            {
                throw new Exception("failed to deploy launcher");
            }
        }
예제 #13
0
        public void Action(DeployArg arg)
        {
            var addDeployResult = AddDeployment(arg);

            if (!addDeployResult)
            {
                throw new Exception("failed to deploy launcher");
            }
        }
        public async Task Action(DeployArg arg)
        {
            var result = await AddService(arg);

            if (!result)
            {
                throw new Exception("failed to deploy launcher service");
            }
        }
예제 #15
0
        public void Action(DeployArg arg)
        {
            var result = AddService(arg);

            if (!result)
            {
                throw new Exception("failed to deploy launcher service");
            }
        }
        private async Task <bool> AddService(DeployArg arg)
        {
            var body = new V1Service
            {
                Metadata = new V1ObjectMeta
                {
                    Name   = GlobalSetting.LauncherServiceName,
                    Labels = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.LauncherServiceName }
                    }
                },
                Spec = new V1ServiceSpec
                {
                    Type  = "LoadBalancer",
                    Ports = new List <V1ServicePort>
                    {
                        new V1ServicePort(GlobalSetting.NodePort, "node-port", null, "TCP", GlobalSetting.NodePort),
                        new V1ServicePort(GlobalSetting.RpcPort, "rpc-port", null, "TCP", GlobalSetting.RpcPort),
                        new V1ServicePort(GlobalSetting.GrpcPort, "grpc-port", null, "TCP", GlobalSetting.GrpcPort)
                    },
                    Selector = new Dictionary <string, string>
                    {
                        { "name", GlobalSetting.LauncherName }
                    }
                }
            };

            var result = await K8SRequestHelper.GetClient().CreateNamespacedServiceAsync(body, arg.SideChainId);

            var service = await K8SRequestHelper.GetClient().ReadNamespacedServiceAsync(result.Metadata.Name, arg.SideChainId);

            var retryGetCount = 0;

            while (true)
            {
                arg.LauncherArg.ClusterIp = service.Spec.ClusterIP;
                if (!string.IsNullOrWhiteSpace(arg.LauncherArg.ClusterIp))
                {
                    break;
                }

                if (retryGetCount > GlobalSetting.DeployRetryTime)
                {
                    return(false);
                }

                retryGetCount++;
                Thread.Sleep(3000);
                service = await K8SRequestHelper.GetClient().ReadNamespacedServiceAsync(result.Metadata.Name, arg.SideChainId);
            }

            return(true);
        }
예제 #17
0
 public void Action(DeployArg arg)
 {
     if (arg.LighthouseArg.IsCluster)
     {
         var addDeployResult = AddDeployment(arg);
         if (!addDeployResult)
         {
             throw new Exception("failed to deploy worker");
         }
     }
 }
예제 #18
0
        private string GetParallelConfigJson(DeployArg arg)
        {
            var config = new ParallelConfig
            {
                IsParallelEnable = false
            };

            var result = JsonSerializer.Instance.Serialize(config);

            return(result);
        }
예제 #19
0
        public void Action(DeployArg arg)
        {
            AddConfig(arg);
            AddService(arg);
            var addSetResult = AddStatefulSet(arg);

            if (!addSetResult)
            {
                throw new Exception("failed to deploy redis");
            }
        }
예제 #20
0
 public void Action(DeployArg arg)
 {
     if (arg.LighthouseArg.IsCluster)
     {
         AddService(arg);
         var addSetResult = AddStatefulSet(arg);
         if (!addSetResult)
         {
             throw new Exception("failed to deploy lighthouse");
         }
     }
 }
예제 #21
0
        public async Task Action(DeployArg arg)
        {
            await AddConfig(arg);
            await AddService(arg);

            var addSetResult = await AddStatefulSet(arg);

            if (!addSetResult)
            {
                throw new Exception("failed to deploy redis");
            }
        }
예제 #22
0
        public async Task Action(DeployArg arg)
        {
            if (arg.LighthouseArg.IsCluster)
            {
                await AddService(arg);

                var addDeployResult = await AddDeployment(arg);

                if (!addDeployResult)
                {
                    throw new Exception("failed to deploy monitor");
                }
            }
        }
예제 #23
0
        private string GetApiKeyConfig(DeployArg arg)
        {
            arg.ApiKey = Guid.NewGuid().ToString("N");
            var config = new ApiKeyConfig()
            {
                ChainKeys = new Dictionary <string, string> {
                    { arg.SideChainId, arg.ApiKey }
                }
            };

            var result = JsonSerializer.Instance.Serialize(config);

            return(result);
        }
예제 #24
0
        //[Fact]
        public async Task DeployTestChainTest()
        {
            var arg = new DeployArg();

            arg.AccountPassword         = "******";
            arg.DBArg                   = new DeployDBArg();
            arg.LighthouseArg           = new DeployLighthouseArg();
            arg.LighthouseArg.IsCluster = false;
            arg.WorkArg                 = new DeployWorkArg();
            arg.LauncherArg             = new DeployLauncherArg();
            arg.LauncherArg.IsConsensusInfoGenerator = true;

            await _chainService.DeployMainChain(arg);
        }
예제 #25
0
        private string GetNetworkConfigJson(DeployArg arg)
        {
            var config = new NetworkConfig();

            config.Bootnodes = new List <string>();

            if (arg.LauncherArg.Bootnodes != null && arg.LauncherArg.Bootnodes.Any())
            {
                config.Bootnodes = arg.LauncherArg.Bootnodes;
            }

            var result = JsonSerializer.Instance.Serialize(config);

            return(result);
        }
예제 #26
0
        private string GetGrpcConfigJson(DeployArg arg)
        {
            var config = new GrpcLocalConfig
            {
                LocalServerIP                = "0.0.0.0",//arg.LauncherArg.ClusterIp,
                LocalSideChainServerPort     = GlobalSetting.GrpcPort,
                ClientToParentChain          = true,
                ClientToSideChain            = true,
                WaitingIntervalInMillisecond = 10,
                SideChainServer              = true
            };

            var result = JsonSerializer.Instance.Serialize(config);

            return(result);
        }
예제 #27
0
        //[Fact]
        public void DeployTestChain()
        {
            var arg = new DeployArg();

            arg.AccountPassword         = "******";
            arg.DBArg                   = new DeployDBArg();
            arg.LighthouseArg           = new DeployLighthouseArg();
            arg.LighthouseArg.IsCluster = false;
            arg.WorkArg                 = new DeployWorkArg();
            arg.LauncherArg             = new DeployLauncherArg();
            arg.LauncherArg.IsConsensusInfoGenerator = true;

            var service = new ChainService();

            service.DeployMainChain(arg);
        }
예제 #28
0
        public void Action(DeployArg arg)
        {
            var body = new V1ConfigMap
            {
                ApiVersion = V1ConfigMap.KubeApiVersion,
                Kind       = V1ConfigMap.KubeKind,
                Metadata   = new V1ObjectMeta
                {
                    Name = GlobalSetting.KeysConfigName,
                    NamespaceProperty = arg.SideChainId
                },
                Data = GetAndCreateAccountKey(arg)
            };

            K8SRequestHelper.GetClient().CreateNamespacedConfigMap(body, arg.SideChainId);
        }
예제 #29
0
        private string GetDatabaseConfigJson(DeployArg arg)
        {
            var config = new DatabaseConfig
            {
                Type  = DatabaseType.Redis,
                Hosts = new Dictionary <string, DatabaseHost>
                {
                    { "Default", new DatabaseHost {
                          Host = "set-redis-0.service-redis", Port = 7001, Number = 0
                      } }
                }
            };

            var result = JsonSerializer.Instance.Serialize(config);

            return(result);
        }
예제 #30
0
        private Dictionary <string, string> GetAndCreateAccountKey(DeployArg arg)
        {
            if (string.IsNullOrWhiteSpace(arg.ChainAccount))
            {
                var keyStore = new AElfKeyStore(ApplicationHelpers.ConfigPath);
                var key      = keyStore.Create(arg.AccountPassword);
                arg.ChainAccount = key.GetAddressHex();
            }

            var fileName   = arg.ChainAccount + ".ak";
            var filePath   = Path.Combine(ApplicationHelpers.ConfigPath, "keys", fileName);
            var keyContent = File.ReadAllText(filePath);

            return(new Dictionary <string, string> {
                { fileName, keyContent }
            });
        }