Remove support for EventMessage deserialisation
From version stable-3.4 events-broker sends Event objects as a
message but for rolling upgrades from stable-3.3 deserialisation of
EventMessage is still supported. Because stable-3.4 is not sending
EventMessage deserialisation logic can be removed.
Bug: Issue 14823
Change-Id: I577ceb86094fa32a040c68ce1dd2308efe0d12e9
diff --git a/src/main/java/com/gerritforge/gerrit/eventbroker/EventDeserializer.java b/src/main/java/com/gerritforge/gerrit/eventbroker/EventDeserializer.java
index 986fab2..babc9d7 100644
--- a/src/main/java/com/gerritforge/gerrit/eventbroker/EventDeserializer.java
+++ b/src/main/java/com/gerritforge/gerrit/eventbroker/EventDeserializer.java
@@ -16,7 +16,6 @@
import static java.util.Objects.requireNonNull;
-import com.google.common.base.Strings;
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.events.EventGson;
import com.google.gson.Gson;
@@ -32,17 +31,8 @@
}
public Event deserialize(String json) {
- Event resultEvent;
- EventMessage eventMessage = gson.fromJson(json, EventMessage.class);
- if (eventMessage.getEvent() == null && eventMessage.getHeader() == null) {
- resultEvent = gson.fromJson(json, Event.class);
- } else {
- eventMessage.validate();
- resultEvent = eventMessage.getEvent();
- if (Strings.isNullOrEmpty(resultEvent.instanceId)) {
- resultEvent.instanceId = eventMessage.getHeader().sourceInstanceId;
- }
- }
+ Event resultEvent = gson.fromJson(json, Event.class);
+
validate(resultEvent);
return resultEvent;
}
diff --git a/src/main/java/com/gerritforge/gerrit/eventbroker/EventMessage.java b/src/main/java/com/gerritforge/gerrit/eventbroker/EventMessage.java
deleted file mode 100644
index 0684ae4..0000000
--- a/src/main/java/com/gerritforge/gerrit/eventbroker/EventMessage.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (C) 2019 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.gerritforge.gerrit.eventbroker;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.gerrit.server.events.Event;
-import java.util.UUID;
-
-/**
- * Enrich an existing {@link Event} object with the information about the source that produced it,
- * including the Gerrit server instance id. Additionally this class contains an event-id, event-type
- * and event-created-on fields.
- */
-public class EventMessage {
-
- private final Header header;
- private final Event body;
-
- public Header getHeader() {
- return header;
- }
-
- /**
- * Returns deserialized {@code Event} object
- *
- * @return {@code Event} class instance
- */
- public Event getEvent() {
- return body;
- }
-
- /** Contains all additional information required to successfully send an {@code Event} object. */
- public static class Header {
- /** Unique event id. */
- public final UUID eventId;
-
- /** Gerrit server instance id from which event was sent. */
- public final String sourceInstanceId;
-
- /** @deprecated required for interoperability with older JSON wire protocols */
- public final String eventType;
-
- public Header(UUID eventId, UUID sourceInstanceId) {
- this(eventId, sourceInstanceId.toString());
- }
-
- public Header(UUID eventId, String sourceInstanceId) {
- this.eventId = eventId;
- this.sourceInstanceId = sourceInstanceId;
- this.eventType = "";
- }
-
- /** Validate if all required header fields are not null. */
- public void validate() {
- requireNonNull(eventId, "EventId cannot be null");
- requireNonNull(sourceInstanceId, "Source Instance ID cannot be null");
- }
-
- @Override
- public String toString() {
- return "{" + "eventId=" + eventId + ", sourceInstanceId=" + sourceInstanceId + '}';
- }
- }
-
- /**
- * Creates a new instance which can be send as a message via {@link BrokerApi}.
- *
- * @param header message header object, contains all additional information required to properly
- * send the message
- * @param event {@link Event} object
- */
- public EventMessage(Header header, Event event) {
- this.header = header;
- this.body = event;
- }
-
- /** Validate if all required fields are not null. */
- public void validate() {
- requireNonNull(header, "Header cannot be null");
- requireNonNull(body, "Event cannot be null");
- header.validate();
- }
-
- @Override
- public String toString() {
- return String.format("Header='%s', Body='%s'", header, body);
- }
-}
diff --git a/src/test/java/com/gerritforge/gerrit/eventbroker/EventDeserializerTest.java b/src/test/java/com/gerritforge/gerrit/eventbroker/EventDeserializerTest.java
index 1bc2535..bd7b98b 100644
--- a/src/test/java/com/gerritforge/gerrit/eventbroker/EventDeserializerTest.java
+++ b/src/test/java/com/gerritforge/gerrit/eventbroker/EventDeserializerTest.java
@@ -19,7 +19,6 @@
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.events.EventGsonProvider;
import com.google.gson.Gson;
-import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
@@ -33,24 +32,6 @@
}
@Test
- public void eventDeserializerShouldParseEventMessage() {
- final UUID eventId = UUID.randomUUID();
- final String eventType = "event-type";
- final String sourceInstanceId = UUID.randomUUID().toString();
- final long eventCreatedOn = 10L;
- final String eventJson =
- String.format(
- "{ "
- + "\"header\": { \"eventId\": \"%s\", \"eventType\": \"%s\", \"sourceInstanceId\": \"%s\", \"eventCreatedOn\": %d },"
- + "\"body\": { \"type\": \"project-created\" }"
- + "}",
- eventId, eventType, sourceInstanceId, eventCreatedOn);
- final Event event = deserializer.deserialize(eventJson);
-
- assertThat(event.instanceId).isEqualTo(sourceInstanceId);
- }
-
- @Test
public void eventDeserializerShouldParseEvent() {
final String eventJson = "{ \"type\": \"project-created\", \"instanceId\":\"instance-id\" }";
final Event event = deserializer.deserialize(eventJson);