本文整理汇总了Golang中github.com/skyrings/skyring/tools/logger.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handle_node_start_event
func handle_node_start_event(node string) error {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
var storage_node models.Node
_ = coll.Find(bson.M{"hostname": node}).One(&storage_node)
if storage_node.State != models.NODE_STATE_INITIALIZING {
logger.Get().Warning(fmt.Sprintf("Node with name: %s not in activating state to update other details", node))
return nil
}
asyncTask := func(t *task.Task) {
t.UpdateStatus("started the task for InitializeNode: %s", t.ID)
// Process the request
if err := initializeStorageNode(node, t); err != nil {
t.UpdateStatus("Failed")
t.Done(models.TASK_STATUS_FAILURE)
} else {
t.UpdateStatus("Success")
t.Done(models.TASK_STATUS_SUCCESS)
}
}
if taskId, err := skyring.GetApp().GetTaskManager().Run(fmt.Sprintf("Initialize Node: %s", node), asyncTask, nil, nil, nil); err != nil {
logger.Get().Error("Unable to create the task for Initialize Node: %s. error: %v", node, err)
} else {
logger.Get().Debug("Task created for initialize node. Task id: %s", taskId.String())
}
return nil
}
示例2: sync_cluster_status
func sync_cluster_status(cluster models.Cluster, provider *Provider) (bool, error) {
var result models.RpcResponse
vars := make(map[string]string)
vars["cluster-id"] = cluster.ClusterId.String()
err = provider.Client.Call(provider.Name+".GetClusterStatus", models.RpcRequest{RpcRequestVars: vars, RpcRequestData: []byte{}}, &result)
if err != nil || result.Status.StatusCode != http.StatusOK {
logger.Get().Error("Error getting status for cluster: %s. error:%v", cluster.Name, err)
return false, err
} else {
statusMsg := result.Status.StatusMessage
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
var clusterStatus int
switch statusMsg {
case models.STATUS_OK:
clusterStatus = models.CLUSTER_STATUS_OK
case models.STATUS_WARN:
clusterStatus = models.CLUSTER_STATUS_WARN
case models.STATUS_ERR:
clusterStatus = models.CLUSTER_STATUS_ERROR
}
// Set the cluster status
logger.Get().Info("Updating the status of the cluster: %s to %d", cluster.Name, clusterStatus)
if err := coll.Update(bson.M{"clusterid": cluster.ClusterId}, bson.M{"$set": bson.M{"status": clusterStatus}}); err != nil {
return false, err
}
}
return true, nil
}
示例3: initializeStorageNode
func initializeStorageNode(node string, t *task.Task) error {
sProfiles, err := skyring.GetDbProvider().StorageProfileInterface().StorageProfiles(nil, models.QueryOps{})
if err != nil {
logger.Get().Error("Unable to get the storage profiles. May not be able to apply storage profiles for node: %v err:%v", node, err)
}
if storage_node, ok := saltnodemanager.GetStorageNodeInstance(node, sProfiles); ok {
if err := updateStorageNodeToDB(*storage_node); err != nil {
logger.Get().Error("Unable to add details of node: %s to DB. error: %v", node, err)
t.UpdateStatus("Unable to add details of node: %s to DB. error: %v", node, err)
updateNodeState(node, models.NODE_STATE_FAILED)
return err
}
if nodeErrorMap, configureError := skyring.GetCoreNodeManager().SetUpMonitoring(node, curr_hostname); configureError != nil && len(nodeErrorMap) != 0 {
if len(nodeErrorMap) != 0 {
logger.Get().Error("Unable to setup collectd on %s because of %v", node, nodeErrorMap)
t.UpdateStatus("Unable to setup collectd on %s because of %v", node, nodeErrorMap)
updateNodeState(node, models.NODE_STATE_FAILED)
return err
} else {
logger.Get().Error("Config Error during monitoring setup for node:%s Error:%v", node, configureError)
t.UpdateStatus("Config Error during monitoring setup for node:%s Error:%v", node, configureError)
updateNodeState(node, models.NODE_STATE_FAILED)
return err
}
}
return nil
} else {
logger.Get().Critical("Error getting the details for node: %s", node)
t.UpdateStatus("Error getting the details for node: %s", node)
updateNodeState(node, models.NODE_STATE_FAILED)
return fmt.Errorf("Error getting the details for node: %s", node)
}
}
示例4: SyncClusterDetails
func (a *App) SyncClusterDetails() {
// Get the list of cluster
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
var clusters models.Clusters
if err := coll.Find(nil).All(&clusters); err != nil {
logger.Get().Error("Error getting the clusters list. Unable to sync details. error: %v", err)
return
}
for _, cluster := range clusters {
provider := a.getProviderFromClusterId(cluster.ClusterId)
if provider == nil {
logger.Get().Error("Error getting provider for the cluster: %s", cluster.Name)
continue
}
// Sync the cluster status
if ok, err := sync_cluster_status(cluster, provider); err != nil || !ok {
logger.Get().Error("Error updating status for cluster: %s", cluster.Name)
}
// TODO:: Sync the nodes status
if ok, err := sync_cluster_nodes(cluster, provider); err != nil && !ok {
logger.Get().Error("Error syncing node details for cluster: %s. error: %v", cluster.Name, err)
}
// TODO:: Sync the storage entities of the cluster
if ok, err := sync_cluster_storage_entities(cluster, provider); err != nil && !ok {
logger.Get().Error("Error syncing storage entities for cluster: %s. error: %v", cluster.Name, err)
}
}
}
示例5: InitializeApplication
/*
Initialize the application
*/
func (a *App) InitializeApplication(sysConfig conf.SkyringCollection) error {
if err := initializeNodeManager(sysConfig.NodeManagementConfig); err != nil {
logger.Get().Error("Unable to create node manager")
return err
}
/*
TODO : This will be removed after porting all the existing things into newer scheme
*/
// Create DB session
if err := db.InitDBSession(sysConfig.DBConfig); err != nil {
logger.Get().Error("Unable to initialize DB")
return err
}
if err := db.InitMonitoringDB(sysConfig.TimeSeriesDBConfig); err != nil {
logger.Get().Error("Unable to initialize monitoring DB")
return err
}
//Initialize the DB provider
if err := initializeDb(sysConfig.DBConfig); err != nil {
logger.Get().Error("Unable to initialize the authentication provider: %s", err)
return err
}
//Initialize the auth provider
if err := initializeAuth(sysConfig.Authentication); err != nil {
logger.Get().Error("Unable to initialize the authentication provider: %s", err)
return err
}
//Initialize the task manager
if err := initializeTaskManager(); err != nil {
logger.Get().Error("Unable to initialize the task manager: %s", err)
return err
}
//Initialize the lock manager
if err := initializeLockManager(); err != nil {
logger.Get().Error("Unable to initialize the lock manager: %s", err)
return err
}
//Initialize the Defaults
if err := initializeDefaults(); err != nil {
logger.Get().Error("Unable to initialize the Defaults: %s", err)
return err
}
if err := application.initializeMonitoringManager(sysConfig.TimeSeriesDBConfig); err != nil {
logger.Get().Error("Unable to create monitoring manager")
os.Exit(1)
}
logger.Get().Info("Starting clusters syncing")
go a.SyncClusterDetails()
go InitSchedules()
return nil
}
示例6: GET_Node
func (a *App) GET_Node(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
node_id_str := vars["node-id"]
node_id, err := uuid.Parse(node_id_str)
if err != nil {
logger.Get().Error("Error parsing node id: %s", node_id_str)
util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing node id: %s", node_id_str))
return
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
var node models.Node
if err := collection.Find(bson.M{"nodeid": *node_id}).One(&node); err != nil {
logger.Get().Error("Error getting the node detail for %v. error: %v", *node_id, err)
}
if node.Hostname == "" {
util.HttpResponse(w, http.StatusBadRequest, "Node not found")
logger.Get().Error("Node: %v not found. error: %v", *node_id, err)
return
} else {
json.NewEncoder(w).Encode(node)
}
}
示例7: getUser
func (a *App) getUser(rw http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
user, err := GetAuthProvider().GetUser(vars["username"], req)
if err != nil {
logger.Get().Error("Unable to Get the user:%s", err)
util.HandleHttpError(rw, err)
return
}
//hide the hash field
bytes, err := json.Marshal(struct {
*models.User
Hash bool `json:"hash,omitempty"`
}{
User: &user,
})
if err != nil {
logger.Get().Error("Unable to marshal the User:%s", err)
util.HandleHttpError(rw, err)
return
}
rw.Write(bytes)
}
示例8: AddStorageNodeToDB
func AddStorageNodeToDB(hostname string, node_state int, node_status string) error {
// Add the node details to the DB
var storage_node models.Node
storage_node.Hostname = hostname
storage_node.State = node_state
storage_node.Status = node_status
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
var node models.Node
err = coll.Find(bson.M{"hostname": storage_node.Hostname}).One(&node)
if err != mgo.ErrNotFound {
logger.Get().Critical(fmt.Sprintf("Node with name: %v already exists", storage_node.Hostname))
return errors.New(fmt.Sprintf("Node with name: %v already exists", storage_node.Hostname))
}
// Persist the node details
if err := coll.Insert(storage_node); err != nil {
logger.Get().Critical("Error adding the node: %s. error: %v", storage_node.Hostname, err)
return err
}
return nil
}
示例9: NewLocalAuthProvider
func NewLocalAuthProvider(config io.Reader) (*Authorizer, error) {
if config == nil {
logger.Get().Error("missing configuration file for Local Auth provider")
return nil, fmt.Errorf("missing configuration file for Local Auth provider")
}
providerCfg := LocalProviderCfg{}
bytes, err := ioutil.ReadAll(config)
if err != nil {
logger.Get().Error("Error reading configuration file. error: %v", err)
return nil, err
}
if err = json.Unmarshal(bytes, &providerCfg); err != nil {
logger.Get().Error("Unable to Unmarshall the data. error: %v", err)
return nil, err
}
//Create DB Backend
userDao := skyring.GetDbProvider().UserInterface()
//Create the Provider
if provider, err := NewAuthorizer(userDao, providerCfg.DefaultRole, providerCfg.Roles); err != nil {
logger.Get().Error("Unable to initialize the authorizer for localauthprovider. error: %v", err)
panic(err)
} else {
return &provider, nil
}
}
示例10: GET_Storages
func (a *App) GET_Storages(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
cluster_id_str := vars["cluster-id"]
cluster_id, err := uuid.Parse(cluster_id_str)
if err != nil {
logger.Get().Error("Error parsing the cluster id: %s. error: %v", cluster_id_str, err)
util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing the cluster id: %s", cluster_id_str))
return
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE)
var storages models.Storages
if err := collection.Find(bson.M{"clusterid": *cluster_id}).All(&storages); err != nil {
util.HttpResponse(w, http.StatusInternalServerError, err.Error())
logger.Get().Error("Error getting the storage list for cluster: %v. error: %v", *cluster_id, err)
return
}
if len(storages) == 0 {
json.NewEncoder(w).Encode(models.Storages{})
} else {
json.NewEncoder(w).Encode(storages)
}
}
示例11: GET_Storage
func (a *App) GET_Storage(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
cluster_id_str := vars["cluster-id"]
cluster_id, err := uuid.Parse(cluster_id_str)
if err != nil {
logger.Get().Error("Error parsing the cluster id: %s. error: %v", cluster_id_str, err)
util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing the cluster id: %s", cluster_id_str))
return
}
storage_id_str := vars["storage-id"]
storage_id, err := uuid.Parse(storage_id_str)
if err != nil {
logger.Get().Error("Error parsing the storage id: %s. error: %v", storage_id_str, err)
util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing the storage id: %s", storage_id_str))
return
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE)
var storage models.Storage
if err := collection.Find(bson.M{"clusterid": *cluster_id, "storageid": *storage_id}).One(&storage); err != nil {
util.HttpResponse(w, http.StatusInternalServerError, err.Error())
logger.Get().Error("Error getting the storage: %v on cluster: %v. error: %v", *storage_id, *cluster_id, err)
return
}
if storage.Name == "" {
util.HttpResponse(w, http.StatusBadRequest, "Storage not found")
logger.Get().Error("Storage with id: %v not found for cluster: %v. error: %v", *storage_id, *cluster_id, err)
return
} else {
json.NewEncoder(w).Encode(storage)
}
}
示例12: InitDbProvider
// InitPlugin creates an instance of the named plugin.
func InitDbProvider(name string, configFilePath string) (DbInterface, error) {
var dbprovider DbInterface
if name == "" {
logger.Get().Info("No providers specified.")
return nil, nil
}
var err error
if configFilePath != "" {
config, err := os.Open(configFilePath)
if err != nil {
logger.Get().Critical("Couldn't open Db provider configuration %s: %v",
configFilePath, err)
}
defer config.Close()
dbprovider, err = GetDbProvider(name, config)
} else {
// Pass explicit nil so providers can actually check for nil. See
// "Why is my nil error value not equal to nil?" in golang.org/doc/faq.
dbprovider, err = GetDbProvider(name, nil)
}
if err != nil {
return nil, fmt.Errorf("could not initialize Db Provider %q: %v", name, err)
}
if dbprovider == nil {
return nil, fmt.Errorf("unknown Db Provider %q", name)
}
return dbprovider, nil
}
示例13: POST_StorageProfiles
func (a *App) POST_StorageProfiles(w http.ResponseWriter, r *http.Request) {
var request models.StorageProfile
// Unmarshal the request body
body, err := ioutil.ReadAll(io.LimitReader(r.Body, models.REQUEST_SIZE_LIMIT))
if err != nil {
logger.Get().Error("Error parsing the request: %v", err)
util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Unable to parse the request: %v", err))
return
}
if err := json.Unmarshal(body, &request); err != nil {
logger.Get().Error("Error Unmarshalling the request: %v", err)
util.HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Unable to unmarshal request: %v", err))
return
}
if (request == models.StorageProfile{}) {
logger.Get().Error("Invalid request")
util.HttpResponse(w, http.StatusBadRequest, "Invalid request")
return
}
// Check if storage profile already added
if _, err := GetDbProvider().StorageProfileInterface().StorageProfile(request.Name); err == nil {
logger.Get().Error("Storage profile already added: %v", err)
util.HttpResponse(w, http.StatusMethodNotAllowed, "Storage profile already added")
return
}
if err := GetDbProvider().StorageProfileInterface().SaveStorageProfile(request); err != nil {
logger.Get().Error("Storage profile add failed: %v", err)
util.HttpResponse(w, http.StatusInternalServerError, err.Error())
return
}
return
}
示例14: SyncStorageDisks
func (a SaltNodeManager) SyncStorageDisks(node string, sProfiles []models.StorageProfile) (bool, error) {
disks, err := salt_backend.GetNodeDisk(node)
if err != nil {
return false, err
}
for _, disk := range disks {
dId, err := uuid.New()
if err != nil {
logger.Get().Error(fmt.Sprintf("Unable to generate uuid for disk : %s. error: %v", disk.DevName, err))
return false, err
}
disk.DiskId = *dId
applyStorageProfile(&disk, sProfiles)
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
if len(disks) != 0 {
if err := coll.Update(bson.M{"hostname": node}, bson.M{"$set": bson.M{"storagedisks": disks}}); err != nil {
logger.Get().Error("Error updating the disk details for node: %s. error: %v", node, err)
return false, err
}
}
return true, nil
}
示例15: GET_Nodes
func (a *App) GET_Nodes(w http.ResponseWriter, r *http.Request) {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
params := r.URL.Query()
admin_state_str := params.Get("state")
collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
var nodes models.Nodes
if admin_state_str == "" {
if err := collection.Find(nil).All(&nodes); err != nil {
util.HttpResponse(w, http.StatusInternalServerError, err.Error())
logger.Get().Error("Error getting the nodes list. error: %v", err)
return
}
} else {
nodes, err = getNodesWithState(w, admin_state_str)
if err != nil {
util.HttpResponse(w, http.StatusInternalServerError, err.Error())
logger.Get().Error("Error getting the nodes list. error: %v", err)
return
}
}
if len(nodes) == 0 {
json.NewEncoder(w).Encode([]models.Node{})
} else {
json.NewEncoder(w).Encode(nodes)
}
}