@@ -49,7 +49,9 @@ public class SchemaConversionUtils {
49
49
private static final String CLUSTERS = "clusters" ;
50
50
private static final String CLUSTER_NAME = "clusterName" ;
51
51
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" ;
53
55
private static final String PRESERVED_AUX = "weblogic.v8.preserved.aux" ;
54
56
private static final String ADDED_ACPFE = "weblogic.v8.adminChannelPortForwardingEnabled" ;
55
57
private static final String FAILED_REASON = "weblogic.v8.failed.reason" ;
@@ -134,24 +136,36 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
134
136
convertDomainStatusTargetV8 (domain );
135
137
constantsToCamelCase (spec );
136
138
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 );
138
149
restore (PRESERVED_AUX , domain , this ::validateRestoreLegacyAuxilaryImages );
139
150
removeAddedAdminChannelPortForwardingEnabled (domain );
140
151
} else {
152
+ restore (PRESERVED_V9 , domain );
153
+
141
154
adjustAdminPortForwardingDefault (domain , spec , apiVersion );
142
155
convertDomainStatusTargetV9 (domain );
143
156
convertDomainHomeInImageToDomainHomeSourceType (domain );
144
157
moveConfigOverrides (domain );
145
158
moveConfigOverrideSecrets (domain );
146
159
constantsToCamelCase (spec );
147
160
adjustReplicasDefault (spec , apiVersion );
161
+ adjustLogHomeLayoutDefault (spec , apiVersion );
148
162
removeWebLogicCredentialsSecretNamespace (spec , apiVersion );
149
163
150
164
try {
151
165
Map <String , Object > toBePreserved = new TreeMap <>();
152
166
removeAndPreserveLegacyAuxiliaryImages (spec , toBePreserved );
153
167
154
- preserve (PRESERVED_AUX , domain , toBePreserved , apiVersion );
168
+ preserveV8 (PRESERVED_AUX , domain , toBePreserved , apiVersion );
155
169
} catch (IOException io ) {
156
170
throw new RuntimeException (io ); // need to use unchecked exception because of stream processing
157
171
}
@@ -163,7 +177,7 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
163
177
removeAndPreserveServerStartState (spec , toBePreserved );
164
178
removeAndPreserveIstio (spec , toBePreserved );
165
179
166
- preserve ( PRESERVED , domain , toBePreserved , apiVersion );
180
+ preserveV8 ( PRESERVED_V8 , domain , toBePreserved , apiVersion );
167
181
} catch (IOException io ) {
168
182
throw new RuntimeException (io ); // need to use unchecked exception because of stream processing
169
183
}
@@ -456,8 +470,6 @@ private void constantsToCamelCase(Map<String, Object> spec) {
456
470
convertServerStartPolicy ((Map <String , Object >) managedServer )));
457
471
458
472
Optional .ofNullable (getConfiguration (spec )).ifPresent (this ::convertOverrideDistributionStrategy );
459
-
460
- convertLogHomeLayout (spec );
461
473
}
462
474
463
475
private void convertServerStartPolicy (Map <String , Object > spec ) {
@@ -509,19 +521,6 @@ private Object overrideDistributionStrategyCamelCase(String key, Object value) {
509
521
return convertWithMap (select (overrideDistributionStrategyMap , invertOverrideDistributionStrategyMap ), value );
510
522
}
511
523
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
-
525
524
private Map <String , Object > getConfiguration (Map <String , Object > spec ) {
526
525
return (Map <String , Object >) spec .get ("configuration" );
527
526
}
@@ -768,6 +767,19 @@ private void adjustReplicasDefault(Map<String, Object> spec, String apiVersion)
768
767
}
769
768
}
770
769
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
+
771
783
private void removeAndPreserveIstio (Map <String , Object > spec , Map <String , Object > toBePreserved ) {
772
784
Optional .ofNullable (getConfiguration (spec )).ifPresent (configuration -> {
773
785
Object existing = configuration .remove ("istio" );
@@ -854,16 +866,27 @@ private void preserve(Map<String, Object> toBePreserved, String key, Map<String,
854
866
}
855
867
856
868
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 )
858
870
throws IOException {
859
- if (!toBePreserved .isEmpty () && API_VERSION_V8 .equals (apiVersion )) {
871
+ if (!toBePreserved .isEmpty () && ( API_VERSION_V8 .equals (apiVersion ) == targetV8 )) {
860
872
Map <String , Object > meta = getMetadata (domain );
861
873
Map <String , Object > annotations = (Map <String , Object >) meta .computeIfAbsent (
862
874
ANNOTATIONS , k -> new LinkedHashMap <>());
863
875
annotations .put (annoName , new ObjectMapper ().writeValueAsString (toBePreserved ));
864
876
}
865
877
}
866
878
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
+
867
890
private void removeAddedAdminChannelPortForwardingEnabled (Map <String , Object > domain ) {
868
891
withAnnotation (ADDED_ACPFE , domain , labelValue -> {
869
892
if ("true" .equals (labelValue )) {
0 commit comments