Ejemplo n.º 1
0
// NewBroker is a constructor for a Broker webapp struct
func NewBroker(config *config.Config) (*Broker, error) {
	bkr := &Broker{
		config:  config.Broker,
		catalog: config.Catalog,
		backups: config.Backups,
		cells:   config.Scheduler.Cells,
	}

	bkr.logger = bkr.setupLogger()
	bkr.callbacks = NewCallbacks(config.Callbacks, bkr.logger)
	var err error
	bkr.state, err = state.NewStateEtcd(config.Etcd, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-state.error", err)
		return nil, err
	}

	bkr.patroni, err = patroni.NewPatroni(config.Etcd, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-patroni.error", err)
		return nil, err
	}

	bkr.scheduler, err = scheduler.NewScheduler(config.Scheduler, bkr.patroni, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-scheduler.error", err)
		return nil, err
	}

	bkr.router, err = routing.NewRouter(config.Etcd, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-router.error", err)
		return nil, err
	}

	// Optionally, provisioned services can asynchronously look up service name
	// to aide disaster recovery/undo-delete/recreate-from-backup by users
	// that only recall the service instance name they provided Cloud Foundry
	bkr.cf, err = NewCloudFoundryFromConfig(config.CloudFoundry, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-cf.error", err)
	} else {
		bkr.logger.Info("new-broker.new-cf.success", lager.Data{"api-url": config.CloudFoundry.ApiAddress})
	}

	return bkr, nil
}
func NewStateEtcdWithPrefix(etcdConfig config.Etcd, prefix string, logger lager.Logger) (*StateEtcd, error) {
	state := &StateEtcd{
		prefix: prefix,
		logger: logger,
	}

	patroniClient, err := patroni.NewPatroni(etcdConfig, logger)
	if err != nil {
		return nil, err
	}
	state.patroni = patroniClient

	state.etcdApi, err = state.setupEtcd(etcdConfig)
	if err != nil {
		return nil, err
	}

	return state, nil
}
func NewScheduler(config config.Scheduler, logger lager.Logger) (*Scheduler, error) {
	s := &Scheduler{
		config: config,
		logger: logger,
	}

	patroni, err := patroni.NewPatroni(config.Etcd, s.logger)
	if err != nil {
		return nil, err
	}
	s.patroni = patroni

	clusterLoader, err := state.NewStateEtcd(config.Etcd, s.logger)
	if err != nil {
		return nil, err
	}
	s.cells = cells.NewCells(config.Cells, clusterLoader)

	return s, nil
}
Ejemplo n.º 4
0
// NewBroker is a constructor for a Broker webapp struct
func NewBroker(config *config.Config) (*Broker, error) {
	bkr := &Broker{
		config:     config.Broker,
		catalog:    config.Catalog,
		etcdConfig: config.Etcd,
		cells:      config.Scheduler.Cells,
	}

	bkr.logger = bkr.setupLogger()
	bkr.callbacks = NewCallbacks(config.Callbacks, bkr.logger)
	var err error
	bkr.scheduler, err = scheduler.NewScheduler(config.Scheduler, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-scheduler.error", err)
		return nil, err
	}
	bkr.state, err = state.NewStateEtcd(config.Etcd, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-state.error", err)
		return nil, err
	}

	bkr.patroni, err = patroni.NewPatroni(config.Etcd, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-patroni.error", err)
		return nil, err
	}

	bkr.router, err = routing.NewRouter(config.Etcd, bkr.logger)
	if err != nil {
		bkr.logger.Error("new-broker.new-router.error", err)
		return nil, err
	}

	return bkr, nil
}