Merge branch 'stable-3.4' into stable-3.5
* stable-3.4:
Fix init step for pull-replication.
Add example using broker notification (Kafka)
Change-Id: I30dd95d9ebe4496644b4f8f631bdd7ed311e51db
diff --git a/example-setup/broker/Dockerfile b/example-setup/broker/Dockerfile
new file mode 100644
index 0000000..2428338
--- /dev/null
+++ b/example-setup/broker/Dockerfile
@@ -0,0 +1,24 @@
+FROM gerritcodereview/gerrit:3.5.4-almalinux8
+
+USER root
+
+RUN yum install -y gettext
+
+ARG JAVA_OPTS='--add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED'
+
+RUN java $JAVA_OPTS -jar /var/gerrit/bin/gerrit.war init --batch --install-all-plugins -d /var/gerrit && \
+ java $JAVA_OPTS -jar /var/gerrit/bin/gerrit.war reindex -d /var/gerrit
+
+RUN git config -f /var/gerrit/etc/secure.config --add auth.bearerToken "theSecretBearerToken"
+
+COPY --chown=gerrit:gerrit pull-replication.jar /var/gerrit/plugins/pull-replication.jar
+COPY --chown=gerrit:gerrit pull-replication.jar /var/gerrit/lib/pull-replication.jar
+
+COPY --chown=gerrit:gerrit events-kafka.jar /var/gerrit/plugins/events-kafka.jar
+COPY --chown=gerrit:gerrit libevents-broker.jar /var/gerrit/lib/libevents-broker.jar
+
+COPY --chown=gerrit:gerrit entrypoint.sh /tmp/
+COPY --chown=gerrit:gerrit configs/replication.config.template /var/gerrit/etc/
+COPY --chown=gerrit:gerrit configs/gerrit.config.template /var/gerrit/etc/
+
+ENTRYPOINT [ "/tmp/entrypoint.sh" ]
diff --git a/example-setup/broker/README.md b/example-setup/broker/README.md
new file mode 100644
index 0000000..d50e097
--- /dev/null
+++ b/example-setup/broker/README.md
@@ -0,0 +1,20 @@
+# What is this for?
+
+This docker compose sets up primary and replica nodes using pull-replication to
+replicate with notifications over a broker. In this case our broker
+implementation is Kafka.
+
+Copy the pull-replication, events-kafka, and events-broker artefacts to test
+into this directory:
+
+```bash
+cp $GERRIT_HOME/bazel-bin/plugins/pull-replication/pull-replication.jar .
+cp $GERRIT_HOME/bazel-bin/plugins/events-kafka/events-kafka.jar .
+cp $GERRIT_HOME/bazel-bin/plugins/events-broker/libevents-broker.jar .
+```
+
+Start up the application using docker compose:
+
+```bash
+docker-compose up
+```
diff --git a/example-setup/broker/configs/gerrit.config.template b/example-setup/broker/configs/gerrit.config.template
new file mode 100644
index 0000000..de65519
--- /dev/null
+++ b/example-setup/broker/configs/gerrit.config.template
@@ -0,0 +1,40 @@
+[gerrit]
+ basePath = git
+ serverId = 69ec38f0-350e-4d9c-96d4-bc956f2faaac
+ canonicalWebUrl = http://localhost:8080
+ installModule = com.gerritforge.gerrit.eventbroker.BrokerApiModule
+ instanceId = $INSTANCE_ID
+[container]
+ javaOptions = "-Dflogger.backend_factory=com.google.common.flogger.backend.log4j.Log4jBackendFactory#getInstance"
+ javaOptions = "-Dflogger.logging_context=com.google.gerrit.server.logging.LoggingContext#getInstance"
+ javaOptions = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:$DEBUG_PORT"
+ replica = $REPLICA
+[index]
+ type = LUCENE
+[auth]
+ type = DEVELOPMENT_BECOME_ANY_ACCOUNT
+[receive]
+ enableSignedPush = false
+[sendemail]
+ smtpServer = localhost
+[sshd]
+ listenAddress = *:29418
+ advertisedAddress = *:29418
+[httpd]
+ listenUrl = http://*:8080/
+ requestLog = true
+[cache]
+ directory = cache
+[plugins]
+ allowRemoteAdmin = true
+[plugin "events-kafka"]
+ sendAsync = true
+ bootstrapServers = $BROKER_HOST:$BROKER_PORT
+ groupId = $INSTANCE_ID
+ numberOfSubscribers = 6
+ securityProtocol = PLAINTEXT
+ pollingIntervalMs = 1000
+ enableAutoCommit = true
+ autoCommitIntervalMs = 1000
+ autoOffsetReset = latest
+ sendStreamEvents = true
\ No newline at end of file
diff --git a/example-setup/broker/configs/replication.config.template b/example-setup/broker/configs/replication.config.template
new file mode 100644
index 0000000..d81662f
--- /dev/null
+++ b/example-setup/broker/configs/replication.config.template
@@ -0,0 +1,25 @@
+[gerrit]
+ autoReload = true
+ replicateOnStartup = false
+[replication]
+ excludeRefs = ^refs/users/\\d\\d/\\d+/edit-\\d+/\\d+$
+ lockErrorMaxRetries = 5
+ maxRetries = 100
+ useCGitClient = false
+ consumeStreamEvents = false
+ eventBrokerTopic = gerrit
+ syncRefs = "ALL REFS ASYNC"
+ maxApiPayloadSize = 40000
+[remote "$REMOTE"]
+ url = http://$REMOTE_URL:8080/#{name}#.git
+ fetch = +refs/*:refs/*
+ mirror = true
+ timeout = 60 # In seconds
+ connectionTimeout = 120000 # In mseconds
+ rescheduleDelay = 15
+ replicationDelay = 1
+ threads = 4
+ createMissingRepositories = true
+ replicateProjectDeletions = true
+ replicateHiddenProjects = true
+ tagopt = --no-tags
\ No newline at end of file
diff --git a/example-setup/broker/docker-compose.yaml b/example-setup/broker/docker-compose.yaml
new file mode 100644
index 0000000..4f7f99f
--- /dev/null
+++ b/example-setup/broker/docker-compose.yaml
@@ -0,0 +1,58 @@
+version: '3'
+services:
+ gerrit1:
+ build: .
+ environment:
+ - INSTANCE_ID=primary
+ - REPLICA=false
+ - REMOTE=replica-1
+ - REMOTE_URL=gerrit2
+ - DEBUG_PORT=5005
+ - BROKER_HOST=broker
+ - BROKER_PORT=9092
+ ports:
+ - "8080:8080"
+ - "29418:29418"
+ - "5005:5005"
+ depends_on:
+ - broker
+ gerrit2:
+ build: .
+ environment:
+ - INSTANCE_ID=replica-1
+ - REPLICA=true
+ - REMOTE=primary
+ - REMOTE_URL=gerrit1
+ - DEBUG_PORT=5006
+ - BROKER_HOST=broker
+ - BROKER_PORT=9092
+ ports:
+ - "8081:8080"
+ - "29419:29418"
+ - "5006:5006"
+ depends_on:
+ - broker
+ - gerrit1
+
+ zookeeper:
+ image: confluentinc/cp-zookeeper:7.3.0
+ container_name: zookeeper
+ environment:
+ ZOOKEEPER_CLIENT_PORT: 2181
+ ZOOKEEPER_TICK_TIME: 2000
+
+ broker:
+ image: confluentinc/cp-kafka:7.3.0
+ container_name: broker
+ ports:
+ - "9092:9092"
+ depends_on:
+ - zookeeper
+ environment:
+ KAFKA_BROKER_ID: 1
+ KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
+ KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT
+ KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:9092,PLAINTEXT_INTERNAL://broker:29092
+ KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
+ KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
+ KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
\ No newline at end of file
diff --git a/example-setup/entrypoint.sh b/example-setup/broker/entrypoint.sh
similarity index 100%
copy from example-setup/entrypoint.sh
copy to example-setup/broker/entrypoint.sh
diff --git a/example-setup/Dockerfile b/example-setup/http/Dockerfile
similarity index 100%
rename from example-setup/Dockerfile
rename to example-setup/http/Dockerfile
diff --git a/example-setup/README.md b/example-setup/http/README.md
similarity index 100%
rename from example-setup/README.md
rename to example-setup/http/README.md
diff --git a/example-setup/configs/gerrit.config.template b/example-setup/http/configs/gerrit.config.template
similarity index 100%
rename from example-setup/configs/gerrit.config.template
rename to example-setup/http/configs/gerrit.config.template
diff --git a/example-setup/configs/replication.config.template b/example-setup/http/configs/replication.config.template
similarity index 100%
rename from example-setup/configs/replication.config.template
rename to example-setup/http/configs/replication.config.template
diff --git a/example-setup/docker-compose.yaml b/example-setup/http/docker-compose.yaml
similarity index 100%
rename from example-setup/docker-compose.yaml
rename to example-setup/http/docker-compose.yaml
diff --git a/example-setup/entrypoint.sh b/example-setup/http/entrypoint.sh
similarity index 100%
rename from example-setup/entrypoint.sh
rename to example-setup/http/entrypoint.sh
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/InitPlugin.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/InitPlugin.java
index 1702948..5539451 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/InitPlugin.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/InitPlugin.java
@@ -52,7 +52,10 @@
}
@Override
- public void run() throws Exception {
+ public void run() {}
+
+ @Override
+ public void postRun() throws Exception {
ui.header("%s initialization", pluginName);
if (!bearerTokenProvider.get().isPresent()) {