// GetApplicationSummaryByNameAndSpace returns an application with process and
// instance stats.
196800
func (actor Actor) GetApplicationSummaryByNameAndSpace(appName string, spaceGUID string, withObfuscatedValues bool) (ApplicationSummary, Warnings, error) {
	app, allWarnings, err := actor.GetApplicationByNameAndSpace(appName, spaceGUID)
	if err != nil {
		return ApplicationSummary{}, allWarnings, err
	}

	processSummaries, processWarnings, err := actor.getProcessSummariesForApp(app.GUID, withObfuscatedValues)
	allWarnings = append(allWarnings, processWarnings...)
	if err != nil {
		return ApplicationSummary{}, allWarnings, err
	}

	droplet, warnings, err := actor.GetCurrentDropletByApplication(app.GUID)
	allWarnings = append(allWarnings, Warnings(warnings)...)
	if err != nil {
		if _, ok := err.(actionerror.DropletNotFoundError); !ok {
			return ApplicationSummary{}, allWarnings, err
		}
	}

	summary := ApplicationSummary{
		Application:      app,
		ProcessSummaries: processSummaries,
		CurrentDroplet:   droplet,
	}
	return summary, allWarnings, nil
}
570340
func getAppName(appPath string) string {
	// Is "/" on both Windows and Linux
	split := strings.Split(appPath, "/")
	return split[len(split)-1]
}
1063929
func (a *HistoricalApi) namespaceMetrics(request *restful.Request, response *restful.Response) {
	key := core.HistoricalKey{
		ObjectType:    core.MetricSetTypeNamespace,
		NamespaceName: request.PathParameter("namespace-name"),
	}
	a.processMetricRequest(key, request, response)
}
1134686
func getSummary(c context.Context, host string, project string, id int64) (*model.BuildSummary, error) {
	client, err := buildbucketClient(c, host, auth.AsProject, auth.WithProject(project))
	if err != nil {
		return nil, err
	}
	b, err := client.GetBuild(c, &buildbucketpb.GetBuildRequest{
		Id:     id,
		Fields: summaryBuildMask,
	})
	if err != nil {
		return nil, err
	}
	buildAddress := fmt.Sprintf("%d", b.Id)
	if b.Number != 0 {
		buildAddress = fmt.Sprintf("luci.%s.%s/%s/%d", b.Builder.Project, b.Builder.Bucket, b.Builder.Builder, b.Number)
	}

	// Note: The parent for buildbucket build summaries is currently a fake entity.
	// In the future, builds can be cached here, but we currently don't do that.
	buildKey := datastore.MakeKey(c, "buildbucket.Build", fmt.Sprintf("%s:%s", host, buildAddress))
	swarming := b.GetInfra().GetSwarming()

	bs := &model.BuildSummary{
		ProjectID:  b.Builder.Project,
		BuildKey:   buildKey,
		BuilderID:  BuilderID{*b.Builder}.String(),
		BuildID:    "buildbucket/" + buildAddress,
		BuildSet:   protoutil.BuildSets(b),
		ContextURI: []string{fmt.Sprintf("buildbucket://%s/build/%d", host, id)},
		Created:    mustTimestamp(b.CreateTime),
		Summary: model.Summary{
			Start:  mustTimestamp(b.StartTime),
			End:    mustTimestamp(b.EndTime),
			Status: statusMap[b.Status],
		},
		Version:      mustTimestamp(b.UpdateTime).UnixNano(),
		Experimental: b.GetInput().GetExperimental(),
	}
	if task := swarming.GetTaskId(); task != "" {
		bs.ContextURI = append(
			bs.ContextURI,
			fmt.Sprintf("swarming://%s/task/%s", swarming.GetHostname(), swarming.GetTaskId()))
	}
	return bs, nil
}
788121
func (s *SupportImpl) GetApplicationConfig(cid string) (channelconfig.Application, bool) {
	return s.PeerSupport.GetApplicationConfig(cid)
}
34582
func (c *CheckRunOutput) GetSummary() string {
	if c == nil || c.Summary == nil {
		return ""
	}
	return *c.Summary
}
719766
func (t *Template) GetAllAWSServerlessApplicationResources() map[string]*resources.AWSServerlessApplication {
	results := map[string]*resources.AWSServerlessApplication{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSServerlessApplication:
			results[name] = resource
		}
	}
	return results
}
458667
func (s *ListRobotApplicationsOutput) SetRobotApplicationSummaries(v []*RobotApplicationSummary) *ListRobotApplicationsOutput {
	s.RobotApplicationSummaries = v
	return s
}
790230
func (actor Actor) GetApplicationByNameAndSpace(name string, spaceGUID string) (Application, Warnings, error) {
	app, warnings, err := actor.CloudControllerClient.GetApplications(
		ccv2.Filter{
			Type:     constant.NameFilter,
			Operator: constant.EqualOperator,
			Values:   []string{name},
		},
		ccv2.Filter{
			Type:     constant.SpaceGUIDFilter,
			Operator: constant.EqualOperator,
			Values:   []string{spaceGUID},
		},
	)

	if err != nil {
		return Application{}, Warnings(warnings), err
	}

	if len(app) == 0 {
		return Application{}, Warnings(warnings), actionerror.ApplicationNotFoundError{
			Name: name,
		}
	}

	return Application(app[0]), Warnings(warnings), nil
}
418341
func (api *API) ApplicationGetByHostIdAndName(hostId, name string) (res *Application, err error) {
	apps, err := api.ApplicationsGet(Params{"hostids": hostId, "filter": map[string]string{"name": name}})
	if err != nil {
		return
	}

	if len(apps) == 1 {
		res = &apps[0]
	} else {
		e := ExpectedOneResult(len(apps))
		err = &e
	}
	return
}
145698
func getApplicationHeaders(md metadata.MD) (transport.Headers, error) {
	if len(md) == 0 {
		return transport.Headers{}, nil
	}
	headers := transport.NewHeadersWithCapacity(md.Len())
	for header, values := range md {
		header = transport.CanonicalizeHeaderKey(header)
		if isReserved(header) {
			continue
		}
		var value string
		switch len(values) {
		case 0:
			continue
		case 1:
			value = values[0]
		default:
			return headers, yarpcerrors.InvalidArgumentErrorf("header has more than one value: %s", header)
		}
		headers = headers.With(header, value)
	}
	return headers, nil
}
461589
func (c *Client) GetApplications() ([]Application, error) {
	var appMap map[string]Application
	if err := c.get(`app/list`, &appMap); err != nil {
		return nil, err
	}

	var appList []Application
	for _, app := range appMap {
		appList = append(appList, app)
	}
	sort.Sort(applications(appList))
	return appList, nil
}
243187
func (k *kubernetesClient) getNamespaceByName(name string) (*core.Namespace, error) {
	ns, err := k.client().CoreV1().Namespaces().Get(name, v1.GetOptions{IncludeUninitialized: true})
	if k8serrors.IsNotFound(err) {
		return nil, errors.NotFoundf("namespace %q", name)
	}
	if err != nil {
		return nil, errors.Annotatef(err, "getting namespace %q", name)
	}
	return ns, nil
}
326774
func (up *tenantURLProvider) GetEnvironmentMapping() map[string]string {
	result := make(map[string]string)
	// Exclude internal namespaces where the user cannot deploy applications

	// Deployments API will receive requests by environment name (e.g. "run", "stage").
	// These names correspond to the "type" attribute in Namespaces.
	for envNS, attr := range up.namespaces {
		envName := attr.Type
		if envName == nil || len(*envName) == 0 {
			log.Error(nil, map[string]interface{}{
				"namespace": envNS,
			}, "namespace has no type")
		} else {
			result[*envName] = envNS
		}
	}
	return result
}
190075
func (client *Client) GetApplicationManifest(appGUID string) ([]byte, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetApplicationManifestRequest,
		URIParams:   internal.Params{"app_guid": appGUID},
	})
	if err != nil {
		return nil, nil, err
	}
	request.Header.Set("Accept", "application/x-yaml")

	var response cloudcontroller.Response
	err = client.connection.Make(request, &response)

	return response.RawResponse, response.Warnings, err
}
1042889
func (r *marathonClient) ListApplications(v url.Values) ([]string, error) {
	applications, err := r.Applications(v)
	if err != nil {
		return nil, err
	}
	var list []string
	for _, application := range applications.Apps {
		list = append(list, application.ID)
	}

	return list, nil
}
1126882
func (c Client) GetServices(appName string) (*ServiceItemsPage, error) {
	var aggregateServiceItemsPages ServiceItemsPage
	var continueToken string
	for {
		res, err := c.getHTTP("Applications/"+appName+"/$/GetServices", withContinue(continueToken))
		if err != nil {
			return nil, err
		}

		var servicesItemsPage ServiceItemsPage
		err = json.Unmarshal(res, &servicesItemsPage)
		if err != nil {
			return nil, fmt.Errorf("could not deserialise JSON response: %+v", err)
		}

		aggregateServiceItemsPages.Items = append(aggregateServiceItemsPages.Items, servicesItemsPage.Items...)

		continueToken = getString(servicesItemsPage.ContinuationToken)
		if continueToken == "" {
			break
		}
	}
	return &aggregateServiceItemsPages, nil
}