or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration.mdexceptions.mdhttp.mdindex.mdio.mdlogging.mdnetwork.mdsecurity.mdservices.mdutilities.md

configuration.mddocs/

0

# Configuration Management

1

2

Centralized configuration system with hierarchical property management, secure configuration handling, and comprehensive constants for all CDAP settings.

3

4

## Capabilities

5

6

### Core Configuration Classes

7

8

Main configuration classes for managing CDAP settings and properties.

9

10

```java { .api }

11

/**

12

* Main configuration class for CDAP

13

*/

14

public class CConfiguration extends Configuration {

15

public static CConfiguration create();

16

public static CConfiguration create(Configuration baseConf);

17

18

public String get(String name);

19

public String get(String name, String defaultValue);

20

public int getInt(String name, int defaultValue);

21

public long getLong(String name, long defaultValue);

22

public boolean getBoolean(String name, boolean defaultValue);

23

public void set(String name, String value);

24

public void setInt(String name, int value);

25

public void setLong(String name, long value);

26

public void setBoolean(String name, boolean value);

27

}

28

29

/**

30

* Secure configuration management for sensitive data

31

*/

32

public class SConfiguration extends Configuration {

33

public static SConfiguration create();

34

public static SConfiguration create(Configuration baseConf);

35

36

public String get(String name);

37

public String get(String name, String defaultValue);

38

public void set(String name, String value);

39

}

40

```

41

42

**Usage Examples:**

43

44

```java

45

import io.cdap.cdap.common.conf.CConfiguration;

46

import io.cdap.cdap.common.conf.SConfiguration;

47

48

// Create and use CConfiguration

49

CConfiguration cConf = CConfiguration.create();

50

51

// Read configuration values

52

String appFabricHost = cConf.get(Constants.AppFabric.SERVER_ADDRESS, "localhost");

53

int appFabricPort = cConf.getInt(Constants.AppFabric.SERVER_PORT, 11015);

54

boolean sslEnabled = cConf.getBoolean(Constants.Security.SSL.EXTERNAL_ENABLED, false);

55

56

// Set configuration values

57

cConf.set("custom.property", "custom-value");

58

cConf.setInt("custom.port", 8080);

59

60

// Secure configuration for sensitive data

61

SConfiguration sConf = SConfiguration.create();

62

sConf.set("database.password", "secret-password");

63

String dbPassword = sConf.get("database.password");

64

```

65

66

### Configuration Constants

67

68

Central location for all CDAP configuration constants organized by functional area.

69

70

```java { .api }

71

/**

72

* Central location for all CDAP configuration constants

73

*/

74

public final class Constants {

75

76

/**

77

* Service names and configurations

78

*/

79

public static final class Service {

80

public static final String MASTER_SERVICES = "master.services";

81

public static final String APP_FABRIC_HTTP = "app.fabric.http";

82

public static final String DATASET_MANAGER = "dataset.service";

83

public static final String METRICS = "metrics";

84

public static final String METRICS_PROCESSOR = "metrics.processor";

85

public static final String LOGSAVER = "log.saver";

86

public static final String TRANSACTION = "transaction";

87

public static final String STREAMS = "streams";

88

}

89

90

/**

91

* Security-related constants

92

*/

93

public static final class Security {

94

public static final String ENABLED = "security.enabled";

95

public static final String AUTHORIZATION_ENABLED = "security.authorization.enabled";

96

97

public static final class SSL {

98

public static final String EXTERNAL_ENABLED = "security.server.ssl.enabled";

99

public static final String EXTERNAL_KEYSTORE_PATH = "security.server.ssl.keystore.path";

100

public static final String EXTERNAL_KEYSTORE_PASSWORD = "security.server.ssl.keystore.password";

101

public static final String EXTERNAL_KEYSTORE_TYPE = "security.server.ssl.keystore.type";

102

}

103

104

public static final class Authentication {

105

public static final String HANDLERCLASSNAME = "security.authentication.handlerClassName";

106

public static final String LOGINMODULE = "security.authentication.loginmodule.className";

107

}

108

109

public static final class Authorization {

110

public static final String EXTENSION_JAR_PATH = "security.authorization.extension.jar.path";

111

public static final String EXTENSION_EXTRA_CLASSPATH = "security.authorization.extension.extra.classpath";

112

}

113

}

114

115

/**

116

* Metrics configuration constants

117

*/

118

public static final class Metrics {

119

public static final String ADDRESS = "metrics.bind.address";

120

public static final String PORT = "metrics.bind.port";

121

public static final String RETENTION_SECONDS = "metrics.retention.seconds";

122

public static final String NUM_INSTANCES = "metrics.num.instances";

123

public static final String NUM_CORES = "metrics.num.cores";

124

public static final String MEMORY_MB = "metrics.memory.mb";

125

}

126

127

/**

128

* Dataset-related constants

129

*/

130

public static final class Dataset {

131

public static final String MANAGER_ADDRESS = "dataset.service.bind.address";

132

public static final String MANAGER_PORT = "dataset.service.bind.port";

133

public static final String EXECUTOR_ADDRESS = "dataset.executor.bind.address";

134

public static final String EXECUTOR_PORT = "dataset.executor.bind.port";

135

}

136

137

/**

138

* API versioning constants

139

*/

140

public static final class Gateway {

141

public static final String API_VERSION_3_TOKEN = "v3";

142

public static final String API_VERSION_3 = "/" + API_VERSION_3_TOKEN;

143

public static final String INTERNAL_API_VERSION_3_TOKEN = "v3Internal";

144

public static final String INTERNAL_API_VERSION_3 = "/" + INTERNAL_API_VERSION_3_TOKEN;

145

}

146

147

/**

148

* Router configuration

149

*/

150

public static final class Router {

151

public static final String ADDRESS = "router.bind.address";

152

public static final String BIND_PORT = "router.bind.port";

153

public static final String SERVER_BOSS_THREADS = "router.server.boss.threads";

154

public static final String SERVER_WORKER_THREADS = "router.server.worker.threads";

155

}

156

157

/**

158

* Logging configuration

159

*/

160

public static final class Logging {

161

public static final String COMPONENT_NAME = "component.name";

162

public static final String KAFKA_TOPIC = "kafka.topic";

163

}

164

165

/**

166

* Messaging system configuration

167

*/

168

public static final class MessagingSystem {

169

public static final String HTTP_SERVER_BIND_ADDRESS = "messaging.bind.address";

170

public static final String HTTP_SERVER_BIND_PORT = "messaging.bind.port";

171

public static final String CONTAINER_VIRTUAL_CORES = "messaging.container.virtual.cores";

172

public static final String CONTAINER_MEMORY_MB = "messaging.container.memory.mb";

173

}

174

}

175

```

176

177

### Configuration Interfaces

178

179

Base interfaces for configuration management and property storage.

180

181

```java { .api }

182

/**

183

* Base configuration interface

184

*/

185

public interface Configuration {

186

String get(String name);

187

String get(String name, String defaultValue);

188

void set(String name, String value);

189

Iterable<Map.Entry<String, String>> iterator();

190

}

191

192

/**

193

* Interface for configurable components

194

*/

195

public interface Configurable {

196

void configure(Configuration conf);

197

}

198

199

/**

200

* Property storage abstraction

201

*/

202

public interface PropertyStore<T> {

203

T get(String key);

204

void put(String key, T value);

205

void remove(String key);

206

boolean exists(String key);

207

}

208

209

/**

210

* Interface for property change notifications

211

*/

212

public interface PropertyChangeListener {

213

void onPropertyChange(String key, String oldValue, String newValue);

214

}

215

```

216

217

**Advanced Usage Examples:**

218

219

```java

220

import io.cdap.cdap.common.conf.*;

221

222

// ZooKeeper configuration helper

223

public class ZooKeeperConfig {

224

public static String getZkQuorum(CConfiguration cConf) {

225

return Constants.Zookeeper.getZkQuorum(cConf);

226

}

227

228

public static String getZkNamespace(CConfiguration cConf) {

229

return cConf.get(Constants.Zookeeper.CFG_SESSION_TIMEOUT_MILLIS, "default");

230

}

231

}

232

233

// Custom configurable component

234

public class MyService implements Configurable {

235

private String bindAddress;

236

private int bindPort;

237

238

@Override

239

public void configure(Configuration conf) {

240

this.bindAddress = conf.get("my.service.bind.address", "localhost");

241

this.bindPort = conf.getInt("my.service.bind.port", 8080);

242

}

243

244

public void start() {

245

// Start service with configured address and port

246

System.out.println("Starting service on " + bindAddress + ":" + bindPort);

247

}

248

}

249

250

// Property change monitoring

251

public class ConfigMonitor implements PropertyChangeListener {

252

@Override

253

public void onPropertyChange(String key, String oldValue, String newValue) {

254

System.out.println("Configuration changed: " + key + " = " + newValue);

255

256

// React to specific configuration changes

257

if (Constants.Security.ENABLED.equals(key)) {

258

// Reconfigure security settings

259

reconfigureSecurity(Boolean.parseBoolean(newValue));

260

}

261

}

262

263

private void reconfigureSecurity(boolean enabled) {

264

// Update security configuration

265

}

266

}

267

268

// Using property store

269

public class ConfigCache {

270

private final PropertyStore<String> cache;

271

272

public ConfigCache(PropertyStore<String> cache) {

273

this.cache = cache;

274

}

275

276

public String getCachedProperty(String key, CConfiguration cConf) {

277

if (cache.exists(key)) {

278

return cache.get(key);

279

}

280

281

String value = cConf.get(key);

282

cache.put(key, value);

283

return value;

284

}

285

}

286

```