blob: dfa9fc870e8beb99ca4fc57efc7960657baacb16 [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 */
16// gRPC affinity router with active/active backends
17
18package main
19/* package main // import "github.com/opencord/voltha-go/arouter" */
20/* package main // import "github.com/opencord/voltha-go" */
21
22
23import (
24 "os"
25 "fmt"
26 slog "log"
27 "google.golang.org/grpc/grpclog"
28 "github.com/opencord/voltha-go/common/log"
29 "github.com/opencord/voltha-go/afrouter/afrouter"
30)
31
32func main() {
33
34
35 conf,err := afrouter.ParseCmd()
sslobodr5f0b5a32019-01-24 07:45:19 -050036 if err != nil {
sslobodr392ebd52019-01-18 12:41:49 -050037 fmt.Printf("Error: %v\n", err)
38 return
39 }
40
41 // Setup logging
42 if _, err := log.SetDefaultLogger(log.JSON, *conf.LogLevel, nil); err != nil {
43 log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
44 }
45
46 defer log.CleanUp()
47
48 // Parse the config file
49 err = conf.LoadConfig()
sslobodr5f0b5a32019-01-24 07:45:19 -050050 if err != nil {
sslobodr392ebd52019-01-18 12:41:49 -050051 log.Error(err)
52 return
53 }
54 log.With(log.Fields{"config":*conf}).Debug("Configuration loaded")
55
56 // Enable grpc logging
57 if *conf.GrpcLog {
58 grpclog.SetLogger(slog.New(os.Stderr, "grpc: ", slog.LstdFlags))
59 //grpclog.SetLoggerV2(lgr)
60 }
61
62 // Install the signal and error handlers.
63 afrouter.InitExitHandler()
64
65
66 // Create the affinity router proxy...
67 if ap,err := afrouter.NewArouterProxy(conf); err != nil {
68 log.Errorf("Failed to create the arouter proxy, exiting:%v",err)
69 return
70 // and start it.
71 // This function never returns unless an error
72 // occurs or a signal is caught.
73 } else if err := ap.ListenAndServe(); err != nil {
74 log.Errorf("Exiting on error %v", err)
75 }
76
77}