Skip to content

Commit d385d37

Browse files
committed
another attempt
1 parent 7dbd479 commit d385d37

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.net.URI;
88
import java.net.URISyntaxException;
99
import java.nio.charset.StandardCharsets;
10+
import java.nio.file.FileAlreadyExistsException;
1011
import java.nio.file.FileSystem;
1112
import java.nio.file.FileSystemAlreadyExistsException;
1213
import java.nio.file.FileSystems;
@@ -152,33 +153,30 @@ protected V1ConfigMap computeDomainConfigMap() {
152153
metadata.setLabels(labels);
153154

154155
cm.setMetadata(metadata);
155-
LOGGER.warning("xyz- computeDomainConfigMap called, cm.getData() is " + cm.getData());
156-
cm.setData(loadScripts());
157-
LOGGER.warning("xyz- computeDomainConfigMap called, cm.getData() after setData().size() is " + cm.getData().size());
156+
LOGGER.warning("xyz- computeDomainConfigMap called for domainNamespace:" + domainNamespace + ", cm.getData() is " + cm.getData());
157+
cm.setData(loadScripts(domainNamespace));
158+
LOGGER.warning("xyz- computeDomainConfigMap called for domainNamespace:" + domainNamespace + ", cm.getData() after setData().size() is " + cm.getData().size());
158159

159160
return cm;
160161
}
161-
Map<String, String> scripts;
162-
private synchronized Map<String, String> loadScripts() {
163-
if (scripts != null) {
164-
LOGGER.warning("xyz- computeDomainConfigMap loadScripts() returning previously loaded scripts");
165-
return scripts;
166-
}
162+
163+
private static synchronized Map<String, String> loadScripts(String domainNamespace) {
167164
URI uri = null;
168165
try {
169-
uri = getClass().getResource(SCRIPT_LOCATION).toURI();
166+
uri = ScriptConfigMapStep.class.getResource(SCRIPT_LOCATION).toURI();
170167
} catch (URISyntaxException e) {
171168
LOGGER.warning(MessageKeys.EXCEPTION, e);
172169
throw new RuntimeException(e);
173170
}
174-
171+
LOGGER.warning("xyz- loadScripts() domainNamespace:" + domainNamespace + ", uri is " + uri + ", scheme=" + uri.getScheme());
175172
try {
176173
if ("jar".equals(uri.getScheme())) {
177174
try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap())) {
178-
return scripts = walkScriptsPath(fileSystem.getPath(SCRIPTS));
175+
LOGGER.warning("xyz- walkScriptsPath for domainNamespace=" + domainNamespace + ", fileSystem=" + fileSystem);
176+
return walkScriptsPath(fileSystem.getPath(SCRIPTS), domainNamespace);
179177
}
180178
} else {
181-
return scripts = walkScriptsPath(Paths.get(uri));
179+
return walkScriptsPath(Paths.get(uri), domainNamespace);
182180
}
183181
// } catch (FileSystemAlreadyExistsException ale) {
184182
// LOGGER.warning(MessageKeys.EXCEPTION, new IOException("xyz-FileSystemAlreadyExistsException uri is " + uri));
@@ -189,12 +187,13 @@ private synchronized Map<String, String> loadScripts() {
189187
// throw new RuntimeException(e);
190188
// }
191189
} catch (IOException e) {
190+
LOGGER.warning(MessageKeys.EXCEPTION, new FileAlreadyExistsException("xyz- uri," + uri));
192191
LOGGER.warning(MessageKeys.EXCEPTION, e);
193192
throw new RuntimeException(e);
194193
}
195194
}
196195

197-
private Map<String, String> walkScriptsPath(Path scriptsDir) throws IOException {
196+
private static Map<String, String> walkScriptsPath(Path scriptsDir, String domainNamespace) throws IOException {
198197
try (Stream<Path> walk = Files.walk(scriptsDir, 1)) {
199198
Map<String, String> data = walk.filter(i -> !Files.isDirectory(i)).collect(Collectors.toMap(
200199
i -> i.getFileName().toString(),
@@ -204,7 +203,7 @@ private Map<String, String> walkScriptsPath(Path scriptsDir) throws IOException
204203
}
205204
}
206205

207-
private byte[] read(Path path) {
206+
private static byte[] read(Path path) {
208207
try {
209208
return Files.readAllBytes(path);
210209
} catch (IOException io) {

0 commit comments

Comments
 (0)