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": |
Scott Baker | 504b480 | 2020-04-17 10:12:20 -0700 | [diff] [blame] | 60 | return kvstore.NewEtcdClient(address, timeout, log.FatalLevel) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 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 | |
khenaidoo | 9084792 | 2018-12-03 14:47:51 -0500 | [diff] [blame] | 113 | // Setup Kafka Client |
Scott Baker | ee6a087 | 2019-10-29 15:59:52 -0700 | [diff] [blame] | 114 | if rw.kafkaClient, err = newKafkaClient("sarama", |
| 115 | rw.config.KafkaAdapterHost, |
| 116 | rw.config.KafkaAdapterPort, |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 117 | instanceID, |
Girish Kumar | 4d3887d | 2019-11-22 14:22:05 +0000 | [diff] [blame] | 118 | rw.config.LiveProbeInterval/2); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 119 | logger.Fatal("Unsupported-kafka-client") |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 120 | } |
| 121 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 122 | // Create the core service |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 123 | rw.core = c.NewCore(ctx, instanceID, rw.config, rw.kvClient, rw.kafkaClient) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 124 | |
| 125 | // start the core |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 126 | err = rw.core.Start(ctx) |
| 127 | if err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 128 | logger.Fatalf("failed-to-start-rwcore", log.Fields{"error": err}) |
Thomas Lee S | e5a4401 | 2019-11-07 20:32:24 +0530 | [diff] [blame] | 129 | } |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 130 | } |
| 131 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 132 | func (rw *rwCore) stop(ctx context.Context) { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 133 | // Stop leadership tracking |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 134 | rw.halted = true |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 135 | |
| 136 | // send exit signal |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 137 | rw.exitChannel <- 0 |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 138 | |
| 139 | // Cleanup - applies only if we had a kvClient |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 140 | if rw.kvClient != nil { |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 141 | // Release all reservations |
npujar | 467fe75 | 2020-01-16 20:17:45 +0530 | [diff] [blame] | 142 | if err := rw.kvClient.ReleaseAllReservations(ctx); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 143 | logger.Infow("fail-to-release-all-reservations", log.Fields{"error": err}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 144 | } |
| 145 | // Close the DB connection |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 146 | rw.kvClient.Close() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 147 | } |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 148 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 149 | rw.core.Stop(ctx) |
khenaidoo | 43c8212 | 2018-11-22 18:38:28 -0500 | [diff] [blame] | 150 | |
| 151 | //if rw.kafkaClient != nil { |
| 152 | // rw.kafkaClient.Stop() |
| 153 | //} |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | func waitForExit() int { |
| 157 | signalChannel := make(chan os.Signal, 1) |
| 158 | signal.Notify(signalChannel, |
| 159 | syscall.SIGHUP, |
| 160 | syscall.SIGINT, |
| 161 | syscall.SIGTERM, |
| 162 | syscall.SIGQUIT) |
| 163 | |
| 164 | exitChannel := make(chan int) |
| 165 | |
| 166 | go func() { |
| 167 | s := <-signalChannel |
| 168 | switch s { |
| 169 | case syscall.SIGHUP, |
| 170 | syscall.SIGINT, |
| 171 | syscall.SIGTERM, |
| 172 | syscall.SIGQUIT: |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 173 | logger.Infow("closing-signal-received", log.Fields{"signal": s}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 174 | exitChannel <- 0 |
| 175 | default: |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 176 | logger.Infow("unexpected-signal-received", log.Fields{"signal": s}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 177 | exitChannel <- 1 |
| 178 | } |
| 179 | }() |
| 180 | |
| 181 | code := <-exitChannel |
| 182 | return code |
| 183 | } |
| 184 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 185 | func printBanner() { |
| 186 | fmt.Println(" ") |
| 187 | fmt.Println(" ______ ______ ") |
| 188 | fmt.Println("| _ \\ \\ / / ___|___ _ __ ___ ") |
| 189 | fmt.Println("| |_) \\ \\ /\\ / / | / _ \\| '__/ _ \\ ") |
| 190 | fmt.Println("| _ < \\ V V /| |__| (_) | | | __/ ") |
| 191 | fmt.Println("|_| \\_\\ \\_/\\_/ \\____\\___/|_| \\___| ") |
| 192 | fmt.Println(" ") |
| 193 | } |
| 194 | |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 195 | func printVersion() { |
| 196 | fmt.Println("VOLTHA Read-Write Core") |
| 197 | fmt.Println(version.VersionInfo.String(" ")) |
| 198 | } |
| 199 | |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 200 | func main() { |
| 201 | start := time.Now() |
| 202 | |
| 203 | cf := config.NewRWCoreFlags() |
| 204 | cf.ParseCommandArguments() |
| 205 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 206 | // Set the instance ID as the hostname |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 207 | var instanceID string |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 208 | hostName := utils.GetHostName() |
| 209 | if len(hostName) > 0 { |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 210 | instanceID = hostName |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 211 | } else { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 212 | logger.Fatal("HOSTNAME not set") |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 213 | } |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 214 | |
Don Newton | 8eca462 | 2020-02-10 16:44:48 -0500 | [diff] [blame] | 215 | realMain() |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 216 | |
| 217 | logLevel, err := log.StringToLogLevel(cf.LogLevel) |
| 218 | if err != nil { |
| 219 | panic(err) |
| 220 | } |
| 221 | |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 222 | //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] | 223 | 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] | 224 | logger.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 225 | } |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 226 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 227 | // Update all loggers (provisioned via init) with a common field |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 228 | if err := log.UpdateAllLoggers(log.Fields{"instanceId": instanceID}); err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 229 | logger.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 230 | } |
| 231 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 232 | // Update all loggers to log level specified as input parameter |
Rohan Agrawal | 7f72f0c | 2020-01-14 12:05:51 +0000 | [diff] [blame] | 233 | log.SetAllLogLevel(logLevel) |
khenaidoo | 2c6a099 | 2019-04-29 13:46:56 -0400 | [diff] [blame] | 234 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 235 | //log.SetPackageLogLevel("github.com/opencord/voltha-go/rw_core/core", log.DebugLevel) |
khenaidoo | b920354 | 2018-09-17 22:56:37 -0400 | [diff] [blame] | 236 | |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 237 | defer func() { |
| 238 | err := log.CleanUp() |
| 239 | if err != nil { |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 240 | logger.Errorw("unable-to-flush-any-buffered-log-entries", log.Fields{"error": err}) |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 241 | } |
| 242 | }() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 243 | |
khenaidoo | 631fe54 | 2019-05-31 15:44:43 -0400 | [diff] [blame] | 244 | // Print version / build information and exit |
David K. Bainbridge | f430cd5 | 2019-05-28 15:00:35 -0700 | [diff] [blame] | 245 | if cf.DisplayVersionOnly { |
| 246 | printVersion() |
| 247 | return |
| 248 | } |
| 249 | |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 250 | // Print banner if specified |
| 251 | if cf.Banner { |
| 252 | printBanner() |
| 253 | } |
| 254 | |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 255 | logger.Infow("rw-core-config", log.Fields{"config": *cf}) |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 256 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 257 | // Create the core |
| 258 | rw := newRWCore(cf) |
| 259 | |
| 260 | // Create a context adding the status update channel |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 261 | ctx, cancel := context.WithCancel(context.Background()) |
| 262 | defer cancel() |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 263 | |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 264 | /* |
| 265 | * Create and start the liveness and readiness container management probes. This |
| 266 | * is done in the main function so just in case the main starts multiple other |
| 267 | * objects there can be a single probe end point for the process. |
| 268 | */ |
| 269 | p := &probe.Probe{} |
Kent Hagerman | c461883 | 2019-10-07 12:24:36 -0400 | [diff] [blame] | 270 | 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] | 271 | |
| 272 | // Add the probe to the context to pass to all the services started |
| 273 | probeCtx := context.WithValue(ctx, probe.ProbeContextKey, p) |
| 274 | |
| 275 | // Start the core |
npujar | 1d86a52 | 2019-11-14 17:11:16 +0530 | [diff] [blame] | 276 | go rw.start(probeCtx, instanceID) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 277 | |
| 278 | code := waitForExit() |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 279 | logger.Infow("received-a-closing-signal", log.Fields{"code": code}) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 280 | |
| 281 | // Cleanup before leaving |
David K. Bainbridge | b4a9ab0 | 2019-09-20 15:12:16 -0700 | [diff] [blame] | 282 | rw.stop(probeCtx) |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 283 | |
| 284 | elapsed := time.Since(start) |
Girish Kumar | f56a468 | 2020-03-20 20:07:46 +0000 | [diff] [blame] | 285 | 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] | 286 | } |