Skip to content

Commit

Permalink
handle availability unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
mickmis committed Nov 10, 2023
1 parent 0488161 commit 1b4a3c5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/scd/store/cockroach/operational_intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
dsssql "github.com/interuss/dss/pkg/sql"
"github.com/interuss/stacktrace"
"github.com/jackc/pgtype"
"github.com/jackc/pgx/v4"
"github.com/pkg/errors"
)

var (
Expand Down Expand Up @@ -59,7 +61,7 @@ func (s *repo) fetchOperationalIntents(ctx context.Context, q dsssql.Queryable,

var payload []*scdmodels.OperationalIntent
pgCids := pgtype.Int8Array{}
ussAvailabilities := map[dssmodels.Manager]*scdmodels.UssAvailabilityStatus{}
ussAvailabilities := map[dssmodels.Manager]scdmodels.UssAvailabilityState{}
for rows.Next() {
var (
o = &scdmodels.OperationalIntent{}
Expand Down Expand Up @@ -88,25 +90,30 @@ func (s *repo) fetchOperationalIntents(ctx context.Context, q dsssql.Queryable,
}
o.OVN = scdmodels.NewOVNFromTime(updatedAt, o.ID.String())
o.SetCells(cids)
ussAvailabilities[o.Manager] = nil
ussAvailabilities[o.Manager] = scdmodels.UssAvailabilityStateUnknown
payload = append(payload, o)
}
if err := rows.Err(); err != nil {
return nil, stacktrace.Propagate(err, "Error in rows query result")
}

for manager := range ussAvailabilities {
if ussAvailabilities[manager], err = s.GetUssAvailability(ctx, manager); err != nil {
ussAvailability, err := s.GetUssAvailability(ctx, manager)
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
return nil, stacktrace.Propagate(err, "Error getting USS availability of %s", manager)
}

if ussAvailability != nil {
ussAvailabilities[manager] = ussAvailability.Availability
}
}

for _, op := range payload {
if err := s.populateOperationalIntentCells(ctx, q, op); err != nil {
return nil, stacktrace.Propagate(err, "Error populating cells for Operation %s", op.ID)
}

op.UssAvailability = ussAvailabilities[op.Manager].Availability
op.UssAvailability = ussAvailabilities[op.Manager]
}

return payload, nil
Expand Down

0 comments on commit 1b4a3c5

Please sign in to comment.