Skip to content

Add verrazzano section to model for updating generated resource file #1365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/src/main/python/wlsdeploy/aliases/model_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
USER_ATTRIBUTES = 'UserAttribute'
USE_SAMPLE_DATABASE = 'UseSampleDatabase'
USE_SSL = "useSSL"
VERRAZZANO = "verrazzano"
VIRTUAL_HOST = 'VirtualHost'
VIRTUAL_TARGET = 'VirtualTarget'
VIRTUAL_USER_AUTHENTICATOR = 'VirtualUserAuthenticator'
Expand Down Expand Up @@ -427,7 +428,14 @@
TOPOLOGY,
RESOURCES,
APP_DEPLOYMENTS,
KUBERNETES
KUBERNETES,
VERRAZZANO
]

# the contents of these sections are based on CRD schemas
CRD_MODEL_SECTIONS = [
KUBERNETES,
VERRAZZANO
]

# these domain attributes have special processing in create,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
Copyright (c) 2020, 2023, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
"""
from wlsdeploy.exception import exception_helper
Expand All @@ -9,18 +9,20 @@
from wlsdeploy.tool.modelhelp import model_help_utils
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
import wlsdeploy.util.unicode_helper as str_helper
from wlsdeploy.util import dictionary_utils
from wlsdeploy.util.exit_code import ExitCode


class ModelKubernetesPrinter(object):
class ModelCrdSectionPrinter(object):
"""
Class for printing kubernetes sections as model samples.
"""
_class_name = "ModelKubernetesPrinter"
_class_name = "ModelCrdSectionPrinter"
_logger = PlatformLogger('wlsdeploy.modelhelp')

def __init__(self, model_context):
self._crd_helper = model_crd_helper.get_helper(model_context)
self._target = model_context.get_target()

def print_model_sample(self, model_path_tokens, control_option):
"""
Expand All @@ -30,6 +32,10 @@ def print_model_sample(self, model_path_tokens, control_option):
:raises CLAException: if a problem is encountered
"""
section_name = model_path_tokens[0]
if section_name != self._crd_helper.get_model_section():
print("")
print(exception_helper.get_message('WLSDPLY-10113', section_name))
return

if len(model_path_tokens) == 1:
self._print_model_section_sample(section_name, control_option)
Expand Down Expand Up @@ -122,25 +128,49 @@ def _print_model_folder_sample(self, section_name, model_path_tokens, control_op

current_folder = schema
for token in model_path_tokens[token_index:]:
lookup_token = token
option_key = None

# check for a folder with multiple options, such as (verrazzano/.../trait#MetricsTrait)
if '#' in token:
parts = token.split('#', 1)
lookup_token = parts[0]
option_key = parts[1]

properties = _get_properties(current_folder)

valid_subfolder_keys = _get_folder_names(properties)
if token not in valid_subfolder_keys:
if lookup_token not in valid_subfolder_keys:
ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR,
"WLSDPLY-10111", model_path, token,
"WLSDPLY-10111", model_path, lookup_token,
', '.join(valid_subfolder_keys))
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
raise ex

current_folder = properties[token]
current_folder = properties[lookup_token]

# find matching option if folder has multiple options, such as (verrazzano/.../trait#MetricsTrait)
token_suffix = ''
folder_options = schema_helper.get_one_of_options(current_folder)
if folder_options and option_key is not None:
token_suffix = ' # ' + option_key
current_folder = self._find_folder_option(folder_options, option_key, model_path + '/' + lookup_token)

_print_indent(token + ":", indent, in_object_array)
_print_indent(lookup_token + ":" + token_suffix, indent, in_object_array)
indent += 1

# apply to the next folder in the path
in_object_array = schema_helper.is_object_array(current_folder)
model_path = model_path + "/" + token

# finished writing the parent folders

# if this is a folder with multiple options, list the options and return
folder_options = schema_helper.get_one_of_options(current_folder)
if folder_options:
print_folder_options(folder_options, model_path, indent)
return

# list the attributes and folders, as specified

if model_help_utils.show_attributes(control_option):
Expand Down Expand Up @@ -247,6 +277,33 @@ def _print_attributes_sample(self, schema_folder, indent_level, in_object_array)

return in_object_array

def _find_folder_option(self, folder_options, option_key, model_path):
"""
Return the folder option that matches the specified index key.
Try matching "kind" field of each option, then try lookup by numeric index.
Throw an exception if no matching option is found.
:param folder_options: the options to be examined
:param option_key: the key to check against
:param model_path: used for error logging
:return: the matching option
"""
_method_name = '_find_folder_option'

for folder_option in folder_options:
key = _get_kind_value(folder_option)
if key == option_key:
return folder_option

if option_key.isdecimal():
index = int(option_key)
if (index > -1) and (index < len(folder_options)):
return folder_options[index]

ex = exception_helper.create_cla_exception(ExitCode.ARG_VALIDATION_ERROR, "WLSDPLY-10115",
model_path, '#' + option_key)
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
raise ex


def _get_properties(schema_folder):
# in array elements, the properties are under "items"
Expand All @@ -272,6 +329,35 @@ def _get_folder_names(schema_properties):
return folder_names


def print_folder_options(folder_options, model_path, indent_level):
"""
Print messages for a folder that has multiple content options.
:param folder_options: the options to be printed
:param model_path: the model path to be included in the output
:param indent_level: the level to indent by, before printing output
:return: the matching option, or None
"""
_print_indent("# " + exception_helper.get_message('WLSDPLY-10114', len(folder_options)), indent_level)
for index, one_of_option in enumerate(folder_options):
key = _get_kind_value(one_of_option) or index
print("")
_print_indent("# see " + model_path + "#" + str_helper.to_string(key), indent_level)


def _get_kind_value(folder_option):
"""
Return the "kind" value of the specified folder option.
If the option doesn't have a kind value, return None.
:param folder_option: the folder option to be examined
:return: the value of the "kind" field, or None
"""
properties = schema_helper.get_properties(folder_option)
kind = dictionary_utils.get_dictionary_element(properties, "kind")
enum = dictionary_utils.get_dictionary_element(kind, "enum")
if enum and len(enum):
return enum[0]


def _print_indent(msg, level=1, first_in_list_object=False):
"""
Print a message at the specified indent level.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
"""
Copyright (c) 2020, 2022, Oracle Corporation and/or its affiliates.
Copyright (c) 2020, 2023, Oracle Corporation and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
"""
import re

