-
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.
chore: adds fetching init container for connector operations (#13373)
- Loading branch information
Showing
16 changed files
with
663 additions
and
84 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
47 changes: 47 additions & 0 deletions
47
airbyte-workload-init-container/src/main/kotlin/input/CheckHydrationProcessor.kt
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,47 @@ | ||
package io.airbyte.initContainer.input | ||
|
||
import io.airbyte.initContainer.system.FileClient | ||
import io.airbyte.workers.CheckConnectionInputHydrator | ||
import io.airbyte.workers.models.CheckConnectionInput | ||
import io.airbyte.workers.models.SidecarInput | ||
import io.airbyte.workers.serde.ObjectSerializer | ||
import io.airbyte.workers.serde.PayloadDeserializer | ||
import io.airbyte.workers.sync.OrchestratorConstants | ||
import io.airbyte.workload.api.client.model.generated.Workload | ||
import io.micronaut.context.annotation.Requires | ||
import jakarta.inject.Singleton | ||
|
||
@Requires(property = "airbyte.init.operation", pattern = "check") | ||
@Singleton | ||
class CheckHydrationProcessor( | ||
private val inputHydrator: CheckConnectionInputHydrator, | ||
private val deserializer: PayloadDeserializer, | ||
private val serializer: ObjectSerializer, | ||
private val fileClient: FileClient, | ||
) : InputHydrationProcessor { | ||
override fun process(workload: Workload) { | ||
val rawPayload = workload.inputPayload | ||
val parsed: CheckConnectionInput = deserializer.toCheckConnectionInput(rawPayload) | ||
|
||
val hydrated = inputHydrator.getHydratedStandardCheckInput(parsed.checkConnectionInput) | ||
|
||
fileClient.writeInputFile( | ||
OrchestratorConstants.CONNECTION_CONFIGURATION, | ||
serializer.serialize(hydrated.connectionConfiguration), | ||
) | ||
|
||
fileClient.writeInputFile( | ||
OrchestratorConstants.SIDECAR_INPUT, | ||
serializer.serialize( | ||
SidecarInput( | ||
hydrated, | ||
null, | ||
workload.id, | ||
parsed.launcherConfig, | ||
SidecarInput.OperationType.CHECK, | ||
workload.logPath, | ||
), | ||
), | ||
) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
airbyte-workload-init-container/src/main/kotlin/input/DiscoverHydrationProcessor.kt
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,47 @@ | ||
package io.airbyte.initContainer.input | ||
|
||
import io.airbyte.initContainer.system.FileClient | ||
import io.airbyte.workers.DiscoverCatalogInputHydrator | ||
import io.airbyte.workers.models.DiscoverCatalogInput | ||
import io.airbyte.workers.models.SidecarInput | ||
import io.airbyte.workers.serde.ObjectSerializer | ||
import io.airbyte.workers.serde.PayloadDeserializer | ||
import io.airbyte.workers.sync.OrchestratorConstants | ||
import io.airbyte.workload.api.client.model.generated.Workload | ||
import io.micronaut.context.annotation.Requires | ||
import jakarta.inject.Singleton | ||
|
||
@Requires(property = "airbyte.init.operation", pattern = "discover") | ||
@Singleton | ||
class DiscoverHydrationProcessor( | ||
private val inputHydrator: DiscoverCatalogInputHydrator, | ||
private val deserializer: PayloadDeserializer, | ||
private val serializer: ObjectSerializer, | ||
private val fileClient: FileClient, | ||
) : InputHydrationProcessor { | ||
override fun process(workload: Workload) { | ||
val rawPayload = workload.inputPayload | ||
val parsed: DiscoverCatalogInput = deserializer.toDiscoverCatalogInput(rawPayload) | ||
|
||
val hydrated = inputHydrator.getHydratedStandardDiscoverInput(parsed.discoverCatalogInput) | ||
|
||
fileClient.writeInputFile( | ||
OrchestratorConstants.CONNECTION_CONFIGURATION, | ||
serializer.serialize(hydrated.connectionConfiguration), | ||
) | ||
|
||
fileClient.writeInputFile( | ||
OrchestratorConstants.SIDECAR_INPUT, | ||
serializer.serialize( | ||
SidecarInput( | ||
null, | ||
hydrated, | ||
workload.id, | ||
parsed.launcherConfig, | ||
SidecarInput.OperationType.DISCOVER, | ||
workload.logPath, | ||
), | ||
), | ||
) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
airbyte-workload-init-container/src/main/kotlin/input/SpecHydrationProcessor.kt
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,38 @@ | ||
package io.airbyte.initContainer.input | ||
|
||
import io.airbyte.initContainer.system.FileClient | ||
import io.airbyte.workers.models.SidecarInput | ||
import io.airbyte.workers.models.SpecInput | ||
import io.airbyte.workers.serde.ObjectSerializer | ||
import io.airbyte.workers.serde.PayloadDeserializer | ||
import io.airbyte.workers.sync.OrchestratorConstants | ||
import io.airbyte.workload.api.client.model.generated.Workload | ||
import io.micronaut.context.annotation.Requires | ||
import jakarta.inject.Singleton | ||
|
||
@Requires(property = "airbyte.init.operation", pattern = "spec") | ||
@Singleton | ||
class SpecHydrationProcessor( | ||
private val deserializer: PayloadDeserializer, | ||
private val serializer: ObjectSerializer, | ||
private val fileClient: FileClient, | ||
) : InputHydrationProcessor { | ||
override fun process(workload: Workload) { | ||
val rawPayload = workload.inputPayload | ||
val parsed: SpecInput = deserializer.toSpecInput(rawPayload) | ||
|
||
fileClient.writeInputFile( | ||
OrchestratorConstants.SIDECAR_INPUT, | ||
serializer.serialize( | ||
SidecarInput( | ||
null, | ||
null, | ||
workload.id, | ||
parsed.launcherConfig, | ||
SidecarInput.OperationType.SPEC, | ||
workload.logPath, | ||
), | ||
), | ||
) | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
airbyte-workload-init-container/src/test/kotlin/input/CheckHydrationProcessorTest.kt
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,107 @@ | ||
package io.airbyte.initContainer.input | ||
|
||
import io.airbyte.commons.json.Jsons | ||
import io.airbyte.config.StandardCheckConnectionInput | ||
import io.airbyte.initContainer.system.FileClient | ||
import io.airbyte.persistence.job.models.IntegrationLauncherConfig | ||
import io.airbyte.workers.CheckConnectionInputHydrator | ||
import io.airbyte.workers.models.CheckConnectionInput | ||
import io.airbyte.workers.models.SidecarInput | ||
import io.airbyte.workers.serde.ObjectSerializer | ||
import io.airbyte.workers.serde.PayloadDeserializer | ||
import io.airbyte.workers.sync.OrchestratorConstants | ||
import io.airbyte.workload.api.client.model.generated.Workload | ||
import io.airbyte.workload.api.client.model.generated.WorkloadType | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.util.UUID | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class CheckHydrationProcessorTest { | ||
@MockK | ||
lateinit var inputHydrator: CheckConnectionInputHydrator | ||
|
||
@MockK | ||
lateinit var serializer: ObjectSerializer | ||
|
||
@MockK | ||
lateinit var deserializer: PayloadDeserializer | ||
|
||
@MockK | ||
lateinit var fileClient: FileClient | ||
|
||
private lateinit var processor: CheckHydrationProcessor | ||
|
||
@BeforeEach | ||
fun setup() { | ||
processor = | ||
CheckHydrationProcessor( | ||
inputHydrator, | ||
deserializer, | ||
serializer, | ||
fileClient, | ||
) | ||
} | ||
|
||
@Test | ||
fun `parses input, hydrates and writes output to expected file`() { | ||
val input = Fixtures.workload | ||
|
||
val unhydrated = StandardCheckConnectionInput() | ||
val parsed = CheckConnectionInput() | ||
parsed.checkConnectionInput = unhydrated | ||
parsed.launcherConfig = IntegrationLauncherConfig() | ||
|
||
val connectionConfiguration = Jsons.jsonNode(mapOf("key-1" to "value-1")) | ||
val hydrated = StandardCheckConnectionInput() | ||
hydrated.connectionConfiguration = connectionConfiguration | ||
val serializedConfig = "serialized hydrated config" | ||
val serializedInput = "serialized hydrated blob" | ||
|
||
val sidecarInput = | ||
SidecarInput( | ||
hydrated, | ||
null, | ||
input.id, | ||
parsed.launcherConfig, | ||
SidecarInput.OperationType.CHECK, | ||
input.logPath, | ||
) | ||
|
||
every { deserializer.toCheckConnectionInput(input.inputPayload) } returns parsed | ||
every { inputHydrator.getHydratedStandardCheckInput(unhydrated) } returns hydrated | ||
every { serializer.serialize(connectionConfiguration) } returns serializedConfig | ||
every { serializer.serialize(sidecarInput) } returns serializedInput | ||
every { fileClient.writeInputFile(OrchestratorConstants.CONNECTION_CONFIGURATION, serializedConfig) } returns Unit | ||
every { fileClient.writeInputFile(OrchestratorConstants.SIDECAR_INPUT, serializedInput) } returns Unit | ||
|
||
processor.process(input) | ||
|
||
verify { deserializer.toCheckConnectionInput(input.inputPayload) } | ||
verify { inputHydrator.getHydratedStandardCheckInput(unhydrated) } | ||
verify { serializer.serialize(connectionConfiguration) } | ||
verify { serializer.serialize(sidecarInput) } | ||
verify { fileClient.writeInputFile(OrchestratorConstants.CONNECTION_CONFIGURATION, serializedConfig) } | ||
verify { fileClient.writeInputFile(OrchestratorConstants.SIDECAR_INPUT, serializedInput) } | ||
} | ||
|
||
object Fixtures { | ||
private const val WORKLOAD_ID = "workload-id-14" | ||
|
||
val workload = | ||
Workload( | ||
WORKLOAD_ID, | ||
listOf(), | ||
"inputPayload", | ||
"logPath", | ||
"geography", | ||
WorkloadType.CHECK, | ||
UUID.randomUUID(), | ||
) | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
airbyte-workload-init-container/src/test/kotlin/input/DiscoverHydrationProcessorTest.kt
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,107 @@ | ||
package io.airbyte.initContainer.input | ||
|
||
import io.airbyte.commons.json.Jsons | ||
import io.airbyte.config.StandardDiscoverCatalogInput | ||
import io.airbyte.initContainer.system.FileClient | ||
import io.airbyte.persistence.job.models.IntegrationLauncherConfig | ||
import io.airbyte.workers.DiscoverCatalogInputHydrator | ||
import io.airbyte.workers.models.DiscoverCatalogInput | ||
import io.airbyte.workers.models.SidecarInput | ||
import io.airbyte.workers.serde.ObjectSerializer | ||
import io.airbyte.workers.serde.PayloadDeserializer | ||
import io.airbyte.workers.sync.OrchestratorConstants | ||
import io.airbyte.workload.api.client.model.generated.Workload | ||
import io.airbyte.workload.api.client.model.generated.WorkloadType | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import io.mockk.junit5.MockKExtension | ||
import io.mockk.verify | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.util.UUID | ||
|
||
@ExtendWith(MockKExtension::class) | ||
class DiscoverHydrationProcessorTest { | ||
@MockK | ||
lateinit var inputHydrator: DiscoverCatalogInputHydrator | ||
|
||
@MockK | ||
lateinit var serializer: ObjectSerializer | ||
|
||
@MockK | ||
lateinit var deserializer: PayloadDeserializer | ||
|
||
@MockK | ||
lateinit var fileClient: FileClient | ||
|
||
private lateinit var processor: DiscoverHydrationProcessor | ||
|
||
@BeforeEach | ||
fun setup() { | ||
processor = | ||
DiscoverHydrationProcessor( | ||
inputHydrator, | ||
deserializer, | ||
serializer, | ||
fileClient, | ||
) | ||
} | ||
|
||
@Test | ||
fun `parses input, hydrates and writes output to expected file`() { | ||
val input = Fixtures.workload | ||
|
||
val unhydrated = StandardDiscoverCatalogInput() | ||
val parsed = DiscoverCatalogInput() | ||
parsed.discoverCatalogInput = unhydrated | ||
parsed.launcherConfig = IntegrationLauncherConfig() | ||
|
||
val connectionConfiguration = Jsons.jsonNode(mapOf("key-1" to "value-1")) | ||
val hydrated = StandardDiscoverCatalogInput() | ||
hydrated.connectionConfiguration = connectionConfiguration | ||
val serializedConfig = "serialized hydrated config" | ||
val serializedInput = "serialized hydrated blob" | ||
|
||
val sidecarInput = | ||
SidecarInput( | ||
null, | ||
hydrated, | ||
input.id, | ||
parsed.launcherConfig, | ||
SidecarInput.OperationType.DISCOVER, | ||
input.logPath, | ||
) | ||
|
||
every { deserializer.toDiscoverCatalogInput(input.inputPayload) } returns parsed | ||
every { inputHydrator.getHydratedStandardDiscoverInput(unhydrated) } returns hydrated | ||
every { serializer.serialize(connectionConfiguration) } returns serializedConfig | ||
every { serializer.serialize(sidecarInput) } returns serializedInput | ||
every { fileClient.writeInputFile(OrchestratorConstants.CONNECTION_CONFIGURATION, serializedConfig) } returns Unit | ||
every { fileClient.writeInputFile(OrchestratorConstants.SIDECAR_INPUT, serializedInput) } returns Unit | ||
|
||
processor.process(input) | ||
|
||
verify { deserializer.toDiscoverCatalogInput(input.inputPayload) } | ||
verify { inputHydrator.getHydratedStandardDiscoverInput(unhydrated) } | ||
verify { serializer.serialize(connectionConfiguration) } | ||
verify { serializer.serialize(sidecarInput) } | ||
verify { fileClient.writeInputFile(OrchestratorConstants.CONNECTION_CONFIGURATION, serializedConfig) } | ||
verify { fileClient.writeInputFile(OrchestratorConstants.SIDECAR_INPUT, serializedInput) } | ||
} | ||
|
||
object Fixtures { | ||
private const val WORKLOAD_ID = "workload-id-15" | ||
|
||
val workload = | ||
Workload( | ||
WORKLOAD_ID, | ||
listOf(), | ||
"inputPayload", | ||
"logPath", | ||
"geography", | ||
WorkloadType.DISCOVER, | ||
UUID.randomUUID(), | ||
) | ||
} | ||
} |
Oops, something went wrong.