|
| 1 | +""" |
| 2 | +Copyright (c) 2020, Oracle Corporation and/or its affiliates. |
| 3 | +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +""" |
| 5 | + |
| 6 | +from java.io import IOException |
| 7 | +from java.lang import Long |
| 8 | +from java.lang import NumberFormatException |
| 9 | + |
| 10 | +from wlsdeploy.exception import exception_helper |
| 11 | +from wlsdeploy.logging.platform_logger import PlatformLogger |
| 12 | +from wlsdeploy.util import path_utils |
| 13 | +from wlsdeploy.util import string_utils |
| 14 | + |
| 15 | +TOOL_PROPERTIES_FILE_NAME = 'tool.properties' |
| 16 | + |
| 17 | +_logger = PlatformLogger('wlsdeploy.config') |
| 18 | +_class_name = 'ModelConfig' |
| 19 | + |
| 20 | +# Tool Properties for configuration and default values if properties not loaded |
| 21 | + |
| 22 | +# WLST TIMEOUT PROPERTIES |
| 23 | +CONNECT_TIMEOUT_PROP = 'connect.timeout' |
| 24 | +CONNECT_TIMEOUT_DEFAULT = '120000' |
| 25 | +ACTIVATE_TIMEOUT_PROP = 'activate.timeout' |
| 26 | +ACTIVATE_TIMEOUT_DEFAULT = '180000' |
| 27 | +DEPLOY_TIMEOUT_PROP = 'deploy.timeout' |
| 28 | +DEPLOY_TIMEOUT_DEFAULT = '180000' |
| 29 | +REDEPLOY_TIMEOUT_PROP = 'redeploy.timeout' |
| 30 | +REDEPLOY_TIMEOUT_DEFAULT = '180000' |
| 31 | +UNDEPLOY_TIMEOUT_PROP = 'undeploy.timeout' |
| 32 | +UNDEPLOY_TIMEOUT_DEFAULT = '180000' |
| 33 | +START_APP_TIMEOUT_PROP = 'start.application.timeout' |
| 34 | +START_APP_TIMEOUT_DEFAULT = '180000' |
| 35 | +STOP_APP_TIMEOUT_PROP = 'stop.application.timeout' |
| 36 | +STOP_APP_TIMEOUT_DEFAULT = '180000' |
| 37 | +SET_SERVER_GRPS_TIMEOUT_PROP = 'set.server.groups.timeout' |
| 38 | +SET_SERVER_GRPS_TIMEOUT_DEFAULT = '30000' |
| 39 | + |
| 40 | + |
| 41 | +class ModelConfiguration(object): |
| 42 | + """ |
| 43 | + This class encapsulates the tool properties used in configuring and tuning |
| 44 | + """ |
| 45 | + |
| 46 | + def __init__(self, program_name): |
| 47 | + """ |
| 48 | + Load the properties from the tools.properties file and save the resulting dictionary |
| 49 | + :return: |
| 50 | + """ |
| 51 | + self._program_name = program_name |
| 52 | + self.__config_dict = _load_properties_file() |
| 53 | + |
| 54 | + def get_connect_timeout(self): |
| 55 | + """ |
| 56 | + Return the connect timeout from tool properties. |
| 57 | + :return: connect timeout |
| 58 | + """ |
| 59 | + return self._get_from_dict(CONNECT_TIMEOUT_PROP, CONNECT_TIMEOUT_DEFAULT) |
| 60 | + |
| 61 | + def get_activate_timeout(self): |
| 62 | + """ |
| 63 | + Return the activate timeout from tool properties. |
| 64 | + :return: activate timeout |
| 65 | + """ |
| 66 | + return self._get_from_dict_as_long(ACTIVATE_TIMEOUT_PROP, ACTIVATE_TIMEOUT_DEFAULT) |
| 67 | + |
| 68 | + def get_deploy_timeout(self): |
| 69 | + """ |
| 70 | + Return the deploy timeout from tool properties. |
| 71 | + :return: deploy timeout |
| 72 | + """ |
| 73 | + return self._get_from_dict_as_long(DEPLOY_TIMEOUT_PROP, DEPLOY_TIMEOUT_DEFAULT) |
| 74 | + |
| 75 | + def get_redeploy_timeout(self): |
| 76 | + """ |
| 77 | + Return the redeploy timeout from tool properties |
| 78 | + :return: redeploy timeout |
| 79 | + """ |
| 80 | + return self._get_from_dict_as_long(REDEPLOY_TIMEOUT_PROP, REDEPLOY_TIMEOUT_DEFAULT) |
| 81 | + |
| 82 | + def get_undeploy_timeout(self): |
| 83 | + """ |
| 84 | + Return undeploy timeout from tool properties. |
| 85 | + :return: undeploy timeout |
| 86 | + """ |
| 87 | + return self._get_from_dict_as_long(UNDEPLOY_TIMEOUT_PROP, UNDEPLOY_TIMEOUT_DEFAULT) |
| 88 | + |
| 89 | + def get_stop_app_timeout(self): |
| 90 | + """ |
| 91 | + Return stop application timeout from tool properties. |
| 92 | + :return: stop application timeout |
| 93 | + """ |
| 94 | + return self._get_from_dict_as_long(STOP_APP_TIMEOUT_PROP, STOP_APP_TIMEOUT_DEFAULT) |
| 95 | + |
| 96 | + def get_start_app_timeout(self): |
| 97 | + """ |
| 98 | + Return start application timeout from tool properties. |
| 99 | + :return: start application timeout |
| 100 | + """ |
| 101 | + return self._get_from_dict_as_long(START_APP_TIMEOUT_PROP, START_APP_TIMEOUT_DEFAULT) |
| 102 | + |
| 103 | + def get_set_server_grps_timeout(self): |
| 104 | + """ |
| 105 | + Return timeout value for setServerGroups from tool properties |
| 106 | + :return: set server groups timeout |
| 107 | + """ |
| 108 | + return self._get_from_dict_as_long(SET_SERVER_GRPS_TIMEOUT_PROP, SET_SERVER_GRPS_TIMEOUT_DEFAULT) |
| 109 | + |
| 110 | + def _get_from_dict(self, name, default_value=None): |
| 111 | + _method_name = '_get_from_dict' |
| 112 | + _logger.entering(name, default_value, class_name=_class_name, method_name=_method_name) |
| 113 | + result = default_value |
| 114 | + if name in self.__config_dict: |
| 115 | + result = self.__config_dict[name] |
| 116 | + _logger.exiting(result=result, class_name=_class_name, method_name=_method_name) |
| 117 | + return result |
| 118 | + |
| 119 | + def _get_from_dict_as_long(self, name, default_value=None): |
| 120 | + _method_name = '_get_from_dict_as_long' |
| 121 | + result = self._get_from_dict(name, default_value) |
| 122 | + try: |
| 123 | + result = Long(result).longValue() |
| 124 | + except NumberFormatException, nfe: |
| 125 | + _logger.warning('WLSDPLY-01571', result, name, self._program_name, default_value, nfe.getLocalizedMessage(), |
| 126 | + class_name=_class_name, method_name=_method_name) |
| 127 | + result = Long(default_value).longValue() |
| 128 | + return result |
| 129 | + |
| 130 | + |
| 131 | +def _load_properties_file(): |
| 132 | + """ |
| 133 | + Load the properties from the WLSDEPLOY properties file into dictionary |
| 134 | + :return: tool config properties in dict format |
| 135 | + """ |
| 136 | + _method_name = 'load_properties_file' |
| 137 | + _logger.entering(class_name=_class_name, method_name=_method_name) |
| 138 | + wlsdeploy_path = path_utils.find_config_path(TOOL_PROPERTIES_FILE_NAME) |
| 139 | + result = None |
| 140 | + try: |
| 141 | + result = string_utils.load_properties(wlsdeploy_path) |
| 142 | + except IOException, ioe: |
| 143 | + _logger.warning('WLSDPLY-01570', wlsdeploy_path, ioe.getMessage(), |
| 144 | + class_name=_class_name, method_name=_method_name) |
| 145 | + _logger.exiting(class_name=_class_name, method_name=_method_name) |
| 146 | + return result |
0 commit comments