Skip to content

Network ports resolution between operator and wls runtime #2256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e2646a9
Provide a get around for wlst returning incorrect listening port/ssl …
jshum2479 Feb 26, 2021
10db0ad
Error out if secure mode is enabled but no ssl nap defined.
jshum2479 Mar 1, 2021
4ee7b72
cor
jshum2479 Mar 1, 2021
aaef308
fix getRealListenPort assignment issue
jshum2479 Mar 1, 2021
2acb008
Fixed comparision
jshum2479 Mar 1, 2021
c7fe574
missed some fix
jshum2479 Mar 1, 2021
4c7a2b4
Fix logic error when getting real listen ports
jshum2479 Mar 1, 2021
672e570
Fixed logic error when getting real listen port
jshum2479 Mar 1, 2021
c638caf
when nap public port is not set, just set it to same as listen port
jshum2479 Mar 2, 2021
331964e
refactor and restore nap listen port 0 check
jshum2479 Mar 8, 2021
d9cbe01
fix getRealListenPort bug
jshum2479 Mar 8, 2021
9d69e48
minor comment
jshum2479 Mar 8, 2021
8417e71
remove secure mode error out. There are ongoing discussion and the f…
jshum2479 Mar 9, 2021
9efbaad
refactoring
jshum2479 Mar 10, 2021
7755935
move helper outside of the class
jshum2479 Mar 10, 2021
46e66c0
remove public port requirements
jshum2479 Mar 10, 2021
f3c0636
fix script error
jshum2479 Mar 11, 2021
cba2477
fixed typo
jshum2479 Mar 11, 2021
e14a19d
fixes for pr comments
jshum2479 Mar 11, 2021
843daad
fix default value set but wlst offline returns otherwise
jshum2479 Mar 11, 2021
e2925b8
cleanup imports
jshum2479 Mar 11, 2021
f0c51bc
missed import
jshum2479 Mar 12, 2021
ee5da53
tempory
jshum2479 Mar 12, 2021
005ecf9
update comment and validation logic
jshum2479 Mar 12, 2021
5066b5c
fix text wordings
jshum2479 Mar 12, 2021
712434a
fixed script error
jshum2479 Mar 12, 2021
0a2f9aa
fixed string comparison
jshum2479 Mar 12, 2021
1607cb7
remove comments and obsolete codes
jshum2479 Mar 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes for pr comments
  • Loading branch information
jshum2479 committed Mar 11, 2021
commit e14a19d911b42fe6bd433c0dcb02d6658ad65d83
221 changes: 116 additions & 105 deletions operator/src/main/resources/scripts/introspectDomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def validateAdminServer(self):
return
adminServer = None
for server in self.env.getDomain().getServers():
self.validateServerTemplateNapListenPortIsSet(server)
if adminServerName == server.getName():
adminServer = server
if adminServer is None:
Expand Down Expand Up @@ -460,19 +461,12 @@ def validateNonDynamicClusterServersHaveSameListenPort(self, cluster):
if cluster is self.env.getClusterOrNone(server):
listenPort = getRealListenPort(server)
listenPortEnabled = isListenPortEnabledForServer(server, self.env.getDomain())
ssl = getSSLOrNone(server)
sslListenPort = None
sslListenPortEnabled = None
ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain())
ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain(), is_server_template=False)
if ssl_listen_port is not None:
sslListenPort = ssl_listen_port
sslListenPortEnabled = True
# if ssl is not None:
# sslListenPort = getRealSSLListenPort(server, ssl.getListenPort())
# sslListenPortEnabled = ssl.isEnabled()
# elif isSecureModeEnabledForDomain(self.env.getDomain()):
# sslListenPort = 7002
# sslListenPortEnabled = True

adminPort = getAdministrationPort(server, self.env.getDomain())
adminPortEnabled = isAdministrationPortEnabledForServer(server, self.env.getDomain())
Expand Down Expand Up @@ -545,6 +539,7 @@ def validateDynamicCluster(self, cluster):
def validateDynamicClusterReferencedByOneServerTemplate(self, cluster):
server_template=None
for template in self.env.getDomain().getServerTemplates():
self.validateServerTemplateNapListenPortIsSet(template)
if self.env.getClusterOrNone(template) is cluster:
if server_template is None:
server_template = template
Expand All @@ -555,6 +550,21 @@ def validateDynamicClusterReferencedByOneServerTemplate(self, cluster):
if server_template is None:
self.addError("The WebLogic dynamic cluster " + self.name(cluster) + "' is not referenced by any server template.")

