Skip to content

Commit 02e029a

Browse files
Merge pull request #992 from oracle/WDT-579-Add-psu-to-version
Wdt 579 add psu to version
2 parents 9e81226 + 3da571d commit 02e029a

File tree

6 files changed

+243
-19
lines changed

6 files changed

+243
-19
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (c) 2021, 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.
4+
*/
5+
package oracle.weblogic.deploy.util;
6+
import org.w3c.dom.Document;
7+
import org.w3c.dom.Node;
8+
import org.xml.sax.SAXException;
9+
10+
import javax.xml.XMLConstants;
11+
import javax.xml.parsers.DocumentBuilder;
12+
import javax.xml.parsers.DocumentBuilderFactory;
13+
import javax.xml.parsers.ParserConfigurationException;
14+
import javax.xml.xpath.XPath;
15+
import javax.xml.xpath.XPathConstants;
16+
import javax.xml.xpath.XPathExpressionException;
17+
import javax.xml.xpath.XPathFactory;
18+
import java.io.File;
19+
import java.io.IOException;
20+
import java.nio.file.DirectoryStream;
21+
import java.nio.file.Files;
22+
import java.nio.file.Path;
23+
import java.nio.file.Paths;
24+
import java.util.*;
25+
26+
import oracle.weblogic.deploy.logging.PlatformLogger;
27+
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;
28+
29+
/*
30+
* Parse the xml file at the designated location for the PSU value
31+
*/
32+
public class XPathUtil {
33+
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.util");
34+
String oracle_home;
35+
String patches_home;
36+
public XPathUtil(String oracle_home){
37+
this.oracle_home = oracle_home;
38+
patches_home = Paths.get(oracle_home, "inventory", "patches").toString();
39+
}
40+
private static XPathFactory factory = null;
41+
42+
private static synchronized XPathFactory factory() {
43+
if (factory == null) {
44+
factory = XPathFactory.newInstance();
45+
}
46+
return factory;
47+
}
48+
49+
/*
50+
* Get the PSU if one exists at the inventory/patches files. Look at the description
51+
* for the PSU wording.
52+
*/
53+
public String getPSU() {
54+
// find the names in the directory first
55+
if (!(new File(patches_home)).exists()) {
56+
LOGGER.info("No patches home at {0}", patches_home);
57+
return null;
58+
}
59+
List<String> patch_files = findPatchFiles();
60+
List<String> list = new ArrayList<>();
61+
for (String patch_file : patch_files){
62+
Document doc = readXmlFile(patch_file);
63+
String descrip = description(doc, "//@description");
64+
LOGGER.fine("Description {0}", descrip);
65+
if (descrip != null && descrip.startsWith("WLS PATCH SET UPDATE")) {
66+
int idx = descrip.lastIndexOf('.');
67+
String psu = descrip.substring(idx+1);
68+
list.add(psu);
69+
Collections.sort(list);
70+
return list.get(list.size() -1);
71+
}
72+
}
73+
return null;
74+
}
75+
76+
/**
77+
* Locate the patch files in the Oracle home
78+
* @return list of patch file names.
79+
*/
80+
public List<String> findPatchFiles() {
81+
List<String> patch_files = new ArrayList<String>();
82+
try (DirectoryStream<Path> stream = Files.newDirectoryStream(new File(patches_home).toPath())){
83+
for (Path path : stream) {
84+
patch_files.add(path.toString());
85+
}
86+
} catch (IOException ieo) {
87+
LOGGER.info("Unable to locate the patch files at {0}", patches_home);
88+
}
89+
return patch_files;
90+
}
91+
92+
/**
93+
* Read the xml file at the indicated path.
94+
* @param path to the xml file
95+
* @return Document from the parsed xml file
96+
*/
97+
public Document readXmlFile(String path) {
98+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
99+
try {
100+
dbf.setXIncludeAware(false);
101+
dbf.setExpandEntityReferences(false);
102+
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
103+
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
104+
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
105+
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
106+
} catch (ParserConfigurationException pce) {
107+
LOGGER.warning("Unable to set feature in DocumentBuilderFactory : {0}");
108+
}
109+
110+
Document doc = null;
111+
try {
112+
// parse XML file
113+
DocumentBuilder db = dbf.newDocumentBuilder();
114+
115+
doc = db.parse(new File(path));
116+
117+
} catch (ParserConfigurationException | SAXException | IOException ioe) {
118+
LOGGER.info("Unable to parse the xml file {0}", path);
119+
}
120+
return doc;
121+
}
122+
123+
/**
124+
* Apply the expression against the Node and return a String.
125+
* @param node parsed xml file Node to search
126+
* @param expression to evaluate on the Node
127+
* @return the String value if located in the Node
128+
*/
129+
private String description(Node node, String expression) {
130+
XPath xpath = factory().newXPath();
131+
try {
132+
return (String) xpath.evaluate(expression, node, XPathConstants.STRING);
133+
} catch (XPathExpressionException xpe) {
134+
LOGGER.info("Unable to apply the expression {0}", expression);
135+
}
136+
return null;
137+
}
138+
}

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
from java.lang import String
@@ -74,9 +74,7 @@ def __init__(self, model_context, wlst_mode=WlstModes.OFFLINE, wls_version=None,
7474
self._logger = PlatformLogger('wlsdeploy.aliases')
7575

7676
if wls_version is None:
77-
from wlsdeploy.util.weblogic_helper import WebLogicHelper
78-
self._wls_helper = WebLogicHelper(self._logger)
79-
self._wls_version = self._wls_helper.wl_version_actual
77+
self._wls_version = self._model_context.get_target_wls_version()
8078
else:
8179
self._wls_version = wls_version
8280

core/src/main/python/wlsdeploy/util/model_context.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55

@@ -9,6 +9,7 @@
99

1010
import java.net.URI as URI
1111

12+
from oracle.weblogic.deploy.util import XPathUtil
1213
from wlsdeploy.aliases.wlst_modes import WlstModes
1314
from wlsdeploy.logging import platform_logger
1415
from wlsdeploy.util.cla_utils import CommandLineArgUtil
@@ -99,6 +100,7 @@ def __init__(self, program_name, arg_map):
99100
if self._wl_version is None:
100101
self._wl_version = self._wls_helper.get_actual_weblogic_version()
101102

103+
102104
if self._wlst_mode is None:
103105
self._wlst_mode = WlstModes.OFFLINE
104106

@@ -107,8 +109,14 @@ def __init__(self, program_name, arg_map):
107109
return
108110

109111
def __copy_from_args(self, arg_map):
112+
_method_name = '__copy_from_args'
110113
if CommandLineArgUtil.ORACLE_HOME_SWITCH in arg_map:
111114
self._oracle_home = arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH]
115+
psu = XPathUtil(self._oracle_home).getPSU()
116+
if psu is not None:
117+
self._wl_version += '.' + psu
118+
self._logger.info('WLSDPLY-01050', self._wl_version, class_name=self._class_name,
119+
method_name=_method_name)
112120
self._wl_home = self._wls_helper.get_weblogic_home(self._oracle_home)
113121

