|
1 | 1 | """ |
2 | | -Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. |
| 2 | +Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | The Universal Permissive License (UPL), Version 1.0 |
4 | 4 | """ |
5 | 5 |
|
@@ -38,85 +38,128 @@ def __init__(self, model, model_context, aliases, exception_type, logger): |
38 | 38 | else: |
39 | 39 | self._admin_server_name = DEFAULT_ADMIN_SERVER_NAME |
40 | 40 |
|
41 | | - def target_server_groups_to_servers(self, server_groups_to_target): |
| 41 | + def target_jrf_groups_to_clusters_servers(self, domain_home): |
42 | 42 | """ |
43 | | - Target the server groups to the servers. |
44 | | - :param server_groups_to_target: the list of server groups to target |
45 | | - :raises: BundleAwareException of the specified type: if an error occurs |
| 43 | + Use the apply_jrf only for those versions of wlst that do not have server groups. |
| 44 | + This assigns the JRF resources to all managed servers. If the managed server is in a |
| 45 | + cluster, this method assigns the JRF resources are assigned to the cluster. Else, if |
| 46 | + the managed server is stand-alone, the resources are assigned to the managed server. |
| 47 | + :param domain_home: the directory for the domain_home |
46 | 48 | """ |
47 | | - _method_name = '__target_server_groups_to_servers' |
| 49 | + _method_name = 'target_jrf_groups_to_clusters_servers' |
48 | 50 |
|
49 | | - self.logger.entering(server_groups_to_target, class_name=self.__class_name, method_name=_method_name) |
50 | | - if len(server_groups_to_target) == 0: |
51 | | - return |
| 51 | + self.logger.entering(domain_home, class_name=self.__class_name, method_name=_method_name) |
52 | 52 |
|
53 | 53 | location = LocationContext() |
54 | 54 | root_path = self.alias_helper.get_wlst_attributes_path(location) |
55 | 55 | self.wlst_helper.cd(root_path) |
| 56 | + admin_server_name = self.wlst_helper.get(ADMIN_SERVER_NAME) |
56 | 57 |
|
57 | 58 | # We need to get the effective list of servers for the domain. Since any servers |
58 | 59 | # referenced in the model have already been created but the templates may have |
59 | 60 | # defined new servers not listed in the model, get the list from WLST. |
60 | | - server_names = self._get_existing_server_names() |
| 61 | + server_names = self.get_existing_server_names() |
| 62 | + if admin_server_name in server_names: |
| 63 | + server_names.remove(admin_server_name) |
61 | 64 |
|
62 | 65 | # Get the clusters and and their members |
63 | | - cluster_map = self._get_clusters_and_members_map() |
| 66 | + cluster_map = self.get_clusters_and_members_map() |
| 67 | + self.wlst_helper.update_domain() |
| 68 | + self.wlst_helper.close_domain() |
64 | 69 |
|
65 | | - # Get any limits that may have been defined in the model |
66 | | - domain_info = self.model.get_model_domain_info() |
67 | | - server_group_targeting_limits = \ |
68 | | - dictionary_utils.get_dictionary_element(domain_info, SERVER_GROUP_TARGETING_LIMITS) |
69 | | - if len(server_group_targeting_limits) > 0: |
70 | | - server_group_targeting_limits = \ |
71 | | - self._get_server_group_targeting_limits(server_group_targeting_limits, cluster_map) |
72 | | - |
73 | | - # Get the map of server names to server groups to target |
74 | | - server_to_server_groups_map =\ |
75 | | - self._get_server_to_server_groups_map(self._admin_server_name, |
76 | | - server_names, |
77 | | - server_groups_to_target, |
78 | | - server_group_targeting_limits) # type: dict |
79 | | - |
80 | | - if len(server_names) > 1: |
81 | | - for server, server_groups in server_to_server_groups_map.iteritems(): |
82 | | - if len(server_groups) > 0: |
83 | | - server_name = self.wlst_helper.get_quoted_name_for_wlst(server) |
84 | | - self.logger.info('WLSDPLY-12224', str(server_groups), server_name, |
85 | | - class_name=self.__class_name, method_name=_method_name) |
86 | | - self.wlst_helper.set_server_groups(server_name, server_groups) |
87 | | - |
88 | | - elif len(server_group_targeting_limits) == 0: |
89 | | - # |
90 | | - # Domain has no managed servers and there were not targeting limits specified to target |
91 | | - # server groups to the admin server so make sure that the server groups are targeted to |
92 | | - # the admin server. |
93 | | - # |
94 | | - # This is really a best effort attempt. It works for JRF domains but it is certainly possible |
95 | | - # that it may cause problems with other custom domain types. Of course, creating a domain with |
96 | | - # no managed servers is not a primary use case of this tool so do it and hope for the best... |
97 | | - # |
98 | | - server_name = self.wlst_helper.get_quoted_name_for_wlst(server_names[0]) |
99 | | - self.wlst_helper.set_server_groups(server_name, server_groups_to_target) |
| 70 | + # Get the clusters and and their members |
| 71 | + for cluster_name, cluster_servers in cluster_map.iteritems(): |
| 72 | + self.logger.info('WLSDPLY-12232', 'Cluster', cluster_name, class_name=self.__class_name, |
| 73 | + method_name=_method_name) |
| 74 | + self.wlst_helper.apply_jrf(cluster_name, domain_home, should_update=True) |
| 75 | + for member in cluster_servers: |
| 76 | + if member in server_names: |
| 77 | + server_names.remove(member) |
| 78 | + for ms_name in server_names: |
| 79 | + self.logger.info('WLSDPLY-12232', 'Managed Server', ms_name, class_name=self.__class_name, |
| 80 | + method_name=_method_name) |
| 81 | + self.wlst_helper.apply_jrf(ms_name, domain_home, should_update=True) |
100 | 82 |
|
101 | 83 | self.logger.exiting(class_name=self.__class_name, method_name=_method_name) |
102 | 84 | return |
103 | 85 |
|
104 | | - def _get_existing_server_names(self): |
| 86 | + def target_server_groups_to_servers(self, domain_home, server_groups_to_target): |
105 | 87 | """ |
106 | | - Get the list of server names from WLST. |
107 | | - :return: the list of server names |
108 | | - :raises: BundleAwareException of the specified type: is an error occurs reading from the aliases or WLST |
| 88 | + Target the server groups to the servers. |
| 89 | + :param server_groups_to_target: the list of server groups to target |
| 90 | + :raises: BundleAwareException of the specified type: if an error occurs |
109 | 91 | """ |
110 | | - _method_name = '_get_existing_server_names' |
| 92 | + _method_name = '__target_server_groups_to_servers' |
111 | 93 |
|
112 | | - self.logger.entering(class_name=self.__class_name, method_name=_method_name) |
113 | | - server_location = LocationContext().append_location(SERVER) |
114 | | - server_list_path = self.alias_helper.get_wlst_list_path(server_location) |
115 | | - result = self.wlst_helper.get_existing_object_list(server_list_path) |
116 | | - self.logger.exiting(class_name=self.__class_name, method_name=_method_name, result=result) |
117 | | - return result |
| 94 | + self.logger.entering(server_groups_to_target, class_name=self.__class_name, method_name=_method_name) |
| 95 | + if len(server_groups_to_target) > 0: |
| 96 | + location = LocationContext() |
| 97 | + root_path = self.alias_helper.get_wlst_attributes_path(location) |
| 98 | + self.wlst_helper.cd(root_path) |
| 99 | + |
| 100 | + # We need to get the effective list of servers for the domain. Since any servers |
| 101 | + # referenced in the model have already been created but the templates may have |
| 102 | + # defined new servers not listed in the model, get the list from WLST. |
| 103 | + server_names = self.get_existing_server_names() |
| 104 | + |
| 105 | + # Get the clusters and and their members |
| 106 | + cluster_map = self.get_clusters_and_members_map() |
| 107 | + |
| 108 | + location = LocationContext() |
| 109 | + root_path = self.alias_helper.get_wlst_attributes_path(location) |
| 110 | + self.wlst_helper.cd(root_path) |
118 | 111 |
|
119 | | - def _get_clusters_and_members_map(self): |
| 112 | + # We need to get the effective list of servers for the domain. Since any servers |
| 113 | + # referenced in the model have already been created but the templates may have |
| 114 | + # defined new servers not listed in the model, get the list from WLST. |
| 115 | + server_names = self.get_existing_server_names() |
| 116 | + |
| 117 | + # Get the clusters and and their members |
| 118 | + cluster_map = self.get_clusters_and_members_map() |
| 119 | + |
| 120 | + # Get any limits that may have been defined in the model |
| 121 | + domain_info = self.model.get_model_domain_info() |
| 122 | + server_group_targeting_limits = \ |
| 123 | + dictionary_utils.get_dictionary_element(domain_info, SERVER_GROUP_TARGETING_LIMITS) |
| 124 | + if len(server_group_targeting_limits) > 0: |
| 125 | + server_group_targeting_limits = \ |
| 126 | + self._get_server_group_targeting_limits(server_group_targeting_limits, cluster_map) |
| 127 | + |
| 128 | + # Get the map of server names to server groups to target |
| 129 | + server_to_server_groups_map =\ |
| 130 | + self._get_server_to_server_groups_map(self._admin_server_name, |
| 131 | + server_names, |
| 132 | + server_groups_to_target, |
| 133 | + server_group_targeting_limits) # type: dict |
| 134 | + |
| 135 | + if len(server_names) > 1: |
| 136 | + for server, server_groups in server_to_server_groups_map.iteritems(): |
| 137 | + if len(server_groups) > 0: |
| 138 | + server_name = self.wlst_helper.get_quoted_name_for_wlst(server) |
| 139 | + self.logger.info('WLSDPLY-12224', str(server_groups), server_name, |
| 140 | + class_name=self.__class_name, method_name=_method_name) |
| 141 | + self.wlst_helper.set_server_groups(server_name, server_groups) |
| 142 | + |
| 143 | + elif len(server_group_targeting_limits) == 0: |
| 144 | + # |
| 145 | + # Domain has no managed servers and there were not targeting limits specified to target |
| 146 | + # server groups to the admin server so make sure that the server groups are targeted to |
| 147 | + # the admin server. |
| 148 | + # |
| 149 | + # This is really a best effort attempt. It works for JRF domains but it is certainly possible |
| 150 | + # that it may cause problems with other custom domain types. Of course, creating a domain with |
| 151 | + # no managed servers is not a primary use case of this tool so do it and hope for the best... |
| 152 | + # |
| 153 | + server_name = self.wlst_helper.get_quoted_name_for_wlst(server_names[0]) |
| 154 | + self.wlst_helper.set_server_groups(server_name, server_groups_to_target) |
| 155 | + |
| 156 | + # might want to replace this later with |
| 157 | + self.wlst_helper.update_domain() |
| 158 | + self.wlst_helper.close_domain() |
| 159 | + self.logger.exiting(class_name=self.__class_name, method_name=_method_name) |
| 160 | + return |
| 161 | + |
| 162 | + def get_clusters_and_members_map(self): |
120 | 163 | """ |
121 | 164 | Get a map keyed by cluster name with values that are a list of member server names |
122 | 165 | :return: the cluster name to member server names map |
@@ -148,6 +191,21 @@ def _get_clusters_and_members_map(self): |
148 | 191 | self.logger.exiting(class_name=self.__class_name, method_name=_method_name, result=cluster_map) |
149 | 192 | return cluster_map |
150 | 193 |
|
| 194 | + def get_existing_server_names(self): |
| 195 | + """ |
| 196 | + Get the list of server names from WLST. |
| 197 | + :return: the list of server names |
| 198 | + :raises: BundleAwareException of the specified type: is an error occurs reading from the aliases or WLST |
| 199 | + """ |
| 200 | + _method_name = '_get_existing_server_names' |
| 201 | + |
| 202 | + self.logger.entering(class_name=self.__class_name, method_name=_method_name) |
| 203 | + server_location = LocationContext().append_location(SERVER) |
| 204 | + server_list_path = self.alias_helper.get_wlst_list_path(server_location) |
| 205 | + result = self.wlst_helper.get_existing_object_list(server_list_path) |
| 206 | + self.logger.exiting(class_name=self.__class_name, method_name=_method_name, result=result) |
| 207 | + return result |
| 208 | + |
151 | 209 | def _get_server_group_targeting_limits(self, server_group_targeting_limits, clusters_map): |
152 | 210 | """ |
153 | 211 | Get any server group targeting limits specified in the model, converting any cluster |
|
0 commit comments