Ejemplo n.º 1
0
def __process_model_args(optional_arg_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the arguments were not valid or an error occurred extracting the model from the archive
    """
    _method_name = '__process_model_args'
    global __tmp_model_dir

    if CommandLineArgUtil.PRINT_USAGE_SWITCH in optional_arg_map:
        # nothing to do since we are printing help information rather than validating supplied artifacts...
        return

    something_to_validate = False
    if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
        #
        # Verify that the archive file exists
        #
        archive_file_name = optional_arg_map[
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
        try:
            FileUtils.validateExistingFile(archive_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20014',
                _program_name,
                archive_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
        something_to_validate = True
Ejemplo n.º 2
0
def validate_optional_archive(program_name, optional_arg_map):
    """
    If the archive file was specified on the command line, verify that it exists.
    :param program_name: the name of the calling program, for logging
    :param optional_arg_map: the optional arguments from the command line
    :raises CLAException: if the archive was specified and does not exist
    """
    _method_name = 'validate_optional_archive'

    if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
        archive_file_name = optional_arg_map[
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH]

        try:
            FileUtils.validateExistingFile(archive_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20014',
                program_name,
                archive_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Ejemplo n.º 3
0
def __process_model_args(optional_arg_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    :param optional_arg_map:   the optional arguments map
    :raises CLAException: If an error occurs validating the arguments or extracting the model from the archive
    """
    _method_name = '__process_model_args'
    global __tmp_model_dir

    archive_file_name = None
    if CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
        archive_file_name = optional_arg_map[
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH]

        try:
            FileUtils.validateExistingFile(archive_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20014',
                _program_name,
                archive_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Ejemplo n.º 4
0
def validate_model_present(program_name, optional_arg_map):
    """
    Determine if the model file was passed separately or requires extraction from the archive.
    If the model is in the archive, extract it to the temporary model location, and set that file as the
    MODEL_FILE_SWITCH argument.
    The MODEL_FILE_SWITCH value may be specified as multiple comma-separated models.
    :param program_name: the name of the calling program, for logging
    :param optional_arg_map: the optional arguments from the command line
    :raises CLAException: if the specified model is not an existing file, or the model is not found in the archive,
    or the model is not found from either argument
    """
    _method_name = 'validate_model_present'
    global __tmp_model_dir

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_value = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]
        model_files = cla_utils.get_model_files(model_file_value)

        for model_file in model_files:
            try:
                FileUtils.validateExistingFile(model_file)
            except IllegalArgumentException, iae:
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-20006',
                    program_name,
                    model_file,
                    iae.getLocalizedMessage(),
                    error=iae)
                ex.setExitCode(
                    CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                __logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
                raise ex
Ejemplo n.º 5
0
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
    the WLSDEPLOY lib directory.
    :param optional_arg_map: containing the variable file name
    :raises: CLAException: if this argument is present but the model variable injector json does not exist
    """
    _method_name = '__process_variable_filename_arg'

    if CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH in optional_arg_map:
        variable_injector_file_name = variable_injector.get_default_variable_injector_file_name(
        )
        try:
            FileUtils.validateExistingFile(variable_injector_file_name)
        except IllegalArgumentException, ie:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-06021',
                optional_arg_map[
                    CommandLineArgUtil.VARIABLE_PROPERTIES_FILE_SWITCH],
                variable_injector_file_name,
                ie.getLocalizedMessage(),
                error=ie)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Ejemplo n.º 6
0
def __process_model_args(optional_arg_map):
    """
    Verify that either the model_file or archive_file was provided and exists.
    Extract the model file if only the archive_file was provided.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the arguments are invalid or an error occurs extracting the model from the archive
    """
    _method_name = '__process_model_args'
    global __tmp_model_dir

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_name = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]

        try:
            FileUtils.validateExistingFile(model_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20006',
                _program_name,
                model_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Ejemplo n.º 7
0
def __validate_mode_args(optional_arg_map):
    """
    Verify that either the model_file or the manual switch was specified.
    :param optional_arg_map: the optional arguments map
    :raises CLAException: if the arguments are not valid
    """
    _method_name = '__validate_mode_args'

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_name = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]
        try:
            FileUtils.validateExistingFile(model_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20006',
                _program_name,
                model_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
def validate_variable_file_exists(program_name, argument_map):
    """
    Validate that the variable file(s) exist.
    Assume that the caller allows multiple variables files.
    :param program_name: the name of the tool
    :param argument_map: the program arguments
    """
    method_name = 'validate_variable_file_exists'
    if CommandLineArgUtil.VARIABLE_FILE_SWITCH in argument_map:
        result_files = []  # type: list
        value = argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH]
        files = value.split(CommandLineArgUtil.MODEL_FILES_SEPARATOR)
        for file in files:
            try:
                variable_file = FileUtils.validateExistingFile(file)
                result_files.append(variable_file.getAbsolutePath())
            except IllegalArgumentException, iae:
                ex = exception_helper.create_cla_exception(
                    'WLSDPLY-20031',
                    program_name,
                    file,
                    iae.getLocalizedMessage(),
                    error=iae)
                ex.setExitCode(
                    CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
                __logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=method_name)
                raise ex

        argument_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = ",".join(
            result_files)
Ejemplo n.º 9
0
def __verify_actual_model_overrides_file_arg(compare_models_args_map):
    """

    :param compare_models_args_map:
    :return:
    """
    _method_name = '__verify_actual_models_overrides_file_arg'

    actual_models_overrides_file = None

    if compare_models_args_map[
            _ACTUAL_MODEL_OVERRIDES_FILE_SWITCH] is not None:
        try:
            actual_model_overrides_file = compare_models_args_map[
                _ACTUAL_MODEL_OVERRIDES_FILE_SWITCH]
            compare_models_args_map[_ACTUAL_MODEL_OVERRIDES_FILE_SWITCH] = \
                FileUtils.validateExistingFile(actual_model_overrides_file)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_verification_exception(
                'WLSDPLY-20014',
                _ACTUAL_MODEL_OVERRIDES_FILE_SWITCH,
                iae.getLocalizedMessage(),
                error=iae)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Ejemplo n.º 10
0
def __verify_expected_model_file_arg(compare_models_args_map):
    """

    :param compare_models_args_map:
    :return:
    """
    _method_name = '__verify_expected_model_file_arg'

    expected_model_file_name = None

    if _EXPECTED_MODEL_FILE_SWITCH in compare_models_args_map:
        try:
            expected_model_file_name = compare_models_args_map[
                _EXPECTED_MODEL_FILE_SWITCH]
            compare_models_args_map[_EXPECTED_MODEL_FILE_SWITCH] = \
                FileUtils.validateExistingFile(expected_model_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_verification_exception(
                'WLSDPLY-20014',
                _EXPECTED_MODEL_FILE_SWITCH,
                iae.getLocalizedMessage(),
                error=iae)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
Ejemplo n.º 11
0
def __validate_archive_file_arg(required_arg_map):
    """
    Verify that the archive file exists.
    :param required_arg_map: the required arguments map
    :return: the archive file name
    :raises CLAException: if the archive file is not valid
    """
    _method_name = '__validate_archive_file_arg'

    archive_file_name = required_arg_map[CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
    try:
        FileUtils.validateExistingFile(archive_file_name)
    except IllegalArgumentException, iae:
        ex = exception_helper.create_cla_exception('WLSDPLY-20014', _program_name, archive_file_name,
                                                   iae.getLocalizedMessage(), error=iae)
        ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
        __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
Ejemplo n.º 12
0
    def _validate_variable_keywords_file_arg(self, value):
        method_name = '_validate_variable_keywords_file_arg'

        try:
            keywords = JFileUtils.validateExistingFile(value)
        except JIllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception('WLSDPLY-01636', value, iae.getLocalizedMessage(), error=iae)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
            raise ex
def validate_variable_file_exists(program_name, optional_arg_map):
    method_name = '_validate_variable_file_arg'
    if CommandLineArgUtil.VARIABLE_FILE_SWITCH in optional_arg_map:
        value = optional_arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH]
        try:
            variable_file = FileUtils.validateExistingFile(value)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception('WLSDPLY-20031', program_name, value,
                                                       iae.getLocalizedMessage(), error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex, class_name=_class_name, method_name=method_name)
            raise ex
        optional_arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = variable_file.getAbsolutePath()
Ejemplo n.º 14
0
def verify_file_exists(file_name, logger):
    """

    :param file_name:
    :param logger: A PlatformLogger instance that will be used for logging
                   any exceptions that are thrown
    :return:
    """
    _method_name = 'verify_file_exists'

    try:
        j_file = FileUtils.validateExistingFile(file_name)
    except IllegalArgumentException, iae:
        ex = exception_helper.create_testing_exception(
            'WLSDPLY-09808', file_name, iae.getLocalizedMessage(), error=iae)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
Ejemplo n.º 15
0
def __verify_test_def_metadata_file_arg(run_test_args_map):
    """

    :param run_test_args_map:
    :return:
    """
    _method_name = '__verify_test_def_metadata_file_arg'

    test_def_metadata_file = None

    if run_test_args_map[_TEST_DEF_METADATA_FILE_SWITCH] is not None:
        try:
            test_def_metadata_file = run_test_args_map[_TEST_DEF_METADATA_FILE_SWITCH]
            run_test_args_map[_TEST_DEF_METADATA_FILE_SWITCH] = \
                FileUtils.validateExistingFile(test_def_metadata_file)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_verification_exception('WLSDPLY-20014',
                                                                _TEST_DEF_METADATA_FILE_SWITCH,
                                                                iae.getLocalizedMessage(), error=iae)
            __logger.throwing(ex, class_name=_class_name, method_name=_method_name)
            raise ex
Ejemplo n.º 16
0
        method_name = '_validate_domain_home_arg'

        try:
            dh = JFileUtils.validateExistingDirectory(value)
        except JIllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-01606', value, iae.getLocalizedMessage(), error=iae)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex

        config_xml = JFile(dh, 'config/config.xml')
        try:
            config_xml = JFileUtils.validateExistingFile(
                config_xml.getAbsolutePath())
        except JIllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-01607',
                dh.getAbsolutePath(),
                config_xml.getAbsolutePath(),
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(self.ARG_VALIDATION_ERROR_EXIT_CODE)
            self._logger.throwing(ex,
                                  class_name=self._class_name,
                                  method_name=method_name)
            raise ex

        return dh.getAbsolutePath()
Ejemplo n.º 17
0
                _program_name,
                archive_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_name = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]

        try:
            FileUtils.validateExistingFile(model_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20006',
                _program_name,
                model_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
    elif archive_file_name is not None:
        try:
            archive_file = WLSDeployArchive(archive_file_name)
Ejemplo n.º 18
0
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
        something_to_validate = True

    if CommandLineArgUtil.MODEL_FILE_SWITCH in optional_arg_map:
        model_file_name = optional_arg_map[
            CommandLineArgUtil.MODEL_FILE_SWITCH]

        try:
            # Reset the value in the arg map so that the value is always a java.io.File object...
            optional_arg_map[
                CommandLineArgUtil.
                MODEL_FILE_SWITCH] = FileUtils.validateExistingFile(
                    model_file_name)
        except IllegalArgumentException, iae:
            ex = exception_helper.create_cla_exception(
                'WLSDPLY-20006',
                _program_name,
                model_file_name,
                iae.getLocalizedMessage(),
                error=iae)
            ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE)
            __logger.throwing(ex,
                              class_name=_class_name,
                              method_name=_method_name)
            raise ex
    elif CommandLineArgUtil.ARCHIVE_FILE_SWITCH in optional_arg_map:
        archive_file_name = optional_arg_map[
            CommandLineArgUtil.ARCHIVE_FILE_SWITCH]
    def _update_server(self, name, dictionary, config_location):
        _method_name = '_update_server'

        # these imports are local, since they are only present in JRF environments.
        # this method is only called after that check has been made.
        from oracle.core.ojdl.weblogic.ODLConfiguration import CONFIG_DIR
        from oracle.core.ojdl.weblogic.ODLConfiguration import CONFIG_FILE
        from oracle.core.ojdl.logging.config import LoggingConfigurationDocument

        config_dir = File(self.model_context.get_domain_home(), CONFIG_DIR)
        server_dir = File(config_dir, name)
        config_file = File(server_dir, CONFIG_FILE)
        log_template_dir = config_dir.getParentFile()

        try:
            if config_file.exists():
                source_file = config_file
                FileUtils.validateWritableFile(config_file.getPath())
            else:
                # for dynamic servers, the logging config does not exist until the server is started.
                # read the from template file, verify that the server directory is present and writable.
                source_file = File(log_template_dir, LOGGING_TEMPLATE_FILE)
                FileUtils.validateExistingFile(source_file)
                if not server_dir.exists() and not server_dir.mkdirs():
                    ex = exception_helper.create_deploy_exception(
                        'WLSDPLY-19710', server_dir)
                    self.logger.throwing(ex,
                                         class_name=self.__class_name,
                                         method_name=_method_name)
                    raise ex
                FileUtils.validateWritableDirectory(server_dir.getPath())

            document = LoggingConfigurationDocument(
                FileInputStream(source_file))

            # configure AddJvmNumber
            add_jvm_number = dictionary_utils.get_element(
                dictionary, _ADD_JVM_NUMBER)
            if add_jvm_number is not None:
                document.setAddJvmNumber(
                    alias_utils.convert_boolean(add_jvm_number))

            # configure HandlerDefaults
            handler_defaults = dictionary_utils.get_dictionary_element(
                dictionary, _HANDLER_DEFAULTS)
            if handler_defaults is not None:
                for key in handler_defaults:
                    value = handler_defaults[key]
                    document.setHandlerDefault(key, _get_property_text(value))

            # configure Handlers
            # do these before loggers, in case new handlers are assigned to loggers
            existing_handler_names = document.getHandlerNames()
            handlers = dictionary_utils.get_dictionary_element(
                dictionary, _HANDLER)
            if handlers is not None:
                for handler_name in handlers:
                    handler = handlers[handler_name]
                    self._configure_handler(handler_name, handler, document,
                                            existing_handler_names,
                                            config_location)

            # configure Loggers
            existing_logger_names = document.getLoggerNames()
            loggers = dictionary_utils.get_dictionary_element(
                dictionary, _LOGGER)
            if loggers is not None:
                for logger_name in loggers:
                    logger = loggers[logger_name]
                    self._configure_logger(logger_name, logger, document,
                                           existing_logger_names,
                                           config_location)

            document.writeDocument(FileOutputStream(config_file))

        except (ParserConfigurationException, SAXException, IOException,
                IllegalArgumentException), ex:
            self.logger.severe('WLSDPLY-19707',
                               name,
                               ex.getLocalizedMessage(),
                               class_name=self.__class_name,
                               method_name=_method_name)