Skip to content

Commit

Permalink
NOISSUE: generate pulsar config based on genesis.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
krestkrest committed Jan 21, 2019
1 parent 02f5a3b commit d113660
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
25 changes: 24 additions & 1 deletion scripts/generate_insolar_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
defaultJaegerEndPoint = defaultHost + ":6831"
defaultLogLevel = "Debug"
defaultGenesisFile = "genesis.yaml"
defaultPulsarTemplate = "scripts/insolard/pulsar_template.yaml"
dataDirectoryTemplate = "scripts/insolard/nodes/%d/data"
certificatePathTemplate = "scripts/insolard/nodes/%d/cert.json"
)
Expand All @@ -49,12 +50,14 @@ var (
outputDir string
debugLevel string
gorundPortsPath string
pulsarTemplate string
)

func parseInputParams() {
var rootCmd = &cobra.Command{}

rootCmd.Flags().StringVarP(&genesisFile, "genesis", "g", defaultGenesisFile, "input genesis file")
rootCmd.Flags().StringVarP(&pulsarTemplate, "pulsar-template", "t", defaultPulsarTemplate, "path to pulsar template file")
rootCmd.Flags().StringVarP(&outputDir, "output", "o", "", "output directory ( required )")
rootCmd.Flags().StringVarP(&debugLevel, "debuglevel", "d", defaultLogLevel, "debug level")
rootCmd.Flags().StringVarP(&gorundPortsPath, "gorundports", "p", "", "path to insgorund ports ( required )")
Expand Down Expand Up @@ -87,6 +90,13 @@ func writeInsolarConfigs(insolarConfigs []configuration.Configuration) {
}
}

func writePulsarConfig(conf configuration.Configuration) {
data, err := yaml.Marshal(conf)
check("Can't Marshal pulsard config", err)
err = genesis.WriteFile(outputDir, "pulsar.yaml", string(data))
check("Can't WriteFile: "+gorundPortsPath, err)
}

func main() {
parseInputParams()

Expand Down Expand Up @@ -125,7 +135,20 @@ func main() {
insolarConfigs = append(insolarConfigs, conf)
}

cfgHolder := configuration.NewHolder()
err = cfgHolder.LoadFromFile(pulsarTemplate)
check("Can't read pulsar template config", err)
err = cfgHolder.LoadEnv()
check("Can't read pulsar template config", err)
fmt.Println("pulsar template config: " + pulsarTemplate)

pulsarConfig := cfgHolder.Configuration
pulsarConfig.Pulsar.PulseDistributor.BootstrapHosts = []string{}
for _, node := range genesisConf.DiscoveryNodes {
pulsarConfig.Pulsar.PulseDistributor.BootstrapHosts = append(pulsarConfig.Pulsar.PulseDistributor.BootstrapHosts, node.Host)
}

writeInsolarConfigs(insolarConfigs)
writeGorundPorts(gorundPorts)

writePulsarConfig(pulsarConfig)
}
4 changes: 2 additions & 2 deletions scripts/insolard/launchnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ create_required_dirs()

generate_insolard_configs()
{
go run scripts/generate_insolar_configs.go -o $GENERATED_CONFIGS_DIR -p $INSGORUND_PORT_FILE -g $GENESIS_CONFIG
go run scripts/generate_insolar_configs.go -o $GENERATED_CONFIGS_DIR -p $INSGORUND_PORT_FILE -g $GENESIS_CONFIG -t $BASE_DIR/pulsar_template.yaml
}

prepare()
Expand Down Expand Up @@ -274,7 +274,7 @@ check_working_dir
process_input_params $@

printf "start pulsar ... \n"
$PULSARD -c $BASE_DIR/pulsar.yaml &> $NODES_DATA/pulsar_output.log &
$PULSARD -c $GENERATED_CONFIGS_DIR/pulsar.yaml &> $NODES_DATA/pulsar_output.log &

if [ "$run_insgorund" == "true" ]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ pulsar:
protocol: TCP
address: 127.0.0.1:58091
behindnat: false
pulsedistributor:
bootstraphosts:
- 127.0.0.1:13831
keyspath: "scripts/insolard/configs/bootstrap_keys.json"
log:
level: Debug
Expand Down

0 comments on commit d113660

Please sign in to comment.