Skip to content

Commit 7ce1aa3

Browse files
committed
HDDS-15082. Add user facing config contract for ozone local
1 parent 7095b46 commit 7ce1aa3

4 files changed

Lines changed: 947 additions & 0 deletions

File tree

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.local;
19+
20+
import java.nio.file.Path;
21+
import java.nio.file.Paths;
22+
import java.time.Duration;
23+
import java.util.Locale;
24+
import java.util.Objects;
25+
26+
/**
27+
* Configuration for a local single-node Ozone runtime.
28+
*/
29+
public final class LocalOzoneClusterConfig {
30+
31+
static final Path DEFAULT_DATA_DIR =
32+
Paths.get(System.getProperty("user.home"), ".ozone", "local")
33+
.toAbsolutePath()
34+
.normalize();
35+
static final FormatMode DEFAULT_FORMAT_MODE = FormatMode.IF_NEEDED;
36+
static final int DEFAULT_DATANODES = 1;
37+
static final String DEFAULT_HOST = "127.0.0.1";
38+
static final String DEFAULT_BIND_HOST = "0.0.0.0";
39+
static final int DEFAULT_PORT = 0;
40+
static final boolean DEFAULT_S3G_ENABLED = true;
41+
static final boolean DEFAULT_EPHEMERAL = false;
42+
static final Duration DEFAULT_STARTUP_TIMEOUT = Duration.ofMinutes(2);
43+
static final String DEFAULT_S3_ACCESS_KEY = "admin";
44+
static final String DEFAULT_S3_SECRET_KEY = "admin123";
45+
static final String DEFAULT_S3_REGION = "us-east-1";
46+
47+
private final Path dataDir;
48+
private final FormatMode formatMode;
49+
private final int datanodes;
50+
private final String host;
51+
private final String bindHost;
52+
private final int scmPort;
53+
private final int omPort;
54+
private final int s3gPort;
55+
private final boolean s3gEnabled;
56+
private final boolean ephemeral;
57+
private final Duration startupTimeout;
58+
private final String s3AccessKey;
59+
private final String s3SecretKey;
60+
private final String s3Region;
61+
62+
private LocalOzoneClusterConfig(Builder builder) {
63+
dataDir = Objects.requireNonNull(builder.dataDir, "dataDir")
64+
.toAbsolutePath()
65+
.normalize();
66+
formatMode = Objects.requireNonNull(builder.formatMode, "formatMode");
67+
datanodes = builder.datanodes;
68+
host = Objects.requireNonNull(builder.host, "host");
69+
bindHost = Objects.requireNonNull(builder.bindHost, "bindHost");
70+
scmPort = builder.scmPort;
71+
omPort = builder.omPort;
72+
s3gPort = builder.s3gPort;
73+
s3gEnabled = builder.s3gEnabled;
74+
ephemeral = builder.ephemeral;
75+
startupTimeout = Objects.requireNonNull(builder.startupTimeout,
76+
"startupTimeout");
77+
s3AccessKey = Objects.requireNonNull(builder.s3AccessKey, "s3AccessKey");
78+
s3SecretKey = Objects.requireNonNull(builder.s3SecretKey, "s3SecretKey");
79+
s3Region = Objects.requireNonNull(builder.s3Region, "s3Region");
80+
}
81+
82+
public Path getDataDir() {
83+
return dataDir;
84+
}
85+
86+
public FormatMode getFormatMode() {
87+
return formatMode;
88+
}
89+
90+
public int getDatanodes() {
91+
return datanodes;
92+
}
93+
94+
public String getHost() {
95+
return host;
96+
}
97+
98+
public String getBindHost() {
99+
return bindHost;
100+
}
101+
102+
public int getScmPort() {
103+
return scmPort;
104+
}
105+
106+
public int getOmPort() {
107+
return omPort;
108+
}
109+
110+
public int getS3gPort() {
111+
return s3gPort;
112+
}
113+
114+
public boolean isS3gEnabled() {
115+
return s3gEnabled;
116+
}
117+
118+
public boolean isEphemeral() {
119+
return ephemeral;
120+
}
121+
122+
public Duration getStartupTimeout() {
123+
return startupTimeout;
124+
}
125+
126+
public String getS3AccessKey() {
127+
return s3AccessKey;
128+
}
129+
130+
public String getS3SecretKey() {
131+
return s3SecretKey;
132+
}
133+
134+
public String getS3Region() {
135+
return s3Region;
136+
}
137+
138+
public static Builder builder() {
139+
return new Builder(DEFAULT_DATA_DIR);
140+
}
141+
142+
public static Builder builder(Path dataDir) {
143+
return new Builder(dataDir);
144+
}
145+
146+
/**
147+
* Storage initialization mode for the local runtime.
148+
*/
149+
public enum FormatMode {
150+
IF_NEEDED,
151+
ALWAYS,
152+
NEVER;
153+
154+
public static FormatMode fromString(String value) {
155+
String normalized = value.trim().toUpperCase(Locale.ROOT)
156+
.replace('-', '_');
157+
return valueOf(normalized);
158+
}
159+
}
160+
161+
/**
162+
* Builder for {@link LocalOzoneClusterConfig}.
163+
*/
164+
public static final class Builder {
165+
166+
private final Path dataDir;
167+
private FormatMode formatMode = DEFAULT_FORMAT_MODE;
168+
private int datanodes = DEFAULT_DATANODES;
169+
private String host = DEFAULT_HOST;
170+
private String bindHost = DEFAULT_BIND_HOST;
171+
private int scmPort = DEFAULT_PORT;
172+
private int omPort = DEFAULT_PORT;
173+
private int s3gPort = DEFAULT_PORT;
174+
private boolean s3gEnabled = DEFAULT_S3G_ENABLED;
175+
private boolean ephemeral = DEFAULT_EPHEMERAL;
176+
private Duration startupTimeout = DEFAULT_STARTUP_TIMEOUT;
177+
private String s3AccessKey = DEFAULT_S3_ACCESS_KEY;
178+
private String s3SecretKey = DEFAULT_S3_SECRET_KEY;
179+
private String s3Region = DEFAULT_S3_REGION;
180+
181+
private Builder(Path dataDir) {
182+
this.dataDir = dataDir;
183+
}
184+
185+
public Builder setFormatMode(FormatMode value) {
186+
formatMode = value;
187+
return this;
188+
}
189+
190+
public Builder setDatanodes(int value) {
191+
datanodes = value;
192+
return this;
193+
}
194+
195+
public Builder setHost(String value) {
196+
host = value;
197+
return this;
198+
}
199+
200+
public Builder setBindHost(String value) {
201+
bindHost = value;
202+
return this;
203+
}
204+
205+
public Builder setScmPort(int value) {
206+
scmPort = value;
207+
return this;
208+
}
209+
210+
public Builder setOmPort(int value) {
211+
omPort = value;
212+
return this;
213+
}
214+
215+
public Builder setS3gPort(int value) {
216+
s3gPort = value;
217+
return this;
218+
}
219+
220+
public Builder setS3gEnabled(boolean value) {
221+
s3gEnabled = value;
222+
return this;
223+
}
224+
225+
public Builder setEphemeral(boolean value) {
226+
ephemeral = value;
227+
return this;
228+
}
229+
230+
public Builder setStartupTimeout(Duration value) {
231+
startupTimeout = value;
232+
return this;
233+
}
234+
235+
public Builder setS3AccessKey(String value) {
236+
s3AccessKey = value;
237+
return this;
238+
}
239+
240+
public Builder setS3SecretKey(String value) {
241+
s3SecretKey = value;
242+
return this;
243+
}
244+
245+
public Builder setS3Region(String value) {
246+
s3Region = value;
247+
return this;
248+
}
249+
250+
public LocalOzoneClusterConfig build() {
251+
return new LocalOzoneClusterConfig(this);
252+
}
253+
}
254+
}

0 commit comments

Comments
 (0)