def validateServerTemplateNapListenPortIsSet(self, server_or_template):
naps = server_or_template.getNetworkAccessPoints()
for nap in naps:
if nap.getListenPort() == 0:
self.addError(
"Invalid listen port value '"
+ str(nap.getListenPort())
+ "' in the WebLogic Domain for "
+ server_or_template.getName()
+ ' Network Channel '
+ nap.getName()
+ '. Please provide a valid value for the listen port, this is likely because of not specifying the port '
'value during domain '
'creation')

def validateDynamicClusterNotReferencedByAnyServers(self, cluster):
for server in self.env.getDomain().getServers():
if self.env.getClusterOrNone(server) is cluster:
Expand Down Expand Up @@ -662,31 +672,20 @@ def addServer(self, server, is_server_template=False):
self.writeln(" listenAddress: " + self.quote(self.env.toDNS1123Legal(self.env.getDomainUID() + "-" + server.getName())))
if isAdministrationPortEnabledForServer(server, self.env.getDomain(), is_server_template):
self.writeln(" adminPort: " + str(getAdministrationPort(server, self.env.getDomain())))
self.addSSL(server)
self.addSSL(server, is_server_template)
self.addNetworkAccessPoints(server, is_server_template)

def addSSL(self, server):
def addSSL(self, server, is_server_template):
'''
Write the SSL topology information to the output
Write the SSL topology information to the topology yaml output
:param server: Server or ServerTemplate
'''
# ssl = getSSLOrNone(server)
ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain())
ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain(), is_server_template)
if ssl_listen_port is not None:
self.indent()
self.writeln("sslListenPort: " + str(ssl_listen_port))
self.undent()

# if ssl is not None and ssl.isEnabled():
# sslport = getRealSSLListenPort(server, ssl.getListenPort())
# self.indent()
# self.writeln("sslListenPort: " + str(sslport))
# self.undent()
# elif ssl is None and isSecureModeEnabledForDomain(self.env.getDomain()):
# self.indent()
# self.writeln("sslListenPort: 7002")
# self.undent()

def addServerTemplates(self):
serverTemplates = self.env.getDomain().getServerTemplates()
if len(serverTemplates) == 0:
Expand Down Expand Up @@ -791,30 +790,8 @@ def addNetworkAccessPoint(self, server, nap, is_server_template):
name=self.name(nap)
self.writeln(" - name: " + name)
self.writeln(" protocol: " + self.quote(nap_protocol))
if nap.getListenPort() == 0:
trace("SEVERE", "Invalid listen port value '"
+ str(nap.getListenPort())
+ "' in the WebLogic Domain for "
+ server.getName()
+ ' Network Channel '
+ nap.getName()
+ '. Please provide a valid value for the listen port, this is likely because of not specifying the port '
'value during domain '
'creation')
sys.exit(1)

self.writeln(" listenPort: " + str(nap.getListenPort()))
# if nap.getPublicPort() == 0:
# trace("SEVERE", "Invalid public listen port value '"
# + str(nap.getListenPort())
# + "' in the WebLogic Domain for "
# + server.getName()
# + ' Network Channel '
# + nap.getName()
# + '. Please provide a valid value for the public port, this is likely because of not specifying the port '
# 'value during domain '
# 'creation')
# sys.exit(1)
self.writeln(" publicPort: " + str(nap.getPublicPort()))


Expand All @@ -840,15 +817,7 @@ def addIstioNetworkAccessPoints(self, server, is_server_template, added_nap):
self.addIstioNetworkAccessPoint("tcp-snmp", "snmp", getRealListenPort(server), 0)
self.addIstioNetworkAccessPoint("tcp-iiop", "iiop", getRealListenPort(server), 0)

# ssl = getSSLOrNone(server)
# ssl_listen_port = None
# if ssl is not None and ssl.isEnabled():
# ssl_listen_port = getRealSSLListenPort(server, ssl.getListenPort())
# elif ssl is None and isSecureModeEnabledForDomain(self.env.getDomain()):
# ssl_listen_port = "7002"
#

ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain())
ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain(), is_server_template)

if ssl_listen_port is not None:
self.addIstioNetworkAccessPoint("https-secure", "https", ssl_listen_port, 0)
Expand Down Expand Up @@ -1245,14 +1214,7 @@ def customizeServerIstioNetworkAccessPoint(self, listen_address, server):
self._writeIstioNAP(name='tcp-iiop', server=server, listen_address=listen_address,
listen_port=admin_server_port, protocol='iiop')

# ssl = getSSLOrNone(server)
# ssl_listen_port = None
# if ssl is not None and ssl.isEnabled():
# ssl_listen_port = getRealSSLListenPort(server, ssl.getListenPort())
# elif ssl is None and isSecureModeEnabledForDomain(self.env.getDomain()):
# ssl_listen_port = "7002"

ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain())
ssl_listen_port = getSSLPortIfEnabled(server, self.env.getDomain(), is_server_template=False)

if ssl_listen_port is not None:
self._writeIstioNAP(name='https-secure', server=server, listen_address=listen_address,
Expand Down Expand Up @@ -1302,12 +1264,6 @@ def customizeManagedIstioNetworkAccessPoint(self, listen_address, template):
self._writeIstioNAP(name='tcp-iiop', server=template, listen_address=listen_address,
listen_port=listen_port, protocol='iiop')

# ssl = getSSLOrNone(template)
# ssl_listen_port = None
# if ssl is not None and ssl.isEnabled():
# ssl_listen_port = getRealSSLListenPort(template, ssl.getListenPort())
# elif ssl is None and isSecureModeEnabledForDomain(self.env.getDomain()):
# ssl_listen_port = "7002"
ssl_listen_port = getSSLPortIfEnabled(template, self.env.getDomain())

if ssl_listen_port is not None:
Expand Down Expand Up @@ -1697,31 +1653,18 @@ def introspect(self):

tg.generate()

# Work-around bugs in off-line WLST when accessing an SSL mbean
def getSSLOrNone(server):
try:
# this can throw if SSL mbean not there
ret = server.getSSL()
# this can throw if SSL mbean is there but enabled is false
ret.getListenPort()
# this can throw if SSL mbean is there but enabled is false
ret.isEnabled()
except:
trace("Ignoring getSSL() exception, this is expected.")
ret = None

return ret

def getRealSSLListenPort(server, sslport):
"""
Return the real ssl listening port that will be used in runtime.
This is the actual port that WebLogic will bind to. This occurs when user
specify 7002 in the model or wlst offline when creating the domain which results empty
entry in the config.xml. The introspector using wlst offline to read the domain and the
mbean returns 8100. we cannot use this in the topology when setting up the container port
since the actual listening port is 7002.
Return the real listening port that will be used in runtime,
which can be different than is reported by WLST off-line.

If it is not a server template, then just return from the mbean.
The difference occurs when a user specifies 7002 in the model
or wlst offline for a server template when creating the domain,
which results in an empty entry in the config.xml. When subsequently
Copy link

@tbarnes-us tbarnes-us Mar 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an empty entry -> an empty entry or a 7002 entry

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

using wlst offline to read the domain, the mbean mistakenly
returns 8100 but the actual listening port is 7001.

If it is not a server template, then just return from the mbean.

:param server: server or server template
:param sslport: sslport from wlst offline mbean
Expand All @@ -1737,30 +1680,33 @@ def getRealSSLListenPort(server, sslport):

return sslport

def getRealListenPort(server):
def getRealListenPort(template):
"""
Return the real listening port that will be used in runtime.
This is the actual port that WebLogic will bind to. This occurs when user
specify 7001 in the model or wlst offline when creating the domain which results empty
entry in the config.xml. The introspector using wlst offline to read the domain and the
mbean returns 7100. we cannot use this in the topology when setting up the container port
since the actual listening port is 7001.
Return the real listening port that will be used in runtime,
which can be different than is reported by WLST off-line.

The difference occurs when a user specifies 7001 in the model
or wlst offline for a server template when creating the domain,
which results in an empty entry in the config.xml. When subsequently

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an empty entry -> an empty entry or a 7001 entry

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

using wlst offline to read the domain, the mbean mistakenly
returns 7100 but the actual listening port is 7001.

If it is not a server template, then just return from the mbean.
If it is not a server template, then just return from the mbean.

:param server: server or server template
:return: listening port
"""
if server_template_listening_ports.has_key(server.getName()):
port = server_template_listening_ports[server.getName()]
if server_template_listening_ports.has_key(template.getName()):
port = server_template_listening_ports[template.getName()]
if port is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if port is not None but has the value of 7001?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then server.getListenPort (actually it's a template) returns 7001, the server_template_listening_ports contains the actual value in the config.xml or None if no entry. Since we only care the case where there is no entry, I let the case to turn from the mbean.

Copy link
Member

@doxiao doxiao Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, since the server here is a template, WLS will treat the value as 7001, but mbean will likely return 7100.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow this use case still does not work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a string comparison issue, fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works now. thanks.

return 7001

port = server.getListenPort()
port = template.getListenPort()
# Probably don't need this - unlike NAP that can be 0.
if port == 0:
return 7001

return server.getListenPort()
return port


# Derive the default value for SecureMode of a domain
Expand Down Expand Up @@ -1838,15 +1784,80 @@ def isSSLListenPortEnabled(ssl, domain):
enabled = True
return enabled

def getSSLPortIfEnabled(server, domain):
ssl = getSSLOrNone(server)
def getSSLPortIfEnabled(server, domain, is_server_template=True):
"""
return the SSL listen port if enabled -
If SSL is enabled:
If is_server_template is False then just return the SSL listen port from server mbean.
If is_server_template is True then return the actual SSL listen port that it listens on. If the server

If SSL is not enabled but domain has SecureMode enabled return 7002.
:param server: server or server template
:param domain: domain mbean
:return: SSL listen port
"""
ssl = None
ssl_listen_port = None
try:
# this can throw if SSL mbean not there
ssl = server.getSSL()
# this can throw if SSL mbean is there but enabled is false
ssl.getListenPort()
# this can throw if SSL mbean is there but enabled is false ??
ssl.isEnabled()
except:
pass

if ssl is not None and ssl.isEnabled():
ssl_listen_port = getRealSSLListenPort(server, ssl.getListenPort())
if not is_server_template:
ssl_listen_port = ssl.getListenPort()
else:
ssl_listen_port = getRealSSLListenPort(server, ssl.getListenPort())
elif ssl is None and isSecureModeEnabledForDomain(domain):
ssl_listen_port = "7002"
return ssl_listen_port

def get_server_template_listening_ports_from_configxml(config_xml):
'''
get_server_tempalate's listening port and ssl port from the config.xml
:param config_xml: full path to config.xml
:return: dictionary of servertemplate ssl port and servertemplate listen port
'''
DOMTree = parse(config_xml)
collection = DOMTree.documentElement

templates = collection.getElementsByTagName("server-template")
server_template_ssls = dict()
server_template_ports = dict()

# if port is not specified in config.xml, set to None

for template in templates:
sslport = None
port = None
if template.parentNode.nodeName != 'domain':
continue
template_name = template.getElementsByTagName('name')[0].firstChild.nodeValue
# Get listen port
listen_ports = template.getElementsByTagName('listen-port')

for listen_port in listen_ports:
if listen_port.parentNode.nodeName == 'server-template':
port = listen_port.firstChild.nodeValue
break
server_template_ports[template_name] = port

# Get ssl port
ssls = template.getElementsByTagName('ssl')
if len(ssls) > 0:
ssl = ssls.item(0)
listen_port = ssl.getElementsByTagName('listen-port')
if len(listen_port) > 0:
sslport = listen_port[0].firstChild.nodeValue
server_template_ssls[template_name] = sslport

return server_template_ssls, server_template_ports

def main(env):
try:
# Needs to build the domain first
Expand Down
40 changes: 0 additions & 40 deletions operator/src/main/resources/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,44 +64,4 @@ def trace(arg1,arg2='SENTINEL'):
else:
traceInner(arg1,arg2)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there is no substantive change to this file. If so, can you revert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

def get_server_template_listening_ports_from_configxml(config_xml):
'''
get_server_tempalate's listening port and ssl port from the config.xml
:param config_xml: full path to config.xml
:return: dictionary of servertemplate ssl port and servertemplate listen port
'''
DOMTree = parse(config_xml)
collection = DOMTree.documentElement

templates = collection.getElementsByTagName("server-template")
server_template_ssls = dict()
server_template_ports = dict()

# if port is not specified in config.xml, set to None

for template in templates:
sslport = None
port = None
if template.parentNode.nodeName != 'domain':
continue
template_name = template.getElementsByTagName('name')[0].firstChild.nodeValue
# Get listen port
listen_ports = template.getElementsByTagName('listen-port')

for listen_port in listen_ports:
if listen_port.parentNode.nodeName == 'server-template':
port = listen_port.firstChild.nodeValue
break
server_template_ports[template_name] = port

# Get ssl port
ssls = template.getElementsByTagName('ssl')
if len(ssls) > 0:
ssl = ssls.item(0)
listen_port = ssl.getElementsByTagName('listen-port')
if len(listen_port) > 0:
sslport = listen_port[0].firstChild.nodeValue
server_template_ssls[template_name] = sslport

return server_template_ssls, server_template_ports