Exemple #1
0
func InitInstaller() error {
	if installerinst, err := provisioner.InitializeProvisioner(conf.SystemConfig.Provisioners[bigfin_conf.ProviderName]); err != nil {
		logger.Get().Error("Unable to initialize the provisioner:%v", err)
		return err
	} else {
		installer_backend = installerinst
	}
	return nil
}
Exemple #2
0
func (a *App) StartProviders(configDir string, binDir string) error {
	key, err := ioutil.ReadFile(models.SKYRING_ENC_KEY_FILE)
	if err != nil {
		panic(fmt.Sprintf("Unable to read enc key file. err: %v", err))
	}

	providerBinaryPath := path.Join(binDir, conf.ProviderBinaryDir)

	configs := conf.LoadProviderConfig(path.Join(configDir, conf.ProviderConfDir))
	logger.Get().Info("Config:", configs)

	for _, config := range configs {
		logger.Get().Debug("Config:", config)

		//check if the routes are unique
		//Load the routes later after the provider starts
		//successfully, otherwise we have to remove the routes if the provider
		//fails to start
		var found bool
		for _, element := range config.Routes {
			if _, ok := a.routes[element.Name]; ok {
				logger.Get().Error("Error in Route configuration, Duplicate route: %s", element.Name)
				//Dont proceed further
				found = true
				break
			}
		}
		//If duplicate routes are detected, dont proceed loading this provider
		if found {
			logger.Get().Error("Duplicate routes detected, skipping the provider", config)
			continue
		}
		//Start the provider if configured
		if config.Provider != (conf.ProviderConfig{}) {

			if config.Provider.Name == "" {
				logger.Get().Error("Provider Name Empty, skipping the provider", config)
				continue
			}
			//check whether the plugin is initialized already
			if _, ok := a.providers[config.Provider.Name]; ok {
				//Provider already initialized
				logger.Get().Info("Provider already initialized, skipping the provider", config)
				continue
			}
			//Initilaize the provisioner
			prov, err := provisioner.InitializeProvisioner(config.Provisioner)
			if err != nil {
				logger.Get().Error("Unable to initialize the provisioner, skipping the provider:%v", config)
				continue
			}
			if config.Provider.ProviderBinary == "" {
				//set the default if not provided in config file
				config.Provider.ProviderBinary = path.Join(providerBinaryPath, config.Provider.Name)
			} else {
				config.Provider.ProviderBinary = path.Join(providerBinaryPath, config.Provider.ProviderBinary)
			}

			confStr, _ := json.Marshal(conf.SystemConfig)
			enConfStr, err := crypto.Encrypt(key, []byte(confStr))
			if err != nil {
				logger.Get().Error("Error encrypting the configurations. err: %v", err)
				continue
			}
			enConfStr1 := make([]byte, base64.StdEncoding.EncodedLen(len(enConfStr)))
			base64.StdEncoding.Encode(enConfStr1, []byte(enConfStr))

			eventTypesStr, _ := json.Marshal(EventTypes)
			providerConfStr, _ := json.Marshal(config)
			client, err := pie.StartProviderCodec(
				jsonrpc.NewClientCodec,
				os.Stderr,
				config.Provider.ProviderBinary,
				string(enConfStr1),
				string(eventTypesStr),
				string(providerConfStr))
			if err != nil {
				logger.Get().Error("Error starting provider for %s. error: %v", config.Provider.Name, err)
				continue
			}
			//Load the routes
			for _, element := range config.Routes {
				//prefix the provider name to the route
				element.Pattern = fmt.Sprintf("%s/%s", config.Provider.Name, element.Pattern)
				a.routes[element.Name] = element
			}

			//add the provider to the map
			a.providers[config.Provider.Name] = Provider{Name: config.Provider.Name, Client: client, ProvisionerName: prov}
		}
	}
	if len(a.providers) < 1 {
		return errors.New("None of the providers are initialized successfully")
	}
	return nil
}