Skip to content

remote processing of discover #1127

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 22 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
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
491 changes: 325 additions & 166 deletions core/src/main/java/oracle/weblogic/deploy/util/WLSDeployArchive.java

Large diffs are not rendered by default.

83 changes: 72 additions & 11 deletions core/src/main/python/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
from wlsdeploy.tool.util.wlst_helper import WlstHelper
from wlsdeploy.tool.validate.validator import Validator
from wlsdeploy.util import cla_helper
from wlsdeploy.util import cla_utils
from wlsdeploy.util import model_translator
from wlsdeploy.util import path_utils
from wlsdeploy.util import tool_exit
from wlsdeploy.util.cla_utils import CommandLineArgUtil
from wlsdeploy.util.cla_utils import TOOL_TYPE_DISCOVER
from wlsdeploy.util.model import Model
from wlsdeploy.util.weblogic_helper import WebLogicHelper
from wlsdeploy.util import target_configuration_helper
Expand Down Expand Up @@ -80,7 +82,8 @@
CommandLineArgUtil.ADMIN_PASS_ENV_SWITCH,
CommandLineArgUtil.TARGET_MODE_SWITCH,
CommandLineArgUtil.OUTPUT_DIR_SWITCH,
CommandLineArgUtil.TARGET_SWITCH
CommandLineArgUtil.TARGET_SWITCH,
CommandLineArgUtil.REMOTE_SWITCH
]


Expand All @@ -93,14 +96,15 @@ def __process_args(args):
global __wlst_mode

cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
argument_map = cla_util.process_args(args)
argument_map = cla_util.process_args(args, TOOL_TYPE_DISCOVER)

__wlst_mode = cla_helper.process_online_args(argument_map)
target_configuration_helper.process_target_arguments(argument_map)
__process_model_archive_args(argument_map)
__process_archive_filename_arg(argument_map)
__process_variable_filename_arg(argument_map)
__process_java_home(argument_map)
__process_domain_home(argument_map, __wlst_mode)

return model_context_helper.create_context(_program_name, argument_map)

Expand All @@ -112,7 +116,8 @@ def __process_model_archive_args(argument_map):
"""
_method_name = '__process_model_archive_args'
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH not in argument_map:
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map:
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH not in argument_map and \
CommandLineArgUtil.REMOTE_SWITCH not in argument_map:
ex = exception_helper.create_cla_exception(CommandLineArgUtil.USAGE_ERROR_EXIT_CODE, 'WLSDPLY-06028')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
Expand All @@ -130,7 +135,7 @@ def __process_archive_filename_arg(argument_map):
"""
_method_name = '__process_archive_filename_arg'

if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map:
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or CommandLineArgUtil.REMOTE_SWITCH in argument_map:
archive_file = WLSDeployArchive.noArchiveFile()
else:
archive_file_name = argument_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
Expand All @@ -151,6 +156,7 @@ def __process_archive_filename_arg(argument_map):
argument_map[CommandLineArgUtil.ARCHIVE_FILE] = archive_file



def __process_variable_filename_arg(optional_arg_map):
"""
If the variable filename argument is present, the required model variable injector json file must exist in
Expand Down Expand Up @@ -191,6 +197,19 @@ def __process_java_home(optional_arg_map):
class_name=_class_name, method_name=_method_name)


def __process_domain_home(arg_map, wlst_mode):
domain_home = None
if CommandLineArgUtil.DOMAIN_HOME_SWITCH not in arg_map:
return
domain_home = arg_map[CommandLineArgUtil.DOMAIN_HOME_SWITCH]
skip_archive = False
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in arg_map or CommandLineArgUtil.REMOTE_SWITCH in arg_map:
skip_archive = True
if wlst_mode == WlstModes.OFFLINE or not skip_archive:
full_path = cla_utils.validate_domain_home_arg(domain_home)
arg_map[CommandLineArgUtil.DOMAIN_HOME_SWITCH] = full_path


def __discover(model_context, aliases, credential_injector, helper):
"""
Populate the model from the domain.
Expand Down Expand Up @@ -224,8 +243,23 @@ def __discover(model_context, aliases, credential_injector, helper):
ae.getLocalizedMessage(), error=ae)
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex

__disconnect_domain(helper)

if model_context.is_remote():
print ''
remote_map = WLSDeployArchive.getRemoteList()
if len(remote_map) == 0:
message = exception_helper.get_message('WLSDPLY-06030')
else:
message = exception_helper.get_message('WLSDPLY-06031')
print message
print ''
for key in remote_map:
other_map = remote_map[key]
type = other_map[WLSDeployArchive.REMOTE_TYPE]
wls_archive = other_map[WLSDeployArchive.REMOTE_ARCHIVE_DIR]
print key, ' ', wls_archive
print ''
return model


Expand Down Expand Up @@ -307,12 +341,13 @@ def __clear_archive_file(model_context):
__logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
raise de

