示例#1
0
// Init initializes the master daemon
func (d *MasterDaemon) Init() {
	// set cluster mode
	err := master.SetClusterMode(d.ClusterMode)
	if err != nil {
		log.Fatalf("Failed to set cluster-mode. Error: %s", err)
	}

	// save dns flag
	err = master.SetDNSEnabled(d.DNSEnabled)
	if err != nil {
		log.Fatalf("Failed to set dns-enable. Error: %s", err)
	}

	// initialize state driver
	d.stateDriver, err = initStateDriver(d.ClusterStore)
	if err != nil {
		log.Fatalf("Failed to init state-store. Error: %s", err)
	}

	// Initialize resource manager
	d.resmgr, err = resources.NewStateResourceManager(d.stateDriver)
	if err != nil {
		log.Fatalf("Failed to init resource manager. Error: %s", err)
	}

	// Create an objdb client
	d.objdbClient, err = objdb.NewClient(d.ClusterStore)
	if err != nil {
		log.Fatalf("Error connecting to state store: %v. Err: %v", d.ClusterStore, err)
	}
}
示例#2
0
func (d *daemon) registerService() {
	// Create an objdb client
	objdbClient := objdb.NewClient("")

	// Get the address to be used for local communication
	localIP, err := objdbClient.GetLocalAddr()
	if err != nil {
		log.Fatalf("Error getting local IP address. Err: %v", err)
	}

	// service info
	srvInfo := objdb.ServiceInfo{
		ServiceName: "netmaster",
		HostAddr:    localIP,
		Port:        9999,
	}

	// Register the node with service registry
	err = objdbClient.RegisterService(srvInfo)
	if err != nil {
		log.Fatalf("Error registering service. Err: %v", err)
	}

	log.Infof("Registered netmaster service with registry")
}
示例#3
0
文件: modeldb.go 项目: jojimt/objdb
// Init initializes the modeldb
func Init(dbURL string) {
	var err error
	cdb, err = objdb.NewClient(dbURL)
	if err != nil {
		log.Fatalf("Error creating db client to URL: %s", dbURL)
	}
}
示例#4
0
文件: daemon.go 项目: vvb/netplugin
// runMasterFsm runs netmaster FSM
func (d *daemon) runMasterFsm() {
	// create new ofnet master
	d.ofnetMaster = ofnet.NewOfnetMaster(ofnet.OFNET_MASTER_PORT)
	if d.ofnetMaster == nil {
		log.Fatalf("Error creating ofnet master")
	}

	// Create an objdb client
	d.objdbClient = objdb.NewClient("")

	// Get the address to be used for local communication
	localIP, err := d.objdbClient.GetLocalAddr()
	if err != nil {
		log.Fatalf("Error getting local IP address. Err: %v", err)
	}

	// Create the lock
	leaderLock, err = d.objdbClient.NewLock("netmaster/leader", localIP, leaderLockTTL)
	if err != nil {
		log.Fatalf("Could not create leader lock. Err: %v", err)
	}

	// Try to acquire the lock
	err = leaderLock.Acquire(0)
	if err != nil {
		// We dont expect any error during acquire.
		log.Fatalf("Error while acquiring lock. Err: %v", err)
	}

	// Initialize the stop channel
	d.stopLeaderChan = make(chan bool, 1)
	d.stopFollowerChan = make(chan bool, 1)

	// set current state
	d.currState = "follower"

	// Start off being a follower
	go d.runFollower()

	// Main run loop waiting on leader lock
	for {
		// Wait for lock events
		select {
		case event := <-leaderLock.EventChan():
			if event.EventType == objdb.LockAcquired {
				log.Infof("Leader lock acquired")

				d.becomeLeader()
			} else if event.EventType == objdb.LockLost {
				log.Infof("Leader lock lost. Becoming follower")

				d.becomeFollower()
			}
		}
	}
}
示例#5
0
// Init initializes the cluster module
func Init(storeURL string) error {
	var err error

	// Create an objdb client
	ObjdbClient, err = objdb.NewClient(storeURL)
	if err != nil {
		return err
	}

	return nil
}
示例#6
0
// Init initializes the cluster module
func Init(netplugin *plugin.NetPlugin, localIP string) error {
	// Create an objdb client
	objdbClient := objdb.NewClient("")

	// Register ourselves
	registerService(objdbClient, localIP)

	// Start peer discovery loop
	go peerDiscoveryLoop(netplugin, objdbClient, localIP)

	return nil
}
示例#7
0
// GetLocalAddr gets local address to be used
func GetLocalAddr() (string, error) {
	// Get objdb's client IP
	clientIP, err := objdb.NewClient("").GetLocalAddr()
	if err != nil {
		log.Warnf("Error getting local address from objdb. Returning first local address. Err: %v", err)

		return netutils.GetFirstLocalAddr()
	}

	// Make sure the ip address is local
	if netutils.IsAddrLocal(clientIP) {
		return clientIP, nil
	}

	// Return first available address if client IP is not local
	return netutils.GetFirstLocalAddr()
}
示例#8
0
// Init initializes the cluster module
func Init(netplugin *plugin.NetPlugin, ctrlIP, vtepIP, storeURL string) error {
	var err error

	// Create an objdb client
	objdbClient, err = objdb.NewClient(storeURL)
	if err != nil {
		return err
	}

	// Register ourselves
	registerService(objdbClient, ctrlIP, vtepIP)

	// Start peer discovery loop
	go peerDiscoveryLoop(netplugin, objdbClient, ctrlIP, vtepIP)

	return nil
}
示例#9
0
文件: cluster.go 项目: vvb/netplugin
// getMasterLockHolder returns the IP of current master lock hoder
func getMasterLockHolder() (string, error) {
	// Create an objdb client
	objdbClient := objdb.NewClient("")

	// Create the lock
	leaderLock, err := objdbClient.NewLock("netmaster/leader", "", 0)
	if err != nil {
		log.Fatalf("Could not create leader lock. Err: %v", err)
	}

	// get current holder of leader lock
	masterNode := leaderLock.GetHolder()
	if masterNode == "" {
		log.Errorf("No leader node found")
		return "", errors.New("No leader node")
	}

	return masterNode, nil
}
示例#10
0
// RemoveLinkSet removes a link from linkset
func RemoveLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
	// check is linkset is nil
	if *linkSet == nil {
		return nil
	}

	// remove the link from map
	delete(*linkSet, obj.GetKey())

	return nil
}

// persistent database
var cdb = objdb.NewClient("")

// WriteObj writes the model to DB
func WriteObj(objType, objKey string, value interface{}) error {
	key := "/modeldb/" + objType + "/" + objKey
	err := cdb.SetObj(key, value)
	if err != nil {
		log.Errorf("Error storing object %s. Err: %v", key, err)
		return err
	}

	return nil
}

// ReadObj reads an object from DB
func ReadObj(objType, objKey string, retVal interface{}) error {