Skip to content

Commit 4e65259

Browse files
authored
Merge pull request #126 from oracle/Issue#96-online-discover-domain
Issue#96 online discover domain
2 parents fcab22f + f7e420e commit 4e65259

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+771
-221
lines changed

core/src/main/java/oracle/weblogic/deploy/aliases/TypeUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ public static Object convertToType(Class<?> targetType, Object value, String del
187187
strValue = String.valueOf((char[]) value);
188188
} else {
189189
strValue = value.toString().trim();
190+
if (strValue.length() == 0) {
191+
return null;
192+
}
190193
}
191194

192195
Object result;
@@ -277,6 +280,7 @@ private static Object[] convertToObjectArray(Object value, String strValue, Stri
277280
} else {
278281
result = convertStringToList(strValue, delimiter).toArray(new String[0]);
279282
}
283+
LOGGER.fine("before convert {0} and after convert {1}", value, strValue);
280284
return result;
281285
}
282286

core/src/main/python/discover.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525

2626
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
2727

28+
from wlsdeploy.aliases import model_constants
29+
from wlsdeploy.aliases.aliases import Aliases
30+
from wlsdeploy.aliases.location_context import LocationContext
2831
import wlsdeploy.tool.util.variable_injector as variable_injector
32+
2933
from wlsdeploy.aliases.wlst_modes import WlstModes
3034
from wlsdeploy.exception import exception_helper
3135
from wlsdeploy.logging.platform_logger import PlatformLogger
@@ -138,7 +142,7 @@ def __process_online_args(optional_arg_map):
138142
raise ex
139143
optional_arg_map[CommandLineArgUtil.ADMIN_PASS_SWITCH] = String(password)
140144

141-
__logger.info('WLSDPLY-06020', class_name=_class_name, method_name=_method_name)
145+
mode = WlstModes.ONLINE
142146
return mode
143147

144148

@@ -184,23 +188,28 @@ def __process_variable_filename_arg(optional_arg_map):
184188
return
185189

186190

187-
def __discover(model_context):
191+
def __discover(model_context, aliases):
188192
"""
189193
Populate the model from the domain.
190194
:param model_context: the model context
191195
:return: the fully-populated model
192196
:raises DiscoverException: if an error occurred while discover the domain
193197
"""
194198
_method_name = '__discover'
195-
196199
model = Model()
200+
base_location = LocationContext()
197201
__connect_to_domain(model_context)
198202
try:
199-
DomainInfoDiscoverer(model_context, model.get_model_domain_info(), wlst_mode=__wlst_mode).discover()
200-
TopologyDiscoverer(model_context, model.get_model_topology(), wlst_mode=__wlst_mode).discover()
201-
ResourcesDiscoverer(model_context, model.get_model_resources(), wlst_mode=__wlst_mode).discover()
202-
DeploymentsDiscoverer(model_context, model.get_model_app_deployments(), wlst_mode=__wlst_mode).discover()
203-
__discover_multi_tenant(model, model_context)
203+
_add_domain_name(base_location, aliases)
204+
DomainInfoDiscoverer(model_context, model.get_model_domain_info(), base_location, wlst_mode=__wlst_mode,
205+
aliases=aliases).discover()
206+
TopologyDiscoverer(model_context, model.get_model_topology(), base_location, wlst_mode=__wlst_mode,
207+
aliases=aliases).discover()
208+
ResourcesDiscoverer(model_context, model.get_model_resources(), base_location, wlst_mode=__wlst_mode,
209+
aliases=aliases).discover()
210+
DeploymentsDiscoverer(model_context, model.get_model_app_deployments(), base_location, wlst_mode=__wlst_mode,
211+
aliases=aliases).discover()
212+
__discover_multi_tenant(model, model_context, base_location, aliases)
204213
except AliasException, ae:
205214
wls_version = WebLogicHelper(__logger).get_actual_weblogic_version()
206215
wlst_mode = WlstModes.from_value(__wlst_mode)
@@ -214,14 +223,32 @@ def __discover(model_context):
214223
return model
215224

216225

217-
def __discover_multi_tenant(model, model_context):
226+
def _add_domain_name(location, aliases):
227+
_method_name = '_get_domain_name'
228+
try:
229+
wlst_helper.cd('/')
230+
domain_name = wlst_helper.get(model_constants.DOMAIN_NAME)
231+
except PyWLSTException, pe:
232+
de = exception_helper.create_discover_exception('WLSDPLY-06020', pe.getLocalizedMessage())
233+
__logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
234+
raise de
235+
if domain_name is not None:
236+
location.add_name_token(aliases.get_name_token(location), domain_name)
237+
__logger.info('WLSDPLY-06022', domain_name, class_name=_class_name, method_name=_method_name)
238+
else:
239+
de = exception_helper.create_discover_exception('WLSDPLY-WLSDPLY-06023')
240+
__logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
241+
raise de
242+
243+
244+
def __discover_multi_tenant(model, model_context, base_location, aliases):
218245
"""
219246
Discover the multi-tenant-related parts of the domain, if they exist.
220247
:param model: the model object to populate
221248
:param model_context: the model context object
222249
:raises DiscoverException: if an error occurs during discovery
223250
"""
224-
MultiTenantDiscoverer(model, model_context, wlst_mode=__wlst_mode).discover()
251+
MultiTenantDiscoverer(model, model_context, base_location, wlst_mode=__wlst_mode, aliases=aliases).discover()
225252
return
226253

