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); }
public async Task <ApiEmptyResult> Post(string chainId, [FromBody] DeployArg arg) { arg.MainChainId = chainId; await _sideChainService.Deploy(arg); return(ApiEmptyResult.Default); }
public ApiEmptyResult Post(string chainId, [FromBody] DeployArg arg) { Console.WriteLine(JsonSerializer.Instance.Serialize(arg)); arg.MainChainId = chainId; _sideChainService.Deploy(arg); return(ApiEmptyResult.Default); }
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); }
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); } }
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)); }
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); }
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)); }
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); }
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); }
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); }
public async Task Action(DeployArg arg) { var addDeployResult = await AddDeployment(arg); if (!addDeployResult) { throw new Exception("failed to deploy launcher"); } }
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"); } }
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); }
public void Action(DeployArg arg) { if (arg.LighthouseArg.IsCluster) { var addDeployResult = AddDeployment(arg); if (!addDeployResult) { throw new Exception("failed to deploy worker"); } } }
private string GetParallelConfigJson(DeployArg arg) { var config = new ParallelConfig { IsParallelEnable = false }; var result = JsonSerializer.Instance.Serialize(config); return(result); }
public void Action(DeployArg arg) { AddConfig(arg); AddService(arg); var addSetResult = AddStatefulSet(arg); if (!addSetResult) { throw new Exception("failed to deploy redis"); } }
public void Action(DeployArg arg) { if (arg.LighthouseArg.IsCluster) { AddService(arg); var addSetResult = AddStatefulSet(arg); if (!addSetResult) { throw new Exception("failed to deploy lighthouse"); } } }
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"); } }
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"); } } }
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); }
//[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); }
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); }
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); }
//[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); }
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); }
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); }
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 } }); }