Skip to content

Commit d3f04ad

Browse files
authored
Update system test for online app updateDomain (#1160)
* Update system test for online updating app and refactor applications_deployer * update system test for online application update and refactor applications_deployer
1 parent d94dfb0 commit d3f04ad

File tree

7 files changed

+196
-13
lines changed

7 files changed

+196
-13
lines changed

core/src/main/python/wlsdeploy/tool/deploy/applications_deployer.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,15 @@ def __shouldCheckForTargetChange(self, src_path, model_src_path):
620620
# or if the model sourcepath + domain home is exactly equal to the running's app source path.
621621
# return True otherwise return False
622622
if not os.path.isabs(model_src_path):
623-
return self.model_context.get_domain_home() + '/' + model_src_path == src_path
623+
return FileUtils.getCanonicalPath(self.model_context.get_domain_home() + '/' + model_src_path) == src_path
624624
else:
625625
return FileUtils.getCanonicalPath(src_path) == FileUtils.getCanonicalPath(model_src_path)
626626

627+
def __append_to_stop_and_undeploy_apps(self, versioned_name, stop_and_undeploy_app_list, existing_targets_set):
628+
if versioned_name not in stop_and_undeploy_app_list and len(existing_targets_set) > 0:
629+
stop_and_undeploy_app_list.append(versioned_name)
630+
631+
627632
def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, stop_and_undeploy_app_list):
628633
"""
629634
Update maps and lists to control re-deployment processing.
@@ -684,26 +689,24 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s
684689

685690
existing_src_hash = self.__get_file_hash(src_path)
686691
existing_plan_hash = self.__get_file_hash(plan_path)
692+
existing_app_targets = dictionary_utils.get_element(existing_app_ref, 'target')
693+
existing_app_targets_set = Set(existing_app_targets)
687694
if model_src_hash == existing_src_hash:
688695
if model_plan_hash == existing_plan_hash:
689696
if self.__shouldCheckForTargetChange(src_path, model_src_path):
690-
691697
# If model hashes match existing hashes, the application did not change.
692698
# Unless targets were added, there's no need to redeploy.
693699
# If it is an absolute path, there is nothing to compare so assume redeploy
694700
model_targets = dictionary_utils.get_element(app_dict, TARGET)
695701
model_targets_list = alias_utils.create_list(model_targets, 'WLSDPLY-08000')
696702
model_targets_set = Set(model_targets_list)
697703

698-
existing_app_targets = dictionary_utils.get_element(existing_app_ref, 'target')
699-
existing_app_targets_set = Set(existing_app_targets)
700-
701704
if existing_app_targets_set == model_targets_set and len(existing_app_targets_set) > 0:
702705
# redeploy the app if everything is the same
703706
self.logger.info('WLSDPLY-09336', src_path,
704707
class_name=self._class_name, method_name=_method_name)
705-
if versioned_name not in stop_and_undeploy_app_list:
706-
stop_and_undeploy_app_list.append(versioned_name)
708+
self.__append_to_stop_and_undeploy_apps(versioned_name, stop_and_undeploy_app_list
709+
, existing_app_targets_set)
707710
elif len(existing_app_targets_set) == 0 and len(model_targets_set) == 0:
708711
self.__remove_app_from_deployment(model_apps, app, "emptyset")
709712
elif existing_app_targets_set.issuperset(model_targets_set):
@@ -721,16 +724,16 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s
721724
app_dict['SourcePath'] = src_path
722725
else:
723726
# same hash but different path, so redeploy it
724-
if versioned_name not in stop_and_undeploy_app_list:
725-
stop_and_undeploy_app_list.append(versioned_name)
727+
self.__append_to_stop_and_undeploy_apps(versioned_name, stop_and_undeploy_app_list
728+
, existing_app_targets_set)
726729
else:
727730
# updated deployment plan
728-
if versioned_name not in stop_and_undeploy_app_list:
729-
stop_and_undeploy_app_list.append(versioned_name)
731+
self.__append_to_stop_and_undeploy_apps(versioned_name, stop_and_undeploy_app_list
732+
, existing_app_targets_set)
730733
else:
731734
# updated app
732-
if versioned_name not in stop_and_undeploy_app_list:
733-
stop_and_undeploy_app_list.append(versioned_name)
735+
self.__append_to_stop_and_undeploy_apps(versioned_name, stop_and_undeploy_app_list
736+
, existing_app_targets_set)
734737

735738
def __remove_delete_targets(self, model_dict, existing_ref):
736739
"""

