Example #1
0
// NewManager initializes and returns an instance of the Manager. It returns nil
// if a failure occurs as part of initialization.
func NewManager(config *Config, configFile string) (*Manager, error) {
	if config == nil {
		return nil, errored.Errorf("nil config passed")
	}

	var err error
	config.Ansible.ExtraVariables, err = validateAndSanitizeEmptyExtraVars(
		"ansible.ExtraVariables configuration", config.Ansible.ExtraVariables)
	if err != nil {
		return nil, err
	}

	m := &Manager{
		monitor:       monitor.NewSerfSubsys(&config.Serf),
		configuration: configuration.NewAnsibleSubsys(&config.Ansible),
		reqQ:          make(chan event, 100),
		addr:          config.Manager.Addr,
		nodes:         make(map[string]*node),
		config:        config,
		configFile:    configFile,
	}
	// We give priority to boltdb inventory if both are set in config
	if config.Inventory.BoltDB != nil {
		if m.inventory, err = boltdbinv.NewBoltdbSubsys(*config.Inventory.BoltDB); err != nil {
			return nil, err
		}
	} else if config.Inventory.Collins != nil {
		if m.inventory, err = collinsinv.NewCollinsSubsys(*config.Inventory.Collins); err != nil {
			return nil, err
		}
	} else {
		// if no inventory config was provided then we default to boltDb
		if m.inventory, err = boltdbinv.NewBoltdbSubsys(boltdb.DefaultConfig()); err != nil {
			return nil, err
		}
	}

	if err := m.monitor.RegisterCb(monitor.Discovered, m.enqueueMonitorEvent); err != nil {
		return nil, errored.Errorf("failed to register node discovery callback. Error: %s", err)
	}

	if err := m.monitor.RegisterCb(monitor.Disappeared, m.enqueueMonitorEvent); err != nil {
		return nil, errored.Errorf("failed to register node disappearance callback. Error: %s", err)
	}

	return m, nil
}
Example #2
0
func (s *SystemTestSuite) nukeNodesInBoltdb(c *C) {
	dbfile := boltdb.DefaultConfig().DBFile
	out, err := s.tbn1.RunCommandWithOutput(fmt.Sprintf("sudo rm -f %s", dbfile))
	c.Logf("boltdb asset deletion result: %v. Output: %s", err, out)
}