|
| 1 | +/* |
| 2 | + * Copyright (c) 2018, Matias Fontanini |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are |
| 7 | + * met: |
| 8 | + * |
| 9 | + * * Redistributions of source code must retain the above copyright |
| 10 | + * notice, this list of conditions and the following disclaimer. |
| 11 | + * * Redistributions in binary form must reproduce the above |
| 12 | + * copyright notice, this list of conditions and the following disclaimer |
| 13 | + * in the documentation and/or other materials provided with the |
| 14 | + * distribution. |
| 15 | + * |
| 16 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | + * |
| 28 | + */ |
| 29 | + |
| 30 | +#ifndef CPPKAFKA_ADMIN_ALTER_CONFIGS_OPERATION_H |
| 31 | +#define CPPKAFKA_ADMIN_ALTER_CONFIGS_OPERATION_H |
| 32 | + |
| 33 | +#include <memory> |
| 34 | +#include "compound_operation.h" |
| 35 | +#include "operation.h" |
| 36 | +#include "../configuration_option.h" |
| 37 | + |
| 38 | +#if RD_KAFKA_VERSION >= RD_KAFKA_ADMIN_API_SUPPORT_VERSION |
| 39 | + |
| 40 | +namespace cppkafka { |
| 41 | +namespace admin { |
| 42 | + |
| 43 | +/** |
| 44 | + * \brief Modifies the configuration for a cluster, broker or topic |
| 45 | + */ |
| 46 | +class AlterConfigsOperation : public Operation { |
| 47 | +public: |
| 48 | + /** |
| 49 | + * The rdkafka type used for this operation's handle |
| 50 | + */ |
| 51 | + using HandleType = rd_kafka_ConfigResource_t; |
| 52 | + |
| 53 | + /** |
| 54 | + * \brief Represents the resource type being modified |
| 55 | + */ |
| 56 | + enum class ResourceType { |
| 57 | + Unknown = RD_KAFKA_RESOURCE_UNKNOWN, |
| 58 | + Any = RD_KAFKA_RESOURCE_ANY, |
| 59 | + Topic = RD_KAFKA_RESOURCE_TOPIC, |
| 60 | + Group = RD_KAFKA_RESOURCE_GROUP, |
| 61 | + Broker = RD_KAFKA_RESOURCE_BROKER |
| 62 | + }; |
| 63 | + |
| 64 | + /** |
| 65 | + * \brief Constructs an alter configs operation |
| 66 | + * |
| 67 | + * The name depends on the type being used. For example, when modifying a topic |
| 68 | + * type, this will be the name of the topic to be modifies. |
| 69 | + * |
| 70 | + * See KIP-133 for more information. |
| 71 | + * |
| 72 | + * \param type The type of the resource to be modified |
| 73 | + * \param name The name of the resource to be modified |
| 74 | + */ |
| 75 | + AlterConfigsOperation(ResourceType type, const std::string& name); |
| 76 | + |
| 77 | + /** |
| 78 | + * \brief Sets a config option |
| 79 | + * |
| 80 | + * \param config_option The configuration option to be set |
| 81 | + */ |
| 82 | + void set_config(const ConfigurationOption& config_option); |
| 83 | + |
| 84 | + /** |
| 85 | + * \brief Removes a configuration option. |
| 86 | + * |
| 87 | + * Note that this implies removing it from the server side, not on list |
| 88 | + * of configs added to this alter configs operation via AlterConfigsOperation::set_config |
| 89 | + * |
| 90 | + * \param key The config key to be removed |
| 91 | + */ |
| 92 | + void remove_config(const std::string& key); |
| 93 | +private: |
| 94 | + using HandlePtr = std::unique_ptr<HandleType, |
| 95 | + decltype(&rd_kafka_ConfigResource_destroy)>; |
| 96 | + |
| 97 | + void do_execute(KafkaHandleBase& kafka_handle, |
| 98 | + Queue& queue, |
| 99 | + const OperationOptions* options) override; |
| 100 | + |
| 101 | + HandlePtr handle_; |
| 102 | +}; |
| 103 | + |
| 104 | +/** |
| 105 | + * \brief Alters the config for multiple resources |
| 106 | + */ |
| 107 | +using CompoundAlterConfigsOperation = CompoundOperation<AlterConfigsOperation, |
| 108 | + &rd_kafka_AlterConfigs>; |
| 109 | + |
| 110 | +} // admin |
| 111 | +} // cppkafka |
| 112 | + |
| 113 | +#endif // Admin API |
| 114 | + |
| 115 | +#endif // CPPKAFKA_ADMIN_ALTER_CONFIGS_OPERATION_H |
0 commit comments