system-test/src/test/java/oracle/weblogic/deploy/integration/BaseTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class BaseTest {
2828
private static final PlatformLogger logger = WLSDeployLogFactory.getLogger("integration.tests");
2929
protected static final String FS = File.separator;
3030
private static final String SAMPLE_ARCHIVE_FILE = "archive.zip";
31+
private static final String UPDATED_SAMPLE_ARCHIVE_FILE = "archive2.zip";
3132
private static final String WDT_ZIPFILE = "weblogic-deploy.zip";
3233
private static final String WDT_HOME_DIR = "weblogic-deploy";
3334
protected static final String SAMPLE_MODEL_FILE_PREFIX = "simple-topology";
@@ -195,10 +196,20 @@ protected static CommandResult buildSampleArchive() throws Exception {
195196
return executeAndVerify(command);
196197
}
197198

199+
protected static CommandResult updateSampleArchive() throws Exception {
200+
logger.info("Update WDT archive ...");
201+
String command = "sh " + getResourcePath() + FS + "update-archive.sh";
202+
return executeAndVerify(command);
203+
}
204+
198205
protected static String getSampleArchiveFile() {
199206
return getGeneratedResourcePath() + FS + SAMPLE_ARCHIVE_FILE;
200207
}
201208

209+
protected static String getUpdatedSampleArchiveFile() {
210+
return getGeneratedResourcePath() + FS + UPDATED_SAMPLE_ARCHIVE_FILE;
211+
}
212+
202213
protected static String getSampleModelFile(String suffix) {
203214
return getResourcePath() + FS + SAMPLE_MODEL_FILE_PREFIX + suffix + ".yaml";
204215
}

system-test/src/test/java/oracle/weblogic/deploy/integration/ITWdt.java

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,111 @@ void test29EncryptModel(TestInfo testInfo) throws Exception {
824824
}
825825
}
826826