from oracle.weblogic.deploy.exception import ExceptionHelper

from wlsdeploy.aliases.model_constants import CRD_MODEL_SECTIONS
from wlsdeploy.aliases.model_constants import KNOWN_TOPLEVEL_MODEL_SECTIONS
from wlsdeploy.aliases.model_constants import KUBERNETES
from wlsdeploy.exception import exception_helper
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
from wlsdeploy.tool.modelhelp.model_kubernetes_printer import ModelKubernetesPrinter
from wlsdeploy.tool.modelhelp.model_crd_section_printer import ModelCrdSectionPrinter
from wlsdeploy.tool.modelhelp.model_sample_printer import ModelSamplePrinter
from wlsdeploy.util import model
import wlsdeploy.util.unicode_helper as str_helper
from wlsdeploy.util.exit_code import ExitCode

_class_name = "ModelHelpPrinter"
MODEL_PATH_PATTERN = re.compile(r'(^[a-zA-Z]+:?)?(/[a-zA-Z0-9^/]+)?$')
MODEL_PATH_PATTERN = re.compile(r'(^[a-zA-Z]+:?)?(/[a-zA-Z0-9#^/]+)?$')


class ModelHelpPrinter(object):
Expand Down Expand Up @@ -64,12 +65,12 @@ def print_model_help(self, model_path, control_option):
elif control_option == ControlOptions.FOLDERS_ONLY:
print(_format_message('WLSDPLY-10103', model_path))
elif control_option == ControlOptions.ATTRIBUTES_ONLY:
print( _format_message('WLSDPLY-10104', model_path))
print(_format_message('WLSDPLY-10104', model_path))
else:
print(_format_message('WLSDPLY-10105', model_path))

if model_path_tokens[0] == KUBERNETES:
sample_printer = ModelKubernetesPrinter(self._model_context)
if model_path_tokens[0] in CRD_MODEL_SECTIONS:
sample_printer = ModelCrdSectionPrinter(self._model_context)
sample_printer.print_model_sample(model_path_tokens, control_option)
else:
sample_printer = ModelSamplePrinter(self._aliases, self._logger)
Expand Down
Loading