broker

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2020 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package broker holds the code that users of the skeleton write for their broker. To make a broker, fill out:

  • The Options type, which holds options for the broker
  • The AddFlags function, which adds CLI flags for an Options
  • The methods of the BusinessLogic type, which implements the broker's business logic
  • The NewBusinessLogic function, which creates a BusinessLogic from the Options the program is run with

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFlags

func AddFlags(o *Options)

func ApplyParamsToStatement

func ApplyParamsToStatement(statement string, args ...string) string

func CanGetBindings

func CanGetBindings(status string) bool

func ConflictErrorWithMessage

func ConflictErrorWithMessage(description string) error

func CrudeOSBIHacks

func CrudeOSBIHacks(router *mux.Router, b *BusinessLogic)

These are hacks to support more of V2.14 such as get service instance and get service bindings.

func FinishedTask

func FinishedTask(storage Storage, taskId string, retries int64, result string, status string)

func HttpWrite

func HttpWrite(w http.ResponseWriter, status int, obj interface{})

func InProgress

func InProgress(status string) bool

func InternalServerError

func InternalServerError() error

func IsAvailable

func IsAvailable(status string) bool

func NotFound

func NotFound() error

func RandomString

func RandomString(n int) string

func RunBackgroundTasks

func RunBackgroundTasks(ctx context.Context, o Options) error

func RunPreprovisionTasks

func RunPreprovisionTasks(ctx context.Context, o Options, namePrefix string, storage Storage, wait int64)

func RunWorkerTasks

func RunWorkerTasks(ctx context.Context, o Options, namePrefix string, storage Storage) error

func TickTocPreprovisionTasks

func TickTocPreprovisionTasks(ctx context.Context, o Options, namePrefix string, storage Storage)

func UnprocessableEntity

func UnprocessableEntity() error

func UnprocessableEntityWithMessage

func UnprocessableEntityWithMessage(err string, description string) error

func UpdateTaskStatus

func UpdateTaskStatus(storage Storage, taskId string, retries int64, result string, status string)

func UpgradeAcrossProviders

func UpgradeAcrossProviders(storage Storage, fromDb *Instance, toPlanId string, namePrefix string) (string, error)

func UpgradeWithinProviders

func UpgradeWithinProviders(storage Storage, fromDb *Instance, toPlanId string, namePrefix string) (string, error)

Types

type Action

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

type ActionBase

type ActionBase struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*ActionBase) ActionSchemaHandler

func (b *ActionBase) ActionSchemaHandler(w http.ResponseWriter, r *http.Request)

func (*ActionBase) AddActions

func (b *ActionBase) AddActions(name string, path string, method string, handler func(string, map[string]string, *broker.RequestContext) (interface{}, error)) error

func (*ActionBase) ConvertActionsToExtensions

func (b *ActionBase) ConvertActionsToExtensions(serviceId string) []osb.ExtensionAPI

func (*ActionBase) RouteActions

func (b *ActionBase) RouteActions(router *mux.Router) error

type BusinessLogic

type BusinessLogic struct {
	ActionBase
	// contains filtered or unexported fields
}

func NewBusinessLogic

func NewBusinessLogic(ctx context.Context, o Options) (*BusinessLogic, error)

func (*BusinessLogic) Bind

func (*BusinessLogic) Deprovision

func (*BusinessLogic) GetBinding

func (b *BusinessLogic) GetBinding(request *osb.GetBindingRequest, context *broker.RequestContext) (*osb.GetBindingResponse, error)

func (*BusinessLogic) GetCatalog

func (*BusinessLogic) GetInstanceById

func (b *BusinessLogic) GetInstanceById(Id string) (*Instance, error)

func (*BusinessLogic) GetUnclaimedInstance

func (b *BusinessLogic) GetUnclaimedInstance(PlanId string, InstanceId string) (*Instance, error)

func (*BusinessLogic) LastOperation

func (*BusinessLogic) Provision

A piece of advice, never try to make this syncronous by waiting for a to return a response. The problem is that can take up to 10 minutes in my experience (depending on the provider), and aside from the API call timing out the other issue is it can cause the mutex lock to make the entire API unresponsive.

func (*BusinessLogic) Unbind

func (*BusinessLogic) Update

func (*BusinessLogic) ValidateBrokerAPIVersion

func (b *BusinessLogic) ValidateBrokerAPIVersion(version string) error

type ChangePlansTaskMetadata

type ChangePlansTaskMetadata struct {
	Plan string `json:"plan"`
}

