Newer
Older
package server
import (
"context"
"time"
subpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/subscriptionmanagement"
"code.fbi.h-da.de/danet/gosdn/controller/nucleus"
)
// SubManagementServer represents a SubsriptionManagementServer.
type SubManagementServer struct {
subpb.UnimplementedSubscriptionManagementServiceServer
networkElementWatchter *nucleus.NetworkElementWatcher
}
// NewSubManagementServer returns a new SubManagementServer.
func NewSubManagementServer(networkElementWatchter *nucleus.NetworkElementWatcher) *SubManagementServer {
return &SubManagementServer{
networkElementWatchter: networkElementWatchter,
}
}
// ResetAllSubscriptions stops all running subscriptions and restarts them the same way they ran before.
func (s *SubManagementServer) ResetAllSubscriptions(ctx context.Context, request *subpb.ResetAllSubscriptionsRequest) (*subpb.ResetAllSubscriptionsResponse, error) {
subscriptions := s.networkElementWatchter.GetAllSubscriptionInformations()
s.networkElementWatchter.StopAndRemoveAllNetworkElementSubscriptions()
s.networkElementWatchter.SubscribeToNetworkElements(subscriptions)
return &subpb.ResetAllSubscriptionsResponse{
Timestamp: time.Now().UnixNano(),
}, nil
}
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// GetAll returns information about all running subscriptions.
func (s *SubManagementServer) GetAll(ctx context.Context, request *subpb.GetAllRequest) (*subpb.GetAllResponse, error) {
subInfos := s.networkElementWatchter.GetAllSubscriptionInformations()
subInfosToReturn := make([]*subpb.Subscription, 0)
for _, info := range subInfos {
tmpPaths := make([]*subpb.Path, 0)
for _, path := range info.Opts.Paths {
tmpPaths = append(tmpPaths, &subpb.Path{
Elem: path,
})
}
subInfosToReturn = append(subInfosToReturn, &subpb.Subscription{
Subid: info.SubID,
Pid: info.PndID,
Mneid: info.MneID,
MneName: info.MneName,
Paths: tmpPaths,
SubscribeOptions: &subpb.SubscribeOptions{
GnmiMode: info.Opts.Mode,
GnmiStreamMode: info.Opts.StreamMode,
SampleInterval: info.Opts.SampleInterval,
},
})
}
return &subpb.GetAllResponse{
Timestamp: time.Now().UnixNano(),
Subscriptions: subInfosToReturn,
}, nil
}