blob: 56f2360078cb870f8e6a20cf77ea46ba525272ff [file] [log] [blame]
subhash kumar singh327d9db2021-09-30 19:07:18 +00001/*
2==================================================================================
3 Copyright (c) 2021 Samsung
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 platform project (RICP).
19==================================================================================
20*/
21package restful
22
23import (
subhash kumar singh327d9db2021-09-30 19:07:18 +000024 "log"
25 "os"
26
subhash kumar singh6017d6a2021-10-26 12:14:26 +000027 "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
subhash kumar singhf8e56192021-10-07 12:28:25 +000028 "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi"
29 "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations"
30 "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator"
31 "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/resthooks"
subhash kumar singh6017d6a2021-10-26 12:14:26 +000032 "github.com/go-openapi/loads"
33 "github.com/go-openapi/runtime/middleware"
subhash kumar singh327d9db2021-09-30 19:07:18 +000034)
35
36func NewRestful() *Restful {
37 r := &Restful{
38 rh: resthooks.NewResthook(),
39 }
40 r.api = r.setupHandler()
41 return r
42}
43
44func (r *Restful) setupHandler() *operations.A1API {
45 swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
46 if err != nil {
47 os.Exit(1)
48 }
49
50 api := operations.NewA1API(swaggerSpec)
51 api.A1MediatorA1ControllerGetAllPolicyTypesHandler = a1_mediator.A1ControllerGetAllPolicyTypesHandlerFunc(func(param a1_mediator.A1ControllerGetAllPolicyTypesParams) middleware.Responder {
subhash kumar singh6017d6a2021-10-26 12:14:26 +000052 a1.Logger.Debug("handler for get all all policy type")
subhash kumar singh327d9db2021-09-30 19:07:18 +000053 return a1_mediator.NewA1ControllerGetAllPolicyTypesOK().WithPayload(r.rh.GetAllPolicyType())
54 })
55 return api
56
57}
58
59func (r *Restful) Run() {
60
61 server := restapi.NewServer(r.api)
62 defer server.Shutdown()
63 server.Port = 8080
64 server.Host = "0.0.0.0"
65 if err := server.Serve(); err != nil {
66 log.Fatal(err.Error())
67 }
68}