Skip to content

Commit a0766bc

Browse files
rakillenddsharpe
authored andcommitted
Add Kubernetes configuration to model (#521)
* Initial commit, Window and Unix scripts and entry python module * Support kubernetes section in model * Cleaned up comments * Corrected usage, fix windows exit code issue * Get child folders and attribute locations for model sections; update print-usage * Provide default for environment variable lookup * Return copy of list that caller can change * Use revised methods to get folder names and attribute location * Use revised methods to get folder names and attribute location; validate kubernetes section * Revised message for multiple tools * Create the domain resource file with content from the model * Disable kubernetes section validation temporarily * Re-enable kubernetes section validation; update alias file; write known values to resource file * Revised aliases to match domain resource format * Process named folders in model * Add option to write list of dictionaries * Revised aliases, added ServerPod * Use dictionary lists in domain resource file * Allow contained alias files for all model folders * Update domain resource file with command-line domain home, and cluster info from the model * Added defaults for several domain resource values * Use different validation of domain home for extract tool * Add WebLogic credentials secret if not present * Updated copyrights * Revised comment * Remove usage comments related to domain type * Added default for spec/image * Check image pull policy before adding image pull secrets
1 parent 5da71f4 commit a0766bc

25 files changed

+1826
-98
lines changed

core/src/main/python/create.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
The main module for the WLSDeploy tool to create empty domains.
@@ -48,6 +48,7 @@
4848
from wlsdeploy.util import wlst_extended
4949
from wlsdeploy.util import wlst_helper
5050
from wlsdeploy.util.cla_utils import CommandLineArgUtil
51+
from wlsdeploy.util.cla_utils import TOOL_TYPE_CREATE
5152
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5253
from wlsdeploy.tool.create import atp_helper
5354

@@ -92,7 +93,7 @@ def __process_args(args):
9293
"""
9394
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
9495
cla_util.set_allow_multiple_models(True)
95-
required_arg_map, optional_arg_map = cla_util.process_args(args, True)
96+
required_arg_map, optional_arg_map = cla_util.process_args(args, TOOL_TYPE_CREATE)
9697
__verify_required_args_present(required_arg_map)
9798
__process_java_home_arg(optional_arg_map)
9899
__process_domain_location_args(optional_arg_map)
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
"""
2+
Copyright (c) 2020, Oracle Corporation and/or its affiliates. All rights reserved.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+
The entry point for the extractDomainResource tool.
6+
"""
7+
import os
8+
import sys
9+
10+
from oracle.weblogic.deploy.deploy import DeployException
11+
from oracle.weblogic.deploy.util import CLAException
12+
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
13+
14+
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
15+
16+
# imports from local packages start here
17+
from wlsdeploy.aliases.aliases import Aliases
18+
from wlsdeploy.aliases.wlst_modes import WlstModes
19+
from wlsdeploy.exception.expection_types import ExceptionType
20+
from wlsdeploy.logging.platform_logger import PlatformLogger
21+
from wlsdeploy.tool.extract.domain_resource_extractor import DomainResourceExtractor
22+
from wlsdeploy.tool.util import model_context_helper
23+
from wlsdeploy.tool.util.wlst_helper import WlstHelper
24+
from wlsdeploy.util import cla_helper
25+
from wlsdeploy.util import tool_exit
26+
from wlsdeploy.util import wlst_extended
27+
from wlsdeploy.util.cla_utils import CommandLineArgUtil
28+
from wlsdeploy.util.cla_utils import TOOL_TYPE_EXTRACT
29+
from wlsdeploy.util.model import Model
30+
from wlsdeploy.util.weblogic_helper import WebLogicHelper
31+
32+
wlst_extended.wlst_functions = globals()
33+
34+
_program_name = 'extractDomainResource'
35+
_class_name = 'extract_resource'
36+
__logger = PlatformLogger('wlsdeploy.extract')
37+
__wls_helper = WebLogicHelper(__logger)
38+
__wlst_helper = WlstHelper(__logger, ExceptionType.DEPLOY)
39+
__wlst_mode = WlstModes.OFFLINE
40+
41+
__required_arguments = [
42+
CommandLineArgUtil.ORACLE_HOME_SWITCH,
43+
CommandLineArgUtil.DOMAIN_HOME_SWITCH,
44+
CommandLineArgUtil.DOMAIN_RESOURCE_FILE_SWITCH
45+
]
46+
47+
__optional_arguments = [
48+
# Used by shell script to locate WLST
49+
CommandLineArgUtil.DOMAIN_TYPE_SWITCH,
50+
CommandLineArgUtil.ARCHIVE_FILE_SWITCH,
51+
CommandLineArgUtil.MODEL_FILE_SWITCH,
52+
CommandLineArgUtil.VARIABLE_FILE_SWITCH,
53+
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
54+
CommandLineArgUtil.PASSPHRASE_SWITCH,
55+
]
56+
57+
58+
def __process_args(args):
59+
"""
60+
Process the command-line arguments and prompt the user for any missing information
61+
:param args: the command-line arguments list
62+
:raises CLAException: if an error occurs while validating and processing the command-line arguments
63+
"""
64+
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
65+
cla_util.set_allow_multiple_models(True)
66+
required_arg_map, optional_arg_map = cla_util.process_args(args, TOOL_TYPE_EXTRACT)
67+
68+
cla_helper.verify_required_args_present(_program_name, __required_arguments, required_arg_map)
69+
cla_helper.validate_optional_archive(_program_name, optional_arg_map)
70+
71+
# determine if the model file was passed separately or requires extraction from the archive.
72+
cla_helper.validate_model_present(_program_name, optional_arg_map)
73+
cla_helper.validate_variable_file_exists(_program_name, optional_arg_map)
74+
cla_helper.process_encryption_args(optional_arg_map)
75+
76+
combined_arg_map = optional_arg_map.copy()
77+
combined_arg_map.update(required_arg_map)
78+
return model_context_helper.create_context(_program_name, combined_arg_map)
79+
80+
81+
def __extract_resource(model, model_context, aliases):
82+
"""
83+
Offline deployment orchestration
84+
:param model: the model
85+
:param model_context: the model context
86+
:param aliases: the aliases object
87+
:raises: DeployException: if an error occurs
88+
"""
89+
_method_name = '__extract_resource'
90+
91+
resource_extractor = DomainResourceExtractor(model, model_context, aliases, __logger)
92+
resource_extractor.extract()
93+
return 0
94+
95+
96+
def main(args):
97+
"""
98+
The python entry point for extractDomainResource.
99+
:param args: the command-line arguments
100+
"""
101+
_method_name = 'main'
102+
103+
__logger.entering(args[0], class_name=_class_name, method_name=_method_name)
104+
for index, arg in enumerate(args):
105+
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
106+
107+
__wlst_helper.silence()
108+
109+
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
110+
111+
try:
112+
model_context = __process_args(args)
113+
except CLAException, ex:
114+
exit_code = ex.getExitCode()
115+
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
116+
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
117+
class_name=_class_name, method_name=_method_name)
118+
cla_helper.clean_up_temp_files()
119+
120+
# create a minimal model for summary logging
121+
model_context = model_context_helper.create_exit_context(_program_name)
122+
tool_exit.end(model_context, exit_code)
123+
124+
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
125+
126+
model_dictionary = cla_helper.load_model(_program_name, model_context, aliases, "extract", __wlst_mode)
127+
128+
try:
129+
model = Model(model_dictionary)
130+
exit_code = __extract_resource(model, model_context, aliases)
131+
except DeployException, ex:
132+
__logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex,
133+
class_name=_class_name, method_name=_method_name)
134+
cla_helper.clean_up_temp_files()
135+
tool_exit.end(model_context, CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
136+
137+
cla_helper.clean_up_temp_files()
138+
139+
tool_exit.end(model_context, exit_code)
140+
return
141+
142+
143+
if __name__ == '__main__' or __name__ == 'main':
144+
WebLogicDeployToolingVersion.logVersionInfo(_program_name)
145+
main(sys.argv)

core/src/main/python/wlsdeploy/aliases/alias_entries.py

Lines changed: 80 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import copy
@@ -45,12 +45,19 @@
4545
from wlsdeploy.aliases.alias_constants import WLST_SUBFOLDERS_PATH
4646
from wlsdeploy.aliases.alias_constants import WLST_TYPE
4747
from wlsdeploy.aliases.location_context import LocationContext
48+
from wlsdeploy.aliases.model_constants import APP_DEPLOYMENTS
4849
from wlsdeploy.aliases.model_constants import APPLICATION
49-
from wlsdeploy.aliases.model_constants import RCU_DB_INFO
50-
from wlsdeploy.aliases.model_constants import WLS_ROLES
51-
from wlsdeploy.aliases.model_constants import ODL_CONFIGURATION
50+
from wlsdeploy.aliases.model_constants import DOMAIN_INFO
5251
from wlsdeploy.aliases.model_constants import DOMAIN_INFO_ALIAS
52+
from wlsdeploy.aliases.model_constants import KUBERNETES_ALIAS
53+
from wlsdeploy.aliases.model_constants import ODL_CONFIGURATION
54+
from wlsdeploy.aliases.model_constants import KUBERNETES
55+
from wlsdeploy.aliases.model_constants import RCU_DB_INFO
5356
from wlsdeploy.aliases.model_constants import RESOURCE_MANAGER
57+
from wlsdeploy.aliases.model_constants import RESOURCES
58+
from wlsdeploy.aliases.model_constants import SERVER_POD
59+
from wlsdeploy.aliases.model_constants import TOPOLOGY
60+
from wlsdeploy.aliases.model_constants import WLS_ROLES
5461
from wlsdeploy.aliases.validation_codes import ValidationCodes
5562
from wlsdeploy.aliases.wlst_modes import WlstModes
5663
from wlsdeploy.exception import exception_helper
@@ -137,6 +144,31 @@ class AliasEntries(object):
137144
WLS_ROLES
138145
]
139146

147+
__kubernetes_top_level_folders = [
148+
'metadata',
149+
'spec'
150+
]
151+
152+
__section_top_folders_map = {
153+
DOMAIN_INFO: __domain_info_top_level_folders,
154+
TOPOLOGY: __topology_top_level_folders,
155+
RESOURCES: __resources_top_level_folders,
156+
APP_DEPLOYMENTS: __app_deployments_top_level_folders,
157+
KUBERNETES: __kubernetes_top_level_folders
158+
}
159+
160+
# in rare cases, the alias file name does not match the folder name
161+
__alternate_alias_file_name_map = {
162+
APPLICATION: 'AppDeployment',
163+
'metadata': 'Metadata',
164+
'spec': 'Spec',
165+
'serverPod': 'ServerPod'
166+
}
167+
168+
# all the categories that appear at the top of model sections
169+
__top_model_categories = []
170+
171+
# all the categories, including section-attribute and contained categories
140172
__all_model_categories = []
141173

142174
__domain_name_token = 'DOMAIN'
@@ -156,16 +188,23 @@ def __init__(self, wlst_mode=WlstModes.OFFLINE, wls_version=None):
156188
self._wls_helper = WebLogicHelper(_logger, wls_version)
157189
self._wls_version = wls_version
158190

159-
self.__all_model_categories.extend(self.__topology_top_level_folders)
160-
self.__all_model_categories.extend(self.__resources_top_level_folders)
161-
self.__all_model_categories.extend(self.__app_deployments_top_level_folders)
162-
self.__all_model_categories.extend(self.__domain_info_top_level_folders)
191+
# top model categories
192+
self.__top_model_categories.extend(self.__topology_top_level_folders)
193+
self.__top_model_categories.extend(self.__resources_top_level_folders)
194+
self.__top_model_categories.extend(self.__app_deployments_top_level_folders)
195+
self.__top_model_categories.extend(self.__domain_info_top_level_folders)
196+
self.__top_model_categories.extend(self.__kubernetes_top_level_folders)
163197

164-
# ResourceManager is not a top-level folder, it's contained by ResourceManagement
198+
# all model categories
199+
self.__all_model_categories.extend(self.__top_model_categories)
200+
201+
# include contained categories
165202
self.__all_model_categories.append(RESOURCE_MANAGER)
203+
self.__all_model_categories.append(SERVER_POD)
166204

167-
# DomainInfo is not a top-level folder, it defines domainInfo top-level attributes
205+
# include section attribute categories
168206
self.__all_model_categories.append(DOMAIN_INFO_ALIAS)
207+
self.__all_model_categories.append(KUBERNETES_ALIAS)
169208
return
170209

171210
def get_dictionary_for_location(self, location, resolve=True):
@@ -196,15 +235,7 @@ def get_model_domain_subfolder_names(self):
196235
_method_name = 'get_model_domain_subfolder_names'
197236

198237
_logger.entering(class_name=_class_name, method_name=_method_name)
199-
folder_list = list(self.__all_model_categories)
200-
#
201-
# Remove all folders that do not appear at the WLST root level
202-
#
203-
if 'Domain' in folder_list:
204-
folder_list.remove('Domain')
205-
if 'ResourceManager' in folder_list:
206-
folder_list.remove('ResourceManager')
207-
238+
folder_list = list(self.__top_model_categories)
208239
_logger.exiting(class_name=_class_name, method_name=_method_name, result=folder_list)
209240
return folder_list
210241

@@ -244,12 +275,31 @@ def get_model_app_deployments_subfolder_names(self):
244275
"""
245276
return list(self.__app_deployments_top_level_folders)
246277

247-
def get_model_domain_info_subfolder_names(self):
278+
def get_model_section_subfolder_names(self, section_name):
248279
"""
249-
Get the top-level model folder names underneath the domain info section.
280+
Get the top-level model folder names underneath the specified section.
250281
:return: a list of the folder names
251282
"""
252-
return list(self.__domain_info_top_level_folders)
283+
result = dictionary_utils.get_element(self.__section_top_folders_map, section_name)
284+
if result is None:
285+
result = []
286+
return result
287+
288+
def get_model_section_attribute_location(self, section_name):
289+
"""
290+
Get the location containing the attributes for a model section (topology, domainInfo, etc.)
291+
:return: a location, or None of the section does not have attributes.
292+
"""
293+
if section_name == TOPOLOGY:
294+
return LocationContext()
295+
296+
if section_name == DOMAIN_INFO:
297+
return LocationContext().append_location(DOMAIN_INFO_ALIAS)
298+
299+
if section_name == KUBERNETES:
300+
return LocationContext().append_location(KUBERNETES_ALIAS)
301+
302+
return None
253303

254304
def get_model_subfolder_names_for_location(self, location):
255305
"""
@@ -883,13 +933,13 @@ def _unit_test_only_get_category_map_files(self):
883933
def _get_category_file_prefix(self, category_name):
884934
"""
885935
Return the file prefix for the specified top-level category.
886-
The file prefix should match the category name exactly.
887-
File name for Application is different for some reason
936+
The file prefix should match the category name exactly, except in rare cases.
888937
:param category_name: the name to be checked
889-
:return: the corressponding file name prefix
938+
:return: the corresponding file name prefix
890939
"""
891-
if category_name == APPLICATION:
892-
return 'AppDeployment'
940+
alternate_name = dictionary_utils.get_element(self.__alternate_alias_file_name_map, category_name)
941+
if alternate_name is not None:
942+
return alternate_name
893943
return category_name
894944

895945
def __get_dictionary_for_location(self, location, resolve_path_tokens=True):
@@ -1041,9 +1091,9 @@ def __load_contains_categories(self, model_category_name, raw_model_dict, base_p
10411091
for key, value in raw_folders_wlst_paths.iteritems():
10421092
raw_model_dict[WLST_PATHS][key] = base_path + value
10431093

1044-
for folder in raw_model_dict_folders:
1045-
raw_folder_dict = raw_model_dict_folders[folder]
1046-
self.__load_contains_categories(folder, raw_folder_dict, base_path)
1094+
for folder in raw_model_dict_folders:
1095+
raw_folder_dict = raw_model_dict_folders[folder]
1096+
self.__load_contains_categories(folder, raw_folder_dict, base_path)
10471097

10481098
#
10491099
# Now that the folder paths are all updated accordingly, load any contains folders, compute the

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
from java.lang import String
@@ -126,13 +126,20 @@ def get_model_app_deployments_top_level_folder_names(self):
126126
"""
127127
return self._alias_entries.get_model_app_deployments_subfolder_names()
128128

129-
def get_model_domain_info_top_level_folder_names(self):
129+
def get_model_section_top_level_folder_names(self, section_name):
130130
"""
131-
Returns a list of the recognized top-level model folders in the domainInfo section corresponding to the
131+
Returns a list of the recognized top-level model folders in the specified section corresponding to the
132132
known WLST top-level folders.
133133
:return: a list of the recognized top-level model folder names
134134
"""
135-
return self._alias_entries.get_model_domain_info_subfolder_names()
135+
return self._alias_entries.get_model_section_subfolder_names(section_name)
136+
137+
def get_model_section_attribute_location(self, section_name):
138+
"""
139+
Get the location containing the attributes for a model section (topology, domainInfo, etc.)
140+
:return: a location, or None of the section does not have attributes.
141+
"""
142+
return self._alias_entries.get_model_section_attribute_location(section_name)
136143

137144
def get_model_subfolder_names(self, location):
138145
"""

0 commit comments

Comments
 (0)