Skip to content

Commit c10d1ec

Browse files
committed
OWLS-69919 Add logHome properties, change domainHomeInImage default to true
1 parent e89c2f4 commit c10d1ec

File tree

6 files changed

+150
-8
lines changed

6 files changed

+150
-8
lines changed

model/src/main/java/oracle/kubernetes/weblogic/domain/DomainConfigurator.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected DomainConfigurator(Domain domain) {
3737
/**
3838
* Sets the home for the domain.
3939
*
40-
* @param home the home of the domain
40+
* @param domainHome the home of the domain
4141
* @return this object
4242
*/
4343
public DomainConfigurator withDomainHome(String domainHome) {
@@ -46,7 +46,7 @@ public DomainConfigurator withDomainHome(String domainHome) {
4646
}
4747

4848
/**
49-
* @param homeInImage
49+
* @param domainHomeInImage
5050
* @return
5151
*/
5252
public DomainConfigurator withDomainHomeInImage(boolean domainHomeInImage) {
@@ -110,6 +110,28 @@ public DomainConfigurator withDefaultImagePullSecrets(
110110
return this;
111111
}
112112

113+
/**
114+
* Sets the log home value
115+
*
116+
* @param logHome the log home value
117+
* @return this object
118+
*/
119+
public DomainConfigurator withLogHome(String logHome) {
120+
getDomainSpec().setLogHome(logHome);
121+
return this;
122+
}
123+
124+
/**
125+
* Sets the log home enabled flag
126+
*
127+
* @param logHomeEnabled true if log home is enabled, false otherwise
128+
* @return this object
129+
*/
130+
public DomainConfigurator withLogHomeEnabled(boolean logHomeEnabled) {
131+
getDomainSpec().setLogHomeEnabled(logHomeEnabled);
132+
return this;
133+
}
134+
113135
/**
114136
* Configures the domain to use a persistent volume claim defined before the domain is created.
115137
*

model/src/main/java/oracle/kubernetes/weblogic/domain/v2/DomainSpec.java

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class DomainSpec extends BaseConfiguration {
3333
/** The pattern for computing the default persistent volume claim name. */
3434
private static final String PVC_NAME_PATTERN = "%s-weblogic-domain-pvc";
3535

36+
/** The pattern for computing the default shared logs directory. */
37+
private static final String LOG_HOME_DEFAULT_PATTERN = "/shared/logs/%s";
38+
3639
/** Domain unique identifier. Must be unique across the Kubernetes cluster. (Required) */
3740
@SerializedName("domainUID")
3841
@Expose
@@ -143,7 +146,9 @@ public class DomainSpec extends BaseConfiguration {
143146
*/
144147
@SerializedName("domainHomeInImage")
145148
@Expose
146-
private boolean domainHomeInImage;
149+
@Description(
150+
"Flag indicating whether the domain home is part of the image. Default value is true. ")
151+
private boolean domainHomeInImage = true;
147152

148153
/** The definition of the storage used for this domain. */
149154
@SerializedName("storage")
@@ -204,6 +209,29 @@ public class DomainSpec extends BaseConfiguration {
204209
@Description("Configuration for the clusters")
205210
protected Map<String, Cluster> clusters = new HashMap<>();
206211

212+
/**
213+
* The log home.
214+
*
215+
* @since 2.0
216+
*/
217+
@SerializedName("logHome")
218+
@Expose
219+
@Description("The folder for the log files (Not required). Defaults to /shared/logs/domainUID. ")
220+
protected String logHome;
221+
222+
/**
223+
* Whether the log home is enabled.
224+
*
225+
* @since 2.0
226+
*/
227+
@SerializedName("logHomeEnabled")
228+
@Expose
229+
@Description(
230+
"Specified whether the log home folder is enabled (Not required). "
231+
+ "Defaults to true if domainHomeInImage is false. "
232+
+ "Defaults to false if domainHomeInImage is true. ")
233+
private Boolean logHomeEnabled; // Boolean object, null if unspecified
234+
207235
public AdminServer getOrCreateAdminServer(String adminServerName) {
208236
if (adminServer != null) return adminServer;
209237

@@ -303,6 +331,49 @@ public void setDomainHome(String domainHome) {
303331
this.domainHome = domainHome;
304332
}
305333

334+
/**
335+
* Log home
336+
*
337+
* @since 2.0
338+
* @return log home
339+
*/
340+
public String getLogHome() {
341+
return Optional.ofNullable(logHome).orElse(String.format(LOG_HOME_DEFAULT_PATTERN, domainUID));
342+
}
343+
344+
/**
345+
* Log home
346+
*
347+
* @since 2.0
348+
* @param logHome log home
349+
*/
350+
public void setLogHome(String logHome) {
351+
this.logHome = logHome;
352+
}
353+
354+
/**
355+
* Log home enabled
356+
*
357+
* @since 2.0
358+
* @return log home enabled
359+
*/
360+
public boolean getLogHomeEnabled() {
361+
if (logHomeEnabled == null) {
362+
return !isDomainHomeInImage();
363+
}
364+
return logHomeEnabled.booleanValue();
365+
}
366+
367+
/**
368+
* Log home enabled
369+
*
370+
* @since 2.0
371+
* @param logHomeEnabled log home enabled
372+
*/
373+
public void setLogHomeEnabled(boolean logHomeEnabled) {
374+
this.logHomeEnabled = new Boolean(logHomeEnabled);
375+
}
376+
306377
/*
307378
* Fluent api for setting the image.
308379
*

model/src/test/java/oracle/kubernetes/weblogic/domain/v2/DomainV2Test.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,55 @@ public void whenDuplicateVolumeMountsConfiguredOnMultipleLevels_useCombination()
12211221
volumeMount("name3", "/server-test1")));
12221222
}
12231223

1224+
@Test
1225+
public void whenDefaultConfiguration_domainHomeInImage() {
1226+
configureDomain(domain);
1227+
1228+
assertThat(domain.getSpec().isDomainHomeInImage(), is(true));
1229+
}
1230+
1231+
@Test
1232+
public void whenDomainHomeInImageSpecified_useValue() {
1233+
configureDomain(domain).withDomainHomeInImage(false);
1234+
1235+
assertThat(domain.getSpec().isDomainHomeInImage(), is(false));
1236+
}
1237+
1238+
@Test
1239+
public void whenLogHomeNotSet_useDefault() {
1240+
configureDomain(domain);
1241+
1242+
assertThat(domain.getSpec().getLogHome(), equalTo("/shared/logs/uid1"));
1243+
}
1244+
1245+
@Test
1246+
public void whenLogHomeSet_useValue() {
1247+
configureDomain(domain).withLogHome("/custom/logs");
1248+
1249+
assertThat(domain.getSpec().getLogHome(), equalTo("/custom/logs"));
1250+
}
1251+
1252+
@Test
1253+
public void whenDomainHomeInImage_logHomeNotEnabled() {
1254+
configureDomain(domain).withDomainHomeInImage(true);
1255+
1256+
assertThat(domain.getSpec().getLogHomeEnabled(), is(false));
1257+
}
1258+
1259+
@Test
1260+
public void whenDomainHomeNotInImage_logHomeEnabled() {
1261+
configureDomain(domain).withDomainHomeInImage(false);
1262+
1263+
assertThat(domain.getSpec().getLogHomeEnabled(), is(true));
1264+
}
1265+
1266+
@Test
1267+
public void whenLogHomeEnabledSet_useValue() {
1268+
configureDomain(domain).withLogHomeEnabled(true);
1269+
1270+
assertThat(domain.getSpec().getLogHomeEnabled(), is(true));
1271+
}
1272+
12241273
@Test
12251274
public void domainHomeTest_standardHome2() {
12261275
configureDomain(domain).withDomainHomeInImage(false);

operator/src/test/java/oracle/kubernetes/operator/helpers/AdminPodHelperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void whenDomainHasEnvironmentItemsWithVariables_createAdminPodStartupWith
254254
assertThat(
255255
getCreatedPodSpecContainer().getEnv(),
256256
allOf(
257-
hasEnvVar("item1", "find uid1 at /shared/domains/uid1"),
257+
hasEnvVar("item1", "find uid1 at /shared/domain"),
258258
hasEnvVar("item2", "ADMIN_SERVER is ADMIN_SERVER:7001")));
259259
}
260260

operator/src/test/java/oracle/kubernetes/operator/helpers/ManagedPodHelperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ManagedPodHelperTest extends PodHelperTestBase {
4646
private static final String VALUE1 = "value1";
4747
private static final String VALUE2 = "value2";
4848
private static final String RAW_VALUE_1 = "find uid1 at $(DOMAIN_HOME)";
49-
private static final String END_VALUE_1 = "find uid1 at /shared/domains/uid1";
49+
private static final String END_VALUE_1 = "find uid1 at /shared/domain";
5050
private static final String RAW_VALUE_2 = "$(SERVER_NAME) is not $(ADMIN_NAME):$(ADMIN_PORT)";
5151
private static final String END_VALUE_2 = "ms1 is not ADMIN_SERVER:7001";
5252
private static final String CLUSTER_NAME = "test-cluster";

operator/src/test/java/oracle/kubernetes/operator/helpers/PodHelperTestBase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public void whenPodCreated_hasPredefinedEnvVariables() {
340340
getCreatedPodSpecContainer().getEnv(),
341341
allOf(
342342
hasEnvVar("DOMAIN_NAME", DOMAIN_NAME),
343-
hasEnvVar("DOMAIN_HOME", "/shared/domains/" + UID),
343+
hasEnvVar("DOMAIN_HOME", "/shared/domain"),
344344
hasEnvVar("ADMIN_NAME", ADMIN_SERVER),
345345
hasEnvVar("ADMIN_PORT", Integer.toString(ADMIN_PORT)),
346346
hasEnvVar("SERVER_NAME", getServerName()),
@@ -563,7 +563,7 @@ V1ObjectMeta createPodMetadata() {
563563
.putLabelsItem(RESOURCE_VERSION_LABEL, VersionConstants.DEFAULT_DOMAIN_VERSION)
564564
.putLabelsItem(LabelConstants.DOMAINUID_LABEL, UID)
565565
.putLabelsItem(LabelConstants.DOMAINNAME_LABEL, DOMAIN_NAME)
566-
.putLabelsItem(LabelConstants.DOMAINHOME_LABEL, "/shared/domains/" + UID)
566+
.putLabelsItem(LabelConstants.DOMAINHOME_LABEL, "/shared/domain")
567567
.putLabelsItem(LabelConstants.SERVERNAME_LABEL, getServerName())
568568
.putLabelsItem(LabelConstants.CREATEDBYOPERATOR_LABEL, "true");
569569
}
@@ -589,7 +589,7 @@ V1Container createPodSpecContainer() {
589589
.readOnly(true))
590590
.command(createStartCommand())
591591
.addEnvItem(envItem("DOMAIN_NAME", DOMAIN_NAME))
592-
.addEnvItem(envItem("DOMAIN_HOME", "/shared/domains/" + UID))
592+
.addEnvItem(envItem("DOMAIN_HOME", "/shared/domain"))
593593
.addEnvItem(envItem("ADMIN_NAME", ADMIN_SERVER))
594594
.addEnvItem(envItem("ADMIN_PORT", Integer.toString(ADMIN_PORT)))
595595
.addEnvItem(envItem("SERVER_NAME", getServerName()))

0 commit comments

Comments
 (0)