Skip to content

Commit

Permalink
simplify the clowder json property source for endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgitario committed Apr 2, 2024
1 parent 4980e1d commit 20acc70
Showing 1 changed file with 30 additions and 46 deletions.
Expand Up @@ -116,9 +116,9 @@ public class ClowderJsonPathPropertySource extends PropertySource<ClowderJson>
KAFKA_TOPICS,
this::getKafkaTopicProperty,
ENDPOINTS,
this::getEndpointProperty,
this::getPublicEndpointProperty,
PRIVATE_ENDPOINTS,
this::getEndpointProperty);
this::getPrivateEndpointProperty);

private static final String SERVLET_ENVIRONMENT_CLASS =
"org.springframework.web.context.support.StandardServletEnvironment";
Expand Down Expand Up @@ -163,14 +163,6 @@ public Object getProperty(String name) {
return null;
}

private Object determineEndpointConfig(String name, EndpointConfigMapper value) {
if (name.contains(ENDPOINTS)) {
return getEndpointConfig(name, value);
} else {
return getPrivateEndpointConfig(name, value);
}
}

protected String getTruststorePath() {
if (trustStoreConfiguration == null) {
initializeTrustStoreConfiguration();
Expand Down Expand Up @@ -241,11 +233,6 @@ private Object getKafkaTopicProperty(String name) {
}

private Object getEndpointProperty(String name) {
for (Map.Entry<String, EndpointConfigMapper> entry : ENDPOINTS_PROPERTIES.entrySet()) {
if (name.endsWith(entry.getKey())) {
return determineEndpointConfig(name, entry.getValue());
}
}

return null;
}
Expand Down Expand Up @@ -475,38 +462,35 @@ private Object getKafkaBrokerConfig(KafkaBrokerConfigMapper configFunction) {
return configFunction.apply(brokers);
}

private Object getEndpointConfig(String name, EndpointConfigMapper configFunction) {
var endpoints = source.getNodeAsListOfMaps(ENDPOINTS);
if (endpoints.isEmpty()) {
return null;
}
String endpoint = extractName(name, ENDPOINTS);
Map<String, Object> found =
endpoints.stream()
.filter(c -> endpoint.equals(getEndpointName(c)))
.findFirst()
.orElseThrow(
() ->
new IllegalStateException(
"Could not find the endpoint configuration for property: " + name));
return configFunction.apply(this, found);
}

private Object getPrivateEndpointConfig(String name, EndpointConfigMapper configFunction) {
var endpoints = source.getNodeAsListOfMaps(PRIVATE_ENDPOINTS);
if (endpoints.isEmpty()) {
return null;
private Object getPublicEndpointProperty(String name) {
return getEndpointConfig(ENDPOINTS, name);
}

private Object getPrivateEndpointProperty(String name) {
return getEndpointConfig(PRIVATE_ENDPOINTS, name);
}

private Object getEndpointConfig(String property, String name) {
for (Map.Entry<String, EndpointConfigMapper> entry : ENDPOINTS_PROPERTIES.entrySet()) {
if (name.endsWith(entry.getKey())) {
var endpoints = source.getNodeAsListOfMaps(property);
if (endpoints.isEmpty()) {
return null;
}
String endpoint = extractName(name, property);
Map<String, Object> found =
endpoints.stream()
.filter(c -> endpoint.equals(getEndpointName(c)))
.findFirst()
.orElseThrow(
() ->
new IllegalStateException(
"Could not find the endpoint configuration for property: " + name));
return entry.getValue().apply(this, found);
}
}
String endpoint = extractName(name, PRIVATE_ENDPOINTS);
Map<String, Object> found =
endpoints.stream()
.filter(c -> endpoint.equals(getEndpointName(c)))
.findFirst()
.orElseThrow(
() ->
new IllegalStateException(
"Could not find the private endpoint configuration for property: " + name));
return configFunction.apply(this, found);

return null;
}

private Object getKafkaTopicConfig(String name, KafkaTopicConfigMapper configFunction) {
Expand Down

0 comments on commit 20acc70

Please sign in to comment.