formation

package
v0.0.0-...-6d13c91 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConverter

func NewConverter() *converter

NewConverter creates new formation converter

func NewFormationStatusService

func NewFormationStatusService(formationRepository FormationRepository, labelDefRepository labelDefRepository, labelDefService labelDefService, notificationsService NotificationsService, constraintEngine constraintEngine) *formationStatusService

NewFormationStatusService creates formation status service

func NewNotificationService

func NewNotificationService(
	tenantRepository tenantRepository,
	webhookClient webhookClient,
	notificationsGenerator notificationsGenerator,
	constraintEngine constraintEngine,
	webhookConverter webhookConverter,
	formationTemplateRepository FormationTemplateRepository,
	formationAssignmentRepo FormationAssignmentRepository,
	formationRepo FormationRepository,

) *notificationsService

NewNotificationService creates notifications service for formation assignment and unassignment

func NewRepository

func NewRepository(conv EntityConverter) *repository

NewRepository creates a new Formation repository

func NewService

func NewService(
	transact persistence.Transactioner,
	applicationRepository applicationRepository,
	labelDefRepository labelDefRepository,
	labelRepository labelRepository,
	formationRepository FormationRepository,
	formationTemplateRepository FormationTemplateRepository,
	labelService labelService,
	uuidService uuidService,
	labelDefService labelDefService,
	asaRepo automaticFormationAssignmentRepository,
	asaService automaticFormationAssignmentService,
	tenantSvc tenantService, runtimeRepo runtimeRepository,
	runtimeContextRepo runtimeContextRepository,
	formationAssignmentService formationAssignmentService,
	formationAssignmentNotificationService FormationAssignmentNotificationsService,
	notificationsService NotificationsService,
	constraintEngine constraintEngine,
	webhookRepository webhookRepository,
	statusService statusService,
	runtimeTypeLabelKey, applicationTypeLabelKey string) *service

NewService creates formation service

Types

type ASAEngine

type ASAEngine struct {
	// contains filtered or unexported fields
}

ASAEngine processes Automatic Scenario Assignments

func NewASAEngine

func NewASAEngine(asaRepository automaticFormationAssignmentRepository, runtimeRepository runtimeRepository, runtimeContextRepository runtimeContextRepository, formationRepository FormationRepository, formationTemplateRepository FormationTemplateRepository, runtimeTypeLabelKey, applicationTypeLabelKey string) *ASAEngine

NewASAEngine returns ASAEngine

func (*ASAEngine) EnsureScenarioAssigned

func (s *ASAEngine) EnsureScenarioAssigned(ctx context.Context, in *model.AutomaticScenarioAssignment, processScenarioFunc ProcessScenarioFunc) error

EnsureScenarioAssigned ensures that the scenario is assigned to all the runtimes and runtimeContexts that are in the ASAs target_tenant_id

func (*ASAEngine) GetMatchingFuncByFormationObjectType

func (s *ASAEngine) GetMatchingFuncByFormationObjectType(objType graphql.FormationObjectType) (MatchingFunc, error)

GetMatchingFuncByFormationObjectType gets matching func based on the objType

func (*ASAEngine) GetScenariosFromMatchingASAs

func (s *ASAEngine) GetScenariosFromMatchingASAs(ctx context.Context, objectID string, objType graphql.FormationObjectType) ([]string, error)

GetScenariosFromMatchingASAs gets all the scenarios that should be added to the runtime based on the matching Automatic Scenario Assignments In order to do that, the ASAs should be searched in the caller tenant as this is the tenant that modifies the runtime and this is the tenant that the ASA produced labels should be added to.

func (*ASAEngine) IsFormationComingFromASA

func (s *ASAEngine) IsFormationComingFromASA(ctx context.Context, objectID, formation string, objectType graphql.FormationObjectType) (bool, error)

IsFormationComingFromASA checks whether the formation comes from ASA

func (*ASAEngine) RemoveAssignedScenario

func (s *ASAEngine) RemoveAssignedScenario(ctx context.Context, in *model.AutomaticScenarioAssignment, processScenarioFunc ProcessScenarioFunc) error

RemoveAssignedScenario removes all the scenarios that are coming from the provided ASA

type Converter

type Converter interface {
	FromGraphQL(i graphql.FormationInput) model.Formation
	ToGraphQL(i *model.Formation) (*graphql.Formation, error)
	MultipleToGraphQL(in []*model.Formation) ([]*graphql.Formation, error)
}

Converter missing godoc

type Entity

