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