Skip to content

Commit dc36fe7

Browse files
committed
Merge branch 'post-create-domain-script' into 'main'
Post create domain script See merge request weblogic-cloud/weblogic-deploy-tooling!1496
2 parents 5d88348 + dff2319 commit dc36fe7

File tree

7 files changed

+262
-58
lines changed

7 files changed

+262
-58
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2023, Oracle Corporation and/or its affiliates.
3+
* Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
*/
5+
package oracle.weblogic.deploy.create;
6+
7+
import java.io.File;
8+
import java.util.Collections;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
import oracle.weblogic.deploy.logging.PlatformLogger;
14+
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;
15+
import oracle.weblogic.deploy.util.FileUtils;
16+
import oracle.weblogic.deploy.util.ScriptRunner;
17+
import oracle.weblogic.deploy.util.ScriptRunnerException;
18+
19+
import static oracle.weblogic.deploy.create.ValidationUtils.validateExistingDirectory;
20+
import static oracle.weblogic.deploy.create.ValidationUtils.validateExistingExecutableFile;
21+
import static oracle.weblogic.deploy.create.ValidationUtils.validateNonEmptyString;
22+
23+
public class PostCreateDomainScriptRunner {
24+
private static final String CLASS = PostCreateDomainScriptRunner.class.getName();
25+
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.create");
26+
private static final List<String> EMPTY_STRING_LIST = Collections.emptyList();
27+
28+
private final File scriptFile;
29+
private final File javaHome;
30+
private final File oracleHome;
31+
private final File domainHome;
32+
private final String domainName;
33+
private Map<String, String> environmentVariables;
34+
public PostCreateDomainScriptRunner(String scriptFileName, String javaHome, String oracleHome, String domainHome,
35+
String domainName) throws CreateException {
36+
final String METHOD = "<init>";
37+
LOGGER.entering(CLASS, METHOD, scriptFileName, javaHome, oracleHome, domainHome, domainName);
38+
39+
this.scriptFile = validateExistingExecutableFile(scriptFileName, "Post Create Domain Script");
40+
this.javaHome = validateExistingDirectory(javaHome, "JAVA_HOME");
41+
this.oracleHome = validateExistingDirectory(oracleHome, "ORACLE_HOME");
42+
this.domainHome = validateExistingDirectory(domainHome, "DOMAIN_HOME");
43+
this.domainName = validateNonEmptyString(domainName, "DOMAIN_NAME");
44+
45+
initializeEnvironment();
46+
LOGGER.exiting(CLASS, METHOD);
47+
}
48+
49+
public void runScript() throws CreateException {
50+
final String METHOD = "runScript";
51+
LOGGER.entering(CLASS, METHOD);
52+
53+
String[] fileComponents = FileUtils.parseFileName(this.scriptFile);
54+
String logFileBaseName = fileComponents.length > 0 ? fileComponents[0] : "postCreateDomainScript";
55+
ScriptRunner runner = new ScriptRunner(this.environmentVariables, logFileBaseName);
56+
57+
int exitCode;
58+
try {
59+
exitCode = runner.executeScript(this.scriptFile, EMPTY_STRING_LIST);
60+
} catch (ScriptRunnerException sre) {
61+
CreateException ce = new CreateException("WLSDPLY-12001", sre, CLASS, this.scriptFile.getAbsolutePath(),
62+
sre.getLocalizedMessage());
63+
LOGGER.throwing(CLASS, METHOD, ce);
64+
throw ce;
65+
}
66+
67+
if (exitCode != 0) {
68+
CreateException ce = new CreateException("WLSDPLY-12014", this.scriptFile.getAbsolutePath(), exitCode,
69+
runner.getStdoutFileName());
70+
LOGGER.throwing(CLASS, METHOD, ce);
71+
throw ce;
72+
}
73+
74+
LOGGER.exiting(CLASS, METHOD, exitCode);
75+
}
76+
77+
private void initializeEnvironment() {
78+
Map<String, String> env = new HashMap<>(System.getenv());
79+
env.put("JAVA_HOME", this.javaHome.getAbsolutePath());
80+
env.put("ORACLE_HOME", this.oracleHome.getAbsolutePath());
81+
env.put("DOMAIN_HOME", this.domainHome.getAbsolutePath());
82+
env.put("DOMAIN_NAME", this.domainName);
83+
this.environmentVariables = env;
84+
}
85+
}

core/src/main/java/oracle/weblogic/deploy/create/RCURunner.java

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
3-
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
2+
* Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
3+
* Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.create;
66

@@ -22,6 +22,9 @@
2222
import org.python.core.PyDictionary;
2323
import org.python.core.PyString;
2424

