def compute_base_path(model_category_name, raw_model_category_dictionary): """ Compute the base path to use from the model category dictionary. :param model_category_name: the model category name for the dictionary (used for error handling only) :param raw_model_category_dictionary: the raw dictionary :return: the new base path (e.g., '/Partition${:s}/%PARTITION%') :raises: AliasException: if bad alias data is encountered """ _method_name = 'compute_base_path' if WLST_SUBFOLDERS_PATH in raw_model_category_dictionary: base_path_index = raw_model_category_dictionary[WLST_SUBFOLDERS_PATH] elif WLST_ATTRIBUTES_PATH in raw_model_category_dictionary: base_path_index = raw_model_category_dictionary[WLST_ATTRIBUTES_PATH] else: ex = exception_helper.create_alias_exception('WLSDPLY-08004', WLST_ATTRIBUTES_PATH, model_category_name) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex if WLST_PATHS in raw_model_category_dictionary: if base_path_index in raw_model_category_dictionary[WLST_PATHS]: base_path = raw_model_category_dictionary[WLST_PATHS][base_path_index] else: ex = exception_helper.create_alias_exception('WLSDPLY-08005', base_path_index, WLST_PATHS, model_category_name) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex else: ex = exception_helper.create_alias_exception('WLSDPLY-08006', WLST_PATHS, model_category_name) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex _logger.exiting(class_name=_class_name, method_name=_method_name, result=base_path) return base_path
def resolve_path_index(folder_dict, paths_index, path_attribute_name_used, location): """ Get the path for the specified path index. :param folder_dict: the folder dictionary :param paths_index: the path index key :param path_attribute_name_used: the path attribute name used :param location: the location of the folder :return: the path for the specified path index :raises: AliasException: if an error occurs while location the path of the specified path index """ _method_name = 'resolve_path_index' # Don't log folder dictionary because it is likely very large _logger.entering(paths_index, path_attribute_name_used, str(location), class_name=_class_name, method_name=_method_name) if WLST_PATHS in folder_dict: if paths_index in folder_dict[WLST_PATHS]: tokenized_path = folder_dict[WLST_PATHS][paths_index] else: ex = exception_helper.create_alias_exception('WLSDPLY-08012', location.get_folder_path(), path_attribute_name_used, paths_index, WLST_PATHS) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex else: ex = exception_helper.create_alias_exception('WLSDPLY-08013', location.get_folder_path(), WLST_PATHS) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex _logger.exiting(class_name=_class_name, method_name=_method_name, result=tokenized_path) return tokenized_path
def convert_to_type(data_type, value, subtype=None, delimiter=None): """ Convert the value to the specified type. :param data_type: the type :param value: the value :param subtype: optional subtype for jarray type :param delimiter: optional delimiter to use for parsing :return: the value converted to the specified type """ _method_name = 'convert_to_type' # # TypeUtils.convertToType doesn't work for passwords... # if value is not None and data_type == 'password': # The password is an array of bytes coming back from the WLST get() method and only # java.lang.String() is able to properly convert it to the cipher text string. However, # we don't really want to return a java.lang.String to the caller so convert that Java # String back to a Python string...ugly but effective. new_value = str(String(value)) else: try: new_value = TypeUtils.convertToType(data_type, value, delimiter) except NumberFormatException, nfe: ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, nfe.getLocalizedMessage(), error=nfe) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex if new_value is not None: try: if data_type == LONG: new_value = Long(new_value) elif data_type == JAVA_LANG_BOOLEAN: new_value = Boolean(new_value) elif data_type == JARRAY: if subtype is None or subtype == 'java.lang.String': new_value = _create_string_jarray(new_value) else: new_value = _create_mbean_array(new_value, subtype) elif data_type == LIST: new_value = list(new_value) elif data_type in ALIAS_DELIMITED_TYPES: # # This code intentionally ignores the delimiter value passed in and computes it from the data type. # This is required to handle the special case where the value we read from WLST might have a # different delimiter than the model value. In this use case, the value passed into the method # is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the # model delimiter from the data_type directly. # delimiter = compute_delimiter_from_data_type(data_type, new_value) new_value = delimiter.join(new_value) except TypeError, te: ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, te) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex
def replace_tokens_in_path(location, path): """ Replace the tokens in the path using the supplied location's name tokens. :param location: the location to use :param path: the path :return: the path with all tokens replaced :raises: AliasException: if an error occurs while processing the path tokens """ _method_name = 'replace_tokens_in_path' _logger.entering(str(location), path, class_name=_class_name, method_name=_method_name) name_tokens = location.get_name_tokens() new_path = path if name_tokens: for key, value in name_tokens.iteritems(): new_path = new_path.replace('%s%s%s' % ('%', key, '%'), value) missing_name_token = get_missing_name_tokens(new_path) if len(missing_name_token) > 0: ex = exception_helper.create_alias_exception('WLSDPLY-08014', new_path, missing_name_token) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex _logger.exiting(class_name=_class_name, method_name=_method_name, result=new_path) return new_path
def _get_low_and_high_version_from_range(version_range): """ Parse a version range into its low and high components. :param version_range: the version range :return: the low and high version components, an empty string is returned if there is no upper bound """ _method_name = '_get_low_and_high_version_from_range' _logger.entering(version_range, class_name=_class_name, method_name=_method_name) try: versions = VersionUtils.getLowerAndUpperVersionStrings(version_range) except VersionException, ve: ex = exception_helper.create_alias_exception('WLSDPLY-08017', version_range, ve.getLocalizedMessage(), error=ve) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex
def get_child_folder_type_value_from_enum_value(child_folder_type): """ Get the child_folder_type value from the enum value :param child_folder_type: the enum value :return: the child_folder_type value """ _method_name = 'get_child_folder_type_value_from_enum_value' try: enum_text = ChildFoldersTypes.from_value(child_folder_type) result = enum_text.lower() except ValueError, ve: ex = exception_helper.create_alias_exception('WLSDPLY-08016', child_folder_type, str(ve), error=ve) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex
def _create_mbean_array(iterable, subtype): """ Create a jarray of the subtype suitable for WLST attributes that take list objects. This is mostly used for WLST online. :param iterable: a List object or other iterable type :return: a jarray containing the same contents as the provided iterable """ _method_name = '__create_mbean_array' array_len = len(iterable) try: clazz = Class.forName(subtype) except (JException, RuntimeException), e: ex = exception_helper.create_alias_exception('WLSDPLY-08020', subtype, e.getLocalizedMessage(), error=e) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex
def _convert_value_to_model_type(data_type, value, delimiter): """ Convert WLST value to model representation type. Assumes that empty values and password data types have been converted elsewhere. :param data_type: the target data type for the model :param value: value to be converted :param delimiter: the delimiter for parsing the WLST representation of the data value (optional) :return: converted value """ _method_name = '_convert_value_to_model_type' try: converted = TypeUtils.convertToType(data_type, value, delimiter) except NumberFormatException, nfe: ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, nfe.getLocalizedMessage(), error=nfe) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex
def __get_size_as_number(self, size_arg, size_string): """ Convert the specified size string into a number. :param size_arg: the arg name that specified the size string :param size_string: the size string :return: the size as a number """ _method_name = '__get_size_as_number' match = self.__size_regex.match(size_string) if not match: ex = exception_helper.create_alias_exception('WLSDPLY-08308', size_arg, size_string) self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name) raise ex number = int(match.group(1)) multiplier = self.__get_size_multiplier(match.group(2)) return number * multiplier
def get_token_value(location, value): """ Replace the name token, if present, in the specified value with the token value from the location :param location: the location to use :param value: the value :return: the value or the location name token value if the value was a name token :raises: AliasException: """ _method_name = 'get_token_value' result = value if value is not None and value.startswith('%') and value.endswith('%'): token_name = value[1:-1] name_tokens = location.get_name_tokens() if token_name in name_tokens: result = name_tokens[token_name] else: ex = exception_helper.create_alias_exception('WLSDPLY-7015', token_name) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex return result
def _get_value_for_path_type(path_type): """ Compute a numeric value for the path type based on the number of directories above the base wlst_attributes_path. :param path_type: path type :return: the numeric value """ _method_name = '_get_value_for_path_type' _logger.entering(path_type, class_name=_class_name, method_name=_method_name) if path_type == WLST_CREATE_PATH: result = 2 elif path_type == WLST_LIST_PATH: result = 1 elif path_type == WLST_SUBFOLDERS_PATH or path_type == WLST_ATTRIBUTES_PATH: result = 0 else: ex = exception_helper.create_alias_exception('WLSDPLY-08019', path_type) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex _logger.exiting(class_name=_class_name, method_name=_method_name, result=result) return result
def resolve_path_tokens(location, path_name, folder_dict): """ Resolve any path tokens in all paths within the folder :param location: the location of the folder :param path_name: the path name :param folder_dict: the dictionary for the folder :return: a new dictionary with all path tokens resolved :raises: AliasException: if an error occurs while processing the path tokens """ _method_name = 'resolve_path_tokens' # # With folder versioning in place, a folder dictionary will be None if it is not relevant to the # current WLS version. As such, just return None since there are no paths to resolve. # if folder_dict is None: return None # # Now that we have the target dictionary, we need to make a copy of it and replace the path tokens. # resolved_dict = copy.deepcopy(folder_dict) if WLST_PATHS in resolved_dict: wlst_paths_dict = resolved_dict[WLST_PATHS] for path_key in wlst_paths_dict: path_value = wlst_paths_dict[path_key] wlst_paths_dict[path_key] = replace_tokens_in_path(location, path_value) else: ex = exception_helper.create_alias_exception('WLSDPLY-08007', path_name) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex # # Resolve the wlst path attributes in the model # if WLST_ATTRIBUTES_PATH in resolved_dict: wlst_path_key = resolved_dict[WLST_ATTRIBUTES_PATH] if wlst_path_key in wlst_paths_dict: resolved_dict[WLST_ATTRIBUTES_PATH] = wlst_paths_dict[wlst_path_key] else: ex = exception_helper.create_alias_exception('WLSDPLY-08008', path_name, WLST_ATTRIBUTES_PATH, wlst_path_key, WLST_PATHS) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex else: ex = exception_helper.create_alias_exception('WLSDPLY-08009', path_name, WLST_ATTRIBUTES_PATH) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex if WLST_SUBFOLDERS_PATH in resolved_dict: wlst_path_key = resolved_dict[WLST_SUBFOLDERS_PATH] if wlst_path_key in wlst_paths_dict: resolved_dict[WLST_SUBFOLDERS_PATH] = wlst_paths_dict[wlst_path_key] else: ex = exception_helper.create_alias_exception('WLSDPLY-08008', path_name, WLST_SUBFOLDERS_PATH, wlst_path_key, WLST_PATHS) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex else: # default back to the attributes path resolved_dict[WLST_SUBFOLDERS_PATH] = resolved_dict[WLST_ATTRIBUTES_PATH] if WLST_LIST_PATH in resolved_dict: wlst_path_key = resolved_dict[WLST_LIST_PATH] if wlst_path_key in wlst_paths_dict: resolved_dict[WLST_LIST_PATH] = wlst_paths_dict[wlst_path_key] else: ex = exception_helper.create_alias_exception('WLSDPLY-08008', path_name, WLST_LIST_PATH, wlst_path_key, WLST_PATHS) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex else: # default back to the parent folder of the attributes path attr_path = resolved_dict[WLST_ATTRIBUTES_PATH] resolved_dict[WLST_LIST_PATH] = strip_trailing_folders_in_path(attr_path) if WLST_CREATE_PATH in resolved_dict: wlst_path_key = resolved_dict[WLST_CREATE_PATH] if wlst_path_key in wlst_paths_dict: resolved_dict[WLST_CREATE_PATH] = wlst_paths_dict[wlst_path_key] else: ex = exception_helper.create_alias_exception('WLSDPLY-08008', path_name, WLST_CREATE_PATH, wlst_path_key, WLST_PATHS) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex else: # default back to the grandparent folder of the attributes path attr_path = resolved_dict[WLST_ATTRIBUTES_PATH] resolved_dict[WLST_CREATE_PATH] = strip_trailing_folders_in_path(attr_path, 2) # # Now that the wlst_paths have been resolved, resolve the references to them in each of the attributes # if ATTRIBUTES in resolved_dict: attrs_dict = resolved_dict[ATTRIBUTES] for attr_name in attrs_dict: attr_dict = attrs_dict[attr_name] if WLST_PATH in attr_dict: wlst_path_key = attr_dict[WLST_PATH] if wlst_path_key in wlst_paths_dict: attr_dict[WLST_PATH] = wlst_paths_dict[wlst_path_key] else: ex = exception_helper.create_alias_exception('WLSDPLY-08010', attr_name, path_name, wlst_path_key) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex else: ex = exception_helper.create_alias_exception('WLSDPLY-08011', attr_name, path_name) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex return resolved_dict
# new_value = _jconvert_to_type(preferred, new_value, delimiter) elif data_type == LIST: if converted: # convert any object elements to str, especially ObjectNames converted = _create_array(converted, delimiter) converted = list(converted) elif data_type in ALIAS_DELIMITED_TYPES: # Use the delimiter from the target type to join the elements of the list. # This can be different from the delimiter passed in, which was used to parse the WLST value. model_delimiter = compute_delimiter_from_data_type(data_type, converted) if model_delimiter and converted: # convert any object elements to str, especially ObjectNames converted = _create_array(converted, model_delimiter) converted = model_delimiter.join(converted) except TypeError, te: ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, str(te)) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex return converted def _get_path_separator(value): """ Get the path separator to use for this value. If the value is a string and contains :param value: the value :return: the computed path separator """ _method_name = '_get_path_separator' _logger.entering(value, class_name=_class_name, method_name=_method_name) result = File.pathSeparator