Skip to content

Commit af87cd9

Browse files
Issue#576 collect foreign server bindings archive (#577)
* Fix java.lang.Boolean issues for ActiveDirectoryAuthenticator * If file scheme for foreign server URL collect file into archive
1 parent 46bddc3 commit af87cd9

File tree

7 files changed

+115
-38
lines changed

7 files changed

+115
-38
lines changed

core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java

Lines changed: 33 additions & 2 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. All rights reserved.
2+
* Copyright (c) 2017, 2020, 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
package oracle.weblogic.deploy.util;
@@ -103,6 +103,17 @@ public class WLSDeployArchive {
103103
*/
104104
public static final String ARCHIVE_SCRIPTS_DIR = WLSDPLY_ARCHIVE_BINARY_DIR + "/scripts";
105105

106+
/**
107+
* Top-level archive subdirectory for JMS and in which its sub-directories will be separated.
108+
*/
109+
public static final String ARCHIVE_JMS_DIR = WLSDPLY_ARCHIVE_BINARY_DIR + "/jms";
110+
111+
/**
112+
* Top-level archive subdirectory where the JMS Foreign Server bindings files are stored and the
113+
* subdirectory to which they will be extracted.
114+
*/
115+
public static final String ARCHIVE_JMS_FOREIGN_SERVER_DIR = ARCHIVE_JMS_DIR + "/foreignServer";
116+
106117
// Used by the unit tests so it requires package level scoping...
107118
//
108119
/* package */
@@ -950,7 +961,6 @@ public String addMimeMappingFile(File mimeMappingFile) throws WLSDeployArchiveIO
950961
LOGGER.exiting(CLASS, METHOD, newName);
951962
return newName;
952963
}
953-
954964
/**
955965
* Add a Coherence configuration file to the archive.
956966
*
@@ -972,6 +982,27 @@ public String addCoherenceConfigFile(String clusterName, File configFile) throws
972982
return newName;
973983
}
974984

985+
/**
986+
* Add a Foreign Server binding file to the archive
987+
*
988+
* @param foreignServer the Foreign Server name used to segregate the directories
989+
* @param configFile the file to add
990+
* @return the new location of the file to use in the model
991+
* @throws WLSDeployArchiveIOException if an error occurs while archiving the file
992+
* @throws IllegalArgumentException if the file does not exist or the foreignServer is empty or null
993+
*/
994+
public String addForeignServerFile(String foreignServer, File configFile) throws WLSDeployArchiveIOException {
995+
final String METHOD = "addForeignServerFile";
996+
997+
LOGGER.entering(CLASS, METHOD, foreignServer, configFile);
998+
999+
validateNonEmptyString(foreignServer, "foreignServerName", METHOD);
1000+
validateExistingFile(configFile, "configFile", getArchiveFileName(), METHOD);
1001+
String newName = addItemToZip(ARCHIVE_JMS_FOREIGN_SERVER_DIR + ZIP_SEP + foreignServer, configFile);
1002+
LOGGER.exiting(CLASS, METHOD, newName);
1003+
return newName;
1004+
}
1005+
9751006
/**
9761007
* Add a Coherence configuration file to the archive from an http site.
9771008
*

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

Lines changed: 2 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. All rights reserved.
2+
Copyright (c) 2017, 2020, 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

@@ -66,6 +66,7 @@
6666
COHERENCE_WELL_KNOWN_ADDRESS = 'CoherenceClusterWellKnownAddress'
6767
CONFIGURATION_PROPERTY = 'ConfigurationProperty'
6868
CONNECTION_FACTORY = 'ConnectionFactory'
69+
CONNECTION_URL = 'ConnectionURL'
6970
CONTEXT_CASE = 'ContextCase'
7071
CONTEXT_REQUEST_CLASS = 'ContextRequestClass'
7172
CPU_UTILIZATION = 'CpuUtilization'

core/src/main/python/wlsdeploy/tool/discover/coherence_resources_discoverer.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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.io import File
66
from java.io import IOException
77
from java.lang import IllegalArgumentException
88
from java.lang import SecurityException
9-
from java.net import URI
10-
from java.net import URISyntaxException
11-
from java.net import MalformedURLException
9+
1210

1311
from oracle.weblogic.deploy.util import FileUtils
1412
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
@@ -200,8 +198,8 @@ def _add_cache_config(self, model_name, model_value, location):
200198
_logger.entering(cluster_name, model_name, model_value, class_name=_class_name, method_name=_method_name)
201199
new_name = model_value
202200
if model_value is not None:
201+
success, url, file_name = self._get_from_url('Coherence Cluster ' + cluster_name + ' Cache Configuration', model_value)
203202
archive_file = self._model_context.get_archive_file()
204-
success, url = _get_from_url(cluster_name, model_value)
205203
if success:
206204
if url is not None:
207205
try:
@@ -212,8 +210,8 @@ def _add_cache_config(self, model_name, model_value, location):
212210
_logger.warning('WLSDPLY-06318', cluster_name, model_value, 'url', wioe.getLocalizedMessage(),
213211
class_name=_class_name, method_name=_method_name)
214212
new_name = None
215-
else:
216-
file_name = self._convert_path(model_value)
213+
elif file_name is not None:
214+
file_name = self._convert_path(file_name)
217215
try:
218216
new_name = archive_file.addCoherenceConfigFile(cluster_name, File(file_name))
219217
_logger.info('WLSDPLY-06319', cluster_name, file_name, new_name, class_name=_class_name,
@@ -263,23 +261,3 @@ def _add_persistence_directory(self, model_name, model_value, location, dir_type
263261

264262
_logger.exiting(class_name=_class_name, method_name=_method_name, result=new_name)
265263
return new_name
266-
267-
268-
def _get_from_url(cluster_name, file_name):
269-
"""
270-
Determine if the provided file name is a URL location where the file is hosted. If it is a URL, return
271-
a URL stream that can be used to retrieve the file from the hosted location.
272-
:param cluster_name: of the coherence cluster being discovered
273-
:param file_name: of the file to be tested as a URL
274-
:return: True if the file is hosted at a URL: URL file handle for the archive file to retrieve the file
275-
"""
276-
url = None
277-
try:
278-
uri = URI(file_name)
279-
if 'http' == uri.getScheme():
280-
url = uri.toURL()
281-
except (URISyntaxException, MalformedURLException), e:
282-
_logger.warning('WLSDPLY-06321', cluster_name, file_name, e.getLocalizedMessage)
283-
return False, None
284-
285-
return True, url

core/src/main/python/wlsdeploy/tool/discover/discoverer.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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
import os
66

7+
from java.net import URI
8+
from java.net import URISyntaxException
9+
from java.net import MalformedURLException
10+
711
from oracle.weblogic.deploy.aliases import AliasException
812
from oracle.weblogic.deploy.discover import DiscoverException
913
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
10-
from oracle.weblogic.deploy.util import PyWLSTException
1114
from oracle.weblogic.deploy.util import StringUtils
1215

1316
from wlsdeploy.aliases.aliases import Aliases
@@ -723,6 +726,29 @@ def _massage_online_folders(self, lsc_folders):
723726
return folder_list
724727

725728

729+
def _get_from_url(self, owner_name, file_name):
730+
"""
731+
Determine if the provided file name is a URL location where the file is hosted. If it is a URL, return
732+
a URL stream that can be used to retrieve the file from the hosted location.
733+
:param owner_name: of the file being discovered
734+
:param file_name: of the file to be tested as a URL
735+
:return: True if the file is hosted at a URL: URL file handle for the archive file to retrieve the file, or path
736+
from file name
737+
"""
738+
url = None
739+
path = None
740+
try:
741+
uri = URI(file_name)
742+
if 'http' == uri.getScheme():
743+
url = uri.toURL()
744+
elif 'file' == uri.getScheme() or uri.getScheme() is None:
745+
path = uri.getPath()
746+
except (URISyntaxException, MalformedURLException), e:
747+
_logger.warning('WLSDPLY-06321', owner_name, file_name, e.getLocalizedMessage)
748+
return False, None, None
749+
750+
return True, url, path
751+
726752
def add_to_model_if_not_empty(dictionary, entry_name, entry_value):
727753
"""
728754
Helper method for discover to add a non-empty value to the dictionary with the provided entry-name

core/src/main/python/wlsdeploy/tool/discover/jms_resources_discoverer.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, 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
"""
5+
from java.io import File
6+
from java.lang import IllegalArgumentException
7+
58
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
9+
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException
610

711
from wlsdeploy.aliases import model_constants
812
from wlsdeploy.aliases.location_context import LocationContext
@@ -244,6 +248,11 @@ def _get_foreign_servers(self, location):
244248
result[server] = OrderedDict()
245249
location.add_name_token(name_token, server)
246250
self._populate_model_parameters(result[server], location)
251+
if model_constants.CONNECTION_URL in result[server]:
252+
_logger.finer('WLSDPLY-06494', server, class_name=_class_name, method_name=_method_name)
253+
result[server][model_constants.CONNECTION_URL] = \
254+
self._add_foreign_server_binding(server, model_constants.CONNECTION_URL,
255+
result[server][model_constants.CONNECTION_URL])
247256
wlst_subfolders = self._find_subfolders(location)
248257
if wlst_subfolders is not None:
249258
for wlst_subfolder in wlst_subfolders:
@@ -371,3 +380,32 @@ def _get_foreign_server_properties(self, location):
371380
location.pop_location()
372381
_logger.exiting(class_name=_class_name, method_name=_method_name, result=subfolder_result)
373382
return model_subfolder_name, subfolder_result
383+
384+
def _add_foreign_server_binding(self, server_name, model_name, model_value):
385+
"""
386+
If the foreign server connection URL contains a file URI, then collect the file into the archive.
387+
The attribute value will be updated to point to the location where the file will
388+
exist after the archive file is deployed.
389+
:param model_name: name of the foreign server connection URL name attribute
390+
:param model_value: containing the foreign connection URI value
391+
:return: updated foreign server file value or original URL
392+
"""
393+
_method_name = '_add_foreign_server_binding'
394+
_logger.entering(server_name, model_name, model_value, class_name=_class_name, method_name=_method_name)
395+
new_name = model_value
396+
if model_value is not None:
397+
success, _, file_name = self._get_from_url('Foreign Server ' + server_name + ' Connection URL', model_value)
398+
archive_file = self._model_context.get_archive_file()
399+
if success and file_name is not None:
400+
file_name = self._convert_path(file_name)
401+
_logger.finer('WLSDPLY-06495', server_name, file_name, class_name=_class_name, method_name=_method_name)
402+
try:
403+
new_name = archive_file.addForeignServerFile(server_name, File(file_name))
404+
_logger.info('WLSDPLY-06492', server_name, file_name, new_name, class_name=_class_name,
405+
method_name=_method_name)
406+
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
407+
_logger.warning('WLSDPLY-06493', server_name, file_name, wioe.getLocalizedMessage())
408+
new_name = None
409+
410+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=new_name)
411+
return new_name

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"copyright": "Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.",
2+
"copyright": "Copyright (c) 2017, 2020, 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": "JMSSystemResource${:s}",
55
"child_folders_type": "multiple",
@@ -271,8 +271,8 @@
271271
}
272272
},
273273
"attributes": {
274-
"ConnectionURL": [ {"version": "[10,12.2.1.4)", "wlst_mode": "both", "wlst_name": "ConnectionURL", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "restart_required": "true" } ,
275-
{"version": "[12.2.1.4,)", "wlst_mode": "both", "wlst_name": "ConnectionURL", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string" } ],
274+
"ConnectionURL": [ {"version": "[10,12.2.1.4)", "wlst_mode": "both", "wlst_name": "ConnectionURL", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "uses_path_tokens": "true", "restart_required": "true" } ,
275+
{"version": "[12.2.1.4,)", "wlst_mode": "both", "wlst_name": "ConnectionURL", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "uses_path_tokens": "true" } ],
276276
"DefaultTargetingEnabled": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "DefaultTargetingEnabled", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "boolean", "restart_required": "true" } ],
277277
"InitialContextFactory": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "InitialContextFactory", "wlst_path": "WP001", "value": {"default": "${None:weblogic.jndi.WLInitialContextFactory}" }, "wlst_type": "string" } ],
278278
"JNDIPropertiesCredentialEncrypted": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "JNDIPropertiesCredentialEncrypted", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "password", "get_method": "GET" } ],

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,7 @@ WLSDPLY-06317=Added Coherence Cluster {0} cache configuration file from URL loca
566566
WLSDPLY-06318=Unable to add Coherence Cluster {0} persistence directory {1} type {2} to archive file : {3}
567567
WLSDPLY-06319=Added Coherence Cluster {0} cache configuration file from location {1} to archive file with name {2}
568568
WLSDPLY-06320=Added Coherence Cluster {0} persistence directory {1} type {2} to archive file
569-
WLSDPLY-06321=Unable to access Coherence Cluster {0} cache configuration file {1} and will not add the file to \
570-
the archive : {2}
569+
WLSDPLY-06321=Unable to access {0} file {1} and will not add the file to the archive : {2}
571570
WLSDPLY-06322=Skipping {0} Coherence Cluster System Resource {1}
572571

573572
# common_resources_discoverer.py
@@ -672,6 +671,10 @@ WLSDPLY-06488=Key missing for Foreign JNDI Property Foreign Server {0} to {1}. T
672671
WLSDPLY-06489=Adding JNDI Property with name {0} to {1}
673672
WLSDPLY-06490=Skipping {0} JMS Server {1}
674673
WLSDPLY-06491=Skipping {0} JMS System Resource {1}
674+
WLSDPLY-06492=Unable to add Foreign Server {0} bindings file {1} to archive file : {2}
675+
WLSDPLY-06493=Added Foreign Server {0} bindings file from location {1} to archive file with name {2}
676+
WLSDPLY-06494=Check for Foreign Server {0} connection URL binding file
677+
WLSDPLY-06495=Add Connection URL file {1} to archive file for Foreign Server {0}
675678

676679
# topology_discoverer.py
677680
WLSDPLY-06600=Discovering domain model topology

0 commit comments

Comments
 (0)