Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions core/src/main/java/oracle/weblogic/deploy/util/XPathUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright (c) 2021, Oracle Corporation and/or its affiliates.
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
*/
package oracle.weblogic.deploy.util;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;

import oracle.weblogic.deploy.logging.PlatformLogger;
import oracle.weblogic.deploy.logging.WLSDeployLogFactory;

/*
* Parse the xml file at the designated location for the PSU value
*/
public class XPathUtil {
private static final PlatformLogger LOGGER = WLSDeployLogFactory.getLogger("wlsdeploy.util");
String oracle_home;
String patches_home;
public XPathUtil(String oracle_home){
this.oracle_home = oracle_home;
patches_home = Paths.get(oracle_home, "inventory", "patches").toString();
}
private static XPathFactory factory = null;

private static synchronized XPathFactory factory() {
if (factory == null) {
factory = XPathFactory.newInstance();
}
return factory;
}

/*
* Get the PSU if one exists at the inventory/patches files. Look at the description
* for the PSU wording.
*/
public String getPSU() {
// find the names in the directory first
if (!(new File(patches_home)).exists()) {
LOGGER.info("No patches home at {0}", patches_home);
return null;
}
List<String> patch_files = findPatchFiles();
List<String> list = new ArrayList<>();
for (String patch_file : patch_files){
Document doc = readXmlFile(patch_file);
String descrip = description(doc, "//@description");
LOGGER.fine("Description {0}", descrip);
if (descrip != null && descrip.startsWith("WLS PATCH SET UPDATE")) {
int idx = descrip.lastIndexOf('.');
String psu = descrip.substring(idx+1);
list.add(psu);
Collections.sort(list);
return list.get(list.size() -1);
}
}
return null;
}

/**
* Locate the patch files in the Oracle hom
* @return list of patch file names.
*/
public List<String> findPatchFiles() {
List<String> patch_files = new ArrayList<String>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(new File(patches_home).toPath())){
for (Path path : stream) {
patch_files.add(path.toString());
}
} catch (IOException ieo) {
LOGGER.info("Unable to locate the patch files at {0}", patches_home);
}
return patch_files;
}

/**
* Read the xml file at the indicated path.
* @param path to the xml file
* @return Document from the parsed xml file
*/
public Document readXmlFile(String path) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (ParserConfigurationException pce) {
LOGGER.warning("Unable to set feature in DocumentBuilderFactory : {0}");
}

Document doc = null;
try {
// parse XML file
DocumentBuilder db = dbf.newDocumentBuilder();

doc = db.parse(new File(path));

} catch (ParserConfigurationException | SAXException | IOException ioe) {
LOGGER.info("Unable to parse the xml file {0}", path);
}
return doc;
}

/**
* Apply the expression against the Node and return a String.
* @param node parsed xml file Node to search
* @param expression to evaluate on the Node
* @return the String value if located in the Node
*/
private String description(Node node, String expression) {
XPath xpath = factory().newXPath();
try {
return (String) xpath.evaluate(expression, node, XPathConstants.STRING);
} catch (XPathExpressionException xpe) {
LOGGER.info("Unable to apply the expression {0}", expression);
}
return null;
}
}
4 changes: 1 addition & 3 deletions core/src/main/python/wlsdeploy/aliases/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ def __init__(self, model_context, wlst_mode=WlstModes.OFFLINE, wls_version=None,
self._logger = PlatformLogger('wlsdeploy.aliases')

if wls_version is None:
from wlsdeploy.util.weblogic_helper import WebLogicHelper
self._wls_helper = WebLogicHelper(self._logger)
self._wls_version = self._wls_helper.wl_version_actual
self._wls_version = self._model_context.get_target_wls_version()
else:
self._wls_version = wls_version

Expand Down
8 changes: 8 additions & 0 deletions core/src/main/python/wlsdeploy/util/model_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.net.URI as URI

from oracle.weblogic.deploy.util import XPathUtil
from wlsdeploy.aliases.wlst_modes import WlstModes
from wlsdeploy.logging import platform_logger
from wlsdeploy.util.cla_utils import CommandLineArgUtil
Expand Down Expand Up @@ -99,6 +100,7 @@ def __init__(self, program_name, arg_map):
if self._wl_version is None:
self._wl_version = self._wls_helper.get_actual_weblogic_version()


if self._wlst_mode is None:
self._wlst_mode = WlstModes.OFFLINE

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

def __copy_from_args(self, arg_map):
_method_name = '__copy_from_args'
if CommandLineArgUtil.ORACLE_HOME_SWITCH in arg_map:
self._oracle_home = arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH]
psu = XPathUtil(self._oracle_home).getPSU()
if psu is not None:
self._wl_version += '.' + psu
self._logger.info('WLSDPLY-01050', self._wl_version, class_name=self._class_name,
method_name=_method_name)
self._wl_home = self._wls_helper.get_weblogic_home(self._oracle_home)

