Skip to content

Commit bc93f95

Browse files
authored
Update to SpringBoot 2.0.x (#65)
* start required refactoring for springboot 2.0 * finish refactoring Repository methods * finish refactoring Repository methods in tests * Fix models annotations * finish refactoring * refactoring configuration files * migrate remaining configuration files * bump dependency versions * Update POM release version to 2.0.0
1 parent 6d43259 commit bc93f95

File tree

29 files changed

+224
-170
lines changed

29 files changed

+224
-170
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
The format is based on [Keep a Changelog](http://keepachangelog.com/)
33
and this project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## 2.0.0 (UNRELEASED)
6+
7+
### Breaking Changes
8+
- Updated SpringBoot framework from 1.5.x to 2.0.4
9+
TODO Write migration guide
10+
511
## 1.0.5 (06/22/2018)
612
- [Issue#75](https://github.com/SourceLabOrg/kafka-webview/issues/75) Bugfix Add Jackson serializer that falls back to using toString() when consuming entries from Kafka.
713
- [Issue#72](https://github.com/SourceLabOrg/kafka-webview/issues/72) Bugfix User role input not displayed when creating new user.

kafka-webview-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.sourcelab</groupId>
77
<artifactId>kafka-webview</artifactId>
8-
<version>1.0.5</version>
8+
<version>2.0.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>kafka-webview-plugin</artifactId>

kafka-webview-ui/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<parent>
66
<artifactId>kafka-webview</artifactId>
77
<groupId>org.sourcelab</groupId>
8-
<version>1.0.5</version>
8+
<version>2.0.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111
<artifactId>kafka-webview-ui</artifactId>
12-
<version>1.0.5</version>
12+
<version>2.0.0</version>
1313

1414
<!-- Module Description and Ownership -->
1515
<name>Kafka WebView UI</name>
@@ -111,6 +111,12 @@
111111
<version>1.2.1</version>
112112
</dependency>
113113

114+
<dependency>
115+
<groupId>javax.xml.bind</groupId>
116+
<artifactId>jaxb-api</artifactId>
117+
<version>2.3.0</version>
118+
</dependency>
119+
114120
<!-- Allows for auto-reloading resources -->
115121
<dependency>
116122
<groupId>org.springframework.boot</groupId>
@@ -134,7 +140,7 @@
134140
<dependency>
135141
<groupId>com.salesforce.kafka.test</groupId>
136142
<artifactId>kafka-junit4</artifactId>
137-
<version>3.0.0</version>
143+
<version>3.0.1</version>
138144
<scope>test</scope>
139145
</dependency>
140146
<dependency>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
server:
22
port: 8080
33

4-
security:
5-
require-ssl: false
6-
74
## Various App Configs
85
app:
96
## Should be unique to your installation.
107
## This key will be used for symmetric encryption of JKS/TrustStore secrets if you configure any SSL enabled Kafka clusters.
118
key: "SuperSecretKey"
129

1310
## Defines a prefix prepended to the Id of all consumers.
14-
consumerIdPrefix: "KafkaWebViewConsumer"
11+
consumerIdPrefix: "KafkaWebViewConsumer"
12+
13+
## Require SSL
14+
require-ssl: false

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/AppProperties.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ public class AppProperties {
4848
@Value("${app.consumerIdPrefix}")
4949
private String consumerIdPrefix;
5050

51+
@Value("${app.require_ssl:false}")
52+
private boolean requireSsl = false;
53+
5154
public String getName() {
5255
return name;
5356
}
@@ -68,6 +71,10 @@ public String getConsumerIdPrefix() {
6871
return consumerIdPrefix;
6972
}
7073

74+
public boolean isRequireSsl() {
75+
return requireSsl;
76+
}
77+
7178
@Override
7279
public String toString() {
7380
return "AppProperties{"
@@ -76,6 +83,7 @@ public String toString() {
7683
+ ", appKey='XXXXXX'"
7784
+ ", maxConcurrentWebSocketConsumers=" + maxConcurrentWebSocketConsumers
7885
+ ", consumerIdPrefix='" + consumerIdPrefix + '\''
86+
+ ", requireSsl='" + requireSsl + '\''
7987
+ '}';
8088
}
8189
}

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/configuration/SecurityConfig.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
import org.sourcelab.kafka.webview.ui.manager.user.CustomUserDetailsService;
2828
import org.sourcelab.kafka.webview.ui.repository.UserRepository;
2929
import org.springframework.beans.factory.annotation.Autowired;
30-
import org.springframework.boot.autoconfigure.security.SecurityProperties;
30+
import org.springframework.beans.factory.annotation.Value;
3131
import org.springframework.context.annotation.Bean;
3232
import org.springframework.context.annotation.Configuration;
33-
import org.springframework.core.annotation.Order;
3433
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
3534
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
3635
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
@@ -45,14 +44,17 @@
4544
*/
4645
@Configuration
4746
@EnableWebSecurity
48-
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
4947
public class SecurityConfig extends WebSecurityConfigurerAdapter {
5048

5149
@Autowired
5250
private UserRepository userRepository;
5351

54-
@Autowired
55-
private SecurityProperties securityProperties;
52+
/**
53+
* Allows for requiring all requests over SSL.
54+
* If not defined in the config under the key security.require_ssl, we default to false.
55+
*/
56+
@Value("${app.require_ssl:false}")
57+
private boolean isRequireSsl;
5658

5759
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
5860

@@ -99,7 +101,7 @@ protected void configure(final HttpSecurity http) throws Exception {
99101
.permitAll();
100102

101103
// If require SSL is enabled
102-
if (securityProperties.isRequireSsl()) {
104+
if (isRequireSsl) {
103105
// Ensure its enabled.
104106
http
105107
.requiresChannel()

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/controller/api/ApiController.java

Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import java.util.HashSet;
6666
import java.util.List;
6767
import java.util.Map;
68+
import java.util.Optional;
6869
import java.util.Set;
6970

7071
/**
@@ -97,25 +98,11 @@ public KafkaResults consume(
9798
@PathVariable final Long id,
9899
@RequestBody final ConsumeRequest consumeRequest) {
99100

100-
// How many results per partition to consume
101-
// Null means use whatever is configured in the view.
102-
final Integer resultsPerPartition = consumeRequest.getResultsPerPartition();
103-
104-
// Comma separated list of partitions to consume from.
105-
// Null or empty string means use whatever is configured in the View.
106-
final String partitions = consumeRequest.getPartitions();
107-
108101
// Action describes what to consume 'next', 'prev', 'head', 'tail'
109102
final String action = consumeRequest.getAction();
110103

111-
// Any custom configured filters
112-
final List<ConsumeRequest.Filter> requestFilters = consumeRequest.getFilters();
113-
114104
// Retrieve the view definition
115-
final View view = viewRepository.findOne(id);
116-
if (view == null) {
117-
throw new NotFoundApiException("Consume", "Unable to find view");
118-
}
105+
final View view = retrieveViewById(id);
119106

120107
// Override settings
121108
final ViewCustomizer viewCustomizer = new ViewCustomizer(view, consumeRequest);
@@ -149,11 +136,8 @@ public KafkaResults consume(
149136
@ResponseBody
150137
@RequestMapping(path = "/consumer/view/{id}/offsets", method = RequestMethod.POST, produces = "application/json")
151138
public ConsumerState setConsumerOffsets(@PathVariable final Long id, @RequestBody final Map<Integer, Long> partitionOffsetMap) {
152-
// Retrieve the view definition
153-
final View view = viewRepository.findOne(id);
154-
if (view == null) {
155-
throw new NotFoundApiException("Offsets", "Unable to find view");
156-
}
139+
// Retrieve View
140+
final View view = retrieveViewById(id);
157141

158142
// Create consumer
159143
try (final WebKafkaConsumer webKafkaConsumer = setup(view, new HashSet<>())) {
@@ -169,11 +153,8 @@ public ConsumerState setConsumerOffsets(@PathVariable final Long id, @RequestBo
169153
@ResponseBody
170154
@RequestMapping(path = "/consumer/view/{id}/timestamp/{timestamp}", method = RequestMethod.POST, produces = "application/json")
171155
public ConsumerState setConsumerOffsetsByTimestamp(@PathVariable final Long id, @PathVariable final Long timestamp) {
172-
// Retrieve the view definition
173-
final View view = viewRepository.findOne(id);
174-
if (view == null) {
175-
throw new NotFoundApiException("OffsetsByTimestamp", "Unable to find view");
176-
}
156+
// Retrieve View
157+
final View view = retrieveViewById(id);
177158

178159
// Create consumer
179160
try (final WebKafkaConsumer webKafkaConsumer = setup(view, new HashSet<>())) {
@@ -190,10 +171,7 @@ public ConsumerState setConsumerOffsetsByTimestamp(@PathVariable final Long id,
190171
@RequestMapping(path = "/view/{id}/partitions", method = RequestMethod.GET, produces = "application/json")
191172
public Collection<Integer> getPartitionsForView(@PathVariable final Long id) {
192173
// Retrieve View
193-
final View view = viewRepository.findOne(id);
194-
if (view == null) {
195-
throw new NotFoundApiException("Partitions", "Unable to find view");
196-
}
174+
final View view = retrieveViewById(id);
197175

198176
// If the view has defined partitions, we'll return them
199177
if (!view.getPartitionsAsSet().isEmpty()) {
@@ -221,10 +199,7 @@ public Collection<Integer> getPartitionsForView(@PathVariable final Long id) {
221199
@RequestMapping(path = "/cluster/{id}/topics/list", method = RequestMethod.GET, produces = "application/json")
222200
public List<TopicListing> getTopics(@PathVariable final Long id) {
223201
// Retrieve cluster
224-
final Cluster cluster = clusterRepository.findOne(id);
225-
if (cluster == null) {
226-
throw new NotFoundApiException("Topics", "Unable to find cluster");
227-
}
202+
final Cluster cluster = retrieveClusterById(id);
228203

229204
// Create new Operational Client
230205
try (final KafkaOperations operations = createOperationsClient(cluster)) {
@@ -242,10 +217,7 @@ public List<TopicListing> getTopics(@PathVariable final Long id) {
242217
@RequestMapping(path = "/cluster/{id}/topic/{topic}/details", method = RequestMethod.GET, produces = "application/json")
243218
public TopicDetails getTopicDetails(@PathVariable final Long id, @PathVariable final String topic) {
244219
// Retrieve cluster
245-
final Cluster cluster = clusterRepository.findOne(id);
246-
if (cluster == null) {
247-
throw new NotFoundApiException("TopicDetails", "Unable to find cluster");
248-
}
220+
final Cluster cluster = retrieveClusterById(id);
249221

250222
// Create new Operational Client
251223
try (final KafkaOperations operations = createOperationsClient(cluster)) {
@@ -262,10 +234,7 @@ public TopicDetails getTopicDetails(@PathVariable final Long id, @PathVariable f
262234
@RequestMapping(path = "/cluster/{id}/topic/{topic}/config", method = RequestMethod.GET, produces = "application/json")
263235
public List<ConfigItem> getTopicConfig(@PathVariable final Long id, @PathVariable final String topic) {
264236
// Retrieve cluster
265-
final Cluster cluster = clusterRepository.findOne(id);
266-
if (cluster == null) {
267-
throw new NotFoundApiException("TopicConfig", "Unable to find cluster");
268-
}
237+
final Cluster cluster = retrieveClusterById(id);
269238

270239
// Create new Operational Client
271240
try (final KafkaOperations operations = createOperationsClient(cluster)) {
@@ -282,10 +251,7 @@ public List<ConfigItem> getTopicConfig(@PathVariable final Long id, @PathVariabl
282251
@RequestMapping(path = "/cluster/{id}/broker/{brokerId}/config", method = RequestMethod.GET, produces = "application/json")
283252
public List<ConfigItem> getBrokerConfig(@PathVariable final Long id, @PathVariable final String brokerId) {
284253
// Retrieve cluster
285-
final Cluster cluster = clusterRepository.findOne(id);
286-
if (cluster == null) {
287-
throw new NotFoundApiException("TopicConfig", "Unable to find cluster");
288-
}
254+
final Cluster cluster = retrieveClusterById(id);
289255

290256
// Create new Operational Client
291257
try (final KafkaOperations operations = createOperationsClient(cluster)) {
@@ -302,10 +268,7 @@ public List<ConfigItem> getBrokerConfig(@PathVariable final Long id, @PathVariab
302268
@RequestMapping(path = "/cluster/{id}/topics/details", method = RequestMethod.GET, produces = "application/json")
303269
public Collection<TopicDetails> getAllTopicsDetails(@PathVariable final Long id) {
304270
// Retrieve cluster
305-
final Cluster cluster = clusterRepository.findOne(id);
306-
if (cluster == null) {
307-
throw new NotFoundApiException("TopicDetails", "Unable to find cluster");
308-
}
271+
final Cluster cluster = retrieveClusterById(id);
309272

310273
// Create new Operational Client
311274
try (final KafkaOperations operations = createOperationsClient(cluster)) {
@@ -329,10 +292,7 @@ public Collection<TopicDetails> getAllTopicsDetails(@PathVariable final Long id)
329292
@RequestMapping(path = "/cluster/{id}/nodes", method = RequestMethod.GET, produces = "application/json")
330293
public List<NodeDetails> getClusterNodes(@PathVariable final Long id) {
331294
// Retrieve cluster
332-
final Cluster cluster = clusterRepository.findOne(id);
333-
if (cluster == null) {
334-
throw new NotFoundApiException("ClusterNodes", "Unable to find cluster");
335-
}
295+
final Cluster cluster = retrieveClusterById(id);
336296

337297
try (final KafkaOperations operations = createOperationsClient(cluster)) {
338298
final NodeList nodes = operations.getClusterNodes();
@@ -349,10 +309,7 @@ public List<NodeDetails> getClusterNodes(@PathVariable final Long id) {
349309
@RequestMapping(path = "/filter/{id}/options", method = RequestMethod.GET, produces = "application/json")
350310
public String[] getFilterOptions(@PathVariable final Long id) {
351311
// Retrieve Filter
352-
final Filter filter = filterRepository.findOne(id);
353-
if (filter == null) {
354-
throw new NotFoundApiException("FilterOptions", "Unable to find filter");
355-
}
312+
final Filter filter = retrieveFilterById(id);
356313
final String[] options = filter.getOptions().split(",");
357314

358315
return options;
@@ -391,4 +348,54 @@ private WebKafkaConsumer setup(final View view, final Collection<FilterDefinitio
391348
public void addAttributes(final Model model) {
392349
// Do nothing.
393350
}
351+
352+
/**
353+
* Helper method to retrieve a cluster by its Id. If its not found it will throw the appropriate
354+
* NotFoundApiException exception.
355+
*
356+
* @param id id of cluster to retrieve
357+
* @return the cluster entity.
358+
* @throws NotFoundApiException if not found.
359+
*/
360+
private Cluster retrieveClusterById(final Long id) throws NotFoundApiException {
361+
final Optional<Cluster> clusterOptional = clusterRepository.findById(id);
362+
if (!clusterOptional.isPresent()) {
363+
throw new NotFoundApiException("TopicConfig", "Unable to find cluster");
364+
}
365+
return clusterOptional.get();
366+
}
367+
368+
/**
369+
* Helper method to retrieve a view by its Id. If its not found it will throw the appropriate
370+
* NotFoundApiException exception.
371+
*
372+
* @param id id of view to retrieve
373+
* @return the view entity.
374+
* @throws NotFoundApiException if not found.
375+
*/
376+
private View retrieveViewById(final Long id) throws NotFoundApiException {
377+
// Retrieve View
378+
final Optional<View> viewOptional = viewRepository.findById(id);
379+
if (!viewOptional.isPresent()) {
380+
throw new NotFoundApiException("Partitions", "Unable to find view");
381+
}
382+
return viewOptional.get();
383+
}
384+
385+
/**
386+
* Helper method to retrieve a filter by its Id. If its not found it will throw the appropriate
387+
* NotFoundApiException exception.
388+
*
389+
* @param id id of filter to retrieve
390+
* @return the filter entity.
391+
* @throws NotFoundApiException if not found.
392+
*/
393+
private Filter retrieveFilterById(final Long id) throws NotFoundApiException {
394+
// Retrieve Filter
395+
final Optional<Filter> filterOptional = filterRepository.findById(id);
396+
if (!filterOptional.isPresent()) {
397+
throw new NotFoundApiException("FilterOptions", "Unable to find filter");
398+
}
399+
return filterOptional.get();
400+
}
394401
}

kafka-webview-ui/src/main/java/org/sourcelab/kafka/webview/ui/controller/cluster/ClusterController.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
import java.util.HashMap;
4242
import java.util.Map;
43+
import java.util.Optional;
4344

4445
/**
4546
* Controller for viewing Cluster details.
@@ -164,8 +165,8 @@ public String readTopic(
164165

165166
private Cluster retrieveCluster(final Long id, final RedirectAttributes redirectAttributes) {
166167
// Retrieve by id
167-
final Cluster cluster = clusterRepository.findOne(id);
168-
if (cluster == null) {
168+
final Optional<Cluster> clusterOptional = clusterRepository.findById(id);
169+
if (!clusterOptional.isPresent()) {
169170
// redirect
170171
// Set flash message
171172
final FlashMessage flashMessage = FlashMessage.newWarning("Unable to find cluster!");
@@ -174,7 +175,7 @@ private Cluster retrieveCluster(final Long id, final RedirectAttributes redirect
174175
// redirect to cluster index
175176
return null;
176177
}
177-
return cluster;
178+
return clusterOptional.get();
178179
}
179180

180181
private BreadCrumbManager setupBreadCrumbs(final Model model) {

0 commit comments

Comments
 (0)