type Entity struct {
	ID                            string         `db:"id"`
	TenantID                      string         `db:"tenant_id"`
	FormationTemplateID           string         `db:"formation_template_id"`
	Name                          string         `db:"name"`
	State                         string         `db:"state"`
	Error                         sql.NullString `db:"error"`
	LastStateChangeTimestamp      *time.Time     `db:"last_state_change_timestamp"`
	LastNotificationSentTimestamp *time.Time     `db:"last_notification_sent_timestamp"`
}

Entity represents the formation entity

type EntityCollection

type EntityCollection []*Entity

EntityCollection is a collection of formation entities.

func (EntityCollection) Len

func (s EntityCollection) Len() int

Len returns the number of entities in the collection.

type EntityConverter

type EntityConverter interface {
	ToEntity(in *model.Formation) *Entity
	FromEntity(entity *Entity) *model.Formation
}

EntityConverter converts between the internal model and entity

type FormationAssignmentConverter

type FormationAssignmentConverter interface {
	MultipleToGraphQL(in []*model.FormationAssignment) ([]*graphql.FormationAssignment, error)
	ToGraphQL(in *model.FormationAssignment) (*graphql.FormationAssignment, error)
}

FormationAssignmentConverter converts FormationAssignment between the model.FormationAssignment service-layer representation and graphql.FormationAssignment.

type FormationAssignmentInputBuilder

FormationAssignmentInputBuilder represents expected signature for methods that create operator input from the provided details

type FormationAssignmentNotificationsService

type FormationAssignmentNotificationsService interface {
	GenerateFormationAssignmentNotification(ctx context.Context, formationAssignment *model.FormationAssignment, operation model.FormationOperation) (*webhookclient.FormationAssignmentNotificationRequest, error)
}

FormationAssignmentNotificationsService represents the notification service for generating and sending notifications

type FormationAssignmentRepository

type FormationAssignmentRepository interface {
	Update(ctx context.Context, model *model.FormationAssignment) error
}

FormationAssignmentRepository represents the Formation Assignment repository layer

type FormationRepository

type FormationRepository interface {
	Get(ctx context.Context, id, tenantID string) (*model.Formation, error)
	GetByName(ctx context.Context, name, tenantID string) (*model.Formation, error)
	GetGlobalByID(ctx context.Context, id string) (*model.Formation, error)
	List(ctx context.Context, tenant string, pageSize int, cursor string) (*model.FormationPage, error)
	ListByIDsGlobal(ctx context.Context, formationIDs []string) ([]*model.Formation, error)
	Create(ctx context.Context, item *model.Formation) error
	DeleteByName(ctx context.Context, tenantID, name string) error
	Update(ctx context.Context, model *model.Formation) error
}

FormationRepository represents the Formations repository layer

type FormationTemplateRepository

type FormationTemplateRepository interface {
	Get(ctx context.Context, id string) (*model.FormationTemplate, error)
	GetByNameAndTenant(ctx context.Context, templateName, tenantID string) (*model.FormationTemplate, error)
}

FormationTemplateRepository represents the FormationTemplate repository layer

type MatchingFunc

type MatchingFunc func(ctx context.Context, asa *model.AutomaticScenarioAssignment, runtimeID string) (bool, error)

MatchingFunc provides signature for functions used for matching asa against runtimeID

type NotificationBuilder

type NotificationBuilder struct {
	// contains filtered or unexported fields
}

NotificationBuilder is responsible for building notification requests

func NewNotificationsBuilder

func NewNotificationsBuilder(webhookConverter webhookConverter, constraintEngine constraintEngine, runtimeTypeLabelKey, applicationTypeLabelKey string) *NotificationBuilder

NewNotificationsBuilder creates new NotificationBuilder

func (*NotificationBuilder) BuildFormationAssignmentNotificationRequest

BuildFormationAssignmentNotificationRequest builds new formation assignment notification request

func (*NotificationBuilder) BuildFormationNotificationRequests

func (nb *NotificationBuilder) BuildFormationNotificationRequests(ctx context.Context, joinPointDetails *formationconstraintpkg.GenerateFormationNotificationOperationDetails, formation *model.Formation, formationTemplateWebhooks []*model.Webhook) ([]*webhookclient.FormationNotificationRequest, error)

BuildFormationNotificationRequests builds new formation notification request

func (*NotificationBuilder) PrepareDetailsForApplicationTenantMappingNotificationGeneration

