-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
422 additions
and
10 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
airbyte-config/models/src/main/resources/types/IntegrationLauncherConfig.yaml
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,18 @@ | ||
--- | ||
"$schema": http://json-schema.org/draft-07/schema# | ||
"$id": https://github.com/airbytehq/airbyte/blob/master/airbyte-config/models/src/main/resources/types/IntegrationLauncherConfig.yaml | ||
title: IntegrationLauncherConfig | ||
description: integration launcher config | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- jobId | ||
- attemptId | ||
- dockerImage | ||
properties: | ||
jobId: | ||
type: integer | ||
attemptId: | ||
type: integer | ||
dockerImage: | ||
type: string |
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
142 changes: 142 additions & 0 deletions
142
airbyte-scheduler/src/main/java/io/airbyte/scheduler/temporal/SpecWorkflow.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,142 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.scheduler.temporal; | ||
|
||
import io.airbyte.commons.io.IOs; | ||
import io.airbyte.commons.io.LineGobbler; | ||
import io.airbyte.config.IntegrationLauncherConfig; | ||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.protocol.models.ConnectorSpecification; | ||
import io.airbyte.workers.WorkerUtils; | ||
import io.airbyte.workers.process.AirbyteIntegrationLauncher; | ||
import io.airbyte.workers.process.IntegrationLauncher; | ||
import io.airbyte.workers.process.ProcessBuilderFactory; | ||
import io.airbyte.workers.protocols.airbyte.AirbyteStreamFactory; | ||
import io.airbyte.workers.protocols.airbyte.DefaultAirbyteStreamFactory; | ||
import io.temporal.activity.ActivityInterface; | ||
import io.temporal.activity.ActivityMethod; | ||
import io.temporal.activity.ActivityOptions; | ||
import io.temporal.workflow.Workflow; | ||
import io.temporal.workflow.WorkflowInterface; | ||
import io.temporal.workflow.WorkflowMethod; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
@WorkflowInterface | ||
public interface SpecWorkflow { | ||
|
||
@WorkflowMethod | ||
ConnectorSpecification run(IntegrationLauncherConfig launcherConfig); | ||
|
||
class WorkflowImpl implements SpecWorkflow { | ||
|
||
ActivityOptions options = ActivityOptions.newBuilder() | ||
.setScheduleToCloseTimeout(Duration.ofMinutes(2)) // todo | ||
.build(); | ||
|
||
private final SpecActivity activity = Workflow.newActivityStub(SpecActivity.class, options); | ||
|
||
@Override | ||
public ConnectorSpecification run(IntegrationLauncherConfig launcherConfig) { | ||
return activity.run(launcherConfig); | ||
} | ||
|
||
} | ||
|
||
@ActivityInterface | ||
interface SpecActivity { | ||
|
||
@ActivityMethod | ||
ConnectorSpecification run(IntegrationLauncherConfig launcherConfig); | ||
|
||
} | ||
|
||
class SpecActivityImpl implements SpecActivity { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(SpecActivityImpl.class); | ||
|
||
private final ProcessBuilderFactory pbf; | ||
private final Path workspaceRoot; | ||
|
||
public SpecActivityImpl(ProcessBuilderFactory pbf, Path workspaceRoot) { | ||
this.pbf = pbf; | ||
this.workspaceRoot = workspaceRoot; | ||
} | ||
|
||
public ConnectorSpecification run(IntegrationLauncherConfig launcherConfig) { | ||
try { | ||
// todo (cgardens) - we need to find a way to standardize log paths sanely across all workflow. | ||
// right now we have this in temporal workflow. | ||
final Path jobRoot = workspaceRoot | ||
.resolve("spec") | ||
.resolve(launcherConfig.getDockerImage().replaceAll("[^A-Za-z0-9]", "")) | ||
.resolve(String.valueOf(Instant.now().getEpochSecond())); | ||
|
||
final IntegrationLauncher integrationLauncher = | ||
new AirbyteIntegrationLauncher(launcherConfig.getJobId(), launcherConfig.getAttemptId().intValue(), launcherConfig.getDockerImage(), pbf); | ||
final Process process = integrationLauncher.spec(jobRoot).start(); | ||
|
||
LineGobbler.gobble(process.getErrorStream(), LOGGER::error); | ||
|
||
final AirbyteStreamFactory streamFactory = new DefaultAirbyteStreamFactory(); | ||
|
||
Optional<ConnectorSpecification> spec; | ||
try (InputStream stdout = process.getInputStream()) { | ||
spec = streamFactory.create(IOs.newBufferedReader(stdout)) | ||
.filter(message -> message.getType() == AirbyteMessage.Type.SPEC) | ||
.map(AirbyteMessage::getSpec) | ||
.findFirst(); | ||
|
||
// todo (cgardens) - let's pre-fetch the images outside of the worker so we don't need account for | ||
// this. | ||
// retrieving spec should generally be instantaneous, but since docker images might not be pulled | ||
// it could take a while longer depending on internet conditions as well. | ||
WorkerUtils.gentleClose(process, 30, TimeUnit.MINUTES); | ||
} | ||
|
||
int exitCode = process.exitValue(); | ||
if (exitCode == 0) { | ||
if (spec.isEmpty()) { | ||
throw new RuntimeException("Spec job failed to output a spec struct."); | ||
} else { | ||
return spec.get(); | ||
} | ||
} else { | ||
throw new RuntimeException(String.format("Spec job subprocess finished with exit code %s", exitCode)); | ||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException("Spec job failed with an exception", e); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
airbyte-scheduler/src/main/java/io/airbyte/scheduler/temporal/TemporalClient.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,53 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.scheduler.temporal; | ||
|
||
import io.airbyte.config.IntegrationLauncherConfig; | ||
import io.airbyte.config.JobGetSpecConfig; | ||
import io.airbyte.protocol.models.ConnectorSpecification; | ||
import io.airbyte.scheduler.temporal.TemporalUtils.TemporalJobType; | ||
import io.temporal.client.WorkflowClient; | ||
|
||
public class TemporalClient { | ||
|
||
private final WorkflowClient client; | ||
|
||
public TemporalClient(WorkflowClient client) { | ||
this.client = client; | ||
} | ||
|
||
public ConnectorSpecification submitGetSpec(long jobId, int attempt, JobGetSpecConfig config) { | ||
final IntegrationLauncherConfig integrationLauncherConfig = new IntegrationLauncherConfig() | ||
.withJobId(jobId) | ||
.withAttemptId((long) attempt) | ||
.withDockerImage(config.getDockerImage()); | ||
return getWorkflowStub(SpecWorkflow.class, TemporalJobType.GET_SPEC).run(integrationLauncherConfig); | ||
} | ||
|
||
private <T> T getWorkflowStub(Class<T> workflowClass, TemporalJobType jobType) { | ||
return client.newWorkflowStub(workflowClass, TemporalUtils.getWorkflowOptions(jobType)); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
airbyte-scheduler/src/main/java/io/airbyte/scheduler/temporal/TemporalPool.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 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.scheduler.temporal; | ||
|
||
import io.airbyte.scheduler.temporal.TemporalUtils.TemporalJobType; | ||
import io.airbyte.workers.process.ProcessBuilderFactory; | ||
import io.temporal.worker.Worker; | ||
import io.temporal.worker.WorkerFactory; | ||
import java.nio.file.Path; | ||
|
||
public class TemporalPool implements Runnable { | ||
|
||
private final Path workspaceRoot; | ||
private final ProcessBuilderFactory pbf; | ||
|
||
public TemporalPool(Path workspaceRoot, ProcessBuilderFactory pbf) { | ||
this.workspaceRoot = workspaceRoot; | ||
this.pbf = pbf; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
WorkerFactory factory = WorkerFactory.newInstance(TemporalUtils.TEMPORAL_CLIENT); | ||
|
||
final Worker specWorker = factory.newWorker(TemporalJobType.GET_SPEC.name()); | ||
specWorker.registerWorkflowImplementationTypes(SpecWorkflow.WorkflowImpl.class); | ||
specWorker.registerActivitiesImplementations(new SpecWorkflow.SpecActivityImpl(pbf, workspaceRoot)); | ||
|
||
// todo (cgardens) - these will come back once we use temporal for these workers. | ||
// Worker discoverWorker = factory.newWorker(TemporalUtils.DISCOVER_WORKFLOW_QUEUE); | ||
// discoverWorker.registerWorkflowImplementationTypes(DiscoverWorkflow.WorkflowImpl.class); | ||
// discoverWorker.registerActivitiesImplementations(new DiscoverWorkflow.DiscoverActivityImpl(pbf, | ||
// configs.getWorkspaceRoot())); | ||
// | ||
// Worker checkConnectionWorker = factory.newWorker(TemporalUtils.CHECK_CONNECTION_WORKFLOW_QUEUE); | ||
// checkConnectionWorker.registerWorkflowImplementationTypes(CheckConnectionWorkflow.WorkflowImpl.class); | ||
// checkConnectionWorker.registerActivitiesImplementations(new | ||
// CheckConnectionWorkflow.CheckConnectionActivityImpl(pbf, configs.getWorkspaceRoot())); | ||
// | ||
// Worker syncWorker = factory.newWorker(TemporalUtils.SYNC_WORKFLOW_QUEUE); | ||
// syncWorker.registerWorkflowImplementationTypes(SyncWorkflow.WorkflowImpl.class); | ||
// syncWorker.registerActivitiesImplementations(new SyncWorkflow.SyncActivityImpl(pbf, | ||
// configs.getWorkspaceRoot())); | ||
|
||
factory.start(); | ||
} | ||
|
||
} |
Oops, something went wrong.