Skip to content

Write missing archive entries from discover to a results file if configured #1139

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 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
52 changes: 37 additions & 15 deletions core/src/main/python/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
from java.lang import IllegalStateException
from oracle.weblogic.deploy.aliases import AliasException
from oracle.weblogic.deploy.discover import DiscoverException
from oracle.weblogic.deploy.json import JsonException
from oracle.weblogic.deploy.util import CLAException
from oracle.weblogic.deploy.util import FileUtils
from oracle.weblogic.deploy.util import PyOrderedDict
from oracle.weblogic.deploy.util import PyWLSTException
from oracle.weblogic.deploy.util import TranslateException
from oracle.weblogic.deploy.util import WLSDeployArchive
Expand All @@ -30,6 +32,7 @@
from wlsdeploy.aliases.wlst_modes import WlstModes
from wlsdeploy.exception import exception_helper
from wlsdeploy.exception.expection_types import ExceptionType
from wlsdeploy.json import json_translator
from wlsdeploy.logging.platform_logger import PlatformLogger
from wlsdeploy.tool.discover import discoverer
from wlsdeploy.tool.discover.deployments_discoverer import DeploymentsDiscoverer
Expand Down Expand Up @@ -62,6 +65,8 @@
__logger = PlatformLogger(discoverer.get_discover_logger_name())
__wlst_mode = WlstModes.OFFLINE

_store_result_environment_variable = '__WLSDEPLOY_STORE_RESULT__'

__required_arguments = [
CommandLineArgUtil.ORACLE_HOME_SWITCH,
CommandLineArgUtil.DOMAIN_HOME_SWITCH
Expand Down Expand Up @@ -137,6 +142,11 @@ def __process_archive_filename_arg(argument_map):

if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or CommandLineArgUtil.REMOTE_SWITCH in argument_map:
archive_file = WLSDeployArchive.noArchiveFile()
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in argument_map:
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
'WLSDPLY-06033')
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
raise ex
else:
archive_file_name = argument_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
archive_dir_name = path_utils.get_parent_directory(archive_file_name)
Expand Down Expand Up @@ -245,20 +255,6 @@ def __discover(model_context, aliases, credential_injector, helper):
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]
wls_archive = other_map[WLSDeployArchive.REMOTE_ARCHIVE_DIR]
print key, ' ', wls_archive
print ''
return model


Expand Down Expand Up @@ -512,10 +508,36 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject


def __remote_report(model_context):
_method_name = '__remote_report'

if not model_context.is_remote():
return
print ''

remote_map = discoverer.remote_dict

# write JSON output if the __WLSDEPLOY_STORE_RESULT__ environment variable is set.
# write to the file before the stdout so any logging messages come first.
if os.environ.has_key(_store_result_environment_variable):
store_path = os.environ.get(_store_result_environment_variable)
__logger.info('WLSDPLY-06034', store_path, class_name=_class_name, method_name=_method_name)
missing_archive_entries = []
for key in remote_map:
archive_map = remote_map[key]
missing_archive_entries.append({
'path': key,
'sourceFile': archive_map[discoverer.REMOTE_ARCHIVE_PATH],
'type': archive_map[discoverer.REMOTE_TYPE]
})
result_root = PyOrderedDict()
result_root['missingArchiveEntries'] = missing_archive_entries
try:
json_translator.PythonToJson(result_root).write_to_json_file(store_path)
except JsonException, ex:
__logger.warning('WLSDPLY-06035', _store_result_environment_variable, ex.getLocalizedMessage(),
class_name=_class_name, method_name=_method_name)

# write to stdout
print ''
if len(remote_map) == 0:
message = exception_helper.get_message('WLSDPLY-06030')
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ WLSDPLY-06031=Remote discovery created a model that references files or director
that could not be collected. Please collect the items at the paths listed below and add them to the archive \
file at the specified locations.
WLSDPLY-06032=Model file name was not included in command arguments and either -skip_archive or -remote was included
WLSDPLY-06033=Archive file name was included in command arguments and either -skip_archive or -remote was selected
WLSDPLY-06034=Writing results file {0}
WLSDPLY-06035=Unable to write the results file specified by environment variable {0}: {1}

# discoverer.py
WLSDPLY-06100=Find attributes at location {0}
WLSDPLY-06102=The attributes found at path {0} are {1}
Expand Down