Skip to content

Commit

Permalink
feat: use manifest CDK version instead of platform CDK verison for bu…
Browse files Browse the repository at this point in the history
…ilder connectors (#12443)
  • Loading branch information
Ella Rohm-Ensing committed May 14, 2024
1 parent 4da36db commit 7d10146
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public DefaultPostLoadExecutor(final ApplyDefinitionsHelper applyDefinitionsHelp
@Override
public void execute() throws Exception {
applyDefinitionsHelper.apply();
declarativeSourceUpdater.apply();
// TODO (ella): Temporarily disabled until semver upgrading is implemented
// declarativeSourceUpdater.apply();

log.info("Loaded seed data.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.SourceType;
import io.airbyte.config.SupportLevel;
import io.airbyte.config.init.CdkVersionProvider;
import io.airbyte.config.secrets.JsonSecretsProcessor;
import io.airbyte.config.secrets.SecretsRepositoryReader;
import io.airbyte.config.secrets.SecretsRepositoryWriter;
Expand Down Expand Up @@ -82,7 +81,6 @@ public class ConnectorBuilderProjectsHandler {
private final BuilderProjectUpdater buildProjectUpdater;
private final Supplier<UUID> uuidSupplier;
private final DeclarativeSourceManifestInjector manifestInjector;
private final CdkVersionProvider cdkVersionProvider;
private final WorkspaceService workspaceService;
private final FeatureFlagClient featureFlagClient;
private final SecretsRepositoryReader secretsRepositoryReader;
Expand All @@ -98,7 +96,6 @@ public class ConnectorBuilderProjectsHandler {
@Inject
public ConnectorBuilderProjectsHandler(final ConnectorBuilderService connectorBuilderService,
final BuilderProjectUpdater builderProjectUpdater,
final CdkVersionProvider cdkVersionProvider,
@Named("uuidGenerator") final Supplier<UUID> uuidSupplier,
final DeclarativeSourceManifestInjector manifestInjector,
final WorkspaceService workspaceService,
Expand All @@ -111,7 +108,6 @@ public ConnectorBuilderProjectsHandler(final ConnectorBuilderService connectorBu
final ConnectorBuilderServerApi connectorBuilderServerApiClient) {
this.connectorBuilderService = connectorBuilderService;
this.buildProjectUpdater = builderProjectUpdater;
this.cdkVersionProvider = cdkVersionProvider;
this.uuidSupplier = uuidSupplier;
this.manifestInjector = manifestInjector;
this.workspaceService = workspaceService;
Expand Down Expand Up @@ -283,7 +279,7 @@ private UUID createActorDefinition(final String name, final UUID workspaceId, fi

final ActorDefinitionVersion defaultVersion = new ActorDefinitionVersion()
.withActorDefinitionId(actorDefinitionId)
.withDockerImageTag(cdkVersionProvider.getCdkVersion())
.withDockerImageTag(manifestInjector.getCdkVersion(manifest))
.withDockerRepository("airbyte/source-declarative-manifest")
.withSpec(connectorSpecification)
.withProtocolVersion(DEFAULT_AIRBYTE_PROTOCOL_VERSION.serialize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void createDeclarativeSourceDefinitionManifest(final DeclarativeSourceDef
.withSpec(spec);
if (requestBody.getSetAsActiveManifest()) {
connectorBuilderService.createDeclarativeManifestAsActiveVersion(declarativeManifest,
manifestInjector.createConfigInjection(requestBody.getSourceDefinitionId(), requestBody.getDeclarativeManifest().getManifest()),
manifestInjector.createDeclarativeManifestConnectorSpecification(spec));
manifestInjector.createConfigInjection(requestBody.getSourceDefinitionId(), declarativeManifest.getManifest()),
manifestInjector.createDeclarativeManifestConnectorSpecification(spec), manifestInjector.getCdkVersion(declarativeManifest.getManifest()));
} else {
connectorBuilderService.insertDeclarativeManifest(declarativeManifest);
}
Expand All @@ -90,7 +90,8 @@ public void updateDeclarativeManifestVersion(final UpdateActiveManifestRequestBo
connectorBuilderService.setDeclarativeSourceActiveVersion(requestBody.getSourceDefinitionId(),
declarativeManifest.getVersion(),
manifestInjector.createConfigInjection(declarativeManifest.getActorDefinitionId(), declarativeManifest.getManifest()),
manifestInjector.createDeclarativeManifestConnectorSpecification(declarativeManifest.getSpec()));
manifestInjector.createDeclarativeManifestConnectorSpecification(declarativeManifest.getSpec()),
manifestInjector.getCdkVersion(declarativeManifest.getManifest()));
}

private Collection<Long> fetchAvailableManifestVersions(final UUID sourceDefinitionId) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,14 @@ public ConnectorSpecification createDeclarativeManifestConnectorSpecification(fi
.withConnectionSpecification(declarativeManifestSpec.get("connectionSpecification"));
}

/**
* Get the CDK version form the manifest.
*
* @param manifest to extract the CDK version from
* @return the CDK version
*/
public String getCdkVersion(final JsonNode manifest) {
return manifest.get("version").asText();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.SourceType;
import io.airbyte.config.SupportLevel;
import io.airbyte.config.init.CdkVersionProvider;
import io.airbyte.config.secrets.JsonSecretsProcessor;
import io.airbyte.config.secrets.SecretsRepositoryReader;
import io.airbyte.config.secrets.SecretsRepositoryWriter;
Expand Down Expand Up @@ -94,14 +93,14 @@ class ConnectorBuilderProjectsHandlerTest {
private static final UUID A_WORKSPACE_ID = UUID.randomUUID();
private static final Long A_VERSION = 32L;
private static final Long ACTIVE_MANIFEST_VERSION = 865L;
private static final String A_CDK_VERSION = "0.79.0";
private static final String A_DESCRIPTION = "a description";
private static final String A_SOURCE_NAME = "a source name";
private static final String A_NAME = "a name";
private static final String A_DOCUMENTATION_URL = "http://documentation.url";
private static final JsonNode A_MANIFEST;
private static final JsonNode A_SPEC;
private static final ActorDefinitionConfigInjection A_CONFIG_INJECTION = new ActorDefinitionConfigInjection().withInjectionPath("something");
private static final String CDK_VERSION = "8.9.10";

static {
try {
Expand All @@ -117,7 +116,6 @@ class ConnectorBuilderProjectsHandlerTest {
private ConnectorBuilderProjectsHandler connectorBuilderProjectsHandler;
private Supplier<UUID> uuidSupplier;
private DeclarativeSourceManifestInjector manifestInjector;
private CdkVersionProvider cdkVersionProvider;
private WorkspaceService workspaceService;
private FeatureFlagClient featureFlagClient;
private SecretsRepositoryReader secretsRepositoryReader;
Expand Down Expand Up @@ -171,7 +169,6 @@ void setUp() throws JsonProcessingException {
builderProjectUpdater = mock(BuilderProjectUpdater.class);
uuidSupplier = mock(Supplier.class);
manifestInjector = mock(DeclarativeSourceManifestInjector.class);
cdkVersionProvider = mock(CdkVersionProvider.class);
workspaceService = mock(WorkspaceService.class);
featureFlagClient = mock(TestClient.class);
secretsRepositoryReader = mock(SecretsRepositoryReader.class);
Expand All @@ -180,19 +177,18 @@ void setUp() throws JsonProcessingException {
sourceService = mock(SourceService.class);
secretsProcessor = mock(JsonSecretsProcessor.class);
connectorBuilderServerApiClient = mock(ConnectorBuilderServerApi.class);
when(cdkVersionProvider.getCdkVersion()).thenReturn(CDK_VERSION);
adaptedConnectorSpecification = mock(ConnectorSpecification.class);
setupConnectorSpecificationAdapter(any(), "");
workspaceId = UUID.randomUUID();

connectorBuilderProjectsHandler =
new ConnectorBuilderProjectsHandler(connectorBuilderService, builderProjectUpdater, cdkVersionProvider, uuidSupplier, manifestInjector,
new ConnectorBuilderProjectsHandler(connectorBuilderService, builderProjectUpdater, uuidSupplier, manifestInjector,
workspaceService, featureFlagClient,
secretsRepositoryReader, secretsRepositoryWriter, secretPersistenceConfigService, sourceService, secretsProcessor,
connectorBuilderServerApiClient);
}

private ConnectorBuilderProject generateBuilderProject() throws JsonProcessingException {
private ConnectorBuilderProject generateBuilderProject() {
final UUID projectId = UUID.randomUUID();
return new ConnectorBuilderProject().withBuilderProjectId(projectId).withWorkspaceId(workspaceId).withName("Test project")
.withHasDraft(true).withManifestDraft(draftManifest);
Expand Down Expand Up @@ -466,6 +462,7 @@ void whenPublishConnectorBuilderProjectThenReturnActorDefinition() throws IOExce
void whenPublishConnectorBuilderProjectThenCreateActorDefinition() throws IOException {
when(uuidSupplier.get()).thenReturn(A_SOURCE_DEFINITION_ID);
when(manifestInjector.createConfigInjection(A_SOURCE_DEFINITION_ID, A_MANIFEST)).thenReturn(A_CONFIG_INJECTION);
when(manifestInjector.getCdkVersion(A_MANIFEST)).thenReturn(A_CDK_VERSION);
setupConnectorSpecificationAdapter(A_SPEC, A_DOCUMENTATION_URL);

connectorBuilderProjectsHandler.publishConnectorBuilderProject(anyConnectorBuilderProjectRequest().workspaceId(workspaceId).name(A_SOURCE_NAME)
Expand All @@ -482,7 +479,7 @@ void whenPublishConnectorBuilderProjectThenCreateActorDefinition() throws IOExce
new ActorDefinitionVersion()
.withActorDefinitionId(A_SOURCE_DEFINITION_ID)
.withDockerRepository("airbyte/source-declarative-manifest")
.withDockerImageTag(CDK_VERSION)
.withDockerImageTag(A_CDK_VERSION)
.withSpec(adaptedConnectorSpecification)
.withSupportLevel(SupportLevel.NONE)
.withReleaseStage(ReleaseStage.CUSTOM)
Expand Down Expand Up @@ -716,10 +713,6 @@ private static DeclarativeSourceManifest anyInitialManifest() {
return new DeclarativeSourceManifest().version(A_VERSION);
}

private static ConnectorBuilderProject anyBuilderProject() {
return new ConnectorBuilderProject();
}

private void setupConnectorSpecificationAdapter(final JsonNode spec, final String documentationUrl) {
when(manifestInjector.createDeclarativeManifestConnectorSpecification(spec)).thenReturn(adaptedConnectorSpecification);
when(adaptedConnectorSpecification.getDocumentationUrl()).thenReturn(URI.create(documentationUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -49,6 +50,7 @@ class DeclarativeSourceDefinitionsHandlerTest {
private static final Long A_VERSION = 32L;
private static final Long ANOTHER_VERSION = 99L;
private static final String A_DESCRIPTION = "a description";
private static final String A_CDK_VERSION = "0.70.0";
private static final JsonNode A_MANIFEST;
private static final JsonNode A_SPEC;

Expand Down Expand Up @@ -116,21 +118,24 @@ void givenSetAsActiveWhenCreateDeclarativeSourceDefinitionManifestThenCreateDecl
givenSourceIsDeclarative();
when(manifestInjector.createDeclarativeManifestConnectorSpecification(A_SPEC)).thenReturn(adaptedConnectorSpecification);
when(manifestInjector.createConfigInjection(A_SOURCE_DEFINITION_ID, A_MANIFEST)).thenReturn(configInjection);
when(manifestInjector.getCdkVersion(A_MANIFEST)).thenReturn(A_CDK_VERSION);

handler.createDeclarativeSourceDefinitionManifest(new DeclarativeSourceDefinitionCreateManifestRequestBody()
.sourceDefinitionId(A_SOURCE_DEFINITION_ID)
.setAsActiveManifest(true)
.declarativeManifest(anyDeclarativeManifest().manifest(A_MANIFEST).spec(A_SPEC).version(A_VERSION).description(A_DESCRIPTION)));

verify(manifestInjector, times(1)).addInjectedDeclarativeManifest(A_SPEC);
verify(manifestInjector, times(1)).getCdkVersion(A_MANIFEST);
verify(connectorBuilderService, times(1)).createDeclarativeManifestAsActiveVersion(eq(new DeclarativeManifest()
.withActorDefinitionId(A_SOURCE_DEFINITION_ID)
.withVersion(A_VERSION)
.withDescription(A_DESCRIPTION)
.withManifest(A_MANIFEST)
.withSpec(A_SPEC)),
eq(configInjection),
eq(adaptedConnectorSpecification));
eq(adaptedConnectorSpecification),
eq(A_CDK_VERSION));
}

@Test
Expand All @@ -149,7 +154,8 @@ void givenNotSetAsActiveWhenCreateDeclarativeSourceDefinitionManifestThenCreateD
.withDescription(A_DESCRIPTION)
.withManifest(A_MANIFEST)
.withSpec(A_SPEC)));
verify(connectorBuilderService, times(0)).createDeclarativeManifestAsActiveVersion(any(), any(), any());
verify(manifestInjector, never()).getCdkVersion(any());
verify(connectorBuilderService, times(0)).createDeclarativeManifestAsActiveVersion(any(), any(), any(), any());
}

@Test
Expand Down Expand Up @@ -204,12 +210,14 @@ void whenUpdateDeclarativeManifestVersionThenSetDeclarativeSourceActiveVersion()
.withSpec(A_SPEC));
when(manifestInjector.createConfigInjection(A_SOURCE_DEFINITION_ID, A_MANIFEST)).thenReturn(configInjection);
when(manifestInjector.createDeclarativeManifestConnectorSpecification(A_SPEC)).thenReturn(adaptedConnectorSpecification);
when(manifestInjector.getCdkVersion(A_MANIFEST)).thenReturn(A_CDK_VERSION);

handler.updateDeclarativeManifestVersion(
new UpdateActiveManifestRequestBody().sourceDefinitionId(A_SOURCE_DEFINITION_ID).workspaceId(A_WORKSPACE_ID).version(A_VERSION));

verify(manifestInjector, times(1)).getCdkVersion(A_MANIFEST);
verify(connectorBuilderService, times(1)).setDeclarativeSourceActiveVersion(A_SOURCE_DEFINITION_ID, A_VERSION, configInjection,
adaptedConnectorSpecification);
adaptedConnectorSpecification, A_CDK_VERSION);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DeclarativeSourceManifestInjectorTest {
try {
A_SPEC = new ObjectMapper().readTree(
"{\"connectionSpecification\":{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"required\":[],\"properties\":{},\"additionalProperties\":true}}\n");
A_MANIFEST = new ObjectMapper().readTree("{\"manifest_key\": \"manifest value\"}");
A_MANIFEST = new ObjectMapper().readTree("{\"manifest_key\": \"manifest value\", \"version\": \"1.0.0\"}");
} catch (final JsonProcessingException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -77,6 +77,11 @@ void givenDocumentationUrlWhenAdaptDeclarativeManifestThenReturnConnectorSpecifi
assertEquals(DOCUMENTATION_URL, connectorSpecification.getDocumentationUrl());
}

@Test
void testGetCdkVersion() {
assertEquals("1.0.0", injector.getCdkVersion(A_MANIFEST));
}

private JsonNode givenSpecWithDocumentationUrl(final URI documentationUrl) {
final JsonNode spec = A_SPEC.deepCopy();
((ObjectNode) spec).put("documentationUrl", documentationUrl.toString());
Expand Down
Loading

0 comments on commit 7d10146

Please sign in to comment.