sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [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 | */ |
| 16 | // gRPC affinity router with active/active backends |
| 17 | |
| 18 | package main |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 19 | |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 20 | /* package main // import "github.com/opencord/voltha-go/arouter" */ |
| 21 | /* package main // import "github.com/opencord/voltha-go" */ |
| 22 | |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 23 | import ( |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 24 | "fmt" |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 25 | "github.com/opencord/voltha-go/afrouter/afrouter" |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 26 | "github.com/opencord/voltha-go/common/log" |
| 27 | "google.golang.org/grpc/grpclog" |
| 28 | slog "log" |
| 29 | "os" |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | func main() { |
| 33 | |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 34 | conf, err := afrouter.ParseCmd() |
sslobodr | 5f0b5a3 | 2019-01-24 07:45:19 -0500 | [diff] [blame] | 35 | if err != nil { |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 36 | fmt.Printf("Error: %v\n", err) |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | // Setup logging |
| 41 | if _, err := log.SetDefaultLogger(log.JSON, *conf.LogLevel, nil); err != nil { |
| 42 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 43 | } |
| 44 | |
| 45 | defer log.CleanUp() |
| 46 | |
| 47 | // Parse the config file |
| 48 | err = conf.LoadConfig() |
sslobodr | 5f0b5a3 | 2019-01-24 07:45:19 -0500 | [diff] [blame] | 49 | if err != nil { |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 50 | log.Error(err) |
| 51 | return |
| 52 | } |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 53 | log.With(log.Fields{"config": *conf}).Debug("Configuration loaded") |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 54 | |
| 55 | // Enable grpc logging |
| 56 | if *conf.GrpcLog { |
| 57 | grpclog.SetLogger(slog.New(os.Stderr, "grpc: ", slog.LstdFlags)) |
| 58 | //grpclog.SetLoggerV2(lgr) |
| 59 | } |
| 60 | |
| 61 | // Install the signal and error handlers. |
| 62 | afrouter.InitExitHandler() |
| 63 | |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 64 | // Create the affinity router proxy... |
Kent Hagerman | 0ab4cb2 | 2019-04-24 13:13:35 -0400 | [diff] [blame] | 65 | if ap, err := afrouter.NewArouterProxy(conf); err != nil { |
| 66 | log.Errorf("Failed to create the arouter proxy, exiting:%v", err) |
| 67 | return |
| 68 | // and start it. |
| 69 | // This function never returns unless an error |
| 70 | // occurs or a signal is caught. |
sslobodr | 392ebd5 | 2019-01-18 12:41:49 -0500 | [diff] [blame] | 71 | } else if err := ap.ListenAndServe(); err != nil { |
| 72 | log.Errorf("Exiting on error %v", err) |
| 73 | } |
| 74 | |
| 75 | } |