Skip to content

Commit

Permalink
use api handlers in WebBackendCheckUpdatesHandler (#7206)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroslopez committed Jun 20, 2023
1 parent e922b81 commit 00ffe5e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.airbyte.commons.server.services.AirbyteRemoteOssCatalog;
import io.airbyte.config.ConnectorRegistryDestinationDefinition;
import io.airbyte.config.ConnectorRegistrySourceDefinition;
import io.airbyte.config.persistence.ConfigRepository;
import jakarta.inject.Singleton;
import java.io.IOException;
import java.util.List;
Expand All @@ -32,13 +31,15 @@ public class WebBackendCheckUpdatesHandler {

private static final int NO_CHANGES_FOUND = 0;

// todo (cgardens) - this handler should NOT have access to the db. only access via handler.
@Deprecated
final ConfigRepository configRepositoryDoNotUse;
final SourceDefinitionsHandler sourceDefinitionsHandler;
final DestinationDefinitionsHandler destinationDefinitionsHandler;
final AirbyteRemoteOssCatalog remoteOssCatalog;

public WebBackendCheckUpdatesHandler(final ConfigRepository configRepositoryDoNotUse, final AirbyteRemoteOssCatalog remoteOssCatalog) {
this.configRepositoryDoNotUse = configRepositoryDoNotUse;
public WebBackendCheckUpdatesHandler(final SourceDefinitionsHandler sourceDefinitionsHandler,
final DestinationDefinitionsHandler destinationDefinitionsHandler,
final AirbyteRemoteOssCatalog remoteOssCatalog) {
this.sourceDefinitionsHandler = sourceDefinitionsHandler;
this.destinationDefinitionsHandler = destinationDefinitionsHandler;
this.remoteOssCatalog = remoteOssCatalog;
}

Expand All @@ -57,7 +58,7 @@ private int getDestinationDiffCount() {
final Map<UUID, String> newActorDefToDockerImageTag;

try {
currentActorDefToDockerImageTag = configRepositoryDoNotUse.listStandardDestinationDefinitions(false)
currentActorDefToDockerImageTag = destinationDefinitionsHandler.listDestinationDefinitions().getDestinationDefinitions()
.stream()
.map(def -> Map.entry(def.getDestinationDefinitionId(), def.getDockerImageTag()))
.toList();
Expand All @@ -79,7 +80,7 @@ private int getSourceDiffCount() {
final Map<UUID, String> newActorDefToDockerImageTag;

try {
currentActorDefToDockerImageTag = configRepositoryDoNotUse.listStandardSourceDefinitions(false)
currentActorDefToDockerImageTag = sourceDefinitionsHandler.listSourceDefinitions().getSourceDefinitions()
.stream()
.map(def -> Map.entry(def.getSourceDefinitionId(), def.getDockerImageTag()))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.airbyte.api.model.generated.DestinationDefinitionRead;
import io.airbyte.api.model.generated.DestinationDefinitionReadList;
import io.airbyte.api.model.generated.SourceDefinitionRead;
import io.airbyte.api.model.generated.SourceDefinitionReadList;
import io.airbyte.api.model.generated.WebBackendCheckUpdatesRead;
import io.airbyte.commons.server.services.AirbyteRemoteOssCatalog;
import io.airbyte.config.ConnectorRegistryDestinationDefinition;
import io.airbyte.config.ConnectorRegistrySourceDefinition;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.persistence.ConfigRepository;
import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand All @@ -25,17 +26,17 @@

class WebBackendCheckUpdatesHandlerTest {

ConfigRepository configRepository;
SourceDefinitionsHandler sourceDefinitionsHandler;
DestinationDefinitionsHandler destinationDefinitionsHandler;
AirbyteRemoteOssCatalog remoteOssCatalog;
WebBackendCheckUpdatesHandler webBackendCheckUpdatesHandler;

static final boolean INCLUDE_TOMBSTONE = false;

@BeforeEach
void beforeEach() {
configRepository = mock(ConfigRepository.class);
sourceDefinitionsHandler = mock(SourceDefinitionsHandler.class);
destinationDefinitionsHandler = mock(DestinationDefinitionsHandler.class);
remoteOssCatalog = mock(AirbyteRemoteOssCatalog.class);
webBackendCheckUpdatesHandler = new WebBackendCheckUpdatesHandler(configRepository, remoteOssCatalog);
webBackendCheckUpdatesHandler = new WebBackendCheckUpdatesHandler(sourceDefinitionsHandler, destinationDefinitionsHandler, remoteOssCatalog);
}

@Test
Expand Down Expand Up @@ -110,7 +111,7 @@ void testCheckWithMissingActorDefFromLatest() throws IOException, InterruptedExc
@Test
void testCheckErrorNoCurrentDestinations() throws IOException, InterruptedException {
setMocksForExceptionCases();
when(configRepository.listStandardDestinationDefinitions(INCLUDE_TOMBSTONE)).thenThrow(new IOException("unable to read current destinations"));
when(destinationDefinitionsHandler.listDestinationDefinitions()).thenThrow(new IOException("unable to read current destinations"));

final WebBackendCheckUpdatesRead actual = webBackendCheckUpdatesHandler.checkUpdates();

Expand All @@ -120,7 +121,7 @@ void testCheckErrorNoCurrentDestinations() throws IOException, InterruptedExcept
@Test
void testCheckErrorNoCurrentSources() throws IOException, InterruptedException {
setMocksForExceptionCases();
when(configRepository.listStandardSourceDefinitions(INCLUDE_TOMBSTONE)).thenThrow(new IOException("unable to read current sources"));
when(sourceDefinitionsHandler.listSourceDefinitions()).thenThrow(new IOException("unable to read current sources"));

final WebBackendCheckUpdatesRead actual = webBackendCheckUpdatesHandler.checkUpdates();

Expand All @@ -146,13 +147,14 @@ private void setMocks(final List<Entry<UUID, String>> currentSources,
final List<Entry<UUID, String>> currentDestinations,
final List<Entry<UUID, String>> latestDestinations)
throws IOException, InterruptedException {
when(configRepository.listStandardSourceDefinitions(INCLUDE_TOMBSTONE))
.thenReturn(currentSources.stream().map(this::createSourceDef).toList());
when(sourceDefinitionsHandler.listSourceDefinitions())
.thenReturn(new SourceDefinitionReadList().sourceDefinitions(currentSources.stream().map(this::createSourceDef).toList()));
when(remoteOssCatalog.getSourceDefinitions())
.thenReturn(latestSources.stream().map(this::createRegistrySourceDef).toList());

when(configRepository.listStandardDestinationDefinitions(INCLUDE_TOMBSTONE))
.thenReturn(currentDestinations.stream().map(this::createDestinationDef).toList());
when(destinationDefinitionsHandler.listDestinationDefinitions())
.thenReturn(
new DestinationDefinitionReadList().destinationDefinitions(currentDestinations.stream().map(this::createDestinationDef).toList()));
when(remoteOssCatalog.getDestinationDefinitions())
.thenReturn(latestDestinations.stream().map(this::createRegistryDestinationDef).toList());
}
Expand All @@ -163,10 +165,10 @@ private ConnectorRegistryDestinationDefinition createRegistryDestinationDef(fina
.withDockerImageTag(idImageTagEntry.getValue());
}

private StandardDestinationDefinition createDestinationDef(final Entry<UUID, String> idImageTagEntry) {
return new StandardDestinationDefinition()
.withDestinationDefinitionId(idImageTagEntry.getKey())
.withDockerImageTag(idImageTagEntry.getValue());
private DestinationDefinitionRead createDestinationDef(final Entry<UUID, String> idImageTagEntry) {
return new DestinationDefinitionRead()
.destinationDefinitionId(idImageTagEntry.getKey())
.dockerImageTag(idImageTagEntry.getValue());
}

private ConnectorRegistrySourceDefinition createRegistrySourceDef(final Entry<UUID, String> idImageTagEntry) {
Expand All @@ -175,10 +177,10 @@ private ConnectorRegistrySourceDefinition createRegistrySourceDef(final Entry<UU
.withDockerImageTag(idImageTagEntry.getValue());
}

private StandardSourceDefinition createSourceDef(final Entry<UUID, String> idImageTagEntry) {
return new StandardSourceDefinition()
.withSourceDefinitionId(idImageTagEntry.getKey())
.withDockerImageTag(idImageTagEntry.getValue());
private SourceDefinitionRead createSourceDef(final Entry<UUID, String> idImageTagEntry) {
return new SourceDefinitionRead()
.sourceDefinitionId(idImageTagEntry.getKey())
.dockerImageTag(idImageTagEntry.getValue());
}

}

0 comments on commit 00ffe5e

Please sign in to comment.