Skip to content

Commit

Permalink
RHCLOUD-28235 Unify how org ID is passed to connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenneg committed Sep 23, 2023
1 parent 2c613eb commit 2b7fd97
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ public class ConnectorSender {
NotificationHistoryRepository notificationHistoryRepository;

public void send(Event event, Endpoint endpoint, JsonObject payload) {
payload.put("orgId", event.getOrgId());

String connector = getConnector(endpoint);

NotificationHistory history = getHistoryStub(endpoint, event, 0L, UUID.randomUUID());
history.setStatus(PROCESSING);

Log.infof("Sending notification to connector [orgId=%s, eventId=%s, connector=%s, historyId=%s]",
endpoint.getOrgId(), event.getId(), connector, history.getId());
event.getOrgId(), event.getId(), connector, history.getId());

notificationHistoryRepository.createNotificationHistory(history);

Expand All @@ -62,7 +63,7 @@ public void send(Event event, Endpoint endpoint, JsonObject payload) {
history.setDetails(Map.of("failure", e.getMessage()));
notificationHistoryRepository.updateHistoryItem(history);
Log.infof(e, "Failed to send notification to connector [orgId=%s, eventId=%s, connector=%s, historyId=%s]",
endpoint.getOrgId(), event.getId(), connector, history.getId());
event.getOrgId(), event.getId(), connector, history.getId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@

public class CamelNotification {

public String orgId;

public String webhookUrl;

public String message;

@Override
public String toString() {
return "CamelNotification [orgId=" + orgId + ", webhookUrl=" + webhookUrl + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ protected CamelNotification getCamelNotification(Event event, Endpoint endpoint)
CamelProperties properties = endpoint.getProperties(CamelProperties.class);

CamelNotification notification = new CamelNotification();
notification.orgId = endpoint.getOrgId();
notification.webhookUrl = properties.getUrl();
notification.message = message;
return notification;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
public class SlackNotification extends CamelNotification {

public String channel;

@Override
public String toString() {
return "SlackNotification [orgId=" + orgId + ", webhookUrl=" + webhookUrl + ", channel=" + channel + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ protected CamelNotification getCamelNotification(Event event, Endpoint endpoint)
CamelProperties properties = endpoint.getProperties(CamelProperties.class);

SlackNotification notification = new SlackNotification();
notification.orgId = endpoint.getOrgId();
notification.webhookUrl = properties.getUrl();
notification.channel = properties.getExtras().get("channel");
notification.message = message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ protected void verifyKafkaMessage() {
assertNotNull(cloudEventMetadata.getId());
assertEquals(getExpectedCloudEventType(), cloudEventMetadata.getType());

CamelNotification notification = message.getPayload().mapTo(CamelNotification.class);
JsonObject notification = message.getPayload();

assertEquals(DEFAULT_ORG_ID, notification.orgId);
assertEquals(WEBHOOK_URL, notification.webhookUrl);
assertEquals(getExpectedMessage(), notification.message);
assertEquals(DEFAULT_ORG_ID, notification.getString("orgId"));
assertEquals(WEBHOOK_URL, notification.getString("webhookUrl"));
assertEquals(getExpectedMessage(), notification.getString("message"));
}

protected void assertNotificationsConnectorHeader(Message<JsonObject> message) {
Expand Down Expand Up @@ -155,6 +155,7 @@ protected static Event buildEvent() {

Event event = new Event();
event.setId(UUID.randomUUID());
event.setOrgId(DEFAULT_ORG_ID);
event.setEventWrapper(new EventWrapperAction(action));

return event;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ protected void verifyKafkaMessage() {
assertNotNull(cloudEventMetadata.getId());
assertEquals(getExpectedCloudEventType(), cloudEventMetadata.getType());

SlackNotification notification = message.getPayload().mapTo(SlackNotification.class);
JsonObject notification = message.getPayload();

assertEquals(DEFAULT_ORG_ID, notification.orgId);
assertEquals(WEBHOOK_URL, notification.webhookUrl);
assertEquals(CHANNEL, notification.channel);
assertEquals(SLACK_EXPECTED_MSG, notification.message);
assertEquals(DEFAULT_ORG_ID, notification.getString("orgId"));
assertEquals(WEBHOOK_URL, notification.getString("webhookUrl"));
assertEquals(CHANNEL, notification.getString("channel"));
assertEquals(SLACK_EXPECTED_MSG, notification.getString("message"));
}

@Override
Expand Down

0 comments on commit 2b7fd97

Please sign in to comment.