From e2c7c69c9d0b2a1c200374ce47a7a1cc5fbb317e Mon Sep 17 00:00:00 2001 From: riyasng12 Date: Tue, 2 Jan 2024 16:11:16 +0530 Subject: [PATCH 1/2] fix: fixed output file names to include uuid --- cli/cmd/bridge/btp/cmd.go | 16 ++- cli/cmd/bridge/btp/run.go | 17 ++- cli/cmd/bridge/ibc/cmd.go | 16 ++- cli/cmd/bridge/ibc/run.go | 16 --- cli/cmd/bridge/utils/types.go | 14 ++- cli/cmd/chains/archway/cmd.go | 16 ++- cli/cmd/chains/eth/cmd.go | 17 ++- cli/cmd/chains/hardhat/cmd.go | 17 ++- cli/cmd/chains/icon/cmd.go | 17 ++- cli/cmd/chains/kusama/cmd.go | 19 +++- cli/cmd/chains/kusama/run.go | 186 +++++++++++++++++++++++++++++---- cli/cmd/chains/neutron/cmd.go | 17 ++- cli/cmd/chains/polkadot/cmd.go | 16 ++- cli/cmd/utility/clean.go | 17 ++- cli/common/constants.go | 7 +- cli/common/types.go | 11 ++ 16 files changed, 358 insertions(+), 61 deletions(-) diff --git a/cli/cmd/bridge/btp/cmd.go b/cli/cmd/bridge/btp/cmd.go index 8a522142..55316c33 100644 --- a/cli/cmd/bridge/btp/cmd.go +++ b/cli/cmd/bridge/btp/cmd.go @@ -55,12 +55,24 @@ func btpRelay(cmd *cobra.Command, args []string) { if err != nil { cliContext.Fatal(err) } + + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } - serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName) + serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName, ShortUuid) err = cliContext.FileHandler().WriteFile(serviceFileName, []byte(result)) if err != nil { cliContext.Fatal(err) } - cliContext.StopSpinnerIfNotVerbose(fmt.Sprintf("BTP Setup Completed between %s and %s. Please find service details in current working directory(%s)", chainA, chainB, serviceFileName), common.DiveLogs) + cliContext.StopSpinnerIfNotVerbose(fmt.Sprintf("BTP Setup Completed between %s and %s. Please find service details in current working directory(%s)\n", chainA, chainB, serviceFileName), common.DiveLogs) } diff --git a/cli/cmd/bridge/btp/run.go b/cli/cmd/bridge/btp/run.go index 94685761..0ce20257 100644 --- a/cli/cmd/bridge/btp/run.go +++ b/cli/cmd/bridge/btp/run.go @@ -138,8 +138,21 @@ func runBtpSetupWhenChainsAreNotIcon(cli *common.Cli, enclaveContext *enclaves.E func runBtpSetupWhenSingleChainRunning(cli *common.Cli, enclaveContext *enclaves.EnclaveContext, chains *utils.Chains, bridge bool) (string, error) { var chainAServiceResponse, chainBServiceResponse, response string var services = common.Services{} - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) - err := cli.FileHandler().ReadJson(serviceFileName, &services) + + enclaves, err := cli.Context().GetEnclaves() + if err != nil { + cli.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + + err = cli.FileHandler().ReadJson(serviceFileName, &services) if err != nil { return "", common.WrapMessageToError(err, fmt.Sprintf("BTP Setup Failed For ChainA %s and ChainB %s", chains.ChainA, chains.ChainB)) diff --git a/cli/cmd/bridge/ibc/cmd.go b/cli/cmd/bridge/ibc/cmd.go index 93085315..cf141a79 100644 --- a/cli/cmd/bridge/ibc/cmd.go +++ b/cli/cmd/bridge/ibc/cmd.go @@ -43,12 +43,24 @@ func ibcRelay(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName) + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName, ShortUuid) err = cliContext.FileHandler().WriteFile(serviceFileName, []byte(result)) if err != nil { cliContext.Fatal(err) } - cliContext.StopSpinnerIfNotVerbose(fmt.Sprintf("IBC Setup Completed between %s and %s. Please find service details in current working directory(%s)", chainA, chainB, serviceFileName), common.DiveLogs) + cliContext.StopSpinnerIfNotVerbose(fmt.Sprintf("IBC Setup Completed between %s and %s. Please find service details in current working directory(%s)\n", chainA, chainB, serviceFileName), common.DiveLogs) } diff --git a/cli/cmd/bridge/ibc/run.go b/cli/cmd/bridge/ibc/run.go index 397f9c20..19610f13 100644 --- a/cli/cmd/bridge/ibc/run.go +++ b/cli/cmd/bridge/ibc/run.go @@ -6,26 +6,10 @@ import ( chainutil "github.com/hugobyte/dive-core/cli/cmd/chains/utils" "github.com/hugobyte/dive-core/cli/cmd/bridge/utils" - "github.com/hugobyte/dive-core/cli/cmd/chains/archway" - "github.com/hugobyte/dive-core/cli/cmd/chains/icon" - "github.com/hugobyte/dive-core/cli/cmd/chains/neutron" "github.com/hugobyte/dive-core/cli/common" "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" ) -var runChain = map[string]func(cli *common.Cli) (*common.DiveServiceResponse, error){ - "icon": func(cli *common.Cli) (*common.DiveServiceResponse, error) { - return icon.RunIconNode(cli) - }, - "archway": func(cli *common.Cli) (*common.DiveServiceResponse, error) { - return archway.RunArchway(cli) - - }, - "neutron": func(cli *common.Cli) (*common.DiveServiceResponse, error) { - return neutron.RunNeutron(cli) - }, -} - func RunIbcRelay(cli *common.Cli) (string, error) { var starlarkExecutionResponse string chains := utils.InitChains(chainA, chainB, serviceA, serviceB, false) diff --git a/cli/cmd/bridge/utils/types.go b/cli/cmd/bridge/utils/types.go index 42d9a4cc..4f70dd3d 100644 --- a/cli/cmd/bridge/utils/types.go +++ b/cli/cmd/bridge/utils/types.go @@ -58,10 +58,20 @@ func (chains *Chains) GetIbcRelayParams(src_service_config string, dst_service_c func (chains *Chains) GetServicesResponse(cli *common.Cli) (string, string, error) { var serviceConfig = common.Services{} + enclaves, err := cli.Context().GetEnclaves() + if err != nil { + cli.Fatal(err) + } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) - err := cli.FileHandler().ReadJson(serviceFileName, &serviceConfig) + err = cli.FileHandler().ReadJson(serviceFileName, &serviceConfig) if err != nil { return "", "", err diff --git a/cli/cmd/chains/archway/cmd.go b/cli/cmd/chains/archway/cmd.go index b8a4491a..6d5934d9 100644 --- a/cli/cmd/chains/archway/cmd.go +++ b/cli/cmd/chains/archway/cmd.go @@ -42,7 +42,19 @@ func archway(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext, serviceFileName) if err != nil { @@ -50,7 +62,7 @@ func archway(cmd *cobra.Command, args []string) { } - stopMessage := fmt.Sprintf("Archway Node Started. Please find service details in current working directory(%s)", serviceFileName) + stopMessage := fmt.Sprintf("Archway Node Started. Please find service details in current working directory(%s)\n", serviceFileName) cliContext.StopSpinnerIfNotVerbose(stopMessage, common.DiveLogs) } diff --git a/cli/cmd/chains/eth/cmd.go b/cli/cmd/chains/eth/cmd.go index a5e65d93..8b8a1b15 100644 --- a/cli/cmd/chains/eth/cmd.go +++ b/cli/cmd/chains/eth/cmd.go @@ -37,14 +37,27 @@ func eth(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) err = common.WriteServiceResponseData(responseData.ServiceName, *responseData, cliContext, serviceFileName) if err != nil { cliContext.Fatal(err) } - stopMessage := fmt.Sprintf("ETH Node Started. Please find service details in current working directory(%s)", serviceFileName) + stopMessage := fmt.Sprintf("ETH Node Started. Please find service details in current working directory(%s)\n", serviceFileName) cliContext.Spinner().StopWithMessage(stopMessage) } diff --git a/cli/cmd/chains/hardhat/cmd.go b/cli/cmd/chains/hardhat/cmd.go index 36b8d4c1..4e9e0ae3 100644 --- a/cli/cmd/chains/hardhat/cmd.go +++ b/cli/cmd/chains/hardhat/cmd.go @@ -36,14 +36,27 @@ func hardhat(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) err = common.WriteServiceResponseData(responseData.ServiceName, *responseData, cliContext, serviceFileName) if err != nil { cliContext.Fatal(err) } - stopMessage := fmt.Sprintf("Hardhat Node Started. Please find service details in current working directory(%s)", serviceFileName) + stopMessage := fmt.Sprintf("Hardhat Node Started. Please find service details in current working directory(%s)\n", serviceFileName) cliContext.Spinner().StopWithMessage(stopMessage) } diff --git a/cli/cmd/chains/icon/cmd.go b/cli/cmd/chains/icon/cmd.go index 7186fe58..0588bdd1 100644 --- a/cli/cmd/chains/icon/cmd.go +++ b/cli/cmd/chains/icon/cmd.go @@ -83,7 +83,20 @@ func icon(cmd *cobra.Command, args []string) { } } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext, serviceFileName) if err != nil { @@ -92,7 +105,7 @@ func icon(cmd *cobra.Command, args []string) { } - stopMessage := fmt.Sprintf("Icon Node Started. Please find service details in current working directory(%s)", serviceFileName) + stopMessage := fmt.Sprintf("Icon Node Started. Please find service details in current working directory(%s)\n", serviceFileName) cliContext.Spinner().StopWithMessage(stopMessage) } diff --git a/cli/cmd/chains/kusama/cmd.go b/cli/cmd/chains/kusama/cmd.go index a4a28f09..c2030057 100644 --- a/cli/cmd/chains/kusama/cmd.go +++ b/cli/cmd/chains/kusama/cmd.go @@ -24,6 +24,9 @@ const ( runUploadFiles = "upload_files" runKusamaParaLocalFunctionName = "start_nodes" runKusamaParaTestMainFunctionName = "run_testnet_mainnet" + runKusamaExplorer = "run_pokadot_js_app" + runKusamaPrometheus = "launch_prometheus" + runKusamaGrafana = "launch_grafana" ) var KusamaCmd = common.NewDiveCommandBuilder(). @@ -59,7 +62,19 @@ func kusama(cmd *cobra.Command, args []string) { } } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) for serviceName := range response.Dive { err = common.WriteServiceResponseData(response.Dive[serviceName].ServiceName, *response.Dive[serviceName], cliContext, serviceFileName) @@ -67,6 +82,6 @@ func kusama(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } } - stopMessage := fmt.Sprintf("Kusama Node Started. Please find service details in current working directory(%s)", serviceFileName) + stopMessage := fmt.Sprintf("Kusama Node Started. Please find service details in current working directory(%s)\n", serviceFileName) cliContext.Spinner().StopWithMessage(stopMessage) } diff --git a/cli/cmd/chains/kusama/run.go b/cli/cmd/chains/kusama/run.go index f6461097..65619648 100644 --- a/cli/cmd/chains/kusama/run.go +++ b/cli/cmd/chains/kusama/run.go @@ -4,10 +4,10 @@ import ( "fmt" "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves" + "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/starlark_run_config" "github.com/hugobyte/dive-core/cli/cmd/chains/utils" "github.com/hugobyte/dive-core/cli/common" - "github.com/kurtosis-tech/kurtosis/api/golang/core/lib/starlark_run_config" ) const ( @@ -63,6 +63,9 @@ func startRelayAndParaChain(cli *common.Cli, enclaveContext *enclaves.EnclaveCon KusamaResponseData := &common.DiveMultipleServiceResponse{} paraResult := &common.DiveMultipleServiceResponse{} + finalResult := &common.DiveMultipleServiceResponse{} + explorerResult := &common.DiveMultipleServiceResponse{} + metricsResult := &common.DiveMultipleServiceResponse{} runConfig := getKusamaRunConfig(serviceConfig, enclaveContext, param) response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.PolkadotRemotePackagePath, runConfig) @@ -88,6 +91,8 @@ func startRelayAndParaChain(cli *common.Cli, enclaveContext *enclaves.EnclaveCon return nil, common.WrapMessageToErrorf(common.ErrDataUnMarshall, "%s.%s", err, "Kusama Run Failed ") } + finalResult = result + if cli.Context().CheckSkippedInstructions(skippedInstructions) { if len(serviceConfig.Para) != 0 && serviceConfig.Para[0].Name != "" { ipAddress, err := GetIPAddress(cli, serviceConfig, true, result) @@ -98,6 +103,8 @@ func startRelayAndParaChain(cli *common.Cli, enclaveContext *enclaves.EnclaveCon if err != nil { return nil, err } + finalResult = ConcatenateDiveResults(result, paraResult) + } else { return nil, common.WrapMessageToError(common.ErrStarlarkResponse, "Kusama Already Running") } @@ -111,10 +118,25 @@ func startRelayAndParaChain(cli *common.Cli, enclaveContext *enclaves.EnclaveCon if err != nil { return nil, err } + finalResult = ConcatenateDiveResults(result, paraResult) + } + } + + if metrics { + metricsResult, err = startMetrics(cli, enclaveContext, para, finalResult) + finalResult = ConcatenateDiveResults(finalResult, metricsResult) + if err != nil { + return nil, err } } - finalResult := ConcatenateDiveResults(result, paraResult) + if explorer { + explorerResult, err = startExplorer(cli, enclaveContext) + if err != nil { + return nil, err + } + finalResult = ConcatenateDiveResults(finalResult, explorerResult) + } return finalResult, nil } @@ -182,16 +204,22 @@ func runParaChain(cli *common.Cli, enclaveContext *enclaves.EnclaveContext, serv return resultPara, nil } -func ConcatenateDiveResults(result, paraResult *common.DiveMultipleServiceResponse) *common.DiveMultipleServiceResponse { +func ConcatenateDiveResults(result1, result2 *common.DiveMultipleServiceResponse) *common.DiveMultipleServiceResponse { + if result1 == nil { + return result2 + } else if result2 == nil { + return result1 + } + concatenatedResult := &common.DiveMultipleServiceResponse{ Dive: make(map[string]*common.DiveServiceResponse), } - for key, value := range result.Dive { + for key, value := range result1.Dive { concatenatedResult.Dive[key] = value } - for key, value := range paraResult.Dive { + for key, value := range result2.Dive { concatenatedResult.Dive[key] = value } @@ -252,8 +280,10 @@ func configureMetrics(serviceConfig *utils.PolkadotServiceConfig) { for i := range serviceConfig.RelayChain.Nodes { serviceConfig.RelayChain.Nodes[i].Prometheus = true } - for i := range serviceConfig.Para[0].Nodes { - serviceConfig.Para[0].Nodes[i].Prometheus = true + if len(serviceConfig.Para) != 0 { + for i := range serviceConfig.Para[0].Nodes { + serviceConfig.Para[0].Nodes[i].Prometheus = true + } } } @@ -280,16 +310,6 @@ func getKusamaRunConfig(serviceConfig *utils.PolkadotServiceConfig, enclaveConte } } -func uploadFiles(cli *common.Cli, enclaveCtx *enclaves.EnclaveContext) error { - runConfig := common.GetStarlarkRunConfig("{}", common.DivePolkaDotUtilsPath, runUploadFiles) - _, err := enclaveCtx.RunStarlarkRemotePackageBlocking(cli.Context().GetContext(), common.PolkadotRemotePackagePath, runConfig) - if err != nil { - return common.WrapMessageToError(common.ErrStarlarkRunFailed, err.Error()) - } - - return nil -} - func getParaRunConfig(serviceConfig *utils.PolkadotServiceConfig, enclaveContext *enclaves.EnclaveContext, para string) *starlark_run_config.StarlarkRunConfig { if len(serviceConfig.Para) != 0 && serviceConfig.Para[0].Name != "" { if serviceConfig.ChainType == localChain { @@ -309,9 +329,21 @@ func GetIPAddress(cli *common.Cli, serviceConfig *utils.PolkadotServiceConfig, r if relayReRun { nodename = serviceConfig.RelayChain.Nodes[0].Name var services = common.Services{} - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) - err := cli.FileHandler().ReadJson(serviceFileName, &serviceConfig) + enclaves, err := cli.Context().GetEnclaves() + if err != nil { + cli.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + + err = cli.FileHandler().ReadJson(serviceFileName, &services) if err != nil { return "", err } @@ -332,3 +364,119 @@ func GetIPAddress(cli *common.Cli, serviceConfig *utils.PolkadotServiceConfig, r } return "", nil } + +func uploadFiles(cli *common.Cli, enclaveCtx *enclaves.EnclaveContext) error { + runConfig := common.GetStarlarkRunConfig("{}", common.DivePolkaDotUtilsPath, runUploadFiles) + _, err := enclaveCtx.RunStarlarkRemotePackageBlocking(cli.Context().GetContext(), common.PolkadotRemotePackagePath, runConfig) + if err != nil { + return common.WrapMessageToError(common.ErrStarlarkRunFailed, err.Error()) + } + + return nil +} + +func startExplorer(cli *common.Cli, enclaveCtx *enclaves.EnclaveContext) (*common.DiveMultipleServiceResponse, error) { + explorerResponseData := &common.DiveMultipleServiceResponse{} + + para := `{"ws_url":"ws://127.0.0.1:9944"}` + runConfig := common.GetStarlarkRunConfig(para, common.DivePolkaDotExplorerPath, runKusamaExplorer) + explorerResponse, _, err := enclaveCtx.RunStarlarkRemotePackage(cli.Context().GetContext(), common.PolkadotRemotePackagePath, runConfig) + if err != nil { + return nil, common.WrapMessageToError(common.ErrStarlarkRunFailed, err.Error()) + } + + responseData, services, skippedInstructions, err := common.GetSerializedData(cli, explorerResponse) + if err != nil { + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) + if errRemove != nil { + return nil, common.WrapMessageToError(errRemove, "Explorer Run Failed ") + } + return nil, common.WrapMessageToError(err, "Explorer Run Failed ") + } + + if cli.Context().CheckSkippedInstructions(skippedInstructions) { + return nil, common.WrapMessageToError(common.ErrStarlarkResponse, "Explorer Already Running") + } + + result, err := explorerResponseData.Decode([]byte(responseData)) + if err != nil { + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) + if errRemove != nil { + return nil, common.WrapMessageToError(errRemove, "Explorer Run Failed ") + } + return nil, common.WrapMessageToErrorf(common.ErrDataUnMarshall, "%s.%s", err, "Explorer Run Failed ") + } + + return result, nil +} + +func startMetrics(cli *common.Cli, enclaveCtx *enclaves.EnclaveContext, para string, final_result *common.DiveMultipleServiceResponse) (*common.DiveMultipleServiceResponse, error) { + prometheus := &common.DiveMultipleServiceResponse{} + grafana := &common.DiveMultipleServiceResponse{} + + service_details, err := final_result.EncodeToString() + if err != nil { + return nil, common.WrapMessageToError(common.ErrDataMarshall, err.Error()) + } + + paraPrometheus := fmt.Sprintf(`{"args":%s, "service_details":%s}`, para, service_details) + runConfig := common.GetStarlarkRunConfig(paraPrometheus, common.DivePolkaDotPrometheusPath, runKusamaPrometheus) + prometheusResponse, _, err := enclaveCtx.RunStarlarkRemotePackage(cli.Context().GetContext(), common.PolkadotRemotePackagePath, runConfig) + if err != nil { + return nil, common.WrapMessageToError(common.ErrStarlarkRunFailed, err.Error()) + } + + prometheusResponseData, services, skippedInstructions, err := common.GetSerializedData(cli, prometheusResponse) + if err != nil { + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) + if errRemove != nil { + return nil, common.WrapMessageToError(errRemove, "Prometheus Run Failed ") + } + return nil, common.WrapMessageToError(err, "Prometheus Run Failed ") + } + + if cli.Context().CheckSkippedInstructions(skippedInstructions) { + return nil, common.WrapMessageToError(common.ErrStarlarkResponse, "Prometheus Already Running") + } + + prometheusResult, err := prometheus.Decode([]byte(prometheusResponseData)) + if err != nil { + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) + if errRemove != nil { + return nil, common.WrapMessageToError(errRemove, "Prometheus Run Failed ") + } + return nil, common.WrapMessageToErrorf(common.ErrDataUnMarshall, "%s.%s", err, "Prometheus Run Failed ") + } + + paraGrafana := `{"args":{}}` + runConfigGrafana := common.GetStarlarkRunConfig(paraGrafana, common.DivePolkaDotGrafanaPath, runKusamaGrafana) + grafanaResponse, _, err := enclaveCtx.RunStarlarkRemotePackage(cli.Context().GetContext(), common.PolkadotRemotePackagePath, runConfigGrafana) + if err != nil { + return nil, common.WrapMessageToError(common.ErrStarlarkRunFailed, err.Error()) + } + + grafanaResponseData, services, skippedInstructions, err := common.GetSerializedData(cli, grafanaResponse) + if err != nil { + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) + if errRemove != nil { + return nil, common.WrapMessageToError(errRemove, "Grafana Run Failed ") + } + return nil, common.WrapMessageToError(err, "Grafana Run Failed ") + } + + if cli.Context().CheckSkippedInstructions(skippedInstructions) { + return nil, common.WrapMessageToError(common.ErrStarlarkResponse, "Grafana Already Running") + } + + grafanaResult, err := grafana.Decode([]byte(grafanaResponseData)) + if err != nil { + errRemove := cli.Context().RemoveServicesByServiceNames(services, common.EnclaveName) + if errRemove != nil { + return nil, common.WrapMessageToError(errRemove, "Grafana Run Failed ") + } + return nil, common.WrapMessageToErrorf(common.ErrDataUnMarshall, "%s.%s", err, "Grafana Run Failed ") + } + + result := ConcatenateDiveResults(prometheusResult, grafanaResult) + return result, nil +} diff --git a/cli/cmd/chains/neutron/cmd.go b/cli/cmd/chains/neutron/cmd.go index cf0bc34c..a74b6abd 100644 --- a/cli/cmd/chains/neutron/cmd.go +++ b/cli/cmd/chains/neutron/cmd.go @@ -39,13 +39,26 @@ func neutron(cmd *cobra.Command, args []string) { if err != nil { cliContext.Fatal(err) } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext, serviceFileName) if err != nil { cliContext.Fatal(err) } - stopMessage := fmt.Sprintf("Neutron Node Started. Please find service details in current working directory(%s)", serviceFileName) + stopMessage := fmt.Sprintf("Neutron Node Started. Please find service details in current working directory(%s)\n", serviceFileName) cliContext.Spinner().StopWithMessage(stopMessage) } diff --git a/cli/cmd/chains/polkadot/cmd.go b/cli/cmd/chains/polkadot/cmd.go index 9ad4c220..9dbd31bb 100644 --- a/cli/cmd/chains/polkadot/cmd.go +++ b/cli/cmd/chains/polkadot/cmd.go @@ -54,7 +54,19 @@ func polkadot(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName) + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) fmt.Print(response.Dive) for serviceName := range response.Dive { @@ -64,6 +76,6 @@ func polkadot(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } } - stopMessage := fmt.Sprintf("Polkadot Node Started. Please find service details in current working directory(%s)", serviceFileName) + stopMessage := fmt.Sprintf("Polkadot Node Started. Please find service details in current working directory(%s)\n", serviceFileName) cliContext.StopSpinnerIfNotVerbose(stopMessage, common.DiveLogs) } diff --git a/cli/cmd/utility/clean.go b/cli/cmd/utility/clean.go index ed0f7d7d..ce4c3b8c 100644 --- a/cli/cmd/utility/clean.go +++ b/cli/cmd/utility/clean.go @@ -50,7 +50,7 @@ func clean(cmd *cobra.Command, args []string) { cliContext.Logger().Fatal(common.CodeOf(err), err.Error()) } for _, enclave := range enclaves { - err = cliContext.FileHandler().RemoveFiles([]string{fmt.Sprintf(common.DiveOutFile, enclave.Name), fmt.Sprintf(common.ServiceFilePath, enclave.Name)}) + err = cliContext.FileHandler().RemoveFiles([]string{fmt.Sprintf(common.DiveOutFile, enclave.Name, enclave.ShortUuid), fmt.Sprintf(common.ServiceFilePath, enclave.Name, enclave.ShortUuid)}) if err != nil { cliContext.Logger().SetErrorToStderr() cliContext.Logger().Fatal(common.CodeOf(err), err.Error()) @@ -61,12 +61,25 @@ func clean(cmd *cobra.Command, args []string) { } else { cliContext.StartSpinnerIfNotVerbose(fmt.Sprintf("Cleaning Dive By Enclave %s", common.EnclaveName), common.DiveLogs) + enclaves, err := cliContext.Context().GetEnclaves() + if err != nil { + cliContext.Fatal(err) + } + + var ShortUuid string + for _, enclave := range enclaves { + if enclave.Name == common.EnclaveName { + ShortUuid = enclave.ShortUuid + } + } + err = cliContext.Context().CleanEnclaveByName(common.EnclaveName) if err != nil { cliContext.Logger().SetErrorToStderr() cliContext.Logger().Fatal(common.CodeOf(err), err.Error()) } - err = cliContext.FileHandler().RemoveFiles([]string{fmt.Sprintf(common.DiveOutFile, common.EnclaveName), fmt.Sprintf(common.ServiceFilePath, common.EnclaveName)}) + + err = cliContext.FileHandler().RemoveFiles([]string{fmt.Sprintf(common.DiveOutFile, common.EnclaveName, ShortUuid), fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid)}) if err != nil { cliContext.Logger().SetErrorToStderr() cliContext.Logger().Fatal(common.CodeOf(err), err.Error()) diff --git a/cli/common/constants.go b/cli/common/constants.go index e8e35cf6..0fa36c40 100644 --- a/cli/common/constants.go +++ b/cli/common/constants.go @@ -21,13 +21,16 @@ const ( DivePolkadotParachainNodeSetup = "/parachain/parachain.star" DivePolkadotRelayNodeSetupScript = "/relaychain/relay-chain.star" DivePolkaDotUtilsPath = "/package_io/utils.star" + DivePolkaDotExplorerPath = "/package_io/polkadot_js_app.star" + DivePolkaDotPrometheusPath = "/package_io/promethues.star" + DivePolkaDotGrafanaPath = "/package_io/grafana.star" DiveDryRun = false DiveDefaultParallelism = 4 DiveLogDirectory = "/logs/" DiveDitLogFile = "dive.log" DiveErrorLogFile = "error.log" - DiveOutFile = "dive_%s.json" - ServiceFilePath = "services_%s.json" + DiveOutFile = "dive_%s_%s.json" + ServiceFilePath = "services_%s_%s.json" DiveAppDir = ".dive" removeServiceStarlarkScript = ` def run(plan,args): diff --git a/cli/common/types.go b/cli/common/types.go index 3bce1243..c3da14b8 100644 --- a/cli/common/types.go +++ b/cli/common/types.go @@ -19,6 +19,7 @@ type DiveServiceResponse struct { Prometheus bool `json:"prometheus,omitempty"` IpAddress string `json:"ip_address,omitempty"` Node string `json:"node-type,omitempty"` + PrometheusPort int `json:"prometheus_port,omitempty"` } type DiveMultipleServiceResponse struct { @@ -57,6 +58,16 @@ func (dive *DiveServiceResponse) EncodeToString() (string, error) { return string(encodedBytes), nil } +func (dive *DiveMultipleServiceResponse) EncodeToString() (string, error) { + + encodedBytes, err := json.Marshal(&dive.Dive) + if err != nil { + return "", WrapMessageToError(ErrDataMarshall, err.Error()) + } + + return string(encodedBytes), nil +} + type Services map[string]*DiveServiceResponse // The EnclaveInfo type represents information about an enclave, including its name, UUID, short UUID, From ea20638c882626f112f2fab370faad11480e22cf Mon Sep 17 00:00:00 2001 From: riyasng12 Date: Tue, 2 Jan 2024 16:41:19 +0530 Subject: [PATCH 2/2] refactor: made a common function to get short uuid --- cli/cmd/bridge/btp/cmd.go | 13 +++---------- cli/cmd/bridge/btp/run.go | 12 +++--------- cli/cmd/bridge/ibc/cmd.go | 11 ++--------- cli/cmd/bridge/utils/types.go | 13 ++++--------- cli/cmd/chains/archway/cmd.go | 11 ++--------- cli/cmd/chains/eth/cmd.go | 11 ++--------- cli/cmd/chains/hardhat/cmd.go | 11 ++--------- cli/cmd/chains/icon/cmd.go | 11 ++--------- cli/cmd/chains/kusama/cmd.go | 11 ++--------- cli/cmd/chains/kusama/run.go | 13 +++---------- cli/cmd/chains/neutron/cmd.go | 11 ++--------- cli/cmd/chains/polkadot/cmd.go | 11 ++--------- cli/cmd/utility/clean.go | 11 ++--------- cli/common/context.go | 16 ++++++++++++++++ cli/common/interfaces.go | 3 +++ 15 files changed, 50 insertions(+), 119 deletions(-) diff --git a/cli/cmd/bridge/btp/cmd.go b/cli/cmd/bridge/btp/cmd.go index 55316c33..401d9fc9 100644 --- a/cli/cmd/bridge/btp/cmd.go +++ b/cli/cmd/bridge/btp/cmd.go @@ -55,20 +55,13 @@ func btpRelay(cmd *cobra.Command, args []string) { if err != nil { cliContext.Fatal(err) } - - enclaves, err := cliContext.Context().GetEnclaves() + + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName, shortUuid) err = cliContext.FileHandler().WriteFile(serviceFileName, []byte(result)) if err != nil { diff --git a/cli/cmd/bridge/btp/run.go b/cli/cmd/bridge/btp/run.go index 0ce20257..1b54713a 100644 --- a/cli/cmd/bridge/btp/run.go +++ b/cli/cmd/bridge/btp/run.go @@ -139,18 +139,12 @@ func runBtpSetupWhenSingleChainRunning(cli *common.Cli, enclaveContext *enclaves var chainAServiceResponse, chainBServiceResponse, response string var services = common.Services{} - enclaves, err := cli.Context().GetEnclaves() + shortUuid, err := cli.Context().GetShortUuid(common.EnclaveName) if err != nil { - cli.Fatal(err) + return "", common.WrapMessageToError(err, "Failed to get enclave UUID") } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = cli.FileHandler().ReadJson(serviceFileName, &services) diff --git a/cli/cmd/bridge/ibc/cmd.go b/cli/cmd/bridge/ibc/cmd.go index cf141a79..bb27dfa9 100644 --- a/cli/cmd/bridge/ibc/cmd.go +++ b/cli/cmd/bridge/ibc/cmd.go @@ -43,19 +43,12 @@ func ibcRelay(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.DiveOutFile, common.EnclaveName, shortUuid) err = cliContext.FileHandler().WriteFile(serviceFileName, []byte(result)) if err != nil { diff --git a/cli/cmd/bridge/utils/types.go b/cli/cmd/bridge/utils/types.go index 4f70dd3d..06089cd3 100644 --- a/cli/cmd/bridge/utils/types.go +++ b/cli/cmd/bridge/utils/types.go @@ -58,18 +58,13 @@ func (chains *Chains) GetIbcRelayParams(src_service_config string, dst_service_c func (chains *Chains) GetServicesResponse(cli *common.Cli) (string, string, error) { var serviceConfig = common.Services{} - enclaves, err := cli.Context().GetEnclaves() + + shortUuid, err := cli.Context().GetShortUuid(common.EnclaveName) if err != nil { - cli.Fatal(err) + return "", "", fmt.Errorf("failed to get short uuid of enclave") } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = cli.FileHandler().ReadJson(serviceFileName, &serviceConfig) diff --git a/cli/cmd/chains/archway/cmd.go b/cli/cmd/chains/archway/cmd.go index 6d5934d9..57dc1658 100644 --- a/cli/cmd/chains/archway/cmd.go +++ b/cli/cmd/chains/archway/cmd.go @@ -42,19 +42,12 @@ func archway(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext, serviceFileName) if err != nil { diff --git a/cli/cmd/chains/eth/cmd.go b/cli/cmd/chains/eth/cmd.go index 8b8a1b15..767db728 100644 --- a/cli/cmd/chains/eth/cmd.go +++ b/cli/cmd/chains/eth/cmd.go @@ -38,19 +38,12 @@ func eth(cmd *cobra.Command, args []string) { } } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = common.WriteServiceResponseData(responseData.ServiceName, *responseData, cliContext, serviceFileName) if err != nil { diff --git a/cli/cmd/chains/hardhat/cmd.go b/cli/cmd/chains/hardhat/cmd.go index 4e9e0ae3..a62402fe 100644 --- a/cli/cmd/chains/hardhat/cmd.go +++ b/cli/cmd/chains/hardhat/cmd.go @@ -37,19 +37,12 @@ func hardhat(cmd *cobra.Command, args []string) { } } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = common.WriteServiceResponseData(responseData.ServiceName, *responseData, cliContext, serviceFileName) if err != nil { diff --git a/cli/cmd/chains/icon/cmd.go b/cli/cmd/chains/icon/cmd.go index 0588bdd1..16f56d32 100644 --- a/cli/cmd/chains/icon/cmd.go +++ b/cli/cmd/chains/icon/cmd.go @@ -84,19 +84,12 @@ func icon(cmd *cobra.Command, args []string) { } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext, serviceFileName) if err != nil { diff --git a/cli/cmd/chains/kusama/cmd.go b/cli/cmd/chains/kusama/cmd.go index c2030057..a6dff01e 100644 --- a/cli/cmd/chains/kusama/cmd.go +++ b/cli/cmd/chains/kusama/cmd.go @@ -62,19 +62,12 @@ func kusama(cmd *cobra.Command, args []string) { } } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) for serviceName := range response.Dive { err = common.WriteServiceResponseData(response.Dive[serviceName].ServiceName, *response.Dive[serviceName], cliContext, serviceFileName) diff --git a/cli/cmd/chains/kusama/run.go b/cli/cmd/chains/kusama/run.go index 65619648..098b45ea 100644 --- a/cli/cmd/chains/kusama/run.go +++ b/cli/cmd/chains/kusama/run.go @@ -330,18 +330,11 @@ func GetIPAddress(cli *common.Cli, serviceConfig *utils.PolkadotServiceConfig, r nodename = serviceConfig.RelayChain.Nodes[0].Name var services = common.Services{} - enclaves, err := cli.Context().GetEnclaves() + shortUuid, err := cli.Context().GetShortUuid(common.EnclaveName) if err != nil { - cli.Fatal(err) + return "", fmt.Errorf("failed to get uuid of enclave") } - - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = cli.FileHandler().ReadJson(serviceFileName, &services) if err != nil { diff --git a/cli/cmd/chains/neutron/cmd.go b/cli/cmd/chains/neutron/cmd.go index a74b6abd..769a7937 100644 --- a/cli/cmd/chains/neutron/cmd.go +++ b/cli/cmd/chains/neutron/cmd.go @@ -40,19 +40,12 @@ func neutron(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) err = common.WriteServiceResponseData(response.ServiceName, *response, cliContext, serviceFileName) if err != nil { diff --git a/cli/cmd/chains/polkadot/cmd.go b/cli/cmd/chains/polkadot/cmd.go index 9dbd31bb..65b594aa 100644 --- a/cli/cmd/chains/polkadot/cmd.go +++ b/cli/cmd/chains/polkadot/cmd.go @@ -54,19 +54,12 @@ func polkadot(cmd *cobra.Command, args []string) { cliContext.Fatal(err) } - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - - serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid) + serviceFileName := fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid) fmt.Print(response.Dive) for serviceName := range response.Dive { diff --git a/cli/cmd/utility/clean.go b/cli/cmd/utility/clean.go index ce4c3b8c..f6598d7c 100644 --- a/cli/cmd/utility/clean.go +++ b/cli/cmd/utility/clean.go @@ -61,25 +61,18 @@ func clean(cmd *cobra.Command, args []string) { } else { cliContext.StartSpinnerIfNotVerbose(fmt.Sprintf("Cleaning Dive By Enclave %s", common.EnclaveName), common.DiveLogs) - enclaves, err := cliContext.Context().GetEnclaves() + shortUuid, err := cliContext.Context().GetShortUuid(common.EnclaveName) if err != nil { cliContext.Fatal(err) } - var ShortUuid string - for _, enclave := range enclaves { - if enclave.Name == common.EnclaveName { - ShortUuid = enclave.ShortUuid - } - } - err = cliContext.Context().CleanEnclaveByName(common.EnclaveName) if err != nil { cliContext.Logger().SetErrorToStderr() cliContext.Logger().Fatal(common.CodeOf(err), err.Error()) } - err = cliContext.FileHandler().RemoveFiles([]string{fmt.Sprintf(common.DiveOutFile, common.EnclaveName, ShortUuid), fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, ShortUuid)}) + err = cliContext.FileHandler().RemoveFiles([]string{fmt.Sprintf(common.DiveOutFile, common.EnclaveName, shortUuid), fmt.Sprintf(common.ServiceFilePath, common.EnclaveName, shortUuid)}) if err != nil { cliContext.Logger().SetErrorToStderr() cliContext.Logger().Fatal(common.CodeOf(err), err.Error()) diff --git a/cli/common/context.go b/cli/common/context.go index 8b2ac7bf..f39532da 100644 --- a/cli/common/context.go +++ b/cli/common/context.go @@ -295,3 +295,19 @@ func (dc *diveContext) RemoveServicesByServiceNames(services map[string]string, func (dc *diveContext) Exit(statusCode int) { os.Exit(statusCode) } + +func (dc *diveContext) GetShortUuid(enclaveName string) (string, error) { + enclaves, err := dc.GetEnclaves() + if err != nil { + return "", err + } + + var shortUuid string + for _, enclave := range enclaves { + if enclave.Name == enclaveName { + shortUuid = enclave.ShortUuid + } + } + + return shortUuid, nil +} diff --git a/cli/common/interfaces.go b/cli/common/interfaces.go index 82de3115..a86774a1 100644 --- a/cli/common/interfaces.go +++ b/cli/common/interfaces.go @@ -116,6 +116,9 @@ type Context interface { // CreateEnclave creates a new enclave with the specified name and returns its context. CreateEnclave(enclaveName string) (*enclaves.EnclaveContext, error) + // Get the short UUID of the given enclave. + GetShortUuid(enclaveName string) (string, error) + // Exit terminates the execution of the context with the given status code. Exit(statusCode int) }