Skip to content

Commit 4325212

Browse files
author
Ryan P
authored
Remove incremental updates (confluentinc#425)
1 parent 2f9187a commit 4325212

File tree

4 files changed

+45
-152
lines changed

4 files changed

+45
-152
lines changed

confluent_kafka/admin/__init__.py

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -103,27 +103,14 @@ class Type(Enum):
103103
BROKER = RESOURCE_BROKER #: Broker resource. Resource name is broker id
104104

105105
def __init__(self, restype, name,
106-
set_config=None, add_config=None, del_config=None,
107-
described_configs=None, error=None):
106+
set_config=None, described_configs=None, error=None):
108107
"""
109108
:param ConfigResource.Type restype: Resource type.
110109
:param str name: Resource name, depending on restype.
111110
For RESOURCE_BROKER the resource name is the broker id.
112111
:param dict set_config: Configuration to set/overwrite. Dict of str, str.
113-
:param dict add_config: Configuration to add/append. Dict of str, str.
114-
Requires broker version with KIP-248 support.
115-
:param list del_config: Configuration to delete/revert to default. List of str.
116-
Requires broker version with KIP-248 support.
117112
:param dict described_configs: For internal use only.
118113
:param KafkaError error: For internal use only.
119-
120-
When alter_configs(incremental=False) only set_config is permitted,
121-
and any configuration parameter not specified will be reverted to
122-
its default value.
123-
124-
With alter_configs(incremental=True) (requires broker version with KIP-248 support)
125-
only the configuration parameters specified through set, add or del
126-
will be modified.
127114
"""
128115
super(ConfigResource, self).__init__()
129116

@@ -150,16 +137,6 @@ def __init__(self, restype, name,
150137
else:
151138
self.set_config_dict = dict()
152139

153-
if add_config is not None:
154-
self.add_config_dict = add_config.copy()
155-
else:
156-
self.add_config_dict = dict()
157-
158-
if del_config is not None:
159-
self.del_config_dict = dict((k, None) for k in del_config)
160-
else:
161-
self.del_config_dict = dict()
162-
163140
self.configs = described_configs
164141
self.error = error
165142

@@ -185,16 +162,15 @@ def __len__(self):
185162
:rtype: int
186163
:returns: number of configuration entries/operations
187164
"""
188-
return len(self.add_config_dict) + len(self.set_config_dict) + len(self.del_config_dict)
165+
return len(self.set_config_dict)
189166

190167
def set_config(self, name, value, overwrite=True):
191168
"""
192169
Set/Overwrite configuration entry
193170
194-
Unless alter_configs() is called with `incremental=True` any configuration properties
195-
that are not included will be reverted to their default values.
196-
As a workaround use describe_configs() to retrieve the current
197-
configuration and overwrite the settings you want to change.
171+
Any configuration properties that are not included will be reverted to their default values.
172+
As a workaround use describe_configs() to retrieve the current configuration and
173+
overwrite the settings you want to change.
198174
199175
:param str name: Configuration property name
200176
:param str value: Configuration value
@@ -205,27 +181,6 @@ def set_config(self, name, value, overwrite=True):
205181
return
206182
self.set_config_dict[name] = value
207183

208-
def add_config(self, name, value):
209-
"""
210-
Append value to configuration entry.
211-
212-
Requires broker version with KIP-248 support and alter_configs(.., incremental=True).
213-
214-
:param str name: Configuration property name
215-
:param str value: Configuration value
216-
"""
217-
self.add_config_dict[name] = value
218-
219-
def del_config(self, name):
220-
"""
221-
Delete configuration entry, reverting it to the default value.
222-
223-
Requires broker version with KIP-248 support and alter_configs(.., incremental=True).
224-
225-
:param str name: Configuration property name
226-
"""
227-
self.del_config_dict[name] = None
228-
229184

230185
class AdminClient (_AdminClientImpl):
231186
"""
@@ -478,8 +433,6 @@ def alter_configs(self, resources, **kwargs):
478433
the provided resources with the new configuration given,
479434
reverting all other configuration for the resource back
480435
to their default values.
481-
Use incremental=True to change the behaviour so that only the
482-
passed configuration is modified, requires broker version with KIP-248 support.
483436
484437
:warning: Multiple resources and resource types may be specified,
485438
but at most one resource of type RESOURCE_BROKER is allowed
@@ -492,9 +445,6 @@ def alter_configs(self, resources, **kwargs):
492445
on broker, and response. Default: `socket.timeout.ms*1000.0`.
493446
:param bool validate_only: Tell broker to only validate the request,
494447
without altering the configuration. Default: False
495-
:param bool incremental: If true, only update the specified configuration
496-
entries, not reverting unspecified configuration.
497-
This requires broker version with KIP-248 support. Default: False
498448
499449
:returns: a dict of futures for each resource, keyed by the ConfigResource.
500450
:rtype: dict(<ConfigResource, future>)

confluent_kafka/src/Admin.c

Lines changed: 37 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ struct Admin_options {
7575
float request_timeout; /* parser: f */
7676
float operation_timeout; /* parser: f */
7777
int broker; /* parser: i */
78-
int incremental; /* needs special bool parsing */
7978
};
8079

8180
/**@brief "unset" value initializers for Admin_options
8281
* Make sure this is kept up to date with Admin_options above. */
8382
#define Admin_options_INITIALIZER { \
8483
Admin_options_def_int, Admin_options_def_float, \
8584
Admin_options_def_float, Admin_options_def_int, \
86-
Admin_options_def_int, \
8785
}
8886

8987
#define Admin_options_is_set_int(v) ((v) != Admin_options_def_int)
@@ -143,12 +141,6 @@ Admin_options_to_c (Handle *self, rd_kafka_admin_op_t for_api,
143141
errstr, sizeof(errstr))))
144142
goto err;
145143

146-
if (Admin_options_is_set_int(options->incremental) &&
147-
(err = rd_kafka_AdminOptions_set_incremental(
148-
c_options, options->incremental,
149-
errstr, sizeof(errstr))))
150-
goto err;
151-
152144
return c_options;
153145

154146
err:
@@ -250,7 +242,7 @@ static int Admin_set_replica_assignment (const char *forApi, void *c_obj,
250242
}
251243

252244
/**
253-
* @brief Translate a dict to ConfigResource {set,add,delete}_config() calls,
245+
* @brief Translate a dict to ConfigResource set_config() calls,
254246
* or to NewTopic_add_config() calls.
255247
*
256248
*
@@ -276,52 +268,44 @@ Admin_config_dict_to_c (void *c_obj, PyObject *dict, const char *op_name) {
276268

277269
k = cfl_PyUnistr_AsUTF8(ks, &ks8);
278270

279-
if (!strcmp(op_name, "del_config")) {
280-
err = rd_kafka_ConfigResource_delete_config(
281-
(rd_kafka_ConfigResource_t *)c_obj, k);
282-
} else {
283-
PyObject *vs = NULL, *vs8 = NULL;
284-
if (!(vs = cfl_PyObject_Unistr(vo)) ||
285-
!(v = cfl_PyUnistr_AsUTF8(vs, &vs8))) {
286-
PyErr_Format(PyExc_ValueError,
287-
"expect %s config value for %s "
288-
"to be unicode string",
289-
op_name, k);
290-
Py_XDECREF(vs);
291-
Py_XDECREF(vs8);
292-
Py_DECREF(ks);
293-
Py_XDECREF(ks8);
294-
return 0;
295-
}
296271

297-
if (!strcmp(op_name, "add_config"))
298-
err = rd_kafka_ConfigResource_add_config(
299-
(rd_kafka_ConfigResource_t *)c_obj,
300-
k, v);
301-
else if (!strcmp(op_name, "set_config"))
302-
err = rd_kafka_ConfigResource_set_config(
303-
(rd_kafka_ConfigResource_t *)c_obj,
304-
k, v);
305-
else if (!strcmp(op_name, "newtopic_set_config"))
306-
err = rd_kafka_NewTopic_set_config(
307-
(rd_kafka_NewTopic_t *)c_obj, k, v);
308-
else
309-
err = RD_KAFKA_RESP_ERR__NOT_IMPLEMENTED;
310-
311-
if (err) {
312-
PyErr_Format(PyExc_ValueError,
313-
"%s config %s failed: %s",
314-
op_name, k, rd_kafka_err2str(err));
315-
Py_XDECREF(vs);
316-
Py_XDECREF(vs8);
317-
Py_DECREF(ks);
318-
Py_XDECREF(ks8);
319-
return 0;
320-
}
272+
PyObject *vs = NULL, *vs8 = NULL;
273+
if (!(vs = cfl_PyObject_Unistr(vo)) ||
274+
!(v = cfl_PyUnistr_AsUTF8(vs, &vs8))) {
275+
PyErr_Format(PyExc_ValueError,
276+
"expect %s config value for %s "
277+
"to be unicode string",
278+
op_name, k);
279+
Py_XDECREF(vs);
280+
Py_XDECREF(vs8);
281+
Py_DECREF(ks);
282+
Py_XDECREF(ks8);
283+
return 0;
284+
}
285+
286+
if (!strcmp(op_name, "set_config"))
287+
err = rd_kafka_ConfigResource_set_config(
288+
(rd_kafka_ConfigResource_t *)c_obj,
289+
k, v);
290+
else if (!strcmp(op_name, "newtopic_set_config"))
291+
err = rd_kafka_NewTopic_set_config(
292+
(rd_kafka_NewTopic_t *)c_obj, k, v);
293+
else
294+
err = RD_KAFKA_RESP_ERR__NOT_IMPLEMENTED;
321295

296+
if (err) {
297+
PyErr_Format(PyExc_ValueError,
298+
"%s config %s failed: %s",
299+
op_name, k, rd_kafka_err2str(err));
322300
Py_XDECREF(vs);
323301
Py_XDECREF(vs8);
302+
Py_DECREF(ks);
303+
Py_XDECREF(ks8);
304+
return 0;
324305
}
306+
307+
Py_XDECREF(vs);
308+
Py_XDECREF(vs8);
325309
Py_DECREF(ks);
326310
Py_XDECREF(ks8);
327311
}
@@ -835,14 +819,13 @@ static PyObject *Admin_describe_configs (Handle *self, PyObject *args,
835819
static PyObject *Admin_alter_configs (Handle *self, PyObject *args,
836820
PyObject *kwargs) {
837821
PyObject *resources, *future;
838-
PyObject *validate_only_obj = NULL, *incremental_obj = NULL;
822+
PyObject *validate_only_obj = NULL;
839823
static char *kws[] = { "resources",
840824
"future",
841825
/* options */
842826
"validate_only",
843827
"request_timeout",
844828
"broker",
845-
"incremental",
846829
NULL };
847830
struct Admin_options options = Admin_options_INITIALIZER;
848831
rd_kafka_AdminOptions_t *c_options = NULL;
@@ -853,12 +836,11 @@ static PyObject *Admin_alter_configs (Handle *self, PyObject *args,
853836
CallState cs;
854837

855838
/* topics is a list of NewPartitions_t objects. */
856-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|OfiO", kws,
839+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|Ofi", kws,
857840
&resources, &future,
858841
&validate_only_obj,
859842
&options.request_timeout,
860-
&options.broker,
861-
&incremental_obj))
843+
&options.broker))
862844
return NULL;
863845

864846
if (!PyList_Check(resources) ||
@@ -874,12 +856,6 @@ static PyObject *Admin_alter_configs (Handle *self, PyObject *args,
874856
&options.validate_only))
875857
return NULL;
876858

877-
if (incremental_obj &&
878-
!cfl_PyBool_get(incremental_obj, "incremental",
879-
&options.incremental))
880-
return NULL;
881-
882-
883859
c_options = Admin_options_to_c(self, RD_KAFKA_ADMIN_OP_ALTERCONFIGS,
884860
&options, future);
885861
if (!c_options)
@@ -955,30 +931,6 @@ static PyObject *Admin_alter_configs (Handle *self, PyObject *args,
955931
goto err;
956932
}
957933
Py_DECREF(dict);
958-
959-
if (!cfl_PyObject_GetAttr(res, "add_config_dict", &dict,
960-
&PyDict_Type, 1)) {
961-
i++;
962-
goto err;
963-
}
964-
if (!Admin_config_dict_to_c(c_objs[i], dict, "add_config")) {
965-
Py_DECREF(dict);
966-
i++;
967-
goto err;
968-
}
969-
Py_DECREF(dict);
970-
971-
if (!cfl_PyObject_GetAttr(res, "del_config_dict", &dict,
972-
&PyDict_Type, 1)) {
973-
i++;
974-
goto err;
975-
}
976-
if (!Admin_config_dict_to_c(c_objs[i], dict, "del_config")) {
977-
Py_DECREF(dict);
978-
i++;
979-
goto err;
980-
}
981-
Py_DECREF(dict);
982934
}
983935

984936

examples/adminapi.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,8 @@ def example_alter_configs(a, args):
143143

144144
def example_delta_alter_configs(a, args):
145145
"""
146-
Alter only supplied configs (pre incremental/KIP-248)
147-
148-
The pre incremental/KIP-248 AlterConfigs Kafka API requires all
149-
configuration to be passed, any left out configuration properties will
150-
revert to their default settings.
146+
The AlterConfigs Kafka API requires all configuration to be passed,
147+
any left out configuration properties will revert to their default settings.
151148
152149
This example shows how to just modify the supplied configuration entries
153150
by first reading the configuration from the broker, updating the supplied

tests/test_Admin.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,9 @@ def test_alter_configs_api():
244244
with pytest.raises(ValueError):
245245
a.alter_configs([])
246246

247-
with pytest.raises(ValueError):
248-
a.alter_configs([None, ConfigResource("topic", "mytopic",
249-
add_config={"something": "else"})])
250-
251247
fs = a.alter_configs([ConfigResource("topic", "mytopic",
252248
set_config={"set": "this",
253-
"and": "this"},
254-
add_config={"add": "this"},
255-
del_config=["this"]),
249+
"and": "this"}),
256250
ConfigResource(confluent_kafka.admin.RESOURCE_GROUP,
257251
"mygroup")],
258252
request_timeout=0.123)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy