本文整理匯總了Golang中github.com/justinsb/gova/log.Warn函數的典型用法代碼示例。如果您正苦於以下問題:Golang Warn函數的具體用法?Golang Warn怎麽用?Golang Warn使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Warn函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ListServicesForTenant
func (self *EtcdRouterRegistry) ListServicesForTenant(tenant string) (*model.Bundles, error) {
children, err := self.listSubkeys(self.basePath + "/service/")
if err != nil {
log.Warn("Error listing subkeys in etcd", err)
return nil, err
}
tenantChildren := []string{}
if tenant != "" {
tenantChildren, err = self.listSubkeys(self.basePath + "/tenant/" + tenant)
if err != nil {
log.Warn("Error listing subkeys in etcd", err)
return nil, err
}
}
bundles := &model.Bundles{}
bundles.Bundles = []model.Bundle{}
all := append(children, tenantChildren...)
for _, child := range all {
bundle := &model.Bundle{}
bundle.Id = child
bundle.Name = child
bundles.Bundles = append(bundles.Bundles, *bundle)
}
return bundles, nil
}
示例2: GetLog
// Gets any log entries for the instance
func (self *Instance) GetLog() (*model.LogData, error) {
jujuClient := self.GetJujuClient()
service := self.primaryServiceId
logStore, err := jujuClient.GetLogStore()
if err != nil {
log.Warn("Error fetching Juju log store", err)
return nil, err
}
// TODO: Expose units?
unitId := 0
logfile, err := logStore.ReadLog(service, unitId)
if err != nil {
log.Warn("Error reading log: %v", unitId, err)
return nil, err
}
if logfile == nil {
log.Warn("Log not found: %v", unitId)
return nil, nil
}
data := &model.LogData{}
data.Lines = make([]string, 0)
logfile.ReadLines(func(line string) (bool, error) {
data.Lines = append(data.Lines, line)
return true, nil
})
return data, nil
}
示例3: DeleteRelationInfo
// Delete any relation properties relating to the specified unit; that unit is going away.
func (self *Instance) DeleteRelationInfo(unitId string, relationId string) error {
jujuClient := self.GetJujuClient()
serviceId := self.primaryServiceId
prefix := ANNOTATION_PREFIX_RELATIONINFO + unitId + "_" + relationId + "_"
annotations, err := jujuClient.GetServiceAnnotations(serviceId)
if err != nil {
log.Warn("Error getting annotations", err)
// TODO: Mask error?
return err
}
deleteKeys := []string{}
for tagName, _ := range annotations {
if !strings.HasPrefix(tagName, prefix) {
continue
}
deleteKeys = append(deleteKeys, tagName)
}
if len(deleteKeys) != 0 {
log.Info("Deleting annotations on service %v: %v", serviceId, deleteKeys)
err = jujuClient.DeleteServiceAnnotations(serviceId, deleteKeys)
if err != nil {
log.Warn("Error deleting annotations", err)
return err
}
}
return nil
}
示例4: waitReady
func waitReady(instance *core.Instance, timeout int) (bool, error) {
ready := false
for i := 0; i < timeout; i++ {
state, err := instance.GetState()
if err != nil {
log.Warn("Error while waiting for instance to become ready", err)
return false, err
}
if state == nil {
log.Warn("Instance not yet created")
continue
}
status := state.Status
if status == "started" {
ready = true
break
}
time.Sleep(time.Second)
if status == "pending" {
log.Debug("Instance not ready; waiting", err)
} else {
log.Warn("Unknown instance status: %v", status)
}
}
return ready, nil
}
示例5: getScalingPolicy
func (self *Instance) getScalingPolicy() (*model.ScalingPolicy, error) {
jujuClient := self.GetJujuClient()
primaryServiceId := self.primaryServiceId
annotations, err := jujuClient.GetServiceAnnotations(primaryServiceId)
if err != nil {
log.Warn("Error getting annotations", err)
// TODO: Ignore?
return nil, err
}
var policy *model.ScalingPolicy
scalingPolicyJson := annotations[ANNOTATION_KEY_SCALING_POLICY]
if scalingPolicyJson == "" {
policy = self.bundleType.GetDefaultScalingPolicy()
} else {
policy = &model.ScalingPolicy{}
err = json.Unmarshal([]byte(scalingPolicyJson), policy)
if err != nil {
log.Warn("Error deserializing scaling policy (%v)", scalingPolicyJson, err)
// TODO: Ignore / go with default?
return nil, err
}
}
return policy, nil
}
示例6: read
func (self *EtcdRouterRegistry) read(key string) (*etcdRouterData, error) {
response, err := self.client.Get(key, false, false)
if err != nil {
etcdError, ok := err.(*etcd.EtcdError)
if ok && etcdError.ErrorCode == etcdErrorKeyNotFound {
log.Debug("Etcd key not found: %v", key)
return nil, nil
}
log.Warn("Error reading key from etcd: %v", key, err)
return nil, err
}
node := response.Node
if node == nil || node.Value == "" {
log.Info("No contents for key from etcd: %v", key)
return nil, nil
}
decoded := &etcdRouterData{}
err = json.Unmarshal([]byte(node.Value), decoded)
if err != nil {
log.Warn("Error parsing value from etcd: %v", node.Value, err)
return nil, err
}
return decoded, nil
}
示例7: GetOptions
func GetOptions() *Options {
flag.Parse()
self := &Options{}
self.Listen = *flagListen
registryUrl, err := url.Parse(*flagRegistryUrl)
if err != nil {
log.Warn("Unable to parse registry url: %v", *flagRegistryUrl)
return nil
}
if registryUrl.Scheme == "etcd" {
registry, err := NewEtcdRouterRegistry(registryUrl)
if err != nil {
log.Warn("Unable to build etcd registry", err)
return nil
}
self.Registry = registry
} else {
log.Warn("Unknown registry type: %v", registryUrl.Scheme)
return nil
}
return self
}
示例8: GetOptions
func GetOptions() *Options {
flag.Parse()
self := &Options{}
self.AgentConf = *flagAgentConf
self.ApiPasswordPath = *flagApiPasswordPath
self.CfTenantId = *flagCfTenantId
self.ListenAddress = *flagListenAddress
host, port, err := net.SplitHostPort(self.ListenAddress)
if err != nil {
log.Warn("Cannot parse listen address: %v", self.ListenAddress)
return nil
}
var portNum int
if port == "" {
portNum = 8080
} else {
portNum, err = net.LookupPort("tcp", port)
if err != nil {
log.Warn("Cannot resolve port: %v", port)
return nil
}
}
privateUrl := *flagPrivateUrl
if privateUrl == "" {
privateHost := host
if privateHost == "" {
ip, err := localIP()
if err != nil {
log.Warn("Error finding local IP", err)
return nil
}
privateHost = ip.String()
}
privateUrl = fmt.Sprintf("http://%v:%v/xaasprivate", privateHost, portNum)
log.Info("Chose private url: %v", privateUrl)
}
self.PrivateUrl = privateUrl
authMode := *flagAuth
authMode = strings.TrimSpace(authMode)
authMode = strings.ToLower(authMode)
if authMode == "openstack" {
keystoneUrl := *flagKeystoneUrl
self.Authenticator = auth.NewOpenstackMultiAuthenticator(keystoneUrl)
} else if authMode == "development" {
self.Authenticator = auth.NewDevelopmentAuthenticator()
} else {
log.Warn("Unknown authentication mode: %v", authMode)
return nil
}
return self
}
示例9: HttpPut
func (self *EndpointServiceBinding) HttpPut(request *CfBindRequest) (*rs.HttpResponse, error) {
service := self.getService()
if request.ServiceId != service.CfServiceId {
log.Warn("service mismatch: %v vs %v", request.ServiceId, service.CfServiceId)
return nil, rs.ErrNotFound()
}
bundleType, instance := service.getInstance(self.getInstanceId())
if instance == nil || bundleType == nil {
return nil, rs.ErrNotFound()
}
ready, err := waitReady(instance, 300)
if err != nil {
log.Warn("Error while waiting for instance to become ready", err)
return nil, err
}
if !ready {
log.Warn("Timeout waiting for service to be ready")
return nil, fmt.Errorf("Service not ready")
}
relationKey := bundleType.PrimaryRelationKey()
_, relationInfo, err := instance.GetRelationInfo(relationKey, true)
if err != nil {
return nil, err
}
if relationInfo == nil {
return nil, rs.ErrNotFound()
}
credentials, err := bundleType.MapCloudFoundryCredentials(relationInfo)
if err != nil {
log.Warn("Error mapping to CloudFoundry credentials", err)
return nil, err
}
// log.Debug("Relation info: %v", relationInfo)
// log.Debug("Mapped to CloudFoundry credentials %v", credentials)
response := &CfBindResponse{}
response.Credentials = credentials
httpResponse := &rs.HttpResponse{Status: http.StatusCreated}
httpResponse.Content = response
return httpResponse, nil
}
示例10: cleanupOldMachines
func (self *Huddle) cleanupOldMachines(state map[string]int, threshold int) (map[string]int, error) {
status, err := self.JujuClient.GetSystemStatus()
if err != nil {
log.Warn("Error getting system status", err)
return nil, err
}
unitsByMachine := map[string]*api.UnitStatus{}
for _, serviceStatus := range status.Services {
for _, unitStatus := range serviceStatus.Units {
machineId := unitStatus.Machine
unitsByMachine[machineId] = &unitStatus
}
}
idleMachines := map[string]*api.MachineStatus{}
for machineId, machineStatus := range status.Machines {
unit := unitsByMachine[machineId]
if unit != nil {
continue
}
idleMachines[machineId] = &machineStatus
}
idleCounts := map[string]int{}
for machineId, _ := range idleMachines {
idleCount := state[machineId]
idleCount++
idleCounts[machineId] = idleCount
}
for machineId, idleCount := range idleCounts {
if idleCount < threshold {
continue
}
if machineId == "0" {
// Machine id 0 is special (the system machine); we can't destroy it
continue
}
log.Info("Machine is idle; removing: %v", machineId)
err = self.JujuClient.DestroyMachine(machineId)
if err != nil {
log.Warn("Failed to delete machine %v", machineId, err)
}
}
return idleCounts, nil
}
示例11: HttpGet
func (self *EndpointServiceInstance) HttpGet() (*rs.HttpResponse, error) {
service := self.getService()
log.Info("CF instance GET request: %v", self.Id)
bundleType, instance := service.getInstance(self.Id)
if instance == nil || bundleType == nil {
return nil, rs.ErrNotFound()
}
state, err := instance.GetState()
if err != nil {
log.Warn("Error while waiting for instance to become ready", err)
return nil, err
}
ready := false
if state == nil {
log.Warn("Instance not yet created")
} else {
status := state.Status
if status == "started" {
ready = true
} else if status == "pending" {
ready = false
} else {
log.Warn("Unknown instance status: %v", status)
}
}
response := &CfCreateInstanceResponse{}
// TODO: We need a dashboard URL - maybe a Juju GUI?
response.DashboardUrl = "http://localhost:8080"
var cfState string
if ready {
cfState = CF_STATE_SUCCEEDED
} else {
cfState = CF_STATE_IN_PROGRESS
}
response.State = cfState
response.LastOperation = &CfOperation{}
response.LastOperation.State = cfState
log.Info("Sending response to CF service get", log.AsJson(response))
httpResponse := &rs.HttpResponse{Status: http.StatusOK}
httpResponse.Content = response
return httpResponse, nil
}
示例12: put
func (self *EtcdRouterRegistry) put(key string, data *etcdRouterData) error {
json, err := json.Marshal(data)
if err != nil {
log.Warn("Error encoding value to json", err)
return err
}
_, err = self.client.Set(key, string(json), 0)
if err != nil {
log.Warn("Error writing key to etcd: %v", key, err)
return err
}
return nil
}
示例13: AddJxaasCharm
// Adds a bundletype to the system, by extracting the required template from the charm itself
func (self *System) AddJxaasCharm(apiclient *juju.Client, key string, charmName string) error {
charmInfo, err := apiclient.CharmInfo(charmName)
if err != nil {
log.Warn("Error reading charm: %v", charmName, err)
return err
}
if charmInfo == nil {
return fmt.Errorf("Unable to find charm: %v", charmName)
}
url := charmInfo.URL
if url == "" {
return fmt.Errorf("Unable to find charm url: %v", charmName)
}
contents, err := apiclient.DownloadCharm(charmName)
if err != nil {
log.Warn("Error reading charm", err)
return err
}
charmFile := NewCharmReader(contents)
config, err := charmFile.read("jxaas.yaml")
if err != nil {
log.Warn("Error reading jxaas.yaml from charm: %v", charmName, err)
return err
}
if config == nil {
return fmt.Errorf("Could not find jxaas.yaml in charm: %v", charmName)
}
// log.Info("Jxaas config: %v", string(config))
bundleTemplate, err := bundle.NewBundleTemplate(sources.NewArrayToByteSource(config))
if err != nil {
return err
}
bundleType, err := bundletype.NewGenericBundleType(key, bundleTemplate)
if err != nil {
return err
}
self.BundleTypes[key] = bundleType
return nil
}
示例14: HttpDelete
func (self *EndpointServiceInstance) HttpDelete(httpRequest *http.Request) (*CfDeleteInstanceResponse, error) {
service := self.getService()
queryValues := httpRequest.URL.Query()
serviceId := queryValues.Get("service_id")
// planId := queryValues.Get("plan_id")
if serviceId != service.CfServiceId {
log.Warn("Service mismatch: %v vs %v", serviceId, service.CfServiceId)
return nil, rs.ErrNotFound()
}
log.Info("Deleting item %v %v", serviceId, self.Id)
bundletype, instance := service.getInstance(self.getInstanceId())
if instance == nil || bundletype == nil {
return nil, rs.ErrNotFound()
}
err := instance.Delete()
if err != nil {
return nil, err
}
// TODO: Wait for deletion?
response := &CfDeleteInstanceResponse{}
return response, nil
}
示例15: Borrow
func (self *InMemoryPool) Borrow(owner string) Pooled {
self.mutex.Lock()
defer self.mutex.Unlock()
if self.allocated == nil {
self.init()
}
head := self.available.Front()
if head == nil {
log.Warn("No elements left in pool")
return nil
}
self.available.Remove(head)
element := head.Value
if self.allocated[element] {
panic("Attempt to do double-allocation")
}
self.allocated[element] = true
return NewPooled(self, element)
}