2 Copyright 2018 Intel Corporation.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software
8 distributed under the License is distributed on an "AS IS" BASIS,
9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 See the License for the specific language governing permissions and
11 limitations under the License.
25 "github.com/gorilla/handlers"
26 "github.com/onap/multicloud-k8s/src/orchestrator/api"
27 "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/auth"
28 "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config"
29 contextDb "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/contextdb"
30 "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/db"
31 "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/rpc"
32 "github.com/onap/multicloud-k8s/src/orchestrator/pkg/module/controller"
37 rand.Seed(time.Now().UnixNano())
39 err := db.InitializeDatabaseConnection("mco")
41 log.Println("Unable to initialize database connection...")
43 log.Fatalln("Exiting...")
45 err = contextDb.InitializeContextDatabase()
47 log.Println("Unable to initialize database connection...")
49 log.Fatalln("Exiting...")
52 httpRouter := api.NewRouter(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
53 loggedRouter := handlers.LoggingHandler(os.Stdout, httpRouter)
54 log.Println("Starting Kubernetes Multicloud API")
56 httpServer := &http.Server{
57 Handler: loggedRouter,
58 Addr: ":" + config.GetConfiguration().ServicePort,
61 controller.NewControllerClient().InitControllers()
63 connectionsClose := make(chan struct{})
65 c := make(chan os.Signal, 1)
66 signal.Notify(c, os.Interrupt)
68 httpServer.Shutdown(context.Background())
70 close(connectionsClose)
73 tlsConfig, err := auth.GetTLSConfig("ca.cert", "server.cert", "server.key")
75 log.Println("Error Getting TLS Configuration. Starting without TLS...")
76 log.Fatal(httpServer.ListenAndServe())
78 httpServer.TLSConfig = tlsConfig
79 // empty strings because tlsconfig already has this information
80 err = httpServer.ListenAndServeTLS("", "")