227254

@@ -381,7 +408,7 @@ def __persist_model(model, model_context):
381408
return
382409

383410

384-
def __check_and_customize_model(model, model_context):
411+
def __check_and_customize_model(model, model_context, aliases):
385412
"""
386413
Customize the model dictionary before persisting. Validate the model after customization for informational
387414
purposes. Any validation errors will not stop the discovered model to be persisted.
@@ -400,7 +427,7 @@ def __check_and_customize_model(model, model_context):
400427
if inserted:
401428
model = Model(variable_model)
402429
try:
403-
validator = Validator(model_context, wlst_mode=__wlst_mode)
430+
validator = Validator(model_context, wlst_mode=__wlst_mode, aliases=aliases)
404431

405432
# no variables are generated by the discover tool
406433
validator.validate_in_tool_mode(model.get_model(), variables_file_name=variable_file_name,
@@ -410,14 +437,15 @@ def __check_and_customize_model(model, model_context):
410437
return model
411438

412439

413-
def __log_and_exit(exit_code, class_name, _method_name):
440+
def __log_and_exit(exit_code, class_name, method_name):
414441
"""
415442
Helper method to log the exiting message and call sys.exit()
416443
:param exit_code: the exit code to use
417444
:param class_name: the class name to pass to the logger
418-
:param _method_name: the method name to pass to the logger
445+
:param method_name: the method name to pass to the logger
419446
"""
420-
__logger.exiting(result=exit_code, class_name=class_name, method_name=_method_name)
447+
__logger.exiting(result=exit_code, class_name=class_name, method_name=method_name)
448+
421449
sys.exit(exit_code)
422450

423451

@@ -455,16 +483,18 @@ def main(args):
455483
ex.getLocalizedMessage(), error=ex, class_name=_class_name, method_name=_method_name)
456484
__log_and_exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name)
457485

486+
aliases = Aliases(model_context, wlst_mode=__wlst_mode)
458487
model = None
459488
try:
460-
model = __discover(model_context)
489+
model = __discover(model_context, aliases)
461490
except DiscoverException, ex:
462491
__logger.severe('WLSDPLY-06011', _program_name, model_context.get_domain_name(),
463492
model_context.get_domain_home(), ex.getLocalizedMessage(),
464493
error=ex, class_name=_class_name, method_name=_method_name)
465494
__log_and_exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE, _class_name, _method_name)
466-
467-
model = __check_and_customize_model(model, model_context)
495+
496+
model = __check_and_customize_model(model, model_context, aliases)
497+
468498
try:
469499
__persist_model(model, model_context)
470500

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
WLST_PATH = 'wlst_path'
4141
WLST_PATHS = 'wlst_paths'
4242
WLST_READ_TYPE = 'wlst_read_type'
43+
WLST_SKIP_NAMES = '__wlst_skip_names__'
4344
WLST_SUBFOLDERS_PATH = 'wlst_subfolders_path'
4445
WLST_TYPE = 'wlst_type'
4546

@@ -106,6 +107,7 @@
106107
ALIAS_DATA_TYPES.extend(ALIAS_LIST_TYPES)
107108
ALIAS_DATA_TYPES.extend(ALIAS_MAP_TYPES)
108109

110+
109111
def __build_security_provider_data_structures(name_map, base_path):
110112
"""
111113
Populate the security provider data structures for the given provider type.
@@ -119,6 +121,7 @@ def __build_security_provider_data_structures(name_map, base_path):
119121
SECURITY_PROVIDER_MBEAN_NAME_MAP[mbean_name] = key
120122
return
121123

