Skip to content

Commit

Permalink
make oss conform to cloud checkstyle rules (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgardens authored Feb 24, 2023
1 parent 217499a commit 876139d
Show file tree
Hide file tree
Showing 732 changed files with 7,003 additions and 1,510 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import io.airbyte.config.Configs.WorkerEnvironment;
import java.util.UUID;

/**
* A deployment describes a deployed instance of Airbyte. It is meant to retain its identity through
* the upgrade process. i.e. Airbyte running on the same VM at version 0.40.1 and then upgraded to
* 0.40.2 is still the same deployment.
*/
public class Deployment {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Tracking client that logs to STDOUT. Mainly used for local deveolpment.
*/
public class LoggingTrackingClient implements TrackingClient {

private static final Logger LOGGER = LoggerFactory.getLogger(LoggingTrackingClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Singleton to get access to the tracking client.
*/
public class TrackingClientSingleton {

private static final Logger LOGGER = LoggerFactory.getLogger(LoggingTrackingClient.class);

private static final Object lock = new Object();
private static TrackingClient trackingClient;

/**
* Get the tracking client. If a tracking client is not yet set, it will initialize a no op, logging
* tracker.
*
* @return tracking client.
*/
public static TrackingClient get() {
synchronized (lock) {
if (trackingClient == null) {
Expand All @@ -41,6 +50,15 @@ static void initialize(final TrackingClient trackingClient) {
}
}

/**
* Initialize the client.
*
* @param trackingStrategy tracking strategy
* @param deployment deployment
* @param airbyteRole is it an airbyte employee
* @param airbyteVersion version of airbyte running
* @param configRepository access to the db
*/
public static void initialize(final Configs.TrackingStrategy trackingStrategy,
final Deployment deployment,
final String airbyteRole,
Expand Down Expand Up @@ -88,7 +106,7 @@ static TrackingIdentity getTrackingIdentity(final ConfigRepository configReposit
* @param trackingStrategy - what type of tracker we want to use.
* @param deployment - deployment tracking info. static because it should not change once the
* instance is running.
* @param airbyteRole
* @param airbyteRole - is it an airbyte employee
* @param trackingIdentityFetcher - how we get the identity of the user. we have a function that
* takes in workspaceId and returns the tracking identity. it does not have any caching as
* email or other fields on the identity can change over time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.util.Optional;
import java.util.UUID;

/**
* POJO that holds fields identity fields for telemetry.
*/
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public class TrackingIdentity {

Expand Down Expand Up @@ -71,11 +74,11 @@ public boolean equals(final Object o) {
return false;
}
final TrackingIdentity that = (TrackingIdentity) o;
return anonymousDataCollection == that.anonymousDataCollection &&
news == that.news &&
securityUpdates == that.securityUpdates &&
Objects.equals(customerId, that.customerId) &&
Objects.equals(email, that.email);
return anonymousDataCollection == that.anonymousDataCollection
&& news == that.news
&& securityUpdates == that.securityUpdates
&& Objects.equals(customerId, that.customerId)
&& Objects.equals(email, that.email);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public PatchedLogsApi(final ApiClient apiClient) {
}

/**
* Get logs
* Get logs.
*
* @param logsRequestBody (required)
* @return File
Expand All @@ -60,7 +60,7 @@ public File getLogs(final LogsRequestBody logsRequestBody) throws ApiException {
}

/**
* Get logs
* Get logs.
*
* @param logsRequestBody (required)
* @return ApiResponse<File>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

/**
* Tests for the Airbyte API Client.
*/
public class AirbyteApiClientTest {

// These set of configurations are so each test case takes ~3 secs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private void assertNonBreakingMigration(final JobPersistence jobPersistence, fin
final String attentionBanner = MoreResources.readResource("banner/attention-banner.txt");
log.error(attentionBanner);
final String message = String.format(
"Cannot upgrade from version %s to version %s directly. First you must upgrade to version %s. After that upgrade is complete, you may upgrade to version %s",
"Cannot upgrade from version %s to version %s directly. First you must upgrade to version %s. "
+ "After that upgrade is complete, you may upgrade to version %s",
initialAirbyteDatabaseVersion.get().serialize(),
airbyteVersion.serialize(),
VERSION_BREAK.serialize(),
Expand All @@ -156,8 +157,8 @@ private void assertNonBreakingProtocolVersionConstraints(final ProtocolVersionCh
final Optional<AirbyteProtocolVersionRange> newProtocolRange = protocolVersionChecker.validate(autoUpgradeConnectors);
if (newProtocolRange.isEmpty()) {
throw new RuntimeException(
"Aborting bootloader to avoid breaking existing connection after an upgrade. " +
"Please address airbyte protocol version support issues in the connectors before retrying.");
"Aborting bootloader to avoid breaking existing connection after an upgrade. "
+ "Please address airbyte protocol version support issues in the connectors before retrying.");
}
trackProtocolVersion(jobPersistence, newProtocolRange.get());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public ProtocolVersionChecker(final JobPersistence jobPersistence,
* @param supportAutoUpgrade whether the connectors will be automatically upgraded by the platform
* @return the supported protocol version range if check is successful, Optional.empty() if we would
* break existing connections.
* @throws IOException
* @throws IOException when interacting with the db.
*/
public Optional<AirbyteProtocolVersionRange> validate(final boolean supportAutoUpgrade) throws IOException {
final Optional<AirbyteVersion> currentAirbyteVersion = getCurrentAirbyteVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import lombok.Value;
import lombok.extern.slf4j.Slf4j;

/**
* Migrate old way of storing configs to always use a secrets store.
*/
@Singleton
@Slf4j
public class SecretMigrator {
Expand Down Expand Up @@ -107,7 +110,7 @@ public void migrateSecrets() throws Exception {
}

/**
* This is migrating the secrets for the source actors
* This is migrating the secrets for the source actors.
*/
@VisibleForTesting
void migrateSources(final List<SourceConnection> sources, final Map<UUID, ConnectorSpecification> definitionIdToSourceSpecs)
Expand All @@ -129,7 +132,7 @@ void migrateSources(final List<SourceConnection> sources, final Map<UUID, Connec
}

/**
* This is migrating the secrets for the destination actors
* This is migrating the secrets for the destination actors.
*/
@VisibleForTesting
void migrateDestinations(final List<DestinationConnection> destinations, final Map<UUID, ConnectorSpecification> definitionIdToDestinationSpecs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public FeatureFlags featureFlags() {
return new EnvVariableFeatureFlags();
}

/**
* Create JsonSecretsProcessor.
*
* @return json secrets processor
*/
@Singleton
public JsonSecretsProcessor jsonSecretsProcessor() {
return JsonSecretsProcessor.builder()
Expand All @@ -64,6 +69,7 @@ public SecretsRepositoryReader secretsRepositoryReader(final ConfigRepository co
return new SecretsRepositoryReader(configRepository, secretsHydrator);
}

@SuppressWarnings("LineLength")
@Singleton
public SecretsRepositoryWriter secretsRepositoryWriter(final ConfigRepository configRepository,
@Named("secretPersistence") final Optional<SecretPersistence> secretPersistence,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ public Database jobsDatabase(@Named("jobs") final DSLContext dslContext) throws
return new Database(dslContext);
}

/**
* Flyway configs db singleton.
*
* @param configFlywayConfigurationProperties config db flyway configuration
* @param configDataSource configs db data source
* @param baselineVersion baseline migration version
* @return flyway
*/
@Singleton
@Named("configFlyway")
public Flyway configFlyway(@Named("config") final FlywayConfigurationProperties configFlywayConfigurationProperties,
Expand All @@ -64,6 +72,14 @@ public Flyway configFlyway(@Named("config") final FlywayConfigurationProperties
.load();
}

/**
* Flyway jobs db singleton.
*
* @param jobsFlywayConfigurationProperties jobs flyway configuration
* @param jobsDataSource jobs data source
* @param baselineVersion base line migration version
* @return flyway
*/
@Singleton
@Named("jobsFlyway")
public Flyway jobsFlyway(@Named("jobs") final FlywayConfigurationProperties jobsFlywayConfigurationProperties,
Expand All @@ -89,6 +105,7 @@ public JobPersistence jobPersistence(@Named("jobsDatabase") final Database jobDa
return new DefaultJobPersistence(jobDatabase);
}

@SuppressWarnings("LineLength")
@Singleton
@Named("configsDatabaseInitializer")
public DatabaseInitializer configsDatabaseInitializer(@Named("config") final DSLContext configsDslContext,
Expand All @@ -98,6 +115,7 @@ public DatabaseInitializer configsDatabaseInitializer(@Named("config") final DSL
configsDatabaseInitializationTimeoutMs, MoreResources.readResource(DatabaseConstants.CONFIGS_INITIAL_SCHEMA_PATH));
}

@SuppressWarnings("LineLength")
@Singleton
@Named("jobsDatabaseInitializer")
public DatabaseInitializer jobsDatabaseInitializer(@Named("jobs") final DSLContext jobsDslContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void testBootloaderAppBlankDb() throws Exception {
}
}

@SuppressWarnings("VariableDeclarationUsageDistance")
@Test
void testBootloaderAppRunSecretMigration() throws Exception {
val mockedConfigs = mock(Configs.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class ProtocolVersionCheckerTest {
DefinitionsProvider definitionsProvider;
JobPersistence jobPersistence;

final Version V0_0_0 = new Version("0.0.0");
final Version V1_0_0 = new Version("1.0.0");
final Version V2_0_0 = new Version("2.0.0");
private static final Version V0_0_0 = new Version("0.0.0");
private static final Version V1_0_0 = new Version("1.0.0");
private static final Version V2_0_0 = new Version("2.0.0");

@BeforeEach
void beforeEach() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

/**
* Common helper methods for writing command line tools and parsing command line arguments.
*/
public class Clis {

/**
* Parse an options object
* Parse an options object.
*
* @param args - command line args
* @param options - expected options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
public class CatalogClientConverters {

/**
* Convert to api model to airbyte protocol model.
*
* @param catalog
* @return
* @param catalog api model
* @return catalog protocol model
*/
public static io.airbyte.protocol.models.AirbyteCatalog toAirbyteProtocol(final io.airbyte.api.client.model.generated.AirbyteCatalog catalog) {

Expand Down Expand Up @@ -109,6 +110,7 @@ private static io.airbyte.protocol.models.AirbyteStream toConfiguredProtocol(fin
/**
* Converts a protocol AirbyteCatalog to an OpenAPI client versioned AirbyteCatalog.
*/
@SuppressWarnings("LineLength")
public static io.airbyte.api.client.model.generated.AirbyteCatalog toAirbyteCatalogClientApi(
final io.airbyte.protocol.models.AirbyteCatalog catalog) {
return new io.airbyte.api.client.model.generated.AirbyteCatalog()
Expand All @@ -121,6 +123,7 @@ public static io.airbyte.api.client.model.generated.AirbyteCatalog toAirbyteCata
.collect(Collectors.toList()));
}

@SuppressWarnings("LineLength")
private static io.airbyte.api.client.model.generated.AirbyteStreamConfiguration generateDefaultConfiguration(
final io.airbyte.api.client.model.generated.AirbyteStream stream) {
final io.airbyte.api.client.model.generated.AirbyteStreamConfiguration result =
Expand All @@ -139,8 +142,7 @@ private static io.airbyte.api.client.model.generated.AirbyteStreamConfiguration
return result;
}

private static io.airbyte.api.client.model.generated.AirbyteStream toAirbyteStreamClientApi(
final AirbyteStream stream) {
private static io.airbyte.api.client.model.generated.AirbyteStream toAirbyteStreamClientApi(final AirbyteStream stream) {
return new io.airbyte.api.client.model.generated.AirbyteStream()
.name(stream.getName())
.jsonSchema(stream.getJsonSchema())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

// todo (cgardens) - we are not getting any value out of instantiating this class. we should just
// use it as statics. not doing it now, because already in the middle of another refactor.
/**
* Connection Helpers.
*/
@Singleton
public class ConnectionHelper {

Expand Down Expand Up @@ -116,6 +119,14 @@ public static StandardSync updateConnectionObject(final WorkspaceHelper workspac
return newConnection;
}

/**
* Validate all resources are from the same workspace.
*
* @param workspaceHelper workspace helper
* @param sourceId source id
* @param destinationId destination id
* @param operationIds operation ids
*/
public static void validateWorkspace(final WorkspaceHelper workspaceHelper,
final UUID sourceId,
final UUID destinationId,
Expand All @@ -126,7 +137,11 @@ public static void validateWorkspace(final WorkspaceHelper workspaceHelper,
Preconditions.checkArgument(
sourceWorkspace.equals(destinationWorkspace),
String.format(
"Source and destination do not belong to the same workspace. Source id: %s, Source workspace id: %s, Destination id: %s, Destination workspace id: %s",
"Source and destination do not belong to the same workspace. "
+ "Source id: %s, "
+ "Source workspace id: %s, "
+ "Destination id: %s, "
+ "Destination workspace id: %s",
sourceId,
sourceWorkspace,
destinationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public static StreamDescriptor streamDescriptorToApi(final io.airbyte.protocol.m
return new StreamDescriptor().name(protocolStreamDescriptor.getName()).namespace(protocolStreamDescriptor.getNamespace());
}

/**
* Convert protocol stream descriptor to api stream descriptor.
*
* @param protocolStreamDescriptor protocol stream descriptor
* @return api stream descriptor
*/
@SuppressWarnings("LineLength")
public static io.airbyte.api.client.model.generated.StreamDescriptor streamDescriptorToClient(final io.airbyte.protocol.models.StreamDescriptor protocolStreamDescriptor) {
return new io.airbyte.api.client.model.generated.StreamDescriptor()
.name(protocolStreamDescriptor.getName())
Expand All @@ -26,6 +33,7 @@ public static io.airbyte.protocol.models.StreamDescriptor streamDescriptorToProt
.withNamespace(apiStreamDescriptor.getNamespace());
}

@SuppressWarnings("LineLength")
public static io.airbyte.protocol.models.StreamDescriptor clientStreamDescriptorToProtocol(final io.airbyte.api.client.model.generated.StreamDescriptor clientStreamDescriptor) {
return new io.airbyte.protocol.models.StreamDescriptor().withName(clientStreamDescriptor.getName())
.withNamespace(clientStreamDescriptor.getNamespace());
Expand Down
Loading

0 comments on commit 876139d

Please sign in to comment.