Skip to content

Commit 4241647

Browse files
authored
expose some methods (#479)
Signed-off-by: Wei Liu <liuweixa@redhat.com>
1 parent 5382130 commit 4241647

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

cmd/maestro/server/event_server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (s *MessageQueueEventServer) startSubscription(ctx context.Context) {
105105
}
106106

107107
// handle the resource status update according status update type
108-
if err := handleStatusUpdate(subCtx, resource, s.resourceService, s.statusEventService); err != nil {
108+
if err := HandleStatusUpdate(subCtx, resource, s.resourceService, s.statusEventService); err != nil {
109109
return fmt.Errorf("failed to handle resource status update %s: %s", resource.ID, err.Error())
110110
}
111111

@@ -150,14 +150,14 @@ func (s *MessageQueueEventServer) PredicateEvent(ctx context.Context, eventID st
150150
return true, nil
151151
}
152152

153-
// handleStatusUpdate processes the resource status update from the agent.
153+
// HandleStatusUpdate processes the resource status update from the agent.
154154
// The resource argument contains the updated status.
155155
// The function performs the following steps:
156156
// 1. Verifies if the resource is still in the Maestro server and checks if the consumer name matches.
157157
// 2. Retrieves the resource from Maestro and fills back the work metadata from the spec event to the status event.
158158
// 3. Checks if the resource has been deleted from the agent. If so, creates a status event and deletes the resource from Maestro;
159159
// otherwise, updates the resource status and creates a status event.
160-
func handleStatusUpdate(ctx context.Context, resource *api.Resource, resourceService services.ResourceService, statusEventService services.StatusEventService) error {
160+
func HandleStatusUpdate(ctx context.Context, resource *api.Resource, resourceService services.ResourceService, statusEventService services.StatusEventService) error {
161161
logger := klog.FromContext(ctx)
162162
logger.Info("handle resource status update by the current instance")
163163

cmd/maestro/server/grpc_broker.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *GRPCBrokerService) List(ctx context.Context, listOpts types.ListOptions
5555

5656
evts := []*ce.Event{}
5757
for _, res := range resources {
58-
evt, err := encodeResourceSpec(res, types.ResyncResponseAction)
58+
evt, err := EncodeResourceSpec(res, types.ResyncResponseAction)
5959
if err != nil {
6060
return nil, kubeerrors.NewInternalError(err)
6161
}
@@ -68,13 +68,13 @@ func (s *GRPCBrokerService) List(ctx context.Context, listOpts types.ListOptions
6868
// HandleStatusUpdate processes the resource status update from the agent.
6969
func (s *GRPCBrokerService) HandleStatusUpdate(ctx context.Context, evt *ce.Event) error {
7070
// decode the cloudevent data as resource with status
71-
resource, err := decodeResourceStatus(evt)
71+
resource, err := DecodeResourceStatus(evt)
7272
if err != nil {
7373
return fmt.Errorf("failed to decode cloudevent: %v", err)
7474
}
7575

7676
// handle the resource status update according status update type
77-
if err := handleStatusUpdate(ctx, resource, s.resourceService, s.statusEventService); err != nil {
77+
if err := HandleStatusUpdate(ctx, resource, s.resourceService, s.statusEventService); err != nil {
7878
return fmt.Errorf("failed to handle resource status update %s: %s", resource.ID, err.Error())
7979
}
8080

@@ -252,7 +252,7 @@ func (s *GRPCBroker) Get(ctx context.Context, resourceID string, action types.Ev
252252
return nil, kubeerrors.NewInternalError(err)
253253
}
254254

255-
return encodeResourceSpec(resource, action)
255+
return EncodeResourceSpec(resource, action)
256256
}
257257

258258
// On StatusUpdate will be called on each new status event inserted into db.
@@ -306,14 +306,14 @@ func (s *GRPCBroker) PredicateEvent(ctx context.Context, eventID string) (bool,
306306
return s.eventServer.Subscribers().Has(resource.ConsumerName), nil
307307
}
308308

309-
// decodeResourceStatus translates a CloudEvent into a resource containing the status JSON map.
310-
func decodeResourceStatus(evt *ce.Event) (*api.Resource, error) {
309+
// DecodeResourceStatus translates a CloudEvent into a resource containing the status JSON map.
310+
func DecodeResourceStatus(evt *ce.Event) (*api.Resource, error) {
311311
codec := cloudevents.NewCodec(source)
312312
return codec.Decode(evt)
313313
}
314314

315-
// encodeResourceSpec translates a resource spec JSON map into a CloudEvent.
316-
func encodeResourceSpec(resource *api.Resource, action types.EventAction) (*ce.Event, error) {
315+
// EncodeResourceSpec translates a resource spec JSON map into a CloudEvent.
316+
func EncodeResourceSpec(resource *api.Resource, action types.EventAction) (*ce.Event, error) {
317317
eventType := types.CloudEventsType{
318318
CloudEventsDataType: workpayload.ManifestBundleEventDataType,
319319
SubResource: types.SubResourceSpec,

0 commit comments

Comments
 (0)