|
@@ -1,12 +1,16 @@
|
|
package com.provectus.kafka.ui.config;
|
|
package com.provectus.kafka.ui.config;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Properties;
|
|
import java.util.Properties;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
@Configuration
|
|
@Configuration
|
|
@ConfigurationProperties("kafka")
|
|
@ConfigurationProperties("kafka")
|
|
@@ -49,4 +53,31 @@ public class ClustersProperties {
|
|
String username;
|
|
String username;
|
|
String password;
|
|
String password;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @PostConstruct
|
|
|
|
+ public void validateAndSetDefaults() {
|
|
|
|
+ validateClusterNames();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void validateClusterNames() {
|
|
|
|
+ // if only one cluster provided it is ok not to set name
|
|
|
|
+ if (clusters.size() == 1 && StringUtils.isEmpty(clusters.get(0).getName())) {
|
|
|
|
+ clusters.get(0).setName("Default");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Set<String> clusterNames = new HashSet<>();
|
|
|
|
+ for (Cluster clusterProperties : clusters) {
|
|
|
|
+ if (StringUtils.isEmpty(clusterProperties.getName())) {
|
|
|
|
+ throw new IllegalStateException(
|
|
|
|
+ "Application config isn't valid. "
|
|
|
|
+ + "Cluster names should be provided in case of multiple clusters present");
|
|
|
|
+ }
|
|
|
|
+ if (!clusterNames.add(clusterProperties.getName())) {
|
|
|
|
+ throw new IllegalStateException(
|
|
|
|
+ "Application config isn't valid. Two clusters can't have the same name");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|