Example #1
0
func (plugin *Plugin) ReConnect() error {

	// Connect to the plugin
	pluginConn, connErr := PluginConn.NewPluginClient(plugin.PluginSock)
	if connErr != nil {
		plugin.connected = false
		return fmt.Errorf("Failed to reconnect: %v", connErr)
	}
	// Set connection object
	plugin.pluginConn = pluginConn
	plugin.connected = true

	return nil
}
Example #2
0
/* Load the plugin to the plugin Registry explicitly when lazy load is active.
(if The discovery Process is not running, It search for the plugin and then load it to the registry)
*/
func (pluginReg *PluginReg) LoadPlugin(namespace string, name string, version string) (*Plugin, error) {

	// Get the plugin tar location
	tarFold := pluginLoc

	// Runtime Conf file
	confFile := filepath.Join(tarFold, DefaultPluginiRuntimeConfFile)

	// Create RuntimeConf
	pluginConf := common.RuntimeConf{}
	StartPath := "./" + PluginBinary
	pluginConf.Url = PluginUrl
	pluginConf.Sock = PluginSockFile

	// Save new plugin Conf
	confSaveError := common.SaveRuntimeConfigs(confFile, pluginConf)
	if confSaveError != nil {
		log.ERROR.Println("Configuration load failed for file: ", confFile, ", Error: ", confSaveError)
		return nil, SaveConfError
	}

	// get the start path
	startPath := filepath.Join(tarFold, StartPath)

	// Start the Plugin
	log.DEBUG.Printf("Starting plugin: %s\n", startPath)
	pid, startErr := pluginReg.startPlugin(startPath)
	if startErr != nil {
		log.ERROR.Println("Failed to start the plugin: ", startErr)
	}

	// get the unix socket file path
	sockFile := filepath.Join(tarFold, pluginConf.Sock)

	retryCount := 0
	var pluginConn *PluginConn.PluginClient = nil
	time.Sleep(DefaultInterval * 4)
	for retryCount < ConnRetryCount {
		var connErr error
		// Initiate Connection to a Plugin
		log.DEBUG.Printf("Trying to connect: %s\n", sockFile)
		pluginConn, connErr = PluginConn.NewPluginClient(sockFile)
		if connErr == nil {
			break
		}
		retryCount++
		// Sleep for a delay
		time.Sleep(DefaultInterval)
	}
	if pluginConn == nil {
		return nil, PluginConnFailed
	}

	plugin := &Plugin{}
	plugin.PluginSock = sockFile
	plugin.PluginUrl = pluginConf.Url
	plugin.pluginConn = pluginConn
	plugin.connected = true
	plugin.callbacks = make(map[string]bool)
	// set the plugin instance process id
	plugin.pid = pid
	plugin.pluginloc = pluginLoc

	// Activate the plugin
	activateErr := plugin.activate()
	if activateErr != nil {
		return plugin, activateErr
	}

	return plugin, nil
}