Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [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 | |
| 17 | package main |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | "github.com/opencord/voltha-api-server/internal/pkg/afrouter" |
| 22 | "github.com/opencord/voltha-go/common/log" |
| 23 | "github.com/opencord/voltha-go/common/version" |
Scott Baker | b3a288a | 2019-10-02 14:57:29 -0700 | [diff] [blame] | 24 | _ "github.com/opencord/voltha-protos" |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 25 | "google.golang.org/grpc/grpclog" |
| 26 | slog "log" |
| 27 | "os" |
| 28 | ) |
| 29 | |
| 30 | func main() { |
| 31 | |
| 32 | conf, err := afrouter.ParseCmd() |
| 33 | if err != nil { |
| 34 | fmt.Printf("Error: %v\n", err) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | // Setup logging |
Hardik Windlass | 9f949c9 | 2019-10-10 06:39:24 +0000 | [diff] [blame] | 39 | if _, err := log.SetDefaultLogger(log.JSON, *conf.LogLevel, log.Fields{"instanceId": conf.InstanceID}); err != nil { |
Scott Baker | e7144bc | 2019-10-01 14:16:47 -0700 | [diff] [blame] | 40 | log.With(log.Fields{"error": err}).Fatal("Cannot setup logging") |
| 41 | } |
| 42 | |
| 43 | defer log.CleanUp() |
| 44 | |
| 45 | if *conf.DisplayVersionOnly { |
| 46 | fmt.Println("VOLTHA API Server (afrouter)") |
| 47 | fmt.Println(version.VersionInfo.String(" ")) |
| 48 | return |
| 49 | } |
| 50 | |
| 51 | // Parse the config file |
| 52 | err = conf.LoadConfig() |
| 53 | if err != nil { |
| 54 | log.Error(err) |
| 55 | return |
| 56 | } |
| 57 | log.With(log.Fields{"config": *conf}).Debug("Configuration loaded") |
| 58 | |
| 59 | // Enable grpc logging |
| 60 | if *conf.GrpcLog { |
| 61 | grpclog.SetLogger(slog.New(os.Stderr, "grpc: ", slog.LstdFlags)) |
| 62 | //grpclog.SetLoggerV2(lgr) |
| 63 | } |
| 64 | |
| 65 | // Install the signal and error handlers. |
| 66 | afrouter.InitExitHandler() |
| 67 | |
| 68 | // Create the affinity router proxy... |
| 69 | if ap, err := afrouter.NewArouterProxy(conf); err != nil { |
| 70 | log.Errorf("Failed to create the arouter proxy, exiting:%v", err) |
| 71 | return |
| 72 | // and start it. |
| 73 | // This function never returns unless an error |
| 74 | // occurs or a signal is caught. |
| 75 | } else if err := ap.ListenAndServe(); err != nil { |
| 76 | log.Errorf("Exiting on error %v", err) |
| 77 | } |
| 78 | |
| 79 | } |