Merge branch 'stable-3.1' into stable-3.2
* stable-3.1:
Propagate FetchRefReplicatedEvent
Send small refs as a fetch call payload
Send ref content as a fetch call payload
Index change upon propagation
Propagate FetchRefReplicatedEvent upon a Ref fetch
Change-Id: I89e4d6104a590a10ed2ecd709d0595f59d1f7f99
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
index 0d4c57d..639bc80 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/Source.java
@@ -29,6 +29,7 @@
import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames;
+import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.extensions.registration.DynamicItem;
import com.google.gerrit.extensions.restapi.AuthException;
@@ -289,10 +290,10 @@
new Callable<Boolean>() {
@Override
public Boolean call() throws NoSuchProjectException, PermissionBackendException {
- ProjectState projectState;
+ Optional<ProjectState> projectState;
try {
- projectState = projectCache.checkedGet(project);
- } catch (IOException e) {
+ projectState = projectCache.get(project);
+ } catch (StorageException e) {
repLog.warn(
"NOT scheduling replication {}:{} because could not open source project",
project,
@@ -300,25 +301,21 @@
e);
return false;
}
- if (projectState == null) {
+ if (!projectState.isPresent()) {
repLog.warn(
"NOT scheduling replication {}:{} because project does not exist",
project,
ref);
throw new NoSuchProjectException(project);
}
- if (!projectState.statePermitsRead()) {
+ if (!projectState.get().statePermitsRead()) {
repLog.warn(
"NOT scheduling replication {}:{} because project is not readable",
project,
ref);
return false;
}
- if (!shouldReplicate(projectState, userProvider.get())) {
- repLog.warn(
- "NOT scheduling replication {}:{} because project is supposed to be replicated",
- project,
- ref);
+ if (!shouldReplicate(projectState.get(), userProvider.get())) {
return false;
}
if (FetchOne.ALL_REFS.equals(ref)) {
@@ -360,16 +357,16 @@
new Callable<Boolean>() {
@Override
public Boolean call() throws NoSuchProjectException, PermissionBackendException {
- ProjectState projectState;
+ Optional<ProjectState> projectState;
try {
- projectState = projectCache.checkedGet(project);
- } catch (IOException e) {
+ projectState = projectCache.get(project);
+ } catch (StorageException e) {
return false;
}
- if (projectState == null) {
+ if (!projectState.isPresent()) {
throw new NoSuchProjectException(project);
}
- return shouldReplicate(projectState, userProvider.get());
+ return shouldReplicate(projectState.get(), userProvider.get());
}
})
.call();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java
index 678ff73..db4edf5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/ApplyObjectAction.java
@@ -96,7 +96,7 @@
} catch (MissingParentObjectException e) {
throw new ResourceConflictException(e.getMessage(), e);
} catch (NumberFormatException | IOException e) {
- throw new RestApiException(e.getMessage(), e);
+ throw RestApiException.wrap(e.getMessage(), e);
} catch (RefUpdateException e) {
throw new UnprocessableEntityException(e.getMessage());
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java
index 6970299..c44bcbc 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/pull/api/FetchAction.java
@@ -84,7 +84,7 @@
| ExecutionException
| IllegalStateException
| TimeoutException e) {
- throw new RestApiException(e.getMessage(), e);
+ throw RestApiException.wrap(e.getMessage(), e);
} catch (RemoteConfigurationMissingException e) {
throw new UnprocessableEntityException(e.getMessage());
}