本文整理汇总了Golang中github.com/skyrings/skyring-common/tools/logger.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getLdapConfig
func (a *App) getLdapConfig(rw http.ResponseWriter, req *http.Request) {
ctxt, err := GetContext(req)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
ldapConfig, err := GetAuthProvider().GetDirectory()
if err != nil {
logger.Get().Error("%s-Unable to reterive directory service configuration:%s", ctxt, err)
HandleHttpError(rw, err)
return
}
json.NewEncoder(rw).Encode(
struct {
LdapServer string `json:"ldapserver"`
Port uint `json:"port"`
Base string `json:"base"`
Type string `json:"ldaptype"`
DomainAdmin string `json:"domainadmin"`
Password string `json:"password"`
Uid string `json:"uid"`
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
DisplayName string `json:"displayname"`
Email string `json:"email"`
}{ldapConfig.LdapServer, ldapConfig.Port, ldapConfig.Base, ldapConfig.Type,
ldapConfig.DomainAdmin, "", ldapConfig.Uid, ldapConfig.FirstName,
ldapConfig.LastName, ldapConfig.DisplayName, ldapConfig.Email})
}
示例2: CreateDefaultECProfiles
func CreateDefaultECProfiles(ctxt string, mon string, clusterId uuid.UUID) (bool, error) {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
var cluster models.Cluster
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
if err := coll.Find(bson.M{"clusterid": clusterId}).One(&cluster); err != nil {
logger.Get().Error("%s-Error getting cluster details for %v. error: %v", ctxt, clusterId, err)
return false, err
}
var cmdMap map[string]string = map[string]string{
"4+2": fmt.Sprintf("ceph osd erasure-code-profile set k4m2 plugin=jerasure k=4 m=2 --cluster %s", cluster.Name),
"6+3": fmt.Sprintf("ceph osd erasure-code-profile set k6m3 plugin=jerasure k=6 m=3 --cluster %s", cluster.Name),
"8+4": fmt.Sprintf("ceph osd erasure-code-profile set k8m4 plugin=jerasure k=8 m=4 --cluster %s", cluster.Name),
}
for k, v := range cmdMap {
ok, _, err := cephapi_backend.ExecCmd(mon, clusterId, v, ctxt)
if err != nil || !ok {
logger.Get().Error("%s-Error creating EC profile for %s. error: %v", ctxt, k, err)
continue
} else {
logger.Get().Debug("%s-Added EC profile for %s", ctxt, k)
}
}
return true, nil
}
示例3: getUser
func (a *App) getUser(rw http.ResponseWriter, req *http.Request) {
ctxt, err := GetContext(req)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
vars := mux.Vars(req)
user, err := GetAuthProvider().GetUser(vars["username"], req)
if err != nil {
rw.WriteHeader(http.StatusNotFound)
bytes, _ := json.Marshal(apiError{Error: err.Error()})
rw.Write(bytes)
logger.Get().Error("%s-Unable to Get the user:%s", ctxt, 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("%s-Unable to marshal the User:%s", ctxt, err)
HandleHttpError(rw, err)
return
}
rw.Write(bytes)
}
示例4: About
func (a *App) About(w http.ResponseWriter, r *http.Request) {
ctxt, err := GetContext(r)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
var syscapabilities conf.SystemCapabilities
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_SYSTEM_CAPABILITIES)
if err := coll.Find(nil).One(&syscapabilities); err != nil {
HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error in retrieving System Capabilities detail. error: %v", err))
logger.Get().Error("%s-Error in retrieving System Capabilities detail. error: %v", ctxt, err)
return
}
storage_provider_details := make(map[string]string)
for key, val := range syscapabilities.StorageProviderDetails {
storage_provider_details[strings.Title(key)] = val
delete(syscapabilities.StorageProviderDetails, key)
}
syscapabilities.StorageProviderDetails = storage_provider_details
if err := json.NewEncoder(w).Encode(syscapabilities); err != nil {
logger.Get().Error("%s-Error encoding data: %v", ctxt, err)
HttpResponse(w, http.StatusInternalServerError, err.Error())
}
}
示例5: FetchClusterDetailsFromProvider
func (a *App) FetchClusterDetailsFromProvider(ctxt string, clusterId uuid.UUID) (retVal map[string]map[string]interface{}, err error) {
retVal = make(map[string]map[string]interface{})
var result models.RpcResponse
vars := make(map[string]string)
vars["cluster-id"] = clusterId.String()
provider := a.GetProviderFromClusterId(ctxt, clusterId)
if provider == nil {
logger.Get().Error("%s-Faield to get provider for cluster: %v", ctxt, clusterId)
return nil, fmt.Errorf("Faield to get provider for cluster: %v", clusterId)
}
err = provider.Client.Call(fmt.Sprintf("%s.%s", provider.Name, "GetClusterSummary"), models.RpcRequest{RpcRequestVars: vars, RpcRequestData: []byte{}, RpcRequestContext: ctxt}, &result)
if result.Status.StatusCode == http.StatusOK || result.Status.StatusCode == http.StatusPartialContent {
providerResult := make(map[string]interface{})
unmarshalError := json.Unmarshal(result.Data.Result, &providerResult)
if unmarshalError != nil {
logger.Get().Error("%s - Error unmarshalling the monitoring data from provider %v.Error %v", ctxt, provider.Name, unmarshalError.Error())
return nil, fmt.Errorf("%s - Error unmarshalling the monitoring data from provider %v.Error %v", ctxt, provider.Name, unmarshalError.Error())
}
retVal[provider.Name] = providerResult
}
if err != nil {
return retVal, fmt.Errorf("%s - Call to provider %v failed.Err: %v\n", ctxt, provider.Name, err)
}
if result.Status.StatusMessage != "" && (result.Status.StatusCode == http.StatusPartialContent || result.Status.StatusCode == http.StatusInternalServerError || result.Status.StatusCode == http.StatusBadRequest) {
return retVal, fmt.Errorf("%s - Call to provider %v failed.Err: %v\n", ctxt, provider.Name, result.Status.StatusMessage)
}
return retVal, nil
}
示例6: GetEventById
func GetEventById(w http.ResponseWriter, r *http.Request) {
ctxt, err := GetContext(r)
if err != nil {
logger.Get().Error("Error Getting the context. error: %v", err)
}
vars := mux.Vars(r)
event_id_str := vars["event-id"]
event_id, err := uuid.Parse(event_id_str)
if err != nil {
logger.Get().Error("%s-Error parsing event id: %s", ctxt, event_id_str)
HttpResponse(w, http.StatusBadRequest, fmt.Sprintf("Error parsing event id: %s", event_id_str))
return
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
collection := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_APP_EVENTS)
var event models.AppEvent
if err := collection.Find(bson.M{"eventid": *event_id}).One(&event); err == mgo.ErrNotFound {
HttpResponse(w, http.StatusNotFound, "Event not found")
logger.Get().Error("%s-Event: %v not found. error: %v", ctxt, *event_id, err)
return
} else if err != nil {
logger.Get().Error("%s-Error getting the event detail for %v. error: %v", ctxt, *event_id, err)
HttpResponse(w, http.StatusBadRequest, "Event finding the record")
return
} else {
json.NewEncoder(w).Encode(event)
}
}
示例7: LoggingContext
//Middleware to create the logging context
func (a *App) LoggingContext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
session, err := Store.Get(r, "session-key")
if err != nil {
logger.Get().Error("Error Getting the session. error: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
var username string
if val, ok := session.Values["username"]; ok {
username = val.(string)
}
reqId, err := uuid.New()
if err != nil {
logger.Get().Error("Error Creating the RequestId. error: %v", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
loggingContext := fmt.Sprintf("%v:%v", username, reqId.String())
context.Set(r, LoggingCtxt, loggingContext)
defer context.Clear(r)
next(w, r)
}
示例8: checkAndUpdateAutoExpand
func checkAndUpdateAutoExpand(t *task.Task, clusterId uuid.UUID, ctxt string) {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_LOGICAL_UNITS)
var slus []models.StorageLogicalUnit
if err := coll.Find(bson.M{"clusterid": clusterId}).All(&slus); err != nil {
logger.Get().Error(
"%s-Error getting SLUs of cluster: %v for colocation check. error: %v",
ctxt,
clusterId,
err)
return
}
for _, slu := range slus {
journalDet := slu.Options["journal"].(map[string]interface{})
if slu.Options["device"] == journalDet["journaldisk"].(string) {
coll1 := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
if err := coll1.Update(
bson.M{"clusterid": clusterId},
bson.M{"$set": bson.M{"autoexpand": false}}); err != nil {
logger.Get().Error(
"%s-Error setting autoexpand flag for cluster: %v. error: %v",
ctxt,
clusterId,
err)
return
}
t.UpdateStatus("Disabled auto expand for cluster")
break
}
}
return
}
示例9: NewLdapAuthProvider
func NewLdapAuthProvider(config io.Reader) (*Authorizer, error) {
if config == nil {
errStr := "missing configuration file for Ldap Auth provider"
logger.Get().Error(errStr)
return nil, fmt.Errorf(errStr)
}
userDao := skyring.GetDbProvider().UserInterface()
session := db.GetDatastore()
c := session.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_LDAP)
ldapDao := models.Directory{}
err := c.Find(bson.M{}).One(&ldapDao)
if err != nil {
logger.Get().Info("Failed to open ldap db collection:%s", err)
}
//Create the Provider
if provider, err := NewAuthorizer(userDao, ldapDao); err != nil {
logger.Get().Error("Unable to initialize the authorizer for Ldapauthprovider. error: %v", err)
panic(err)
} else {
return &provider, nil
}
}
示例10: SyncNodeUtilizations
func SyncNodeUtilizations(params map[string]interface{}) {
ctxt, ctxtOk := params["ctxt"].(string)
if !ctxtOk {
logger.Get().Error("Failed to fetch context")
return
}
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_NODES)
var nodes []models.Node
if err := coll.Find(bson.M{"state": models.NODE_STATE_ACTIVE}).All(&nodes); err != nil {
if err == mgo.ErrNotFound {
return
}
logger.Get().Warning("%s - Failed to fetch nodes in active state.Error %v", ctxt, err)
}
time_stamp_str := strconv.FormatInt(time.Now().Unix(), 10)
var nodeNames []string
for _, node := range nodes {
if node.State == models.NODE_STATE_ACTIVE {
nodeNames = append(nodeNames, node.Hostname)
}
}
if len(nodeNames) == 0 {
return
}
for _, node := range nodes {
go SyncNodeUtilization(ctxt, node, time_stamp_str)
}
go ComputeSystemSummary(make(map[string]interface{}))
}
示例11: UpdateAlarmCount
func UpdateAlarmCount(event models.AppEvent, severity models.AlarmStatus, ctxt string) error {
if presentInList(ClusterAffectingEntities, event.NotificationEntity) {
if err := UpdateClusterAlarmCount(event, severity, ctxt); err != nil {
logger.Get().Error("%s-Could not update Alarm count for Cluster, for alert: %v. Error: %v", ctxt, event.EventId, err)
}
}
if presentInList(HostAffectingEntities, event.NotificationEntity) {
if err := UpdateNodeAlarmCount(event, severity, ctxt); err != nil {
logger.Get().Error("%s-Could not update Alarm count for node, for alert: %v. Error: %v", ctxt, event.EventId, err)
}
}
if presentInList(SluAffectingEntities, event.NotificationEntity) {
if err := UpdateSluAlarmCount(event, severity, ctxt); err != nil {
logger.Get().Error("%s-Could not update Alarm count for Slu, for alert: %v. Error: %v", ctxt, event.EventId, err)
}
}
if presentInList(StorageAffectingEntities, event.NotificationEntity) {
if err := UpdateStorageAlarmCount(event, severity, ctxt); err != nil {
logger.Get().Error("%s-Could not update Alarm count for storage, for alert: %v. Error: %v", ctxt, event.EventId, err)
}
}
if presentInList(BlockDeviceAffectingEntities, event.NotificationEntity) {
if err := UpdateBlockDeviceAlarmCount(event, severity, ctxt); err != nil {
logger.Get().Error("%s-Could not update Alarm count for Block Device, for alert: %v. Error: %v", ctxt, event.EventId, err)
}
}
return nil
}
示例12: AuditLog
func AuditLog(ctxt string, event models.AppEvent, dbprovider dbprovider.DbInterface) error {
sessionCopy := db.GetDatastore().Copy()
defer sessionCopy.Close()
if event.ClusterName == "" {
coll := sessionCopy.DB(
conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_STORAGE_CLUSTERS)
var cluster models.Cluster
if err := coll.Find(bson.M{"clusterid": event.ClusterId}).One(&cluster); err == nil {
event.ClusterName = cluster.Name
}
}
event.Context = ctxt
if event.Notify {
subject, body, err := getMailDetails(event)
if err != nil {
logger.Get().Error("%s-Could not get mail details for event: %s", ctxt, event.Name)
} else {
if err = notifier.MailNotify(subject, body, dbprovider, ctxt); err == nil {
event.Notified = true
} else {
logger.Get().Error("%s-Could not send mail for event: %s", ctxt, event.Name)
}
}
}
coll := sessionCopy.DB(conf.SystemConfig.DBConfig.Database).C(models.COLL_NAME_APP_EVENTS)
if err := coll.Insert(event); err != nil {
logger.Get().Error("%s-Error adding the app event: %v", ctxt, err)
return err
}
return nil
}
示例13: node_lost_handler
func node_lost_handler(event models.AppEvent, ctxt string) (models.AppEvent, error) {
//worry about the node only if the node in active state
state, err := skyringutils.GetNodeStateById(ctxt, event.NodeId)
if state == models.NODE_STATE_ACTIVE && err == nil {
if err := skyringutils.Update_node_status_byId(ctxt, event.NodeId, models.NODE_STATUS_ERROR); err != nil {
return event, err
}
}
event.Name = skyring.EventTypes["NODE_STATE_CHANGED"]
event.Message = fmt.Sprintf("Host: %s lost contact", event.NodeName)
event.EntityId = event.NodeId
event.Severity = models.ALARM_STATUS_MAJOR
event.NotificationEntity = models.NOTIFICATION_ENTITY_HOST
event.Notify = true
util.AppendServiceToNode(bson.M{"nodeid": event.NodeId}, models.SkyringServices[1], models.STATUS_DOWN, ctxt)
if err := update_alarm_count(event, ctxt); err != nil {
logger.Get().Error("%s-could not update alarm"+
" count for event: %s", ctxt, event.EventId.String())
return event, err
}
app := skyring.GetApp()
if err := app.RouteProviderEvents(ctxt, event); err != nil {
logger.Get().Error("%s-Event:%s could not be handled for node: %s. error: %v", ctxt, event.Name, event.NodeName, err)
}
return event, nil
}
示例14: TestMailNotify
func TestMailNotify(notifier models.MailNotifier, subject string, body string, recepient []string, ctxt string) error {
subject = fmt.Sprintf("%s: ", notifier.SubPrefix) + subject
msg := []byte("To: " + recepient[0] + "\r\n" +
"Subject: " + subject + "\r\n" +
"\r\n" +
body + "\r\n")
err := SetMailClient(notifier, ctxt)
if err != nil {
logger.Get().Error("%s-Error setting the Mail Client Error: %v", ctxt, err)
return err
}
err = sendMail(notifier.MailId, recepient, msg)
if err != nil {
// retry once again after setting the client, as client might have timed out
if err := SetMailClient(notifier, ctxt); err != nil {
if err != nil {
logger.Get().Error("%s-Error setting the Mail Client Error: %v", ctxt, err)
return err
}
}
if err := sendMail(notifier.MailId, recepient, msg); err != nil {
logger.Get().Error("%s-Could not Send the Mail Notification. Error: %v", ctxt, err)
return err
}
}
client = nil
return nil
}
示例15: InitAuthProvider
// InitPlugin creates an instance of the named plugin.
func InitAuthProvider(name string, configFilePath string) (AuthInterface, error) {
var authprovider AuthInterface
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 auth provider configuration %s. error: %v",
configFilePath, err)
}
defer config.Close()
authprovider, err = GetAuthProvider(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.
authprovider, err = GetAuthProvider(name, nil)
}
if err != nil {
return nil, fmt.Errorf("could not init plugin %s. error: %v", name, err)
}
if authprovider == nil {
return nil, fmt.Errorf("unknown plugin %s", name)
}
return authprovider, nil
}