Add source interface for setting change attributes

Changes are mostly created and updated by the drivers. However, since
there are some change attributes that are also modified from other parts
of the code, we need to make sure to update the cache in Zookeeper in
those cases. For this we introduce `setChangeAttributes()` as an
additional `Source` interface.

Change-Id: Iab9bc4a6e40f254c1cbc4405e90cb5f03e3ecd56
This commit is contained in:
Simon Westphahl
2021-08-23 09:40:18 +02:00
parent fa647d86fd
commit 22c379bf80
3 changed files with 31 additions and 6 deletions

View File

@@ -599,7 +599,6 @@ class PipelineManager(metaclass=ABCMeta):
# Search for Depends-On headers and find appropriate changes
log.debug(" Updating commit dependencies for %s", change)
change.refresh_deps = False
dependencies = []
seen = set()
for match in find_dependency_headers(change.message):
@@ -620,7 +619,12 @@ class PipelineManager(metaclass=ABCMeta):
if dep and (not dep.is_merged) and dep not in dependencies:
log.debug(" Adding dependency: %s", dep)
dependencies.append(dep)
change.commit_needs_changes = dependencies
source = self.sched.connections.getSource(
change.project.connection_name)
source.setChangeAttributes(
change,
commit_needs_changes=[d for d in dependencies],
refresh_deps=False)
def provisionNodes(self, item):
log = item.annotateLogger(self.log)
@@ -1458,7 +1462,9 @@ class PipelineManager(metaclass=ABCMeta):
def onFilesChangesCompleted(self, event, build_set):
item = build_set.item
item.change.files = event.files
source = self.sched.connections.getSource(
item.change.project.connection_name)
source.setChangeAttributes(item.change, files=event.files)
build_set.files_state = build_set.COMPLETE
def onMergeCompleted(self, event, build_set):
@@ -1469,7 +1475,11 @@ class PipelineManager(metaclass=ABCMeta):
def _onMergeCompleted(self, event, build_set):
item = build_set.item
item.change.containing_branches = event.item_in_branches
source = self.sched.connections.getSource(
item.change.project.connection_name)
if isinstance(item.change, model.Tag):
source.setChangeAttributes(
item.change, containing_branches=event.item_in_branches)
build_set.merge_state = build_set.COMPLETE
build_set.repo_state = event.repo_state
if event.merged:

View File

@@ -2192,8 +2192,11 @@ class Scheduler(threading.Thread):
continue
for dep in other_change.commit_needs_changes:
if change.isUpdateOf(dep):
other_change.refresh_deps = True
change.refresh_deps = True
source.setChangeAttributes(
other_change, refresh_deps=True)
source = self.connections.getSource(change.project.connection_name)
source.setChangeAttributes(change, refresh_deps=True)
def cancelJob(self, buildset, job, build=None, final=False,
force=False):

View File

@@ -126,3 +126,15 @@ class BaseSource(object, metaclass=abc.ABCMeta):
def getRejectFilters(self, config):
"""Return a list of ChangeFilters for the scheduler to match against.
"""
def setChangeAttributes(self, change, **attrs):
""""Set the provided attributes on the given change.
This method must be used when modifying attributes of a change
outside the driver context. The driver needs to make sure that
the change is also reflected in the cache in Zookeeper.
"""
# TODO (swestphahl): Remove this workaround after all drivers
# have been converted to use a Zookeeper backed changed cache.
for name, value in attrs.items():
setattr(change, name, value)