827+
/**
828+
* test updateDomain.sh online with untargeting, deploy, and app update
829+
* @throws Exception - if any error occurs
830+
*/
831+
@DisplayName("Test 30: createDomain and run updateDomain online for application")
832+
@Order(30)
833+
@Tag("gate")
834+
@Test
835+
void test30OnlineUpdateApp(TestInfo testInfo) throws Exception {
836+
String domainDir = "domain2";
837+
String cmd = createDomainScript
838+
+ " -oracle_home " + mwhome_12213
839+
+ " -domain_home " + domainParentDir + FS + domainDir
840+
+ " -model_file " + getSampleModelFile("-onlinebase")
841+
+ " -archive_file " + getSampleArchiveFile();
842+
843+
try (PrintWriter out = getTestMethodWriter(testInfo)) {
844+
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
845+
assertEquals(0, result.exitValue(), "Unexpected return code");
846+
assertTrue(result.stdout().contains("createDomain.sh completed successfully"), "Create failed");
847+
}
848+
849+
String domainHome = domainParentDir + FS + domainDir;
850+
setUpBootProperties(domainHome, "admin-server", "weblogic", "welcome1");
851+
Path adminServerOut = getTestOutputPath(testInfo).resolve("admin-server.out");
852+
boolean isServerUp = startAdminServer(domainHome, adminServerOut);
853+
854+
if (isServerUp) {
855+
try (PrintWriter out = getTestMethodWriter(testInfo)) {
856+
// update wdt model file
857+
Path source = Paths.get(getSampleModelFile("-untargetapp"));
858+
Path model = getTestOutputPath(testInfo).resolve(SAMPLE_MODEL_FILE_PREFIX + "-onlineUpdate.yaml");
859+
Files.copy(source, model, StandardCopyOption.REPLACE_EXISTING);
860+
861+
cmd = "echo welcome1 | "
862+
+ updateDomainScript
863+
+ " -oracle_home " + mwhome_12213
864+
+ " -domain_home " + domainParentDir + FS + domainDir
865+
+ " -model_file " + model
866+
+ " -archive_file " + getSampleArchiveFile()
867+
+ " -admin_url t3://localhost:7001 -admin_user weblogic";
868+
CommandResult result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
869+
870+
assertEquals(0, result.exitValue(), "Unexpected return code for untargeting app");
871+
assertTrue(result.stdout().contains("<remove_app_from_deployment> <WLSDPLY-09339>"),
872+
"Update does not contains expected message WLSDPLY-09339");
873+
874+
// Check result
875+
source = Paths.get(getSampleModelFile("-targetapp"));
876+
model = getTestOutputPath(testInfo).resolve(SAMPLE_MODEL_FILE_PREFIX + "-onlineUpdate.yaml");
877+
Files.copy(source, model, StandardCopyOption.REPLACE_EXISTING);
878+
879+
cmd = "echo welcome1 | "
880+
+ updateDomainScript
881+
+ " -oracle_home " + mwhome_12213
882+
+ " -domain_home " + domainParentDir + FS + domainDir
883+
+ " -model_file " + model
884+
+ " -archive_file " + getSampleArchiveFile()
885+
+ " -admin_url t3://localhost:7001 -admin_user weblogic";
886+
result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
887+
888+
assertEquals(0, result.exitValue(), "Unexpected return code for targeting app");
889+
assertTrue(result.stdout().contains("<__deploy_app_online> <WLSDPLY-09316>"),
890+
"Update does not contains expected message WLSDPLY-09316");
891+
assertTrue(result.stdout().contains("<__start_app> <WLSDPLY-09313>"),
892+
"Update does not contains expected message WLSDPLY-09313");
893+
894+
updateSampleArchive();
895+
896+
source = Paths.get(getSampleModelFile("-targetapp"));
897+
model = getTestOutputPath(testInfo).resolve(SAMPLE_MODEL_FILE_PREFIX + "-onlineUpdate.yaml");
898+
Files.copy(source, model, StandardCopyOption.REPLACE_EXISTING);
899+
900+
cmd = "echo welcome1 | "
901+
+ updateDomainScript
902+
+ " -oracle_home " + mwhome_12213
903+
+ " -domain_home " + domainParentDir + FS + domainDir
904+
+ " -model_file " + model
905+
+ " -archive_file " + getUpdatedSampleArchiveFile()
906+
+ " -admin_url t3://localhost:7001 -admin_user weblogic";
907+
result = Runner.run(cmd, getTestMethodEnvironment(testInfo), out);
908+
909+
assertEquals(0, result.exitValue(), "Unexpected return code for updating domain with new archive");
910+
assertTrue(result.stdout().contains("<__stop_app> <WLSDPLY-09312>"),
911+
"Update does not contains expected message WLSDPLY-09312");
912+
assertTrue(result.stdout().contains("<__undeploy_app> <WLSDPLY-09314>"),
913+
"Update does not contains expected message WLSDPLY-09314");
914+
assertTrue(result.stdout().contains("<__deploy_app_online> <WLSDPLY-09316>"),
915+
"Update does not contains expected message WLSDPLY-09316");
916+
assertTrue(result.stdout().contains("<__start_app> <WLSDPLY-09313>"),
917+
"Update does not contains expected message WLSDPLY-09313");
918+
919+
stopAdminServer(domainHome);
920+
}
921+
922+
} else {
923+
// Best effort to clean up server
924+
tryKillTheAdminServer(domainHome, "admin-server");
925+
throw new Exception("testDOnlineUpdate failed - cannot bring up server");
926+
}
927+
928+
929+
}
930+
931+
827932
private boolean startAdminServer(String domainHome, Path outputFile) throws Exception {
828933
boolean isServerUp = false;
829934
String cmd = "nohup " + domainHome + "/bin/startWebLogic.sh > " + outputFile + " 2>&1 &";
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
domainInfo:
2+
AdminUserName: weblogic
3+
AdminPassword: welcome1
4+
ServerStartMode: prod
5+
topology:
6+
Name: domain2
7+
AdminServerName: 'admin-server'
8+
ProductionModeEnabled: true
9+
Cluster:
10+
'cluster1':
11+
ClientCertProxyEnabled: true
12+
FrontendHost: localhost
13+
DynamicServers:
14+
ServerTemplate: template1
15+
CalculatedListenPorts: true
16+
ServerNamePrefix: 'managed-server-'
17+
DynamicClusterSize: 2
18+
MaxDynamicClusterSize: 2
19+
Server:
20+
'admin-server':
21+
ListenPort: 7001
22+
ServerTemplate:
23+
template1:
24+
ListenPort: 8001
25+
appDeployments:
26+
Application:
27+
# Quote needed because of hyphen in string
28+
'simple-app':
29+
SourcePath: 'wlsdeploy/applications/simple-app.war'
30+
Target: 'admin-server'
31+
ModuleType: war
32+
StagingMode: nostage
33+
PlanStagingMode: nostage
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
appDeployments:
2+
Application:
3+
# Quote needed because of hyphen in string
4+
'simple-app':
5+
SourcePath: 'wlsdeploy/applications/simple-app.war'
6+
Target: 'admin-server'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
appDeployments:
2+
Application:
3+
# Quote needed because of hyphen in string
4+
'simple-app':
5+
SourcePath: 'wlsdeploy/applications/simple-app.war'
6+
Target: '!admin-server'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2022, Oracle and/or its affiliates.
4+
#
5+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
#
7+
set -e
8+
projectDir=$(pwd)
9+
archiveDir=${projectDir}/target/resources
10+
cd "$archiveDir"
11+
cp archive.zip archive2.zip
12+
mkdir temp
13+
cd temp
14+
jar xf ../archive2.zip
15+
touch dummy.html
16+
jar uf wlsdeploy/applications/simple-app.war dummy.html
17+
jar uf ../archive2.zip wlsdeploy/applications/simple-app.war
18+
19+

0 commit comments

Comments
 (0)