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