Documentation
¶
Index ¶
- Variables
- func Delay(ctx context.Context, delay time.Duration) error
- func NewCosmosDatabaseClient(url string, dbName string, clientOptions azcore.ClientOptions) (*azcosmos.DatabaseClient, error)
- func NewPartitionKey(subscriptionID string) azcosmos.PartitionKey
- type DBClient
- type DBClientIterator
- type DBClientIteratorItem
- type LockClient
- func (c *LockClient) AcquireLock(ctx context.Context, id string, timeout *time.Duration) (*azcosmos.ItemResponse, error)
- func (c *LockClient) GetDefaultTimeToLive() time.Duration
- func (c *LockClient) HoldLock(ctx context.Context, item *azcosmos.ItemResponse) (cancelCtx context.Context, stop StopHoldLock)
- func (c *LockClient) ReleaseLock(ctx context.Context, item *azcosmos.ItemResponse) error
- func (c *LockClient) RenewLock(ctx context.Context, item *azcosmos.ItemResponse) (*azcosmos.ItemResponse, error)
- func (c *LockClient) SetName(name string)
- func (c *LockClient) SetRetryAfterHeader(header http.Header)
- func (c *LockClient) TryAcquireLock(ctx context.Context, id string) (*azcosmos.ItemResponse, error)
- type OperationDocument
- type OperationRequest
- type ResourceDocument
- type StopHoldLock
- type SubscriptionDocument
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
func NewCosmosDatabaseClient ¶
func NewCosmosDatabaseClient(url string, dbName string, clientOptions azcore.ClientOptions) (*azcosmos.DatabaseClient, error)
NewCosmosDatabaseClient instantiates a generic Cosmos database client.
func NewPartitionKey ¶
func NewPartitionKey(subscriptionID string) azcosmos.PartitionKey
NewPartitionKey creates a partition key from an Azure subscription ID.
Types ¶
type DBClient ¶
type DBClient interface { // DBConnectionTest is used to health check the database. If the database is not reachable or otherwise not ready // to be used, an error should be returned. DBConnectionTest(ctx context.Context) error // GetLockClient returns a LockClient, or nil if the DBClient does not support a LockClient. GetLockClient() *LockClient // GetResourceDoc retrieves a ResourceDocument from the database given its resourceID. // ErrNotFound is returned if an associated ResourceDocument cannot be found. GetResourceDoc(ctx context.Context, resourceID *azcorearm.ResourceID) (*ResourceDocument, error) CreateResourceDoc(ctx context.Context, doc *ResourceDocument) error UpdateResourceDoc(ctx context.Context, resourceID *azcorearm.ResourceID, callback func(*ResourceDocument) bool) (bool, error) // DeleteResourceDoc deletes a ResourceDocument from the database given the resourceID // of a Microsoft.RedHatOpenShift/HcpOpenShiftClusters resource or NodePools child resource. DeleteResourceDoc(ctx context.Context, resourceID *azcorearm.ResourceID) error ListResourceDocs(prefix *azcorearm.ResourceID, maxItems int32, continuationToken *string) DBClientIterator[ResourceDocument] GetOperationDoc(ctx context.Context, operationID string) (*OperationDocument, error) CreateOperationDoc(ctx context.Context, doc *OperationDocument) (string, error) UpdateOperationDoc(ctx context.Context, operationID string, callback func(*OperationDocument) bool) (bool, error) ListOperationDocs(subscriptionID string) DBClientIterator[OperationDocument] // GetSubscriptionDoc retrieves a SubscriptionDocument from the database given the subscriptionID. // ErrNotFound is returned if an associated SubscriptionDocument cannot be found. GetSubscriptionDoc(ctx context.Context, subscriptionID string) (*SubscriptionDocument, error) CreateSubscriptionDoc(ctx context.Context, subscriptionID string, doc *SubscriptionDocument) error UpdateSubscriptionDoc(ctx context.Context, subscriptionID string, callback func(*SubscriptionDocument) bool) (bool, error) ListAllSubscriptionDocs() DBClientIterator[SubscriptionDocument] }
DBClient is a document store for frontend to perform required CRUD operations against
func NewDBClient ¶
NewDBClient instantiates a DBClient from a Cosmos DatabaseClient instance targeting the Frontends async database.
type DBClientIterator ¶
type DBClientIteratorItem ¶
type LockClient ¶
type LockClient struct {
// contains filtered or unexported fields
}
func NewLockClient ¶
func NewLockClient(ctx context.Context, containerClient *azcosmos.ContainerClient) (*LockClient, error)
NewLockClient creates a LockClient around a ContainerClient. It attempts to read container properties to extract a default TTL. If this fails or if the container does not define a default TTL, the function returns an error.
func (*LockClient) AcquireLock ¶
func (c *LockClient) AcquireLock(ctx context.Context, id string, timeout *time.Duration) (*azcosmos.ItemResponse, error)
AcquireLock persistently tries to acquire a lock for the given ID. If a timeout is provided, the function will cease after the timeout duration and return a context.DeadlineExceeded error.
func (*LockClient) GetDefaultTimeToLive ¶
func (c *LockClient) GetDefaultTimeToLive() time.Duration
GetDefaultTimeToLive returns the default time-to-live value of the container as a time.Duration.
func (*LockClient) HoldLock ¶
func (c *LockClient) HoldLock(ctx context.Context, item *azcosmos.ItemResponse) (cancelCtx context.Context, stop StopHoldLock)
HoldLock tries to hold an acquired lock by renewing it periodically from a goroutine until the returned stop function is called. The function also returns a new context which is cancelled if the lock is lost or some other error occurs. The stop function terminates the goroutine and returns the current lock, or nil if the lock was lost.
func (*LockClient) ReleaseLock ¶
func (c *LockClient) ReleaseLock(ctx context.Context, item *azcosmos.ItemResponse) error
ReleaseLock attempts to release an acquired lock. Errors should be logged but not treated as fatal, since the container item's TTL value guarantees that it will be released eventually.
func (*LockClient) RenewLock ¶
func (c *LockClient) RenewLock(ctx context.Context, item *azcosmos.ItemResponse) (*azcosmos.ItemResponse, error)
RenewLock attempts to renew an acquired lock. If successful it returns a new lock. If the lock was somehow lost, it returns a nil azcosmos.ItemResponse and no error.
func (*LockClient) SetName ¶
func (c *LockClient) SetName(name string)
SetName overrides how a lock item identifies the owner. This is for informational purposes only. LockClient uses the hostname by default.
func (*LockClient) SetRetryAfterHeader ¶
func (c *LockClient) SetRetryAfterHeader(header http.Header)
SetRetryAfterHeader sets a "Retry-After" header to the default TTL value.
func (*LockClient) TryAcquireLock ¶
func (c *LockClient) TryAcquireLock(ctx context.Context, id string) (*azcosmos.ItemResponse, error)
TryAcquireLock tries once to acquire a lock for the given ID. If the lock is already taken, it returns a nil azcosmos.ItemResponse and no error.
type OperationDocument ¶
type OperationDocument struct { PartitionKey string `json:"partitionKey,omitempty"` // TenantID is the tenant ID of the client that requested the operation TenantID string `json:"tenantId,omitempty"` // ClientID is the object ID of the client that requested the operation ClientID string `json:"clientId,omitempty"` // Request is the type of asynchronous operation requested Request OperationRequest `json:"request,omitempty"` // ExternalID is the Azure resource ID of the cluster or node pool ExternalID *azcorearm.ResourceID `json:"externalId,omitempty"` // InternalID is the Cluster Service resource identifier in the form of a URL path InternalID ocm.InternalID `json:"internalId,omitempty"` // OperationID is the Azure resource ID of the operation status (may be nil if the // operation was implicit, such as deleting a child resource along with the parent) OperationID *azcorearm.ResourceID `json:"operationId,omitempty"` // NotificationURI is provided by the Azure-AsyncNotificationUri header if the // Async Operation Callbacks ARM feature is enabled NotificationURI string `json:"notificationUri,omitempty"` // StartTime marks the start of the operation StartTime time.Time `json:"startTime,omitempty"` // LastTransitionTime marks the most recent state change LastTransitionTime time.Time `json:"lastTransitionTime,omitempty"` // Status is the current operation status, using the same set of values // as the resource's provisioning state Status arm.ProvisioningState `json:"status,omitempty"` // Error is an OData error, present when Status is "Failed" or "Canceled" Error *arm.CloudErrorBody `json:"error,omitempty"` // contains filtered or unexported fields }
OperationDocument tracks an asynchronous operation.
func NewOperationDocument ¶
func NewOperationDocument(request OperationRequest, externalID *azcorearm.ResourceID, internalID ocm.InternalID) *OperationDocument
func (*OperationDocument) ToStatus ¶
func (doc *OperationDocument) ToStatus() *arm.Operation
ToStatus converts an OperationDocument to the ARM operation status format.
func (*OperationDocument) UpdateStatus ¶
func (doc *OperationDocument) UpdateStatus(status arm.ProvisioningState, err *arm.CloudErrorBody) bool
UpdateStatus conditionally updates the document if the status given differs from the status already present. If so, it sets the Status and Error fields to the values given, updates the LastTransitionTime, and returns true. This is intended to be used with DBClient.UpdateOperationDoc.
type OperationRequest ¶
type OperationRequest string
const ( OperationRequestCreate OperationRequest = "Create" OperationRequestUpdate OperationRequest = "Update" OperationRequestDelete OperationRequest = "Delete" )
type ResourceDocument ¶
type ResourceDocument struct { // FIXME: Change the JSON field name when we're ready to break backward-compat. ResourceID *azcorearm.ResourceID `json:"key,omitempty"` PartitionKey string `json:"partitionKey,omitempty"` InternalID ocm.InternalID `json:"internalId,omitempty"` ActiveOperationID string `json:"activeOperationId,omitempty"` ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty"` Identity *arm.ManagedServiceIdentity `json:"identity,omitempty"` SystemData *arm.SystemData `json:"systemData,omitempty"` Tags map[string]string `json:"tags,omitempty"` // contains filtered or unexported fields }
ResourceDocument captures the mapping of an Azure resource ID to an internal resource ID (the OCM API path), as well as any ARM-specific metadata for the resource.
func NewResourceDocument ¶
func NewResourceDocument(resourceID *azcorearm.ResourceID) *ResourceDocument
type StopHoldLock ¶
type StopHoldLock func() *azcosmos.ItemResponse
type SubscriptionDocument ¶
type SubscriptionDocument struct { Subscription *arm.Subscription `json:"subscription,omitempty"` // contains filtered or unexported fields }
SubscriptionDocument represents an Azure Subscription document.
func NewSubscriptionDocument ¶
func NewSubscriptionDocument(subscriptionID string, subscription *arm.Subscription) *SubscriptionDocument