Skip to content

Commit

Permalink
Update to use ServiceConfigUpdates class to manage service-wide confi…
Browse files Browse the repository at this point in the history
…guration

Signed-off-by: Webster Mudge <[email protected]>
  • Loading branch information
wmudge committed Dec 16, 2024
1 parent 2063642 commit 06363d3
Showing 1 changed file with 26 additions and 41 deletions.
67 changes: 26 additions & 41 deletions plugins/modules/service_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright 2024 Cloudera, Inc. All Rights Reserved.
Expand All @@ -14,33 +15,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import json

from ansible_collections.cloudera.cluster.plugins.module_utils.cm_utils import (
ClouderaManagerMutableModule,
resolve_parameter_updates,
)

from cm_client import (
ApiConfig,
ApiServiceConfig,
ClustersResourceApi,
ServicesResourceApi,
)
from cm_client.rest import ApiException

ANSIBLE_METADATA = {
"metadata_version": "1.1",
"status": ["preview"],
"supported_by": "community",
}

DOCUMENTATION = r"""
---
module: service_config
short_description: Manage a service configuration in cluster
short_description: Manage a cluster service configuration
description:
- Manage a service configuration (service-wide) in a cluster.
- Manage a configuration (service-wide) for a cluster service.
author:
- "Webster Mudge (@wmudge)"
requirements:
Expand Down Expand Up @@ -216,6 +195,22 @@
returned: when supported
"""

import json

from ansible_collections.cloudera.cluster.plugins.module_utils.cm_utils import (
ClouderaManagerMutableModule,
)
from ansible_collections.cloudera.cluster.plugins.module_utils.service_utils import (
ServiceConfigUpdates,
)


from cm_client import (
ClustersResourceApi,
ServicesResourceApi,
)
from cm_client.rest import ApiException


class ClusterServiceConfig(ClouderaManagerMutableModule):
def __init__(self, module):
Expand Down Expand Up @@ -257,32 +252,22 @@ def process(self):
else:
raise ex

current = {r.name: r.value for r in existing.items}
incoming = {k: str(v) if v is not None else v for k, v in self.params.items()}

change_set = resolve_parameter_updates(current, incoming, self.purge)
updates = ServiceConfigUpdates(existing, self.params, self.purge)

if change_set:
if updates.changed:
self.changed = True

if self.module._diff:
self.diff = dict(
before={
k: current[k] if k in current else None
for k in change_set.keys()
},
after=change_set,
)
self.diff = updates.diff

if not self.module.check_mode:
body = ApiServiceConfig(
items=[ApiConfig(name=k, value=v) for k, v in change_set.items()]
)

self.config = [
p.to_dict()
for p in api_instance.update_service_config(
self.cluster, self.service, message=self.message, body=body
self.cluster,
self.service,
message=self.message,
body=updates.config,
).items
]

Expand Down

0 comments on commit 06363d3

Please sign in to comment.