if CommandLineArgUtil.JAVA_HOME_SWITCH in arg_map:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1418,8 +1418,10 @@
"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" } ,
{"version": "[10,)", "wlst_mode": "online", "wlst_name": "RealmBootStrapVersion", "wlst_path": "WP001", "value": {"default": "1" }, "wlst_type": "string", "get_method": "GET", "restart_required": "true" } ],
"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" } ],
"RemoteAnonymousRmiiiopEnabled": [ {"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
"RemoteAnonymousRmit3Enabled": [ {"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
"RemoteAnonymousRmiiiopEnabled": [ {"version": "[12.2.1.4.0.210930,12.2.1.5)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" },
{"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmiiiop:RMIIIOP}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
"RemoteAnonymousRmit3Enabled": [ {"version": "[12.2.1.4.0.210930,12.2.1.5)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ,
{"version": "[14.1.1,)", "wlst_mode": "both", "wlst_name": "RemoteAnonymous${Rmit3:RMIT3}Enabled", "wlst_path": "WP001", "value": {"default": "true" }, "wlst_type": "boolean" } ],
"UseKSSForDemo": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "UseKSSForDemo", "wlst_path": "WP001", "value": {"default": "false" }, "wlst_type": "boolean", "restart_required": "true" } ],
"WebAppFilesCaseInsensitive": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "WebAppFilesCaseInsensitive", "wlst_path": "WP001", "value": {"default": "${None:false}"}, "wlst_type": "string", "restart_required": "true" } ]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ WLSDPLY-00127=Unable to load the DomainRuntimeService from the WLST globals : {0
# oracle.weblogic.deploy.util.CLAUtil.java
WLSDPLY-01000=Password was truncated to {0} characters

# oracle.weblogic.deploy.util.XPathUtils.java
WLSDPLY-01050=Weblogic version for aliases is {0}

# oracle.weblogic.deploy.util.FileUtils.java
WLSDPLY-01100=Failed to get the canonical file for {0} so falling back to absolute file instead: {1}
WLSDPLY-01101=File {0} does not exist
Expand Down
91 changes: 82 additions & 9 deletions core/src/test/python/aliases_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,13 @@ def testGetWlstAttributeName2(self):

def testIsWlstModelAttributeName(self):
wls_version = '10.3.6'
online_aliases = Aliases(self.model_context, WlstModes.ONLINE, wls_version)
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '10.3.6'
}
online_model_context = ModelContext("test", arg_map)
online_aliases = Aliases(online_model_context, WlstModes.ONLINE, wls_version)
location = get_jdbc_driver_params_location('my-datasource', self.aliases)
model_attribute_name = 'QosDegradationAllowed'
path = self.aliases.get_model_folder_path(location)
Expand Down Expand Up @@ -440,6 +446,46 @@ def testIsWlstModelAttributeName(self):
self.assertEqual(message, expected)
return

def testIsPSUMatch(self):
wls_version = '12.2.1.4.0.210930'
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.4.0.210930'
}

this_model_context = ModelContext("test", arg_map)

online_aliases = Aliases(this_model_context, WlstModes.ONLINE, wls_version)
location = LocationContext()
location.append_location('SecurityConfiguration')
location.add_name_token(online_aliases.get_name_token(location), 'domain')
location.add_name_token('domain', 'system_test')
model_attribute_name = 'RemoteAnonymousRmiiiopEnabled'
value, message = online_aliases.is_valid_model_attribute_name(location, model_attribute_name)

self.assertEqual(value, 2)

wls_version = '12.2.1.5'
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.5'
}

this_model_context = ModelContext("test", arg_map)

online_aliases = Aliases(this_model_context, WlstModes.ONLINE, wls_version)
location = LocationContext()
location.append_location('SecurityConfiguration')
location.add_name_token(online_aliases.get_name_token(location), 'domain')
location.add_name_token('domain', 'system_test')
model_attribute_name = 'RemoteAnonymousRmiiiopEnabled'
value, message = online_aliases.is_valid_model_attribute_name(location, model_attribute_name)

self.assertEqual(value, 1)
return

def testPropertyTypes(self):
expected = Properties()
expected.put('key1', 'val1')
Expand Down Expand Up @@ -503,9 +549,20 @@ def testNewGetWlstPaths(self):
def testVersionFilteredFolders(self):
old_wls_version = '10.3.6'
new_wls_version = '12.2.1.3'

old_aliases = Aliases(self.model_context, WlstModes.OFFLINE, old_wls_version)
new_aliases = Aliases(self.model_context, WlstModes.OFFLINE, new_wls_version)
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '10.3.6'
}
old_model_context = ModelContext("test", arg_map)
old_aliases = Aliases(old_model_context, WlstModes.OFFLINE, old_wls_version)
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.3'
}
new_model_context = ModelContext("test", arg_map)
new_aliases = Aliases(new_model_context, WlstModes.OFFLINE, new_wls_version)
location = LocationContext()
location.append_location(FOLDERS.PARTITION)
mbean_type = old_aliases.get_wlst_mbean_type(location)
Expand All @@ -525,9 +582,20 @@ def testVersionFilteredFolders(self):
def testVersionFilteredFoldersWithFolderParams(self):
old_wls_version = '10.3.6'
new_wls_version = '12.2.1.3'