type ChangeProvidersTaskMetadata

type ChangeProvidersTaskMetadata struct {
	Plan string `json:"plan"`
}

type Entry

type Entry struct {
	Id       string
	Name     string
	PlanId   string
	Claimed  bool
	Tasks    int
	Status   string
	Username string
	Password string
	Endpoint string
}

type InfoData

type InfoData struct {
	DatabaseName string
	BillingCode  string
	MONGODB_URL  string
}

type Instance

type Instance struct {
	Id            string        `json:"id"`
	Name          string        `json:"name"`
	ProviderId    string        `json:"provider_id"`
	Plan          *ProviderPlan `json:"plan,omitempty"`
	Username      string        `json:"username"`
	Password      string        `json:"password"`
	Endpoint      string        `json:"endpoint"`
	Status        string        `json:"status"`
	Ready         bool          `json:"ready"`
	Engine        string        `json:"engine"`
	EngineVersion string        `json:"engine_version"`
	Scheme        string        `json:"scheme"`
}

func GetInstanceById

func GetInstanceById(namePrefix string, storage Storage, Id string) (*Instance, error)

func (*Instance) Match

func (i *Instance) Match(other *Instance) bool

type MongodbProvider

type MongodbProvider struct {
	Provider
	// contains filtered or unexported fields
}

func NewMongodbProvider

func NewMongodbProvider(namePrefix string) (MongodbProvider, error)

func (MongodbProvider) Deprovision

func (provider MongodbProvider) Deprovision(instance *Instance, takeSnapshot bool) error

func (MongodbProvider) GetInstance

func (provider MongodbProvider) GetInstance(name string, plan *ProviderPlan) (*Instance, error)

func (MongodbProvider) Modify

func (provider MongodbProvider) Modify(instance *Instance, plan *ProviderPlan) (*Instance, error)

func (MongodbProvider) PerformPostProvision

func (provider MongodbProvider) PerformPostProvision(db *Instance) (*Instance, error)

func (MongodbProvider) Provision

func (provider MongodbProvider) Provision(Id string, plan *ProviderPlan, Owner string) (*Instance, error)

func (MongodbProvider) Tag

func (provider MongodbProvider) Tag(Instance *Instance, Name string, Value string) error

func (MongodbProvider) Untag

func (provider MongodbProvider) Untag(Instance *Instance, Name string) error

type MongodbProviderPlanSettings

type MongodbProviderPlanSettings struct {
	MasterUri     string `json:"master_uri"`
	Engine        string `json:"engine"`
	EngineVersion string `json:"engine_version"`
}

provider=mongodb in database These values come out of the plans table provider_private_details column.

func (MongodbProviderPlanSettings) MasterHost

func (mpps MongodbProviderPlanSettings) MasterHost() string

type Options

type Options struct {
	DatabaseUrl string
	NamePrefix  string
}

type PostgresStorage

type PostgresStorage struct {
	Storage
	// contains filtered or unexported fields
}

func InitStorage

func InitStorage(ctx context.Context, o Options) (*PostgresStorage, error)

func (*PostgresStorage) AddInstance

func (b *PostgresStorage) AddInstance(Instance *Instance) error

func (*PostgresStorage) AddTask

func (b *PostgresStorage) AddTask(Id string, action TaskAction, metadata string) (string, error)

func (*PostgresStorage) DeleteInstance

func (b *PostgresStorage) DeleteInstance(Instance *Instance) error

func (*PostgresStorage) GetInstance

func (b *PostgresStorage) GetInstance(Id string) (*Entry, error)

func (*PostgresStorage) GetPlanByID

func (b *PostgresStorage) GetPlanByID(planId string) (*ProviderPlan, error)

func (*PostgresStorage) GetPlans

func (b *PostgresStorage) GetPlans(serviceId string) ([]ProviderPlan, error)

func (*PostgresStorage) GetServices

func (b *PostgresStorage) GetServices() ([]osb.Service, error)

func (*PostgresStorage) GetUnclaimedInstance

func (b *PostgresStorage) GetUnclaimedInstance(PlanId string, InstanceId string) (*Entry, error)

func (*PostgresStorage) IsRestoring

func (b *PostgresStorage) IsRestoring(dbId string) (bool, error)

func (*PostgresStorage) IsUpgrading

func (b *PostgresStorage) IsUpgrading(dbId string) (bool, error)

func (*PostgresStorage) NukeInstance

func (b *PostgresStorage) NukeInstance(Id string) error

