// GetServiceVHosts retrieves service endpoints that specify a virtual HostPort
556478
func (s *Service) GetServiceVHosts() []ServiceEndpoint {
	result := []ServiceEndpoint{}

	if s.Endpoints != nil {
		for _, ep := range s.Endpoints {
			if len(ep.VHostList) > 0 {
				result = append(result, ep)
			}
		}
	}

	return result
}
46893
func (api *SystemAPI) GetSystemVms() (result *VMs, err error) {
	res, err := api.client.restClient.GetList(api.client.Endpoint, api.getEndpointUrl("vms"),
		api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &VMs{}
	err = json.Unmarshal(res, result)
	return
}
1286699
func (b *bpfService) getBackendsV2() map[BackendAddrID]ServiceValue {
	b.mutex.RLock()
	defer b.mutex.RUnlock()

	backends := make(map[BackendAddrID]ServiceValue, len(b.backendsV2))
	for addrID, backend := range b.backendsV2 {
		backends[addrID] = backend
	}

	return backends
}
1292950
func (lb *LoadBalancerRR) ServiceHasEndpoints(svcPort proxy.ServicePortName) bool {
	lb.lock.RLock()
	defer lb.lock.RUnlock()
	state, exists := lb.services[svcPort]
	// TODO: while nothing ever assigns nil to the map, *some* of the code using the map
	// checks for it.  The code should all follow the same convention.
	return exists && state != nil && len(state.endpoints) > 0
}
1036813
func (a *api) GetServiceTemplates() ([]template.ServiceTemplate, error) {
	client, err := a.connectMaster()
	if err != nil {
		return nil, err
	}

	templateMap, err := client.GetServiceTemplates()
	if err != nil {
			return nil, err
	}
	templates := make([]template.ServiceTemplate, len(templateMap))
	i := 0
	for id, t := range templateMap {
		t.ID = id
		templates[i] = t
		i++
	}

	return templates, nil
}
373007
func (a *api) GetEndpoints(serviceID string, reportImports, reportExports, validate bool) ([]applicationendpoint.EndpointReport, error) {
	client, err := a.connectMaster()
	if err != nil {
		return nil, err
	}

	serviceIDs := make([]string, 0)
	serviceIDs = append(serviceIDs, serviceID)
	if endpoints, err := client.GetServiceEndpoints(serviceIDs, reportImports, reportExports, validate); err != nil {
		return nil, err
	} else {
		return endpoints, nil
	}
}
35569
func (svc *Service) PortForServicePort(findPort int64, pType string) int64 {
	for _, port := range svc.Ports {
		if port.ServicePort == findPort && port.Type == pType {
			return port.Port
		}
	}

	log.Warnf("Unable to find ServicePort %d for service %s", findPort, svc.ID)
	return -1
}
766044
func (sc *ServiceConfig) getRoutes() []rest.Route {

	gz := gzipHandler

	routes := []rest.Route{
		rest.Route{"GET", "/", gz(mainPage)},

		// Backups
		rest.Route{"GET", "/backup/check", gz(sc.authorizedClient(RestBackupCheck))},
		rest.Route{"GET", "/backup/create", gz(sc.authorizedClient(RestBackupCreate))},
		rest.Route{"GET", "/backup/restore", gz(sc.authorizedClient(RestBackupRestore))},
		rest.Route{"GET", "/backup/list", gz(sc.authorizedClient(RestBackupFileList))},
		rest.Route{"GET", "/backup/status", gz(sc.authorizedClient(RestBackupStatus))},
		rest.Route{"GET", "/backup/restore/status", gz(sc.authorizedClient(RestRestoreStatus))},

		// Hosts
		rest.Route{"GET", "/hosts", gz(sc.checkAuth(restGetHosts))},
		rest.Route{"GET", "/hosts/running", gz(sc.checkAuth(restGetActiveHostIDs))},
		rest.Route{"GET", "/hosts/defaultHostAlias", gz(sc.checkAuth(restGetDefaultHostAlias))},
		rest.Route{"GET", "/hosts/:hostId", gz(sc.checkAuth(restGetHost))},
		rest.Route{"POST", "/hosts/add", gz(sc.checkAuth(restAddHost))},
		rest.Route{"DELETE", "/hosts/:hostId", gz(sc.checkAuth(restRemoveHost))},
		rest.Route{"PUT", "/hosts/:hostId", gz(sc.checkAuth(restUpdateHost))},
		rest.Route{"GET", "/hosts/:hostId/running", gz(sc.authorizedClient(restGetRunningForHost))},
		rest.Route{"DELETE", "/hosts/:hostId/:serviceStateId", gz(sc.authorizedClient(restKillRunning))},
		rest.Route{"POST", "/hosts/:hostId/key", gz(sc.checkAuth(restResetHostKey))},

		// Pools
		rest.Route{"GET", "/pools/:poolId", gz(sc.checkAuth(restGetPool))},
		rest.Route{"DELETE", "/pools/:poolId", gz(sc.checkAuth(restRemovePool))},
		rest.Route{"PUT", "/pools/:poolId", gz(sc.checkAuth(restUpdatePool))},
		rest.Route{"POST", "/pools/add", gz(sc.checkAuth(restAddPool))},
		rest.Route{"GET", "/pools", gz(sc.checkAuth(restGetPools))},
		rest.Route{"GET", "/pools/:poolId/hosts", gz(sc.checkAuth(restGetHostsForResourcePool))},

		// Pools (VirtualIP)
		rest.Route{"PUT", "/pools/:poolId/virtualip", gz(sc.checkAuth(restAddPoolVirtualIP))},
		rest.Route{"DELETE", "/pools/:poolId/virtualip/*ip", gz(sc.checkAuth(restRemovePoolVirtualIP))},

		// Pools (IPs)
		rest.Route{"GET", "/pools/:poolId/ips", gz(sc.checkAuth(restGetPoolIps))},

		// Services (Apps)
		rest.Route{"GET", "/services", gz(sc.checkAuth(restGetAllServices))},
		rest.Route{"GET", "/servicehealth", gz(sc.checkAuth(restGetServicesHealth))},
		rest.Route{"GET", "/services/:serviceId", gz(sc.authorizedClient(restGetService))},
		rest.Route{"GET", "/services/:serviceId/running", gz(sc.authorizedClient(restGetRunningForService))},
		rest.Route{"GET", "/services/:serviceId/:serviceStateId/logs", gz(sc.authorizedClient(restGetServiceStateLogs))},
		rest.Route{"GET", "/services/:serviceId/:serviceStateId/logs/download", gz(sc.authorizedClient(downloadServiceStateLogs))},
		rest.Route{"POST", "/services/add", gz(sc.authorizedClient(restAddService))},
		rest.Route{"POST", "/services/deploy", gz(sc.authorizedClient(restDeployService))},
		rest.Route{"PUT", "/services/restartServices", gz(sc.checkAuth(restRestartServices))},
		rest.Route{"PUT", "/services/startServices", gz(sc.checkAuth(restStartServices))},
		rest.Route{"PUT", "/services/stopServices", gz(sc.checkAuth(restStopServices))},
		rest.Route{"DELETE", "/services/:serviceId", gz(sc.checkAuth(restRemoveService))},
		rest.Route{"GET", "/services/:serviceId/logs", gz(sc.authorizedClient(restGetServiceLogs))},
		rest.Route{"PUT", "/services/:serviceId", gz(sc.authorizedClient(restUpdateService))},
		rest.Route{"GET", "/services/:serviceId/snapshot", gz(sc.authorizedClient(restSnapshotService))},
		rest.Route{"PUT", "/services/:serviceId/restartService", gz(sc.checkAuth(restRestartService))},
		rest.Route{"PUT", "/services/:serviceId/startService", gz(sc.checkAuth(restStartService))},
		rest.Route{"PUT", "/services/:serviceId/stopService", gz(sc.checkAuth(restStopService))},
		rest.Route{"POST", "/services/:serviceId/migrate", sc.authorizedClient(restPostServicesForMigration)},

		// Services (Virtual Host)
		rest.Route{"PUT", "/services/:serviceId/endpoint/:application/vhosts/*name", gz(sc.checkAuth(restAddVirtualHost))},
		rest.Route{"DELETE", "/services/:serviceId/endpoint/:application/vhosts/*name", gz(sc.checkAuth(restRemoveVirtualHost))},
		rest.Route{"POST", "/services/:serviceId/endpoint/:application/vhosts/*name", gz(sc.checkAuth(restVirtualHostEnable))},
		// Services (Endpoint Ports)
		rest.Route{"PUT", "/services/:serviceId/endpoint/:application/ports/*portname", gz(sc.checkAuth(restAddPort))},
		rest.Route{"DELETE", "/services/:serviceId/endpoint/:application/ports/*portname", gz(sc.checkAuth(restRemovePort))},
		rest.Route{"POST", "/services/:serviceId/endpoint/:application/ports/*portname", gz(sc.checkAuth(restPortEnable))},

		// Services (IP)
		rest.Route{"PUT", "/services/:serviceId/ip", gz(sc.checkAuth(restServiceAutomaticAssignIP))},
		rest.Route{"PUT", "/services/:serviceId/ip/*ip", gz(sc.checkAuth(restServiceManualAssignIP))},

		// Service templates (App templates)
		rest.Route{"GET", "/templates", gz(sc.checkAuth(restGetAppTemplates))},
		rest.Route{"POST", "/templates/add", gz(sc.checkAuth(restAddAppTemplate))},
		rest.Route{"DELETE", "/templates/:templateId", gz(sc.checkAuth(restRemoveAppTemplate))},
		rest.Route{"POST", "/templates/deploy", gz(sc.checkAuth(restDeployAppTemplate))},
		rest.Route{"POST", "/templates/deploy/status", gz(sc.checkAuth(restDeployAppTemplateStatus))},
		rest.Route{"GET", "/templates/deploy/active", gz(sc.checkAuth(restDeployAppTemplateActive))},

		// Login
		rest.Route{"POST", "/login", gz(sc.noAuth(restLogin))},
		rest.Route{"DELETE", "/login", gz(restLogout)},

		// "Misc" stuff
		rest.Route{"GET", "/top/services", gz(sc.checkAuth(restGetTopServices))},
		rest.Route{"GET", "/config", gz(sc.authorizedClient(restGetUIConfig))},
		rest.Route{"GET", "/servicestatus", gz(sc.checkAuth(restGetConciseServiceStatus))},

		// Generic static data
		rest.Route{"GET", "/favicon.ico", gz(favIcon)},
		rest.Route{"GET", "/static/globals.js", sc.noAuth(restGetAuth0Config)},
		rest.Route{"GET", "/static/*resource", gz(staticData)},
		rest.Route{"GET", "/licenses.html", gz(licenses)},

		// Info about serviced itself
		rest.Route{"GET", "/dockerIsLoggedIn", gz(sc.authorizedClient(restDockerIsLoggedIn))},
		rest.Route{"GET", "/stats", gz(sc.isCollectingStats())},
		rest.Route{"GET", "/version", gz(restGetServicedVersion)},
		rest.Route{"GET", "/storage", gz(sc.authorizedClient(restGetStorage))},

		// V2 API
		rest.Route{"GET", "/api/v2/pools", gz(sc.checkAuth(getPools))},
		rest.Route{"GET", "/api/v2/pools/:poolId/hosts", gz(sc.checkAuth(getHostsForPool))},
		rest.Route{"GET", "/api/v2/hosts", gz(sc.checkAuth(getHosts))},
		rest.Route{"GET", "/api/v2/hosts/:hostId/instances", gz(sc.checkAuth(restGetHostInstances))},
		rest.Route{"GET", "/api/v2/internalservices", gz(sc.checkAuth(getAllInternalServices))},
		rest.Route{"GET", "/api/v2/internalservices/:id", gz(sc.checkAuth(getInternalService))},
		rest.Route{"GET", "/api/v2/internalservices/:id/instances", gz(sc.checkAuth(getInternalServiceInstances))},
		rest.Route{"GET", "/api/v2/internalservicestatuses", gz(sc.checkAuth(getInternalServiceStatuses))},
		rest.Route{"GET", "/api/v2/services", gz(sc.checkAuth(getAllServiceDetails))},
		rest.Route{"GET", "/api/v2/services/:serviceId", gz(sc.checkAuth(getServiceDetails))},
		rest.Route{"PUT", "/api/v2/services/:serviceId", gz(sc.checkAuth(putServiceDetails))},
		rest.Route{"GET", "/api/v2/services/:serviceId/services", gz(sc.checkAuth(getChildServiceDetails))},
		rest.Route{"GET", "/api/v2/services/:serviceId/instances", gz(sc.checkAuth(restGetServiceInstances))},
		rest.Route{"GET", "/api/v2/services/:serviceId/monitoringprofile", gz(sc.checkAuth(restGetServiceMonitoringProfile))},
		rest.Route{"GET", "/api/v2/services/:serviceId/publicendpoints", gz(sc.checkAuth(restGetServicePublicEndpoints))},
		rest.Route{"GET", "/api/v2/services/:serviceId/ipassignments", gz(sc.checkAuth(restGetServiceIPAssignments))},
		rest.Route{"GET", "/api/v2/services/:serviceId/exportendpoints", gz(sc.checkAuth(restGetServiceExportedEndpoints))},
		rest.Route{"GET", "/api/v2/services/:serviceId/descendantstates", gz(sc.checkAuth(restCountDescendantStates))},
		rest.Route{"GET", "/api/v2/services/:serviceId/context", gz(sc.checkAuth(getServiceContext))},
		rest.Route{"PUT", "/api/v2/services/:serviceId/context", gz(sc.checkAuth(putServiceContext))},
		rest.Route{"GET", "/api/v2/statuses", gz(sc.checkAuth(restGetAggregateServices))},
		rest.Route{"GET", "/api/v2/hoststatuses", gz(sc.checkAuth(getHostStatuses))},

		rest.Route{"GET", "/api/v2/services/:serviceId/serviceconfigs", gz(sc.checkAuth(restGetServiceConfigFiles))},
		rest.Route{"POST", "/api/v2/services/:serviceId/serviceconfigs", gz(sc.checkAuth(restAddServiceConfigFile))},
		rest.Route{"GET", "/api/v2/serviceconfigs/:fileId", gz(sc.checkAuth(restGetServiceConfigFile))},
		rest.Route{"PUT", "/api/v2/serviceconfigs/:fileId", gz(sc.checkAuth(restUpdateServiceConfigFile))},
		rest.Route{"DELETE", "/api/v2/serviceconfigs/:fileId", gz(sc.checkAuth(restDeleteServiceConfigFile))},
	}

	// Hardcoding these target URLs for now.
	// TODO: When internal services are allowed to run on other hosts, look that up.
	// All API calls require authentication
	routes = routeToInternalServiceProxy("/api/controlplane/elastic", "http://127.0.0.1:9100/", true, routes)
	routes = routeToInternalServiceProxy("/metrics/api", "http://127.0.0.1:8888/api", true, routes)
	routes = routeToInternalServiceProxy("/api/controlplane/kibana", "http://127.0.0.1:5601", true, routes)

	// Allow static assets for metrics data to be loaded without authentication since they are
	// included in index.html by default.
	routes = routeToInternalServiceProxy("/metrics/static", "http://127.0.0.1:8888/static", false, routes)

	return routes
}
851929
func (s *Server) GetServiceTemplates(unused struct{}, response *map[string]servicetemplate.ServiceTemplate) error  {
	templates, err := s.f.GetServiceTemplates(s.context())
	if err != nil {
		return err
	}
	*response = templates
	return nil
}
1154808
func (c *Cluster) GetAllHosts() []*Host {
	hosts := make([]*Host, 0, len(c.hostsCache))

	if err := c.Update(); err != nil {
		c.logger.Log("level", "error", "message", "error getting the list of hosts based on the internal cache: %#v", "stack", err)
		return hosts
	}

	for _, cachedHost := range c.hostsCache {
		hosts = append(hosts, cachedHost.get())
	}
	return hosts
}
859621
func (api *InfraHostsAPI) GetHosts() (result *Hosts, err error) {
	uri := api.client.Endpoint + InfraHostsUrl
	res, err := api.client.restClient.GetList(api.client.Endpoint, uri, api.client.options.TokenOptions)
	if err != nil {
		return
	}

	result = &Hosts{}
	err = json.Unmarshal(res, result)
	return
}
858878
func (lbc *loadBalancerController) getEndpoints(
	s *api.Service, servicePort *api.ServicePort) (endpoints []string) {
	ep, err := lbc.epLister.GetServiceEndpoints(s)
	if err != nil {
		return
	}

	// The intent here is to create a union of all subsets that match a targetPort.
	// We know the endpoint already matches the service, so all pod ips that have
	// the target port are capable of service traffic for it.
	for _, ss := range ep.Subsets {
		for _, epPort := range ss.Ports {
			var targetPort int
			switch servicePort.TargetPort.Type {
			case intstr.Int:
				if epPort.Port == getTargetPort(servicePort) {
					targetPort = epPort.Port
				}
			case intstr.String:
				if epPort.Name == servicePort.TargetPort.StrVal {
					targetPort = epPort.Port
				}
			}
			if targetPort == 0 {
				continue
			}
			for _, epAddress := range ss.Addresses {
				endpoints = append(endpoints, fmt.Sprintf("%v:%v", epAddress.IP, targetPort))
			}
		}
	}
	return
}
457401
func (c *Client) APIHostPorts() ([][]network.HostPort, error) {
	var result params.APIHostPortsResult
	if err := c.facade.FacadeCall("APIHostPorts", nil, &result); err != nil {
		return nil, err
	}
	return result.NetworkHostsPorts(), nil
}
37537
func (vm *VM) listHostedServices() ([]hostedservice.HostedService, error) {
	sc, err := vm.getServiceClient()
	if err != nil {
		return nil, fmt.Errorf(errGetClient, err)
	}

	resp, err := sc.ListHostedServices()
	if err != nil {
		return nil, err
	}

	return resp.HostedServices, nil
}
757582
func (f *Facade) getServices(ctx datastore.Context) ([]service.Service, error) {
	defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.getServices"))
	plog.Debug("Started Facade.getServices")
	defer plog.Debug("Finished Facade.getServices")

	store := f.serviceStore
	results, err := store.GetServices(ctx)
	if err != nil {
		plog.WithError(err).Error("Unable to get a list of all services")
		return results, err
	}
	return results, nil
}
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, ", ")
}
308849
func (s *Server) GetServiceEndpoints(request *EndpointRequest, reply *[]applicationendpoint.EndpointReport) error {
	endpoints, err := s.f.GetServiceEndpoints(s.context(), request.ServiceIDs[0], request.ReportImports, request.ReportExports, request.Validate)
	if err != nil {
		return err
	}

	*reply = endpoints
	return nil
}