114122
if CommandLineArgUtil.JAVA_HOME_SWITCH in arg_map:

core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/SecurityConfiguration.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"copyright": "Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.",
2+
"copyright": "Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.",
33
"license": "Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl",
44
"wlst_type": "SecurityConfiguration",
55
"default_name_value": "%DOMAIN%",
@@ -1418,8 +1418,12 @@
14181418
"RealmBootStrapVersion": [ {"version": "[10,12.2.1)", "wlst_mode": "offline", "wlst_name": "RealmBootStrapVersion", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "get_method": "GET", "restart_required": "true" } ,
14191419
{"version": "[10,)", "wlst_mode": "online", "wlst_name": "RealmBootStrapVersion", "wlst_path": "WP001", "value": {"default": "1" }, "wlst_type": "string", "get_method": "GET", "restart_required": "true" } ],
14201420
"RemoteAnonymousJndiEnabled": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Jndi:JNDI}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean", "restart_required": "true" } ],
1421-
"RemoteAnonymousRmiiiopEnabled": [ {"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
1422-
"RemoteAnonymousRmit3Enabled": [ {"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
1421+
"RemoteAnonymousRmiiiopEnabled": [ {"version": "[12.2.1.4.210930,12.2.1.5]", "wlst_mode": "online", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" },
1422+
{"version": "[12.2.1.3.210929,12.2.1.4)", "wlst_mode": "online", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ,
1423+
{"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
1424+
"RemoteAnonymousRmit3Enabled": [ {"version": "[12.2.1.4.210930,12.2.1.5]", "wlst_mode": "online", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ,
1425+
{"version": "[12.2.1.3.210929,12.2.1.4)", "wlst_mode": "online", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ,
1426+
{"version": "[14.1.1)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
14231427
"UseKSSForDemo": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "UseKSSForDemo", "wlst_path": "WP001", "value": {"default": "false" }, "wlst_type": "boolean", "restart_required": "true" } ],
14241428
"WebAppFilesCaseInsensitive": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "WebAppFilesCaseInsensitive", "wlst_path": "WP001", "value": {"default": "${None:false}"}, "wlst_type": "string", "restart_required": "true" } ]
14251429
},

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2017, 2022, Oracle and/or its affiliates.
22
# The Universal Permissive License (UPL), Version 1.0
33
#
44
#
@@ -119,6 +119,9 @@ WLSDPLY-00127=Unable to load the DomainRuntimeService from the WLST globals : {0
119119
# oracle.weblogic.deploy.util.CLAUtil.java
120120
WLSDPLY-01000=Password was truncated to {0} characters
121121

122+
# oracle.weblogic.deploy.util.XPathUtils.java
123+
WLSDPLY-01050=WebLogic version for aliases is {0}
124+
122125
# oracle.weblogic.deploy.util.FileUtils.java
123126
WLSDPLY-01100=Failed to get the canonical file for {0} so falling back to absolute file instead: {1}
124127
WLSDPLY-01101=File {0} does not exist

core/src/test/python/aliases_test.py

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
from org.python.modules import jarray
@@ -407,7 +407,13 @@ def testGetWlstAttributeName2(self):
407407

408408
def testIsWlstModelAttributeName(self):
409409
wls_version = '10.3.6'
410-
online_aliases = Aliases(self.model_context, WlstModes.ONLINE, wls_version)
410+
arg_map = {
411+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
412+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
413+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '10.3.6'
414+
}
415+
online_model_context = ModelContext("test", arg_map)
416+
online_aliases = Aliases(online_model_context, WlstModes.ONLINE, wls_version)
411417
location = get_jdbc_driver_params_location('my-datasource', self.aliases)
412418
model_attribute_name = 'QosDegradationAllowed'
413419
path = self.aliases.get_model_folder_path(location)
@@ -440,6 +446,46 @@ def testIsWlstModelAttributeName(self):
440446
self.assertEqual(message, expected)
441447
return
442448

449+
def testIsPSUMatch(self):
450+
wls_version = '12.2.1.3.210929'
451+
arg_map = {
452+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
453+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
454+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.3.210929'
455+
}
456+
457+
this_model_context = ModelContext("test", arg_map)
458+
459+
online_aliases = Aliases(this_model_context, WlstModes.ONLINE, wls_version)
460+
location = LocationContext()
461+
location.append_location('SecurityConfiguration')
462+
location.add_name_token(online_aliases.get_name_token(location), 'domain')
463+
location.add_name_token('domain', 'system_test')
464+
model_attribute_name = 'RemoteAnonymousRmiiiopEnabled'
465+
value, message = online_aliases.is_valid_model_attribute_name(location, model_attribute_name)
466+
467+
self.assertEqual(value, 2)
468+
469+
wls_version = '12.2.1.4'
470+
arg_map = {
471+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
472+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
473+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.4'
474+
}
475+
476+
this_model_context = ModelContext("test", arg_map)
477+
478+
online_aliases = Aliases(this_model_context, WlstModes.ONLINE, wls_version)
479+
location = LocationContext()
480+
location.append_location('SecurityConfiguration')
481+
location.add_name_token(online_aliases.get_name_token(location), 'domain')
482+
location.add_name_token('domain', 'system_test')
483+
model_attribute_name = 'RemoteAnonymousRmiiiopEnabled'
484+
value, message = online_aliases.is_valid_model_attribute_name(location, model_attribute_name)
485+
486+
self.assertEqual(value, 1)
487+
return
488+
443489
def testPropertyTypes(self):
444490
expected = Properties()
445491
expected.put('key1', 'val1')
@@ -503,9 +549,20 @@ def testNewGetWlstPaths(self):
503549
def testVersionFilteredFolders(self):
504550
old_wls_version = '10.3.6'
505551
new_wls_version = '12.2.1.3'
506-
507-
old_aliases = Aliases(self.model_context, WlstModes.OFFLINE, old_wls_version)
508-
new_aliases = Aliases(self.model_context, WlstModes.OFFLINE, new_wls_version)
552+
arg_map = {
553+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
554+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
555+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '10.3.6'
556+
}
557+
old_model_context = ModelContext("test", arg_map)
558+
old_aliases = Aliases(old_model_context, WlstModes.OFFLINE, old_wls_version)
559+
arg_map = {
560+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
561+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
562+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.3'
563+
}
564+
new_model_context = ModelContext("test", arg_map)
565+
new_aliases = Aliases(new_model_context, WlstModes.OFFLINE, new_wls_version)
509566
location = LocationContext()
510567
location.append_location(FOLDERS.PARTITION)
511568
mbean_type = old_aliases.get_wlst_mbean_type(location)
@@ -525,9 +582,20 @@ def testVersionFilteredFolders(self):
525582
def testVersionFilteredFoldersWithFolderParams(self):
526583
old_wls_version = '10.3.6'
527584
new_wls_version = '12.2.1.3'
528-
529-
old_aliases = Aliases(self.model_context, WlstModes.OFFLINE, old_wls_version)
530-
new_aliases = Aliases(self.model_context, WlstModes.OFFLINE, new_wls_version)
585+
arg_map = {
586+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
587+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
588+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '10.3.6'
589+
}
590+
old_model_context = ModelContext("test", arg_map)
591+
old_aliases = Aliases(old_model_context, WlstModes.OFFLINE, old_wls_version)
592+
arg_map = {
593+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
594+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
595+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.3'
596+
}
597+
new_model_context = ModelContext("test", arg_map)
598+
new_aliases = Aliases(new_model_context, WlstModes.OFFLINE, new_wls_version)
531599
location = LocationContext()
532600
location.append_location(FOLDERS.SAF_AGENT)
533601
name_token = old_aliases.get_name_token(location)
@@ -774,8 +842,13 @@ def testIsValidModelFolderName(self):
774842
location = LocationContext()
775843
result, message = self.aliases.is_valid_model_folder_name(location, 'ServerTemplate')
776844
self.assertEqual(result, ValidationCodes.VALID)
777-
778-
aliases = Aliases(self.model_context, wls_version='12.1.1')
845+
arg_map = {
846+
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
847+
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
848+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.1.1'
849+
}
850+
this_model_context = ModelContext("test", arg_map)
851+
aliases = Aliases(this_model_context, wls_version='12.1.1')
779852
result, message = aliases.is_valid_model_folder_name(location, 'ServerTemplate')
780853
self.assertEqual(result, ValidationCodes.VERSION_INVALID)
781854

0 commit comments

Comments
 (0)