Skip to content

Commit 2390188

Browse files
Write missing archive entries from discover to a results file if configured (#1139)
* remove duplicate invalid report section * Write missing archive entries from discover to a results file if configured Co-authored-by: Carolyn Rountree <[email protected]>
1 parent 3a6f4b9 commit 2390188

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

core/src/main/python/discover.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
from java.lang import IllegalStateException
1414
from oracle.weblogic.deploy.aliases import AliasException
1515
from oracle.weblogic.deploy.discover import DiscoverException
16+
from oracle.weblogic.deploy.json import JsonException
1617
from oracle.weblogic.deploy.util import CLAException
1718
from oracle.weblogic.deploy.util import FileUtils
19+
from oracle.weblogic.deploy.util import PyOrderedDict
1820
from oracle.weblogic.deploy.util import PyWLSTException
1921
from oracle.weblogic.deploy.util import TranslateException
2022
from oracle.weblogic.deploy.util import WLSDeployArchive
@@ -30,6 +32,7 @@
3032
from wlsdeploy.aliases.wlst_modes import WlstModes
3133
from wlsdeploy.exception import exception_helper
3234
from wlsdeploy.exception.expection_types import ExceptionType
35+
from wlsdeploy.json import json_translator
3336
from wlsdeploy.logging.platform_logger import PlatformLogger
3437
from wlsdeploy.tool.discover import discoverer
3538
from wlsdeploy.tool.discover.deployments_discoverer import DeploymentsDiscoverer
@@ -62,6 +65,8 @@
6265
__logger = PlatformLogger(discoverer.get_discover_logger_name())
6366
__wlst_mode = WlstModes.OFFLINE
6467

68+
_store_result_environment_variable = '__WLSDEPLOY_STORE_RESULT__'
69+
6570
__required_arguments = [
6671
CommandLineArgUtil.ORACLE_HOME_SWITCH,
6772
CommandLineArgUtil.DOMAIN_HOME_SWITCH
@@ -137,6 +142,11 @@ def __process_archive_filename_arg(argument_map):
137142

138143
if CommandLineArgUtil.SKIP_ARCHIVE_FILE_SWITCH in argument_map or CommandLineArgUtil.REMOTE_SWITCH in argument_map:
139144
archive_file = WLSDeployArchive.noArchiveFile()
145+
if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in argument_map:
146+
ex = exception_helper.create_cla_exception(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE,
147+
'WLSDPLY-06033')
148+
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
149+
raise ex
140150
else:
141151
archive_file_name = argument_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
142152
archive_dir_name = path_utils.get_parent_directory(archive_file_name)
@@ -245,20 +255,6 @@ def __discover(model_context, aliases, credential_injector, helper):
245255
raise ex
246256
__disconnect_domain(helper)
247257

248-
if model_context.is_remote():
249-
print ''
250-
remote_map = WLSDeployArchive.getRemoteList()
251-
if len(remote_map) == 0:
252-
message = exception_helper.get_message('WLSDPLY-06030')
253-
else:
254-
message = exception_helper.get_message('WLSDPLY-06031')
255-
print message
256-
print ''
257-
for key in remote_map:
258-
other_map = remote_map[key]
259-
wls_archive = other_map[WLSDeployArchive.REMOTE_ARCHIVE_DIR]
260-
print key, ' ', wls_archive
261-
print ''
262258
return model
263259

264260

@@ -512,10 +508,36 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
512508

513509

514510
def __remote_report(model_context):
511+
_method_name = '__remote_report'
512+
515513
if not model_context.is_remote():
516514
return
517-
print ''
515+
518516
remote_map = discoverer.remote_dict
517+
518+
# write JSON output if the __WLSDEPLOY_STORE_RESULT__ environment variable is set.
519+
# write to the file before the stdout so any logging messages come first.
520+
if os.environ.has_key(_store_result_environment_variable):
521+
store_path = os.environ.get(_store_result_environment_variable)
522+
__logger.info('WLSDPLY-06034', store_path, class_name=_class_name, method_name=_method_name)
523+
missing_archive_entries = []
524+
for key in remote_map:
525+
archive_map = remote_map[key]
526+
missing_archive_entries.append({
527+
'path': key,
528+
'sourceFile': archive_map[discoverer.REMOTE_ARCHIVE_PATH],
529+
'type': archive_map[discoverer.REMOTE_TYPE]
530+
})
531+
result_root = PyOrderedDict()
532+
result_root['missingArchiveEntries'] = missing_archive_entries
533+
try:
534+
json_translator.PythonToJson(result_root).write_to_json_file(store_path)
535+
except JsonException, ex:
536+
__logger.warning('WLSDPLY-06035', _store_result_environment_variable, ex.getLocalizedMessage(),
537+
class_name=_class_name, method_name=_method_name)
538+
539+
# write to stdout
540+
print ''
519541
if len(remote_map) == 0:
520542
message = exception_helper.get_message('WLSDPLY-06030')
521543
else:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ WLSDPLY-06031=Remote discovery created a model that references files or director
569569
that could not be collected. Please collect the items at the paths listed below and add them to the archive \
570570
file at the specified locations.
571571
WLSDPLY-06032=Model file name was not included in command arguments and either -skip_archive or -remote was included
572+
WLSDPLY-06033=Archive file name was included in command arguments and either -skip_archive or -remote was selected
573+
WLSDPLY-06034=Writing results file {0}
574+
WLSDPLY-06035=Unable to write the results file specified by environment variable {0}: {1}
575+
572576
# discoverer.py
573577
WLSDPLY-06100=Find attributes at location {0}
574578
WLSDPLY-06102=The attributes found at path {0} are {1}

0 commit comments

Comments
 (0)