func (*PostgresStorage) PopPendingTask

func (b *PostgresStorage) PopPendingTask() (*Task, error)

func (*PostgresStorage) ReturnClaimedInstance

func (b *PostgresStorage) ReturnClaimedInstance(Id string) error

func (*PostgresStorage) StartProvisioningTasks

func (b *PostgresStorage) StartProvisioningTasks() ([]Entry, error)

func (*PostgresStorage) UpdateInstance

func (b *PostgresStorage) UpdateInstance(Instance *Instance, PlanId string) error

func (*PostgresStorage) UpdateTask

func (b *PostgresStorage) UpdateTask(Id string, status *string, retries *int64, metadata *string, result *string, started *time.Time, finsihed *time.Time) error

func (*PostgresStorage) ValidateInstanceID

func (b *PostgresStorage) ValidateInstanceID(id string) error

func (*PostgresStorage) WarnOnUnfinishedTasks

func (b *PostgresStorage) WarnOnUnfinishedTasks()

type Provider

type Provider interface {
	GetInstance(string, *ProviderPlan) (*Instance, error)
	Provision(string, *ProviderPlan, string) (*Instance, error)
	Deprovision(*Instance, bool) error
	Modify(*Instance, *ProviderPlan) (*Instance, error)
	Tag(*Instance, string, string) error
	Untag(*Instance, string) error
	PerformPostProvision(*Instance) (*Instance, error)
	GetUrl(*Instance) map[string]interface{}
}

func GetProviderByPlan

func GetProviderByPlan(namePrefix string, plan *ProviderPlan) (Provider, error)

type ProviderPlan

type ProviderPlan struct {
	Provider Providers `json:"provider"`

	ID     string `json:"id"`
	Scheme string `json:"scheme"`
	// contains filtered or unexported fields
}

type Providers

type Providers string
const (
	MongoDBInstance Providers = "mongodb"
	Unknown         Providers = "unknown"
)

func GetProvidersFromString

func GetProvidersFromString(str string) Providers

type ResourceSpec

type ResourceSpec struct {
	Name string `json:"name"`
}

type ResourceUrlSpec

type ResourceUrlSpec struct {
	Username string
	Password string
	Endpoint string
	Plan     string
}

type RestoreDbTaskMetadata

type RestoreDbTaskMetadata struct {
	Backup string `json:"backup"`
}

type Stat

type Stat struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Storage

type Storage interface {
	GetPlans(string) ([]ProviderPlan, error)
	GetPlanByID(string) (*ProviderPlan, error)
	GetInstance(string) (*Entry, error)
	AddInstance(*Instance) error
	DeleteInstance(*Instance) error
	UpdateInstance(*Instance, string) error
	AddTask(string, TaskAction, string) (string, error)
	GetServices() ([]osb.Service, error)
	UpdateTask(string, *string, *int64, *string, *string, *time.Time, *time.Time) error
	PopPendingTask() (*Task, error)
	GetUnclaimedInstance(string, string) (*Entry, error)
	ReturnClaimedInstance(string) error
	StartProvisioningTasks() ([]Entry, error)
	NukeInstance(string) error
	WarnOnUnfinishedTasks()
	IsRestoring(string) (bool, error)
	IsUpgrading(string) (bool, error)
	ValidateInstanceID(string) error
}

func InitFromOptions

func InitFromOptions(ctx context.Context, o Options) (Storage, string, error)

type Task

type Task struct {
	Id         string
	Action     TaskAction
	ResourceId string
	Status     string
	Retries    int64
	Metadata   string
	Result     string
	Started    *time.Time
	Finished   *time.Time
}

type TaskAction

type TaskAction string
const (
	DeleteTask                           TaskAction = "delete"
	ResyncFromProviderTask               TaskAction = "resync-from-provider"
	ResyncFromProviderUntilAvailableTask TaskAction = "resync-until-available"
	NotifyCreateServiceWebhookTask       TaskAction = "notify-create-service-webhook"
	NotifyCreateBindingWebhookTask       TaskAction = "notify-create-binding-webhook"
	ChangeProvidersTask                  TaskAction = "change-providers"
	ChangePlansTask                      TaskAction = "change-plans"
	RestoreDbTask                        TaskAction = "restore-database"
	PerformPostProvisionTask             TaskAction = "perform-post-provision"
)

type WebhookTaskMetadata

type WebhookTaskMetadata struct {
	Url    string `json:"url"`
	Secret string `json:"secret"`
}

Jump to

Keyboard shortcuts

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