33
44package oracle .weblogic .kubernetes ;
55
6+ import java .io .File ;
7+ import java .io .FileOutputStream ;
68import java .net .InetAddress ;
79import java .nio .file .Files ;
810import java .nio .file .Path ;
1416import java .util .LinkedHashMap ;
1517import java .util .List ;
1618import java .util .Map ;
17-
19+ import java .util .Properties ;
20+
21+ import io .kubernetes .client .custom .Quantity ;
22+ import oracle .weblogic .domain .Configuration ;
23+ import oracle .weblogic .domain .CreateIfNotExists ;
24+ import oracle .weblogic .domain .DomainCreationImage ;
25+ import oracle .weblogic .domain .DomainOnPV ;
26+ import oracle .weblogic .domain .DomainOnPVType ;
27+ import oracle .weblogic .domain .DomainResource ;
1828import oracle .weblogic .kubernetes .actions .impl .primitive .Command ;
1929import oracle .weblogic .kubernetes .actions .impl .primitive .CommandParams ;
30+ import oracle .weblogic .kubernetes .actions .impl .primitive .WitParams ;
2031import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
2132import oracle .weblogic .kubernetes .annotations .Namespaces ;
2233import oracle .weblogic .kubernetes .logging .LoggingFacade ;
3344import static java .nio .file .StandardCopyOption .REPLACE_EXISTING ;
3445import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
3546import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
47+ import static oracle .weblogic .kubernetes .TestConstants .BASE_IMAGES_REPO_SECRET_NAME ;
3648import static oracle .weblogic .kubernetes .TestConstants .CLUSTER_VERSION ;
3749import static oracle .weblogic .kubernetes .TestConstants .DEFAULT_EXTERNAL_SERVICE_NAME_SUFFIX ;
3850import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
51+ import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_IMAGES_PREFIX ;
3952import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_STATUS_CONDITION_COMPLETED_TYPE ;
4053import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
4154import static oracle .weblogic .kubernetes .TestConstants .ENCRYPION_PASSWORD_DEFAULT ;
4861import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_NAME ;
4962import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_TAG ;
5063import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_WDT_MODEL_FILE ;
64+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
5165import static oracle .weblogic .kubernetes .TestConstants .OLD_DOMAIN_VERSION ;
5266import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
67+ import static oracle .weblogic .kubernetes .TestConstants .RESULTS_TEMPFILE ;
5368import static oracle .weblogic .kubernetes .TestConstants .SKIP_CLEANUP ;
5469import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTP_HOSTPORT ;
5570import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TO_USE_IN_SPEC ;
6681import static oracle .weblogic .kubernetes .utils .ApplicationUtils .deployAndAccessApplication ;
6782import static oracle .weblogic .kubernetes .utils .ApplicationUtils .verifyAdminConsoleAccessible ;
6883import static oracle .weblogic .kubernetes .utils .ApplicationUtils .verifyAdminServerRESTAccess ;
84+ import static oracle .weblogic .kubernetes .utils .AuxiliaryImageUtils .createAndPushAuxiliaryImage ;
6985import static oracle .weblogic .kubernetes .utils .AuxiliaryImageUtils .createPushAuxiliaryImageWithDomainConfig ;
7086import static oracle .weblogic .kubernetes .utils .CommonMiiTestUtils .verifyPodsNotRolled ;
7187import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkServiceExists ;
7288import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createIngressHostRouting ;
7389import static oracle .weblogic .kubernetes .utils .CommonTestUtils .formatIPv6Host ;
90+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
91+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getUniqueName ;
7492import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
93+ import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
94+ import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainResourceOnPv ;
7595import static oracle .weblogic .kubernetes .utils .DomainUtils .verifyDomainStatusConditionTypeDoesNotExist ;
7696import static oracle .weblogic .kubernetes .utils .FileUtils .generateFileFromTemplate ;
7797import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
98+ import static oracle .weblogic .kubernetes .utils .FmwUtils .getConfiguration ;
99+ import static oracle .weblogic .kubernetes .utils .FmwUtils .verifyDomainReady ;
78100import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
79101import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
80102import static oracle .weblogic .kubernetes .utils .PatchDomainUtils .patchServerStartPolicy ;
81103import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodDeleted ;
82104import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodReady ;
83105import static oracle .weblogic .kubernetes .utils .PodUtils .getExternalServicePodName ;
84106import static oracle .weblogic .kubernetes .utils .PodUtils .getPodCreationTime ;
107+ import static oracle .weblogic .kubernetes .utils .PodUtils .setPodAntiAffinity ;
85108import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
86109import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
87110import static oracle .weblogic .kubernetes .utils .UpgradeUtils .checkCrdVersion ;
@@ -162,6 +185,46 @@ void testOperatorUpgradeMiiDomainV8From409ToCurrent() {
162185 installOperatorCreateMiiDomainAndUpgrade ("4.0.9" , OLD_DOMAIN_VERSION , DEFAULT_EXTERNAL_SERVICE_NAME_SUFFIX );
163186 }
164187
188+ /**
189+ * Operator upgrade from 4.2.9 to current with DPV domain in V9 schema.
190+ */
191+ @ Test
192+ @ DisplayName ("Upgrade Operator from 4.2.9 to current" )
193+ void testOperatorUpgradeDomainOnPVV9From429ToCurrent () {
194+ logger .info ("Starting test testOperatorUpgradeDomainOnPVV9From429ToCurrent, domain v9 schema" );
195+ installOperatorCreatesPvPvcWlsDomainAndUpgrade ("4.2.9" );
196+ }
197+
198+ /**
199+ * Operator upgrade from 4.2.8 to current with DPV domain in V9 schema.
200+ */
201+ @ Test
202+ @ DisplayName ("Upgrade Operator from 4.2.8 to current" )
203+ void testOperatorUpgradeDomainOnPVV9From428ToCurrent () {
204+ logger .info ("Starting test testOperatorUpgradeDomainOnPVV9From428ToCurrent, domain v9 schema" );
205+ installOperatorCreatesPvPvcWlsDomainAndUpgrade ("4.2.8" );
206+ }
207+
208+ /**
209+ * Operator upgrade from 4.1.8 to current with DPV domain in V9 schema.
210+ */
211+ @ Test
212+ @ DisplayName ("Upgrade Operator from 4.1.8 to current" )
213+ void testOperatorUpgradeDomainOnPVV9From418ToCurrent () {
214+ logger .info ("Starting test testOperatorUpgradeDomainOnPVV9From418ToCurrent, domain v9 schema" );
215+ installOperatorCreatesPvPvcWlsDomainAndUpgrade ("4.1.8" );
216+ }
217+
218+ /**
219+ * Operator upgrade from 4.1.7 to current with DPV domain in V9 schema.
220+ */
221+ @ Test
222+ @ DisplayName ("Upgrade Operator from 4.1.7 to current" )
223+ void testOperatorUpgradeDomainOnPVV9From417ToCurrent () {
224+ logger .info ("Starting test testOperatorUpgradeDomainOnPVV9From417ToCurrent, domain v9 schema" );
225+ installOperatorCreatesPvPvcWlsDomainAndUpgrade ("4.1.7" );
226+ }
227+
165228 /**
166229 * Upgrade Operator from 4.0.10 to current with Auxiliary image domain, V9 schema.
167230 */
@@ -172,7 +235,6 @@ void testOperatorUpgradeAuxDomainV9From4010ToCurrent() {
172235 installOperatorCreateAuxDomainAndUpgrade ("4.0.10" , DOMAIN_VERSION );
173236 }
174237
175-
176238 /**
177239 * Upgrade Operator from 4.1.7 to current with Mii domain in V8 schema.
178240 */
@@ -216,29 +278,6 @@ void testOperatorUpgradeMiiDomainV8From426ToCurrent() {
216278 installOperatorCreateMiiDomainAndUpgrade ("4.2.6" , OLD_DOMAIN_VERSION , DEFAULT_EXTERNAL_SERVICE_NAME_SUFFIX );
217279 }
218280
219- /**
220- * Operator upgrade from 3.4.13 to current with Auxiliary Image Domain, V8 schema.
221- * V9 schema is from Operator 4.0.
222- */
223- @ Test
224- @ DisplayName ("Upgrade 3.4.13 Auxiliary Domain(v8 schema) Image to current" )
225- void testOperatorUpgradeAuxDomainV8From3413ToCurrent () {
226- logger .info ("Starting testOperatorUpgradeAuxDomainV8From3413ToCurrent "
227- + "to upgrade Domain with Auxiliary Image with v8 schema to current" );
228- installOperatorCreateAuxDomainAndUpgrade ("3.4.13" , OLD_DOMAIN_VERSION );
229- }
230-
231- /**
232- * Upgrade Operator from 3.4.12 to current with Mii domain in V8 schema.
233- */
234- @ Test
235- @ DisplayName ("Upgrade 3.4.12 Mii Domain(v8 schema) Image to current" )
236- void testOperatorUpgradeMiiDomainV8From3412ToCurrent () {
237- logger .info ("Starting testOperatorWlsAuxDomainV8UpgradeFrom3412ToCurrent "
238- + "to upgrade MII Domain with v8 schema to current" );
239- installOperatorCreateMiiDomainAndUpgrade ("3.4.12" , OLD_DOMAIN_VERSION , DEFAULT_EXTERNAL_SERVICE_NAME_SUFFIX );
240- }
241-
242281 /**
243282 * Cleanup Kubernetes artifacts in the namespaces used by the test and
244283 * delete CRD.
@@ -323,6 +362,93 @@ void installOperatorCreateAuxDomainAndUpgrade(String operatorVersion, String dom
323362 scaleClusterUpAndDown (domainApiVersion );
324363 }
325364
365+ void installOperatorCreatesPvPvcWlsDomainAndUpgrade (String operatorVersion ) {
366+ final String storageClassName = "weblogic-domain-storage-class" ;
367+ String domainHomePrefix = "/shared/" + domainNamespace + "/domains/" ;
368+ final String clusterName = "cluster-1" ;
369+ final String pvName = getUniqueName (domainUid + "-pv-" );
370+ final String pvcName = getUniqueName (domainUid + "-pvc-" );
371+ final int t3ChannelPort = getNextFreePort ();
372+ final String wlsModelFile = "model-wlsdomain-onpv-simplified.yaml" ;
373+
374+ logger .info ("Upgrade version/{0} Auxiliary Domain(v9) to current" , operatorVersion );
375+ installOldOperator (operatorVersion , opNamespace , domainNamespace );
376+ createSecrets ();
377+
378+ // Create the repo secret to pull base WebLogic image
379+ createBaseRepoSecret (domainNamespace );
380+
381+ // create a model property file
382+ File wlsModelPropFile = createWdtPropertyFile ("wlsonpv-upgrade" );
383+
384+ // create domainCreationImage
385+ String domainCreationImageName = DOMAIN_IMAGES_PREFIX + "wls-domain-on-pv-upgrade" ;
386+ // create image with model and wdt installation files
387+ WitParams witParams
388+ = new WitParams ()
389+ .modelImageName (domainCreationImageName )
390+ .modelImageTag (MII_BASIC_IMAGE_TAG )
391+ .modelFiles (Collections .singletonList (MODEL_DIR + "/" + wlsModelFile ))
392+ .modelVariableFiles (Collections .singletonList (wlsModelPropFile .getAbsolutePath ()));
393+ createAndPushAuxiliaryImage (domainCreationImageName , MII_BASIC_IMAGE_TAG , witParams );
394+
395+ DomainCreationImage domainCreationImage
396+ = new DomainCreationImage ().image (domainCreationImageName + ":" + MII_BASIC_IMAGE_TAG );
397+
398+ // create a domain resource
399+ logger .info ("Creating domain custom resource" );
400+ Map <String , Quantity > pvCapacity = new HashMap <>();
401+ pvCapacity .put ("storage" , new Quantity ("2Gi" ));
402+
403+ Map <String , Quantity > pvcRequest = new HashMap <>();
404+ pvcRequest .put ("storage" , new Quantity ("2Gi" ));
405+ Configuration configuration = null ;
406+ if (OKE_CLUSTER ) {
407+ configuration = getConfiguration (pvcName , pvcRequest , "oci-fss" );
408+ } else {
409+ configuration = getConfiguration (pvName , pvcName , pvCapacity , pvcRequest , storageClassName ,
410+ this .getClass ().getSimpleName ());
411+ }
412+ configuration .getInitializeDomainOnPV ().domain (new DomainOnPV ()
413+ .createMode (CreateIfNotExists .DOMAIN )
414+ .domainCreationImages (Collections .singletonList (domainCreationImage ))
415+ .domainType (DomainOnPVType .WLS ));
416+ DomainResource domain = createDomainResourceOnPv (domainUid ,
417+ domainNamespace ,
418+ adminSecretName ,
419+ clusterName ,
420+ pvName ,
421+ pvcName ,
422+ new String []{BASE_IMAGES_REPO_SECRET_NAME },
423+ domainHomePrefix ,
424+ replicaCount ,
425+ 0 ,
426+ configuration );
427+
428+ // Set the inter-pod anti-affinity for the domain custom resource
429+ setPodAntiAffinity (domain );
430+
431+ // create a domain custom resource and verify domain is created
432+ createDomainAndVerify (domain , domainNamespace );
433+
434+ // verify that all servers are ready
435+ verifyDomainReady (domainNamespace , domainUid , replicaCount , "nosuffix" );
436+ LinkedHashMap <String , OffsetDateTime > pods = new LinkedHashMap <>();
437+ pods .put (adminServerPodName , getPodCreationTime (domainNamespace , adminServerPodName ));
438+ // get the creation time of the managed server pods before upgrading the operator
439+ for (int i = 1 ; i <= replicaCount ; i ++) {
440+ pods .put (managedServerPodNamePrefix + i , getPodCreationTime (domainNamespace , managedServerPodNamePrefix + i ));
441+ }
442+ // verify there is no status condition type Completed
443+ // before upgrading to Latest
444+ verifyDomainStatusConditionTypeDoesNotExist (domainUid , domainNamespace ,
445+ DOMAIN_STATUS_CONDITION_COMPLETED_TYPE , DOMAIN_VERSION );
446+ upgradeOperatorToCurrent (opNamespace );
447+ checkDomainStatus (domainNamespace , domainUid );
448+ verifyPodsNotRolled (domainNamespace , pods );
449+ scaleClusterUpAndDown (clusterName );
450+ }
451+
326452 // After upgrade scale up/down the cluster
327453 private void scaleClusterUpAndDown (String domainApiVersion ) {
328454
@@ -603,5 +729,25 @@ private void verifyDomain(String domainUidString, String domainNamespace, String
603729 String .valueOf (serviceNodePort ), false );
604730 }
605731 }
732+
733+ private File createWdtPropertyFile (String wlsModelFilePrefix ) {
734+
735+ // create property file used with domain model file
736+ Properties p = new Properties ();
737+ p .setProperty ("adminUsername" , ADMIN_USERNAME_DEFAULT );
738+ p .setProperty ("adminPassword" , ADMIN_PASSWORD_DEFAULT );
739+
740+ // create a model property file
741+ File domainPropertiesFile = assertDoesNotThrow (() ->
742+ File .createTempFile (wlsModelFilePrefix , ".properties" , new File (RESULTS_TEMPFILE )),
743+ "Failed to create WLS model properties file" );
606744
745+ // create the property file
746+ assertDoesNotThrow (() ->
747+ p .store (new FileOutputStream (domainPropertiesFile ), "WLS properties file" ),
748+ "Failed to write WLS properties file" );
749+
750+ return domainPropertiesFile ;
751+ }
752+
607753}
0 commit comments