Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCD] Populate uss_availability field of operational intents #971

Merged
merged 2 commits into from
Nov 14, 2023
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
27 changes: 14 additions & 13 deletions pkg/scd/models/operational_intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ func (s OperationalIntentState) IsValidInDSS() bool {
// OperationalIntent models an operational intent.
type OperationalIntent struct {
// Reference
ID dssmodels.ID
Manager dssmodels.Manager
Version VersionNumber
State OperationalIntentState
OVN OVN
StartTime *time.Time
EndTime *time.Time
USSBaseURL string
SubscriptionID dssmodels.ID
AltitudeLower *float32
AltitudeUpper *float32
Cells s2.CellUnion
ID dssmodels.ID
Manager dssmodels.Manager
UssAvailability UssAvailabilityState
Version VersionNumber
State OperationalIntentState
OVN OVN
StartTime *time.Time
EndTime *time.Time
USSBaseURL string
SubscriptionID dssmodels.ID
AltitudeLower *float32
AltitudeUpper *float32
Cells s2.CellUnion
}

func (s OperationalIntentState) String() string {
Expand All @@ -86,7 +87,7 @@ func (o *OperationalIntent) ToRest() *restapi.OperationalIntentReference {
UssBaseUrl: restapi.OperationalIntentUssBaseURL(o.USSBaseURL),
SubscriptionId: restapi.SubscriptionID(o.SubscriptionID.String()),
State: o.State.ToRest(),
UssAvailability: UssAvailabilityStateUnknown.ToRest(),
UssAvailability: o.UssAvailability.ToRest(),
}

if o.StartTime != nil {
Expand Down
17 changes: 17 additions & 0 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,6 +61,7 @@ func (s *repo) fetchOperationalIntents(ctx context.Context, q dsssql.Queryable,

var payload []*scdmodels.OperationalIntent
pgCids := pgtype.Int8Array{}
ussAvailabilities := map[dssmodels.Manager]scdmodels.UssAvailabilityState{}
for rows.Next() {
var (
o = &scdmodels.OperationalIntent{}
Expand Down Expand Up @@ -87,16 +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] = 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 {
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]
}

return payload, nil
Expand Down
Loading