25+
import static oracle.weblogic.deploy.create.ValidationUtils.validateExistingDirectory;
26+
import static oracle.weblogic.deploy.create.ValidationUtils.validateExistingExecutableFile;
27+
2528

2629
/**
2730
* This class does all the work to drop and recreate the RCU schemas based on the domain type definition.
@@ -421,24 +424,6 @@ private static boolean isSchemaNotExistError(ScriptRunner runner) {
421424
return schemaDoesNotExist;
422425
}
423426

424-
private static File validateExistingDirectory(String directoryName, String directoryTypeName)
425-
throws CreateException {
426-
final String METHOD = "validateExistingDirectory";
427-
428-
LOGGER.entering(CLASS, METHOD, directoryName, directoryTypeName);
429-
File result;
430-
try {
431-
result = FileUtils.validateExistingDirectory(directoryName);
432-
} catch (IllegalArgumentException iae) {
433-
CreateException ce = new CreateException("WLSDPLY-12004", iae, CLASS, directoryTypeName,
434-
directoryName, iae.getLocalizedMessage());
435-
LOGGER.throwing(CLASS, METHOD, ce);
436-
throw ce;
437-
}
438-
LOGGER.exiting(CLASS, METHOD, result);
439-
return result;
440-
}
441-
442427
private static String quoteStringForCommandLine(String text, String textTypeName) throws CreateException {
443428
String result = validateNonEmptyString(text, textTypeName);
444429
return StringUtils.quoteString(result);
@@ -489,29 +474,6 @@ private static List<String> validateNonEmptyListOfStrings(List<String> stringLis
489474
return stringList;
490475
}
491476

492-
private static void validateExistingExecutableFile(File executable, String executableTypeName)
493-
throws CreateException {
494-
final String METHOD = "validateExistingExecutableFile";
495-
496-
LOGGER.entering(CLASS, METHOD, executable, executableTypeName);
497-
File tmp;
498-
try {
499-
tmp = FileUtils.validateExistingFile(executable.getAbsolutePath());
500-
} catch (IllegalArgumentException iae) {
501-
CreateException ce = new CreateException("WLSDPLY-12008", iae, CLASS, executableTypeName,
502-
executable.getAbsolutePath(), iae.getLocalizedMessage());
503-
LOGGER.throwing(CLASS, METHOD, ce);
504-
throw ce;
505-
}
506-
if (!tmp.canExecute()) {
507-
CreateException ce =
508-
new CreateException("WLSDPLY-12009", CLASS, executableTypeName, executable.getAbsolutePath());
509-
LOGGER.throwing(CLASS, METHOD, ce);
510-
throw ce;
511-
}
512-
LOGGER.exiting(CLASS, METHOD);
513-
}
514-
515477
/**
516478
* Extract the specified string from the specified python dictionary.
517479
*/
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2023, Oracle Corporation and/or its affiliates.
3+
* Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
*/
5+
package oracle.weblogic.deploy.create;
6+
7+
import java.io.File;
8+
9+
import oracle.weblogic.deploy.logging.PlatformLogger;
10+
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;
11+
import oracle.weblogic.deploy.util.FileUtils;
12+
import oracle.weblogic.deploy.util.StringUtils;
13+
14+
public class ValidationUtils {
15+
private static final String CLASS = ValidationUtils.class.getName();
16+
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.create");
17+
18+
private ValidationUtils() {
19+
// hide the constructor for this utility class
20+
}
21+
22+
public static File validateExistingDirectory(String directoryName, String directoryTypeName)
23+
throws CreateException {
24+
final String METHOD = "validateExistingDirectory";
25+
26+
LOGGER.entering(CLASS, METHOD, directoryName, directoryTypeName);
27+
File result;
28+
try {
29+
result = FileUtils.validateExistingDirectory(directoryName);
30+
} catch (IllegalArgumentException iae) {
31+
CreateException ce = new CreateException("WLSDPLY-12004", iae, CLASS, directoryTypeName,
32+
directoryName, iae.getLocalizedMessage());
33+
LOGGER.throwing(CLASS, METHOD, ce);
34+
throw ce;
35+
}
36+
LOGGER.exiting(CLASS, METHOD, result);
37+
return result;
38+
}
39+
40+
public static File validateExistingExecutableFile(String executableFileName, String executableTypeName)
41+
throws CreateException {
42+
validateNonEmptyString(executableFileName, executableTypeName);
43+
return validateExistingExecutableFile(new File(executableFileName), executableTypeName);
44+
}
45+
46+
public static File validateExistingExecutableFile(File executable, String executableTypeName)
47+
throws CreateException {
48+
final String METHOD = "validateExistingExecutableFile";
49+
50+
LOGGER.entering(CLASS, METHOD, executable, executableTypeName);
51+
File tmp;
52+
try {
53+
tmp = FileUtils.validateExistingFile(executable.getAbsolutePath());
54+
} catch (IllegalArgumentException iae) {
55+
CreateException ce = new CreateException("WLSDPLY-12008", iae, CLASS, executableTypeName,
56+
executable.getAbsolutePath(), iae.getLocalizedMessage());
57+
LOGGER.throwing(CLASS, METHOD, ce);
58+
throw ce;
59+
}
60+
if (!tmp.canExecute()) {
61+
CreateException ce =
62+
new CreateException("WLSDPLY-12009", CLASS, executableTypeName, executable.getAbsolutePath());
63+
LOGGER.throwing(CLASS, METHOD, ce);
64+
throw ce;
65+
}
66+
LOGGER.exiting(CLASS, METHOD, tmp);
67+
return tmp;
68+
}
69+
70+
public static String validateNonEmptyString(String value, String valueTypeName) throws CreateException {
71+
final String METHOD = "validateNonEmptyString";
72+
73+
LOGGER.entering(CLASS, METHOD, value, valueTypeName);
74+
if (StringUtils.isEmpty(value)) {
75+
CreateException ce = new CreateException("WLSDPLY-12011", CLASS, valueTypeName);
76+
LOGGER.throwing(CLASS, METHOD, ce);
77+
throw ce;
78+
}
79+
return value;
80+
}
81+
}

