Add is applying config grpc command to check config status.
This commit is contained in:
		
							parent
							
								
									b0de9be277
								
							
						
					
					
						commit
						a6bb83947a
					
				@ -20,11 +20,20 @@ func (s *GRPCServer) SaveConfig(ctx context.Context, in *pb.Empty) (*pb.Empty, e
 | 
				
			|||||||
// Reload the configuration from the yaml file.
 | 
					// Reload the configuration from the yaml file.
 | 
				
			||||||
func (s *GRPCServer) ReloadConfig(ctx context.Context, in *pb.Empty) (*pb.Empty, error) {
 | 
					func (s *GRPCServer) ReloadConfig(ctx context.Context, in *pb.Empty) (*pb.Empty, error) {
 | 
				
			||||||
	log.Println("Reloading configurations.")
 | 
						log.Println("Reloading configurations.")
 | 
				
			||||||
 | 
						app.ApplyingConfig = true
 | 
				
			||||||
	config := ReadConfig()
 | 
						config := ReadConfig()
 | 
				
			||||||
	err := ApplyConfig(config)
 | 
						err := ApplyConfig(config)
 | 
				
			||||||
 | 
						app.ApplyingConfig = false
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		log.Println(err)
 | 
							log.Println(err)
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return new(pb.Empty), nil
 | 
						return new(pb.Empty), nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Check if the config is being applied.
 | 
				
			||||||
 | 
					func (s *GRPCServer) IsApplyingConfig(ctx context.Context, in *pb.Empty) (*pb.IsApplyingConfigReply, error) {
 | 
				
			||||||
 | 
						reply := new(pb.IsApplyingConfigReply)
 | 
				
			||||||
 | 
						reply.IsApplying = app.ApplyingConfig
 | 
				
			||||||
 | 
						return reply, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.go
									
									
									
									
									
								
							@ -6,7 +6,7 @@ const (
 | 
				
			|||||||
	serviceDisplayName = "Virtual VXLAN"
 | 
						serviceDisplayName = "Virtual VXLAN"
 | 
				
			||||||
	serviceVendor      = "com.mrgeckosmedia"
 | 
						serviceVendor      = "com.mrgeckosmedia"
 | 
				
			||||||
	serviceDescription = "Virtual VXLAN using TUN interfaces"
 | 
						serviceDescription = "Virtual VXLAN using TUN interfaces"
 | 
				
			||||||
	serviceVersion     = "0.1.8"
 | 
						serviceVersion     = "0.2"
 | 
				
			||||||
	defaultConfigFile  = "config.yaml"
 | 
						defaultConfigFile  = "config.yaml"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -24,6 +24,7 @@ type App struct {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	ControllerMac net.HardwareAddr
 | 
						ControllerMac net.HardwareAddr
 | 
				
			||||||
	grpcServer    *GRPCServer
 | 
						grpcServer    *GRPCServer
 | 
				
			||||||
 | 
						ApplyingConfig bool
 | 
				
			||||||
	Stop          chan struct{}
 | 
						Stop          chan struct{}
 | 
				
			||||||
	UpdateConfig  *UpdateConfig
 | 
						UpdateConfig  *UpdateConfig
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -41,6 +42,9 @@ func (a *ServerCmd) Run() error {
 | 
				
			|||||||
		config := ReadConfig()
 | 
							config := ReadConfig()
 | 
				
			||||||
		app.UpdateConfig = config.Update
 | 
							app.UpdateConfig = config.Update
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// So that other services interacting can confirm the config is applied prior to working.
 | 
				
			||||||
 | 
							app.ApplyingConfig = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Start the GRPC server for cli communication.
 | 
							// Start the GRPC server for cli communication.
 | 
				
			||||||
		_, err := NewGRPCServer(config.RPCPath)
 | 
							_, err := NewGRPCServer(config.RPCPath)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
@ -55,6 +59,9 @@ func (a *ServerCmd) Run() error {
 | 
				
			|||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				log.Println("An error occurred applying configuration:", err)
 | 
									log.Println("An error occurred applying configuration:", err)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								// Other services may now work.
 | 
				
			||||||
 | 
								app.ApplyingConfig = false
 | 
				
			||||||
		}()
 | 
							}()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -7,6 +7,7 @@ service vxlan {
 | 
				
			|||||||
    // Config commands.
 | 
					    // Config commands.
 | 
				
			||||||
    rpc SaveConfig (Empty) returns (Empty) {}
 | 
					    rpc SaveConfig (Empty) returns (Empty) {}
 | 
				
			||||||
    rpc ReloadConfig (Empty) returns (Empty) {}
 | 
					    rpc ReloadConfig (Empty) returns (Empty) {}
 | 
				
			||||||
 | 
					    rpc IsApplyingConfig (Empty) returns (IsApplyingConfigReply) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Listener commands.
 | 
					    // Listener commands.
 | 
				
			||||||
    rpc ListListeners (Empty) returns (ListListenersReply) {}
 | 
					    rpc ListListeners (Empty) returns (ListListenersReply) {}
 | 
				
			||||||
@ -39,6 +40,11 @@ service vxlan {
 | 
				
			|||||||
message Empty {
 | 
					message Empty {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Response to is applying config.
 | 
				
			||||||
 | 
					message IsApplyingConfigReply {
 | 
				
			||||||
 | 
					    bool isApplying = 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Listener messages.
 | 
					// Listener messages.
 | 
				
			||||||
message ListenerRequestWithName {
 | 
					message ListenerRequestWithName {
 | 
				
			||||||
    string name = 1;
 | 
					    string name = 1;
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
 | 
					// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
 | 
				
			||||||
// versions:
 | 
					// versions:
 | 
				
			||||||
// - protoc-gen-go-grpc v1.5.1
 | 
					// - protoc-gen-go-grpc v1.5.1
 | 
				
			||||||
// - protoc             v3.21.12
 | 
					// - protoc             v5.29.2
 | 
				
			||||||
// source: vxlan/vxlan.proto
 | 
					// source: vxlan/vxlan.proto
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package vxlan
 | 
					package vxlan
 | 
				
			||||||
@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion9
 | 
				
			|||||||
const (
 | 
					const (
 | 
				
			||||||
	Vxlan_SaveConfig_FullMethodName                 = "/vxlan.vxlan/SaveConfig"
 | 
						Vxlan_SaveConfig_FullMethodName                 = "/vxlan.vxlan/SaveConfig"
 | 
				
			||||||
	Vxlan_ReloadConfig_FullMethodName               = "/vxlan.vxlan/ReloadConfig"
 | 
						Vxlan_ReloadConfig_FullMethodName               = "/vxlan.vxlan/ReloadConfig"
 | 
				
			||||||
 | 
						Vxlan_IsApplyingConfig_FullMethodName           = "/vxlan.vxlan/IsApplyingConfig"
 | 
				
			||||||
	Vxlan_ListListeners_FullMethodName              = "/vxlan.vxlan/ListListeners"
 | 
						Vxlan_ListListeners_FullMethodName              = "/vxlan.vxlan/ListListeners"
 | 
				
			||||||
	Vxlan_AddListener_FullMethodName                = "/vxlan.vxlan/AddListener"
 | 
						Vxlan_AddListener_FullMethodName                = "/vxlan.vxlan/AddListener"
 | 
				
			||||||
	Vxlan_RemoveListener_FullMethodName             = "/vxlan.vxlan/RemoveListener"
 | 
						Vxlan_RemoveListener_FullMethodName             = "/vxlan.vxlan/RemoveListener"
 | 
				
			||||||
@ -52,6 +53,7 @@ type VxlanClient interface {
 | 
				
			|||||||
	// Config commands.
 | 
						// Config commands.
 | 
				
			||||||
	SaveConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
 | 
						SaveConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
 | 
				
			||||||
	ReloadConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
 | 
						ReloadConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
 | 
				
			||||||
 | 
						IsApplyingConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*IsApplyingConfigReply, error)
 | 
				
			||||||
	// Listener commands.
 | 
						// Listener commands.
 | 
				
			||||||
	ListListeners(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*ListListenersReply, error)
 | 
						ListListeners(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*ListListenersReply, error)
 | 
				
			||||||
	AddListener(ctx context.Context, in *Listener, opts ...grpc.CallOption) (*Empty, error)
 | 
						AddListener(ctx context.Context, in *Listener, opts ...grpc.CallOption) (*Empty, error)
 | 
				
			||||||
@ -106,6 +108,16 @@ func (c *vxlanClient) ReloadConfig(ctx context.Context, in *Empty, opts ...grpc.
 | 
				
			|||||||
	return out, nil
 | 
						return out, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (c *vxlanClient) IsApplyingConfig(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*IsApplyingConfigReply, error) {
 | 
				
			||||||
 | 
						cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
 | 
				
			||||||
 | 
						out := new(IsApplyingConfigReply)
 | 
				
			||||||
 | 
						err := c.cc.Invoke(ctx, Vxlan_IsApplyingConfig_FullMethodName, in, out, cOpts...)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return out, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (c *vxlanClient) ListListeners(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*ListListenersReply, error) {
 | 
					func (c *vxlanClient) ListListeners(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*ListListenersReply, error) {
 | 
				
			||||||
	cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
 | 
						cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
 | 
				
			||||||
	out := new(ListListenersReply)
 | 
						out := new(ListListenersReply)
 | 
				
			||||||
@ -333,6 +345,7 @@ type VxlanServer interface {
 | 
				
			|||||||
	// Config commands.
 | 
						// Config commands.
 | 
				
			||||||
	SaveConfig(context.Context, *Empty) (*Empty, error)
 | 
						SaveConfig(context.Context, *Empty) (*Empty, error)
 | 
				
			||||||
	ReloadConfig(context.Context, *Empty) (*Empty, error)
 | 
						ReloadConfig(context.Context, *Empty) (*Empty, error)
 | 
				
			||||||
 | 
						IsApplyingConfig(context.Context, *Empty) (*IsApplyingConfigReply, error)
 | 
				
			||||||
	// Listener commands.
 | 
						// Listener commands.
 | 
				
			||||||
	ListListeners(context.Context, *Empty) (*ListListenersReply, error)
 | 
						ListListeners(context.Context, *Empty) (*ListListenersReply, error)
 | 
				
			||||||
	AddListener(context.Context, *Listener) (*Empty, error)
 | 
						AddListener(context.Context, *Listener) (*Empty, error)
 | 
				
			||||||
@ -373,6 +386,9 @@ func (UnimplementedVxlanServer) SaveConfig(context.Context, *Empty) (*Empty, err
 | 
				
			|||||||
func (UnimplementedVxlanServer) ReloadConfig(context.Context, *Empty) (*Empty, error) {
 | 
					func (UnimplementedVxlanServer) ReloadConfig(context.Context, *Empty) (*Empty, error) {
 | 
				
			||||||
	return nil, status.Errorf(codes.Unimplemented, "method ReloadConfig not implemented")
 | 
						return nil, status.Errorf(codes.Unimplemented, "method ReloadConfig not implemented")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					func (UnimplementedVxlanServer) IsApplyingConfig(context.Context, *Empty) (*IsApplyingConfigReply, error) {
 | 
				
			||||||
 | 
						return nil, status.Errorf(codes.Unimplemented, "method IsApplyingConfig not implemented")
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
func (UnimplementedVxlanServer) ListListeners(context.Context, *Empty) (*ListListenersReply, error) {
 | 
					func (UnimplementedVxlanServer) ListListeners(context.Context, *Empty) (*ListListenersReply, error) {
 | 
				
			||||||
	return nil, status.Errorf(codes.Unimplemented, "method ListListeners not implemented")
 | 
						return nil, status.Errorf(codes.Unimplemented, "method ListListeners not implemented")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -496,6 +512,24 @@ func _Vxlan_ReloadConfig_Handler(srv interface{}, ctx context.Context, dec func(
 | 
				
			|||||||
	return interceptor(ctx, in, info, handler)
 | 
						return interceptor(ctx, in, info, handler)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _Vxlan_IsApplyingConfig_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 | 
				
			||||||
 | 
						in := new(Empty)
 | 
				
			||||||
 | 
						if err := dec(in); err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if interceptor == nil {
 | 
				
			||||||
 | 
							return srv.(VxlanServer).IsApplyingConfig(ctx, in)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						info := &grpc.UnaryServerInfo{
 | 
				
			||||||
 | 
							Server:     srv,
 | 
				
			||||||
 | 
							FullMethod: Vxlan_IsApplyingConfig_FullMethodName,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						handler := func(ctx context.Context, req interface{}) (interface{}, error) {
 | 
				
			||||||
 | 
							return srv.(VxlanServer).IsApplyingConfig(ctx, req.(*Empty))
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return interceptor(ctx, in, info, handler)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _Vxlan_ListListeners_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 | 
					func _Vxlan_ListListeners_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
 | 
				
			||||||
	in := new(Empty)
 | 
						in := new(Empty)
 | 
				
			||||||
	if err := dec(in); err != nil {
 | 
						if err := dec(in); err != nil {
 | 
				
			||||||
@ -907,6 +941,10 @@ var Vxlan_ServiceDesc = grpc.ServiceDesc{
 | 
				
			|||||||
			MethodName: "ReloadConfig",
 | 
								MethodName: "ReloadConfig",
 | 
				
			||||||
			Handler:    _Vxlan_ReloadConfig_Handler,
 | 
								Handler:    _Vxlan_ReloadConfig_Handler,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								MethodName: "IsApplyingConfig",
 | 
				
			||||||
 | 
								Handler:    _Vxlan_IsApplyingConfig_Handler,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			MethodName: "ListListeners",
 | 
								MethodName: "ListListeners",
 | 
				
			||||||
			Handler:    _Vxlan_ListListeners_Handler,
 | 
								Handler:    _Vxlan_ListListeners_Handler,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user