Skip to content

Commit 9cca685

Browse files
jshum2479Johnny
authored andcommitted
Add run_rcu logic to support create rcu schema for atp
1 parent 7285914 commit 9cca685

File tree

4 files changed

+200
-44
lines changed

4 files changed

+200
-44
lines changed

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

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class RCURunner {
5858
private static final String WLS_COMPONENT = "WLS";
5959
private static final String WLS_RUNTIME_COMPONENT = "WLS_RUNTIME";
6060

61-
private static final Pattern SCHEMA_DOES_NOT_EXIST_PATTERN = Pattern.compile("(ORA-01918|RCU-6013)");
61+
private static final Pattern SCHEMA_DOES_NOT_EXIST_PATTERN = Pattern.compile("(ORA-01918|RCU-6013|ORA-12899)");
6262

6363
private static final int RCU_CREATE_COMMON_ARG_COUNT = 13;
6464

@@ -71,6 +71,7 @@ public class RCURunner {
7171
private String rcuPrefix;
7272
private List<String> rcuSchemas;
7373
private boolean ATP_DB = false;
74+
private String atpSSlArgs = null;
7475

7576
/**
7677
* The constructor.
@@ -105,7 +106,8 @@ public RCURunner(String domainType, String oracleHome, String javaHome, String r
105106
* @param javaHome the JAVA_HOME location
106107
* @throws CreateException if a parameter validation error occurs
107108
*/
108-
public RCURunner(String domainType, String oracleHome, String javaHome, PyDictionary rcuProperties)
109+
public RCURunner(String domainType, String oracleHome, String javaHome, List<String> rcuSchemas,
110+
PyDictionary rcuProperties)
109111
throws CreateException {
110112

111113

@@ -119,7 +121,7 @@ public RCURunner(String domainType, String oracleHome, String javaHome, PyDictio
119121
sslArgs.append(",oracle.net.ssl_version=1.2");
120122
sslArgs.append(",javax.net.ssl.trustStore=");
121123
sslArgs.append(tnsAdmin + "/truststore.jks");
122-
sslArgs.append("javax.net.ssl.trustStoreType=JKS");
124+
sslArgs.append(",javax.net.ssl.trustStoreType=JKS");
123125
sslArgs.append(",javax.net.ssl.trustStorePassword=");
124126
sslArgs.append(trustStorePassword);
125127
sslArgs.append(",javax.net.ssl.keyStore=");
@@ -131,15 +133,16 @@ public RCURunner(String domainType, String oracleHome, String javaHome, PyDictio
131133
sslArgs.append(",oracle.net.ssl_server_dn_match=true");
132134

133135
ATP_DB = true;
136+
atpSSlArgs = sslArgs.toString();
134137

135138
this.oracleHome = validateExistingDirectory(oracleHome, "ORACLE_HOME");
136139
this.javaHome = validateExistingDirectory(javaHome, "JAVA_HOME");
137-
this.rcuDb = rcuProperties.get(new PyString("tns.entry")).toString();
140+
this.rcuDb = "jdbc:oracle:thin:@" + rcuProperties.get(new PyString("tns.entry")).toString();
138141
this.rcuPrefix = rcuProperties.get(new PyString("rcu_prefix")).toString();
139142
this.rcuSchemas = validateNonEmptyListOfStrings(rcuSchemas, "rcu_schema_list");
140-
if (this.rcuSchemas.contains(SERVICE_TABLE_COMPONENT)) {
143+
if (!this.rcuSchemas.contains(SERVICE_TABLE_COMPONENT)) {
141144
LOGGER.warning("WLSDPLY-12000", CLASS, domainType, SERVICE_TABLE_COMPONENT);
142-
this.rcuSchemas.remove(SERVICE_TABLE_COMPONENT);
145+
this.rcuSchemas.add(SERVICE_TABLE_COMPONENT);
143146
}
144147
}
145148

@@ -187,6 +190,9 @@ public void runRcu(String rcuSysPass, String rcuSchemaPass) throws CreateExcepti
187190
runner = new ScriptRunner(createEnv, RCU_CREATE_LOG_BASENAME);
188191
try {
189192
exitCode = runner.executeScript(rcuScript, scriptStdinLines, scriptArgs);
193+
if (ATP_DB && exitCode != 0 && isSchemaNotExistError(runner)) {
194+
exitCode = 0;
195+
}
190196
} catch (ScriptRunnerException sre) {
191197
CreateException ce = new CreateException("WLSDPLY-12003", sre, CLASS, sre.getLocalizedMessage());
192198
LOGGER.throwing(CLASS, METHOD, ce);
@@ -231,10 +237,23 @@ private String[] getRcuDropArgs() {
231237
dropArgs.add(ORACLE_DB_TYPE);
232238
dropArgs.add(DB_CONNECT_SWITCH);
233239
dropArgs.add(rcuDb);
234-
dropArgs.add(DB_USER_SWITCH);
235-
dropArgs.add(DB_USER);
236-
dropArgs.add(DB_ROLE_SWITCH);
237-
dropArgs.add(DB_ROLE);
240+
241+
if (ATP_DB) {
242+
dropArgs.add(DB_USER_SWITCH);
243+
dropArgs.add("admin");
244+
dropArgs.add(USE_SSL_SWITCH);
245+
dropArgs.add("true");
246+
dropArgs.add(SERVER_DN_SWITCH);
247+
dropArgs.add("CN=ignored");
248+
dropArgs.add(SSLARGS);
249+
dropArgs.add(atpSSlArgs);
250+
251+
} else {
252+
dropArgs.add(DB_USER_SWITCH);
253+
dropArgs.add(DB_USER);
254+
dropArgs.add(DB_ROLE_SWITCH);
255+
dropArgs.add(DB_ROLE);
256+
}
238257
dropArgs.add(SCHEMA_PREFIX_SWITCH);
239258
dropArgs.add(rcuPrefix);
240259

@@ -260,10 +279,21 @@ private String[] getRcuCreateArgs() {
260279
createArgs.add(ORACLE_DB_TYPE);
261280
createArgs.add(DB_CONNECT_SWITCH);
262281
createArgs.add(rcuDb);
263-
createArgs.add(DB_USER_SWITCH);
264-
createArgs.add(DB_USER);
265-
createArgs.add(DB_ROLE_SWITCH);
266-
createArgs.add(DB_ROLE);
282+
if (ATP_DB) {
283+
createArgs.add(DB_USER_SWITCH);
284+
createArgs.add("admin");
285+
createArgs.add(USE_SSL_SWITCH);
286+
createArgs.add("true");
287+
createArgs.add(SERVER_DN_SWITCH);
288+
createArgs.add("CN=ignored");
289+
createArgs.add(SSLARGS);
290+
createArgs.add(atpSSlArgs);
291+
} else {
292+
createArgs.add(DB_USER_SWITCH);
293+
createArgs.add(DB_USER);
294+
createArgs.add(DB_ROLE_SWITCH);
295+
createArgs.add(DB_ROLE);
296+
}
267297
createArgs.add(SCHEMA_PREFIX_SWITCH);
268298
createArgs.add(rcuPrefix);
269299

@@ -329,6 +359,19 @@ private static boolean isSchemaNotExistError(ScriptRunner runner) {
329359
return schemaDoesNotExist;
330360
}
331361

362+
private static boolean isValueTooLargeError(ScriptRunner runner) {
363+
List<String> stdoutBuffer = runner.getStdoutBuffer();
364+
boolean schemaDoesNotExist = false;
365+
for (String line : stdoutBuffer) {
366+
Matcher matcher = SCHEMA_DOES_NOT_EXIST_PATTERN.matcher(line);
367+
if (matcher.find()) {
368+
schemaDoesNotExist = true;
369+
break;
370+
}
371+
}
372+
return schemaDoesNotExist;
373+
}
374+
332375
private static File validateExistingDirectory(String directoryName, String directoryTypeName)
333376
throws CreateException {
334377
final String METHOD = "validateExistingDirectory";

core/src/main/python/create.py

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import javaos as os
88
import sys
9+
from xml.dom.minidom import parse
910

1011
from java.io import IOException
1112
from java.lang import IllegalArgumentException
@@ -75,7 +76,7 @@
7576
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
7677
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
7778
CommandLineArgUtil.PASSPHRASE_SWITCH,
78-
CommandLineArgUtil.RCU_PROPERTIES_FILE_SWITCH
79+
CommandLineArgUtil.ATP_PROPERTIES_FILE_SWITCH
7980
]
8081

8182

@@ -272,7 +273,7 @@ def __process_rcu_args(optional_arg_map, domain_type, domain_typedef):
272273
ex.setExitCode(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE)
273274
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
274275
raise ex
275-
elif CommandLineArgUtil.RCU_PROPERTIES_FILE_SWITCH in optional_arg_map:
276+
elif CommandLineArgUtil.ATP_PROPERTIES_FILE_SWITCH in optional_arg_map:
276277
pass
277278
else:
278279
ex = exception_helper.create_cla_exception('WLSDPLY-12408', domain_type, rcu_schema_count,
@@ -337,6 +338,49 @@ def validate_model(model_dictionary, model_context, aliases):
337338
__clean_up_temp_files()
338339
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
339340

341+
def set_ssl_properties(xmlDoc, atp_creds_path, keystore_password, truststore_password):
342+
'''
343+
Add SSL config properties to the specified XML document.
344+
:param xmlDoc: The XML document
345+
:param db_keystore_password: The DB keystore/truststore password (assumed to be same)
346+
:return: void
347+
'''
348+
DOMTree = parse(xmlDoc)
349+
collection = DOMTree.documentElement
350+
props = collection.getElementsByTagName("propertySet")
351+
352+
for prop in props:
353+
if prop.getAttribute('name') == 'props.db.1':
354+
set_property(DOMTree, prop, 'javax.net.ssl.trustStoreType', 'JKS')
355+
set_property(DOMTree, prop, 'javax.net.ssl.trustStore', atp_creds_path + '/truststore.jks')
356+
set_property(DOMTree, prop, 'oracle.net.tns_admin', atp_creds_path)
357+
set_property(DOMTree, prop, 'javax.net.ssl.keyStoreType', 'JKS')
358+
set_property(DOMTree, prop, 'javax.net.ssl.keyStore', atp_creds_path + '/keystore.jks')
359+
set_property(DOMTree, prop, 'javax.net.ssl.keyStorePassword', keystore_password)
360+
set_property(DOMTree, prop, 'javax.net.ssl.trustStorePassword', truststore_password)
361+
set_property(DOMTree, prop, 'oracle.net.ssl_server_dn_match', 'true')
362+
set_property(DOMTree, prop, 'oracle.net.ssl_version', '1.2')
363+
# Persist the changes in the xml file
364+
file_handle = open(xmlDoc,"w")
365+
DOMTree.writexml(file_handle)
366+
file_handle.close()
367+
368+
def set_property(DOMTree, prop, name, value):
369+
'''
370+
Sets the property child element under prop parent node.
371+
:param DOMTree: The DOM document handle
372+
:param prop: The propertySet parent handle
373+
:param name: The property name
374+
:param value: The property value
375+
:return: void
376+
'''
377+
property = DOMTree.createElement('property')
378+
property.setAttribute("name", name)
379+
property.setAttribute("value", value)
380+
prop.appendChild(property)
381+
newline = DOMTree.createTextNode('\n')
382+
prop.appendChild(newline)
383+
340384

341385
def main(args):
342386
"""
@@ -355,6 +399,9 @@ def main(args):
355399

356400
try:
357401
model_context = __process_args(args)
402+
if model_context.get_atp_properties_file():
403+
current_wlst_properties = os.environ.get('WLST_PROPERTIES')
404+
os.environ['oracle.net.fanEnabled'] = 'false'
358405
except CLAException, ex:
359406
exit_code = ex.getExitCode()
360407
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
@@ -396,7 +443,19 @@ def main(args):
396443
try:
397444
creator = DomainCreator(model, model_context, aliases)
398445
creator.create()
399-
except CreateException, ex:
446+
atp_props_path = model_context.get_atp_properties_file()
447+
448+
if atp_props_path:
449+
rcu_properties_map = variables.load_variables(atp_props_path)
450+
atp_creds_path = rcu_properties_map['oracle.net.tns_admin']
451+
jsp_config = model_context.get_domain_home() + '/config/fmwconfig/jps-config.xml'
452+
jsp_config_jse = model_context.get_domain_home() + '/config/fmwconfig/jps-config-jse.xml'
453+
set_ssl_properties(jsp_config, atp_creds_path, rcu_properties_map['javax.net.ssl.keyStorePassword'],
454+
rcu_properties_map['javax.net.ssl.trustStorePassword'])
455+
set_ssl_properties(jsp_config_jse, atp_creds_path, rcu_properties_map['javax.net.ssl.keyStorePassword'],
456+
rcu_properties_map['javax.net.ssl.trustStorePassword'])
457+
458+
except (IOException | CreateException), ex:
400459
__logger.severe('WLSDPLY-12409', _program_name, ex.getLocalizedMessage(), error=ex,
401460
class_name=_class_name, method_name=_method_name)
402461
__clean_up_temp_files()

0 commit comments

Comments
 (0)