Skip to content

Commit 6b3ce79

Browse files
committed
HDDS-15084. Add SCM and OM runtime for ozone local
1 parent 98ce73b commit 6b3ce79

4 files changed

Lines changed: 476 additions & 17 deletions

File tree

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
import java.io.IOException;
25+
import java.net.InetSocketAddress;
26+
import java.net.Socket;
27+
import java.nio.file.Path;
28+
import java.time.Duration;
29+
import java.util.UUID;
30+
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
31+
import org.apache.hadoop.ozone.client.OzoneBucket;
32+
import org.apache.hadoop.ozone.client.OzoneClient;
33+
import org.apache.hadoop.ozone.client.OzoneClientFactory;
34+
import org.apache.hadoop.ozone.client.OzoneVolume;
35+
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.io.TempDir;
37+
38+
/**
39+
* Integration tests for the SCM and OM portion of {@link LocalOzoneCluster}.
40+
*/
41+
class TestLocalOzoneClusterRuntime {
42+
43+
@TempDir
44+
private Path tempDir;
45+
46+
@Test
47+
void scmAndOmStartAndReuseExistingMetadata() throws Exception {
48+
String volumeName = uniqueName("vol");
49+
String bucketName = uniqueName("bucket");
50+
Path dataDir = tempDir.resolve("local-ozone-runtime");
51+
LocalOzoneClusterConfig config = LocalOzoneClusterConfig.builder(dataDir)
52+
.setS3gEnabled(false)
53+
.setStartupTimeout(Duration.ofMinutes(2))
54+
.build();
55+
56+
startRuntimeAndCreateBucket(config, volumeName, bucketName);
57+
restartRuntimeAndVerifyBucket(config, volumeName, bucketName);
58+
}
59+
60+
@Test
61+
void formatNeverRejectsUninitializedScmOmStorage() throws Exception {
62+
Path dataDir = tempDir.resolve("local-ozone-runtime");
63+
LocalOzoneClusterConfig initialConfig =
64+
LocalOzoneClusterConfig.builder(dataDir).build();
65+
try (LocalOzoneCluster cluster =
66+
new LocalOzoneCluster(initialConfig, new OzoneConfiguration())) {
67+
cluster.prepareConfiguration();
68+
}
69+
70+
LocalOzoneClusterConfig neverFormatConfig =
71+
LocalOzoneClusterConfig.builder(dataDir)
72+
.setFormatMode(LocalOzoneClusterConfig.FormatMode.NEVER)
73+
.setS3gEnabled(false)
74+
.build();
75+
76+
IOException error = assertThrows(IOException.class, () -> {
77+
try (LocalOzoneCluster cluster =
78+
new LocalOzoneCluster(neverFormatConfig,
79+
new OzoneConfiguration())) {
80+
cluster.start();
81+
}
82+
});
83+
84+
assertTrue(error.getMessage().contains("storage is not initialized"),
85+
error.getMessage());
86+
}
87+
88+
private void startRuntimeAndCreateBucket(LocalOzoneClusterConfig config,
89+
String volumeName, String bucketName) throws Exception {
90+
try (LocalOzoneCluster cluster =
91+
new LocalOzoneCluster(config, new OzoneConfiguration())) {
92+
OzoneConfiguration clientConf =
93+
cluster.prepareConfiguration().getConfiguration();
94+
cluster.start();
95+
96+
assertServicePortsReachable(cluster);
97+
98+
try (OzoneClient client = OzoneClientFactory.getRpcClient(clientConf)) {
99+
OzoneVolume volume = createVolume(client, volumeName);
100+
createBucket(volume, bucketName);
101+
}
102+
}
103+
}
104+
105+
private void restartRuntimeAndVerifyBucket(LocalOzoneClusterConfig config,
106+
String volumeName, String bucketName) throws Exception {
107+
try (LocalOzoneCluster cluster =
108+
new LocalOzoneCluster(config, new OzoneConfiguration())) {
109+
OzoneConfiguration clientConf =
110+
cluster.prepareConfiguration().getConfiguration();
111+
cluster.start();
112+
113+
assertServicePortsReachable(cluster);
114+
115+
try (OzoneClient client = OzoneClientFactory.getRpcClient(clientConf)) {
116+
OzoneVolume volume = client.getObjectStore().getVolume(volumeName);
117+
OzoneBucket bucket = volume.getBucket(bucketName);
118+
assertEquals(bucketName, bucket.getName());
119+
}
120+
}
121+
}
122+
123+
private static void assertServicePortsReachable(LocalOzoneCluster cluster)
124+
throws IOException {
125+
assertTrue(cluster.getScmPort() > 0);
126+
assertTrue(cluster.getOmPort() > 0);
127+
assertPortReachable(cluster.getDisplayHost(), cluster.getScmPort());
128+
assertPortReachable(cluster.getDisplayHost(), cluster.getOmPort());
129+
}
130+
131+
private static void assertPortReachable(String host, int port)
132+
throws IOException {
133+
try (Socket socket = new Socket()) {
134+
socket.connect(new InetSocketAddress(host, port), 1_000);
135+
}
136+
}
137+
138+
private static OzoneVolume createVolume(OzoneClient client, String volumeName)
139+
throws IOException {
140+
client.getObjectStore().createVolume(volumeName);
141+
return client.getObjectStore().getVolume(volumeName);
142+
}
143+
144+
private static OzoneBucket createBucket(OzoneVolume volume, String bucketName)
145+
throws IOException {
146+
volume.createBucket(bucketName);
147+
return volume.getBucket(bucketName);
148+
}
149+
150+
private static String uniqueName(String prefix) {
151+
return prefix + UUID.randomUUID().toString().replace("-", "");
152+
}
153+
}

hadoop-ozone/tools/pom.xml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,22 @@
6262
<groupId>org.apache.ozone</groupId>
6363
<artifactId>hdds-config</artifactId>
6464
</dependency>
65+
<dependency>
66+
<groupId>org.apache.ozone</groupId>
67+
<artifactId>hdds-server-framework</artifactId>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.apache.ozone</groupId>
71+
<artifactId>hdds-server-scm</artifactId>
72+
</dependency>
6573
<dependency>
6674
<groupId>org.apache.ozone</groupId>
6775
<artifactId>ozone-common</artifactId>
6876
</dependency>
77+
<dependency>
78+
<groupId>org.apache.ozone</groupId>
79+
<artifactId>ozone-manager</artifactId>
80+
</dependency>
6981
<dependency>
7082
<groupId>org.apache.ratis</groupId>
7183
<artifactId>ratis-common</artifactId>
@@ -78,6 +90,10 @@
7890
<groupId>org.reflections</groupId>
7991
<artifactId>reflections</artifactId>
8092
</dependency>
93+
<dependency>
94+
<groupId>org.slf4j</groupId>
95+
<artifactId>slf4j-api</artifactId>
96+
</dependency>
8197
<dependency>
8298
<!-- required for @MetaInfServices at compile-time, but not at runtime -->
8399
<groupId>org.kohsuke.metainf-services</groupId>
@@ -106,12 +122,6 @@
106122
<artifactId>ratis-thirdparty-misc</artifactId>
107123
<scope>runtime</scope>
108124
</dependency>
109-
<dependency>
110-
<!-- transitive via hdds-common, but also for test in this module -->
111-
<groupId>org.slf4j</groupId>
112-
<artifactId>slf4j-api</artifactId>
113-
<scope>runtime</scope>
114-
</dependency>
115125
<dependency>
116126
<groupId>org.slf4j</groupId>
117127
<artifactId>slf4j-reload4j</artifactId>

0 commit comments

Comments
 (0)