// coreChange returns the core package representation of this change.
// Stored keys are unescaped.
487029
func (c *itemChange) coreChange() settings.ItemChange {
	return settings.ItemChange{
		Type:     c.Type,
		Key:      utils.UnescapeKey(c.Key),
		OldValue: c.OldValue,
		NewValue: c.NewValue,
	}
}
558415
func (t *PlatformsTable) computeChanges(c context.Context, platforms []*config.Platform) {
	cfgs := make(map[string]*Platform, len(platforms))
	for _, cfg := range platforms {
		cfgs[cfg.Name] = &Platform{
			Platform: config.Platform{
				Name:         cfg.Name,
				Description:  cfg.Description,
				Manufacturer: cfg.Manufacturer,
			},
		}
	}

	for _, p := range t.current {
		if cfg, ok := cfgs[p.Name]; ok {
			// Platform found in the config.
			if t.needsUpdate(p, cfg) {
				// Platform doesn't match the config.
				cfg.Id = p.Id
				t.updates = append(t.updates, cfg)
			}
			// Record that the platform config has been seen.
			delete(cfgs, cfg.Name)
		} else {
			// Platform not found in the config.
			t.removals = append(t.removals, p)
		}
	}

	// Platforms remaining in the map are present in the config but not the database.
	// Iterate deterministically over the slice to determine which platforms need to be added.
	for _, cfg := range platforms {
		if p, ok := cfgs[cfg.Name]; ok {
			t.additions = append(t.additions, p)
		}
	}
}
412713
func (s *ChangesService) AbandonChange(changeID string, input *AbandonInput) (*ChangeInfo, *Response, error) {
	return s.change("abandon", changeID, input)
}
547591
func (c *Client) ConsumeRemoteRelationChange(change params.RemoteRelationChangeEvent) error {
	args := params.RemoteRelationsChanges{
		Changes: []params.RemoteRelationChangeEvent{change},
	}
	var results params.ErrorResults
	err := c.facade.FacadeCall("ConsumeRemoteRelationChanges", args, &results)
	if err != nil {
		return errors.Trace(err)
	}
	return results.OneError()
}
208220
func (t *OSesTable) computeChanges(c context.Context, oses []*config.OS) {
	cfgs := make(map[string]*OS, len(oses))
	for _, cfg := range oses {
		cfgs[cfg.Name] = &OS{
			OS: config.OS{
				Name:        cfg.Name,
				Description: cfg.Description,
			},
		}
	}

	for _, os := range t.current {
		if cfg, ok := cfgs[os.Name]; ok {
			// Operating system found in the config.
			if t.needsUpdate(os, cfg) {
				// Operating system doesn't match the config.
				cfg.Id = os.Id
				t.updates = append(t.updates, cfg)
			}
			// Record that the operating system config has been seen.
			delete(cfgs, cfg.Name)
		} else {
			// Operating system not found in the config.
			t.removals = append(t.removals, os)
		}
	}

	// Operating systems remaining in the map are present in the config but not the database.
	// Iterate deterministically over the slice to determine which operating systems need to be added.
	for _, cfg := range oses {
		if os, ok := cfgs[cfg.Name]; ok {
			t.additions = append(t.additions, os)
		}
	}
}
789105
func (r *Orchestrator) handleTaskChange(ctx context.Context, t *api.Task) {
	// If we already set the desired state past TaskStateRunning, there is no
	// further action necessary.
	if t.DesiredState > api.TaskStateRunning {
		return
	}

	var (
		n       *api.Node
		service *api.Service
	)
	r.store.View(func(tx store.ReadTx) {
		if t.NodeID != "" {
			n = store.GetNode(tx, t.NodeID)
		}
		if t.ServiceID != "" {
			service = store.GetService(tx, t.ServiceID)
		}
	})

	if !orchestrator.IsReplicatedService(service) {
		return
	}

	if t.Status.State > api.TaskStateRunning ||
		(t.NodeID != "" && orchestrator.InvalidNode(n)) {
		r.restartTasks[t.ID] = struct{}{}
	}
}
572883
func (s *Change) SetResourceChange(v *ResourceChange) *Change {
	s.ResourceChange = v
	return s
}
414418
func (c *Client) CreateChange(ctx context.Context, ci *ChangeInput) (*Change, error) {
	var resp Change
	if _, err := c.post(ctx, "a/changes/", ci, &resp); err != nil {
		return nil, err
	}
	return &resp, nil
}
703666
func (s *ChangesService) RebaseChange(changeID string, input *RebaseInput) (*ChangeInfo, *Response, error) {
	return s.change("rebase", changeID, input)
}
772923
func (b *allWatcherStateBacking) Changed(all *multiwatcherStore, change watcher.Change) error {
	c, ok := b.collectionByName[change.C]
	if !ok {
		return errors.Errorf("unknown collection %q in fetch request", change.C)
	}
	col, closer := b.st.db().GetCollection(c.name)
	defer closer()
	doc := reflect.New(c.docType).Interface().(backingEntityDoc)

	id := b.st.localID(change.Id.(string))

	// TODO(rog) investigate ways that this can be made more efficient
	// than simply fetching each entity in turn.
	// TODO(rog) avoid fetching documents that we have no interest
	// in, such as settings changes to entities we don't care about.
	err := col.FindId(id).One(doc)
	if err == mgo.ErrNotFound {
		err := doc.removed(all, b.st.ModelUUID(), id, b.st)
		return errors.Trace(err)
	}
	if err != nil {
		return err
	}
	return doc.updated(b.st, all, id)
}
179951
func ValidateChange(key string, f ValueChangeValidationFunc) schema.CustomizeDiffFunc {
	return func(d *schema.ResourceDiff, meta interface{}) error {
		old, new := d.GetChange(key)
		return f(old, new, meta)
	}
}
312796
func ApplyChange(ctx context.Context, ds ipld.DAGService, nd *dag.ProtoNode, cs []*Change) (*dag.ProtoNode, error) {
	e := NewDagEditor(nd, ds)
	for _, c := range cs {
		switch c.Type {
		case Add:
			child, err := ds.Get(ctx, c.After)
			if err != nil {
				return nil, err
			}

			childpb, ok := child.(*dag.ProtoNode)
			if !ok {
				return nil, dag.ErrNotProtobuf
			}

			err = e.InsertNodeAtPath(ctx, c.Path, childpb, nil)
			if err != nil {
				return nil, err
			}

		case Remove:
			err := e.RmLink(ctx, c.Path)
			if err != nil {
				return nil, err
			}

		case Mod:
			err := e.RmLink(ctx, c.Path)
			if err != nil {
				return nil, err
			}
			child, err := ds.Get(ctx, c.After)
			if err != nil {
				return nil, err
			}

			childpb, ok := child.(*dag.ProtoNode)
			if !ok {
				return nil, dag.ErrNotProtobuf
			}

			err = e.InsertNodeAtPath(ctx, c.Path, childpb, nil)
			if err != nil {
				return nil, err
			}
		}
	}

	return e.Finalize(ctx, ds)
}
973801
func (h *bundleHandler) applicationsForMachineChange(changeId string) []string {
	applications := set.NewStrings()
mainloop:
	for _, change := range h.changes {
		for _, required := range change.Requires() {
			if required != changeId {
				continue
			}
			switch change := change.(type) {
			case *bundlechanges.AddMachineChange:
				// The original machine is a container, and its parent is
				// another "addMachines" change. Search again using the
				// parent id.
				for _, application := range h.applicationsForMachineChange(change.Id()) {
					applications.Add(application)
				}
				continue mainloop
			case *bundlechanges.AddUnitChange:
				// We have found the "addUnit" change, which refers to a
				// application: now resolve the application holding the unit.
				application := resolve(change.Params.Application, h.results)
				applications.Add(application)
				continue mainloop
			case *bundlechanges.SetAnnotationsChange:
				// A machine change is always required to set machine
				// annotations, but this isn't the interesting change here.
				continue mainloop
			default:
				// Should never happen.
				panic(fmt.Sprintf("unexpected change %T", change))
			}
		}
	}
	return applications.SortedValues()
}
390540
func (s *ChangesService) RestoreChange(changeID string, input *RestoreInput) (*ChangeInfo, *Response, error) {
	return s.change("restore", changeID, input)
}
540211
func (b *allModelWatcherStateBacking) Changed(all *multiwatcherStore, change watcher.Change) error {
	c, ok := b.collectionByName[change.C]
	if !ok {
		return errors.Errorf("unknown collection %q in fetch request", change.C)
	}

	modelUUID, id, err := b.idForChange(change)
	if err != nil {
		return errors.Trace(err)
	}

	doc := reflect.New(c.docType).Interface().(backingEntityDoc)

	st, err := b.getState(modelUUID)
	if err != nil {
		if exists, modelErr := b.st.ModelExists(modelUUID); exists && modelErr == nil {
			// The entity's model is gone so remove the entity
			// from the store.
			doc.removed(all, modelUUID, id, nil)
			return nil
		}
		return errors.Trace(err) // prioritise getState error
	}
	defer st.Release()

	col, closer := st.db().GetCollection(c.name)
	defer closer()

	// TODO - see TODOs in allWatcherStateBacking.Changed()
	err = col.FindId(id).One(doc)
	if err == mgo.ErrNotFound {
		err := doc.removed(all, modelUUID, id, st.State)
		return errors.Trace(err)
	}
	if err != nil {
		return err
	}
	return doc.updated(st.State, all, id)
}
115219
func (am *AutogitManager) LocalChange(
	ctx context.Context, node libkbfs.Node, wr libkbfs.WriteRange) {
	// Do nothing.
}
955782
func (f * Facade) getChanges(ctx datastore.Context, svc service.Service) string {
	var updates string
	store := f.serviceStore
	cursvc, err := store.Get(ctx, svc.ID)
	if err != nil {
		glog.Errorf("Could not load service %s (%s) from database: %s", svc.Name, svc.ID, err)
		return updates
	}
        if !reflect.DeepEqual(svc, cursvc) {
		sUpdated := reflect.ValueOf(&svc).Elem()
		typeOfS := sUpdated.Type()
		sCur := reflect.ValueOf(cursvc).Elem()
		for i := 0; i < sUpdated.NumField(); i++ {
			fUpdated := sUpdated.Field(i)
			fCur:= sCur.Field(i)
			fValue := fUpdated.Interface()
			rt := reflect.TypeOf(fValue)
			if rt.Kind() == reflect.Slice || rt.Kind() == reflect.Map || rt.Kind() == reflect.Struct {
				// we don't record changes in ConfigFiles
				if !reflect.DeepEqual(fUpdated.Interface(), fCur.Interface()) && typeOfS.Field(i).Name != "ConfigFiles" {
					str := fmt.Sprintf("%s:%v;", typeOfS.Field(i).Name, fUpdated.Interface())
					updates = updates + str
				}
			} else if fUpdated.Interface() != fCur.Interface() {
				str := fmt.Sprintf("%s:%v;", typeOfS.Field(i).Name, fUpdated.Interface())
				updates = updates + str
			}
		}
	}
	return updates
}