Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fd4bbaa
Changes for adding OSUpdateRun resource in inventory
SushilLakra Jun 7, 2025
324d183
Merge branch 'main' into itep-67234-changes-br
SushilLakra Jun 7, 2025
383d006
Added implementation to API handlers in APIv2 for OSUpdateRun
SushilLakra Jun 10, 2025
34ffaaf
Changes for adding OSUpdateRun resource in inventory
SushilLakra Jun 7, 2025
31dc9c5
Added implementation to API handlers in APIv2 for OSUpdateRun
SushilLakra Jun 10, 2025
dbb6394
Fix for review comments in apiv2 + chnages for resolving rebase confl…
SushilLakra Jun 12, 2025
f298daa
fixed merge conflicts
SushilLakra Jun 12, 2025
03ad15f
Merge branch 'main' into api-handler-impl-osupdaterun-br
SushilLakra Jun 12, 2025
71d2bde
fixed merge conflicts - 2
SushilLakra Jun 12, 2025
ac5c5f1
Merge branch 'main' into api-handler-impl-osupdaterun-br
SushilLakra Jun 13, 2025
74bdcbb
Ypdated version in VERSION file
SushilLakra Jun 13, 2025
dff3058
Merge branch 'api-handler-impl-osupdaterun-br' of https://github.com/…
SushilLakra Jun 13, 2025
33bc89b
fix for review comment to use correct time format for timestamp strin…
SushilLakra Jun 13, 2025
2b72d48
Merge branch 'main' into api-handler-impl-osupdaterun-br
SushilLakra Jun 13, 2025
061d3d6
fixed go-lint errors
SushilLakra Jun 13, 2025
15da55f
Merge branch 'api-handler-impl-osupdaterun-br' of https://github.com/…
SushilLakra Jun 13, 2025
dead7c5
Merge branch 'main' into api-handler-impl-osupdaterun-br
SushilLakra Jun 13, 2025
25f4d0f
changed version
SushilLakra Jun 13, 2025
8497d2b
updated build error observed
SushilLakra Jun 13, 2025
17274b7
Update apiv2/VERSION
SushilLakra Jun 13, 2025
918b05f
fixed further review comments
SushilLakra Jun 13, 2025
365f12a
Merge branch 'main' into api-handler-impl-osupdaterun-br
SushilLakra Jun 13, 2025
87c182a
fixed further review comments - 2
SushilLakra Jun 13, 2025
9591212
Merge branch 'api-handler-impl-osupdaterun-br' of https://github.com/…
SushilLakra Jun 13, 2025
0740104
fixed further review comments - 3
SushilLakra Jun 13, 2025
4b89061
Merge branch 'main' into api-handler-impl-osupdaterun-br
SushilLakra Jun 13, 2025
25640d9
fixed further review comments - 4
SushilLakra Jun 13, 2025
f9aea6d
Merge branch 'api-handler-impl-osupdaterun-br' of https://github.com/…
SushilLakra Jun 13, 2025
8655798
fixed further review comments - 5
SushilLakra Jun 13, 2025
e2869f3
Merge branch 'main' into api-handler-impl-osupdaterun-br
daniele-moro Jun 13, 2025
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
151 changes: 142 additions & 9 deletions apiv2/internal/server/os_update_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,164 @@ package server

import (
"context"
"time"

"google.golang.org/grpc/codes"
"google.golang.org/protobuf/types/known/timestamppb"

computev1 "github.com/open-edge-platform/infra-core/apiv2/v2/internal/pbapi/resources/compute/v1"
statusv1 "github.com/open-edge-platform/infra-core/apiv2/v2/internal/pbapi/resources/status/v1"
restv1 "github.com/open-edge-platform/infra-core/apiv2/v2/internal/pbapi/services/v1"
inv_computev1 "github.com/open-edge-platform/infra-core/inventory/v2/pkg/api/compute/v1"
inventory "github.com/open-edge-platform/infra-core/inventory/v2/pkg/api/inventory/v1"
"github.com/open-edge-platform/infra-core/inventory/v2/pkg/errors"
"github.com/open-edge-platform/infra-core/inventory/v2/pkg/validator"
)

