-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce notification settings on schema change (#7104)
- Loading branch information
1 parent
d50fc0a
commit e7897a8
Showing
10 changed files
with
176 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...otification/src/main/java/io/airbyte/notification/WorkspaceNotificationConfigFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.notification; | ||
|
||
import io.airbyte.api.client.AirbyteApiClient; | ||
import io.airbyte.api.client.generated.WorkspaceApi; | ||
import io.airbyte.api.client.model.generated.ConnectionIdRequestBody; | ||
import io.airbyte.api.client.model.generated.NotificationItem; | ||
import io.airbyte.api.client.model.generated.WorkspaceRead; | ||
import jakarta.inject.Singleton; | ||
import java.util.UUID; | ||
import lombok.Value; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* Fetching notification settings from workspace. | ||
*/ | ||
@Singleton | ||
@Slf4j | ||
public class WorkspaceNotificationConfigFetcher { | ||
|
||
private final WorkspaceApi workspaceApi; | ||
|
||
public WorkspaceNotificationConfigFetcher(WorkspaceApi workspaceApi) { | ||
this.workspaceApi = workspaceApi; | ||
} | ||
|
||
@Value | ||
class NotificationItemWithCustomerIoConfig { | ||
|
||
NotificationItem notificationItem; | ||
CustomerIoEmailConfig customerIoEmailConfig; | ||
|
||
} | ||
|
||
/** | ||
* Fetch corresponding notificationItem based on notification action. | ||
*/ | ||
public NotificationItemWithCustomerIoConfig fetchNotificationConfig(final UUID connectionId, NotificationEvent notificationEvent) { | ||
final WorkspaceRead workspaceRead = AirbyteApiClient.retryWithJitter( | ||
() -> workspaceApi.getWorkspaceByConnectionId(new ConnectionIdRequestBody().connectionId(connectionId)), | ||
"retrieve workspace for notification use.", | ||
/* jitterMaxIntervalSecs= */10, | ||
/* finalInternvalSecs= */10, | ||
/* maxTries= */ 3); | ||
if (workspaceRead == null) { | ||
log.error( | ||
String.format("Unable to fetch workspace by connection %s. Not blocking but we are not sending any notifications. \n", connectionId)); | ||
return new NotificationItemWithCustomerIoConfig(new NotificationItem(), new CustomerIoEmailConfig("")); | ||
} | ||
|
||
NotificationItem item; | ||
|
||
switch (notificationEvent) { | ||
case onBreakingChange -> { | ||
item = workspaceRead.getNotificationSettings().getSendOnConnectionUpdateActionRequired(); | ||
break; | ||
} | ||
case onNonBreakingChange -> { | ||
item = workspaceRead.getNotificationSettings().getSendOnConnectionUpdate(); | ||
break; | ||
} | ||
default -> throw new RuntimeException("Unexpected notification action: " + notificationEvent); | ||
} | ||
|
||
return new NotificationItemWithCustomerIoConfig(item, new CustomerIoEmailConfig(workspaceRead.getEmail())); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ication/src/test/java/io/airbyte/notification/WorkspaceNotificationConfigFetcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.notification; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.airbyte.api.client.generated.WorkspaceApi; | ||
import io.airbyte.api.client.invoker.generated.ApiException; | ||
import io.airbyte.api.client.model.generated.ConnectionIdRequestBody; | ||
import io.airbyte.api.client.model.generated.NotificationItem; | ||
import io.airbyte.api.client.model.generated.NotificationSettings; | ||
import io.airbyte.api.client.model.generated.NotificationType; | ||
import io.airbyte.api.client.model.generated.WorkspaceRead; | ||
import io.airbyte.notification.WorkspaceNotificationConfigFetcher.NotificationItemWithCustomerIoConfig; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class WorkspaceNotificationConfigFetcherTest { | ||
|
||
private final WorkspaceApi workspaceApi = mock(WorkspaceApi.class); | ||
|
||
private final WorkspaceNotificationConfigFetcher workspaceNotificationConfigFetcher = new WorkspaceNotificationConfigFetcher(workspaceApi); | ||
|
||
@Test | ||
void testReturnTheRightConfig() throws ApiException { | ||
final UUID connectionId = UUID.randomUUID(); | ||
final String email = "em@il.com"; | ||
final NotificationItem notificationItem = new NotificationItem().addNotificationTypeItem(NotificationType.CUSTOMERIO); | ||
when(workspaceApi.getWorkspaceByConnectionId(new ConnectionIdRequestBody().connectionId(connectionId))) | ||
.thenReturn( | ||
new WorkspaceRead().email(email).notificationSettings(new NotificationSettings().sendOnConnectionUpdateActionRequired(notificationItem))); | ||
|
||
NotificationItemWithCustomerIoConfig result = | ||
workspaceNotificationConfigFetcher.fetchNotificationConfig(connectionId, NotificationEvent.onBreakingChange); | ||
assertEquals(notificationItem, result.getNotificationItem()); | ||
assertEquals(email, result.getCustomerIoEmailConfig().getTo()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters