<commit_before>/*Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package conf

import (
	"encoding/json"
	"github.com/op/go-logging"
	"github.com/skyrings/skyring-common/tools/logger"
	"io/ioutil"
	"path"
)

const (
	ProviderConfDir   = "providers.d"
	ProviderBinaryDir = "providers"
	aboutConfigFile   = "about.conf"
)

type SkyringConfig struct {
	Host              string `json:"host"`
	HttpPort          int    `json:"httpPort"`
	SSLEnabled        bool   `json:"sslEnabled"`
	SslPort           int    `json:"sslPort"`
	SslCert           string `json:"sslCert"`
	SslKey            string `json:"sslKey"`
	SupportedVersions []int  `json:"supportedversions"`
}

type SkyringLogging struct {
	LogToStderr bool          `json:"logToStderr"`
	Filename    string        `json:"filename"`
	Level       logging.Level `json:"level"`
}

type AuthConfig struct {
	ProviderName string
	ConfigFile   string
}

type ProvisionerConfig struct {
	ProvisionerName string `json:"provisionername"`
	ConfigFilePath  string `json:"configfilepath"`
	RedhatStorage   bool   `json:"redhatstorage"`
	RedhatUseCdn    bool   `json:"redhatusecdn"`
}

type SkyringCollection struct {
	Config               SkyringConfig                `json:"config"`
	Logging              SkyringLogging               `json:"logging"`
	NodeManagementConfig NodeManagerConfig            `json:"nodemanagementconfig"`
	DBConfig             AppDBConfig                  `json:"dbconfig"`
	TimeSeriesDBConfig   MonitoringDBconfig           `json:"timeseriesdbconfig"`
	Authentication       AuthConfig                   `json:"authentication"`
	SummaryConfig        SystemSummaryConfig          `json:"summary"`
	Provisioners         map[string]ProvisionerConfig `json:"provisioners"`
	SysCapabilities      SystemCapabilities           `json:"systemcapabilities"`
	ScheduleConfig       ScheduleConfig               `json:"schedule"`
}

type SystemSummaryConfig struct {
	NetSummaryInterval int `json:"netSummaryInterval"`
}

type ScheduleConfig struct {
	ClustersSyncInterval int `json:"clustersSyncInterval"`
}

type AppDBConfig struct {
	Hostname string `json:"hostname"`
	Port     int    `json:"port"`
	Database string `json:"database"`
	User     string `json:"user"`
	Password string `json:"password"`
}

type MonitoringDBconfig struct {
	Hostname       string `json:"hostname"`
	Port           int    `json:"port"`
	DataPushPort   int    `json:"dataPushPort"`
	CollectionName string `json:"collection_name"`
	User           string `json:"user"`
	Password       string `json:"password"`
	ManagerName    string `json:"managername"`
	ConfigFilePath string `json:"configfilepath"`
}

type NodeManagerConfig struct {
	ManagerName    string `json:"managername"`
	ConfigFilePath string `json:"configfilepath"`
}

type SystemCapabilities struct {
	ProductName            string            `bson:"productname",json:"productname"`
	ProductVersion         string            `bson:"productversion",json:"productversion"`
	StorageProviderDetails map[string]string `bson:"providerversion",json:"providerversion"`
	DbSoftware             string            `bson:"dbsoftware",json:"dbsoftware"`
	DbSoftwareVersion      string            `bson:"dbsoftwareversion",json:"dbsoftwareversion"`
}

var (
	SystemConfig SkyringCollection
)

func LoadAppConfiguration(configFilePath string, configFile string) {
	file, err := ioutil.ReadFile(path.Join(configFilePath, configFile))
	if err != nil {
		logger.Get().Critical("Error reading skyring config. error: %v", err)
		return
	}
	err = json.Unmarshal(file, &SystemConfig)
	if err != nil {
		logger.Get().Critical("Error unmarshalling skyring config. error: %v", err)
		return
	}
	//Initialize the Provisioner Map
	SystemConfig.Provisioners = make(map[string]ProvisionerConfig)
	//Initialize System_capabilities
	file, err = ioutil.ReadFile(path.Join(configFilePath, aboutConfigFile))
	if err != nil {
		logger.Get().Critical("Error reading about config. error: %v", err)
		return
	}
	err = json.Unmarshal(file, &SystemConfig.SysCapabilities)
	if err != nil {
		logger.Get().Critical("Error unmarshalling about config. error: %v", err)
		return<commit_msg>models: Added monitoring software details to SysCapabilities<commit_after>/*Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package conf

import (
	"encoding/json"
	"github.com/op/go-logging"
	"github.com/skyrings/skyring-common/tools/logger"
	"io/ioutil"
	"path"
)

const (
	ProviderConfDir   = "providers.d"
	ProviderBinaryDir = "providers"
	aboutConfigFile   = "about.conf"
)

type SkyringConfig struct {
	Host              string `json:"host"`
	HttpPort          int    `json:"httpPort"`
	SSLEnabled        bool   `json:"sslEnabled"`
	SslPort           int    `json:"sslPort"`
	SslCert           string `json:"sslCert"`
	SslKey            string `json:"sslKey"`
	SupportedVersions []int  `json:"supportedversions"`
}

type SkyringLogging struct {
	LogToStderr bool          `json:"logToStderr"`
	Filename    string        `json:"filename"`
	Level       logging.Level `json:"level"`
}

type AuthConfig struct {
	ProviderName string
	ConfigFile   string
}

type ProvisionerConfig struct {
	ProvisionerName string `json:"provisionername"`
	ConfigFilePath  string `json:"configfilepath"`
	RedhatStorage   bool   `json:"redhatstorage"`
	RedhatUseCdn    bool   `json:"redhatusecdn"`
}

type SkyringCollection struct {
	Config               SkyringConfig                `json:"config"`
	Logging              SkyringLogging               `json:"logging"`
	NodeManagementConfig NodeManagerConfig            `json:"nodemanagementconfig"`
	DBConfig             AppDBConfig                  `json:"dbconfig"`
	TimeSeriesDBConfig   MonitoringDBconfig           `json:"timeseriesdbconfig"`
	Authentication       AuthConfig                   `json:"authentication"`
	SummaryConfig        SystemSummaryConfig          `json:"summary"`
	Provisioners         map[string]ProvisionerConfig `json:"provisioners"`
	SysCapabilities      SystemCapabilities           `json:"systemcapabilities"`
	ScheduleConfig       ScheduleConfig               `json:"schedule"`
}

type SystemSummaryConfig struct {
	NetSummaryInterval int `json:"netSummaryInterval"`
}

type ScheduleConfig struct {
	ClustersSyncInterval int `json:"clustersSyncInterval"`
}

type AppDBConfig struct {
	Hostname string `json:"hostname"`
	Port     int    `json:"port"`
	Database string `json:"database"`
	User     string `json:"user"`
	Password string `json:"password"`
}

type MonitoringDBconfig struct {
	Hostname       string `json:"hostname"`
	Port           int    `json:"port"`
	DataPushPort   int    `json:"dataPushPort"`
	CollectionName string `json:"collection_name"`
	User           string `json:"user"`
	Password       string `json:"password"`
	ManagerName    string `json:"managername"`
	ConfigFilePath string `json:"configfilepath"`
}

type NodeManagerConfig struct {
	ManagerName    string `json:"managername"`
	ConfigFilePath string `json:"configfilepath"`
}

type SystemCapabilities struct {
	ProductName            string            `bson:"productname",json:"productname"`
	ProductVersion         string            `bson:"productversion",json:"productversion"`
	StorageProviderDetails map[string]string `bson:"providerversion",json:"providerversion"`
	DbSoftware             string            `bson:"dbsoftware",json:"dbsoftware"`
	DbSoftwareVersion      string            `bson:"dbsoftwareversion",json:"dbsoftwareversion"`
	MonitoringSoftware     string            `bson:"monitoringsoftware",json:"monitoringsoftware"`
	MonitoringSoftwareVer  string            `bson:"monitoringsoftwarever",json:"monitoringsoftwarever"`
}

var (
	SystemConfig SkyringCollection
)

func LoadAppConfiguration(configFilePath string, configFile string) {
	file, err := ioutil.ReadFile(path.Join(configFilePath, configFile))
	if err != nil {
		logger.Get().Critical("Error reading skyring config. error: %v", err)
		return
	}
	err = json.Unmarshal(file, &SystemConfig)
	if err != nil {
		logger.Get().Critical("Error unmarshalling skyring config. error: %v", err)
		return
	}
	//Initialize the Provisioner Map
	SystemConfig.Provisioners = make(map[string]ProvisionerConfig)
	//Initialize System_capabilities
	file, err = ioutil.ReadFile(path.Join(configFilePath, aboutConfigFile))
	if err != nil {
		logger.Get().Critical("Error reading about config. error: %v", err)
		return
	}
	err = json.Unmarshal(file, &SystemConfig.SysCapabilities)
	if err != nil {
		logger.Get().Critical("Error unmarshalling about config. error: %v", err)
		return
{'fraction_non_alphanumeric': 0.09859749024570284, 'fraction_numerical': 0.000843614889802805, 'mean_word_length': 3.6950495049504952, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3456124', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2626, 'n_words': 695}