Skip to content

Commit

Permalink
remove tryNotification from WorkspaceHandler (#22531)
Browse files Browse the repository at this point in the history
* remove tryNotification from WorkspaceHandler

* rm unused WorkspaceHandler
  • Loading branch information
colesnodgrass committed Feb 7, 2023
1 parent 44d747d commit 2bd8596
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
1 change: 0 additions & 1 deletion airbyte-commons-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ dependencies {
implementation project(':airbyte-metrics:metrics-lib')
implementation project(':airbyte-db:db-lib')
implementation project(":airbyte-json-validation")
implementation project(':airbyte-notification')
implementation project(':airbyte-oauth')
implementation project(':airbyte-protocol:protocol-models')
implementation project(':airbyte-persistence:job-persistence')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import io.airbyte.api.model.generated.ConnectionRead;
import io.airbyte.api.model.generated.DestinationRead;
import io.airbyte.api.model.generated.Geography;
import io.airbyte.api.model.generated.Notification;
import io.airbyte.api.model.generated.NotificationRead;
import io.airbyte.api.model.generated.NotificationRead.StatusEnum;
import io.airbyte.api.model.generated.SlugRequestBody;
import io.airbyte.api.model.generated.SourceRead;
import io.airbyte.api.model.generated.WorkspaceCreate;
Expand All @@ -29,14 +26,12 @@
import io.airbyte.commons.server.converters.ApiPojoConverters;
import io.airbyte.commons.server.converters.NotificationConverter;
import io.airbyte.commons.server.converters.WorkspaceWebhookConfigsConverter;
import io.airbyte.commons.server.errors.IdNotFoundKnownException;
import io.airbyte.commons.server.errors.InternalServerKnownException;
import io.airbyte.commons.server.errors.ValueConflictKnownException;
import io.airbyte.config.StandardWorkspace;
import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.config.persistence.SecretsRepositoryWriter;
import io.airbyte.notification.NotificationClient;
import io.airbyte.validation.json.JsonValidationException;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
Expand Down Expand Up @@ -222,23 +217,6 @@ public WorkspaceRead updateWorkspaceName(final WorkspaceUpdateName workspaceUpda
return buildWorkspaceReadFromId(workspaceId);
}

public NotificationRead tryNotification(final Notification notification) {
try {
final NotificationClient notificationClient = NotificationClient.createNotificationClient(NotificationConverter.toConfig(notification));
final String messageFormat = "Hello World! This is a test from Airbyte to try %s notification settings for sync %s";
final boolean failureNotified = notificationClient.notifyFailure(String.format(messageFormat, notification.getNotificationType(), "failures"));
final boolean successNotified = notificationClient.notifySuccess(String.format(messageFormat, notification.getNotificationType(), "successes"));
if (failureNotified || successNotified) {
return new NotificationRead().status(StatusEnum.SUCCEEDED);
}
} catch (final IllegalArgumentException e) {
throw new IdNotFoundKnownException(e.getMessage(), notification.getNotificationType().name(), e);
} catch (final IOException | InterruptedException e) {
return new NotificationRead().status(StatusEnum.FAILED).message(e.getMessage());
}
return new NotificationRead().status(StatusEnum.FAILED);
}

public void setFeedbackDone(final WorkspaceGiveFeedback workspaceGiveFeedback)
throws JsonValidationException, ConfigNotFoundException, IOException {
configRepository.setFeedback(workspaceGiveFeedback.getWorkspaceId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,48 @@
import io.airbyte.api.generated.NotificationsApi;
import io.airbyte.api.model.generated.Notification;
import io.airbyte.api.model.generated.NotificationRead;
import io.airbyte.commons.server.handlers.WorkspacesHandler;
import io.airbyte.api.model.generated.NotificationRead.StatusEnum;
import io.airbyte.commons.server.converters.NotificationConverter;
import io.airbyte.commons.server.errors.IdNotFoundKnownException;
import io.airbyte.notification.NotificationClient;
import io.micronaut.context.annotation.Requires;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
import java.io.IOException;

@Controller("/api/v1/notifications/try")
@Requires(property = "airbyte.deployment-mode",
value = "OSS")
@Secured(SecurityRule.IS_AUTHENTICATED)
public class NotificationsApiController implements NotificationsApi {

private final WorkspacesHandler workspacesHandler;

public NotificationsApiController(final WorkspacesHandler workspacesHandler) {
this.workspacesHandler = workspacesHandler;
}
public NotificationsApiController() {}

@Post
@Secured({AUTHENTICATED_USER})
@Override
public NotificationRead tryNotificationConfig(@Body final Notification notification) {
return ApiHelper.execute(() -> workspacesHandler.tryNotification(notification));
return ApiHelper.execute(() -> tryNotification(notification));
}

private NotificationRead tryNotification(final Notification notification) {
try {
final NotificationClient notificationClient = NotificationClient.createNotificationClient(NotificationConverter.toConfig(notification));
final String messageFormat = "Hello World! This is a test from Airbyte to try %s notification settings for sync %s";
final boolean failureNotified = notificationClient.notifyFailure(String.format(messageFormat, notification.getNotificationType(), "failures"));
final boolean successNotified = notificationClient.notifySuccess(String.format(messageFormat, notification.getNotificationType(), "successes"));
if (failureNotified || successNotified) {
return new NotificationRead().status(StatusEnum.SUCCEEDED);
}
} catch (final IllegalArgumentException e) {
throw new IdNotFoundKnownException(e.getMessage(), notification.getNotificationType().name(), e);
} catch (final IOException | InterruptedException e) {
return new NotificationRead().status(StatusEnum.FAILED).message(e.getMessage());
}
return new NotificationRead().status(StatusEnum.FAILED);
}

}

0 comments on commit 2bd8596

Please sign in to comment.