func (nb *NotificationBuilder) PrepareDetailsForApplicationTenantMappingNotificationGeneration(
	operation model.FormationOperation,
	formationTemplateID string,
	formation *model.Formation,
	sourceApplicationTemplate *webhookdir.ApplicationTemplateWithLabels,
	sourceApplication *webhookdir.ApplicationWithLabels,
	targetApplicationTemplate *webhookdir.ApplicationTemplateWithLabels,
	targetApplication *webhookdir.ApplicationWithLabels,
	assignment *webhookdir.FormationAssignment,
	reverseAssignment *webhookdir.FormationAssignment,
	tenantContext *webhookdir.CustomerTenantContext,
	tenantID string,
) (*formationconstraintpkg.GenerateFormationAssignmentNotificationOperationDetails, error)

PrepareDetailsForApplicationTenantMappingNotificationGeneration returns GenerateFormationAssignmentNotificationOperationDetails for applicationTenantMapping webhooks

func (*NotificationBuilder) PrepareDetailsForConfigurationChangeNotificationGeneration

func (nb *NotificationBuilder) PrepareDetailsForConfigurationChangeNotificationGeneration(
	operation model.FormationOperation,
	formationTemplateID string,
	formation *model.Formation,
	applicationTemplate *webhookdir.ApplicationTemplateWithLabels,
	application *webhookdir.ApplicationWithLabels,
	runtime *webhookdir.RuntimeWithLabels,
	runtimeContext *webhookdir.RuntimeContextWithLabels,
	assignment *webhookdir.FormationAssignment,
	reverseAssignment *webhookdir.FormationAssignment,
	targetType model.ResourceType,
	tenantContext *webhookdir.CustomerTenantContext,
	tenantID string,
) (*formationconstraintpkg.GenerateFormationAssignmentNotificationOperationDetails, error)

PrepareDetailsForConfigurationChangeNotificationGeneration returns GenerateFormationAssignmentNotificationOperationDetails for ConfigurationChanged webhooks

type NotificationsGenerator

type NotificationsGenerator struct {
	// contains filtered or unexported fields
}

NotificationsGenerator is responsible for generation of notification requests

func NewNotificationsGenerator

func NewNotificationsGenerator(
	applicationRepository applicationRepository,
	applicationTemplateRepository applicationTemplateRepository,
	runtimeRepo runtimeRepository,
	runtimeContextRepo runtimeContextRepository,
	labelRepository labelRepository,
	webhookRepository webhookRepository,
	webhookDataInputBuilder databuilder.DataInputBuilder,
	notificationBuilder notificationBuilder) *NotificationsGenerator

NewNotificationsGenerator returns an instance of NotificationsGenerator

func (*NotificationsGenerator) GenerateFormationLifecycleNotifications

func (ns *NotificationsGenerator) GenerateFormationLifecycleNotifications(ctx context.Context, formationTemplateWebhooks []*model.Webhook, tenantID string, formation *model.Formation, formationTemplateName, formationTemplateID string, formationOperation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationNotificationRequest, error)

GenerateFormationLifecycleNotifications generates formation notifications for the provided webhooks

func (*NotificationsGenerator) GenerateNotificationsAboutApplicationsForTheRuntimeContextThatIsAssigned

func (ns *NotificationsGenerator) GenerateNotificationsAboutApplicationsForTheRuntimeContextThatIsAssigned(ctx context.Context, tenant, runtimeCtxID string, formation *model.Formation, operation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)

GenerateNotificationsAboutApplicationsForTheRuntimeContextThatIsAssigned generates notification per runtime context that is part of the formation with target the runtime context and source the application on which `operation` is performed

func (*NotificationsGenerator) GenerateNotificationsAboutApplicationsForTheRuntimeThatIsAssigned

func (ns *NotificationsGenerator) GenerateNotificationsAboutApplicationsForTheRuntimeThatIsAssigned(ctx context.Context, tenant, runtimeID string, formation *model.Formation, operation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)

GenerateNotificationsAboutApplicationsForTheRuntimeThatIsAssigned generates notification per runtime that is part of the formation with target the runtime and source the application on which `operation` is performed

func (*NotificationsGenerator) GenerateNotificationsAboutRuntimeAndRuntimeContextForTheApplicationThatIsAssigned

func (ns *NotificationsGenerator) GenerateNotificationsAboutRuntimeAndRuntimeContextForTheApplicationThatIsAssigned(ctx context.Context, tenant string, appID string, formation *model.Formation, operation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)

GenerateNotificationsAboutRuntimeAndRuntimeContextForTheApplicationThatIsAssigned generates notification with target the application that is assigned about for each runtime and each runtimeContext that is part of the formation

func (*NotificationsGenerator) GenerateNotificationsForApplicationsAboutTheApplicationThatIsAssigned