try:
archive_file.removeAllBinaries()
except WLSDeployArchiveIOException, wioe:
de = exception_helper.create_discover_exception('WLSDPLY-06005', wioe.getLocalizedMessage())
__logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
raise de
if not model_context.skip_archive() and not model_context.is_remote():
try:
archive_file.removeAllBinaries()
except WLSDeployArchiveIOException, wioe:
de = exception_helper.create_discover_exception('WLSDPLY-06005', wioe.getLocalizedMessage())
__logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
raise de


def __close_archive(model_context):
Expand Down Expand Up @@ -373,6 +408,10 @@ def __persist_model(model, model_context):
add_to_archive = False
model_file_name = model_context.get_model_file()
if model_file_name is None:
if model_context.skip_archive() or model_context.is_remote():
ex = exception_helper.create_discover_exception('WLSDPLY-06032')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
add_to_archive = True
try:
domain_name = model_context.get_domain_name()
Expand All @@ -396,6 +435,7 @@ def __persist_model(model, model_context):
if add_to_archive:
try:
archive_file = model_context.get_archive_file()
print '********** model_file_name ', model_file_name
archive_file.addModel(model_file, model_file_name)
if not model_file.delete():
model_file.deleteOnExit()
Expand Down Expand Up @@ -473,6 +513,26 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
return model


def __remote_report(model_context):
if not model_context.is_remote():
return
print ''
remote_map = discoverer.remote_dict
if len(remote_map) == 0:
message = exception_helper.get_message('WLSDPLY-06030')
else:
message = exception_helper.get_message('WLSDPLY-06031')
print message
print ''
for key in remote_map:
other_map = remote_map[key]
type = other_map[discoverer.REMOTE_TYPE]
wls_archive = other_map[discoverer.REMOTE_ARCHIVE_PATH]
print key, ' ', wls_archive
print ''
return


def __log_and_exit(model_context, exit_code, class_name, method_name):
"""
Helper method to log the exiting message and call sys.exit()
Expand Down Expand Up @@ -538,6 +598,7 @@ def main(args):

model = __check_and_customize_model(model, model_context, aliases, credential_injector)

__remote_report(model_context)
except DiscoverException, ex:
__logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(),
model_context.get_domain_home(), ex.getLocalizedMessage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from oracle.weblogic.deploy.util import FileUtils
from oracle.weblogic.deploy.util import PyOrderedDict as OrderedDict
from oracle.weblogic.deploy.util import WLSDeployArchive
from oracle.weblogic.deploy.util import WLSDeployArchiveIOException

from wlsdeploy.aliases import model_constants
Expand Down Expand Up @@ -163,23 +164,22 @@ def _add_custom_configuration_to_archive(self, model_name, model_value, location
new_name = model_value
if model_value is not None:
archive_file = self._model_context.get_archive_file()
file_name_path = self._convert_path(model_value)
config_file = None
try:
config_file = FileUtils.getCanonicalFile(File(file_name_path))
except (IOException, SecurityException), se:
_logger.warning('WLSDPLY-06314', cluster_name, file_name_path, se.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)
new_name = None
file_name_path = model_value
if not self._model_context.is_remote():
file_name_path = self._convert_path(model_value)
if not self._model_context.skip_archive():
try:
new_name = archive_file.addCoherenceConfigFile(cluster_name, new_name)
_logger.finer('WLSDPLY-06315', file_name_path, class_name=_class_name, method_name=_method_name)
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
_logger.warning('WLSDPLY-06316', cluster_name, file_name_path, wioe.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)
new_name = None
else:
new_name = archive_file.getCoherenceConfigArchivePath(cluster_name, new_name)
self.add_to_remote_map(file_name_path, new_name,
WLSDeployArchive.ArchiveEntryType.COHERENCE_CONFIG.name())

if file is not None:
try:
new_name = archive_file.addCoherenceConfigFile(cluster_name, config_file)
_logger.finer('WLSDPLY-06315', file_name_path, class_name=_class_name, method_name=_method_name)
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
_logger.warning('WLSDPLY-06316', cluster_name, file_name_path, wioe.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)
new_name = None

_logger.exiting(class_name=_class_name, method_name=_method_name, result=new_name)
return new_name
Expand All @@ -201,27 +201,39 @@ def _add_cache_config(self, model_name, model_value, location):
_logger.entering(cluster_name, model_name, model_value, class_name=_class_name, method_name=_method_name)
new_name = model_value
if model_value is not None:
success, url, file_name = self._get_from_url('Coherence Cluster ' + cluster_name + ' Cache Configuration', model_value)
success, url, file_name = self._get_from_url('Coherence Cluster ' + cluster_name + ' Cache Configuration',
model_value)
archive_file = self._model_context.get_archive_file()
if success:
if url is not None:
try:
new_name = archive_file.addCoherenceConfigFileFromUrl(cluster_name, url)
_logger.info('WLSDPLY-06317', cluster_name, url, new_name, class_name=_class_name,
method_name=_method_name)
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
_logger.warning('WLSDPLY-06318', cluster_name, model_value, 'url', wioe.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)
new_name = None
if self._model_context.is_remote():
new_name = archive_file.getCoherenceURLArchivePath(cluster_name, url)
self.add_to_remote_map(file_name, new_name,
WLSDeployArchive.ArchiveEntryType.COHERENCE_CONFIG.name())
elif not self._model_context.skip_archive():
try:
new_name = archive_file.addCoherenceConfigFileFromUrl(cluster_name, url)
_logger.info('WLSDPLY-06317', cluster_name, url, new_name, class_name=_class_name,
method_name=_method_name)
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
_logger.warning('WLSDPLY-06318', cluster_name, model_value, 'url', wioe.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)
new_name = None
elif file_name is not None:
file_name = self._convert_path(file_name)
try:
new_name = archive_file.addCoherenceConfigFile(cluster_name, File(file_name))
_logger.info('WLSDPLY-06319', cluster_name, file_name, new_name, class_name=_class_name,
method_name=_method_name)
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
_logger.warning('WLSDPLY-06318', cluster_name, file_name, 'file', wioe.getLocalizedMessage())
new_name = None
if not self._model_context.is_remote():
file_name = self._convert_path(file_name)
if self._model_context.is_remote():
new_name = archive_file.getCoherenceConfigArchivePath(file_name)
self.add_to_remote_map(file_name, new_name,
WLSDeployArchive.ArchiveEntryType.COHERENCE_CONFIG.name())
elif not self._model_context.skip_archive():
try:
new_name = archive_file.addCoherenceConfigFile(cluster_name, file_name)
_logger.info('WLSDPLY-06319', cluster_name, file_name, new_name, class_name=_class_name,
method_name=_method_name)
except (IllegalArgumentException, WLSDeployArchiveIOException), wioe:
_logger.warning('WLSDPLY-06318', cluster_name, file_name, 'file', wioe.getLocalizedMessage())
new_name = None

_logger.exiting(class_name=_class_name, method_name=_method_name, result=new_name)
return new_name
Expand Down Expand Up @@ -253,14 +265,19 @@ def _add_persistence_directory(self, model_name, model_value, location, dir_type
new_name = model_value
if model_value is not None:
archive_file = self._model_context.get_archive_file()
try:
new_name = archive_file.addCoherencePersistenceDirectory(cluster_name, dir_type)
_logger.info('WLSDPLY-06320', cluster_name, model_value, dir_type, class_name=_class_name,
method_name=_method_name)
except WLSDeployArchiveIOException, wioe:
_logger.warning('WLSDPLY-06318', cluster_name, model_value, dir_type, wioe.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)
new_name = None
if self._model_context.is_remote():
new_name = archive_file.getCoherencePersistArchivePath(cluster_name, dir_type)
self.add_to_remote_map(model_value, new_name,
WLSDeployArchive.ArchiveEntryType.COHERENCE_PERSISTENCE_DIR.name())
elif not self._model_context.skip_archive():
try:
new_name = archive_file.addCoherencePersistenceDirectory(cluster_name, dir_type)
_logger.info('WLSDPLY-06320', cluster_name, model_value, dir_type, class_name=_class_name,
method_name=_method_name)
except WLSDeployArchiveIOException, wioe:
_logger.warning('WLSDPLY-06318', cluster_name, model_value, dir_type, wioe.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)
new_name = None

_logger.exiting(class_name=_class_name, method_name=_method_name, result=new_name)
return new_name
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def archive_jdbc_create_script(self, jdbc_store_name, jdbc_store_dictionary):
file_name = self._convert_path(jdbc_store_dictionary[model_constants.CREATE_TABLE_DDL_FILE])
_logger.info('WLSDPLY-06352', jdbc_store_name, file_name, class_name=_class_name, method_name=_method_name)
try:
new_source_name = archive_file.addScript(File(file_name))
new_source_name = archive_file.addScript(file_name)
except IllegalArgumentException, iae:
_logger.warning('WLSDPLY-06353', jdbc_store_name, file_name,
iae.getLocalizedMessage(), class_name=_class_name,
Expand Down Expand Up @@ -376,14 +376,16 @@ def _add_wldf_script(self, model_name, model_value, location):
_logger.entering(model_name, class_name=_class_name, method_name=_method_name)
new_script_name = model_value
if model_value is not None:
file_name = self._convert_path(model_value)
file_name = model_value
if not self._model_context.is_remote():
file_name = self._convert_path(model_value)
_logger.info('WLSDPLY-06359', file_name, self._aliases.get_model_folder_path(location),
class_name=_class_name, method_name=_method_name)
archive_file = self._model_context.get_archive_file()
# Set model_value to None if unable to add it to archive file
modified_name = None
try:
modified_name = archive_file.addScript(File(file_name))
modified_name = archive_file.addScript(file_name)
except IllegalArgumentException, iae:
_logger.warning('WLSDPLY-06360', self._aliases.get_model_folder_path(location), file_name,
iae.getLocalizedMessage(), class_name=_class_name,
Expand Down
Loading