Skip to content

Commit 391ddba

Browse files
authored
ATLAS-4963: checkstyle compliance updates - atlas-notification module (#280)
1 parent c482cc3 commit 391ddba

File tree

59 files changed

+1649
-1682
lines changed

Some content is hidden

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

59 files changed

+1649
-1682
lines changed

dev-support/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@
3535
<suppress files="AtlasGraphTraversalSource.java" checks="MethodName"/>
3636
<suppress files="DeleteHandlerV1.java" checks="MethodName"/>
3737
<suppress files="Id.java" checks="MethodName"/>
38+
<suppress files="KafkaNotification.java" checks="StaticVariableName"/>
3839
</suppressions>

notification/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
<name>Apache Atlas Notification</name>
3232
<description>Apache Atlas Notification</description>
3333

34+
<properties>
35+
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
36+
<checkstyle.skip>false</checkstyle.skip>
37+
</properties>
38+
3439
<dependencies>
3540

3641
<dependency>

notification/src/main/java/org/apache/atlas/hook/AtlasHook.java

Lines changed: 208 additions & 203 deletions
Large diffs are not rendered by default.

notification/src/main/java/org/apache/atlas/hook/AtlasHookException.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,6 @@
2121
* Exception class for Atlas Hooks.
2222
*/
2323
public class AtlasHookException extends Exception {
24-
2524
public AtlasHookException() {
2625
}
2726

notification/src/main/java/org/apache/atlas/hook/AtlasTopicCreator.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -39,11 +39,17 @@
3939
* Use this class to create a Kafka topic with specific configuration like number of partitions, replicas, etc.
4040
*/
4141
public class AtlasTopicCreator {
42-
4342
private static final Logger LOG = LoggerFactory.getLogger(AtlasTopicCreator.class);
4443

4544
public static final String ATLAS_NOTIFICATION_CREATE_TOPICS_KEY = "atlas.notification.create.topics";
4645

46+
public static void main(String[] args) throws AtlasException {
47+
Configuration configuration = ApplicationProperties.get();
48+
AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator();
49+
50+
atlasTopicCreator.createAtlasTopic(configuration, args);
51+
}
52+
4753
/**
4854
* Create an Atlas topic.
4955
*
@@ -61,46 +67,46 @@ public void createAtlasTopic(Configuration atlasProperties, String... topicNames
6167
if (!handleSecurity(atlasProperties)) {
6268
return;
6369
}
64-
try(KafkaUtils kafkaUtils = getKafkaUtils(atlasProperties)) {
70+
71+
try (KafkaUtils kafkaUtils = getKafkaUtils(atlasProperties)) {
6572
int numPartitions = atlasProperties.getInt("atlas.notification.partitions", 1);
66-
int numReplicas = atlasProperties.getInt("atlas.notification.replicas", 1);
73+
int numReplicas = atlasProperties.getInt("atlas.notification.replicas", 1);
74+
6775
kafkaUtils.createTopics(Arrays.asList(topicNames), numPartitions, numReplicas);
6876
} catch (Exception e) {
69-
LOG.error("Error while creating topics e :" + e.getMessage(), e);
77+
LOG.error("Error while creating topics e :{}", e.getMessage(), e);
7078
}
7179
} else {
72-
LOG.info("Not creating topics {} as {} is false", StringUtils.join(topicNames, ","),
73-
ATLAS_NOTIFICATION_CREATE_TOPICS_KEY);
80+
LOG.info("Not creating topics {} as {} is false", StringUtils.join(topicNames, ","), ATLAS_NOTIFICATION_CREATE_TOPICS_KEY);
7481
}
7582
}
7683

7784
@VisibleForTesting
7885
protected boolean handleSecurity(Configuration atlasProperties) {
7986
if (AuthenticationUtil.isKerberosAuthenticationEnabled(atlasProperties)) {
80-
String kafkaPrincipal = atlasProperties.getString("atlas.notification.kafka.service.principal");
81-
String kafkaKeyTab = atlasProperties.getString("atlas.notification.kafka.keytab.location");
82-
org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
87+
String kafkaPrincipal = atlasProperties.getString("atlas.notification.kafka.service.principal");
88+
String kafkaKeyTab = atlasProperties.getString("atlas.notification.kafka.keytab.location");
89+
org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
90+
8391
SecurityUtil.setAuthenticationMethod(UserGroupInformation.AuthenticationMethod.KERBEROS, hadoopConf);
92+
8493
try {
8594
String serverPrincipal = SecurityUtil.getServerPrincipal(kafkaPrincipal, (String) null);
95+
8696
UserGroupInformation.setConfiguration(hadoopConf);
8797
UserGroupInformation.loginUserFromKeytab(serverPrincipal, kafkaKeyTab);
8898
} catch (IOException e) {
8999
LOG.warn("Could not login as {} from keytab file {}", kafkaPrincipal, kafkaKeyTab, e);
100+
90101
return false;
91102
}
92103
}
104+
93105
return true;
94106
}
95107

96108
// This method is added to mock the creation of kafkaUtils object while writing the test cases
97109
KafkaUtils getKafkaUtils(Configuration configuration) {
98110
return new KafkaUtils(configuration);
99111
}
100-
101-
public static void main(String[] args) throws AtlasException {
102-
Configuration configuration = ApplicationProperties.get();
103-
AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator();
104-
atlasTopicCreator.createAtlasTopic(configuration, args);
105-
}
106112
}

notification/src/main/java/org/apache/atlas/hook/FailedMessagesLogger.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,11 +18,9 @@
1818

1919
package org.apache.atlas.hook;
2020

21-
2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
2423

25-
2624
/**
2725
* A logger wrapper that can be used to write messages that failed to be sent to a log file.
2826
*/
@@ -32,4 +30,4 @@ public class FailedMessagesLogger {
3230
public void log(String message) {
3331
LOG.info(message);
3432
}
35-
}
33+
}

notification/src/main/java/org/apache/atlas/kafka/AtlasKafkaConsumer.java

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,6 +21,11 @@
2121
import org.apache.atlas.notification.AtlasNotificationMessageDeserializer;
2222
import org.apache.atlas.notification.NotificationInterface;
2323
import org.apache.commons.collections.MapUtils;
24+
import org.apache.kafka.clients.consumer.ConsumerRecord;
25+
import org.apache.kafka.clients.consumer.ConsumerRecords;
26+
import org.apache.kafka.clients.consumer.KafkaConsumer;
27+
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
28+
import org.apache.kafka.common.TopicPartition;
2429
import org.slf4j.Logger;
2530
import org.slf4j.LoggerFactory;
2631

@@ -29,12 +34,6 @@
2934
import java.util.List;
3035
import java.util.Map;
3136

32-
import org.apache.kafka.clients.consumer.ConsumerRecord;
33-
import org.apache.kafka.clients.consumer.ConsumerRecords;
34-
import org.apache.kafka.clients.consumer.KafkaConsumer;
35-
import org.apache.kafka.common.TopicPartition;
36-
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
37-
3837
/**
3938
* Kafka specific notification consumer.
4039
*
@@ -45,7 +44,7 @@ public class AtlasKafkaConsumer<T> extends AbstractNotificationConsumer<T> {
4544

4645
private final KafkaConsumer kafkaConsumer;
4746
private final boolean autoCommitEnabled;
48-
private long pollTimeoutMilliSeconds = 1000L;
47+
private final long pollTimeoutMilliSeconds;
4948

5049
public AtlasKafkaConsumer(NotificationInterface.NotificationType notificationType, KafkaConsumer kafkaConsumer, boolean autoCommitEnabled, long pollTimeoutMilliSeconds) {
5150
this(notificationType.getDeserializer(), kafkaConsumer, autoCommitEnabled, pollTimeoutMilliSeconds);
@@ -59,32 +58,11 @@ public AtlasKafkaConsumer(AtlasNotificationMessageDeserializer<T> deserializer,
5958
this.pollTimeoutMilliSeconds = pollTimeoutMilliSeconds;
6059
}
6160

62-
public List<AtlasKafkaMessage<T>> receive() {
63-
return this.receive(this.pollTimeoutMilliSeconds);
64-
}
65-
66-
@Override
67-
public List<AtlasKafkaMessage<T>> receive(long timeoutMilliSeconds) {
68-
return receive(this.pollTimeoutMilliSeconds, null);
69-
}
70-
71-
@Override
72-
public List<AtlasKafkaMessage<T>> receiveWithCheckedCommit(Map<TopicPartition, Long> lastCommittedPartitionOffset) {
73-
return receive(this.pollTimeoutMilliSeconds, lastCommittedPartitionOffset);
74-
}
75-
76-
@Override
77-
public List<AtlasKafkaMessage<T>> receiveRawRecordsWithCheckedCommit(Map<TopicPartition, Long> lastCommittedPartitionOffset) {
78-
return receiveRawRecords(this.pollTimeoutMilliSeconds, lastCommittedPartitionOffset);
79-
}
80-
81-
8261
@Override
8362
public void commit(TopicPartition partition, long offset) {
8463
if (!autoCommitEnabled) {
85-
if (LOG.isDebugEnabled()) {
86-
LOG.info(" commiting the offset ==>> " + offset);
87-
}
64+
LOG.debug(" commiting the offset ==>> {}", offset);
65+
8866
kafkaConsumer.commitSync(Collections.singletonMap(partition, new OffsetAndMetadata(offset)));
8967
}
9068
}
@@ -103,6 +81,25 @@ public void wakeup() {
10381
}
10482
}
10583

84+
public List<AtlasKafkaMessage<T>> receive() {
85+
return this.receive(this.pollTimeoutMilliSeconds);
86+
}
87+
88+
@Override
89+
public List<AtlasKafkaMessage<T>> receive(long timeoutMilliSeconds) {
90+
return receive(this.pollTimeoutMilliSeconds, null);
91+
}
92+
93+
@Override
94+
public List<AtlasKafkaMessage<T>> receiveWithCheckedCommit(Map<TopicPartition, Long> lastCommittedPartitionOffset) {
95+
return receive(this.pollTimeoutMilliSeconds, lastCommittedPartitionOffset);
96+
}
97+
98+
@Override
99+
public List<AtlasKafkaMessage<T>> receiveRawRecordsWithCheckedCommit(Map<TopicPartition, Long> lastCommittedPartitionOffset) {
100+
return receiveRawRecords(this.pollTimeoutMilliSeconds, lastCommittedPartitionOffset);
101+
}
102+
106103
private List<AtlasKafkaMessage<T>> receiveRawRecords(long timeoutMilliSeconds, Map<TopicPartition, Long> lastCommittedPartitionOffset) {
107104
return receive(timeoutMilliSeconds, lastCommittedPartitionOffset, true);
108105
}
@@ -112,7 +109,7 @@ private List<AtlasKafkaMessage<T>> receive(long timeoutMilliSeconds, Map<TopicPa
112109
}
113110

114111
private List<AtlasKafkaMessage<T>> receive(long timeoutMilliSeconds, Map<TopicPartition, Long> lastCommittedPartitionOffset, boolean isRawDataRequired) {
115-
List<AtlasKafkaMessage<T>> messages = new ArrayList();
112+
List<AtlasKafkaMessage<T>> messages = new ArrayList<>();
116113

117114
ConsumerRecords<?, ?> records = kafkaConsumer != null ? kafkaConsumer.poll(timeoutMilliSeconds) : null;
118115

@@ -127,10 +124,9 @@ private List<AtlasKafkaMessage<T>> receive(long timeoutMilliSeconds, Map<TopicPa
127124
if (MapUtils.isNotEmpty(lastCommittedPartitionOffset)
128125
&& lastCommittedPartitionOffset.containsKey(topicPartition)
129126
&& record.offset() < lastCommittedPartitionOffset.get(topicPartition)) {
130-
131127
commit(topicPartition, record.offset());
132128
LOG.info("Skipping already processed message: topic={}, partition={} offset={}. Last processed offset={}",
133-
record.topic(), record.partition(), record.offset(), lastCommittedPartitionOffset.get(topicPartition));
129+
record.topic(), record.partition(), record.offset(), lastCommittedPartitionOffset.get(topicPartition));
134130
continue;
135131
}
136132

@@ -147,21 +143,18 @@ private List<AtlasKafkaMessage<T>> receive(long timeoutMilliSeconds, Map<TopicPa
147143
continue;
148144
}
149145

150-
AtlasKafkaMessage kafkaMessage = null;
146+
AtlasKafkaMessage kafkaMessage;
151147

152148
if (isRawDataRequired) {
153-
kafkaMessage = new AtlasKafkaMessage(message, record.offset(), record.topic(), record.partition(),
154-
deserializer.getMsgCreated(), deserializer.getSpooled(), deserializer.getSource(), record.value().toString());
149+
kafkaMessage = new AtlasKafkaMessage(message, record.offset(), record.topic(), record.partition(), deserializer.getMsgCreated(), deserializer.getSpooled(), deserializer.getSource(), record.value().toString());
155150
} else {
156-
kafkaMessage = new AtlasKafkaMessage(message, record.offset(), record.topic(), record.partition(),
157-
deserializer.getMsgCreated(), deserializer.getSpooled(), deserializer.getSource());
151+
kafkaMessage = new AtlasKafkaMessage(message, record.offset(), record.topic(), record.partition(), deserializer.getMsgCreated(), deserializer.getSpooled(), deserializer.getSource());
158152
}
159153

160154
messages.add(kafkaMessage);
161155
}
162156
}
163157

164158
return messages;
165-
166159
}
167160
}

notification/src/main/java/org/apache/atlas/kafka/AtlasKafkaMessage.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
9-
*
10-
* http://www.apache.org/licenses/LICENSE-2.0
11-
*
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -79,7 +79,11 @@ public long getMsgCreated() {
7979
return this.msgCreated;
8080
}
8181

82-
public String getSource() { return this.source; }
82+
public String getSource() {
83+
return this.source;
84+
}
8385

84-
public String getRawRecordData() { return this.rawRecordData; }
86+
public String getRawRecordData() {
87+
return this.rawRecordData;
88+
}
8589
}

0 commit comments

Comments
 (0)