forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor the catalog discovery workflow (airbytehq#7350)
* refactor the catalog discovery workflow * Format
- Loading branch information
1 parent
61e07fb
commit f241642
Showing
8 changed files
with
151 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
112 changes: 0 additions & 112 deletions
112
airbyte-workers/src/main/java/io/airbyte/workers/temporal/DiscoverCatalogWorkflow.java
This file was deleted.
Oops, something went wrong.
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
22 changes: 22 additions & 0 deletions
22
...s/src/main/java/io/airbyte/workers/temporal/discover/catalog/DiscoverCatalogActivity.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,22 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.temporal.discover.catalog; | ||
|
||
import io.airbyte.config.StandardDiscoverCatalogInput; | ||
import io.airbyte.protocol.models.AirbyteCatalog; | ||
import io.airbyte.scheduler.models.IntegrationLauncherConfig; | ||
import io.airbyte.scheduler.models.JobRunConfig; | ||
import io.temporal.activity.ActivityInterface; | ||
import io.temporal.activity.ActivityMethod; | ||
|
||
@ActivityInterface | ||
public interface DiscoverCatalogActivity { | ||
|
||
@ActivityMethod | ||
AirbyteCatalog run(JobRunConfig jobRunConfig, | ||
IntegrationLauncherConfig launcherConfig, | ||
StandardDiscoverCatalogInput config); | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...c/main/java/io/airbyte/workers/temporal/discover/catalog/DiscoverCatalogActivityImpl.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,70 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.temporal.discover.catalog; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.commons.functional.CheckedSupplier; | ||
import io.airbyte.config.StandardDiscoverCatalogInput; | ||
import io.airbyte.config.persistence.split_secrets.SecretsHydrator; | ||
import io.airbyte.protocol.models.AirbyteCatalog; | ||
import io.airbyte.scheduler.models.IntegrationLauncherConfig; | ||
import io.airbyte.scheduler.models.JobRunConfig; | ||
import io.airbyte.workers.DefaultDiscoverCatalogWorker; | ||
import io.airbyte.workers.Worker; | ||
import io.airbyte.workers.WorkerUtils; | ||
import io.airbyte.workers.process.AirbyteIntegrationLauncher; | ||
import io.airbyte.workers.process.IntegrationLauncher; | ||
import io.airbyte.workers.process.ProcessFactory; | ||
import io.airbyte.workers.protocols.airbyte.AirbyteStreamFactory; | ||
import io.airbyte.workers.protocols.airbyte.DefaultAirbyteStreamFactory; | ||
import io.airbyte.workers.temporal.CancellationHandler; | ||
import io.airbyte.workers.temporal.TemporalAttemptExecution; | ||
import java.nio.file.Path; | ||
import java.util.function.Supplier; | ||
|
||
public class DiscoverCatalogActivityImpl implements DiscoverCatalogActivity { | ||
|
||
private final ProcessFactory processFactory; | ||
private final SecretsHydrator secretsHydrator; | ||
private final Path workspaceRoot; | ||
|
||
public DiscoverCatalogActivityImpl(final ProcessFactory processFactory, final SecretsHydrator secretsHydrator, final Path workspaceRoot) { | ||
this.processFactory = processFactory; | ||
this.secretsHydrator = secretsHydrator; | ||
this.workspaceRoot = workspaceRoot; | ||
} | ||
|
||
public AirbyteCatalog run(final JobRunConfig jobRunConfig, | ||
final IntegrationLauncherConfig launcherConfig, | ||
final StandardDiscoverCatalogInput config) { | ||
|
||
final JsonNode fullConfig = secretsHydrator.hydrate(config.getConnectionConfiguration()); | ||
|
||
final StandardDiscoverCatalogInput input = new StandardDiscoverCatalogInput() | ||
.withConnectionConfiguration(fullConfig); | ||
|
||
final Supplier<StandardDiscoverCatalogInput> inputSupplier = () -> input; | ||
|
||
final TemporalAttemptExecution<StandardDiscoverCatalogInput, AirbyteCatalog> temporalAttemptExecution = new TemporalAttemptExecution<>( | ||
workspaceRoot, | ||
jobRunConfig, | ||
getWorkerFactory(launcherConfig), | ||
inputSupplier, | ||
new CancellationHandler.TemporalCancellationHandler()); | ||
|
||
return temporalAttemptExecution.get(); | ||
} | ||
|
||
private CheckedSupplier<Worker<StandardDiscoverCatalogInput, AirbyteCatalog>, Exception> getWorkerFactory(final IntegrationLauncherConfig launcherConfig) { | ||
return () -> { | ||
final IntegrationLauncher integrationLauncher = | ||
new AirbyteIntegrationLauncher(launcherConfig.getJobId(), launcherConfig.getAttemptId().intValue(), launcherConfig.getDockerImage(), | ||
processFactory, WorkerUtils.DEFAULT_RESOURCE_REQUIREMENTS); | ||
final AirbyteStreamFactory streamFactory = new DefaultAirbyteStreamFactory(); | ||
return new DefaultDiscoverCatalogWorker(integrationLauncher, streamFactory); | ||
}; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...s/src/main/java/io/airbyte/workers/temporal/discover/catalog/DiscoverCatalogWorkflow.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,22 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.temporal.discover.catalog; | ||
|
||
import io.airbyte.config.StandardDiscoverCatalogInput; | ||
import io.airbyte.protocol.models.AirbyteCatalog; | ||
import io.airbyte.scheduler.models.IntegrationLauncherConfig; | ||
import io.airbyte.scheduler.models.JobRunConfig; | ||
import io.temporal.workflow.WorkflowInterface; | ||
import io.temporal.workflow.WorkflowMethod; | ||
|
||
@WorkflowInterface | ||
public interface DiscoverCatalogWorkflow { | ||
|
||
@WorkflowMethod | ||
AirbyteCatalog run(JobRunConfig jobRunConfig, | ||
IntegrationLauncherConfig launcherConfig, | ||
StandardDiscoverCatalogInput config); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...c/main/java/io/airbyte/workers/temporal/discover/catalog/DiscoverCatalogWorkflowImpl.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,31 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.workers.temporal.discover.catalog; | ||
|
||
import io.airbyte.config.StandardDiscoverCatalogInput; | ||
import io.airbyte.protocol.models.AirbyteCatalog; | ||
import io.airbyte.scheduler.models.IntegrationLauncherConfig; | ||
import io.airbyte.scheduler.models.JobRunConfig; | ||
import io.airbyte.workers.temporal.TemporalUtils; | ||
import io.temporal.activity.ActivityOptions; | ||
import io.temporal.workflow.Workflow; | ||
import java.time.Duration; | ||
|
||
public class DiscoverCatalogWorkflowImpl implements DiscoverCatalogWorkflow { | ||
|
||
final ActivityOptions options = ActivityOptions.newBuilder() | ||
.setScheduleToCloseTimeout(Duration.ofHours(2)) | ||
.setRetryOptions(TemporalUtils.NO_RETRY) | ||
.build(); | ||
private final DiscoverCatalogActivity activity = Workflow.newActivityStub(DiscoverCatalogActivity.class, options); | ||
|
||
@Override | ||
public AirbyteCatalog run(final JobRunConfig jobRunConfig, | ||
final IntegrationLauncherConfig launcherConfig, | ||
final StandardDiscoverCatalogInput config) { | ||
return activity.run(jobRunConfig, launcherConfig, config); | ||
} | ||
|
||
} |
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