// FindUnitServiceNames accepts a collection of service names as managed by the
// local init system. Any that are identified as being for unit agents are
// returned, keyed on the unit name.
977777
func FindUnitServiceNames(svcNames []string) map[string]string {
	svcMatcher := regexp.MustCompile("^(jujud-.*unit-([a-z0-9-]+)-([0-9]+))$")
	unitServices := make(map[string]string)
	for _, svc := range svcNames {
		if groups := svcMatcher.FindStringSubmatch(svc); len(groups) > 0 {
			unitName := groups[2] + "/" + groups[3]
			if names.IsValidUnit(unitName) {
				unitServices[unitName] = groups[1]
			}
		}
	}
	return unitServices
}
1213183
func (f *Facade) validateServiceName(ctx datastore.Context, svc *service.Service) error {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.validateServiceName"))
	store := f.serviceStore
	if svc.ParentServiceID != "" {
		psvc, err := store.Get(ctx, svc.ParentServiceID)
		if err != nil {
			glog.Errorf("Could not verify the existance of parent %s for service %s: %s", svc.ParentServiceID, svc.Name, err)
			return err
		}
		svc.DeploymentID = psvc.DeploymentID
	}
	cursvc, err := store.FindChildService(ctx, svc.DeploymentID, svc.ParentServiceID, svc.Name)
	if err != nil {
		glog.Errorf("Could not check the service name %s for parent %s: %s", svc.Name, svc.ParentServiceID, err)
		return err
	}
	if cursvc != nil {
		return ErrServiceCollision
	}
	return nil
}
1233402
func ValidServiceName(service string) error {
	// Blank service names are not allowed.
	if service == "" {
		return ErrUnsetService
	}

	// Service names must consist of the characters [a-z0-9-]
	for _, r := range service {
		if (r < 'a' || r > 'z') && (r < '0' || r > '9') && r != '-' {
			return ErrInvalidService
		}
	}

	return nil
}
1076887
func (s *Server) initializeServices() error {
	serviceNames, err := s.Store.List("/services/")
	if err != nil {
		return err
	}
	for _, serviceName := range serviceNames {
		service := Service{}
		if err := s.Store.Get(fmt.Sprintf("/services/%s", serviceName), &service); err != nil {
			return err
		}

		s.idpConfigMu.Lock()
		s.serviceProviders[service.Metadata.EntityID] = &service.Metadata
		s.idpConfigMu.Unlock()
	}
	return nil
}
214166
func ValidateServiceName(name string, prefix bool) (bool, string) {
	return NameIsDNS952Label(name, prefix)
}
358919
func (c *Client) GetServices(ctx context.Context) (map[string]string, error) {
	var services map[string]string

	req, err := c.NewRequest("GET", servicesPath, nil, nil)
	if err != nil {
		return nil, err
	}

	if err := c.Do(ctx, req, &services); err != nil {
		return nil, err
	}

	return services, err
}
823693
func (c Client) GetServiceLabels(service *ServiceItem, app *ApplicationItem, prefix string) (map[string]string, error) {
	extensionData := ServiceExtensionLabels{}
	err := c.GetServiceExtension(app.TypeName, app.TypeVersion, service.TypeName, prefix, &extensionData)
	if err != nil {
		return nil, err
	}

	prefixPeriod := prefix + "."

	labels := map[string]string{}
	if extensionData.Label != nil {
		for _, label := range extensionData.Label {
			if strings.HasPrefix(label.Key, prefixPeriod) {
				labelKey := strings.Replace(label.Key, prefixPeriod, "", -1)
				labels[labelKey] = label.Value
			}
		}
	}

	exists, properties, err := c.GetProperties(service.ID)
	if err != nil {
		return nil, err
	}

	if exists {
		for k, v := range properties {
			if strings.HasPrefix(k, prefixPeriod) {
				labelKey := strings.Replace(k, prefixPeriod, "", -1)
				labels[labelKey] = v
			}
		}
	}

	return labels, nil
}
927383
func (client *Client) GetServiceBindings(filters ...Filter) ([]ServiceBinding, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetServiceBindingsRequest,
		Query:       ConvertFilterParameters(filters),
	})
	if err != nil {
		return nil, nil, err
	}

	var fullBindingsList []ServiceBinding
	warnings, err := client.paginate(request, ServiceBinding{}, func(item interface{}) error {
		if binding, ok := item.(ServiceBinding); ok {
			fullBindingsList = append(fullBindingsList, binding)
		} else {
			return ccerror.UnknownObjectInListError{
				Expected:   ServiceBinding{},
				Unexpected: item,
			}
		}
		return nil
	})

	return fullBindingsList, warnings, err
}
466218
func getAllUnitNames(st *state.State, units, services []string) (result []names.Tag, err error) {
	var leaders map[string]string
	getLeader := func(appName string) (string, error) {
		if leaders == nil {
			var err error
			leaders, err = st.ApplicationLeaders()
			if err != nil {
				return "", err
			}
		}
		if leader, ok := leaders[appName]; ok {
			return leader, nil
		}
		return "", errors.Errorf("could not determine leader for %q", appName)
	}

	// Replace units matching $app/leader with the appropriate unit for
	// the leader.
	unitsSet := set.NewStrings()
	for _, unit := range units {
		if !strings.HasSuffix(unit, "leader") {
			unitsSet.Add(unit)
			continue
		}

		app := strings.Split(unit, "/")[0]
		leaderUnit, err := getLeader(app)
		if err != nil {
			return nil, common.ServerError(err)
		}

		unitsSet.Add(leaderUnit)
	}

	for _, name := range services {
		service, err := st.Application(name)
		if err != nil {
			return nil, err
		}
		units, err := service.AllUnits()
		if err != nil {
			return nil, err
		}
		for _, unit := range units {
			unitsSet.Add(unit.Name())
		}
	}
	for _, unitName := range unitsSet.SortedValues() {
		if !names.IsValidUnit(unitName) {
			return nil, errors.Errorf("invalid unit name %q", unitName)
		}
		result = append(result, names.NewUnitTag(unitName))
	}
	return result, nil
}
366617
func findServicesMessagesAndEnumerations(s []*descriptor.Service, reg *descriptor.Registry, m messageMap, ms messageMap, e enumMap, refs refMap) {
	for _, svc := range s {
		for _, meth := range svc.Methods {
			// Request may be fully included in query
			if _, ok := refs[fmt.Sprintf("#/definitions/%s", fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg))]; ok {
				if !skipRenderingRef(meth.RequestType.FQMN()) {
					m[fullyQualifiedNameToSwaggerName(meth.RequestType.FQMN(), reg)] = meth.RequestType
				}
			}
			findNestedMessagesAndEnumerations(meth.RequestType, reg, m, e)

			if !skipRenderingRef(meth.ResponseType.FQMN()) {
				m[fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)] = meth.ResponseType
				if meth.GetServerStreaming() {
					runtimeStreamError := fullyQualifiedNameToSwaggerName(".grpc.gateway.runtime.StreamError", reg)
					glog.V(1).Infof("StreamError FQMN: %s", runtimeStreamError)
					streamError, err := reg.LookupMsg(".grpc.gateway.runtime", "StreamError")
					if err == nil {
						glog.V(1).Infof("StreamError: %v", streamError)
						m[runtimeStreamError] = streamError
						findNestedMessagesAndEnumerations(streamError, reg, m, e)
					} else {
						//just in case there is an error looking up StreamError
						glog.Error(err)
					}
					ms[fullyQualifiedNameToSwaggerName(meth.ResponseType.FQMN(), reg)] = meth.ResponseType
				}
			}
			findNestedMessagesAndEnumerations(meth.ResponseType, reg, m, e)
		}
	}
}
30852
func (m *marathonAdapter) GetServices() ([]*api.Service, *api.Error) {
	var apiErr *api.Error

	response, err := m.client.ListApps()
	if err != nil {
		apiErr = api.NewError(http.StatusNotFound, err.Error())
		return nil, apiErr
	}
	return m.conv.convertToServices(response.Apps), apiErr
}
1282163
func getServiceName(service *v1.Service) string {
	return fmt.Sprintf("%s/%s", service.Namespace, service.Name)
}
1196937
func (client *Client) GetServiceInstanceServiceBindings(serviceInstanceGUID string) ([]ServiceBinding, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetServiceInstanceServiceBindingsRequest,
		URIParams:   map[string]string{"service_instance_guid": serviceInstanceGUID},
	})
	if err != nil {
		return nil, nil, err
	}

	var fullBindingsList []ServiceBinding
	warnings, err := client.paginate(request, ServiceBinding{}, func(item interface{}) error {
		if binding, ok := item.(ServiceBinding); ok {
			fullBindingsList = append(fullBindingsList, binding)
		} else {
			return ccerror.UnknownObjectInListError{
				Expected:   ServiceBinding{},
				Unexpected: item,
			}
		}
		return nil
	})

	return fullBindingsList, warnings, err
}
1022705
func FindServiceForFile(f *pb.FileDescriptorProto, name string) int {
	for i, x := range f.GetService() {
		if x.GetName() == name {
			return i
		}
	}
	return -1
}
1245778
func getAvailableServiceNames(svcMap map[string]struct{}) string {
	var serviceNames []string
	for key := range svcMap {
		serviceNames = append(serviceNames, strconv.Quote(key))
	}
	// Sort the string array to generate consistent result
	sort.Strings(serviceNames)
	return strings.Join(serviceNames, ", ")
}
297384
func (s *Server) ServiceNames() []string {
	s.mu.Lock()
	defer s.mu.Unlock()

	names := make([]string, 0, len(s.services))
	for name := range s.services {
		names = append(names, name)
	}
	sort.Strings(names)
	return names
}
124167
func GetStorageService(
	ctx types.Context, name string) types.StorageService {
	servicesByServerRWL.RLock()
	defer servicesByServerRWL.RUnlock()
	name = strings.ToLower(name)
	ctx.WithField("service", name).Debug("getting storage service")
	return getStorageServices(ctx)[name]
}