|
17 | 17 |
|
18 | 18 | package org.apache.seatunnel.connectors.seatunnel.cassandra.config;
|
19 | 19 |
|
20 |
| -import org.apache.seatunnel.shade.com.typesafe.config.Config; |
| 20 | +import org.apache.seatunnel.api.configuration.Option; |
| 21 | +import org.apache.seatunnel.api.configuration.Options; |
21 | 22 |
|
22 |
| -import com.datastax.oss.driver.api.core.ConsistencyLevel; |
23 |
| -import com.datastax.oss.driver.api.core.DefaultConsistencyLevel; |
24 |
| -import com.datastax.oss.driver.api.core.cql.DefaultBatchType; |
25 |
| -import lombok.Data; |
26 |
| -import lombok.NoArgsConstructor; |
27 |
| -import lombok.NonNull; |
28 |
| -import lombok.ToString; |
| 23 | +public class CassandraConfig { |
29 | 24 |
|
30 |
| -import java.io.Serializable; |
31 |
| -import java.util.List; |
| 25 | + public static final Integer DEFAULT_BATCH_SIZE = 5000; |
32 | 26 |
|
33 |
| -@Data |
34 |
| -@ToString |
35 |
| -@NoArgsConstructor |
36 |
| -public class CassandraConfig implements Serializable { |
| 27 | + public static final Option<String> HOST = |
| 28 | + Options.key("host").stringType().noDefaultValue().withDescription(""); |
37 | 29 |
|
38 |
| - public static final String HOST = "host"; |
39 |
| - public static final String USERNAME = "username"; |
40 |
| - public static final String PASSWORD = "password"; |
41 |
| - public static final String DATACENTER = "datacenter"; |
42 |
| - public static final String KEYSPACE = "keyspace"; |
43 |
| - public static final String TABLE = "table"; |
44 |
| - public static final String CQL = "cql"; |
45 |
| - public static final String FIELDS = "fields"; |
46 |
| - public static final String CONSISTENCY_LEVEL = "consistency_level"; |
47 |
| - public static final String BATCH_SIZE = "batch_size"; |
48 |
| - public static final String BATCH_TYPE = "batch_type"; |
49 |
| - public static final String ASYNC_WRITE = "async_write"; |
| 30 | + public static final Option<String> KEYSPACE = |
| 31 | + Options.key("keyspace").stringType().noDefaultValue().withDescription(""); |
50 | 32 |
|
51 |
| - private String host; |
52 |
| - private String username; |
53 |
| - private String password; |
54 |
| - private String datacenter; |
55 |
| - private String keyspace; |
56 |
| - private String table; |
57 |
| - private String cql; |
58 |
| - private List<String> fields; |
59 |
| - private ConsistencyLevel consistencyLevel; |
60 |
| - private Integer batchSize; |
61 |
| - private DefaultBatchType batchType; |
62 |
| - private Boolean asyncWrite; |
| 33 | + public static final Option<String> USERNAME = |
| 34 | + Options.key("username").stringType().noDefaultValue().withDescription(""); |
| 35 | + public static final Option<String> PASSWORD = |
| 36 | + Options.key("password").stringType().noDefaultValue().withDescription(""); |
| 37 | + public static final Option<String> DATACENTER = |
| 38 | + Options.key("datacenter").stringType().defaultValue("datacenter1").withDescription(""); |
63 | 39 |
|
64 |
| - public CassandraConfig(@NonNull String host, @NonNull String keyspace) { |
65 |
| - this.host = host; |
66 |
| - this.keyspace = keyspace; |
67 |
| - } |
| 40 | + public static final Option<String> CONSISTENCY_LEVEL = |
| 41 | + Options.key("consistency_level") |
| 42 | + .stringType() |
| 43 | + .defaultValue("LOCAL_ONE") |
| 44 | + .withDescription(""); |
68 | 45 |
|
69 |
| - public static CassandraConfig getCassandraConfig(Config config) { |
70 |
| - CassandraConfig cassandraConfig = |
71 |
| - new CassandraConfig(config.getString(HOST), config.getString(KEYSPACE)); |
72 |
| - if (config.hasPath(USERNAME)) { |
73 |
| - cassandraConfig.setUsername(config.getString(USERNAME)); |
74 |
| - } |
75 |
| - if (config.hasPath(PASSWORD)) { |
76 |
| - cassandraConfig.setPassword(config.getString(PASSWORD)); |
77 |
| - } |
78 |
| - if (config.hasPath(DATACENTER)) { |
79 |
| - cassandraConfig.setDatacenter(config.getString(DATACENTER)); |
80 |
| - } else { |
81 |
| - cassandraConfig.setDatacenter("datacenter1"); |
82 |
| - } |
83 |
| - if (config.hasPath(TABLE)) { |
84 |
| - cassandraConfig.setTable(config.getString(TABLE)); |
85 |
| - } |
86 |
| - if (config.hasPath(CQL)) { |
87 |
| - cassandraConfig.setCql(config.getString(CQL)); |
88 |
| - } |
89 |
| - if (config.hasPath(FIELDS)) { |
90 |
| - cassandraConfig.setFields(config.getStringList(FIELDS)); |
91 |
| - } |
92 |
| - if (config.hasPath(CONSISTENCY_LEVEL)) { |
93 |
| - cassandraConfig.setConsistencyLevel( |
94 |
| - DefaultConsistencyLevel.valueOf(config.getString(CONSISTENCY_LEVEL))); |
95 |
| - } else { |
96 |
| - cassandraConfig.setConsistencyLevel(DefaultConsistencyLevel.LOCAL_ONE); |
97 |
| - } |
98 |
| - if (config.hasPath(BATCH_SIZE)) { |
99 |
| - cassandraConfig.setBatchSize(config.getInt(BATCH_SIZE)); |
100 |
| - } else { |
101 |
| - cassandraConfig.setBatchSize(Integer.parseInt("5000")); |
102 |
| - } |
103 |
| - if (config.hasPath(BATCH_TYPE)) { |
104 |
| - cassandraConfig.setBatchType(DefaultBatchType.valueOf(config.getString(BATCH_TYPE))); |
105 |
| - } else { |
106 |
| - cassandraConfig.setBatchType(DefaultBatchType.UNLOGGED); |
107 |
| - } |
108 |
| - if (config.hasPath(ASYNC_WRITE)) { |
109 |
| - cassandraConfig.setAsyncWrite(config.getBoolean(ASYNC_WRITE)); |
110 |
| - } else { |
111 |
| - cassandraConfig.setAsyncWrite(true); |
112 |
| - } |
113 |
| - return cassandraConfig; |
114 |
| - } |
| 46 | + public static final Option<String> TABLE = |
| 47 | + Options.key("table").stringType().noDefaultValue().withDescription(""); |
| 48 | + |
| 49 | + public static final Option<String> FIELDS = |
| 50 | + Options.key("fields").stringType().defaultValue("LOCAL_ONE").withDescription(""); |
| 51 | + |
| 52 | + public static final Option<Integer> BATCH_SIZE = |
| 53 | + Options.key("batch_size") |
| 54 | + .intType() |
| 55 | + .defaultValue(DEFAULT_BATCH_SIZE) |
| 56 | + .withDescription(""); |
| 57 | + |
| 58 | + public static final Option<String> BATCH_TYPE = |
| 59 | + Options.key("batch_type").stringType().defaultValue("UNLOGGED").withDescription(""); |
| 60 | + |
| 61 | + public static final Option<Boolean> ASYNC_WRITE = |
| 62 | + Options.key("async_write").booleanType().defaultValue(true).withDescription(""); |
| 63 | + |
| 64 | + public static final Option<String> CQL = |
| 65 | + Options.key("cql").stringType().noDefaultValue().withDescription(""); |
115 | 66 | }
|
0 commit comments