func (is *InventorygRPCServer) ListOSUpdateRun(_ context.Context, _ *restv1.ListOSUpdateRunRequest) (
func parseTimestamp(ts string) (*timestamppb.Timestamp, error) {
if ts == "" {
zlog.Warn().Msgf("timestamp is empty")
return nil, errors.Errorfc(
codes.InvalidArgument, "timestamp is empty",
)
}
parsedTime, err := time.Parse(ISO8601TimeFormat, ts)
if err != nil {
zlog.Warn().Err(err).Msgf("Failed to parse timestamp: %s", ts)
return nil, err
}
return timestamppb.New(parsedTime), nil
}

func fromInvOSUpdateRunResource(invOSUpdateRunResource *inv_computev1.OSUpdateRunResource) (*computev1.OSUpdateRun, error) {
if invOSUpdateRunResource == nil {
return &computev1.OSUpdateRun{}, nil
}
instance, err := fromInvInstance(invOSUpdateRunResource.GetInstance())
if err != nil {
zlog.Warn().Err(err).Msgf("Failed to get the inventory instance edge from OS Update Run resource")
return nil, err
}
invStatusTimestamp, err := parseTimestamp(invOSUpdateRunResource.GetStatusTimestamp())
if err != nil && err.Error() != errors.Errorfc(codes.InvalidArgument, "timestamp is empty").Error() {
zlog.Warn().Msgf("Status timestamp parsing failed for OS Update Run resource: %s", invOSUpdateRunResource.GetResourceId())
return nil, errors.Errorfc(
codes.InvalidArgument, "status timestamp parsing failed for OS Update Run resource: %s",
invOSUpdateRunResource.GetResourceId(),
)
}
invStartTime, err := parseTimestamp(invOSUpdateRunResource.GetStartTime())
if err != nil && err.Error() != errors.Errorfc(codes.InvalidArgument, "timestamp is empty").Error() {
zlog.Warn().Msgf("Start time parsing failed for OS Update Run resource: %s", invOSUpdateRunResource.GetResourceId())
return nil, errors.Errorfc(
codes.InvalidArgument, "start time parsing failed for OS Update Run resource: %s",
invOSUpdateRunResource.GetResourceId(),
)
}
invEndTime, err := parseTimestamp(invOSUpdateRunResource.GetEndTime())
if err != nil && err.Error() != errors.Errorfc(codes.InvalidArgument, "timestamp is empty").Error() {
zlog.Warn().Msgf("End time parsing failed for OS Update Run resource: %s", invOSUpdateRunResource.GetResourceId())
return nil, errors.Errorfc(
codes.InvalidArgument, "end time parsing failed for OS Update Run resource: %s",
invOSUpdateRunResource.GetResourceId(),
)
}

osUpdateRunResource := &computev1.OSUpdateRun{
ResourceId: invOSUpdateRunResource.GetResourceId(),
Name: invOSUpdateRunResource.GetName(),
Description: invOSUpdateRunResource.GetDescription(),
AppliedPolicy: fromInvOSUpdatePolicy(invOSUpdateRunResource.GetAppliedPolicy()),
Instance: instance,
StatusIndicator: statusv1.StatusIndication(invOSUpdateRunResource.GetStatusIndicator()),
Status: invOSUpdateRunResource.GetStatus(),
StatusDetails: invOSUpdateRunResource.GetStatusDetails(),
StatusTimestamp: invStatusTimestamp,
StartTime: invStartTime,
EndTime: invEndTime,
Timestamps: GrpcToOpenAPITimestamps(invOSUpdateRunResource),
}
return osUpdateRunResource, nil
}

func (is *InventorygRPCServer) ListOSUpdateRun(ctx context.Context, req *restv1.ListOSUpdateRunRequest) (
*restv1.ListOSUpdateRunResponse, error,
) {
// TODO implement me
return nil, errors.Errorfc(codes.Unimplemented, "ListOSUpdateRun not implemented")
zlog.Debug().Msg("ListOSUpdateRunResources")

filter := &inventory.ResourceFilter{
Resource: &inventory.Resource{
Resource: &inventory.Resource_OsUpdateRun{
OsUpdateRun: &inv_computev1.OSUpdateRunResource{},
},
},
Offset: req.GetOffset(),
Limit: req.GetPageSize(),
OrderBy: req.GetOrderBy(),
Filter: req.GetFilter(),
}
if err := validator.ValidateMessage(filter); err != nil {
zlog.InfraSec().InfraErr(err).Msg("failed to validate query params")
return nil, errors.Wrap(err)
}
invResp, err := is.InvClient.List(ctx, filter)
if err != nil {
zlog.InfraErr(err).Msg("Failed to list OS resources from inventory")
return nil, errors.Wrap(err)
}

osUpdateRunResources := []*computev1.OSUpdateRun{}
for _, invRes := range invResp.GetResources() {
osUpdateRunResource, err := fromInvOSUpdateRunResource(invRes.GetResource().GetOsUpdateRun())
if err != nil {
zlog.InfraErr(err).Msgf("Failed to convert inventory OS Update Run resource %s",
invRes.GetResource().GetOsUpdateRun().GetResourceId())
return nil, errors.Wrap(err)
}
osUpdateRunResources = append(osUpdateRunResources, osUpdateRunResource)
}

resp := &restv1.ListOSUpdateRunResponse{
OsUpdateRuns: osUpdateRunResources,
TotalElements: invResp.GetTotalElements(),
HasNext: invResp.GetHasNext(),
}
zlog.Debug().Msgf("Listed %s", resp)
return resp, nil
}

func (is *InventorygRPCServer) GetOSUpdateRun(_ context.Context, _ *restv1.GetOSUpdateRunRequest) (
func (is *InventorygRPCServer) GetOSUpdateRun(ctx context.Context, req *restv1.GetOSUpdateRunRequest) (
*computev1.OSUpdateRun, error,
) {
// TODO implement me
return nil, errors.Errorfc(codes.Unimplemented, "GetOSUpdateRun not implemented")
zlog.Debug().Msg("GetOSUpdateRunResource")

invResp, err := is.InvClient.Get(ctx, req.GetResourceId())
if err != nil {
zlog.InfraErr(err).Msg("Failed to get OS Update Run resource from inventory")
return nil, errors.Wrap(err)
}

invOSUpdateRunResource := invResp.GetResource().GetOsUpdateRun()
osUpdateRunResource, err := fromInvOSUpdateRunResource(invOSUpdateRunResource)
if err != nil {
zlog.InfraErr(err).Msgf("Failed to convert inventory OS Update Run resource %s", invOSUpdateRunResource.GetResourceId())
return nil, errors.Wrap(err)
}

zlog.Debug().Msgf("Got %s", osUpdateRunResource)
return osUpdateRunResource, nil
}

func (is *InventorygRPCServer) DeleteOSUpdateRun(_ context.Context, _ *restv1.DeleteOSUpdateRunRequest) (
func (is *InventorygRPCServer) DeleteOSUpdateRun(ctx context.Context, req *restv1.DeleteOSUpdateRunRequest) (
*restv1.DeleteOSUpdateRunResponse, error,
) {
// TODO implement me
return nil, errors.Errorfc(codes.Unimplemented, "DeleteOSUpdateRun not implemented")
zlog.Debug().Msg("DeleteOSUpdateRunResource")

_, err := is.InvClient.Delete(ctx, req.GetResourceId())
if err != nil {
zlog.InfraErr(err).Msg("Failed to delete OS Update Run resource from inventory")
return nil, errors.Wrap(err)
}
zlog.Debug().Msgf("Deleted %s", req.GetResourceId())
return &restv1.DeleteOSUpdateRunResponse{}, nil
}
Loading