2 * Copyright (C) 2017-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.
23 common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git"
24 "github.com/gin-gonic/gin"
27 // getSupervisorTopo : return current AGL daemons topology using supervisor
28 func (s *APIService) getSupervisorTopo(c *gin.Context) {
30 xdspvr, err := s._initXdsSupervisor()
32 common.APIError(c, err.Error())
36 var res XdsSuperVReply
37 if err = xdspvr.GetTopo(&res); err != nil {
38 common.APIError(c, err.Error())
42 if res.Request.Status != "success" {
43 common.APIError(c, res.Request.Info)
47 c.JSON(http.StatusOK, res.Response)
50 // startSupervisor : resquest to supervisor to start tracing
51 func (s *APIService) startSupervisor(c *gin.Context) {
53 xdspvr, err := s._initXdsSupervisor()
55 common.APIError(c, err.Error())
59 var cfg XdsSuperVTraceConfig
60 if c.BindJSON(&cfg) != nil {
61 common.APIError(c, "Invalid config argument")
64 s.Log.Debugf("Start Supervisor cfgArg %v\n", cfg)
66 var res XdsSuperVReply
67 if err = xdspvr.StartTrace(cfg, &res); err != nil {
68 common.APIError(c, err.Error())
72 if res.Request.Status != "success" {
73 common.APIError(c, res.Request.Info)
77 c.JSON(http.StatusOK, res.Response)
80 // stopSupervisor : resquest to supervisor to stop tracing
81 func (s *APIService) stopSupervisor(c *gin.Context) {
83 xdspvr, err := s._initXdsSupervisor()
85 common.APIError(c, err.Error())
89 var res XdsSuperVReply
90 if err = xdspvr.StopTrace(&res); err != nil {
91 common.APIError(c, err.Error())
95 if res.Request.Status != "success" {
96 common.APIError(c, res.Request.Info)
100 c.JSON(http.StatusOK, res.Response)
103 // _initXdsSupervisor .
104 func (s *APIService) _initXdsSupervisor() (*XdsSupervisor, error) {
106 if s.XdsSupervisor == nil {
107 xs := NewXdsSupervisor(s.Context)
108 if err := xs.Connect(); err != nil {
113 return s.XdsSupervisor, nil