Jonathan Hart | 501f788 | 2018-07-24 14:39:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.opencord.kafka.impl; |
| 18 | |
| 19 | import org.onosproject.core.ApplicationId; |
| 20 | import org.onosproject.net.config.Config; |
| 21 | |
| 22 | /** |
| 23 | * Configuration of the Kafka publishing endpoint. |
| 24 | */ |
| 25 | public class KafkaConfig extends Config<ApplicationId> { |
| 26 | |
| 27 | private static final String BOOTSTRAP_SERVERS = "bootstrapServers"; |
| 28 | private static final String RETRIES = "retries"; |
| 29 | private static final String RECONNECT_BACKOFF = "reconnectBackoff"; |
| 30 | private static final String INFLIGHT_REQUESTS = "inflightRequests"; |
| 31 | private static final String ACKS = "acks"; |
| 32 | |
| 33 | private static final String DEFAULT_RETRIES = "1"; |
| 34 | private static final String DEFAULT_RECONNECT_BACKOFF = "500"; |
| 35 | private static final String DEFAULT_INFLIGHT_REQUESTS = "5"; |
| 36 | private static final String DEFAULT_ACKS = "1"; |
| 37 | |
| 38 | @Override |
| 39 | public boolean isValid() { |
| 40 | return hasOnlyFields(BOOTSTRAP_SERVERS, RETRIES, RECONNECT_BACKOFF, |
| 41 | INFLIGHT_REQUESTS, ACKS) && hasFields(BOOTSTRAP_SERVERS); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Returns the Kafka bootstrap servers. |
| 46 | * <p> |
| 47 | * This can be a hostname/IP and port (e.g. 10.1.1.1:9092). |
| 48 | * </p> |
| 49 | * |
| 50 | * @return Kafka bootstrap servers |
| 51 | */ |
| 52 | public String getBootstrapServers() { |
| 53 | return object.path(BOOTSTRAP_SERVERS).asText(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the number of retries. |
| 58 | * |
| 59 | * @return retries |
| 60 | */ |
| 61 | public String getRetries() { |
| 62 | return get(RETRIES, DEFAULT_RETRIES); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns the reconnect backoff in milliseconds. |
| 67 | * |
| 68 | * @return reconnect backoff |
| 69 | */ |
| 70 | public String getReconnectBackoff() { |
| 71 | return get(RECONNECT_BACKOFF, DEFAULT_RECONNECT_BACKOFF); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns the number of inflight requests. |
| 76 | * |
| 77 | * @return inflight requests |
| 78 | */ |
| 79 | public String getInflightRequests() { |
| 80 | return get(INFLIGHT_REQUESTS, DEFAULT_INFLIGHT_REQUESTS); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Returns the number of acks. |
| 85 | * |
| 86 | * @return acks |
| 87 | */ |
| 88 | public String getAcks() { |
| 89 | return get(ACKS, DEFAULT_ACKS); |
| 90 | } |
| 91 | } |