Simplify Zookeeper change cache API

Move common methods to AbstractChangeCache so that concrete
implementations only need to defined the mapping from change type as
string to the change class.

Change-Id: I78c1bdfad1c0986aa6aef387424ea35b6c2aa71d
This commit is contained in:
Simon Westphahl
2021-09-17 12:55:06 +02:00
committed by James E. Blair
parent 5113fbceb0
commit deb0b69260
7 changed files with 9 additions and 39 deletions

View File

@@ -1243,12 +1243,6 @@ class DummyChangeCache(AbstractChangeCache):
"DummyChange": DummyChange,
}
def _getChangeClass(self, change_type):
return self.CHANGE_TYPE_MAP[change_type]
def _getChangeType(self, change):
return type(change).__name__
class DummySource:

View File

@@ -63,12 +63,6 @@ class GerritChangeCache(AbstractChangeCache):
"GerritChange": GerritChange,
}
def _getChangeClass(self, change_type):
return self.CHANGE_TYPE_MAP[change_type]
def _getChangeType(self, change):
return type(change).__name__
class GerritChangeData(object):
"""Compatability layer for SSH/HTTP

View File

@@ -34,12 +34,6 @@ class GitChangeCache(AbstractChangeCache):
"Branch": Branch,
}
def _getChangeClass(self, change_type):
return self.CHANGE_TYPE_MAP[change_type]
def _getChangeType(self, change):
return type(change).__name__
class GitConnection(ZKChangeCacheMixin, BaseConnection):
driver_name = 'git'

View File

@@ -103,12 +103,6 @@ class GithubChangeCache(AbstractChangeCache):
"PullRequest": PullRequest,
}
def _getChangeClass(self, change_type):
return self.CHANGE_TYPE_MAP[change_type]
def _getChangeType(self, change):
return type(change).__name__
class GithubRequestLogger:

View File

@@ -51,12 +51,6 @@ class GitlabChangeCache(AbstractChangeCache):
"MergeRequest": MergeRequest,
}
def _getChangeClass(self, change_type):
return self.CHANGE_TYPE_MAP[change_type]
def _getChangeType(self, change):
return type(change).__name__
class GitlabEventConnector(threading.Thread):
"""Move events from Gitlab into the scheduler"""

View File

@@ -107,12 +107,6 @@ class PagureChangeCache(AbstractChangeCache):
"PullRequest": PullRequest,
}
def _getChangeClass(self, change_type):
return self.CHANGE_TYPE_MAP[change_type]
def _getChangeType(self, change):
return type(change).__name__
class PagureEventConnector(threading.Thread):
"""Move events from Pagure into the scheduler"""

View File

@@ -286,12 +286,18 @@ class AbstractChangeCache(ZooKeeperSimpleBase, Iterable, abc.ABC):
def _updateChange(self, change, data):
change.deserialize(data["change_data"])
@abc.abstractmethod
def _getChangeClass(self, change_type):
"""Return the change class for the given type."""
pass
return self.CHANGE_TYPE_MAP[change_type]
@abc.abstractmethod
def _getChangeType(self, change):
"""Return the change type as a string for the given type."""
return type(change).__name__
@abc.abstractproperty
def CHANGE_TYPE_MAP(self):
"""Return a mapping of change type as string to change class.
This property cann also be defined as a class attribute.
"""
pass