blob: cfd028292975ae91535ebc505d91a54054549594 [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"
Scott Bakerb3a288a2019-10-02 14:57:29 -070024 _ "github.com/opencord/voltha-protos"
Scott Bakere7144bc2019-10-01 14:16:47 -070025 "google.golang.org/grpc/grpclog"
Scott Baker4989fe92019-10-09 17:03:06 -070026 "io/ioutil"
Scott Bakere7144bc2019-10-01 14:16:47 -070027 "os"
28)
29
30func 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 Windlass9f949c92019-10-10 06:39:24 +000039 if _, err := log.SetDefaultLogger(log.JSON, *conf.LogLevel, log.Fields{"instanceId": conf.InstanceID}); err != nil {
Scott Bakere7144bc2019-10-01 14:16:47 -070040 log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
41 }
42
Scott Baker4989fe92019-10-09 17:03:06 -070043 defer func() {
44 err := log.CleanUp()
45 if err != nil {
46 // Let's not use the logger to print the error message, since the
47 // logger could be in a bad state.
48 fmt.Fprintf(os.Stderr, "Failed to cleanup logger: %v", err)
49 }
50 }()
Scott Bakere7144bc2019-10-01 14:16:47 -070051
52 if *conf.DisplayVersionOnly {
53 fmt.Println("VOLTHA API Server (afrouter)")
54 fmt.Println(version.VersionInfo.String(" "))
55 return
56 }
57
58 // Parse the config file
59 err = conf.LoadConfig()
60 if err != nil {
61 log.Error(err)
62 return
63 }
64 log.With(log.Fields{"config": *conf}).Debug("Configuration loaded")
65
66 // Enable grpc logging
67 if *conf.GrpcLog {
Scott Baker4989fe92019-10-09 17:03:06 -070068 grpclog.SetLoggerV2(grpclog.NewLoggerV2(os.Stderr, ioutil.Discard, ioutil.Discard))
Scott Bakere7144bc2019-10-01 14:16:47 -070069 }
70
71 // Install the signal and error handlers.
Scott Baker4989fe92019-10-09 17:03:06 -070072 err = afrouter.InitExitHandler()
73 if err != nil {
74 log.Errorf("Failed to initialize exit handler, exiting: %v", err)
75 return
76 }
Scott Bakere7144bc2019-10-01 14:16:47 -070077
78 // Create the affinity router proxy...
79 if ap, err := afrouter.NewArouterProxy(conf); err != nil {
80 log.Errorf("Failed to create the arouter proxy, exiting:%v", err)
81 return
82 // and start it.
83 // This function never returns unless an error
84 // occurs or a signal is caught.
85 } else if err := ap.ListenAndServe(); err != nil {
86 log.Errorf("Exiting on error %v", err)
87 }
88
89}