blob: 952fc7ba75c557b2a311f56ba832628a31473b64 [file] [log] [blame]
Scott Bakere7144bc2019-10-01 14:16:47 -07001/*
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
17package main
18
19import (
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"
24 "google.golang.org/grpc/grpclog"
25 slog "log"
26 "os"
27)
28
29func main() {
30
31 conf, err := afrouter.ParseCmd()
32 if err != nil {
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
44 if *conf.DisplayVersionOnly {
45 fmt.Println("VOLTHA API Server (afrouter)")
46 fmt.Println(version.VersionInfo.String(" "))
47 return
48 }
49
50 // Parse the config file
51 err = conf.LoadConfig()
52 if err != nil {
53 log.Error(err)
54 return
55 }
56 log.With(log.Fields{"config": *conf}).Debug("Configuration loaded")
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
67 // Create the affinity router proxy...
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.
74 } else if err := ap.ListenAndServe(); err != nil {
75 log.Errorf("Exiting on error %v", err)
76 }
77
78}