本文整理汇总了Golang中github.com/litl/galaxy/log.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: pullImage
func pullImage(appCfg config.App) (*docker.Image, error) {
image, err := serviceRuntime.InspectImage(appCfg.Version())
if image != nil && image.ID == appCfg.VersionID() || appCfg.VersionID() == "" {
return image, nil
}
log.Printf("Pulling %s version %s\n", appCfg.Name(), appCfg.Version())
image, err = serviceRuntime.PullImage(appCfg.Version(),
appCfg.VersionID())
if image == nil || err != nil {
log.Errorf("ERROR: Could not pull image %s: %s",
appCfg.Version(), err)
return nil, err
}
if image.ID != appCfg.VersionID() && len(appCfg.VersionID()) > 12 {
log.Errorf("ERROR: Pulled image for %s does not match expected ID. Expected: %s: Got: %s",
appCfg.Version(),
image.ID[0:12], appCfg.VersionID()[0:12])
return nil, errors.New(fmt.Sprintf("failed to pull image ID %s", appCfg.VersionID()[0:12]))
}
log.Printf("Pulled %s\n", appCfg.Version())
return image, nil
}
示例2: monitorService
func monitorService(changedConfigs chan *config.ConfigChange) {
for {
var changedConfig *config.ConfigChange
select {
case changedConfig = <-changedConfigs:
if changedConfig.Error != nil {
log.Errorf("ERROR: Error watching changes: %s", changedConfig.Error)
continue
}
if changedConfig.AppConfig == nil {
continue
}
assigned, err := appAssigned(changedConfig.AppConfig.Name())
if err != nil {
log.Errorf("ERROR: Error retrieving service config for %s: %s", changedConfig.AppConfig.Name(), err)
if !loop {
return
}
continue
}
if !assigned {
continue
}
ch, ok := workerChans[changedConfig.AppConfig.Name()]
if !ok {
name := changedConfig.AppConfig.Name()
ch := make(chan string)
workerChans[name] = ch
wg.Add(1)
go restartContainers(name, ch)
ch <- "deploy"
log.Printf("Started new worker for %s\n", name)
continue
}
if changedConfig.Restart {
log.Printf("Restarting %s", changedConfig.AppConfig.Name())
ch <- "restart"
} else {
ch <- "deploy"
}
}
}
}
示例3: unregisterShuttle
func unregisterShuttle(configStore *config.Store, env, hostIP, shuttleAddr string) {
if client == nil {
return
}
registrations, err := configStore.ListRegistrations(env)
if err != nil {
log.Errorf("ERROR: Unable to list registrations: %s", err)
return
}
backends := make(map[string]*shuttle.ServiceConfig)
for _, r := range registrations {
// Registration for a container on a different host? Skip it.
if r.ExternalIP != hostIP {
continue
}
// No service ports exposed on the host, skip it.
if r.ExternalAddr() == "" || r.Port == "" {
continue
}
service := backends[r.Name]
if service == nil {
service = &shuttle.ServiceConfig{
Name: r.Name,
VirtualHosts: r.VirtualHosts,
}
if r.Port != "" {
service.Addr = "0.0.0.0:" + r.Port
}
backends[r.Name] = service
}
b := shuttle.BackendConfig{
Name: r.ContainerID[0:12],
Addr: r.ExternalAddr(),
}
service.Backends = append(service.Backends, b)
}
for _, service := range backends {
err := client.RemoveService(service.Name)
if err != nil {
log.Errorf("ERROR: Unable to remove shuttle service: %s", err)
}
}
}
示例4: Register
func Register(serviceRuntime *runtime.ServiceRuntime, configStore *config.Store, env, pool, hostIP, shuttleAddr string) {
if shuttleAddr != "" {
client = shuttle.NewClient(shuttleAddr)
}
RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, false)
containerEvents := make(chan runtime.ContainerEvent)
err := serviceRuntime.RegisterEvents(env, pool, hostIP, containerEvents)
if err != nil {
log.Printf("ERROR: Unable to register docker event listener: %s", err)
}
for {
select {
case ce := <-containerEvents:
switch ce.Status {
case "start":
reg, err := configStore.RegisterService(env, pool, hostIP, ce.Container)
if err != nil {
log.Errorf("ERROR: Unable to register container: %s", err)
continue
}
log.Printf("Registered %s running as %s for %s%s", strings.TrimPrefix(reg.ContainerName, "/"),
reg.ContainerID[0:12], reg.Name, locationAt(reg))
registerShuttle(configStore, env, shuttleAddr)
case "die", "stop":
reg, err := configStore.UnRegisterService(env, pool, hostIP, ce.Container)
if err != nil {
log.Errorf("ERROR: Unable to unregister container: %s", err)
continue
}
if reg != nil {
log.Printf("Unregistered %s running as %s for %s%s", strings.TrimPrefix(reg.ContainerName, "/"),
reg.ContainerID[0:12], reg.Name, locationAt(reg))
}
RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, true)
pruneShuttleBackends(configStore, env, shuttleAddr)
}
case <-time.After(10 * time.Second):
RegisterAll(serviceRuntime, configStore, env, pool, hostIP, shuttleAddr, true)
pruneShuttleBackends(configStore, env, shuttleAddr)
}
}
}
示例5: RegisterAll
func RegisterAll(serviceRuntime *runtime.ServiceRuntime, configStore *config.Store, env, pool, hostIP, shuttleAddr string, loggedOnce bool) {
columns := []string{"CONTAINER ID | IMAGE | EXTERNAL | INTERNAL | CREATED | EXPIRES"}
registrations, err := serviceRuntime.RegisterAll(env, pool, hostIP)
if err != nil {
log.Errorf("ERROR: Unable to register containers: %s", err)
return
}
fn := log.Debugf
if !loggedOnce {
fn = log.Printf
}
for _, registration := range registrations {
if !loggedOnce || time.Now().Unix()%60 < 10 {
fn("Registered %s running as %s for %s%s", strings.TrimPrefix(registration.ContainerName, "/"),
registration.ContainerID[0:12], registration.Name, locationAt(registration))
}
columns = append(columns, strings.Join([]string{
registration.ContainerID[0:12],
registration.Image,
registration.ExternalAddr(),
registration.InternalAddr(),
utils.HumanDuration(time.Now().Sub(registration.StartedAt)) + " ago",
"In " + utils.HumanDuration(registration.Expires.Sub(time.Now().UTC())),
}, " | "))
}
registerShuttle(configStore, env, shuttleAddr)
}
示例6: StopOldVersion
func (s *ServiceRuntime) StopOldVersion(appCfg config.App, limit int) error {
containers, err := s.ManagedContainers()
if err != nil {
return err
}
stopped := 0
for _, container := range containers {
if stopped == limit {
return nil
}
env := s.EnvFor(container)
// Container name does match one that would be started w/ this service config
if env["GALAXY_APP"] != appCfg.Name() {
continue
}
image, err := s.InspectImage(container.Image)
if err != nil {
log.Errorf("ERROR: Unable to inspect image: %s", container.Image)
continue
}
if image == nil {
log.Errorf("ERROR: Image for container %s does not exist!", container.ID[0:12])
continue
}
version := env["GALAXY_VERSION"]
if version == "" {
log.Printf("WARNING: %s missing GALAXY_VERSION", appCfg.ContainerName())
}
if version != strconv.FormatInt(appCfg.ID(), 10) && version != "" {
s.stopContainer(container)
stopped = stopped + 1
}
}
return nil
}
示例7: appBackup
// Backup app config to a file or STDOUT
func appBackup(c *cli.Context) {
initStore(c)
env := utils.GalaxyEnv(c)
if env == "" {
log.Fatal("ERROR: env is required. Pass --env or set GALAXY_ENV")
}
backup := &backupData{
Time: time.Now(),
}
toBackup := c.Args()
if len(toBackup) == 0 {
appList, err := configStore.ListApps(env)
if err != nil {
log.Fatalf("ERROR: %s\n", err)
}
for _, app := range appList {
toBackup = append(toBackup, app.Name())
}
}
errCount := 0
for _, app := range toBackup {
data, err := getAppBackup(app, env)
if err != nil {
// log errors and continue
log.Errorf("ERROR: %s [%s]", err, app)
errCount++
continue
}
backup.Apps = append(backup.Apps, data)
}
if errCount > 0 {
fmt.Printf("WARNING: backup completed with %d errors\n", errCount)
defer os.Exit(errCount)
}
j, err := json.MarshalIndent(backup, "", " ")
if err != nil {
log.Fatal(err)
}
fileName := c.String("file")
if fileName != "" {
if err := ioutil.WriteFile(fileName, j, 0666); err != nil {
log.Fatal(err)
}
return
}
os.Stdout.Write(j)
}
示例8: pullImage
func pullImage(appCfg config.App) (*docker.Image, error) {
image, err := serviceRuntime.PullImage(appCfg.Version(), appCfg.VersionID())
if image == nil || err != nil {
log.Errorf("ERROR: Could not pull image %s: %s", appCfg.Version(), err)
return nil, err
}
log.Printf("Pulled %s version %s\n", appCfg.Name(), appCfg.Version())
return image, nil
}
示例9: PullImage
func (s *ServiceRuntime) PullImage(version, id string) (*docker.Image, error) {
image, err := s.InspectImage(version)
if err != nil && err != docker.ErrNoSuchImage {
return nil, err
}
if image != nil && image.ID == id {
return image, nil
}
registry, repository, tag := utils.SplitDockerImage(version)
// No, pull it down locally
pullOpts := docker.PullImageOptions{
Repository: repository,
Tag: tag,
OutputStream: log.DefaultLogger}
dockerAuth := findAuth(registry)
if registry != "" {
pullOpts.Repository = registry + "/" + repository
} else {
pullOpts.Repository = repository
}
pullOpts.Registry = registry
pullOpts.Tag = tag
retries := 0
for {
retries += 1
err = s.dockerClient.PullImage(pullOpts, dockerAuth)
if err != nil {
// Don't retry 404, they'll never succeed
if err.Error() == "HTTP code: 404" {
return image, nil
}
if retries > 3 {
return image, err
}
log.Errorf("ERROR: error pulling image %s. Attempt %d: %s", version, retries, err)
continue
}
break
}
return s.InspectImage(version)
}
示例10: StopAllButCurrentVersion
func (s *ServiceRuntime) StopAllButCurrentVersion(appCfg config.App) error {
containers, err := s.ManagedContainers()
if err != nil {
return err
}
for _, container := range containers {
env := s.EnvFor(container)
// Container name does match one that would be started w/ this service config
if env["GALAXY_APP"] != appCfg.Name() {
continue
}
image, err := s.InspectImage(container.Image)
if err != nil {
log.Errorf("ERROR: Unable to inspect image: %s", container.Image)
continue
}
if image == nil {
log.Errorf("ERROR: Image for container %s does not exist!", container.ID[0:12])
continue
}
version := env["GALAXY_VERSION"]
imageDiffers := image.ID != appCfg.VersionID() && appCfg.VersionID() != ""
versionDiffers := version != strconv.FormatInt(appCfg.ID(), 10) && version != ""
if imageDiffers || versionDiffers {
s.stopContainer(container)
}
}
return nil
}
示例11: startService
func startService(appCfg config.App, logStatus bool) {
desired, err := commander.Balanced(configStore, hostIP, appCfg.Name(), env, pool)
if err != nil {
log.Errorf("ERROR: Could not determine instance count: %s", err)
return
}
running, err := serviceRuntime.InstanceCount(appCfg.Name(), strconv.FormatInt(appCfg.ID(), 10))
if err != nil {
log.Errorf("ERROR: Could not determine running instance count: %s", err)
return
}
for i := 0; i < desired-running; i++ {
container, err := serviceRuntime.Start(env, pool, appCfg)
if err != nil {
log.Errorf("ERROR: Could not start containers: %s", err)
return
}
log.Printf("Started %s version %s as %s\n", appCfg.Name(), appCfg.Version(), container.ID[0:12])
err = serviceRuntime.StopOldVersion(appCfg, 1)
if err != nil {
log.Errorf("ERROR: Could not stop containers: %s", err)
}
}
running, err = serviceRuntime.InstanceCount(appCfg.Name(), strconv.FormatInt(appCfg.ID(), 10))
if err != nil {
log.Errorf("ERROR: Could not determine running instance count: %s", err)
return
}
for i := 0; i < running-desired; i++ {
err := serviceRuntime.Stop(appCfg)
if err != nil {
log.Errorf("ERROR: Could not stop container: %s", err)
}
}
err = serviceRuntime.StopOldVersion(appCfg, -1)
if err != nil {
log.Errorf("ERROR: Could not stop old containers: %s", err)
}
// check the image version, and log any inconsistencies
inspectImage(appCfg)
}
示例12: StopUnassigned
// Stop any running galaxy containers that are not assigned to us
// TODO: We call ManagedContainers a lot, repeatedly listing and inspecting all containers.
func (s *ServiceRuntime) StopUnassigned(env, pool string) error {
containers, err := s.ManagedContainers()
if err != nil {
return err
}
for _, container := range containers {
name := s.EnvFor(container)["GALAXY_APP"]
pools, err := s.configStore.ListAssignedPools(env, name)
if err != nil {
log.Errorf("ERROR: Unable to list pool assignments for %s: %s", container.Name, err)
continue
}
if len(pools) == 0 || !utils.StringInSlice(pool, pools) {
log.Warnf("galaxy container %s not assigned to %s/%s", container.Name, env, pool)
s.stopContainer(container)
}
}
return nil
}
示例13: restartContainers
func restartContainers(app string, cmdChan chan string) {
defer wg.Done()
logOnce := true
ticker := time.NewTicker(10 * time.Second)
for {
select {
case cmd := <-cmdChan:
assigned, err := appAssigned(app)
if err != nil {
log.Errorf("ERROR: Error retrieving assignments for %s: %s", app, err)
if !loop {
return
}
continue
}
if !assigned {
continue
}
appCfg, err := configStore.GetApp(app, env)
if err != nil {
log.Errorf("ERROR: Error retrieving service config for %s: %s", app, err)
if !loop {
return
}
continue
}
if appCfg.Version() == "" {
if !loop {
return
}
continue
}
if cmd == "deploy" {
_, err = pullImage(appCfg)
if err != nil {
log.Errorf("ERROR: Error pulling image for %s: %s", app, err)
if !loop {
return
}
continue
}
startService(appCfg, logOnce)
}
if cmd == "restart" {
err := serviceRuntime.Stop(appCfg)
if err != nil {
log.Errorf("ERROR: Could not stop %s: %s",
appCfg.Version(), err)
if !loop {
return
}
startService(appCfg, logOnce)
continue
}
}
logOnce = false
case <-ticker.C:
appCfg, err := configStore.GetApp(app, env)
if err != nil {
log.Errorf("ERROR: Error retrieving service config for %s: %s", app, err)
continue
}
assigned, err := appAssigned(app)
if err != nil {
log.Errorf("ERROR: Error retrieving service config for %s: %s", app, err)
if !loop {
return
}
continue
}
if appCfg == nil || !assigned {
log.Errorf("%s no longer exists. Stopping worker.", app)
serviceRuntime.StopAllMatching(app)
delete(workerChans, app)
return
}
if appCfg.Version() == "" {
continue
}
startService(appCfg, logOnce)
}
//.........这里部分代码省略.........
示例14: RegisterEvents
// RegisterEvents monitors the docker daemon for events, and returns those
// that require registration action over the listener chan.
func (s *ServiceRuntime) RegisterEvents(env, pool, hostIP string, listener chan ContainerEvent) error {
go func() {
c := make(chan *docker.APIEvents)
watching := false
for {
err := s.Ping()
if err != nil {
log.Errorf("ERROR: Unable to ping docker daemaon: %s", err)
if watching {
s.dockerClient.RemoveEventListener(c)
watching = false
}
time.Sleep(10 * time.Second)
continue
}
if !watching {
err = s.dockerClient.AddEventListener(c)
if err != nil && err != docker.ErrListenerAlreadyExists {
log.Printf("ERROR: Error registering docker event listener: %s", err)
time.Sleep(10 * time.Second)
continue
}
watching = true
}
select {
case e := <-c:
if e.Status == "start" || e.Status == "stop" || e.Status == "die" {
container, err := s.InspectContainer(e.ID)
if err != nil {
log.Printf("ERROR: Error inspecting container: %s", err)
continue
}
if container == nil {
log.Printf("WARN: Nil container returned for %s", e.ID[:12])
continue
}
name := s.EnvFor(container)["GALAXY_APP"]
if name != "" {
registration, err := s.configStore.GetServiceRegistration(env, pool, hostIP, container)
if err != nil {
log.Printf("WARN: Could not find service registration for %s/%s: %s", name, container.ID[:12], err)
continue
}
if registration == nil && e.Status != "start" {
continue
}
// if a container is restarting, don't continue re-registering the app
if container.State.Restarting {
continue
}
listener <- ContainerEvent{
Status: e.Status,
Container: container,
ServiceRegistration: registration,
}
}
}
case <-time.After(10 * time.Second):
// check for docker liveness
}
}
}()
return nil
}
示例15: main
//.........这里部分代码省略.........
log.Fatalf("ERROR: Bad command line options: %s", err)
}
ensureEnv()
if configFs.NArg() != 1 {
log.Error("ERROR: Missing app name argument")
log.Printf("Usage: %s", usage)
os.Exit(1)
}
app := configFs.Args()[0]
err = commander.ConfigList(configStore, app, env)
if err != nil {
log.Fatalf("ERROR: %s", err)
}
return
case "config:get":
configFs := flag.NewFlagSet("config:get", flag.ExitOnError)
configFs.Usage = func() {
println("Usage: commander config <app> KEY [KEY]*\n")
println(" Get config values for an app\n")
println("Options:\n")
configFs.PrintDefaults()
}
err := configFs.Parse(flag.Args()[1:])
if err != nil {
log.Fatalf("ERROR: Bad command line options: %s", err)
}
ensureEnv()
if configFs.NArg() == 0 {
log.Errorf("ERROR: Missing app name")
configFs.Usage()
os.Exit(1)
}
app := configFs.Args()[0]
err = commander.ConfigGet(configStore, app, env, configFs.Args()[1:])
if err != nil {
log.Fatalf("ERROR: %s", err)
}
return
case "config:set":
configFs := flag.NewFlagSet("config:set", flag.ExitOnError)
configFs.Usage = func() {
println("Usage: commander config <app> KEY=VALUE [KEY=VALUE]*\n")
println(" Set config values for an app\n")
println("Options:\n")
configFs.PrintDefaults()
}
err := configFs.Parse(flag.Args()[1:])
if err != nil {
log.Fatalf("ERROR: Bad command line options: %s", err)
}
ensureEnv()
if configFs.NArg() == 0 {
log.Errorf("ERROR: Missing app name")
configFs.Usage()
os.Exit(1)
}
app := configFs.Args()[0]