OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package service | 5 package service |
6 | 6 |
7 import ( | 7 import ( |
8 "flag" | 8 "flag" |
9 "net/http" | 9 "net/http" |
10 "net/url" | 10 "net/url" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 s.addFlags(c, &s.Flags) | 176 s.addFlags(c, &s.Flags) |
177 if err := s.Flags.Parse(os.Args[1:]); err != nil { | 177 if err := s.Flags.Parse(os.Args[1:]); err != nil { |
178 log.WithError(err).Errorf(c, "Failed to parse command-line.") | 178 log.WithError(err).Errorf(c, "Failed to parse command-line.") |
179 return err | 179 return err |
180 } | 180 } |
181 | 181 |
182 // Install logging configuration. | 182 // Install logging configuration. |
183 c = s.loggingFlags.Set(c) | 183 c = s.loggingFlags.Set(c) |
184 | 184 |
185 if err := s.profiler.Start(); err != nil { | 185 if err := s.profiler.Start(); err != nil { |
186 » » return errors.Annotate(err).Reason("failed to start profiler").E
rr() | 186 » » return errors.Annotate(err, "failed to start profiler").Err() |
187 } | 187 } |
188 defer s.profiler.Stop() | 188 defer s.profiler.Stop() |
189 | 189 |
190 // Cancel our Context after we're done our run loop. | 190 // Cancel our Context after we're done our run loop. |
191 c, cancelFunc := context.WithCancel(c) | 191 c, cancelFunc := context.WithCancel(c) |
192 defer cancelFunc() | 192 defer cancelFunc() |
193 | 193 |
194 // Validate the runtime environment. | 194 // Validate the runtime environment. |
195 if s.serviceID == "" { | 195 if s.serviceID == "" { |
196 return errors.New("no service ID was configured (-service-id)") | 196 return errors.New("no service ID was configured (-service-id)") |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 // | 393 // |
394 // Older Coordinator instances may provide the full URL instead
of the host, | 394 // Older Coordinator instances may provide the full URL instead
of the host, |
395 // in which case we will extract the host from the URL. | 395 // in which case we will extract the host from the URL. |
396 host := ccfg.ConfigServiceHost | 396 host := ccfg.ConfigServiceHost |
397 if host == "" { | 397 if host == "" { |
398 if ccfg.ConfigServiceUrl == "" { | 398 if ccfg.ConfigServiceUrl == "" { |
399 return errors.New("coordinator does not specify
a config service") | 399 return errors.New("coordinator does not specify
a config service") |
400 } | 400 } |
401 u, err := url.Parse(ccfg.ConfigServiceUrl) | 401 u, err := url.Parse(ccfg.ConfigServiceUrl) |
402 if err != nil { | 402 if err != nil { |
403 » » » » return errors.Annotate(err).Reason("failed to pa
rse config service URL").Err() | 403 » » » » return errors.Annotate(err, "failed to parse con
fig service URL").Err() |
404 } | 404 } |
405 host = u.Host | 405 host = u.Host |
406 } | 406 } |
407 | 407 |
408 if ccfg.ConfigSet == "" { | 408 if ccfg.ConfigSet == "" { |
409 return errors.New("coordinator does not specify a config
set") | 409 return errors.New("coordinator does not specify a config
set") |
410 } | 410 } |
411 | 411 |
412 log.Fields{ | 412 log.Fields{ |
413 "host": host, | 413 "host": host, |
(...skipping 15 matching lines...) Expand all Loading... |
429 | 429 |
430 // Add config caching layers. | 430 // Add config caching layers. |
431 *c = opts.WrapBackend(*c, &client.Backend{ | 431 *c = opts.WrapBackend(*c, &client.Backend{ |
432 Provider: p, | 432 Provider: p, |
433 }) | 433 }) |
434 | 434 |
435 // Load our service configuration. | 435 // Load our service configuration. |
436 var meta cfgclient.Meta | 436 var meta cfgclient.Meta |
437 cset, path := s.ServiceConfigPath() | 437 cset, path := s.ServiceConfigPath() |
438 if err := cfgclient.Get(*c, cfgclient.AsService, cset, path, textproto.M
essage(&s.serviceConfig), &meta); err != nil { | 438 if err := cfgclient.Get(*c, cfgclient.AsService, cset, path, textproto.M
essage(&s.serviceConfig), &meta); err != nil { |
439 » » return errors.Annotate(err).Reason("failed to load service confi
g").Err() | 439 » » return errors.Annotate(err, "failed to load service config").Err
() |
440 } | 440 } |
441 | 441 |
442 // Create a poller for our service config. | 442 // Create a poller for our service config. |
443 if s.killCheckInterval > 0 { | 443 if s.killCheckInterval > 0 { |
444 pollerC, pollerCancelFunc := context.WithCancel(*c) | 444 pollerC, pollerCancelFunc := context.WithCancel(*c) |
445 | 445 |
446 poller := config.ChangePoller{ | 446 poller := config.ChangePoller{ |
447 ConfigSet: cset, | 447 ConfigSet: cset, |
448 Path: path, | 448 Path: path, |
449 Period: time.Duration(s.killCheckInterval), | 449 Period: time.Duration(s.killCheckInterval), |
(...skipping 25 matching lines...) Expand all Loading... |
475 return cfgtypes.ProjectConfigSet(proj), svcconfig.ProjectConfigPath(s.se
rviceID) | 475 return cfgtypes.ProjectConfigSet(proj), svcconfig.ProjectConfigPath(s.se
rviceID) |
476 } | 476 } |
477 | 477 |
478 // ProjectConfig returns the current service's project configuration for proj. | 478 // ProjectConfig returns the current service's project configuration for proj. |
479 func (s *Service) ProjectConfig(c context.Context, proj cfgtypes.ProjectName) (*
svcconfig.ProjectConfig, error) { | 479 func (s *Service) ProjectConfig(c context.Context, proj cfgtypes.ProjectName) (*
svcconfig.ProjectConfig, error) { |
480 cset, path := s.ProjectConfigPath(proj) | 480 cset, path := s.ProjectConfigPath(proj) |
481 | 481 |
482 var pcfg svcconfig.ProjectConfig | 482 var pcfg svcconfig.ProjectConfig |
483 msg, err := s.configCache.Get(c, cset, path, &pcfg) | 483 msg, err := s.configCache.Get(c, cset, path, &pcfg) |
484 if err != nil { | 484 if err != nil { |
485 » » return nil, errors.Annotate(err).Reason("failed to load project
config from %(cset)s.%(path)s"). | 485 » » return nil, errors.Annotate(err, "failed to load project config
from %s.%s", cset, path).Err() |
486 » » » D("cset", cset).D("path", path).Err() | |
487 } | 486 } |
488 return msg.(*svcconfig.ProjectConfig), nil | 487 return msg.(*svcconfig.ProjectConfig), nil |
489 } | 488 } |
490 | 489 |
491 // SetShutdownFunc sets the service shutdown function. | 490 // SetShutdownFunc sets the service shutdown function. |
492 func (s *Service) SetShutdownFunc(f func()) { | 491 func (s *Service) SetShutdownFunc(f func()) { |
493 s.shutdownFunc.Store(f) | 492 s.shutdownFunc.Store(f) |
494 } | 493 } |
495 | 494 |
496 func (s *Service) shutdown() { | 495 func (s *Service) shutdown() { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 authOpts.Scopes = append([]string(nil), scopes...) | 669 authOpts.Scopes = append([]string(nil), scopes...) |
671 authOpts.Transport = s.unauthenticatedTransport() | 670 authOpts.Transport = s.unauthenticatedTransport() |
672 | 671 |
673 a = commonAuth.NewAuthenticator(c, commonAuth.SilentLogin, authOpts) | 672 a = commonAuth.NewAuthenticator(c, commonAuth.SilentLogin, authOpts) |
674 if s.authCache == nil { | 673 if s.authCache == nil { |
675 s.authCache = make(map[string]*commonAuth.Authenticator) | 674 s.authCache = make(map[string]*commonAuth.Authenticator) |
676 } | 675 } |
677 s.authCache[key] = a | 676 s.authCache[key] = a |
678 return a, nil | 677 return a, nil |
679 } | 678 } |
OLD | NEW |