old_aliases = Aliases(self.model_context, WlstModes.OFFLINE, old_wls_version)
new_aliases = Aliases(self.model_context, WlstModes.OFFLINE, new_wls_version)
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '10.3.6'
}
old_model_context = ModelContext("test", arg_map)
old_aliases = Aliases(old_model_context, WlstModes.OFFLINE, old_wls_version)
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.2.1.3'
}
new_model_context = ModelContext("test", arg_map)
new_aliases = Aliases(new_model_context, WlstModes.OFFLINE, new_wls_version)
location = LocationContext()
location.append_location(FOLDERS.SAF_AGENT)
name_token = old_aliases.get_name_token(location)
Expand Down Expand Up @@ -774,8 +842,13 @@ def testIsValidModelFolderName(self):
location = LocationContext()
result, message = self.aliases.is_valid_model_folder_name(location, 'ServerTemplate')
self.assertEqual(result, ValidationCodes.VALID)

aliases = Aliases(self.model_context, wls_version='12.1.1')
arg_map = {
CommandLineArgUtil.ORACLE_HOME_SWITCH: '/oracleHome',
CommandLineArgUtil.DOMAIN_HOME_SWITCH: '',
CommandLineArgUtil.TARGET_VERSION_SWITCH: '12.1.1'
}
this_model_context = ModelContext("test", arg_map)
aliases = Aliases(this_model_context, wls_version='12.1.1')
result, message = aliases.is_valid_model_folder_name(location, 'ServerTemplate')
self.assertEqual(result, ValidationCodes.VERSION_INVALID)

Expand Down