-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Platform): update actor configuration when receiving control mes…
…sages from connectors during sync (#19811) * track latest config message * pass new config as part of outputs * persist new config * persist config as the messages come through, dont set output * clean up old implementation * accept control messages for destinations * get api client from micronaut * mask instance-wide oauth params when updating configs * defaultreplicationworker tests * formatting * tests for source/destination handlers * rm todo * refactor test a bit to fix pmd * fix pmd * fix test * add PersistConfigHelperTest * update message tracker comment * fix pmd * format * move ApiClientBeanFactory to commons-worker, use in container-orchestrator * pull out config updating to separate methods * add jitter * rename PersistConfigHelper -> UpdateConnectorConfigHelper, docs * fix exception type * fmt * move message type check into runnable * formatting * pass api client env vars to container orchestrator * pass micronaut envs to container orchestrator * print stacktrace for debugging * different api host for container orchestrator * fix default env var * format * fix errors after merge * set source and destination actor id as part of the sync input * fix: get destination definition * fix null ptr * remove "actor" from naming * fix missing change from rename * revert ContainerOrchestratorConfigBeanFactory changes * inject sourceapi/destinationapi directly rather than airbyteapiclient * UpdateConnectorConfigHelper -> ConnectorConfigUpdater * rm log * fix test * dont fail on config update error * pass id, not full config to runnables/accept control message * add new config required for api client * add test file * fix test compatibility * mount data plane credentials secret to container orchestrator (#20724) * mount data plane credentials secret to container orchestrator * rm copy-pasta * properly handle empty strings * set env vars like before * use the right config vars
- Loading branch information
1 parent
f11d7ff
commit 2a38177
Showing
36 changed files
with
808 additions
and
115 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
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
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
87 changes: 87 additions & 0 deletions
87
airbyte-commons-worker/src/main/java/io/airbyte/workers/helper/ConnectorConfigUpdater.java
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,87 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.helper; | ||
|
||
import com.google.common.hash.Hashing; | ||
import io.airbyte.api.client.AirbyteApiClient; | ||
import io.airbyte.api.client.generated.DestinationApi; | ||
import io.airbyte.api.client.generated.SourceApi; | ||
import io.airbyte.api.client.model.generated.DestinationIdRequestBody; | ||
import io.airbyte.api.client.model.generated.DestinationRead; | ||
import io.airbyte.api.client.model.generated.DestinationUpdate; | ||
import io.airbyte.api.client.model.generated.SourceIdRequestBody; | ||
import io.airbyte.api.client.model.generated.SourceRead; | ||
import io.airbyte.api.client.model.generated.SourceUpdate; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.protocol.models.Config; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.UUID; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Helper class for workers to persist updates to Source/Destination configs emitted from | ||
* AirbyteControlMessages. | ||
* | ||
* This is in order to support connectors updating configs when running commands, which is specially | ||
* useful for migrating configuration to a new version or for enabling connectors that require | ||
* single-use or short-lived OAuth tokens. | ||
*/ | ||
public class ConnectorConfigUpdater { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(ConnectorConfigUpdater.class); | ||
|
||
private final SourceApi sourceApi; | ||
private final DestinationApi destinationApi; | ||
|
||
public ConnectorConfigUpdater(final SourceApi sourceApi, final DestinationApi destinationApi) { | ||
this.sourceApi = sourceApi; | ||
this.destinationApi = destinationApi; | ||
} | ||
|
||
/** | ||
* Updates the Source from a sync job ID with the provided Configuration. Secrets and OAuth | ||
* parameters will be masked when saving. | ||
*/ | ||
public void updateSource(final UUID sourceId, final Config config) { | ||
final SourceRead source = AirbyteApiClient.retryWithJitter( | ||
() -> sourceApi.getSource(new SourceIdRequestBody().sourceId(sourceId)), | ||
"get source"); | ||
|
||
final SourceRead updatedSource = AirbyteApiClient.retryWithJitter( | ||
() -> sourceApi | ||
.updateSource(new SourceUpdate() | ||
.sourceId(sourceId) | ||
.name(source.getName()) | ||
.connectionConfiguration(Jsons.jsonNode(config.getAdditionalProperties()))), | ||
"update source"); | ||
|
||
LOGGER.info("Persisted updated configuration for source {}. New config hash: {}.", sourceId, | ||
Hashing.sha256().hashString(updatedSource.getConnectionConfiguration().asText(), StandardCharsets.UTF_8)); | ||
|
||
} | ||
|
||
/** | ||
* Updates the Destination from a sync job ID with the provided Configuration. Secrets and OAuth | ||
* parameters will be masked when saving. | ||
*/ | ||
public void updateDestination(final UUID destinationId, final Config config) { | ||
final DestinationRead destination = AirbyteApiClient.retryWithJitter( | ||
() -> destinationApi.getDestination(new DestinationIdRequestBody().destinationId(destinationId)), | ||
"get destination"); | ||
|
||
final DestinationRead updatedDestination = AirbyteApiClient.retryWithJitter( | ||
() -> destinationApi | ||
.updateDestination(new DestinationUpdate() | ||
.destinationId(destinationId) | ||
.name(destination.getName()) | ||
.connectionConfiguration(Jsons.jsonNode(config.getAdditionalProperties()))), | ||
"update destination"); | ||
|
||
LOGGER.info("Persisted updated configuration for destination {}. New config hash: {}.", destinationId, | ||
Hashing.sha256().hashString(updatedDestination.getConnectionConfiguration().asText(), StandardCharsets.UTF_8)); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.