// UpdateCharmConfig applies the input changes to the input application's
// charm configuration under this branch.
// the incoming charm settings are assumed to have been validated.
161824
func (g *Generation) UpdateCharmConfig(appName string, master *Settings, validChanges charm.Settings) error {
	buildTxn := func(attempt int) ([]txn.Op, error) {
		if attempt > 0 {
			if err := g.Refresh(); err != nil {
				return nil, errors.Trace(err)
			}
		}
		if err := g.CheckNotComplete(); err != nil {
			return nil, errors.Trace(err)
		}

		// Apply the current branch deltas to the master settings.
		branchChanges := g.Config()
		branchDelta, branchHasDelta := branchChanges[appName]
		if branchHasDelta {
			master.applyChanges(branchDelta)
		}

		// Now apply the incoming changes on top and generate a new delta.
		for k, v := range validChanges {
			if v == nil {
				master.Delete(k)
			} else {
				master.Set(k, v)
			}
		}
		newDelta := master.changes()

		// Ensure that the delta represents a change from master settings
		// as they were when each setting was first modified under the branch.
		if branchHasDelta {
			var err error
			if newDelta, err = newDelta.ApplyDeltaSource(branchDelta); err != nil {
				return nil, errors.Trace(err)
			}
		}

		return []txn.Op{
			{
				C:  generationsC,
				Id: g.doc.DocId,
				Assert: bson.D{{"$and", []bson.D{
					{{"completed", 0}},
					{{"txn-revno", g.doc.TxnRevno}},
				}}},
				Update: bson.D{
					{"$set", bson.D{{"charm-config." + appName, makeItemChanges(newDelta)}}},
				},
			},
		}, nil
	}

	return errors.Trace(g.st.db().Run(buildTxn))
}
714149
func (s *Server) UpdateRuntimeConfig(ctx context.Context, req *pb.UpdateRuntimeConfigRequest) (resp *pb.UpdateRuntimeConfigResponse, err error) {
	const operation = "update_runtime_config"
	defer func() {
		recordOperation(operation, time.Now())
		recordError(operation, err)
	}()

	return &pb.UpdateRuntimeConfigResponse{}, nil
}
954645
func applicationSetSettingsStrings(
	application Application, gen string, settings map[string]string,
) error {
	ch, _, err := application.Charm()
	if err != nil {
		return errors.Trace(err)
	}
	// Parse config in a compatible way (see function comment).
	changes, err := parseSettingsCompatible(ch.Config(), settings)
	if err != nil {
		return errors.Trace(err)
	}
	return application.UpdateCharmConfig(gen, changes)
}
167406
func (_m *FacadeInterface) UpdateServiceConfig(ctx datastore.Context, fileID string, conf servicedefinition.ConfigFile) error {
	ret := _m.Called(ctx, fileID, conf)

	var r0 error
	if rf, ok := ret.Get(0).(func(datastore.Context, string, servicedefinition.ConfigFile) error); ok {
		r0 = rf(ctx, fileID, conf)
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
349440
func (c *configCommand) resetConfig(client applicationAPI, ctx *cmd.Context) error {
	var err error
	if client.BestAPIVersion() < 6 {
		err = client.Unset(c.applicationName, c.resetKeys)
	} else {
		err = client.UnsetApplicationConfig(c.branchName, c.applicationName, c.resetKeys)
	}
	return block.ProcessBlockedError(err, block.BlockChange)
}
335118
func (m *MockAgent) ChangeConfig(arg0 agent.ConfigMutator) error {
	ret := m.ctrl.Call(m, "ChangeConfig", arg0)
	ret0, _ := ret[0].(error)
	return ret0
}
463267
func (api *APIBase) CharmConfig(args params.ApplicationGetArgs) (params.ApplicationGetConfigResults, error) {
	if err := api.checkCanRead(); err != nil {
		return params.ApplicationGetConfigResults{}, err
	}
	results := params.ApplicationGetConfigResults{
		Results: make([]params.ConfigResult, len(args.Args)),
	}
	for i, arg := range args.Args {
		config, err := api.getCharmConfig(arg.BranchName, arg.ApplicationName)
		results.Results[i].Config = config
		results.Results[i].Error = common.ServerError(err)
	}
	return results, nil
}
953370
func (h *bundleHandler) addCharm(change *bundlechanges.AddCharmChange) error {
	if h.dryRun {
		return nil
	}
	id := change.Id()
	p := change.Params
	// First attempt to interpret as a local path.
	if h.isLocalCharm(p.Charm) {
		charmPath := p.Charm
		if !filepath.IsAbs(charmPath) {
			charmPath = filepath.Join(h.bundleDir, charmPath)
		}

		series := p.Series
		if series == "" {
			series = h.data.Series
		}
		ch, curl, err := charmrepo.NewCharmAtPath(charmPath, series)
		if err != nil && !os.IsNotExist(err) {
			return errors.Annotatef(err, "cannot deploy local charm at %q", charmPath)
		}
		if err == nil {
			if err := lxdprofile.ValidateLXDProfile(lxdCharmProfiler{
				Charm: ch,
			}); err != nil {
				return errors.Annotatef(err, "cannot deploy local charm at %q", charmPath)
			}
			if curl, err = h.api.AddLocalCharm(curl, ch, false); err != nil {
				return err
			}
			logger.Debugf("added charm %s", curl)
			h.results[id] = curl.String()
			return nil
		}
	}

	// Not a local charm, so grab from the store.
	ch, err := charm.ParseURL(p.Charm)
	if err != nil {
		return errors.Trace(err)
	}

	url, channel, _, err := resolveCharm(h.api.ResolveWithChannel, ch)
	if err != nil {
		return errors.Annotatef(err, "cannot resolve URL %q", p.Charm)
	}
	if url.Series == "bundle" {
		return errors.Errorf("expected charm URL, got bundle URL %q", p.Charm)
	}
	var macaroon *macaroon.Macaroon
	url, macaroon, err = addCharmFromURL(h.api, url, channel, false)
	if err != nil {
		return errors.Annotatef(err, "cannot add charm %q", p.Charm)
	}
	logger.Debugf("added charm %s", url)
	h.results[id] = url.String()
	h.macaroons[url] = macaroon
	h.channels[url] = channel
	return nil
}
144299
func (m *MockLambdaAPI) UpdateFunctionConfiguration(arg0 *lambda.UpdateFunctionConfigurationInput) (*lambda.FunctionConfiguration, error) {
	ret := m.ctrl.Call(m, "UpdateFunctionConfiguration", arg0)
	ret0, _ := ret[0].(*lambda.FunctionConfiguration)
	ret1, _ := ret[1].(error)
	return ret0, ret1
}
494901
func (s *CreateTrainingJobInput) SetInputDataConfig(v []*Channel) *CreateTrainingJobInput {
	s.InputDataConfig = v
	return s
}
1341579
func (i *ImageService) UpdateConfig(maxDownloads, maxUploads *int) {
	if i.downloadManager != nil && maxDownloads != nil {
		i.downloadManager.SetConcurrency(*maxDownloads)
	}
	if i.uploadManager != nil && maxUploads != nil {
		i.uploadManager.SetConcurrency(*maxUploads)
	}
}
672777
func (a *Application) updateBranchConfig(branchName string, current *Settings, validChanges charm.Settings) error {
	branch, err := a.st.Branch(branchName)
	if err != nil {
		return errors.Trace(err)
	}

	return errors.Trace(branch.UpdateCharmConfig(a.Name(), current, validChanges))
}
275076
func (c *agentConf) ChangeConfig(change agent.ConfigMutator) error {
	c.mu.Lock()
	defer c.mu.Unlock()
	if err := change(c._config); err != nil {
		return errors.Trace(err)
	}
	if err := c._config.Write(); err != nil {
		return errors.Annotate(err, "cannot write agent configuration")
	}
	return nil
}
458948
func (a *Application) ApplicationConfig() (application.ConfigAttributes, error) {
	config, err := readSettings(a.st.db(), settingsC, a.applicationConfigKey())
	if errors.IsNotFound(err) || len(config.Keys()) == 0 {
		return application.ConfigAttributes(nil), nil
	} else if err != nil {
		return nil, errors.Annotatef(err, "application config for application %q", a.doc.Name)
	}
	return application.ConfigAttributes(config.Map()), nil
}
73496
func (c *configCommand) resetConfig(client configCommandAPI, ctx *cmd.Context) error {
	// ctx unused in this method
	if err := c.verifyKnownKeys(client, c.resetKeys); err != nil {
		return errors.Trace(err)
	}

	return block.ProcessBlockedError(client.ModelUnset(c.resetKeys...), block.BlockChange)
}
793594
func (mr *MockTriremeControllerMockRecorder) UpdateConfiguration(cfg interface{}) *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateConfiguration", reflect.TypeOf((*MockTriremeController)(nil).UpdateConfiguration), cfg)
}
1329700
func (st *State) AddCharm(info CharmInfo) (stch *Charm, err error) {
	charms, closer := st.db().GetCollection(charmsC)
	defer closer()

	if err := validateCharmVersion(info.Charm); err != nil {
		return nil, errors.Trace(err)
	}
	model, err := st.Model()
	if err != nil {
		return nil, errors.Trace(err)
	}
	if err := validateCharmSeries(model.Type(), info.ID.Series, info.Charm); err != nil {
		return nil, errors.Trace(err)
	}

	query := charms.FindId(info.ID.String()).Select(bson.M{
		"placeholder":   1,
		"pendingupload": 1,
	})
	buildTxn := func(attempt int) ([]txn.Op, error) {
		var doc charmDoc
		if err := query.One(&doc); err == mgo.ErrNotFound {
			if info.ID.Schema == "local" {
				curl, err := st.PrepareLocalCharmUpload(info.ID)
				if err != nil {
					return nil, errors.Trace(err)
				}
				info.ID = curl
				return updateCharmOps(st, info, stillPending)
			}
			return insertCharmOps(st, info)
		} else if err != nil {
			return nil, errors.Trace(err)
		} else if doc.PendingUpload {
			return updateCharmOps(st, info, stillPending)
		} else if doc.Placeholder {
			return updateCharmOps(st, info, stillPlaceholder)
		}
		return nil, errors.AlreadyExistsf("charm %q", info.ID)
	}
	if err = st.db().Run(buildTxn); err == nil {
		return st.Charm(info.ID)
	}
	return nil, errors.Trace(err)
}