Skip to content

Commit fac8b4a

Browse files
committed
Allow user to specify default installer versions in user config
1 parent e41bc70 commit fac8b4a

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/settings/UserSettings.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.file.Paths;
1111
import java.util.Map;
1212

13+
import com.oracle.weblogic.imagetool.installer.InstallerType;
1314
import com.oracle.weblogic.imagetool.logging.LoggingFacade;
1415
import com.oracle.weblogic.imagetool.logging.LoggingFactory;
1516
import com.oracle.weblogic.imagetool.util.Utils;
@@ -65,6 +66,11 @@ public class UserSettings {
6566
*/
6667
private final Integer aruRetryInterval;
6768

69+
/**
70+
* The time between each ARU REST call in milliseconds.
71+
*/
72+
private final Map<String, Object> installers;
73+
6874
/**
6975
* Default construct with all default values for settings.
7076
*/
@@ -77,6 +83,7 @@ public UserSettings() {
7783

7884
aruRetryMax = null;
7985
aruRetryInterval = null;
86+
installers = null;
8087
}
8188

8289
/**
@@ -94,6 +101,8 @@ public UserSettings(Map<String, Object> settings) {
94101

95102
aruRetryMax = getValue("aruRetryMax", Integer.class, settings);
96103
aruRetryInterval = getValue("aruRetryInterval", Integer.class, settings);
104+
105+
installers = getValue("installers", Map.class, settings);
97106
}
98107

99108
/**
@@ -130,18 +139,22 @@ public static UserSettings load(InputStream settings) {
130139
}
131140

132141
private <T> T getValue(String settingName, Class<T> type, Map<String, Object> settings) {
142+
if (settings == null) {
143+
return null;
144+
}
145+
133146
Object value = settings.get(settingName);
134147
if (value == null) {
135148
return null;
136149
}
137150

138151
if (type.isInstance(value)) {
139152
return type.cast(value);
140-
} else {
141-
logger.severe("Setting for {0} could not be loaded. Expected {1}, but found {2}. Invalid value: {3}",
142-
settingName, type, value.getClass(), value.toString());
143-
return null;
144153
}
154+
155+
logger.severe("Setting for {0} could not be loaded. Expected {1}, but found {2}. Invalid value: {3}",
156+
settingName, type, value.getClass(), value.toString());
157+
return null;
145158
}
146159

147160
/**
@@ -222,6 +235,22 @@ public int getAruRetryInterval() {
222235
return aruRetryInterval;
223236
}
224237

238+
/**
239+
* The settings asscociated with the installers to be used.
240+
* @return a map of settings for installers
241+
*/
242+
public Map<String,Object> getInstallers() {
243+
return installers;
244+
}
245+
246+
public String getDefaultInstallerVersion(InstallerType installerType) {
247+
if (installers == null) {
248+
return null;
249+
}
250+
Map<String, Object> installerSettings = getValue(installerType.toString(), Map.class, installers);
251+
return getValue("defaultVersion", String.class, installerSettings);
252+
}
253+
225254
/**
226255
* UserSettings as a YAML string.
227256
* @return UserSettings as a YAML string.

imagetool/src/test/java/com/oracle/weblogic/imagetool/settings/UserSettingsTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.InputStream;
77

8+
import com.oracle.weblogic.imagetool.installer.InstallerType;
89
import org.junit.jupiter.api.Test;
910

1011
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -25,6 +26,16 @@ void testSimpleSettingsFile() {
2526
assertEquals(200, settings.getAruRetryInterval());
2627
}
2728

29+
@Test
30+
void testDefaultInstallers() {
31+
InputStream inputStream = this.getClass()
32+
.getClassLoader()
33+
.getResourceAsStream("settings/basic_settings.yaml");
34+
UserSettings settings = UserSettings.load(inputStream);
35+
assertEquals("8u241", settings.getDefaultInstallerVersion(InstallerType.JDK));
36+
assertEquals("12.2.1.4.0", settings.getDefaultInstallerVersion(InstallerType.WLS));
37+
}
38+
2839
@Test
2940
void testInvalidSettings() {
3041
InputStream inputStream = this.getClass()
@@ -40,6 +51,13 @@ void testOutput() {
4051
//TODO: re-enable this test
4152
String expected = "aruRetryInterval: 200\n"
4253
+ "imageBuildDirectory: ./builds\n"
54+
+ "installers:\n"
55+
+ " JDK:\n"
56+
+ " defaultVersion: 8u241\n"
57+
+ " WLS:\n"
58+
+ " defaultVersion: 12.2.1.4.0\n"
59+
+ " WDT:\n"
60+
+ " defaultVersion: latest"
4361
+ "patchDirectory: /home/user/patches\n";
4462

4563
InputStream inputStream = this.getClass()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
aruRetryInterval: 200
22
imageBuildDirectory: ./builds
3+
installers:
4+
jdk:
5+
defaultVersion: 8u241
6+
wls:
7+
defaultVersion: 12.2.1.4.0
8+
wdt:
9+
defaultVersion: latest
310
patchDirectory: /home/user/patches

0 commit comments

Comments
 (0)