Skip to content

Commit db5c519

Browse files
committed
fix: pass migrate and normalize flags to the CDK if set on the manifest (#15961)
## What EDIT: Changing this PR to only set the normalize flag for now, since we want to hold off on the `migrate` flag until we are ready to ship this to all users We need to provide the way to communicate the `Form-Based UI` <> `CDK` to be able to toggle the `normalization` and the `migration` for the given manifest. After the `Form-Based UI` is released to the world and stable - these flags should be removed or set to True at the CDK level for the time being. ## How ## Airbyte-Webapp - set the `__should_normalize` and `__should_migrate` flags by UI to the `manifest` level ## Connector Builder Server - handle the additional flags set by UI to be at the `root` of the requestBody == `config`, to not to introduce `declarative_component_schema.yaml` changes and handle this only in platform. - This code path handles the above: `oss/airbyte-connector-builder-server/src/main/java/io/airbyte/connector_builder/requester/AirbyteCdkRequesterImpl.java` > `adaptConfig` for `ResolveManifest`. ## Can this PR be safely reverted and rolled back? - [X] YES 💚 - [ ] NO ❌
1 parent e4226b8 commit db5c519

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

airbyte-connector-builder-server/src/main/kotlin/io/airbyte/connectorbuilder/requester/AirbyteCdkRequesterImpl.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ class AirbyteCdkRequesterImpl(
232232
): String {
233233
val adaptedConfig = Jsons.deserializeIfText(config).deepCopy<JsonNode>()
234234
(adaptedConfig as ObjectNode).set<JsonNode>(MANIFEST_KEY, Jsons.deserializeIfText(manifest))
235+
236+
moveNormalizeAndMigrateFlagsToConfig(manifest, adaptedConfig)
237+
235238
if (!StringUtils.isBlank(customComponentsCode)) {
236239
adaptedConfig.put(CUSTOM_COMPONENT_KEY, customComponentsCode)
237240
adaptedConfig.set<JsonNode>(CUSTOM_COMPONENT_CHECKSUM_KEY, calculateChecksums(customComponentsCode))
@@ -244,13 +247,16 @@ class AirbyteCdkRequesterImpl(
244247
@Throws(IOException::class)
245248
private fun adaptConfig(
246249
manifest: JsonNode,
247-
customComponentsCode: String,
250+
customComponentsCode: String?,
248251
config: JsonNode,
249252
command: String,
250253
userProvidedStreamLimit: Int?,
251254
): String {
252255
val adaptedConfig = Jsons.deserializeIfText(config).deepCopy<JsonNode>()
253256
(adaptedConfig as ObjectNode).set<JsonNode>(MANIFEST_KEY, Jsons.deserializeIfText(manifest))
257+
258+
moveNormalizeAndMigrateFlagsToConfig(manifest, adaptedConfig)
259+
254260
adaptedConfig.put(COMMAND_KEY, command)
255261
if (!StringUtils.isBlank(customComponentsCode)) {
256262
adaptedConfig.put(CUSTOM_COMPONENT_KEY, customComponentsCode)
@@ -285,6 +291,9 @@ class AirbyteCdkRequesterImpl(
285291
): String {
286292
val adaptedConfig = Jsons.deserializeIfText(config).deepCopy<JsonNode>()
287293
(adaptedConfig as ObjectNode).set<JsonNode>(MANIFEST_KEY, Jsons.deserializeIfText(manifest))
294+
295+
moveNormalizeAndMigrateFlagsToConfig(manifest, adaptedConfig)
296+
288297
adaptedConfig.put(COMMAND_KEY, command)
289298
if (!StringUtils.isBlank(customComponentsCode)) {
290299
adaptedConfig.put(CUSTOM_COMPONENT_KEY, customComponentsCode)
@@ -328,6 +337,29 @@ class AirbyteCdkRequesterImpl(
328337
return OBJECT_WRITER.writeValueAsString(adaptedConfig)
329338
}
330339

340+
private fun moveNormalizeAndMigrateFlagsToConfig(
341+
manifest: JsonNode,
342+
config: JsonNode,
343+
) {
344+
// the hack to include additional flags to control the Form-based UI rendering
345+
346+
// add `__should_normalize: bool` set by UI and remove it from the manifest for the time of the call
347+
if (manifest.has(SHOULD_NORMALIZE_KEY)) {
348+
(config as ObjectNode).set<JsonNode>(SHOULD_NORMALIZE_KEY, manifest.get(SHOULD_NORMALIZE_KEY))
349+
// remove the flag from the manifest JsonNode once it's there
350+
((config as ObjectNode).get(MANIFEST_KEY) as ObjectNode).remove(SHOULD_NORMALIZE_KEY)
351+
}
352+
353+
// add `__should_migrate: bool` set by UI and remove it from the manifest for the time of the call
354+
if (manifest.has(SHOULD_MIGRATE_KEY)) {
355+
(config as ObjectNode).set<JsonNode>(SHOULD_MIGRATE_KEY, manifest.get(SHOULD_MIGRATE_KEY))
356+
// now remove the flag from the manifest JsonNode once it's there
357+
((config as ObjectNode).get(MANIFEST_KEY) as ObjectNode).remove(SHOULD_MIGRATE_KEY)
358+
}
359+
360+
// end of hack
361+
}
362+
331363
private fun <T> convertToList(
332364
`object`: JsonNode,
333365
typeReference: TypeReference<List<T>>,
@@ -354,6 +386,8 @@ class AirbyteCdkRequesterImpl(
354386
private const val RESOLVE_MANIFEST_COMMAND = "resolve_manifest"
355387
private const val FULL_RESOLVED_MANIFEST_COMMAND = "full_resolve_manifest"
356388
private const val STREAM_READ_COMMAND = "test_read"
389+
private const val SHOULD_NORMALIZE_KEY = "__should_normalize"
390+
private const val SHOULD_MIGRATE_KEY = "__should_migrate"
357391
private val CATALOG_TEMPLATE =
358392
"""
359393
{

0 commit comments

Comments
 (0)