Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 36 additions & 31 deletions service/pilot/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/JustHumanz/Go-Simp/pkg/database"
"github.com/JustHumanz/Go-Simp/pkg/engine"
"github.com/JustHumanz/Go-Simp/pkg/metric"

"github.com/JustHumanz/Go-Simp/pkg/config"
Expand Down Expand Up @@ -145,6 +146,7 @@ type UnitMetadata struct {
Hostname string
Length int
AgencyList []string
LastUpdate time.Time
}

type Server struct {
Expand Down Expand Up @@ -202,6 +204,11 @@ func (s *Server) IsYtCheckerRunning() bool {
return false
}

func (u *UnitService) UpdateLastReport(toki int64) {
TimeUnit := time.Unix(toki, 0)
u.Metadata.LastUpdate = TimeUnit
}

//var ModuleWatcher = make(map[string]int)

func (s *Server) CheckUUID(UUID string) bool {
Expand Down Expand Up @@ -290,8 +297,9 @@ func (s *Server) RequestRunJobsOfService(ctx context.Context, in *ServiceMessage
1,
nil,
UnitMetadata{
Hostname: in.Hostname,
UUID: in.ServiceUUID,
Hostname: in.Hostname,
UUID: in.ServiceUUID,
LastUpdate: time.Now(),
},
})

Expand Down Expand Up @@ -533,37 +541,34 @@ func (s *Server) MetricReport(ctx context.Context, in *Metric) (*Message, error)
}, nil
}

func (s *Server) HeartBeat(in *ServiceMessage, stream PilotService_HeartBeatServer) error {
func (s *Server) HeartBeat(ctx context.Context, in *ServiceMessage) (*Message, error) {
Svc, Unit := GetServiceUnitFromUUID(&S, in.ServiceUUID)
if Svc != nil {
Unit.UpdateLastReport(in.Timestamp)
}

return &Message{
Message: "Cek",
}, nil

}

func RunHeartBeat(client PilotServiceClient, Service string, UUID string) {

for {
err := stream.Send(&Message{
Message: "Cek",
_, err := client.HeartBeat(context.Background(), &ServiceMessage{
Service: Service,
Message: "Bep Bob",
ServiceUUID: UUID,
Timestamp: time.Now().Unix(),
Hostname: engine.GetHostname(),
})
if err != nil {
log.WithFields(log.Fields{
"Service": in.Service,
"Messsage": in.Message,
"UUID": in.ServiceUUID,
}).Error(fmt.Sprintf("%s Removing unit if exist", err))
Svc := GetServiceFromUUID(&S, in.ServiceUUID)
if Svc != nil {
Svc.RemoveUnitFromDeadNode(in.ServiceUUID)
}
ReportDeadService(err.Error(), in.Service)
return err
ReportDeadService("Pilot down", Service)
log.Fatal(err)
}
time.Sleep(1 * time.Second)
}
}

func RunHeartBeat(client PilotServiceClient, Service string, UUID string) {
_, err := client.HeartBeat(context.Background(), &ServiceMessage{
Service: Service,
Message: "Bep Bob",
ServiceUUID: UUID,
})
if err != nil {
ReportDeadService("Pilot down", Service)
log.Fatal(err)
time.Sleep(1 * time.Second)
}
}

Expand Down Expand Up @@ -608,13 +613,13 @@ func BoolString(a bool) string {
return "false"
}

func GetServiceFromUUID(s *Server, UUID string) *Service {
func GetServiceUnitFromUUID(s *Server, UUID string) (*Service, *UnitService) {
for _, v := range s.Service {
for _, v2 := range v.Unit {
if v2.UUID == UUID {
return v
return v, v2
}
}
}
return nil
return nil, nil
}
100 changes: 55 additions & 45 deletions service/pilot/grpc/grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion service/pilot/grpc/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ message ServiceMessage {
string Service = 2;
string ServiceUUID = 3;
string Hostname = 4;
int64 Timestamp = 5;
}


Expand Down Expand Up @@ -45,7 +46,7 @@ service PilotService {
//Get agency payload for non scaling service only
rpc GetAgencyPayload(ServiceMessage) returns (AgencyPayload){}

rpc HeartBeat(ServiceMessage) returns (stream Message){}
rpc HeartBeat(ServiceMessage) returns (Message){}
rpc MetricReport(Metric) returns (Message){}
rpc ReportError(ServiceMessage) returns (Message){}
}
84 changes: 28 additions & 56 deletions service/pilot/grpc/grpc_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading