def get_parent_directory(path): """ Return the parent directory of the last folder or file in the provided path. The path will be reformatted into its canonical form. :param path: containing the parent directory :return: parent directory in its canonical format """ result = path if path is not None: result = JFile(path).getParentFile().getCanonicalPath() return result
def get_canonical_path(path): """ Return the canonical representation of the path and standardize the path, replacing back slashes with forward slashes. :param path: :return: """ result = path if path is not None: result = JFile(path).getCanonicalPath().replace('\\', '/') return result
def write_to_file(self, file_name): """ Write the Python dictionary to a file. :param file_name: the file name :return: the java.io.File object """ _method_name = 'writeToFile' self.logger.entering(file_name, class_name=self._class_name, method_name=_method_name) model_file = JFile(file_name) if JFileUtils.isYamlFile(model_file): return_file = self._write_to_yaml_file(file_name) else: return_file = self._write_to_json_file(file_name) # called method already logged the return_file. don't log again self.logger.exiting(class_name=self._class_name, method_name=_method_name) return return_file
def main(): """ The main entry point for the discoverDomain tool. :param args: the command-line arguments """ _method_name = 'main' _logger.entering(class_name=_class_name, method_name=_method_name) for index, arg in enumerate(sys.argv): _logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name) _outputdir = None try: model_context = __process_args(sys.argv) _outputdir = model_context.get_compare_model_output_dir() model1 = model_context.get_trailing_argument(0) model2 = model_context.get_trailing_argument(1) for f in [model1, model2]: if not os.path.exists(f): raise CLAException("Model %s does not exists" % f) if os.path.isdir(f): raise CLAException("Model %s is a directory" % f) model1_file = JFile(model1) model2_file = JFile(model2) if not (FileUtils.isYamlFile(model1_file) or FileUtils.isJsonFile(model1_file)): raise CLAException("Model extension must be either yaml or json") if not (FileUtils.isYamlFile(model1_file) and FileUtils.isYamlFile(model2_file) or FileUtils.isJsonFile(model1_file) and FileUtils.isJsonFile(model2_file)): ext = os.path.splitext(model1)[1] raise CLAException("Model %s is not a %s file " % (model2, ext)) obj = ModelFileDiffer(model1, model2, model_context, _outputdir) rc = obj.compare() if rc == VALIDATION_FAIL: System.exit(2) if _outputdir: fos = None writer = None file_name = None if len(compare_msgs) > 0: try: file_name = _outputdir + '/compare_model_stdout' fos = JFileOutputStream(file_name, False) writer = JPrintWriter(fos, True) writer.println(BLANK_LINE) writer.println(BLANK_LINE) index = 1 for line in compare_msgs: msg_key = line[0] msg_value = line[1] writer.println("%s. %s" % (index, format_message(msg_key,msg_value.replace(PATH_TOKEN, "-->")))) index = index + 1 writer.println(BLANK_LINE) fos.close() writer.close() except JIOException, ioe: if fos: fos.close() if writer: writer.close() _logger.severe('WLSDPLY-05708', file_name, ioe.getLocalizedMessage(), error=ioe, class_name=_class_name, method_name=_method_name) else:
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 _validate_domain_home_arg(self, value): 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
# # The domain home arg is only used by discover and deploy so it must be a valid domain home. # The create domain operation should use the domain parent arg. # def _validate_domain_home_arg(self, value): 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() def get_domain_parent_key(self): return self.DOMAIN_PARENT_SWITCH