blob: 65bb7df3bef00999f038b0f8afa3332423dc292c [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
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040019
sslobodr392ebd52019-01-18 12:41:49 -050020/* package main // import "github.com/opencord/voltha-go/arouter" */
21/* package main // import "github.com/opencord/voltha-go" */
22
sslobodr392ebd52019-01-18 12:41:49 -050023import (
sslobodr392ebd52019-01-18 12:41:49 -050024 "fmt"
sslobodr392ebd52019-01-18 12:41:49 -050025 "github.com/opencord/voltha-go/afrouter/afrouter"
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040026 "github.com/opencord/voltha-go/common/log"
27 "google.golang.org/grpc/grpclog"
28 slog "log"
29 "os"
sslobodr392ebd52019-01-18 12:41:49 -050030)
31
32func main() {
33
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040034 conf, err := afrouter.ParseCmd()
sslobodr5f0b5a32019-01-24 07:45:19 -050035 if err != nil {
sslobodr392ebd52019-01-18 12:41:49 -050036 fmt.Printf("Error: %v\n", err)
37 return
38 }
39
40 // Setup logging
41 if _, err := log.SetDefaultLogger(log.JSON, *conf.LogLevel, nil); err != nil {
42 log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
43 }
44
45 defer log.CleanUp()
46
47 // Parse the config file
48 err = conf.LoadConfig()
sslobodr5f0b5a32019-01-24 07:45:19 -050049 if err != nil {
sslobodr392ebd52019-01-18 12:41:49 -050050 log.Error(err)
51 return
52 }
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040053 log.With(log.Fields{"config": *conf}).Debug("Configuration loaded")
sslobodr392ebd52019-01-18 12:41:49 -050054
55 // Enable grpc logging
56 if *conf.GrpcLog {
57 grpclog.SetLogger(slog.New(os.Stderr, "grpc: ", slog.LstdFlags))
58 //grpclog.SetLoggerV2(lgr)
59 }
60
61 // Install the signal and error handlers.
62 afrouter.InitExitHandler()
63
sslobodr392ebd52019-01-18 12:41:49 -050064 // Create the affinity router proxy...
Kent Hagerman0ab4cb22019-04-24 13:13:35 -040065 if ap, err := afrouter.NewArouterProxy(conf); err != nil {
66 log.Errorf("Failed to create the arouter proxy, exiting:%v", err)
67 return
68 // and start it.
69 // This function never returns unless an error
70 // occurs or a signal is caught.
sslobodr392ebd52019-01-18 12:41:49 -050071 } else if err := ap.ListenAndServe(); err != nil {
72 log.Errorf("Exiting on error %v", err)
73 }
74
75}