|
1 | 1 | /**
|
2 | 2 | * Copyright 2018 Bikas Katwal.
|
3 | 3 | *
|
4 |
| - * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 |
| - * use this file except in compliance with the License. You may obtain a copy of |
6 |
| - * the License at |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
7 | 6 | *
|
8 | 7 | * http://www.apache.org/licenses/LICENSE-2.0
|
9 | 8 | *
|
10 |
| - * Unless required by applicable law or agreed to in writing, software |
11 |
| - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 |
| - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 |
| - * License for the specific language governing permissions and limitations under |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
14 | 12 | * the License.
|
15 | 13 | **/
|
16 | 14 |
|
17 | 15 | package com.bkatwal.kafkaproject;
|
18 | 16 |
|
| 17 | +import com.bkatwal.kafkaproject.utils.SolrMode; |
| 18 | +import java.util.Map; |
19 | 19 | import org.apache.kafka.common.config.AbstractConfig;
|
20 | 20 | import org.apache.kafka.common.config.ConfigDef;
|
21 | 21 | import org.apache.kafka.common.config.ConfigDef.Importance;
|
22 | 22 | import org.apache.kafka.common.config.ConfigDef.Type;
|
23 | 23 |
|
24 |
| -import java.util.Map; |
25 |
| - |
26 | 24 |
|
27 | 25 | public class SolrSinkConnectorConfig extends AbstractConfig {
|
28 | 26 |
|
29 |
| - private static final String TOPIC_DOC = "Topic from where data needs to be read."; |
| 27 | + public static final String COLLECTION_CONFIG = "solr.collection"; |
| 28 | + private static final String COLLECTION_DOC = "Solr Collection name to which data need to be be written"; |
| 29 | + |
| 30 | + public static final String SOLRURL_CONFIG = "solr.url"; |
| 31 | + private static final String SOLRURL_DOC = |
| 32 | + "Comma separated zookeeper hosts, eg: localhost:2181,localhost:2182,localhost:2183" + |
| 33 | + " or it could be standalone solr mode too, ex: localhost:8983/solr"; |
| 34 | + |
| 35 | + public static final String USERNAME_CONFIG = "solr.username"; |
| 36 | + private static final String USERNAME_DOC = "username to connect to solr."; |
30 | 37 |
|
31 |
| - public static final String COLLECTION_CONFIG = "solr.collection"; |
32 |
| - private static final String COLLECTION_DOC = "Solr Collection name to which data need to be be written"; |
| 38 | + public static final String PASSWORD_CONFIG = "solr.password"; |
| 39 | + private static final String PASSWORD_DOC = "password to connect to solr."; |
33 | 40 |
|
34 |
| - public static final String ZKHOSTS_CONFIG = "solr.zkhosts"; |
35 |
| - private static final String ZKHOSTS_DOC = "Comma separated zookeeper hosts, eg: localhost:2181,localhost:2182,localhost:2183"; |
| 41 | + public static final String COMMIT_WITHIN_MS = "commit.within.ms"; |
| 42 | + private static final String COMMIT_WITHIN_MS_DOC = "solr commit within milli seconds param."; |
36 | 43 |
|
37 |
| - public static final String USERNAME_CONFIG = "solr.username"; |
38 |
| - private static final String USERNAME_DOC = "username to connect to solr."; |
| 44 | + public static final String SOLRMODE_CONFIG = "solr.mode"; |
| 45 | + private static final String SOLRMODE_DOC = "solr mode can be STANDALONE/CLOUD"; |
39 | 46 |
|
40 |
| - public static final String PASSWORD_CONFIG = "solr.password"; |
41 |
| - private static final String PASSWORD_DOC = "password to connect to solr."; |
42 | 47 |
|
| 48 | + public SolrSinkConnectorConfig(ConfigDef config, Map<String, String> parsedConfig) { |
| 49 | + super(config, parsedConfig); |
| 50 | + } |
43 | 51 |
|
44 |
| - public SolrSinkConnectorConfig(ConfigDef config, Map<String, String> parsedConfig) { |
45 |
| - super(config, parsedConfig); |
46 |
| - } |
| 52 | + public SolrSinkConnectorConfig(Map<String, String> parsedConfig) { |
| 53 | + this(conf(), parsedConfig); |
| 54 | + } |
47 | 55 |
|
48 |
| - public SolrSinkConnectorConfig(Map<String, String> parsedConfig) { |
49 |
| - this(conf(), parsedConfig); |
50 |
| - } |
| 56 | + public static ConfigDef conf() { |
| 57 | + return new ConfigDef() |
| 58 | + .define(COLLECTION_CONFIG, Type.STRING, Importance.HIGH, COLLECTION_DOC) |
| 59 | + .define(SOLRURL_CONFIG, Type.STRING, Importance.HIGH, SOLRURL_DOC) |
| 60 | + .define(USERNAME_CONFIG, Type.STRING, "", Importance.MEDIUM, USERNAME_DOC) |
| 61 | + .define(PASSWORD_CONFIG, Type.PASSWORD, "", Importance.MEDIUM, PASSWORD_DOC) |
| 62 | + .define(SOLRMODE_CONFIG, Type.STRING, "", Importance.MEDIUM, SOLRMODE_DOC) |
| 63 | + .define(COMMIT_WITHIN_MS, Type.INT, 10, Importance.MEDIUM, COMMIT_WITHIN_MS_DOC); |
| 64 | + } |
51 | 65 |
|
52 |
| - public static ConfigDef conf() { |
53 |
| - return new ConfigDef() |
54 |
| - .define(COLLECTION_CONFIG, Type.STRING, Importance.HIGH, COLLECTION_DOC) |
55 |
| - .define(ZKHOSTS_CONFIG, Type.STRING, Importance.HIGH, ZKHOSTS_DOC) |
56 |
| - .define(USERNAME_CONFIG, Type.STRING, "", Importance.MEDIUM, USERNAME_DOC) |
57 |
| - .define(PASSWORD_CONFIG, Type.PASSWORD, "", Importance.MEDIUM, PASSWORD_DOC); |
58 |
| - } |
59 | 66 |
|
| 67 | + public String getCollectionConfig() { |
| 68 | + return this.getString(COLLECTION_CONFIG); |
| 69 | + } |
60 | 70 |
|
61 |
| - public String getCollectionConfig() { |
62 |
| - return this.getString(COLLECTION_CONFIG); |
63 |
| - } |
64 | 71 |
|
| 72 | + public String getSolrURLConfig() { |
| 73 | + return this.getString(SOLRURL_CONFIG); |
| 74 | + } |
65 | 75 |
|
66 |
| - public String getZkhostsConfig() { |
67 |
| - return this.getString(ZKHOSTS_CONFIG); |
68 |
| - } |
69 | 76 |
|
| 77 | + public String getUsernameConfig() { |
| 78 | + return this.getString(USERNAME_CONFIG); |
| 79 | + } |
70 | 80 |
|
71 |
| - public String getUsernameConfig() { |
72 |
| - return this.getString(USERNAME_CONFIG); |
73 |
| - } |
74 | 81 |
|
| 82 | + public String getPasswordConfig() { |
| 83 | + return this.getString(PASSWORD_CONFIG); |
| 84 | + } |
75 | 85 |
|
76 |
| - public String getPasswordConfig() { |
77 |
| - return this.getString(PASSWORD_CONFIG); |
78 |
| - } |
| 86 | + public SolrMode getSolrModeConfig() { |
| 87 | + return SolrMode.valueOf(this.getString(SOLRMODE_CONFIG)); |
| 88 | + } |
79 | 89 |
|
| 90 | + public int getCommitWithinMs(){ |
| 91 | + return getInt(COMMIT_WITHIN_MS); |
| 92 | + } |
80 | 93 | }
|
0 commit comments