|
| 1 | +""" |
| 2 | +Copyright (c) 2020, Oracle Corporation and/or its affiliates. All rights reserved. |
| 3 | +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +
|
| 5 | +The entry point for the extractDomainResource tool. |
| 6 | +""" |
| 7 | +import os |
| 8 | +import sys |
| 9 | + |
| 10 | +from oracle.weblogic.deploy.deploy import DeployException |
| 11 | +from oracle.weblogic.deploy.util import CLAException |
| 12 | +from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion |
| 13 | + |
| 14 | +sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0]))) |
| 15 | + |
| 16 | +# imports from local packages start here |
| 17 | +from wlsdeploy.aliases.aliases import Aliases |
| 18 | +from wlsdeploy.aliases.wlst_modes import WlstModes |
| 19 | +from wlsdeploy.exception.expection_types import ExceptionType |
| 20 | +from wlsdeploy.logging.platform_logger import PlatformLogger |
| 21 | +from wlsdeploy.tool.extract.domain_resource_extractor import DomainResourceExtractor |
| 22 | +from wlsdeploy.tool.util import model_context_helper |
| 23 | +from wlsdeploy.tool.util.wlst_helper import WlstHelper |
| 24 | +from wlsdeploy.util import cla_helper |
| 25 | +from wlsdeploy.util import tool_exit |
| 26 | +from wlsdeploy.util import wlst_extended |
| 27 | +from wlsdeploy.util.cla_utils import CommandLineArgUtil |
| 28 | +from wlsdeploy.util.cla_utils import TOOL_TYPE_EXTRACT |
| 29 | +from wlsdeploy.util.model import Model |
| 30 | +from wlsdeploy.util.weblogic_helper import WebLogicHelper |
| 31 | + |
| 32 | +wlst_extended.wlst_functions = globals() |
| 33 | + |
| 34 | +_program_name = 'extractDomainResource' |
| 35 | +_class_name = 'extract_resource' |
| 36 | +__logger = PlatformLogger('wlsdeploy.extract') |
| 37 | +__wls_helper = WebLogicHelper(__logger) |
| 38 | +__wlst_helper = WlstHelper(__logger, ExceptionType.DEPLOY) |
| 39 | +__wlst_mode = WlstModes.OFFLINE |
| 40 | + |
| 41 | +__required_arguments = [ |
| 42 | + CommandLineArgUtil.ORACLE_HOME_SWITCH, |
| 43 | + CommandLineArgUtil.DOMAIN_HOME_SWITCH, |
| 44 | + CommandLineArgUtil.DOMAIN_RESOURCE_FILE_SWITCH |
| 45 | +] |
| 46 | + |
| 47 | +__optional_arguments = [ |
| 48 | + # Used by shell script to locate WLST |
| 49 | + CommandLineArgUtil.DOMAIN_TYPE_SWITCH, |
| 50 | + CommandLineArgUtil.ARCHIVE_FILE_SWITCH, |
| 51 | + CommandLineArgUtil.MODEL_FILE_SWITCH, |
| 52 | + CommandLineArgUtil.VARIABLE_FILE_SWITCH, |
| 53 | + CommandLineArgUtil.USE_ENCRYPTION_SWITCH, |
| 54 | + CommandLineArgUtil.PASSPHRASE_SWITCH, |
| 55 | +] |
| 56 | + |
| 57 | + |
| 58 | +def __process_args(args): |
| 59 | + """ |
| 60 | + Process the command-line arguments and prompt the user for any missing information |
| 61 | + :param args: the command-line arguments list |
| 62 | + :raises CLAException: if an error occurs while validating and processing the command-line arguments |
| 63 | + """ |
| 64 | + cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments) |
| 65 | + cla_util.set_allow_multiple_models(True) |
| 66 | + required_arg_map, optional_arg_map = cla_util.process_args(args, TOOL_TYPE_EXTRACT) |
| 67 | + |
| 68 | + cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map) |
| 69 | + cla_helper.validate_optional_archive(_program_name, optional_arg_map) |
| 70 | + |
| 71 | + # determine if the model file was passed separately or requires extraction from the archive. |
| 72 | + cla_helper.validate_model_present(_program_name, optional_arg_map) |
| 73 | + cla_helper.validate_variable_file_exists(_program_name, optional_arg_map) |
| 74 | + cla_helper.process_encryption_args(optional_arg_map) |
| 75 | + |
| 76 | + combined_arg_map = optional_arg_map.copy() |
| 77 | + combined_arg_map.update(required_arg_map) |
| 78 | + return model_context_helper.create_context(_program_name, combined_arg_map) |
| 79 | + |
| 80 | + |
| 81 | +def __extract_resource(model, model_context, aliases): |
| 82 | + """ |
| 83 | + Offline deployment orchestration |
| 84 | + :param model: the model |
| 85 | + :param model_context: the model context |
| 86 | + :param aliases: the aliases object |
| 87 | + :raises: DeployException: if an error occurs |
| 88 | + """ |
| 89 | + _method_name = '__extract_resource' |
| 90 | + |
| 91 | + resource_extractor = DomainResourceExtractor(model, model_context, aliases, __logger) |
| 92 | + resource_extractor.extract() |
| 93 | + return 0 |
| 94 | + |
| 95 | + |
| 96 | +def main(args): |
| 97 | + """ |
| 98 | + The python entry point for extractDomainResource. |
| 99 | + :param args: the command-line arguments |
| 100 | + """ |
| 101 | + _method_name = 'main' |
| 102 | + |
| 103 | + __logger.entering(args[0], class_name=_class_name, method_name=_method_name) |
| 104 | + for index, arg in enumerate(args): |
| 105 | + __logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name) |
| 106 | + |
| 107 | + __wlst_helper.silence() |
| 108 | + |
| 109 | + exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE |
| 110 | + |
| 111 | + try: |
| 112 | + model_context = __process_args(args) |
| 113 | + except CLAException, ex: |
| 114 | + exit_code = ex.getExitCode() |
| 115 | + if exit_code != CommandLineArgUtil.HELP_EXIT_CODE: |
| 116 | + __logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex, |
| 117 | + class_name=_class_name, method_name=_method_name) |
| 118 | + cla_helper.clean_up_temp_files() |
| 119 | + |
| 120 | + # create a minimal model for summary logging |
| 121 | + model_context = model_context_helper.create_exit_context(_program_name) |
| 122 | + tool_exit.end(model_context, exit_code) |
| 123 | + |
| 124 | + aliases = Aliases(model_context, wlst_mode=__wlst_mode) |
| 125 | + |
| 126 | + model_dictionary = cla_helper.load_model(_program_name, model_context, aliases, "extract", __wlst_mode) |
| 127 | + |
| 128 | + try: |
| 129 | + model = Model(model_dictionary) |
| 130 | + exit_code = __extract_resource(model, model_context, aliases) |
| 131 | + except DeployException, ex: |
| 132 | + __logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex, |
| 133 | + class_name=_class_name, method_name=_method_name) |
| 134 | + cla_helper.clean_up_temp_files() |
| 135 | + tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) |
| 136 | + |
| 137 | + cla_helper.clean_up_temp_files() |
| 138 | + |
| 139 | + tool_exit.end(model_context, exit_code) |
| 140 | + return |
| 141 | + |
| 142 | + |
| 143 | +if __name__ == '__main__' or __name__ == 'main': |
| 144 | + WebLogicDeployToolingVersion.logVersionInfo(_program_name) |
| 145 | + main(sys.argv) |
0 commit comments