// AddService Adds a service to a configurations.
184989
func AddService(configuration *config.HTTPConfiguration, serviceName string, service *config.Service) bool {
	if _, ok := configuration.Services[serviceName]; !ok {
		configuration.Services[serviceName] = service
		return true
	}

	if !configuration.Services[serviceName].LoadBalancer.Mergeable(service.LoadBalancer) {
		return false
	}

	configuration.Services[serviceName].LoadBalancer.Servers = append(configuration.Services[serviceName].LoadBalancer.Servers, service.LoadBalancer.Servers...)
	return true
}
849646
func (s *Store) AddService(service string, config *discoverd.ServiceConfig) error {
	if config == nil {
		config = DefaultServiceConfig
	}

	// Serialize command.
	cmd, err := json.Marshal(&addServiceCommand{
		Service: service,
		Config:  config,
	})
	if err != nil {
		return err
	}

	if _, err := s.raftApply(addServiceCommandType, cmd); err != nil {
		return err
	}
	return err
}
1120980
func (device *Device) FindService(serviceType string) []*Service {
	var services []*Service
	device.VisitServices(func(s *Service) {
		if s.ServiceType == serviceType {
			services = append(services, s)
		}
	})
	return services
}
317152
func (a *Agent) addServiceLocked(service *structs.NodeService, chkTypes []*structs.CheckType, persist bool, token string, source configSource) error {
	if err := a.validateService(service, chkTypes); err != nil {
		return err
	}

	if a.config.EnableCentralServiceConfig {
		return a.serviceManager.AddService(service, chkTypes, persist, token, source)
	}

	return a.addServiceInternal(service, chkTypes, persist, token, source)
}
1269683
func (lb *LoadBalancer) AddService(svc LBSVC) bool {
	scopedLog := log.WithFields(logrus.Fields{
		logfields.ServiceName: svc.FE.String(),
		logfields.SHA:         svc.Sha256,
	})

	oldSvc, ok := lb.SVCMapID[ServiceID(svc.FE.ID)]
	if ok {
		// If service already existed, remove old entry from Cilium's map
		scopedLog.Debug("service is already in lb.SVCMapID; deleting old entry and updating it with new entry")
		delete(lb.SVCMap, oldSvc.Sha256)
		updateMetric.Inc()
	} else {
		addMetric.Inc()
	}
	scopedLog.Debug("adding service to loadbalancer")
	lb.SVCMap[svc.Sha256] = svc
	lb.SVCMapID[ServiceID(svc.FE.ID)] = &svc
	return !ok
}
1015327
func (i *Infrastructure) MergeService(name string, s Service) {
	i.Lock.Lock()
	if _, ok := i.Services[name]; ok {
		i.Services[name].Addresses = append(i.Services[name].Addresses, s.Addresses...)
		i.Lock.Unlock()
		return
	}
	i.Services[name] = &s
	i.Lock.Unlock()
}
833520
func (m ServiceMap) Add(service service.ServiceDetails) error {
	if _, ok := m[service.ID]; ok {
		return fmt.Errorf("service already exists")
	}
	m[service.ID] = service
	return nil
}
32745
func GetConfigService(c context.Context) configInterface.Interface {
	if iface, ok := c.Value(&configInterfaceKey).(configInterface.Interface); ok {
		return iface
	}
	return nil
}
553904
func (s *DescribeTaskSetsInput) SetService(v string) *DescribeTaskSetsInput {
	s.Service = &v
	return s
}
1071762
func AddNodeWithService(serviceName string) AddNodeOption {
	return func(o *adapters.NodeConfig) {
		o.Services = append(o.Services, serviceName)
	}
}
140182
func (s *CreateServiceOutput) SetService(v *Service) *CreateServiceOutput {
	s.Service = v
	return s
}
1075061
func (na *NetAddress) HasService(service ServiceFlag) bool {
	return na.Services&service == service
}
482123
func RegisterService(name string, port int, ttl int) {
	go registerService(name, port, ttl)
}
1140163
func (p *Processor) AddOrUpdateService(apis *urisearch.APICache, serviceType policy.UserAuthorizationTypeValues, handler usertokens.Verifier, mappings map[string]string) {
	p.Lock()
	defer p.Unlock()

	p.apis = apis
	p.userTokenMappings = mappings
	p.userTokenHandler = handler
	p.userAuthorizationType = serviceType
}
1288576
func AddServiceTCP(configuration *config.TCPConfiguration, serviceName string, service *config.TCPService) bool {
	if _, ok := configuration.Services[serviceName]; !ok {
		configuration.Services[serviceName] = service
		return true
	}

	if !configuration.Services[serviceName].LoadBalancer.Mergeable(service.LoadBalancer) {
		return false
	}

	configuration.Services[serviceName].LoadBalancer.Servers = append(configuration.Services[serviceName].LoadBalancer.Servers, service.LoadBalancer.Servers...)
	return true
}
542027
func (f *Facade) AddServiceTemplate(ctx datastore.Context, serviceTemplate servicetemplate.ServiceTemplate, reloadLogstashConfig bool) (string, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.AddServiceTemplate"))
	alog := f.auditLogger.Message(ctx, "Adding Service Template").
		Action(audit.Add).Type(serviceTemplate.GetType())
	logger := plog.WithFields(logrus.Fields{
		"template":       serviceTemplate.Name,
		"reloadlogstash": reloadLogstashConfig,
	})
	store := f.templateStore
	hash, err := serviceTemplate.Hash()
	if err != nil {
		return "", alog.Error(err)
	}
	serviceTemplate.ID = hash
	alog = alog.Entity(&serviceTemplate)
	// Look up the template by ID
	if st, err := store.Get(ctx, hash); err != nil && !datastore.IsErrNoSuchEntity(err) {
		logger.WithError(err).WithField("hash", hash).Error("Could not look up service template by hash")
		return "", alog.Error(err)
	} else if st != nil {
		logger.Info("Not replacing existing template")
		alog.Succeeded()
		return hash, nil
	}
	// Look up the template by md5 hash
	logger = logger.WithField("hash", hash)
	if tid, err := f.getServiceTemplateByMD5Sum(ctx, hash); err != nil {
		logger.WithError(err).Error("Could not verify existance of template by md5sum")
		alog.Succeeded()
		return "", nil
	} else if tid != "" {
		logger.WithField("tid", tid).Info("Not replacing existing template")
		alog.Succeeded()
		return tid, nil
	}
	// Add the template to the database
	if err := store.Put(ctx, serviceTemplate); err != nil {
		logger.WithError(err).Error("Could not add template")
		return "", alog.Error(err)
	}

	if err := f.UpdateLogFilters(ctx, &serviceTemplate); err != nil {
		logger.WithError(err).Error("Could not add/update logfilters for template")
		return "", alog.Error(err)
	}

	logger.WithField("templateid", serviceTemplate.ID).Info("Added template")
	// This takes a while so don't block the main thread
	if reloadLogstashConfig {
		go LogstashContainerReloader(ctx, f)
	}
	return hash, alog.Error(err)
}
1031157
func (ep *endpoint) disableService() {
	ep.Lock()
	defer ep.Unlock()
	ep.serviceEnabled = false
}