// NewAppcFromApp returns an Appc distribution from an appc App discovery string
355864
func NewAppcFromApp(app *discovery.App) Distribution {
	rawuri := NewCIMDString(TypeAppc, distAppcVersion, url.QueryEscape(app.Name.String()))

	var version string
	labels := types.Labels{}
	for n, v := range app.Labels {
		if n == "version" {
			version = v
		}

		labels = append(labels, types.Label{Name: n, Value: v})
	}

	if len(labels) > 0 {
		queries := make([]string, len(labels))
		rawuri += "?"
		for i, l := range labels {
			queries[i] = fmt.Sprintf("%s=%s", l.Name, url.QueryEscape(l.Value))
		}
		rawuri += strings.Join(queries, "&")
	}

	u, err := url.Parse(rawuri)
	if err != nil {
		panic(fmt.Errorf("cannot parse URI %q: %v", rawuri, err))
	}

	// save the URI as sorted to make it ready for comparison
	purell.NormalizeURL(u, purell.FlagSortQuery)

	str := app.Name.String()
	if version != "" {
		str += fmt.Sprintf(":%s", version)
	}

	labelsort.By(labelsort.RankedName).Sort(labels)
	for _, l := range labels {
		if l.Name != "version" {
			str += fmt.Sprintf(",%s=%s", l.Name, l.Value)
		}
	}

	return &Appc{
		cimd: u,
		app:  app.Copy(),
		str:  str,
	}
}
1320947
func (c *Client) CreateApp(req AppCreateRequest) (App, error) {
	var appResp AppResource
	buf := bytes.NewBuffer(nil)
	err := json.NewEncoder(buf).Encode(req)
	if err != nil {
		return App{}, err
	}
	r := c.NewRequestWithBody("POST", "/v2/apps", buf)
	resp, err := c.DoRequest(r)
	if err != nil {
		return App{}, errors.Wrapf(err, "Error creating app %s", req.Name)
	}
	if resp.StatusCode != http.StatusCreated {
		return App{}, errors.Wrapf(err, "Error creating app %s, response code: %d", req.Name, resp.StatusCode)
	}
	resBody, err := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()
	if err != nil {
		return App{}, errors.Wrapf(err, "Error reading app %s http response body", req.Name)
	}
	err = json.Unmarshal(resBody, &appResp)
	if err != nil {
		return App{}, errors.Wrapf(err, "Error deserializing app %s response", req.Name)
	}
	return c.mergeAppResource(appResp), nil
}
623127
func (s *Service) AddOnAttachmentInfoByApp(ctx context.Context, appIdentity string, addOnAttachmentScopedIdentity string) (*AddOnAttachment, error) {
	var addOnAttachment AddOnAttachment
	return &addOnAttachment, s.Get(ctx, &addOnAttachment, fmt.Sprintf("/apps/%v/addon-attachments/%v", appIdentity, addOnAttachmentScopedIdentity), nil, nil)
}
154465
func (s *Service) AppWebhookCreate(ctx context.Context, appIdentity string, o AppWebhookCreateOpts) (*AppWebhookCreateResult, error) {
	var appWebhook AppWebhookCreateResult
	return &appWebhook, s.Post(ctx, &appWebhook, fmt.Sprintf("/apps/%v/webhooks", appIdentity), o)
}
970707
func NewApplicationGroup(name string) *Group {
	return &Group{
		ID:           name,
		Apps:         make([]*Application, 0),
		Dependencies: make([]string, 0),
		Groups:       make([]*Group, 0),
	}
}
799066
func CreateAppNw(app *contivModel.AppProfile) error {
	aciPresent, aErr := master.IsAciConfigured()
	if aErr != nil {
		log.Errorf("Couldn't read global config %v", aErr)
		return aErr
	}

	if !aciPresent {
		log.Debugf("ACI not configured")
		return nil
	}

	// Get the state driver
	stateDriver, uErr := utils.GetStateDriver()
	if uErr != nil {
		return uErr
	}

	eMap := &epgMap{}
	eMap.Specs = make(map[string]epgSpec)
	eMap.Contracts = make(map[string]*contrSpec)
	ans := &appNwSpec{}

	ans.ACIGwAPIVersion = aciGwAPIVersion
	gwConfig := contivModel.FindAciGw("aciGw")
	if gwConfig == nil {
		log.Infof("aciGw object not found -- gw will use env settings")
	} else {
		ans.GWConfig = gwConfig
		log.Infof("gwConfig: %+v", gwConfig)
	}
	ans.TenantName = app.TenantName
	ans.AppName = app.AppProfileName

	// Gather all basic epg info into the epg map
	for epgKey := range app.LinkSets.EndpointGroups {
		epgObj := contivModel.FindEndpointGroup(epgKey)
		if epgObj == nil {
			err := fmt.Sprintf("Epg %v does not exist", epgKey)
			log.Errorf("%v", err)
			return errors.New(err)
		}

		if err := appendEpgInfo(eMap, epgObj, stateDriver); err != nil {
			log.Errorf("Error getting epg info %v", err)
			return err
		}
	}

	// walk the map and add to ANS
	for _, epg := range eMap.Specs {
		ans.Epgs = append(ans.Epgs, epg)
		log.Debugf("Added epg %v", epg.Name)
	}

	for _, contract := range eMap.Contracts {
		ans.ContractDefs = append(ans.ContractDefs, *contract)
		log.Debugf("Added contract %v", contract.Name)
	}

	log.Infof("Launching appNwSpec: %+v", ans)
	lErr := ans.launch()
	time.Sleep(2 * time.Second)
	ans.notifyDP()

	return lErr
}
70464
func (obj *Global) PublishApp(ctx context.Context, appId string, name string, streamId string) error {
	err := obj.rpc(ctx, "PublishApp", nil, appId, name, streamId)
	return err 
}
229036
func NewDefaultRocPForStream(priceStream gotrade.DOHLCVStreamSubscriber) (indicator *RocP, err error) {
	ind, err := NewDefaultRocP()
	priceStream.AddTickSubscription(ind)
	return ind, err
}
106743
func NewApp(binPath string, paths *model.RevelContainer) *App {
	return &App{BinaryPath: binPath, Paths: paths, Port: paths.HTTPPort}
}
872879
func (fmd *FakeMysqlDaemon) GetAppConnection(ctx context.Context) (*dbconnpool.PooledDBConnection, error) {
	return fmd.appPool.Get(ctx)
}
1082005
func (e *Endpoint) BPFConfigMapPath() string {
	return bpf.LocalMapPath(bpfconfig.MapNamePrefix, e.ID)
}
728783
func countApplicationOffersRefOp(mb modelBackend, appName string) (txn.Op, int, error) {
	refcounts, closer := mb.db().GetCollection(refcountsC)
	defer closer()
	key := applicationOffersRefCountKey(appName)
	return nsRefcounts.CurrentOp(refcounts, key)
}
57003
func newAppScanner(opts *Opts) (*appScanner, error) {
	if Debug {
		log.Println("scanning packages discovered through entrypoint @ ", opts.BasePath)
	}
	var ldr loader.Config
	ldr.ParserMode = goparser.ParseComments
	ldr.Import(opts.BasePath)
	if opts.BuildTags != "" {
		ldr.Build = &build.Default
		ldr.Build.BuildTags = strings.Split(opts.BuildTags, ",")
	}
	ldr.TypeChecker = types.Config{FakeImportC: true}
	prog, err := ldr.Load()
	if err != nil {
		return nil, err
	}

	var includes, excludes packageFilters
	if len(opts.Include) > 0 {
		for _, include := range opts.Include {
			includes = append(includes, packageFilter{Name: include})
		}
	}
	if len(opts.Exclude) > 0 {
		for _, exclude := range opts.Exclude {
			excludes = append(excludes, packageFilter{Name: exclude})
		}
	}
	includeTags := make(map[string]bool)
	for _, includeTag := range opts.IncludeTags {
		includeTags[includeTag] = true
	}
	excludeTags := make(map[string]bool)
	for _, excludeTag := range opts.ExcludeTags {
		excludeTags[excludeTag] = true
	}

	input := opts.Input
	if input == nil {
		input = new(spec.Swagger)
		input.Swagger = "2.0"
	}

	if input.Paths == nil {
		input.Paths = new(spec.Paths)
	}
	if input.Definitions == nil {
		input.Definitions = make(map[string]spec.Schema)
	}
	if input.Responses == nil {
		input.Responses = make(map[string]spec.Response)
	}
	if input.Extensions == nil {
		input.Extensions = make(spec.Extensions)
	}

	return &appScanner{
		MainPackage: opts.BasePath,
		prog:        prog,
		input:       input,
		loader:      &ldr,
		operations:  collectOperationsFromInput(input),
		definitions: input.Definitions,
		responses:   input.Responses,
		scanModels:  opts.ScanModels,
		classifier: &programClassifier{
			Includes: includes,
			Excludes: excludes,
		},
		includeTags: includeTags,
		excludeTas:  excludeTags,
	}, nil
}
66031
func (ac *AppClient) NewAppRequest() *omaha.Request {
	req := omaha.NewRequest()
	req.Version = ac.clientVersion
	req.UserID = ac.userID
	req.SessionID = ac.sessionID
	if ac.isMachine {
		req.IsMachine = 1
	}

	app := req.AddApp(ac.appID, ac.version)
	app.Track = ac.track
	app.OEM = ac.oem

	// MachineID and BootID are non-standard fields used by CoreOS'
	// update_engine and Core Update. Copy their values from the
	// standard UserID and SessionID. Eventually the non-standard
	// fields should be deprecated.
	app.MachineID = req.UserID
	app.BootID = req.SessionID

	return req
}
837396
func NewMultiAppConn(clientCreator ClientCreator) *multiAppConn {
	multiAppConn := &multiAppConn{
		clientCreator: clientCreator,
	}
	multiAppConn.BaseService = *cmn.NewBaseService(nil, "multiAppConn", multiAppConn)
	return multiAppConn
}
226618
func (r *AppRepo) Create(app *App) error {
	if !utils.AppNamePattern.Match([]byte(app.Name)) {
		return ErrAppNameInvalid
	}

	if len(app.Name) > AppNameMax {
		return ErrAppNameTooLong
	}

	if _, err := r.DB.NamedExec(`INSERT INTO apps (name) VALUES (:name)`, app); err != nil {
		return err
	}

	newApp, err := r.GetByName(app.Name)
	if err != nil {
		return err
	}

	app.ID = newApp.ID
	app.CreatedAt = newApp.CreatedAt
	app.UpdatedAt = newApp.UpdatedAt

	return nil
}
1128728
func (ac *APIController) AciGwCreate(aci *contivModel.AciGw) error {
	log.Infof("Received AciGwCreate: %+v", aci)
	// Fail the create if app profiles exist
	profCount := contivModel.GetAppProfileCount()
	if profCount != 0 {
		log.Warnf("AciGwCreate: %d existing App-Profiles found.",
			profCount)
	}

	return nil
}