124+
122125
ADJUDICATION_PROVIDER_NAME_MAP = {
123126
'DefaultAdjudicator': 'weblogic.security.providers.authorization.DefaultAdjudicator'
124127
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111
from oracle.weblogic.deploy.util import FileUtils
1212

1313
import wlsdeploy.aliases.alias_utils as alias_utils
14+
from wlsdeploy.aliases import password_utils
1415
from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
1516
from wlsdeploy.aliases.location_context import LocationContext
1617
from wlsdeploy.aliases.validation_codes import ValidationCodes
1718
from wlsdeploy.aliases.wlst_modes import WlstModes
1819
from wlsdeploy.exception import exception_helper
1920
from wlsdeploy.logging.platform_logger import PlatformLogger
21+
from wlsdeploy.util import dictionary_utils
2022
from wlsdeploy.util.weblogic_helper import WebLogicHelper
2123

2224
from wlsdeploy.aliases.alias_constants import ATTRIBUTES
@@ -46,9 +48,11 @@
4648
from wlsdeploy.aliases.alias_constants import WLST_NAMES_MAP
4749
from wlsdeploy.aliases.alias_constants import WLST_PATH
4850
from wlsdeploy.aliases.alias_constants import WLST_PATHS
51+
from wlsdeploy.aliases.alias_constants import WLST_SKIP_NAMES
4952
from wlsdeploy.aliases.alias_constants import WLST_SUBFOLDERS_PATH
5053
from wlsdeploy.aliases.alias_constants import WLST_TYPE
5154

55+
IGNORE_FOR_MODEL_LIST = ['DynamicallyCreated', 'Id', 'Tag', 'Tags', 'Type', 'Name']
5256
_class_name = 'AliasEntries'
5357
_logger = PlatformLogger('wlsdeploy.aliases')
5458

@@ -730,15 +734,17 @@ def get_alias_attribute_entry_by_wlst_name(self, location, wlst_attribute_name):
730734

731735
_logger.entering(str(location), class_name=_class_name, method_name=_method_name)
732736
folder_dict = self.__get_dictionary_for_location(location, False)
733-
if folder_dict is not None and WLST_NAMES_MAP in folder_dict:
737+
if self._is_wlst_attribute_skipped(folder_dict, wlst_attribute_name):
738+
result = None
739+
elif folder_dict is not None and WLST_NAMES_MAP in folder_dict:
734740
if wlst_attribute_name in folder_dict[WLST_NAMES_MAP]:
735741
result = copy.deepcopy(folder_dict[WLST_NAMES_MAP][wlst_attribute_name])
736742
if WLST_PATH in result:
737743
del result[WLST_PATH]
738744
else:
739745
_logger.warning('WLSDPLY-08110', wlst_attribute_name, location.get_folder_path(), WLST_PATH)
740746
else:
741-
if wlst_attribute_name not in ('Id', 'Tag', 'Name'):
747+
if wlst_attribute_name not in IGNORE_FOR_MODEL_LIST:
742748
ex = exception_helper.create_alias_exception('WLSDPLY-08111', location.get_folder_path(),
743749
wlst_attribute_name)
744750
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
@@ -1149,6 +1155,7 @@ def __apply_wlst_context_changes(self, path_name, alias_dict, parent_dict):
11491155
result_model_attrs = dict()
11501156
result_wlst_attrs = dict()
11511157
unresolved_attrs = dict()
1158+
wlst_skip_attrs = list()
11521159

11531160
model_attrs = alias_dict[ATTRIBUTES]
11541161
for model_attr in model_attrs:
@@ -1184,9 +1191,15 @@ def __apply_wlst_context_changes(self, path_name, alias_dict, parent_dict):
11841191
result_model_attrs[model_attr] = model_attr_dict
11851192
result_wlst_attrs[wlst_name] = model_attr_dict
11861193

1194+
# if attribute is dual-password, add its WLST skip name to the skip list
1195+
skip_name = password_utils.get_wlst_skip_name(model_attr_dict, self._wlst_mode)
1196+
if skip_name is not None:
1197+
wlst_skip_attrs.append(skip_name)
1198+
11871199
result[ATTRIBUTES] = result_model_attrs
11881200
result[WLST_NAMES_MAP] = result_wlst_attrs
11891201
result[UNRESOLVED_ATTRIBUTES_MAP] = unresolved_attrs
1202+
result[WLST_SKIP_NAMES] = wlst_skip_attrs
11901203

11911204
return result
11921205

@@ -1364,6 +1377,12 @@ def __get_valid_version_range_for_folder(self, location):
13641377
_logger.exiting(class_name=_class_name, method_name=_method_name, result=version_range)
13651378
return version_range
13661379

1380+
def _is_wlst_attribute_skipped(self, folder_dict, wlst_attribute_name):
1381+
skip_names = dictionary_utils.get_element(folder_dict, WLST_SKIP_NAMES) # type: list
1382+
if skip_names is not None:
1383+
return wlst_attribute_name in skip_names
1384+
return False
1385+
13671386
def __get_path_for_location(self, location, path_type=WLST_ATTRIBUTES_PATH):
13681387
"""
13691388
Get the tokenized path of the specified type for the location. This method is used by all path-related methods.

0 commit comments

Comments
 (0)