From 082d6901f7f24e98108404fd9df5b531bca5ff67 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 3 May 2016 09:50:49 -0700 Subject: [PATCH] visitor --- nomad/structs/diff/job.go | 2 ++ nomad/structs/diff/job_visitor.go | 52 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 nomad/structs/diff/job_visitor.go diff --git a/nomad/structs/diff/job.go b/nomad/structs/diff/job.go index 0eaccb9c3..9bbcab955 100644 --- a/nomad/structs/diff/job.go +++ b/nomad/structs/diff/job.go @@ -250,6 +250,8 @@ type PrimitiveStructDiff struct { PrimitiveFields []*FieldDiff } +// DiffFields performs the diff of the passed fields against the old and new +// object. func (p *PrimitiveStructDiff) DiffFields(old, new interface{}, fields []string) { for _, field := range fields { oldV := getField(old, field) diff --git a/nomad/structs/diff/job_visitor.go b/nomad/structs/diff/job_visitor.go new file mode 100644 index 000000000..c9ef9a4cc --- /dev/null +++ b/nomad/structs/diff/job_visitor.go @@ -0,0 +1,52 @@ +package diff + +// JobVisitor is the set of types a visitor must implement to traverse a JobDiff +// structure. +type JobVisitor interface { + VisitJob(*JobDiff) + VisitTaskGroups(*TaskGroupsDiff) + VisitTaskGroup(*TaskGroupDiff) + VisitTasks(*TasksDiff) + VisitTask(*TaskDiff) + VisitServices(*ServicesDiff) + VisitService(*ServiceDiff) + VisitServiceChecks(*ServiceChecksDiff) + VisitServiceCheck(*ServiceCheckDiff) + VisitTaskArtifactsDiff(*TaskArtifactsDiff) + VisitTaskArtifactDiff(*TaskArtifactDiff) + VisitResources(*ResourcesDiff) + VisitNetworkResources(*NetworkResourcesDiff) + VisitNetworkResource(*NetworkResourceDiff) + VisitPorts(*PortsDiff) + VisitPrimitiveStruct(*PrimitiveStructDiff) + VisitField(*FieldDiff) + VisitStringSet(*StringSetDiff) + VisitStringMap(*StringMapDiff) + VisitStringValueDelta(*StringValueDelta) +} + +// JobDiffComponent is the method a diff component must implement to be visited. +type JobDiffComponent interface { + Accept(JobVisitor) +} + +func (j *JobDiff) Accept(v JobVisitor) { v.VisitJob(j) } +func (t *TaskGroupsDiff) Accept(v JobVisitor) { v.VisitTaskGroups(t) } +func (t *TaskGroupDiff) Accept(v JobVisitor) { v.VisitTaskGroup(t) } +func (t *TasksDiff) Accept(v JobVisitor) { v.VisitTasks(t) } +func (t *TaskDiff) Accept(v JobVisitor) { v.VisitTask(t) } +func (s *ServicesDiff) Accept(v JobVisitor) { v.VisitServices(s) } +func (s *ServiceDiff) Accept(v JobVisitor) { v.VisitService(s) } +func (s *ServiceChecksDiff) Accept(v JobVisitor) { v.VisitServiceChecks(s) } +func (s *ServiceCheckDiff) Accept(v JobVisitor) { v.VisitServiceCheck(s) } +func (t *TaskArtifactsDiff) Accept(v JobVisitor) { v.VisitTaskArtifactsDiff(t) } +func (t *TaskArtifactDiff) Accept(v JobVisitor) { v.VisitTaskArtifactDiff(t) } +func (r *ResourcesDiff) Accept(v JobVisitor) { v.VisitResources(r) } +func (n *NetworkResourcesDiff) Accept(v JobVisitor) { v.VisitNetworkResources(n) } +func (n *NetworkResourceDiff) Accept(v JobVisitor) { v.VisitNetworkResource(n) } +func (p *PortsDiff) Accept(v JobVisitor) { v.VisitPorts(p) } +func (p *PrimitiveStructDiff) Accept(v JobVisitor) { v.VisitPrimitiveStruct(p) } +func (f *FieldDiff) Accept(v JobVisitor) { v.VisitField(f) } +func (s *StringSetDiff) Accept(v JobVisitor) { v.VisitStringSet(s) } +func (s *StringMapDiff) Accept(v JobVisitor) { v.VisitStringMap(s) } +func (s *StringValueDelta) Accept(v JobVisitor) { v.VisitStringValueDelta(s) }