Skip to content

Commit c328cd1

Browse files
Look up PSU for alias definition wls version
1 parent b2cbc29 commit c328cd1

File tree

7 files changed

+144
-11
lines changed

7 files changed

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ def is_valid_model_folder_name_for_location(self, location, model_folder_name):
790790
result = ValidationCodes.VALID
791791
else:
792792
folder_dict = self.__get_dictionary_for_location(location, False)
793+
793794
if folder_dict is None:
794795
ex = exception_helper.create_alias_exception('WLSDPLY-08113', model_folder_name,
795796
location.get_folder_path())

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ def __init__(self, model_context, wlst_mode=WlstModes.OFFLINE, wls_version=None,
7373
self._exception_type = exception_type
7474
self._logger = PlatformLogger('wlsdeploy.aliases')
7575

76-
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
80-
else:
81-
self._wls_version = wls_version
82-
76+
self._wls_version = self._model_context.get_target_wls_version()
8377
self._alias_entries = AliasEntries(wlst_mode, self._wls_version)
8478
return
8579

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,15 @@ 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+
self._logger.info("PSU is {0}", psu)
117+
if psu is not None:
118+
self._wl_version += '.' + psu
119+
self._logger.info('WLSDPLY-01050', self._wl_version, class_name=self._class_name,
120+
method_name=_method_name)
112121
self._wl_home = self._wls_helper.get_weblogic_home(self._oracle_home)
113122

114123
if CommandLineArgUtil.JAVA_HOME_SWITCH in arg_map:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,8 +1418,8 @@
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-
{"version": "[12.2.1.3.33344,12.2.1.4)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
1421+
"RemoteAnonymousRmiiiopEnabled": [ {"version": "[12.2.1.4.0.2000,12.2.1.5)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" },
1422+
{"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
14231423
"RemoteAnonymousRmit3Enabled": [ {"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
14241424
"UseKSSForDemo": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "UseKSSForDemo", "wlst_path": "WP001", "value": {"default": "false" }, "wlst_type": "boolean", "restart_required": "true" } ],
14251425
"WebAppFilesCaseInsensitive": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "WebAppFilesCaseInsensitive", "wlst_path": "WP001", "value": {"default": "${None:false}"}, "wlst_type": "string", "restart_required": "true" } ]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,11 @@ def testIsWlstModelAttributeName(self):
441441
return
442442

443443
def testIsPSUMatch(self):
444-
wls_version = '12.2.1.3.33344'
444+
wls_version = '12.2.1.4.2001'
445445
arg_map = {
446446
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
447447
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
448-
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.3.33344'
448+
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.4.2001'
449449
}
450450

451451
this_model_context = ModelContext("test", arg_map)

0 commit comments

Comments
 (0)