// getApp returns the app to export
// If one was supplied in the flags then it's returned if present
// If the PM contains a single app, that app is returned
// If the PM has multiple apps, the names are printed and an error is returned
165137
func getApp(p *pkgPod.Pod) (*schema.RuntimeApp, error) {
	_, manifest, err := p.PodManifest()
	if err != nil {
		return nil, errwrap.Wrap(errors.New("problem getting the pod's manifest"), err)
	}

	apps := manifest.Apps

	if flagExportAppName != "" {
		exportAppName, err := types.NewACName(flagExportAppName)
		if err != nil {
			return nil, err
		}
		for _, ra := range apps {
			if *exportAppName == ra.Name {
				return &ra, nil
			}
		}
		return nil, fmt.Errorf("app %s is not present in pod", flagExportAppName)
	}

	switch len(apps) {
	case 0:
		return nil, fmt.Errorf("pod contains zero apps")
	case 1:
		return &apps[0], nil
	default:
	}

	stderr.Print("pod contains multiple apps:")
	for _, ra := range apps {
		stderr.Printf("\t%v", ra.Name)
	}

	return nil, fmt.Errorf("specify app using \"rkt export --app= ...\"")
}
506429
func (c *FakeDeployments) Get(name string, options v1.GetOptions) (result *appsv1.Deployment, err error) {
	obj, err := c.Fake.
		Invokes(testing.NewGetAction(deploymentsResource, c.ns, name), &appsv1.Deployment{})

	if obj == nil {
		return nil, err
	}
	return obj.(*appsv1.Deployment), err
}
302745
func GetAppEnv() (AppEnv, error) {
	appEnv := AppEnv{}
	if err := env.Populate(&appEnv); err != nil {
		return AppEnv{}, err
	}
	return appEnv, nil
}
842341
func (p *Pod) getApps() (schema.AppList, error) {
	_, pm, err := p.PodManifest()
	if err != nil {
		return nil, err
	}
	return pm.Apps, nil
}
219821
func Get(c *deis.Client, appID string, version int) (api.Release, error) {
	u := fmt.Sprintf("/v2/apps/%s/releases/v%d/", appID, version)

	res, reqErr := c.Request("GET", u, nil)
	if reqErr != nil && !deis.IsErrAPIMismatch(reqErr) {
		return api.Release{}, reqErr
	}
	defer res.Body.Close()

	release := api.Release{}
	if err := json.NewDecoder(res.Body).Decode(&release); err != nil {
		return api.Release{}, err
	}

	return release, reqErr
}
873285
func GetAppTopics(app_name, org string) (*[]db.AvailableTopic, error) {
	session := db.Conn.Session.Copy()
	defer session.Close()

	query := utils.M{"app_name": app_name}
	var topics []db.AvailableTopic

	iter := db.Conn.GetCursor(
		session, db.AvailableTopicCollection, query,
	).Select(utils.M{"ident": 1, "channels": 1}).Sort("ident").Iter()

	err := iter.All(&topics)
	// TODO: handle this error

	return &topics, err
}
1087412
func Get(c *client.Client, appID string) (api.App, error) {
	u := fmt.Sprintf("/v1/apps/%s/", appID)

	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return api.App{}, err
	}

	app := api.App{}

	if err = json.Unmarshal([]byte(body), &app); err != nil {
		return api.App{}, err
	}

	return app, nil
}
1354947
func Get(c *client.Client, appID string, version int) (api.Release, error) {
	u := fmt.Sprintf("/v1/apps/%s/releases/v%d/", appID, version)

	body, err := c.BasicRequest("GET", u, nil)

	if err != nil {
		return api.Release{}, err
	}

	release := api.Release{}
	if err = json.Unmarshal([]byte(body), &release); err != nil {
		return api.Release{}, err
	}

	return release, nil
}
182691
func (client *Client) GetApplicationApplicationInstances(guid string) (map[int]ApplicationInstance, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetAppInstancesRequest,
		URIParams:   Params{"app_guid": guid},
	})
	if err != nil {
		return nil, nil, err
	}

	var instances map[string]ApplicationInstance
	response := cloudcontroller.Response{
		DecodeJSONResponseInto: &instances,
	}

	err = client.connection.Make(request, &response)
	if err != nil {
		return nil, response.Warnings, err
	}

	returnedInstances := map[int]ApplicationInstance{}
	for instanceID, instance := range instances {
		id, convertErr := strconv.Atoi(instanceID)
		if convertErr != nil {
			return nil, response.Warnings, convertErr
		}
		instance.ID = id
		returnedInstances[id] = instance
	}

	return returnedInstances, response.Warnings, nil
}
666819
func (r *Group) App(application *Application) *Group {
	if r.Apps == nil {
		r.Apps = make([]*Application, 0)
	}
	r.Apps = append(r.Apps, application)
	return r
}
695670
func (s *Service) GetPort(application, portAddr string) *servicedefinition.Port {
	if s.Endpoints != nil {
		//find the matching endpoint
		for i := range s.Endpoints {
			ep := &s.Endpoints[i]

			if ep.Application == application && ep.Purpose == "export" {
				portAddrLower := strings.ToLower(portAddr)
				for _, port := range ep.PortList {
					if strings.ToLower(port.PortAddr) == portAddrLower {
						return &port
					}
				}
			}
		}
	}

	return nil
}
855352
func (c *Client) GetAppBits(guid string) (io.ReadCloser, error) {
	requestURL := fmt.Sprintf("/v2/apps/%s/download", guid)
	req := c.NewRequest("GET", requestURL)
	resp, err := c.DoRequestWithoutRedirects(req)
	if err != nil {
		return nil, errors.Wrapf(err, "Error downloading app %s bits, API request failed", guid)
	}
	if isResponseRedirect(resp) {
		// directly download the bits from blobstore using a non cloud controller transport
		// some blobstores will return a 400 if an Authorization header is sent
		blobStoreLocation := resp.Header.Get("Location")
		tr := &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: c.Config.SkipSslValidation},
		}
		client := &http.Client{Transport: tr}
		resp, err = client.Get(blobStoreLocation)
		if err != nil {
			return nil, errors.Wrapf(err, "Error downloading app %s bits from blobstore", guid)
		}
	} else {
		return nil, errors.Wrapf(err, "Error downloading app %s bits, expected redirect to blobstore", guid)
	}
	return resp.Body, nil
}
583378
func (c *Page) GetAppManifest() (string, []*PageAppManifestError, string, error) {
	resp, err := gcdmessage.SendCustomReturn(c.target, c.target.GetSendCh(), &gcdmessage.ParamRequest{Id: c.target.GetId(), Method: "Page.getAppManifest"})
	if err != nil {
		return "", nil, "", err
	}

	var chromeData struct {
		Result struct {
			Url    string
			Errors []*PageAppManifestError
			Data   string
		}
	}

	if resp == nil {
		return "", nil, "", &gcdmessage.ChromeEmptyResponseErr{}
	}

	// test if error first
	cerr := &gcdmessage.ChromeErrorResponse{}
	json.Unmarshal(resp.Data, cerr)
	if cerr != nil && cerr.Error != nil {
		return "", nil, "", &gcdmessage.ChromeRequestErr{Resp: cerr}
	}

	if err := json.Unmarshal(resp.Data, &chromeData); err != nil {
		return "", nil, "", err
	}

	return chromeData.Result.Url, chromeData.Result.Errors, chromeData.Result.Data, nil
}
847134
func (api *APIv5) Get(args params.ApplicationGet) (params.ApplicationGetResults, error) {
	results, err := api.getConfig(args, describe)
	if err != nil {
		return params.ApplicationGetResults{}, err
	}
	results.ApplicationConfig = nil
	return results, nil
}
161043
func (client *Client) GetApplications(query ...Query) ([]Application, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.GetApplicationsRequest,
		Query:       query,
	})
	if err != nil {
		return nil, nil, err
	}

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

	return fullAppsList, warnings, err
}
515341
func (obj *Doc) GetAppPropertiesRaw(ctx context.Context) (json.RawMessage, error) {
	result := &struct {
		Prop json.RawMessage	`json:"qProp"`
	} {}
	err := obj.rpc(ctx, "GetAppProperties", result)
	return result.Prop, err 
}
853831
func GetAppsResources(apps schema.AppList) (totalCpus, totalMem int64) {
	cpusSpecified := false
	for i := range apps {
		ra := &apps[i]
		app := ra.App
		mem, cpus := findResources(app.Isolators)
		cpusSpecified = cpusSpecified || cpus != 0
		totalCpus += cpus
		totalMem += mem
	}
	// In case when number of specified cpus is greater than
	// number or when cpus aren't specified, we set number
	// of logical cpus as a limit.
	availableCpus := int64(runtime.NumCPU())
	if !cpusSpecified || totalCpus > availableCpus {
		totalCpus = availableCpus
	}

	// Add an overhead for the VM system
	totalMem += systemMemOverhead

	// Always ensure we have at least the minimum RAM needed
	if totalMem < minMem {
		totalMem = minMem
	}

	return totalCpus, totalMem
}