Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit e77d4b6

Browse files
alovewJordan Scott
authored andcommitted
Apply pmd to airbyte-config (airbytehq#13003)
* Apply pmd to airbyte-config, exclude rules for now
1 parent 97a3f9b commit e77d4b6

File tree

68 files changed

+920
-653
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+920
-653
lines changed

airbyte-config/init/src/main/java/io/airbyte/config/init/YamlSeedConfigPersistence.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
* This config persistence contains all seed definitions according to the yaml files. It is
3434
* read-only.
3535
*/
36-
public class YamlSeedConfigPersistence implements ConfigPersistence {
36+
final public class YamlSeedConfigPersistence implements ConfigPersistence {
3737

38+
private static final String PERSISTENCE_READ_ONLY_ERROR_MSG = "The seed config persistence is read only.";
3839
public static final Class<?> DEFAULT_SEED_DEFINITION_RESOURCE_CLASS = SeedType.class;
3940

4041
private static final Map<AirbyteConfig, SeedType> CONFIG_SCHEMA_MAP = Map.of(
@@ -178,22 +179,22 @@ public <T> List<ConfigWithMetadata<T>> listConfigsWithMetadata(final AirbyteConf
178179

179180
@Override
180181
public <T> void writeConfig(final AirbyteConfig configType, final String configId, final T config) {
181-
throw new UnsupportedOperationException("The seed config persistence is read only.");
182+
throw new UnsupportedOperationException(PERSISTENCE_READ_ONLY_ERROR_MSG);
182183
}
183184

184185
@Override
185186
public <T> void writeConfigs(final AirbyteConfig configType, final Map<String, T> configs) {
186-
throw new UnsupportedOperationException("The seed config persistence is read only.");
187+
throw new UnsupportedOperationException(PERSISTENCE_READ_ONLY_ERROR_MSG);
187188
}
188189

189190
@Override
190191
public void deleteConfig(final AirbyteConfig configType, final String configId) {
191-
throw new UnsupportedOperationException("The seed config persistence is read only.");
192+
throw new UnsupportedOperationException(PERSISTENCE_READ_ONLY_ERROR_MSG);
192193
}
193194

194195
@Override
195196
public void replaceAllConfigs(final Map<AirbyteConfig, Stream<?>> configs, final boolean dryRun) {
196-
throw new UnsupportedOperationException("The seed config persistence is read only.");
197+
throw new UnsupportedOperationException(PERSISTENCE_READ_ONLY_ERROR_MSG);
197198
}
198199

199200
@Override
@@ -205,7 +206,7 @@ public Map<String, Stream<JsonNode>> dumpConfigs() {
205206

206207
@Override
207208
public void loadData(final ConfigPersistence seedPersistence) throws IOException {
208-
throw new UnsupportedOperationException("The seed config persistence is read only.");
209+
throw new UnsupportedOperationException(PERSISTENCE_READ_ONLY_ERROR_MSG);
209210
}
210211

211212
}

airbyte-config/init/src/test/java/io/airbyte/config/init/SpecFormatTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121

2222
@Slf4j
23-
public class SpecFormatTest {
23+
class SpecFormatTest {
2424

2525
@Test
2626
void testOnAllExistingConfig() throws IOException, JsonValidationException {

airbyte-config/init/src/test/java/io/airbyte/config/init/YamlSeedConfigPersistenceTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
import org.junit.jupiter.api.BeforeAll;
2424
import org.junit.jupiter.api.Test;
2525

26-
public class YamlSeedConfigPersistenceTest {
26+
class YamlSeedConfigPersistenceTest {
2727

28-
private static YamlSeedConfigPersistence PERSISTENCE;
28+
private static YamlSeedConfigPersistence persistence;
2929

3030
@BeforeAll
3131
static void setup() throws IOException {
32-
PERSISTENCE = YamlSeedConfigPersistence.getDefault();
32+
persistence = YamlSeedConfigPersistence.getDefault();
3333
}
3434

3535
@Test
36-
public void testGetConfig() throws Exception {
36+
void testGetConfig() throws Exception {
3737
// source
3838
final String mySqlSourceId = "435bb9a5-7887-4809-aa58-28c27df0d7ad";
39-
final StandardSourceDefinition mysqlSource = PERSISTENCE
39+
final StandardSourceDefinition mysqlSource = persistence
4040
.getConfig(ConfigSchema.STANDARD_SOURCE_DEFINITION, mySqlSourceId, StandardSourceDefinition.class);
4141
assertEquals(mySqlSourceId, mysqlSource.getSourceDefinitionId().toString());
4242
assertEquals("MySQL", mysqlSource.getName());
@@ -49,7 +49,7 @@ public void testGetConfig() throws Exception {
4949

5050
// destination
5151
final String s3DestinationId = "4816b78f-1489-44c1-9060-4b19d5fa9362";
52-
final StandardDestinationDefinition s3Destination = PERSISTENCE
52+
final StandardDestinationDefinition s3Destination = persistence
5353
.getConfig(ConfigSchema.STANDARD_DESTINATION_DEFINITION, s3DestinationId, StandardDestinationDefinition.class);
5454
assertEquals(s3DestinationId, s3Destination.getDestinationDefinitionId().toString());
5555
assertEquals("S3", s3Destination.getName());
@@ -61,27 +61,27 @@ public void testGetConfig() throws Exception {
6161
}
6262

6363
@Test
64-
public void testGetInvalidConfig() {
64+
void testGetInvalidConfig() {
6565
assertThrows(
6666
UnsupportedOperationException.class,
67-
() -> PERSISTENCE.getConfig(ConfigSchema.STANDARD_SYNC, "invalid_id", StandardSync.class));
67+
() -> persistence.getConfig(ConfigSchema.STANDARD_SYNC, "invalid_id", StandardSync.class));
6868
assertThrows(
6969
ConfigNotFoundException.class,
70-
() -> PERSISTENCE.getConfig(ConfigSchema.STANDARD_SOURCE_DEFINITION, "invalid_id", StandardWorkspace.class));
70+
() -> persistence.getConfig(ConfigSchema.STANDARD_SOURCE_DEFINITION, "invalid_id", StandardWorkspace.class));
7171
}
7272

7373
@Test
74-
public void testDumpConfigs() {
75-
final Map<String, Stream<JsonNode>> allSeedConfigs = PERSISTENCE.dumpConfigs();
74+
void testDumpConfigs() {
75+
final Map<String, Stream<JsonNode>> allSeedConfigs = persistence.dumpConfigs();
7676
assertEquals(2, allSeedConfigs.size());
7777
assertTrue(allSeedConfigs.get(ConfigSchema.STANDARD_SOURCE_DEFINITION.name()).findAny().isPresent());
7878
assertTrue(allSeedConfigs.get(ConfigSchema.STANDARD_DESTINATION_DEFINITION.name()).findAny().isPresent());
7979
}
8080

8181
@Test
82-
public void testWriteMethods() {
83-
assertThrows(UnsupportedOperationException.class, () -> PERSISTENCE.writeConfig(ConfigSchema.STANDARD_SOURCE_DEFINITION, "id", new Object()));
84-
assertThrows(UnsupportedOperationException.class, () -> PERSISTENCE.replaceAllConfigs(Collections.emptyMap(), false));
82+
void testWriteMethods() {
83+
assertThrows(UnsupportedOperationException.class, () -> persistence.writeConfig(ConfigSchema.STANDARD_SOURCE_DEFINITION, "id", new Object()));
84+
assertThrows(UnsupportedOperationException.class, () -> persistence.replaceAllConfigs(Collections.emptyMap(), false));
8585
}
8686

8787
}

airbyte-config/models/src/main/java/io/airbyte/config/AirbyteConfigValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class AirbyteConfigValidator extends AbstractSchemaValidator<ConfigSchema> {
1111

12-
public static AirbyteConfigValidator AIRBYTE_CONFIG_VALIDATOR = new AirbyteConfigValidator();
12+
final public static AirbyteConfigValidator AIRBYTE_CONFIG_VALIDATOR = new AirbyteConfigValidator();
1313

1414
@Override
1515
public Path getSchemaPath(final ConfigSchema configType) {

airbyte-config/models/src/main/java/io/airbyte/config/ConfigSchema.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Path;
1010
import java.util.function.Function;
1111

12+
@SuppressWarnings({"PMD.AvoidThrowingRawExceptionTypes", "PMD.NullAssignment"})
1213
public enum ConfigSchema implements AirbyteConfig {
1314

1415
// workspace
@@ -108,6 +109,7 @@ public File getConfigSchemaFile() {
108109
return KNOWN_SCHEMAS_ROOT.resolve(schemaFilename).toFile();
109110
}
110111

112+
@Override
111113
public <T> Class<T> getClassName() {
112114
return (Class<T>) className;
113115
}

airbyte-config/models/src/main/java/io/airbyte/config/ConfigWithMetadata.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.time.Instant;
88
import java.util.Objects;
99

10+
@SuppressWarnings("PMD.ShortVariable")
1011
public class ConfigWithMetadata<T> {
1112

1213
private final String configId;

airbyte-config/models/src/main/java/io/airbyte/config/Configs.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* <p>
2525
* 2. 'Alpha support' if a var does not have proper support and should be used with care.
2626
*/
27+
28+
@SuppressWarnings("PMD.BooleanGetMethodName")
2729
public interface Configs {
2830

2931
// CORE

airbyte-config/models/src/main/java/io/airbyte/config/EnvConfigs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434

35+
@SuppressWarnings({"PMD.LongVariable", "PMD.CyclomaticComplexity", "PMD.AvoidReassigningParameters"})
3536
public class EnvConfigs implements Configs {
3637

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

airbyte-config/models/src/main/java/io/airbyte/config/TolerationPOJO.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/**
1010
* Represents a minimal io.fabric8.kubernetes.api.model.Toleration
1111
*/
12+
@SuppressWarnings("PMD.ShortVariable")
1213
public class TolerationPOJO {
1314

1415
private final String key;

airbyte-config/models/src/main/java/io/airbyte/config/helpers/CloudLogs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* that path 2) log files names start with timestamps, making it possible extract the time the file
2121
* was written from it's name.
2222
*/
23+
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
2324
public interface CloudLogs {
2425

2526
Logger LOGGER = LoggerFactory.getLogger(CloudLogs.class);

airbyte-config/models/src/main/java/io/airbyte/config/helpers/GcsLogs.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424

25+
@SuppressWarnings({"PMD.AvoidFileStream", "PMD.ShortVariable", "PMD.CloseResource", "PMD.AvoidInstantiatingObjectsInLoops"})
2526
public class GcsLogs implements CloudLogs {
2627

2728
private static final Logger LOGGER = LoggerFactory.getLogger(GcsLogs.class);
2829

29-
private static Storage GCS;
30+
private static Storage gcs;
3031
private final Supplier<Storage> gcsClientFactory;
3132

3233
public GcsLogs(final Supplier<Storage> gcsClientFactory) {
@@ -120,10 +121,10 @@ public void deleteLogs(final LogConfigs configs, final String logPath) {
120121
}
121122

122123
private Storage getOrCreateGcsClient() {
123-
if (GCS == null) {
124-
GCS = gcsClientFactory.get();
124+
if (gcs == null) {
125+
gcs = gcsClientFactory.get();
125126
}
126-
return GCS;
127+
return gcs;
127128
}
128129

129130
}

airbyte-config/models/src/main/java/io/airbyte/config/helpers/LogClientSingleton.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* {@link LogConfigs} within this class. Beyond this class, all configuration consumption is via the
2727
* {@link LogConfigs} interface via the {@link CloudLogs} interface.
2828
*/
29+
@SuppressWarnings({"PMD.AvoidThrowingRawExceptionTypes", "PMD.AvoidSynchronizedAtMethodLevel"})
2930
public class LogClientSingleton {
3031

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

airbyte-config/models/src/main/java/io/airbyte/config/helpers/LogConfigs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
public class LogConfigs {
1414

15-
public static LogConfigs EMPTY = new LogConfigs(null);
15+
public final static LogConfigs EMPTY = new LogConfigs(null);
1616

1717
private final CloudStorageConfigs storageConfigs;
1818

airbyte-config/models/src/main/java/io/airbyte/config/helpers/S3Logs.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
3131
import software.amazon.awssdk.services.s3.model.ObjectIdentifier;
3232

33+
@SuppressWarnings({"PMD.ShortVariable", "PMD.CloseResource", "PMD.AvoidFileStream"})
3334
public class S3Logs implements CloudLogs {
3435

3536
private static final Logger LOGGER = LoggerFactory.getLogger(S3Logs.class);
3637

37-
private static S3Client S3;
38+
private static S3Client s3;
3839

3940
private final Supplier<S3Client> s3ClientFactory;
4041

@@ -100,7 +101,7 @@ public List<String> tailCloudLog(final LogConfigs configs, final String logPath,
100101

101102
final var s3Bucket = getBucketName(configs.getStorageConfigs());
102103
LOGGER.debug("Start making S3 list request.");
103-
final ArrayList<String> ascendingTimestampKeys = getAscendingObjectKeys(s3Client, logPath, s3Bucket);
104+
final List<String> ascendingTimestampKeys = getAscendingObjectKeys(s3Client, logPath, s3Bucket);
104105
final var descendingTimestampKeys = Lists.reverse(ascendingTimestampKeys);
105106

106107
final var lines = new ArrayList<String>();
@@ -145,13 +146,13 @@ public void deleteLogs(final LogConfigs configs, final String logPath) {
145146
}
146147

147148
private S3Client getOrCreateS3Client() {
148-
if (S3 == null) {
149-
S3 = s3ClientFactory.get();
149+
if (s3 == null) {
150+
s3 = s3ClientFactory.get();
150151
}
151-
return S3;
152+
return s3;
152153
}
153154

154-
private static ArrayList<String> getAscendingObjectKeys(final S3Client s3Client, final String logPath, final String s3Bucket) {
155+
private static List<String> getAscendingObjectKeys(final S3Client s3Client, final String logPath, final String s3Bucket) {
155156
final var listObjReq = ListObjectsV2Request.builder().bucket(s3Bucket).prefix(logPath).build();
156157
final var ascendingTimestampObjs = new ArrayList<String>();
157158

@@ -164,7 +165,7 @@ private static ArrayList<String> getAscendingObjectKeys(final S3Client s3Client,
164165
return ascendingTimestampObjs;
165166
}
166167

167-
private static ArrayList<String> getCurrFile(final S3Client s3Client, final String s3Bucket, final String poppedKey) throws IOException {
168+
private static List<String> getCurrFile(final S3Client s3Client, final String s3Bucket, final String poppedKey) throws IOException {
168169
final var getObjReq = GetObjectRequest.builder()
169170
.key(poppedKey)
170171
.bucket(s3Bucket)

airbyte-config/models/src/main/java/io/airbyte/config/helpers/ScheduleHelpers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.airbyte.config.Schedule;
88
import java.util.concurrent.TimeUnit;
99

10+
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
1011
public class ScheduleHelpers {
1112

1213
public static Long getSecondsInUnit(final Schedule.TimeUnit timeUnitEnum) {

airbyte-config/models/src/main/java/io/airbyte/config/helpers/YamlListToStandardDefinitions.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,43 @@
3131
*
3232
* Methods in these class throw Runtime exceptions upon validation failure.
3333
*/
34+
@SuppressWarnings("PMD.ShortVariable")
3435
public class YamlListToStandardDefinitions {
3536

36-
private static final Map<String, String> classNameToIdName = Map.ofEntries(
37+
private static final Map<String, String> CLASS_NAME_TO_ID_NAME = Map.ofEntries(
3738
new SimpleImmutableEntry<>(StandardDestinationDefinition.class.getCanonicalName(), "destinationDefinitionId"),
3839
new SimpleImmutableEntry<>(StandardSourceDefinition.class.getCanonicalName(), "sourceDefinitionId"));
3940

40-
public static List<StandardSourceDefinition> toStandardSourceDefinitions(final String yamlStr) throws RuntimeException {
41+
public static List<StandardSourceDefinition> toStandardSourceDefinitions(final String yamlStr) {
4142
return verifyAndConvertToModelList(StandardSourceDefinition.class, yamlStr);
4243
}
4344

44-
public static List<StandardDestinationDefinition> toStandardDestinationDefinitions(final String yamlStr) throws RuntimeException {
45+
public static List<StandardDestinationDefinition> toStandardDestinationDefinitions(final String yamlStr) {
4546
return verifyAndConvertToModelList(StandardDestinationDefinition.class, yamlStr);
4647
}
4748

48-
public static JsonNode verifyAndConvertToJsonNode(final String idName, final String yamlStr) throws RuntimeException {
49+
public static JsonNode verifyAndConvertToJsonNode(final String idName, final String yamlStr) {
4950
final var jsonNode = Yamls.deserialize(yamlStr);
5051
checkYamlIsPresentWithNoDuplicates(jsonNode, idName);
5152
return jsonNode;
5253
}
5354

5455
@VisibleForTesting
55-
static <T> List<T> verifyAndConvertToModelList(final Class<T> klass, final String yamlStr) throws RuntimeException {
56+
static <T> List<T> verifyAndConvertToModelList(final Class<T> klass, final String yamlStr) {
5657
final var jsonNode = Yamls.deserialize(yamlStr);
57-
final var idName = classNameToIdName.get(klass.getCanonicalName());
58+
final var idName = CLASS_NAME_TO_ID_NAME.get(klass.getCanonicalName());
5859
checkYamlIsPresentWithNoDuplicates(jsonNode, idName);
5960
return toStandardXDefinitions(jsonNode.elements(), klass);
6061
}
6162

62-
private static void checkYamlIsPresentWithNoDuplicates(final JsonNode deserialize, final String idName) throws RuntimeException {
63+
private static void checkYamlIsPresentWithNoDuplicates(final JsonNode deserialize, final String idName) {
6364
final var presentDestList = !deserialize.elements().equals(ClassUtil.emptyIterator());
6465
Preconditions.checkState(presentDestList, "Definition list is empty");
6566
checkNoDuplicateNames(deserialize.elements());
6667
checkNoDuplicateIds(deserialize.elements(), idName);
6768
}
6869

69-
private static void checkNoDuplicateNames(final Iterator<JsonNode> iter) throws IllegalArgumentException {
70+
private static void checkNoDuplicateNames(final Iterator<JsonNode> iter) {
7071
final var names = new HashSet<String>();
7172
while (iter.hasNext()) {
7273
final var element = Jsons.clone(iter.next());
@@ -78,7 +79,7 @@ private static void checkNoDuplicateNames(final Iterator<JsonNode> iter) throws
7879
}
7980
}
8081

81-
private static void checkNoDuplicateIds(final Iterator<JsonNode> fileIterator, final String idName) throws IllegalArgumentException {
82+
private static void checkNoDuplicateIds(final Iterator<JsonNode> fileIterator, final String idName) {
8283
final var ids = new HashSet<String>();
8384
while (fileIterator.hasNext()) {
8485
final var element = Jsons.clone(fileIterator.next());
@@ -90,7 +91,7 @@ private static void checkNoDuplicateIds(final Iterator<JsonNode> fileIterator, f
9091
}
9192
}
9293

93-
private static <T> List<T> toStandardXDefinitions(final Iterator<JsonNode> iter, final Class<T> c) throws RuntimeException {
94+
private static <T> List<T> toStandardXDefinitions(final Iterator<JsonNode> iter, final Class<T> c) {
9495
final Iterable<JsonNode> iterable = () -> iter;
9596
final var defList = new ArrayList<T>();
9697
for (final JsonNode n : iterable) {

airbyte-config/models/src/main/java/io/airbyte/config/storage/CloudStorageConfigs.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* wherever that cloud storage is used and then, based on the configuration, spin up the correct
1313
* client. This configuration object allows us to do that.
1414
*/
15+
@SuppressWarnings("PMD.ShortMethodName")
1516
public class CloudStorageConfigs {
1617

1718
public enum WorkerStorageType {
@@ -88,7 +89,7 @@ public GcsConfig getGcsConfig() {
8889
return gcsConfig;
8990
}
9091

91-
public static abstract class S3ApiWorkerStorageConfig {
92+
public static class S3ApiWorkerStorageConfig {
9293

9394
private final String bucketName;
9495
private final String awsAccessKey;

airbyte-config/models/src/main/java/io/airbyte/config/storage/DefaultGcsClientFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* Takes in the constructor our standard format for gcs configuration and provides a factory that
1919
* uses that configuration to create a GCS client (Storage).
2020
*/
21+
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
2122
public class DefaultGcsClientFactory implements Supplier<Storage> {
2223

2324
private final GcsConfig config;
@@ -38,7 +39,7 @@ public Storage get() {
3839
final var credentialsByteStream = new ByteArrayInputStream(Files.readAllBytes(Path.of(config.getGoogleApplicationCredentials())));
3940
final var credentials = ServiceAccountCredentials.fromStream(credentialsByteStream);
4041
return StorageOptions.newBuilder().setCredentials(credentials).build().getService();
41-
} catch (Exception e) {
42+
} catch (final Exception e) {
4243
throw new RuntimeException(e);
4344
}
4445
}

0 commit comments

Comments
 (0)