database and admin API updates for queue things

This commit is contained in:
Amber Brown 2024-11-07 16:22:06 +11:00
Родитель 75e96909a0
Коммит 0cb90d3c08
5 изменённых файлов: 29 добавлений и 9 удалений

Просмотреть файл

@ -19,6 +19,8 @@ type MaintenanceManifest struct {
// The ID for the resource.
ID string `json:"id,omitempty"`
ClusterResourceID string `json:"clusterResourceID,omitempty"`
State MaintenanceManifestState `json:"state,omitempty"`
StatusText string `json:"statusText,omitempty"`

Просмотреть файл

@ -9,10 +9,16 @@ import (
type maintenanceManifestConverter struct{}
func (m maintenanceManifestConverter) ToExternal(d *api.MaintenanceManifestDocument) interface{} {
func (m maintenanceManifestConverter) ToExternal(d *api.MaintenanceManifestDocument, clusterNamespaced bool) interface{} {
clusterResourceID := ""
if !clusterNamespaced {
clusterResourceID = d.ClusterResourceID
}
return &MaintenanceManifest{
ID: d.ID,
ClusterResourceID: clusterResourceID,
State: MaintenanceManifestState(d.MaintenanceManifest.State),
StatusText: d.MaintenanceManifest.StatusText,
@ -24,14 +30,14 @@ func (m maintenanceManifestConverter) ToExternal(d *api.MaintenanceManifestDocum
}
}
func (m maintenanceManifestConverter) ToExternalList(docs []*api.MaintenanceManifestDocument, nextLink string) interface{} {
func (m maintenanceManifestConverter) ToExternalList(docs []*api.MaintenanceManifestDocument, nextLink string, clusterNamespaced bool) interface{} {
l := &MaintenanceManifestList{
MaintenanceManifests: make([]*MaintenanceManifest, 0, len(docs)),
NextLink: nextLink,
}
for _, doc := range docs {
l.MaintenanceManifests = append(l.MaintenanceManifests, m.ToExternal(doc).(*MaintenanceManifest))
l.MaintenanceManifests = append(l.MaintenanceManifests, m.ToExternal(doc, clusterNamespaced).(*MaintenanceManifest))
}
return l

Просмотреть файл

@ -12,13 +12,13 @@ import (
type maintenanceManifestStaticValidator struct{}
// Validate validates an OpenShift cluster
// Validate validates a MaintenanceManifest
func (sv maintenanceManifestStaticValidator) Static(_new interface{}, _current *api.MaintenanceManifestDocument) error {
new := _new.(*MaintenanceManifest)
var current *MaintenanceManifest
if _current != nil {
current = (&maintenanceManifestConverter{}).ToExternal(_current).(*MaintenanceManifest)
current = (&maintenanceManifestConverter{}).ToExternal(_current, false).(*MaintenanceManifest)
}
err := sv.validate(new)

Просмотреть файл

@ -72,8 +72,8 @@ type SecretConverter interface {
}
type MaintenanceManifestConverter interface {
ToExternal(*MaintenanceManifestDocument) interface{}
ToExternalList([]*MaintenanceManifestDocument, string) interface{}
ToExternal(doc *MaintenanceManifestDocument, clusterNamespaced bool) interface{}
ToExternalList(docs []*MaintenanceManifestDocument, nextLink string, clusterNamespaced bool) interface{}
ToInternal(interface{}, *MaintenanceManifestDocument)
}

Просмотреть файл

@ -17,6 +17,7 @@ import (
const (
MaintenanceManifestDequeueQueryForCluster = `SELECT * FROM MaintenanceManifests doc WHERE doc.maintenanceManifest.state IN ("Pending") AND doc.clusterResourceID = @clusterResourceID`
MaintenanceManifestQueryForCluster = `SELECT * FROM MaintenanceManifests doc WHERE doc.clusterResourceID = @clusterResourceID`
MaintenanceManifestQueueOverallQuery = `SELECT * FROM MaintenanceManifests doc WHERE doc.maintenanceManifest.state IN ("Pending") AND (doc.leaseExpires ?? 0) < GetCurrentTimestamp() / 1000`
MaintenanceManifestQueueLengthQuery = `SELECT VALUE COUNT(1) FROM MaintenanceManifests doc WHERE doc.maintenanceManifest.state IN ("Pending") AND (doc.leaseExpires ?? 0) < GetCurrentTimestamp() / 1000`
)
@ -39,6 +40,8 @@ type MaintenanceManifests interface {
EndLease(context.Context, string, string, api.MaintenanceManifestState, *string) (*api.MaintenanceManifestDocument, error)
Get(context.Context, string, string) (*api.MaintenanceManifestDocument, error)
Delete(context.Context, string, string) error
QueueLength(context.Context) (int, error)
Queued(ctx context.Context, continuation string) (cosmosdb.MaintenanceManifestDocumentIterator, error)
NewUUID() string
}
@ -87,8 +90,8 @@ func (c *maintenanceManifests) Get(ctx context.Context, clusterResourceID string
// QueueLength returns the number of MaintenanceManifests which are waiting to
// be unqueued. If error occurs, 0 is returned with error message
func (c *maintenanceManifests) QueueLength(ctx context.Context, collid string) (int, error) {
partitions, err := c.collc.PartitionKeyRanges(ctx, collid)
func (c *maintenanceManifests) QueueLength(ctx context.Context) (int, error) {
partitions, err := c.collc.PartitionKeyRanges(ctx, "MaintenanceManifests")
if err != nil {
return 0, err
}
@ -116,6 +119,15 @@ func (c *maintenanceManifests) QueueLength(ctx context.Context, collid string) (
return countTotal, nil
}
// Queued returns the number of MaintenanceManifests which are waiting to
// be unqueued. If error occurs, 0 is returned with error message
func (c *maintenanceManifests) Queued(ctx context.Context, continuation string) (cosmosdb.MaintenanceManifestDocumentIterator, error) {
return c.c.Query("", &cosmosdb.Query{
Query: MaintenanceManifestQueueOverallQuery,
Parameters: []cosmosdb.Parameter{},
}, &cosmosdb.Options{Continuation: continuation}), nil
}
func (c *maintenanceManifests) Patch(ctx context.Context, clusterResourceID string, id string, f MaintenanceManifestDocumentMutator) (*api.MaintenanceManifestDocument, error) {
return c.patch(ctx, clusterResourceID, id, f, nil)
}