@@ -49,7 +49,9 @@ public class SchemaConversionUtils {
4949 private static final String CLUSTERS = "clusters" ;
5050 private static final String CLUSTER_NAME = "clusterName" ;
5151 private static final String ACPFE = "adminChannelPortForwardingEnabled" ;
52- private static final String PRESERVED = "weblogic.v8.preserved" ;
52+ private static final String LHL = "logHomeLayout" ;
53+ private static final String PRESERVED_V9 = "weblogic.v9.preserved" ;
54+ private static final String PRESERVED_V8 = "weblogic.v8.preserved" ;
5355 private static final String PRESERVED_AUX = "weblogic.v8.preserved.aux" ;
5456 private static final String ADDED_ACPFE = "weblogic.v8.adminChannelPortForwardingEnabled" ;
5557 private static final String FAILED_REASON = "weblogic.v8.failed.reason" ;
@@ -134,24 +136,36 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
134136 convertDomainStatusTargetV8 (domain );
135137 constantsToCamelCase (spec );
136138
137- restore (PRESERVED , domain );
139+ try {
140+ Map <String , Object > toBePreserved = new TreeMap <>();
141+ removeAndPreserveLogHomeLayout (spec , toBePreserved );
142+
143+ preserveV9 (PRESERVED_V9 , domain , toBePreserved , apiVersion );
144+ } catch (IOException io ) {
145+ throw new RuntimeException (io ); // need to use unchecked exception because of stream processing
146+ }
147+
148+ restore (PRESERVED_V8 , domain );
138149 restore (PRESERVED_AUX , domain , this ::validateRestoreLegacyAuxilaryImages );
139150 removeAddedAdminChannelPortForwardingEnabled (domain );
140151 } else {
152+ restore (PRESERVED_V9 , domain );
153+
141154 adjustAdminPortForwardingDefault (domain , spec , apiVersion );
142155 convertDomainStatusTargetV9 (domain );
143156 convertDomainHomeInImageToDomainHomeSourceType (domain );
144157 moveConfigOverrides (domain );
145158 moveConfigOverrideSecrets (domain );
146159 constantsToCamelCase (spec );
147160 adjustReplicasDefault (spec , apiVersion );
161+ adjustLogHomeLayoutDefault (spec , apiVersion );
148162 removeWebLogicCredentialsSecretNamespace (spec , apiVersion );
149163
150164 try {
151165 Map <String , Object > toBePreserved = new TreeMap <>();
152166 removeAndPreserveLegacyAuxiliaryImages (spec , toBePreserved );
153167
154- preserve (PRESERVED_AUX , domain , toBePreserved , apiVersion );
168+ preserveV8 (PRESERVED_AUX , domain , toBePreserved , apiVersion );
155169 } catch (IOException io ) {
156170 throw new RuntimeException (io ); // need to use unchecked exception because of stream processing
157171 }
@@ -163,7 +177,7 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
163177 removeAndPreserveServerStartState (spec , toBePreserved );
164178 removeAndPreserveIstio (spec , toBePreserved );
165179
166- preserve ( PRESERVED , domain , toBePreserved , apiVersion );
180+ preserveV8 ( PRESERVED_V8 , domain , toBePreserved , apiVersion );
167181 } catch (IOException io ) {
168182 throw new RuntimeException (io ); // need to use unchecked exception because of stream processing
169183 }
@@ -456,8 +470,6 @@ private void constantsToCamelCase(Map<String, Object> spec) {
456470 convertServerStartPolicy ((Map <String , Object >) managedServer )));
457471
458472 Optional .ofNullable (getConfiguration (spec )).ifPresent (this ::convertOverrideDistributionStrategy );
459-
460- convertLogHomeLayout (spec );
461473 }
462474
463475 private void convertServerStartPolicy (Map <String , Object > spec ) {
@@ -509,19 +521,6 @@ private Object overrideDistributionStrategyCamelCase(String key, Object value) {
509521 return convertWithMap (select (overrideDistributionStrategyMap , invertOverrideDistributionStrategyMap ), value );
510522 }
511523
512- private void convertLogHomeLayout (Map <String , Object > configuration ) {
513- configuration .computeIfPresent ("logHomeLayout" , this ::logHomeLayoutCamelCase );
514- }
515-
516- private static final Map <String , String > logHomeLayoutMap = Map .of (
517- "FLAT" , "Flat" , "BY_SERVERS" , "ByServers" );
518-
519- private static final Map <String , String > invertLogHomeLayoutMap = invertMapUsingMapper (logHomeLayoutMap );
520-
521- private Object logHomeLayoutCamelCase (String key , Object value ) {
522- return convertWithMap (select (logHomeLayoutMap , invertLogHomeLayoutMap ), value );
523- }
524-
525524 private Map <String , Object > getConfiguration (Map <String , Object > spec ) {
526525 return (Map <String , Object >) spec .get ("configuration" );
527526 }
@@ -768,6 +767,19 @@ private void adjustReplicasDefault(Map<String, Object> spec, String apiVersion)
768767 }
769768 }
770769
770+ private void adjustLogHomeLayoutDefault (Map <String , Object > spec , String apiVersion ) {
771+ if (CommonConstants .API_VERSION_V8 .equals (apiVersion )) {
772+ spec .putIfAbsent (LHL , "Flat" );
773+ }
774+ }
775+
776+ private void removeAndPreserveLogHomeLayout (Map <String , Object > spec , Map <String , Object > toBePreserved ) {
777+ Object existing = Optional .ofNullable (spec .remove (LHL )).orElse ("ByServers" );
778+ if (!"Flat" .equals (existing )) {
779+ preserve (toBePreserved , "$.spec" , Map .of (LHL , existing ));
780+ }
781+ }
782+
771783 private void removeAndPreserveIstio (Map <String , Object > spec , Map <String , Object > toBePreserved ) {
772784 Optional .ofNullable (getConfiguration (spec )).ifPresent (configuration -> {
773785 Object existing = configuration .remove ("istio" );
@@ -854,16 +866,27 @@ private void preserve(Map<String, Object> toBePreserved, String key, Map<String,
854866 }
855867
856868 private void preserve (String annoName , Map <String , Object > domain ,
857- Map <String , Object > toBePreserved , String apiVersion )
869+ Map <String , Object > toBePreserved , String apiVersion , boolean targetV8 )
858870 throws IOException {
859- if (!toBePreserved .isEmpty () && API_VERSION_V8 .equals (apiVersion )) {
871+ if (!toBePreserved .isEmpty () && ( API_VERSION_V8 .equals (apiVersion ) == targetV8 )) {
860872 Map <String , Object > meta = getMetadata (domain );
861873 Map <String , Object > annotations = (Map <String , Object >) meta .computeIfAbsent (
862874 ANNOTATIONS , k -> new LinkedHashMap <>());
863875 annotations .put (annoName , new ObjectMapper ().writeValueAsString (toBePreserved ));
864876 }
865877 }
866878
879+ private void preserveV8 (String annoName , Map <String , Object > domain ,
880+ Map <String , Object > toBePreserved , String apiVersion ) throws IOException {
881+ preserve (annoName , domain , toBePreserved , apiVersion , true );
882+ }
883+
884+ private void preserveV9 (String annoName , Map <String , Object > domain ,
885+ Map <String , Object > toBePreserved , String apiVersion )
886+ throws IOException {
887+ preserve (annoName , domain , toBePreserved , apiVersion , false );
888+ }
889+
867890 private void removeAddedAdminChannelPortForwardingEnabled (Map <String , Object > domain ) {
868891 withAnnotation (ADDED_ACPFE , domain , labelValue -> {
869892 if ("true" .equals (labelValue )) {
0 commit comments