khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 16 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 17 | package main |
| 18 | |
| 19 | import ( |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 20 | "context" |
| 21 | "errors" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 22 | "fmt" |
| 23 | "os" |
| 24 | "os/signal" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 25 | "strconv" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 26 | "syscall" |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 27 | "time" |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 28 | |
| 29 | "github.com/opencord/voltha-go/rw_core/config" |
| 30 | c "github.com/opencord/voltha-go/rw_core/core" |
| 31 | "github.com/opencord/voltha-go/rw_core/utils" |
divyadesai | c68c9c0 | 2020-02-26 12:48:09 +0000 | [diff] [blame] | 32 | conf "github.com/opencord/voltha-lib-go/v3/pkg/config" |
serkant.uluderya | 2ae470f | 2020-01-21 11:13:09 -0800 | [diff] [blame] | 33 | "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore" |
| 34 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
| 35 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
| 36 | "github.com/opencord/voltha-lib-go/v3/pkg/probe" |
| 37 | "github.com/opencord/voltha-lib-go/v3/pkg/version" |
| 38 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 39 | ) |
| 40 | |
| 41 | type rwCore struct { |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 42 | kvClient kvstore.Client |
| 43 | config *config.RWCoreFlags |
| 44 | halted bool |
| 45 | exitChannel chan int |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 46 | //kmp *kafka.KafkaMessagingProxy |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 47 | kafkaClient kafka.Client |
| 48 | core *c.Core |
khenaidoo | abad44c | 2018-08-03 16:58:35 -0400 | [diff] [blame] | 49 | //For test |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 50 | receiverChannels []<-chan *ic.InterContainerMessage |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | func newKVClient(storeType string, address string, timeout int) (kvstore.Client, error) { |
| 54 | |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 55 | logger.Infow("kv-store-type", log.Fields{"store": storeType}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 56 | switch storeType { |
| 57 | case "consul": |
| 58 | return kvstore.NewConsulClient(address, timeout) |
| 59 | case "etcd": |
| 60 | return kvstore.NewEtcdClient(address, timeout) |
| 61 | } |
| 62 | return nil, errors.New("unsupported-kv-store") |
| 63 | } |
| 64 | |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 65 | func newKafkaClient(clientType string, host string, port int, instanceID string, livenessChannelInterval time.Duration) (kafka.Client, error) { |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 66 | |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 67 | logger.Infow("kafka-client-type", log.Fields{"client": clientType}) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 68 | switch clientType { |
| 69 | case "sarama": |
| 70 | return kafka.NewSaramaClient( |
| 71 | kafka.Host(host), |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 72 | kafka.Port(port), |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 73 | kafka.ConsumerType(kafka.GroupCustomer), |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 74 | kafka.ProducerReturnOnErrors(true), |
| 75 | kafka.ProducerReturnOnSuccess(true), |
| 76 | kafka.ProducerMaxRetries(6), |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 77 | kafka.NumPartitions(3), |
| 78 | kafka.ConsumerGroupName(instanceID), |
| 79 | kafka.ConsumerGroupPrefix(instanceID), |
khenaidoo | 54e0ddf | 2019-02-27 16:21:33 -0500 | [diff] [blame] | 80 | kafka.AutoCreateTopic(true), |
khenaidoo | ca30132 | 2019-01-09 23:06:32 -0500 | [diff] [blame] | 81 | kafka.ProducerFlushFrequency(5), |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 82 | kafka.ProducerRetryBackoff(time.Millisecond*30), |
| 83 | kafka.LivenessChannelInterval(livenessChannelInterval), |
| 84 | ), nil |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 85 | } |
| 86 | return nil, errors.New("unsupported-client-type") |
| 87 | } |
| 88 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 89 | func newRWCore(cf *config.RWCoreFlags) *rwCore { |
| 90 | var rwCore rwCore |
| 91 | rwCore.config = cf |
| 92 | rwCore.halted = false |
| 93 | rwCore.exitChannel = make(chan int, 1) |
khenaidoo | 7923270 | 2018-12-04 11:00:41 -0500 | [diff] [blame] | 94 | rwCore.receiverChannels = make([]<-chan *ic.InterContainerMessage, 0) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 95 | return &rwCore |
| 96 | } |
| 97 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 98 | func (rw *rwCore) start(ctx context.Context, instanceID string) { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 99 | logger.Info("Starting RW Core components") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 100 | |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 101 | // Setup KV Client |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 102 | logger.Debugw("create-kv-client", log.Fields{"kvstore": rw.config.KVStoreType}) |
Kent Hagerman | 16ce36a | 2019-12-17 13:40:53 -0500 | [diff] [blame] | 103 | var err error |
| 104 | if rw.kvClient, err = newKVClient( |
| 105 | rw.config.KVStoreType, |
| 106 | rw.config.KVStoreHost+":"+strconv.Itoa(rw.config.KVStorePort), |
| 107 | rw.config.KVStoreTimeout); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 108 | logger.Fatal(err) |
Kent Hagerman | 16ce36a | 2019-12-17 13:40:53 -0500 | [diff] [blame] | 109 | } |
divyadesai | c68c9c0 | 2020-02-26 12:48:09 +0000 | [diff] [blame] | 110 | cm := conf.NewConfigManager(rw.kvClient, rw.config.KVStoreType, rw.config.KVStoreHost, rw.config.KVStorePort, rw.config.KVStoreTimeout) |
divyadesai | 5ff3092 | 2020-03-19 05:46:25 +0000 | [diff] [blame] | 111 | go conf.StartLogLevelConfigProcessing(cm, ctx) |
Kent Hagerman | 16ce36a | 2019-12-17 13:40:53 -0500 | [diff] [blame] | 112 | |
| 113 | // Setup KV transaction context |
| 114 | if err := c.SetTransactionContext(instanceID, |
| 115 | rw.config.KVStoreDataPrefix+"/transactions/", |
| 116 | rw.kvClient, |
| 117 | rw.config.KVStoreTimeout); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 118 | logger.Fatal("creating-transaction-context-failed") |
Richard Jankowski | e4d7766 | 2018-10-17 13:53:21 -0400 | [diff] [blame] | 119 | } |
| 120 | |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 121 | // Setup Kafka Client |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 122 | if rw.kafkaClient, err = newKafkaClient("sarama", |
| 123 | rw.config.KafkaAdapterHost, |
| 124 | rw.config.KafkaAdapterPort, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 125 | instanceID, |
Girish Kumar | 4d3887d | 2019-11-22 14:22:05 +0000 | [diff] [blame] | 126 | rw.config.LiveProbeInterval/2); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 127 | logger.Fatal("Unsupported-kafka-client") |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 128 | } |
| 129 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 130 | // Create the core service |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 131 | rw.core = c.NewCore(ctx, instanceID, rw.config, rw.kvClient, rw.kafkaClient) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 132 | |
| 133 | // start the core |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 134 | err = rw.core.Start(ctx) |
| 135 | if err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 136 | logger.Fatalf("failed-to-start-rwcore", log.Fields{"error": err}) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 137 | } |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 138 | } |
| 139 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 140 | func (rw *rwCore) stop(ctx context.Context) { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 141 | // Stop leadership tracking |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 142 | rw.halted = true |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 143 | |
| 144 | // send exit signal |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 145 | rw.exitChannel <- 0 |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 146 | |
| 147 | // Cleanup - applies only if we had a kvClient |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 148 | if rw.kvClient != nil { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 149 | // Release all reservations |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 150 | if err := rw.kvClient.ReleaseAllReservations(ctx); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 151 | logger.Infow("fail-to-release-all-reservations", log.Fields{"error": err}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 152 | } |
| 153 | // Close the DB connection |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 154 | rw.kvClient.Close() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 155 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 156 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 157 | rw.core.Stop(ctx) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 158 | |
| 159 | //if rw.kafkaClient != nil { |
| 160 | // rw.kafkaClient.Stop() |
| 161 | //} |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | func waitForExit() int { |
| 165 | signalChannel := make(chan os.Signal, 1) |
| 166 | signal.Notify(signalChannel, |
| 167 | syscall.SIGHUP, |
| 168 | syscall.SIGINT, |
| 169 | syscall.SIGTERM, |
| 170 | syscall.SIGQUIT) |
| 171 | |
| 172 | exitChannel := make(chan int) |
| 173 | |
| 174 | go func() { |
| 175 | s := <-signalChannel |
| 176 | switch s { |
| 177 | case syscall.SIGHUP, |
| 178 | syscall.SIGINT, |
| 179 | syscall.SIGTERM, |
| 180 | syscall.SIGQUIT: |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 181 | logger.Infow("closing-signal-received", log.Fields{"signal": s}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 182 | exitChannel <- 0 |
| 183 | default: |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 184 | logger.Infow("unexpected-signal-received", log.Fields{"signal": s}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 185 | exitChannel <- 1 |
| 186 | } |
| 187 | }() |
| 188 | |
| 189 | code := <-exitChannel |
| 190 | return code |
| 191 | } |
| 192 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 193 | func printBanner() { |
| 194 | fmt.Println(" ") |
| 195 | fmt.Println(" ______ ______ ") |
| 196 | fmt.Println("| _ \\ \\ / / ___|___ _ __ ___ ") |
| 197 | fmt.Println("| |_) \\ \\ /\\ / / | / _ \\| '__/ _ \\ ") |
| 198 | fmt.Println("| _ < \\ V V /| |__| (_) | | | __/ ") |
| 199 | fmt.Println("|_| \\_\\ \\_/\\_/ \\____\\___/|_| \\___| ") |
| 200 | fmt.Println(" ") |
| 201 | } |
| 202 | |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 203 | func printVersion() { |
| 204 | fmt.Println("VOLTHA Read-Write Core") |
| 205 | fmt.Println(version.VersionInfo.String(" ")) |
| 206 | } |
| 207 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 208 | func main() { |
| 209 | start := time.Now() |
| 210 | |
| 211 | cf := config.NewRWCoreFlags() |
| 212 | cf.ParseCommandArguments() |
| 213 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 214 | // Set the instance ID as the hostname |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 215 | var instanceID string |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 216 | hostName := utils.GetHostName() |
| 217 | if len(hostName) > 0 { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 218 | instanceID = hostName |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 219 | } else { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 220 | logger.Fatal("HOSTNAME not set") |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 221 | } |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 222 | |
Don Newton | 8eca462 | 2020-02-10 16:44:48 -0500 | [diff] [blame] | 223 | realMain() |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 224 | |
| 225 | logLevel, err := log.StringToLogLevel(cf.LogLevel) |
| 226 | if err != nil { |
| 227 | panic(err) |
| 228 | } |
| 229 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 230 | //Setup default logger - applies for packages that do not have specific logger set |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 231 | if _, err := log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": instanceID}); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 232 | logger.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 233 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 234 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 235 | // Update all loggers (provisioned via init) with a common field |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 236 | if err := log.UpdateAllLoggers(log.Fields{"instanceId": instanceID}); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 237 | logger.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 238 | } |
| 239 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 240 | // Update all loggers to log level specified as input parameter |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 241 | log.SetAllLogLevel(logLevel) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 242 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 243 | //log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 244 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 245 | defer func() { |
| 246 | err := log.CleanUp() |
| 247 | if err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 248 | logger.Errorw("unable-to-flush-any-buffered-log-entries", log.Fields{"error": err}) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 249 | } |
| 250 | }() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 251 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 252 | // Print version / build information and exit |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 253 | if cf.DisplayVersionOnly { |
| 254 | printVersion() |
| 255 | return |
| 256 | } |
| 257 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 258 | // Print banner if specified |
| 259 | if cf.Banner { |
| 260 | printBanner() |
| 261 | } |
| 262 | |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 263 | logger.Infow("rw-core-config", log.Fields{"config": *cf}) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 264 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 265 | // Create the core |
| 266 | rw := newRWCore(cf) |
| 267 | |
| 268 | // Create a context adding the status update channel |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 269 | ctx, cancel := context.WithCancel(context.Background()) |
| 270 | defer cancel() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 271 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 272 | /* |
| 273 | * Create and start the liveness and readiness container management probes. This |
| 274 | * is done in the main function so just in case the main starts multiple other |
| 275 | * objects there can be a single probe end point for the process. |
| 276 | */ |
| 277 | p := &probe.Probe{} |
Kent Hagerman | c461883 | 2019-10-07 12:24:36 -0400 | [diff] [blame] | 278 | go p.ListenAndServe(fmt.Sprintf("%s:%d", rw.config.ProbeHost, rw.config.ProbePort)) |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 279 | |
| 280 | // Add the probe to the context to pass to all the services started |
| 281 | probeCtx := context.WithValue(ctx, probe.ProbeContextKey, p) |
| 282 | |
| 283 | // Start the core |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 284 | go rw.start(probeCtx, instanceID) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 285 | |
| 286 | code := waitForExit() |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 287 | logger.Infow("received-a-closing-signal", log.Fields{"code": code}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 288 | |
| 289 | // Cleanup before leaving |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 290 | rw.stop(probeCtx) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 291 | |
| 292 | elapsed := time.Since(start) |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 293 | logger.Infow("rw-core-run-time", log.Fields{"core": instanceID, "time": elapsed / time.Second}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 294 | } |