blob: 10ee87367b74b089fbc5792549682a656597bb57 [file] [log] [blame]
sslobodr392ebd52019-01-18 12:41:49 -05001/*
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 */
sslobodr392ebd52019-01-18 12:41:49 -050016
17package main
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040018
sslobodr392ebd52019-01-18 12:41:49 -050019import (
sslobodr392ebd52019-01-18 12:41:49 -050020 "fmt"
sslobodr392ebd52019-01-18 12:41:49 -050021 "github.com/opencord/voltha-go/afrouter/afrouter"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040022 "github.com/opencord/voltha-go/common/log"
David K. Bainbridgef430cd52019-05-28 15:00:35 -070023 "github.com/opencord/voltha-go/common/version"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040024 "google.golang.org/grpc/grpclog"
25 slog "log"
26 "os"
sslobodr392ebd52019-01-18 12:41:49 -050027)
28
29func main() {
30
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040031 conf, err := afrouter.ParseCmd()
sslobodr5f0b5a32019-01-24 07:45:19 -050032 if err != nil {
sslobodr392ebd52019-01-18 12:41:49 -050033 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. Bainbridgef430cd52019-05-28 15:00:35 -070044 if *conf.DisplayVersionOnly {
45 fmt.Println("VOLTHA API Server (afrouter)")
46 fmt.Println(version.VersionInfo.String(" "))
47 return
48 }
49
sslobodr392ebd52019-01-18 12:41:49 -050050 // Parse the config file
51 err = conf.LoadConfig()
sslobodr5f0b5a32019-01-24 07:45:19 -050052 if err != nil {
sslobodr392ebd52019-01-18 12:41:49 -050053 log.Error(err)
54 return
55 }
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040056 log.With(log.Fields{"config": *conf}).Debug("Configuration loaded")
sslobodr392ebd52019-01-18 12:41:49 -050057
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
sslobodr392ebd52019-01-18 12:41:49 -050067 // Create the affinity router proxy...
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040068 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.
sslobodr392ebd52019-01-18 12:41:49 -050074 } else if err := ap.ListenAndServe(); err != nil {
75 log.Errorf("Exiting on error %v", err)
76 }
77
78}