2 * Copyright (C) 2018 "IoT.bzh"
3 * Author Sebastien Douheret <sebastien@iot.bzh>
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 "gerrit.automotivelinux.org/gerrit/src/xds/xds-agent.git/lib/xaapiv1"
25 common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git"
26 "github.com/gin-gonic/gin"
29 // getServersList Return the list of XDS Servers
30 func (s *APIService) getServersList(c *gin.Context) {
32 defer confMut.Unlock()
34 svrList := []xaapiv1.ServerCfg{}
35 for _, svr := range s.xdsServers {
36 svrList = append(svrList, svr.GetConfig())
39 c.JSON(http.StatusOK, svrList)
42 // getServer Return info of a XDS Servers
43 func (s *APIService) getServer(c *gin.Context) {
45 id := s.ParamGetIndex(c)
47 common.APIError(c, "invalid parameter, id must be set")
52 defer confMut.Unlock()
54 svr := s.GetXdsServerFromURLIndex(id)
56 common.APIError(c, "unknown id")
60 c.JSON(http.StatusOK, svr.GetConfig())
63 // reconnectServer Force reconnection of a XDS Server
64 func (s *APIService) reconnectServer(c *gin.Context) {
66 id := s.ParamGetIndex(c)
68 common.APIError(c, "invalid parameter, id must be set")
72 svr := s.GetXdsServerFromURLIndex(id)
74 common.APIError(c, "unknown id")
78 s.Log.Debugf("Reconnect XDS Server id %v", svr.ID)
80 if err := svr.Close(); err != nil {
81 common.APIError(c, err.Error())
85 time.Sleep(time.Millisecond * 100)
87 if err := svr.Connect(); err != nil {
88 common.APIError(c, err.Error())
92 c.JSON(http.StatusOK, svr.GetConfig())