// ForService returns all the active proof links for a service.
516194
func (r *RemoteProofLinks) ForService(st ServiceType) []RemoteProofChainLink {
	var links []RemoteProofChainLink
	for _, linkWithState := range r.links[st.Key()] {
		if linkWithState.link.LastWriterWins() {
			// Clear the array if it's a last-writer wins service.
			// (like many social networks)
			links = nil
		}
		if linkWithState.link.IsRevoked() {
			continue
		}
		links = append(links, linkWithState.link)
	}
	return links
}
1174229
func (i *injector) GetService(t reflect.Type) reflect.Value {
	v := i.services[t]

	if v.IsValid() {
		return returnService(v)
	}

	if t.Kind() == reflect.Interface {
		for tp, val := range i.services {
			if tp.Implements(t) {
				if val.IsValid() {
					return returnService(val)
				}
			}
		}
	}

	if i.parent != nil {
		v = i.parent.GetService(t)
	}

	return returnService(v)
}
1016896
func (c *Client) ImageService() images.Store {
	if c.imageStore != nil {
		return c.imageStore
	}
	c.connMu.Lock()
	defer c.connMu.Unlock()
	return NewImageStoreFromClient(imagesapi.NewImagesClient(c.conn))
}
614678
func (_m *Facade) GetServicesForScheduling(_a0 datastore.Context, _a1 []string) []*service.Service {
	ret := _m.Called(_a0, _a1)

	var r0 []*service.Service
	if rf, ok := ret.Get(0).(func(datastore.Context, []string) []*service.Service); ok {
		r0 = rf(_a0, _a1)
	} else {
		r0 = ret.Get(0).([]*service.Service)
	}

	return r0
}
1093438
func (_m *Balancer) DeleteService(_a0 string) error {
	ret := _m.Called(_a0)

	var r0 error
	if rf, ok := ret.Get(0).(func(string) error); ok {
		r0 = rf(_a0)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
906175
func (s *Server) GetService(serviceID string, svc *service.Service) error {
	sv, err := s.f.GetService(s.context(), serviceID)
	if err != nil {
		return err
	}
	*svc = *sv
	return nil
}
869371
func (s *GetReservationPurchaseRecommendationInput) SetService(v string) *GetReservationPurchaseRecommendationInput {
	s.Service = &v
	return s
}
718084
func (f *Facade) evaluateService(ctx datastore.Context, svc *service.Service, instanceID int) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.evaluatedService"))

	// service lookup
	getService := func(serviceID string) (service.Service, error) {
		svc := service.Service{}
		result, err := f.GetService(ctx, serviceID)
		if result != nil {
			svc = *result
		}
		return svc, err
	}

	// service child lookup
	getServiceChild := func(parentID, childName string) (service.Service, error) {
		svc := service.Service{}
		result, err := f.FindChildService(ctx, parentID, childName)
		if result != nil {
			svc = *result
		}
		return svc, err
	}
	return svc.Evaluate(getService, getServiceChild, instanceID)
}
1037209
func (s *ServiceController) enqueueService(obj interface{}) {
	key, err := controller.KeyFunc(obj)
	if err != nil {
		klog.Errorf("Couldn't get key for object %#v: %v", obj, err)
		return
	}
	s.queue.Add(key)
}
1299574
func NewService() *Service {
	return &Service{
		TokenGenerator: rand.NewTokenGenerator(64),
		IDGenerator:    snowflake.NewIDGenerator(),
		time:           time.Now,
	}
}
1031157
func (ep *endpoint) disableService() {
	ep.Lock()
	defer ep.Unlock()
	ep.serviceEnabled = false
}
1236952
func (a *Agent) persistService(service *structs.NodeService) error {
	svcPath := filepath.Join(a.config.DataDir, servicesDir, stringHash(service.ID))

	wrapped := persistedService{
		Token:   a.State.ServiceToken(service.ID),
		Service: service,
	}
	encoded, err := json.Marshal(wrapped)
	if err != nil {
		return err
	}

	return file.WriteAtomic(svcPath, encoded)
}
175181
func (ec *ServiceManager) BindService(service RunnableInterface) {
	ec.services = append(ec.services, service)
}
493666
func WaitForService(c kubernetes.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error {
	err := wait.PollImmediate(interval, timeout, func() (bool, error) {
		_, err := c.Core().Services(namespace).Get(name, metav1.GetOptions{})
		switch {
		case err == nil:
			glog.Infof("Service %s in namespace %s found.", name, namespace)
			return exist, nil
		case apierrs.IsNotFound(err):
			glog.Infof("Service %s in namespace %s disappeared.", name, namespace)
			return !exist, nil
		case !IsRetryableAPIError(err):
			glog.Info("Non-retryable failure while getting service.")
			return false, err
		default:
			glog.Infof("Get service %s in namespace %s failed: %v", name, namespace, err)
			return false, nil
		}
	})
	if err != nil {
		stateMsg := map[bool]string{true: "to appear", false: "to disappear"}
		return fmt.Errorf("error waiting for service %s/%s %s: %v", namespace, name, stateMsg[exist], err)
	}
	return nil
}
85585
func (sys *System) detectService() {
	switch DetectService() {
	case "upstart":
		sys.NewService = NewServiceUpstart
	case "systemd":
		sys.NewService = NewServiceSystemd
	case "alpineinit":
		sys.NewService = NewAlpineServiceInit
	default:
		sys.NewService = NewServiceInit
	}
}
775276
func serviceToAgentService(svc *structs.ServiceDefinition) (*api.AgentServiceRegistration, error) {
	// mapstructure can do this for us, but we encapsulate it in this
	// helper function in case we need to change the logic in the future.
	var result api.AgentServiceRegistration
	d, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
		Result:           &result,
		DecodeHook:       timeDurationToStringHookFunc(),
		WeaklyTypedInput: true,
	})
	if err != nil {
		return nil, err
	}
	if err := d.Decode(svc); err != nil {
		return nil, err
	}

	// The structs version has non-pointer checks and the destination
	// has pointers, so we need to set the destination to nil if there
	// is no check ID set.
	if result.Check != nil && result.Check.Name == "" {
		result.Check = nil
	}
	if len(result.Checks) == 1 && result.Checks[0].Name == "" {
		result.Checks = nil
	}

	return &result, nil
}
867669
func (_m *FacadeInterface) GetHealthChecksForService(ctx datastore.Context, id string) (map[string]health.HealthCheck, error) {
	ret := _m.Called(ctx, id)

	var r0 map[string]health.HealthCheck
	if rf, ok := ret.Get(0).(func(datastore.Context, string) map[string]health.HealthCheck); ok {
		r0 = rf(ctx, id)
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(map[string]health.HealthCheck)
		}
	}

	var r1 error
	if rf, ok := ret.Get(1).(func(datastore.Context, string) error); ok {
		r1 = rf(ctx, id)
	} else {
		r1 = ret.Error(1)
	}

	return r0, r1
}