func (ns *NotificationsGenerator) GenerateNotificationsForApplicationsAboutTheApplicationThatIsAssigned(ctx context.Context, tenant string, appID string, formation *model.Formation, operation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)

GenerateNotificationsForApplicationsAboutTheApplicationThatIsAssigned generates notification per application that is part of the formation with target the application and source the application on which `operation` is performed

func (*NotificationsGenerator) GenerateNotificationsForApplicationsAboutTheRuntimeContextThatIsAssigned

func (ns *NotificationsGenerator) GenerateNotificationsForApplicationsAboutTheRuntimeContextThatIsAssigned(ctx context.Context, tenant, runtimeCtxID string, formation *model.Formation, operation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)

GenerateNotificationsForApplicationsAboutTheRuntimeContextThatIsAssigned generates notification per application that is part of the formation with target the application and source the runtime context on which `operation` is performed

func (*NotificationsGenerator) GenerateNotificationsForApplicationsAboutTheRuntimeThatIsAssigned

func (ns *NotificationsGenerator) GenerateNotificationsForApplicationsAboutTheRuntimeThatIsAssigned(ctx context.Context, tenant, runtimeID string, formation *model.Formation, operation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)

GenerateNotificationsForApplicationsAboutTheRuntimeThatIsAssigned generates notification per application that is part of the formation with target the application and source the runtime on which `operation` is performed

func (*NotificationsGenerator) GenerateNotificationsForRuntimeAboutTheApplicationThatIsAssigned

func (ns *NotificationsGenerator) GenerateNotificationsForRuntimeAboutTheApplicationThatIsAssigned(ctx context.Context, tenant string, appID string, formation *model.Formation, operation model.FormationOperation, customerTenantContext *webhookdir.CustomerTenantContext) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)

GenerateNotificationsForRuntimeAboutTheApplicationThatIsAssigned generates notification per runtime that is part of the formation with target the runtime and source the application on which `operation` is performed

type NotificationsService

type NotificationsService interface {
	GenerateFormationAssignmentNotifications(ctx context.Context, tenant, objectID string, formation *model.Formation, operation model.FormationOperation, objectType graphql.FormationObjectType) ([]*webhookclient.FormationAssignmentNotificationRequestTargetMapping, error)
	GenerateFormationNotifications(ctx context.Context, formationTemplateWebhooks []*model.Webhook, tenantID string, formation *model.Formation, formationTemplateName, formationTemplateID string, formationOperation model.FormationOperation) ([]*webhookclient.FormationNotificationRequest, error)
	SendNotification(ctx context.Context, webhookNotificationReq webhookclient.WebhookExtRequest) (*webhookdir.Response, error)
	PrepareDetailsForNotificationStatusReturned(ctx context.Context, formation *model.Formation, operation model.FormationOperation) (*formationconstraint.NotificationStatusReturnedOperationDetails, error)
}

NotificationsService represents the notification service for generating and sending notifications

type ProcessScenarioFunc

ProcessScenarioFunc provides the signature for functions that process scenarios

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver is the formation resolver

func NewResolver

func NewResolver(transact persistence.Transactioner, service Service, conv Converter, formationAssignmentSvc formationAssignmentService, formationAssignmentConv FormationAssignmentConverter, fetcher TenantFetcher, tenantSvc tenantSvc) *Resolver

NewResolver creates formation resolver

func (*Resolver) AssignFormation

func (r *Resolver) AssignFormation(ctx context.Context, objectID string, objectType graphql.FormationObjectType, formation graphql.FormationInput) (*graphql.Formation, error)

AssignFormation assigns object to the provided formation

func (*Resolver) CreateFormation

func (r *Resolver) CreateFormation(ctx context.Context, formationInput graphql.FormationInput) (*graphql.Formation, error)

CreateFormation creates new formation for the caller tenant

func (*Resolver) DeleteFormation

func (r *Resolver) DeleteFormation(ctx context.Context, formation graphql.FormationInput) (*graphql.Formation, error)

DeleteFormation deletes the formation from the caller tenant formations

func (*Resolver) FinalizeDraftFormation

func (r *Resolver) FinalizeDraftFormation(ctx context.Context, formationID string) (*graphql.Formation, error)

FinalizeDraftFormation changes the formation state to initial and start processing the formation and formation assignment notifications

func (*Resolver) Formation

func (r *Resolver) Formation(ctx context.Context, id string) (*graphql.Formation, error)

Formation returns a Formation by its id

func (*Resolver) FormationAssignment

func (r *Resolver) FormationAssignment(ctx context.Context, obj *graphql.Formation, id string) (*graphql.FormationAssignment, error)

FormationAssignment missing godoc

func (*Resolver) FormationAssignments

func (r *Resolver) FormationAssignments(ctx context.Context, obj *graphql.Formation, first *int, after *graphql.PageCursor) (*graphql.FormationAssignmentPage, error)

FormationAssignments retrieves a page of FormationAssignments for the specified Formation

func (*Resolver) FormationAssignmentsDataLoader

func (r *Resolver) FormationAssignmentsDataLoader(keys []dataloader.ParamFormationAssignment) ([]*graphql.FormationAssignmentPage, []error)

FormationAssignmentsDataLoader retrieves a page of FormationAssignments for each Formation ID in the keys argument The sub-resolver is referred from tenant scoped resolvers but in some cases it can be referred in non tenant scoped resolver(e.g. formationsForObject) In order to work correctly in both cases the formations from the keys are processed grouped by tenant. After the processing the correct order of the assignment pages(same as the order of the formations from the keys) must be ensured as the dataloaders depend on the order of the results when resolving the sub-resolvers

func (*Resolver) FormationByName

func (r *Resolver) FormationByName(ctx context.Context, name string) (*graphql.Formation, error)

FormationByName returns a Formation by its name

func (*Resolver) Formations

func (r *Resolver) Formations(ctx context.Context, first *int, after *graphql.PageCursor) (*graphql.FormationPage, error)

Formations returns paginated Formations based on first and after

func (*Resolver) FormationsForObject

func (r *Resolver) FormationsForObject(ctx context.Context, objectID string) ([]*graphql.Formation, error)

FormationsForObject returns all Formations `objectID` is part of

func (*Resolver) ResynchronizeFormationNotifications

func (r *Resolver) ResynchronizeFormationNotifications(ctx context.Context, formationID string, reset *bool) (*graphql.Formation, error)

ResynchronizeFormationNotifications sends all notifications that are in error or initial state

func (*Resolver) Status

Status retrieves a Status for the specified Formation

func (*Resolver) StatusDataLoader

func (r *Resolver) StatusDataLoader(keys []dataloader.ParamFormationStatus) ([]*graphql.FormationStatus, []error)

StatusDataLoader retrieves a Status for each Formation ID in the keys argument The sub-resolver is referred from tenant scoped resolvers but in some cases it can be referred in non tenant scoped resolver(e.g. formationsForObject) In order to work correctly in both cases the formations from the keys are processed grouped by tenant. After the processing the correct order of the statuses(same as the order of the formations from the keys) must be ensured as the dataloaders depend on the order of the results when resolving the sub-resolvers

func (*Resolver) UnassignFormation

func (r *Resolver) UnassignFormation(ctx context.Context, objectID string, objectType graphql.FormationObjectType, formation graphql.FormationInput) (*graphql.Formation, error)

UnassignFormation unassigns the object from the provided formation

func (*Resolver) UnassignFormationGlobal

func (r *Resolver) UnassignFormationGlobal(ctx context.Context, objectID string, objectType graphql.FormationObjectType, formationID string) (*graphql.Formation, error)

UnassignFormationGlobal unassigns the objectID from the provided formation globally

type Service

type Service interface {
	Get(ctx context.Context, id string) (*model.Formation, error)
	GetFormationByName(ctx context.Context, formationName, tnt string) (*model.Formation, error)
	List(ctx context.Context, pageSize int, cursor string) (*model.FormationPage, error)
	GetGlobalByID(ctx context.Context, id string) (*model.Formation, error)
	ListFormationsForObject(ctx context.Context, objectID string) ([]*model.Formation, error)
	CreateFormation(ctx context.Context, tnt string, formation model.Formation, templateName string) (*model.Formation, error)
	DeleteFormation(ctx context.Context, tnt string, formation model.Formation) (*model.Formation, error)
	AssignFormation(ctx context.Context, tnt, objectID string, objectType graphql.FormationObjectType, formation model.Formation) (*model.Formation, error)
	UnassignFormation(ctx context.Context, tnt, objectID string, objectType graphql.FormationObjectType, formation model.Formation) (*model.Formation, error)
	ResynchronizeFormationNotifications(ctx context.Context, formationID string, reset bool) (*model.Formation, error)
	FinalizeDraftFormation(ctx context.Context, formationID string) (*model.Formation, error)
}

Service missing godoc

type TenantFetcher

type TenantFetcher interface {
	FetchOnDemand(ctx context.Context, tenant, parentTenant string) error
}

TenantFetcher calls an API which fetches details for the given tenant from an external tenancy service, stores the tenant in the Compass DB and returns 200 OK if the tenant was successfully created.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL