-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
AdaptiveDestinationRunner.java
94 lines (71 loc) · 3.27 KB
/
AdaptiveDestinationRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2023 Airbyte, Inc., all rights reserved.
*/
package io.airbyte.cdk.integrations.base.adaptive;
import io.airbyte.cdk.integrations.base.Destination;
import io.airbyte.cdk.integrations.base.IntegrationRunner;
import io.airbyte.commons.features.EnvVariableFeatureFlags;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This class launches different variants of a destination connector based on where Airbyte is
* deployed.
*/
public class AdaptiveDestinationRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(AdaptiveDestinationRunner.class);
private static final String DEPLOYMENT_MODE_KEY = EnvVariableFeatureFlags.DEPLOYMENT_MODE;
private static final String CLOUD_MODE = "CLOUD";
public static OssDestinationBuilder baseOnEnv() {
final String mode = System.getenv(DEPLOYMENT_MODE_KEY);
return new OssDestinationBuilder(mode);
}
public static final class OssDestinationBuilder {
private final String deploymentMode;
private OssDestinationBuilder(final String deploymentMode) {
this.deploymentMode = deploymentMode;
}
public <OT extends Destination> CloudDestinationBuilder<OT> withOssDestination(final Supplier<OT> ossDestinationSupplier) {
return new CloudDestinationBuilder<>(deploymentMode, ossDestinationSupplier);
}
}
public static final class CloudDestinationBuilder<OT extends Destination> {
private final String deploymentMode;
private final Supplier<OT> ossDestinationSupplier;
public CloudDestinationBuilder(final String deploymentMode, final Supplier<OT> ossDestinationSupplier) {
this.deploymentMode = deploymentMode;
this.ossDestinationSupplier = ossDestinationSupplier;
}
public <CT extends Destination> Runner<OT, CT> withCloudDestination(final Supplier<CT> cloudDestinationSupplier) {
return new Runner<>(deploymentMode, ossDestinationSupplier, cloudDestinationSupplier);
}
}
public static final class Runner<OT extends Destination, CT extends Destination> {
private final String deploymentMode;
private final Supplier<OT> ossDestinationSupplier;
private final Supplier<CT> cloudDestinationSupplier;
public Runner(final String deploymentMode,
final Supplier<OT> ossDestinationSupplier,
final Supplier<CT> cloudDestinationSupplier) {
this.deploymentMode = deploymentMode;
this.ossDestinationSupplier = ossDestinationSupplier;
this.cloudDestinationSupplier = cloudDestinationSupplier;
}
private Destination getDestination() {
LOGGER.info("Running destination under deployment mode: {}", deploymentMode);
if (deploymentMode != null && deploymentMode.equals(CLOUD_MODE)) {
return cloudDestinationSupplier.get();
}
if (deploymentMode == null) {
LOGGER.warn("Deployment mode is null, default to OSS mode");
}
return ossDestinationSupplier.get();
}
public void run(final String[] args) throws Exception {
final Destination destination = getDestination();
LOGGER.info("Starting destination: {}", destination.getClass().getName());
new IntegrationRunner(destination).run(args);
LOGGER.info("Completed destination: {}", destination.getClass().getName());
}
}
}