Add pull-replication plugin in primary-replica topology.

Bug: Issue 16393
Change-Id: I97a9eb7866d3595779060120cba02d290f4a8295
diff --git a/primary-replica/Makefile b/primary-replica/Makefile
index 0bc0dba..887ff0c 100644
--- a/primary-replica/Makefile
+++ b/primary-replica/Makefile
@@ -10,6 +10,8 @@
 CLOUDWATCH_DASHBOARD_TEMPLATE:=cf-dashboard.yml
 AWS_FC_COMMAND=export AWS_PAGER=;aws cloudformation
 GIT_GC_SOURCE_PATH=/gerrit-mount-point/gerrit-git
+PLUGINS=javamelody healthcheck metrics-reporter-cloudwatch pull-replication
+PLUGINS_LIBS_LINKS=pull-replication
 
 .PHONY: create-all delete-all \
 				cluster cluster-keys service-primary service-replica dns-routing dashboard \
@@ -95,6 +97,7 @@
 		ParameterKey=GerritCPU,ParameterValue=$(GERRIT_CPU) \
 		ParameterKey=GerritHeapLimit,ParameterValue=$(GERRIT_HEAP_LIMIT) \
 		ParameterKey=JgitCacheSize,ParameterValue=$(JGIT_CACHE_SIZE) \
+		ParameterKey=HttpReplicaSubdomain,ParameterValue=$(HTTP_REPLICA_SUBDOMAIN) \
 		$(JGIT_OPTIONAL_PARAMS) \
 		$(LDAP_ACCOUNT_PATTERN_PARAM) \
 		$(PRIMARY_SERVICE_OPTIONAL_PARAMS) \
@@ -141,6 +144,8 @@
 		ParameterKey=GerritCPU,ParameterValue=$(GERRIT_CPU) \
 		ParameterKey=GerritHeapLimit,ParameterValue=$(GERRIT_HEAP_LIMIT) \
 		ParameterKey=JgitCacheSize,ParameterValue=$(JGIT_CACHE_SIZE) \
+		ParameterKey=HttpPrimaryGerritSubdomain,ParameterValue=$(HTTP_PRIMARY_SUBDOMAIN) \
+		ParameterKey=GerritPrimarynstanceId,ParameterValue=$(GERRIT_PRIMARY_INSTANCE_ID) \
 		$(JGIT_OPTIONAL_PARAMS) \
 		$(LDAP_ACCOUNT_PATTERN_PARAM) \
 		$(REPLICA_SERVICE_OPTIONAL_PARAMS) \
@@ -289,7 +294,7 @@
 						delete-dashboard wait-for-dashboard-deletion
 
 gerrit-publish:
-	$(MAKE) -C ../gerrit gerrit-publish RECIPE=primary-replica
+	$(MAKE) -C ../gerrit gerrit-publish RECIPE=primary-replica PLUGINS="$(PLUGINS)" PLUGINS_LIBS_LINKS="$(PLUGINS_LIBS_LINKS)"
 
 git-daemon-publish:
 	$(MAKE) -C git-daemon git-daemon-publish
diff --git a/primary-replica/cf-service-primary.yml b/primary-replica/cf-service-primary.yml
index fc25e5e..893a4cd 100644
--- a/primary-replica/cf-service-primary.yml
+++ b/primary-replica/cf-service-primary.yml
@@ -181,6 +181,9 @@
     Type: String
     Default: false
     AllowedValues: [true, false]
+  HttpReplicaSubdomain:
+    Description: The subdomain of the loadbalancer serving HTTP traffic to the replicas
+    Type: String
 
 Mappings:
   XRay:
@@ -306,6 +309,8 @@
                       Value: !Ref MetricsCloudwatchDryRun
                     - Name: METRICS_CLOUDWATCH_EXCLUDE_METRICS_LIST
                       Value: !Join [',', !Ref MetricsCloudwatchExcludeMetrics]
+                    - Name: HTTP_REPLICA_SUBDOMAIN
+                      Value: !Ref HttpReplicaSubdomain
                   Ulimits:
                     - Name: nofile
                       HardLimit: !Ref FileDescriptorsHardLimit
diff --git a/primary-replica/cf-service-replica.yml b/primary-replica/cf-service-replica.yml
index 5a44761..7e6c128 100644
--- a/primary-replica/cf-service-replica.yml
+++ b/primary-replica/cf-service-replica.yml
@@ -218,6 +218,12 @@
     Type: String
     Default: false
     AllowedValues: [true, false]
+  HttpPrimaryGerritSubdomain:
+    Description: The subdomain of the loadbalancer serving HTTP traffic to the primary
+    Type: String
+  GerritPrimarynstanceId:
+    Description: Gerrit InstanceId of the Primary
+    Type: String
 
 Mappings:
   XRay:
@@ -324,6 +330,14 @@
                       Value: !Ref MetricsCloudwatchDryRun
                     - Name: METRICS_CLOUDWATCH_EXCLUDE_METRICS_LIST
                       Value: !Join [',', !Ref MetricsCloudwatchExcludeMetrics]
+                    - Name: HTTP_PRIMARIES_GERRIT_SUBDOMAIN
+                      Value: !Ref HttpPrimaryGerritSubdomain
+                    - Name: GERRIT_PRIMARY_INSTANCE_ID
+                      Value: !Ref GerritPrimarynstanceId
+                    - Name: SETUP_REPLICATION
+                      Value: true
+                    - Name: HOSTED_ZONE_NAME
+                      Value: !Ref HostedZoneName
                   Ulimits:
                     - Name: nofile
                       HardLimit: !Ref FileDescriptorsHardLimit