Merge branch 'stable-2.9' into stable-2.10

* stable-2.9:
  Prevent creating repos on extra servers

Conflicts:
	src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java

Change-Id: I5934d118a72dd249b17b7f381aa3081ef58aa09d
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
index 14337d6..ef659f2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java
@@ -199,28 +199,30 @@
     return cfg.getInt("remote", rc.getName(), name, defValue);
   }
 
-  void schedule(final Project.NameKey project, final String ref,
-      final URIish uri, ReplicationState state) {
+  private boolean isVisible(final Project.NameKey project,
+      ReplicationState... states) {
     try {
-      repLog.info("scheduling replication {}:{} => {}", project, ref, uri);
-      boolean visible = threadScoper.scope(new Callable<Boolean>(){
+      return threadScoper.scope(new Callable<Boolean>() {
         @Override
         public Boolean call() throws NoSuchProjectException {
           return controlFor(project).isVisible();
         }
       }).call();
-      if (!visible) {
-        stateLog.warn(String.format("project %s is not visible", project),
-            state);
-        return;
-      }
     } catch (NoSuchProjectException err) {
-      stateLog.error(String.format(
-          "source project %s not available", project), err, state);
-      return;
+      stateLog.error(String.format("source project %s not available", project),
+          err, states);
     } catch (Exception e) {
       throw Throwables.propagate(e);
     }
+    return false;
+  }
+
+  void schedule(final Project.NameKey project, final String ref,
+      final URIish uri, ReplicationState state) {
+    repLog.info("scheduling replication {}:{} => {}", project, ref, uri);
+    if (!isVisible(project, state)) {
+      return;
+    }
 
     if (!replicatePermissions) {
       PushOne e;
@@ -384,7 +386,11 @@
     }
   }
 
-  boolean wouldPushProject(Project.NameKey project) {
+  boolean wouldPushProject(final Project.NameKey project) {
+    if (!isVisible(project)) {
+      return false;
+    }
+
     // by default push all projects
     if (projects.length < 1) {
       return true;