def __perform_model_file_validation(model_file_name, model_context): """ :param model_file_name: :param model_context: :return: :raises ValidationException: """ _method_name = '__perform_model_file_validation' __logger.entering(model_file_name, class_name=_class_name, method_name=_method_name) try: model_dictionary = cla_helper.merge_model_files(model_file_name) model_validator = Validator(model_context, logger=__logger) model_validator.validate_in_standalone_mode( model_dictionary, model_context.get_variable_file(), model_context.get_archive_file_name()) except TranslateException, te: __logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_validate_exception( te.getLocalizedMessage(), error=te) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex
def __perform_model_file_validation(model_file_name, model_context): """ :param model_file_name: :param model_context: :return: :raises ValidationException: """ _method_name = '__perform_model_file_validation' __logger.entering(model_file_name, class_name=_class_name, method_name=_method_name) try: model_validator = Validator(model_context, logger=__logger) variable_map = model_validator.load_variables(model_context.get_variable_file()) model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map) if cla_helper.check_persist_model(): persist_model_dict = copy.deepcopy(model_dictionary) variables.substitute(persist_model_dict, variable_map, model_context) cla_helper.persist_model(model_context, persist_model_dict) model_validator.validate_in_standalone_mode(model_dictionary, variable_map, model_context.get_archive_file_name()) except (TranslateException, VariableException), te: __logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_validate_exception(te.getLocalizedMessage(), error=te) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex
if model_context.get_variable_file(): variable_map = variables.load_variables( model_context.get_variable_file()) except VariableException, ex: __logger.severe('WLSDPLY-20004', _program_name, ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) model_file_value = model_context.get_model_file() try: model_dictionary = cla_helper.merge_model_files( model_file_value, variable_map) except TranslateException, te: __logger.severe('WLSDPLY-09014', _program_name, model_file_value, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) try: variables.substitute(model_dictionary, variable_map, model_context) except VariableException, ex: __logger.severe('WLSDPLY-20004',
def compare(self): """ Do the actual compare of the models. :return: whether the difference is safe for online dynamic update """ _method_name = "compare" # arguments have been verified and same extensions model_file_name = None # validate models first try: if FileUtils.isYamlFile(JFile(os.path.splitext(self.current_dict_file)[1].lower())): model_file_name = self.current_dict_file FileToPython(model_file_name, True).parse() model_file_name = self.past_dict_file FileToPython(model_file_name, True).parse() self.model_context.set_validation_method('lax') aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE, exception_type=ExceptionType.COMPARE) validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE) variable_map = validator.load_variables(self.model_context.get_variable_file()) model_file_name = self.current_dict_file model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map) variables.substitute(model_dictionary, variable_map, self.model_context) # Run this utility in stand-alone mode instead of tool mode, # which has stricter checks for the tools. # An archive is not used with the compare models and if the model # references a file in an archive, the compareModel will fail if # running in the stricter tool mode (even with lax). # arg_map = dict() arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = model_file_name model_context_copy = self.model_context.copy(arg_map) val_copy = Validator(model_context_copy, aliases, wlst_mode=WlstModes.OFFLINE) # any variables should have been substituted at this point validate_variables = {} return_code = val_copy.validate_in_standalone_mode(model_dictionary, validate_variables, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: _logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL current_dict = model_dictionary model_file_name = self.past_dict_file model_dictionary = cla_helper.merge_model_files(model_file_name, variable_map) variables.substitute(model_dictionary, variable_map, self.model_context) arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH] = model_file_name model_context_copy = self.model_context.copy(arg_map) val_copy = Validator(model_context_copy, aliases, wlst_mode=WlstModes.OFFLINE) return_code = val_copy.validate_in_standalone_mode(model_dictionary, validate_variables, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: _logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL past_dict = model_dictionary except ValidateException, te: _logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception(te.getLocalizedMessage(), error=te) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL
def compare(self): """ Do the actual compare of the models. :return: whether the difference is safe for online dynamic update """ _method_name = "compare" # arguments have been verified and same extensions model_file_name = None # validate models first try: if os.path.splitext(self.current_dict_file)[1].lower() == ".yaml": model_file_name = self.current_dict_file FileToPython(model_file_name, True).parse() model_file_name = self.past_dict_file FileToPython(model_file_name, True).parse() aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE) validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE) variable_map = validator.load_variables( self.model_context.get_variable_file()) model_file_name = self.current_dict_file model_dictionary = cla_helper.merge_model_files( model_file_name, variable_map) variables.substitute(model_dictionary, variable_map, self.model_context) return_code = validator.validate_in_tool_mode( model_dictionary, variables_file_name=None, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: __logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL current_dict = model_dictionary model_file_name = self.past_dict_file model_dictionary = cla_helper.merge_model_files( model_file_name, variable_map) variables.substitute(model_dictionary, variable_map, self.model_context) return_code = validator.validate_in_tool_mode( model_dictionary, variables_file_name=None, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: __logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL past_dict = model_dictionary except ValidateException, te: __logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception( te.getLocalizedMessage(), error=te) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE: __logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() # create a minimal model for summary logging model_context = ModelContext(_program_name, dict()) tool_exit.end(model_context, exit_code) model_file_value = model_context.get_model_file() try: model = cla_helper.merge_model_files(model_file_value) except TranslateException, te: __logger.severe('WLSDPLY-20009', _program_name, model_file_value, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) try: variable_map = {} if model_context.get_variable_file(): variable_map = variables.load_variables(
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE: __logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() # create a minimal model for summary logging model_context = ModelContext(_program_name, dict()) tool_exit.end(model_context, exit_code) model_file_value = model_context.get_model_file() try: model_dictionary = cla_helper.merge_model_files(model_file_value) except TranslateException, te: __logger.severe('WLSDPLY-09014', _program_name, model_file_value, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) try: variable_map = {} if model_context.get_variable_file(): variable_map = variables.load_variables(
if model_context.get_variable_file(): variable_map = variables.load_variables( model_context.get_variable_file()) except VariableException, ex: __logger.severe('WLSDPLY-20004', _program_name, ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) model_file_value = model_context.get_model_file() try: model = cla_helper.merge_model_files(model_file_value, variable_map) except TranslateException, te: __logger.severe('WLSDPLY-20009', _program_name, model_file_value, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) cla_helper.clean_up_temp_files() tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE) try: variables.substitute(model, variable_map, model_context) except VariableException, ex: __logger.severe('WLSDPLY-20004',
def walk(self): """ Replace password attributes in each model file with secret tokens, and write each model. Generate a script to create the required secrets. Create any additional output specified for the target environment. """ _method_name = "walk" model_file_name = None try: model_file_list = self.model_files.split(',') for model_file in model_file_list: self.cache.clear() if os.path.splitext(model_file)[1].lower() == ".yaml": model_file_name = model_file FileToPython(model_file_name, True).parse() aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE) validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE) # Just merge and validate but without substitution model_dictionary = cla_helper.merge_model_files( model_file_name, None) variable_file = self.model_context.get_variable_file() if not os.path.exists(variable_file): variable_file = None return_code = validator.validate_in_tool_mode( model_dictionary, variables_file_name=variable_file, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: self._logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL self.current_dict = model_dictionary self.__walk_model_section( model.get_model_domain_info_key(), self.current_dict, aliases.get_model_section_top_level_folder_names( DOMAIN_INFO)) self.__walk_model_section( model.get_model_topology_key(), self.current_dict, aliases.get_model_topology_top_level_folder_names()) self.__walk_model_section( model.get_model_resources_key(), self.current_dict, aliases.get_model_resources_top_level_folder_names()) self.current_dict = self._apply_filter_and_inject_variable( self.current_dict, self.model_context, validator) file_name = os.path.join(self.output_dir, os.path.basename(model_file_name)) fos = JFileOutputStream(file_name, False) writer = JPrintWriter(fos, True) pty = PythonToYaml(self.current_dict) pty._write_dictionary_to_yaml_file(self.current_dict, writer) writer.close() self.cache.clear() for key in self.secrets_to_generate: self.cache[key] = '' # use a merged, substituted, filtered model to get domain name and create additional target output. full_model_dictionary = cla_helper.load_model( _program_name, self.model_context, self._aliases, "discover", WlstModes.OFFLINE) target_configuration_helper.generate_k8s_script( self.model_context, self.cache, full_model_dictionary) # create any additional outputs from full model dictionary target_configuration_helper.create_additional_output( Model(full_model_dictionary), self.model_context, self._aliases, ExceptionType.VALIDATE) except ValidateException, te: self._logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception( te.getLocalizedMessage(), error=te) self._logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL
def walk(self): _method_name = "walk" model_file_name = None try: model_file_list = self.model_files.split(',') for model_file in model_file_list: self.cache.clear() if os.path.splitext(model_file)[1].lower() == ".yaml": model_file_name = model_file FileToPython(model_file_name, True).parse() aliases = Aliases(model_context=self.model_context, wlst_mode=WlstModes.OFFLINE) validator = Validator(self.model_context, aliases, wlst_mode=WlstModes.OFFLINE) # Just merge and validate but without substitution model_dictionary = cla_helper.merge_model_files(model_file_name, None) variable_file = self.model_context.get_variable_file() if not os.path.exists(variable_file): variable_file=None return_code = validator.validate_in_tool_mode(model_dictionary, variables_file_name=variable_file, archive_file_name=None) if return_code == Validator.ReturnCode.STOP: __logger.severe('WLSDPLY-05705', model_file_name) return VALIDATION_FAIL self.current_dict = model_dictionary self.__walk_model_section(model.get_model_domain_info_key(), self.current_dict, aliases.get_model_section_top_level_folder_names(DOMAIN_INFO)) self.__walk_model_section(model.get_model_topology_key(), self.current_dict, aliases.get_model_topology_top_level_folder_names()) self.__walk_model_section(model.get_model_resources_key(), self.current_dict, aliases.get_model_resources_top_level_folder_names()) self.current_dict = self._apply_filter_and_inject_variable(self.current_dict, self.model_context, validator) file_name = os.path.join(self.output_dir, os.path.basename(model_file_name)) fos = JFileOutputStream(file_name, False) writer = JPrintWriter(fos, True) pty = PythonToYaml(self.current_dict) pty._write_dictionary_to_yaml_file(self.current_dict, writer) writer.close() self.cache.clear() for key in self.secrets_to_generate: self.cache[key] = '' target_configuration_helper.generate_k8s_script(self.model_context.get_kubernetes_variable_file(), self.cache) except ValidateException, te: __logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) ex = exception_helper.create_compare_exception(te.getLocalizedMessage(), error=te) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) return VALIDATION_FAIL