core/src/main/java/oracle/weblogic/deploy/util/FileUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
3-
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
2+
* Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
3+
* Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
44
*/
55
package oracle.weblogic.deploy.util;
66

@@ -344,7 +344,7 @@ public static String[] parseFileName(String filename) {
344344
}
345345

346346
/**
347-
* Whether or not the specified file has a YAML file extension.
347+
* Whether the specified file has a YAML file extension.
348348
*
349349
* @param file the file
350350
* @return true, if the file extension matches the known YAML file extensions

core/src/main/python/wlsdeploy/tool/create/domain_creator.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Copyright (c) 2017, 2023, Oracle and/or its affiliates.
3-
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import os, re
66
import weblogic.security.internal.SerializedSystemIni as SerializedSystemIni
@@ -10,6 +10,7 @@
1010
from java.lang import IllegalArgumentException
1111
from java.util import Properties
1212

13+
from oracle.weblogic.deploy.create import PostCreateDomainScriptRunner
1314
from oracle.weblogic.deploy.create import RCURunner
1415
from oracle.weblogic.deploy.util import FileUtils
1516
from wlsdeploy.aliases.location_context import LocationContext
@@ -182,6 +183,7 @@ def create(self):
182183
self.__create_boot_dot_properties()
183184
self.__create_credential_mappings()
184185
self.__install_saml2_security_files()
186+
self.__run_post_create_domain_script()
185187

186188
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
187189

@@ -684,13 +686,6 @@ def __set_server_groups(self):
684686
self.target_helper.target_jrf_groups_to_clusters_servers()
685687
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
686688

687-
def __update_domain(self):
688-
_method_name = '__update_domain'
689-
self.logger.entering(class_name=self.__class_name, method_name=_method_name)
690-
self.wlst_helper.update_domain()
691-
self.wlst_helper.close_domain()
692-
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
693-
694689
def __apply_base_domain_config(self, topology_folder_list, delete=True):
695690
"""
696691
Apply the base domain configuration from the model topology section.
@@ -1523,6 +1518,22 @@ def __install_saml2_security_files(self):
15231518
saml2_security_helper = Saml2SecurityHelper(self._domain_home, ExceptionType.CREATE)
15241519
saml2_security_helper.extract_initialization_files(self.archive_helper)
15251520

1521+
def __run_post_create_domain_script(self):
1522+
_method_name = '__run_post_create_domain_script'
1523+
1524+
self.logger.entering(self.__class_name, _method_name)
1525+
script = self._domain_typedef.get_post_create_domain_script()
1526+
if script is None:
1527+
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
1528+
return
1529+
1530+
java_home = self.model_context.get_java_home()
1531+
oracle_home = self.model_context.get_oracle_home()
1532+
runner = PostCreateDomainScriptRunner(script, java_home, oracle_home, self._domain_home, self._domain_name)
1533+
runner.runScript()
1534+
self.logger.info('WLSDPLY-12576', script, class_name=self.__class_name, method_name=_method_name)
1535+
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
1536+
15261537
def __configure_opss_secrets(self):
15271538
_method_name = '__configure_opss_secrets'
15281539

0 commit comments

Comments
 (0)