|
9 | 9 | import io.kubernetes.client.openapi.models.V1ObjectMeta; |
10 | 10 | import java.io.IOException; |
11 | 11 | import java.io.StringReader; |
| 12 | +import java.util.List; |
12 | 13 | import java.util.Map; |
13 | 14 | import java.util.NoSuchElementException; |
14 | 15 | import java.util.Optional; |
15 | 16 | import java.util.Properties; |
| 17 | +import java.util.stream.Collectors; |
16 | 18 | import lombok.RequiredArgsConstructor; |
17 | 19 | import lombok.extern.slf4j.Slf4j; |
18 | 20 |
|
@@ -40,50 +42,41 @@ public void read(DataSet input, String serviceLabel, Map<String, Map<String, Str |
40 | 42 | { |
41 | 43 | new RetryCommand<Void>(retryConfig).run(() -> |
42 | 44 | { |
43 | | - boolean foundAll = kubernetesGetObjectMetaCommand.get(serviceLabel, POD, input.getServiceName(), apiClient) |
| 45 | + kubernetesGetObjectMetaCommand.get(serviceLabel, POD, input.getServiceName(), apiClient) |
44 | 46 | .map(V1ObjectMeta::getName) |
45 | | - .map(podName -> exec(podName, input, propertiesFilesCheck, apiClient)) |
46 | | - .orElse(false); |
47 | | - |
48 | | - if (!foundAll) |
49 | | - { |
50 | | - throw new NoSuchElementException(String.format("Properties %s not found.", propertiesFilesCheck)); |
51 | | - } |
| 47 | + .ifPresent(podName -> exec(podName, input, propertiesFilesCheck, apiClient)); |
52 | 48 | return null; |
53 | 49 | }); |
54 | 50 | } |
55 | 51 |
|
56 | 52 |
|
57 | | - private Boolean exec(final String podName, DataSet input, final Map<String, Map<String, String>> propertiesFilesCheck, final ApiClient apiClient) |
| 53 | + private void exec(final String podName, DataSet input, final Map<String, Map<String, String>> propertiesFilesCheck, final ApiClient apiClient) |
58 | 54 | { |
59 | | - return propertiesFilesCheck.entrySet().stream().allMatch(it -> { |
60 | | - Optional<String> podFileProps = kubernetesExecCommand.exec(podName, String.format(ENV_COMMAND, it.getKey()), apiClient); |
| 55 | + propertiesFilesCheck.forEach((propFilePath, propKeys) -> { |
| 56 | + Optional<String> podFileProps = kubernetesExecCommand.exec(podName, String.format(ENV_COMMAND, propFilePath), apiClient); |
61 | 57 | if (podFileProps.isPresent()) |
62 | 58 | { |
63 | 59 | Properties props = parse(podFileProps.get()); |
64 | | - return matchProps(input, it.getKey(), it.getValue(), props); |
| 60 | + matchProps(input, propFilePath, propKeys, props); |
65 | 61 | } |
66 | 62 | else |
67 | 63 | { |
68 | | - log.info("Properties not found in {} at POD {}", it.getKey(), podName); |
69 | | - return false; |
| 64 | + log.info("Properties file {} not found in POD {}. Properties: {} will be skipped", propFilePath, podName, String.join(",", propKeys.keySet())); |
70 | 65 | } |
71 | 66 | }); |
72 | 67 | } |
73 | 68 |
|
74 | 69 |
|
75 | | - private boolean matchProps(DataSet input, String propFilePath, Map<String, String> propKeys, Properties props) |
| 70 | + private void matchProps(DataSet input, String propFilePath, Map<String, String> propKeys, Properties props) |
76 | 71 | { |
77 | | - return propKeys.entrySet().stream().allMatch(prop -> { |
78 | | - if (props.containsKey(prop.getValue())) |
| 72 | + propKeys.forEach((key, value) -> { |
| 73 | + if (props.containsKey(value)) |
79 | 74 | { |
80 | | - input.setAdditionalInformation(prop.getKey(), props.get(prop.getValue())); |
81 | | - return true; |
| 75 | + input.setAdditionalInformation(key, props.get(value)); |
82 | 76 | } |
83 | 77 | else |
84 | 78 | { |
85 | | - log.info("Property Key {}, not found at {}", prop.getValue(), propFilePath); |
86 | | - return false; |
| 79 | + log.info("Property Key {}, not found at {}", value, propFilePath); |
87 | 80 | } |
88 | 81 | }); |
89 | 82 | } |
|
0 commit comments