Exemplo n.º 1
0
// ServiceList implements GET /service/list
func (s *ServerRPC) ServiceList(ctx context.Context, req *types.ServiceListRequest) (*types.ServiceListResponse, error) {
	glog.V(3).Infof("ServiceList with request %s", req.String())

	services, err := s.daemon.GetServices(req.PodID)
	if err != nil {
		glog.Errorf("ServiceList error: %v", err)
		return nil, err
	}

	result := make([]*types.UserService, 0, len(services))

	for _, service := range services {
		var hosts []*types.UserServiceBackend
		// deep copy service.Hosts to rpc.Hosts
		for _, host := range service.Hosts {
			rpcHost := &types.UserServiceBackend{HostIP: host.HostIP, HostPort: int32(host.HostPort)}
			hosts = append(hosts, rpcHost)
		}
		result = append(result, &types.UserService{
			ServiceIP:   service.ServiceIP,
			Protocol:    service.Protocol,
			ServicePort: int32(service.ServicePort),
			Hosts:       hosts,
		})
	}

	return &types.ServiceListResponse{
		Services: result,
	}, nil
}
Exemplo n.º 2
0
// ServiceList implements GET /service/list
func (s *ServerRPC) ServiceList(ctx context.Context, req *types.ServiceListRequest) (*types.ServiceListResponse, error) {
	glog.V(3).Infof("ServiceList with request %s", req.String())

	services, err := s.daemon.GetServices(req.PodID)
	if err != nil {
		glog.Errorf("ServiceList error: %v", err)
		return nil, err
	}

	return &types.ServiceListResponse{
		Services: services,
	}, nil
}