// Implements jujuclient.ModelUpdater.
342194
func (s QualifyingClientStore) SetModels(controllerName string, models map[string]jujuclient.ModelDetails) error {
	qualified := make(map[string]jujuclient.ModelDetails, len(models))
	for name, details := range models {
		modelName, err := s.QualifiedModelName(controllerName, name)
		if err != nil {
			return errors.Annotatef(err, "updating model %q", name)
		}
		qualified[modelName] = details
	}
	return s.ClientStore.SetModels(controllerName, models)
}
378356
func (enpStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
	return validation.ValidateEgressNetworkPolicyUpdate(obj.(*networkapi.EgressNetworkPolicy), old.(*networkapi.EgressNetworkPolicy))
}
134509
func (db *Database) commonCreateUpdate(value DBModel, builder func() string) error {
	defer db.clear()
	// if Model has been called, skip table name inference procedure
	if len(db.tables) == 0 {
		db.tables = append(db.tables, handleIdentifier(value.TableName()))
		db.models = append(db.models, value)
	}

	in := getStruct(value)
	// getFields handle anonymous nested fields
	fields := getFields(value)

	for _, structField := range fields {
		field := in.FieldByName(structField.Name)
		if value := fieldValue(field, structField); value != nil {
			db.updateCreateFields = append(db.updateCreateFields, getColumnName(structField))
			db.updateCreateValues = append(db.updateCreateValues, value)
		}
	}

	// Compile query
	var stmt *sql.Stmt
	var err error
	if stmt, err = db.db.Prepare(builder()); err != nil {
		return err
	}

	// Pass query parameters and executes the query
	// set db.rawRows to query results (of returning) in order to make it possible to scan rows into result
	if db.rawRows, err = stmt.Query(append(db.updateCreateValues, db.whereValues...)...); err != nil {
		return err
	}
	if err = db.Scan(value); err != nil {
		panic(err)
	}
	return nil
}
818668
func (d *DataSource) InsertOrUpdate(user Model) (Model, error) {
	// no matter what we will update the password hash
	// for both update and insert actions.
	hashedPassword, err := GeneratePassword(user.password)
	if err != nil {
		return user, err
	}
	user.HashedPassword = hashedPassword

	// update
	if id := user.ID; id > 0 {
		_, found := d.GetByID(id)
		if !found {
			return user, errors.New("ID should be zero or a valid one that maps to an existing User")
		}
		d.mu.Lock()
		d.Users[id] = user
		d.mu.Unlock()
		return user, nil
	}

	// insert
	id := d.getLastID() + 1
	user.ID = id
	d.mu.Lock()
	user.CreatedAt = time.Now()
	d.Users[id] = user
	d.mu.Unlock()

	return user, nil
}
922581
func (ac *APIController) PolicyUpdate(policy, params *contivModel.Policy) error {
	log.Infof("Received PolicyUpdate: %+v, params: %+v", policy, params)
	return nil
}
1002493
func (ac *APIController) NetworkUpdate(network, params *contivModel.Network) error {
	log.Infof("Received NetworkUpdate: %+v, params: %+v", network, params)
	return core.Errorf("Cant change network parameters after its created")
}
106394
func (db *Database) buildUpdate() string {
	var query bytes.Buffer
	query.WriteString(db.buildCTE())
	query.WriteString("UPDATE ")

	// Model only
	if len(db.tables) != 1 {
		db.panicLog("Please set a table with Model to Update")
	}
	query.WriteString(db.tables[0])
	query.WriteString(" SET ")

	updateSize := len(db.updateCreateFields)
	if updateSize == 0 {
		db.panicLog("Unable to detect fields to update")
	}

	for j, field := range db.updateCreateFields {
		query.WriteString(handleIdentifier(field))
		query.WriteString(" = $")
		query.WriteString(strconv.Itoa(db.varCount))
		db.varCount++
		if j != updateSize-1 {
			query.WriteString(", ")
		}
	}

	// Where (optional)
	if len(db.whereFields) > 0 {
		query.WriteString(db.buildWhere())
	}

	query.WriteString(db.buildReturning())

	qs := query.String()
	db.printLog(qs)
	return qs
}
1024806
func (st *resourceSyncTask) createOrUpdate(spec *unstructured.Unstructured, actual runtime.Object) (actualRet *unstructured.Unstructured, retriableRet bool, e error) {
	// Prepare client
	gvk := spec.GroupVersionKind()
	resClient, err := st.smartClient.ForGVK(gvk, st.bundle.Namespace)
	if err != nil {
		return nil, false, errors.Wrapf(err, "failed to get the client for %s", gvk)
	}
	switch actual {
	case nil:
		return st.createResource(resClient, spec)
	default:
		return st.updateResource(resClient, spec, actual)
	}
}
86488
func (model *Model) updateSuffixArr() {
	if !model.UseAutocomplete {
		return
	}
	model.RLock()
	termArr := make([]string, 0, 1000)
	for term, count := range model.Data {
		if count.Corpus > model.Threshold || count.Query > 0 { // TODO: query threshold?
			termArr = append(termArr, term)
		}
	}
	model.SuffixArrConcat = "\x00" + strings.Join(termArr, "\x00") + "\x00"
	model.SuffixArr = suffixarray.New([]byte(model.SuffixArrConcat))
	model.SuffDivergence = 0
	model.RUnlock()
}
103167
func (sdnStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
	return validation.ValidateClusterNetworkUpdate(obj.(*networkapi.ClusterNetwork), old.(*networkapi.ClusterNetwork))
}
1193469
func (c *Client) LinodeUpdate(linodeID int, conf LinodeOpts) error {
	args, err := c.argMarshal(conf)
	if err != nil {
		return err
	}
	args["LinodeID"] = linodeID

	_, err = c.apiCall("linode.update", args)
	if err != nil {
		return err
	}
	return nil
}
1166065
func (strategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
	return validation.ValidateDeploymentConfigUpdate(obj.(*appsapi.DeploymentConfig), old.(*appsapi.DeploymentConfig))
}
580112
func (s *ServiceOfferingService) UpdateServiceOffering(p *UpdateServiceOfferingParams) (*UpdateServiceOfferingResponse, error) {
	resp, err := s.cs.newRequest("updateServiceOffering", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r UpdateServiceOfferingResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	return &r, nil
}
700503
func (m *Model) UpdateModelConfig(updateAttrs map[string]interface{}, removeAttrs []string, additionalValidation ...ValidateConfigFunc) error {
	if len(updateAttrs)+len(removeAttrs) == 0 {
		return nil
	}

	st := m.State()
	if len(removeAttrs) > 0 {
		var removed []string
		if updateAttrs == nil {
			updateAttrs = make(map[string]interface{})
		}
		// For each removed attribute, pick up any inherited value
		// and if there's one, use that.
		inherited, err := st.inheritedConfigAttributes()
		if err != nil {
			return errors.Trace(err)
		}
		for _, attr := range removeAttrs {
			// We we are updating an attribute, that takes
			// precedence over removing.
			if _, ok := updateAttrs[attr]; ok {
				continue
			}
			if val, ok := inherited[attr]; ok {
				updateAttrs[attr] = val
			} else {
				removed = append(removed, attr)
			}
		}
		removeAttrs = removed
	}
	// TODO(axw) 2013-12-6 #1167616
	// Ensure that the settings on disk have not changed
	// underneath us. The settings changes are actually
	// applied as a delta to what's on disk; if there has
	// been a concurrent update, the change may not be what
	// the user asked for.

	modelSettings, err := readSettings(st.db(), settingsC, modelGlobalKey)
	if err != nil {
		return errors.Annotatef(err, "model %q", m.UUID())
	}

	oldConfig, err := m.ModelConfig()
	if err != nil {
		return errors.Trace(err)
	}
	for _, additionalValidationFunc := range additionalValidation {
		err = additionalValidationFunc(updateAttrs, removeAttrs, oldConfig)
		if err != nil {
			return errors.Trace(err)
		}
	}
	validCfg, err := st.buildAndValidateModelConfig(updateAttrs, removeAttrs, oldConfig)
	if err != nil {
		return errors.Trace(err)
	}

	validAttrs := validCfg.AllAttrs()
	for k := range oldConfig.AllAttrs() {
		if _, ok := validAttrs[k]; !ok {
			modelSettings.Delete(k)
		}
	}
	// Some values require marshalling before storage.
	validAttrs = config.CoerceForStorage(validAttrs)

	modelSettings.Update(validAttrs)
	_, ops := modelSettings.settingsUpdateOps()
	return modelSettings.write(ops)
}
162178
func (self *Model) CreateOrUpdate(id interface{}, from interface{}) error {
	if id == nil || !self.Exists(id) {
		return self.Create(from)
	} else {
		return self.Update(from)
	}
}
309493
func ServiceUpdate(info *model.ServiceInfo) error { // nolint: gocyclo
	return mgr.Do(func(ctx context.Context, cli *client.Client) (err error) {
		service, _, err := cli.ServiceInspectWithRaw(ctx, info.Name, types.ServiceInspectOptions{})
		if err != nil {
			return err
		}
		spec := service.Spec

		// Annotations
		spec.Annotations.Labels = info.ServiceLabels.ToMap()

		// ContainerSpec
		spec.TaskTemplate.ContainerSpec.Image = info.Image
		spec.TaskTemplate.ContainerSpec.Dir = info.Dir
		spec.TaskTemplate.ContainerSpec.User = info.User
		spec.TaskTemplate.ContainerSpec.Labels = info.ContainerLabels.ToMap()
		spec.TaskTemplate.ContainerSpec.Command = nil
		spec.TaskTemplate.ContainerSpec.Args = nil
		spec.TaskTemplate.ContainerSpec.Env = nil
		if info.Command != "" {
			spec.TaskTemplate.ContainerSpec.Command = strings.Split(info.Command, " ")
		}
		if info.Args != "" {
			spec.TaskTemplate.ContainerSpec.Args = strings.Split(info.Args, " ")
		}
		if envs := info.Environments.ToMap(); len(envs) > 0 {
			for n, v := range envs {
				spec.TaskTemplate.ContainerSpec.Env = append(spec.TaskTemplate.ContainerSpec.Env, n+"="+v)
			}
		}

		// Mode
		if info.Mode == "replicated" {
			if spec.Mode.Replicated == nil {
				spec.Mode.Global = nil
				spec.Mode.Replicated = &swarm.ReplicatedService{Replicas: &info.Replicas}
			} else {
				spec.Mode.Replicated.Replicas = &info.Replicas
			}
		} else if info.Mode == "global" && spec.Mode.Global == nil {
			spec.Mode.Replicated = nil
			spec.Mode.Global = &swarm.GlobalService{}
		}

		// Network
		// todo: only process updated networks
		spec.TaskTemplate.Networks = nil
		for _, n := range info.Networks {
			spec.TaskTemplate.Networks = append(spec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: n})
		}

		// Endpoint
		spec.EndpointSpec = &swarm.EndpointSpec{Mode: swarm.ResolutionMode(info.Endpoint.Mode)}
		for _, p := range info.Endpoint.Ports {
			port := swarm.PortConfig{
				Protocol:      p.Protocol,
				TargetPort:    p.TargetPort,
				PublishedPort: p.PublishedPort,
				PublishMode:   p.PublishMode,
			}
			spec.EndpointSpec.Ports = append(spec.EndpointSpec.Ports, port)
		}

		spec.TaskTemplate.ContainerSpec.Secrets = nil
		for _, s := range info.Secrets {
			spec.TaskTemplate.ContainerSpec.Secrets = append(spec.TaskTemplate.ContainerSpec.Secrets, s.ToSecret())
		}

		spec.TaskTemplate.ContainerSpec.Configs = nil
		for _, c := range info.Configs {
			spec.TaskTemplate.ContainerSpec.Configs = append(spec.TaskTemplate.ContainerSpec.Configs, c.ToConfig())
		}

		// Mounts
		// todo: fix > original options are not reserved.
		spec.TaskTemplate.ContainerSpec.Mounts = nil
		for _, m := range info.Mounts {
			if m.Target != "" {
				mnt := mount.Mount{
					Type:     mount.Type(m.Type),
					Source:   m.Source,
					Target:   m.Target,
					ReadOnly: m.ReadOnly,
				}
				if m.Propagation != "" {
					mnt.BindOptions = &mount.BindOptions{Propagation: m.Propagation}
				}
				spec.TaskTemplate.ContainerSpec.Mounts = append(spec.TaskTemplate.ContainerSpec.Mounts, mnt)
			}
		}

		// Placement
		if spec.TaskTemplate.Placement == nil {
			spec.TaskTemplate.Placement = &swarm.Placement{}
		}
		spec.TaskTemplate.Placement.Constraints = nil
		for _, c := range info.Placement.Constraints {
			if cons := c.ToConstraint(); cons != "" {
				spec.TaskTemplate.Placement.Constraints = append(spec.TaskTemplate.Placement.Constraints, cons)
			}
		}
		spec.TaskTemplate.Placement.Preferences = nil
		for _, p := range info.Placement.Preferences {
			if p.Spread != "" {
				pref := swarm.PlacementPreference{
					Spread: &swarm.SpreadOver{SpreadDescriptor: p.Spread},
				}
				spec.TaskTemplate.Placement.Preferences = append(spec.TaskTemplate.Placement.Preferences, pref)
			}
		}

		// update policy
		spec.UpdateConfig = &swarm.UpdateConfig{
			Parallelism:   info.UpdatePolicy.Parallelism,
			FailureAction: info.UpdatePolicy.FailureAction,
			Order:         info.UpdatePolicy.Order,
		}
		if info.UpdatePolicy.Delay != "" {
			spec.UpdateConfig.Delay, err = time.ParseDuration(info.UpdatePolicy.Delay)
			if err != nil {
				return err
			}
		}

		// rollback policy
		spec.RollbackConfig = &swarm.UpdateConfig{
			Parallelism:   info.RollbackPolicy.Parallelism,
			FailureAction: info.RollbackPolicy.FailureAction,
			Order:         info.RollbackPolicy.Order,
		}
		if info.RollbackPolicy.Delay != "" {
			spec.RollbackConfig.Delay, err = time.ParseDuration(info.RollbackPolicy.Delay)
			if err != nil {
				return err
			}
		}

		// restart policy
		var d time.Duration
		spec.TaskTemplate.RestartPolicy = &swarm.RestartPolicy{
			Condition:   info.RestartPolicy.Condition,
			MaxAttempts: &info.RestartPolicy.MaxAttempts,
		}
		if info.RestartPolicy.Delay != "" {
			d, err = time.ParseDuration(info.RestartPolicy.Delay)
			if err != nil {
				return err
			}
			spec.TaskTemplate.RestartPolicy.Delay = &d
		}
		if info.RestartPolicy.Window != "" {
			d, err = time.ParseDuration(info.RestartPolicy.Window)
			if err != nil {
				return err
			}
			spec.TaskTemplate.RestartPolicy.Window = &d
		}

		// resources
		if info.Resource.Limit.IsSet() || info.Resource.Reserve.IsSet() {
			spec.TaskTemplate.Resources = &swarm.ResourceRequirements{}
			if info.Resource.Limit.IsSet() {
				spec.TaskTemplate.Resources.Limits, err = info.Resource.Limit.ToResources()
				if err != nil {
					return err
				}
			}
			if info.Resource.Limit.IsSet() {
				spec.TaskTemplate.Resources.Reservations, err = info.Resource.Reserve.ToResources()
				if err != nil {
					return err
				}
			}
		}

		// log driver
		if info.LogDriver.Name == "" {
			spec.TaskTemplate.LogDriver = nil
		} else {
			spec.TaskTemplate.LogDriver = &swarm.Driver{
				Name:    info.LogDriver.Name,
				Options: info.LogDriver.Options.ToMap(),
			}
		}

		// Host & DNS
		spec.TaskTemplate.ContainerSpec.Hostname = info.Hostname
		if info.Hosts != "" {
			spec.TaskTemplate.ContainerSpec.Hosts = strings.Split(info.Hosts, "\n")
		}
		spec.TaskTemplate.ContainerSpec.DNSConfig = info.GetDNSConfig()

		options := types.ServiceUpdateOptions{
			RegistryAuthFrom: types.RegistryAuthFromSpec,
			QueryRegistry:    false,
		}
		resp, err := cli.ServiceUpdate(context.Background(), info.Name, version(info.Version), spec, options)
		if err == nil && len(resp.Warnings) > 0 {
			mgr.Logger().Warnf("service %s was updated but got warnings: %v", info.Name, resp.Warnings)
		}
		return err
	})
}
414959
func (r ResourceEventHandlerFuncs) OnUpdate(oldObj, newObj interface{}) {
	if r.UpdateFunc != nil {
		r.UpdateFunc(oldObj, newObj)
	}
}