Skip to content

Commit 1ae062c

Browse files
committed
HDDS-1382. Create customized CSI server for Ozone
Closes #693
1 parent 52128e3 commit 1ae062c

File tree

16 files changed

+2141
-2
lines changed

16 files changed

+2141
-2
lines changed

hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/HddsUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ public static Optional<String> getHostName(String value) {
226226
if ((value == null) || value.isEmpty()) {
227227
return Optional.empty();
228228
}
229-
return Optional.of(HostAndPort.fromString(value).getHostText());
229+
String hostname = value.replaceAll("\\:[0-9]+$", "");
230+
if (hostname.length() == 0) {
231+
return Optional.empty();
232+
} else {
233+
return Optional.of(hostname);
234+
}
230235
}
231236

232237
/**
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hdds;
19+
20+
import java.util.Optional;
21+
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
25+
/**
26+
* Testing HddsUtils.
27+
*/
28+
public class TestHddsUtils {
29+
30+
@Test
31+
public void testGetHostName() {
32+
Assert.assertEquals(Optional.of("localhost"),
33+
HddsUtils.getHostName("localhost:1234"));
34+
35+
Assert.assertEquals(Optional.of("localhost"),
36+
HddsUtils.getHostName("localhost"));
37+
38+
Assert.assertEquals(Optional.empty(),
39+
HddsUtils.getHostName(":1234"));
40+
}
41+
42+
}

hadoop-ozone/common/src/main/bin/ozone

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function hadoop_usage
4646
hadoop_add_subcommand "om" daemon "Ozone Manager"
4747
hadoop_add_subcommand "scm" daemon "run the Storage Container Manager service"
4848
hadoop_add_subcommand "s3g" daemon "run the S3 compatible REST gateway"
49+
hadoop_add_subcommand "csi" daemon "run the standalone CSI daemon"
4950
hadoop_add_subcommand "recon" daemon "run the Recon service"
5051
hadoop_add_subcommand "scmcli" client "run the CLI of the Storage Container Manager"
5152
hadoop_add_subcommand "sh" client "command line interface for object store operations"
@@ -154,6 +155,11 @@ function ozonecmd_case
154155
HADOOP_CLASSNAME='org.apache.hadoop.ozone.s3.Gateway'
155156
OZONE_RUN_ARTIFACT_NAME="hadoop-ozone-s3gateway"
156157
;;
158+
csi)
159+
HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
160+
HADOOP_CLASSNAME='org.apache.hadoop.ozone.csi.CsiServer'
161+
OZONE_RUN_ARTIFACT_NAME="hadoop-ozone-csi"
162+
;;
157163
recon)
158164
HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true"
159165
HADOOP_CLASSNAME='org.apache.hadoop.ozone.recon.ReconServer'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<FindBugsFilter>
19+
<Match>
20+
<Package name="csi.v1"/>
21+
</Match>
22+
</FindBugsFilter>

hadoop-ozone/csi/pom.xml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License. See accompanying LICENSE file.
14+
-->
15+
<project xmlns="http://maven.apache.org/POM/4.0.0"
16+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
18+
http://maven.apache.org/xsd/maven-4.0.0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
<parent>
21+
<groupId>org.apache.hadoop</groupId>
22+
<artifactId>hadoop-ozone</artifactId>
23+
<version>0.5.0-SNAPSHOT</version>
24+
</parent>
25+
<artifactId>hadoop-ozone-csi</artifactId>
26+
<version>0.5.0-SNAPSHOT</version>
27+
<description>Apache Hadoop Ozone CSI service</description>
28+
<name>Apache Hadoop Ozone CSI service</name>
29+
<packaging>jar</packaging>
30+
31+
<properties>
32+
<grpc.version>1.17.1</grpc.version>
33+
</properties>
34+
<dependencies>
35+
<dependency>
36+
<groupId>com.google.protobuf</groupId>
37+
<artifactId>protobuf-java-util</artifactId>
38+
<version>3.5.1</version>
39+
<exclusions>
40+
<exclusion>
41+
<groupId>com.google.protobuf</groupId>
42+
<artifactId>protobuf-java</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.apache.hadoop</groupId>
48+
<artifactId>hadoop-hdds-config</artifactId>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.google.guava</groupId>
52+
<artifactId>guava</artifactId>
53+
<version>26.0-android</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>com.google.protobuf</groupId>
57+
<artifactId>protobuf-java</artifactId>
58+
<version>3.5.1</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>io.grpc</groupId>
62+
<artifactId>grpc-netty</artifactId>
63+
<version>${grpc.version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>io.netty</groupId>
67+
<artifactId>netty-transport-native-epoll</artifactId>
68+
<version>4.1.30.Final</version>
69+
</dependency>
70+
<dependency>
71+
<groupId>io.grpc</groupId>
72+
<artifactId>grpc-protobuf</artifactId>
73+
<version>${grpc.version}</version>
74+
<exclusions>
75+
<exclusion>
76+
<groupId>com.google.protobuf</groupId>
77+
<artifactId>protobuf-java</artifactId>
78+
</exclusion>
79+
</exclusions>
80+
</dependency>
81+
<dependency>
82+
<groupId>io.grpc</groupId>
83+
<artifactId>grpc-stub</artifactId>
84+
<version>${grpc.version}</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.apache.hadoop</groupId>
88+
<artifactId>hadoop-ozone-client</artifactId>
89+
<exclusions>
90+
<exclusion>
91+
<groupId>com.google.guava</groupId>
92+
<artifactId>guava</artifactId>
93+
</exclusion>
94+
<exclusion>
95+
<groupId>com.google.protobuf</groupId>
96+
<artifactId>protobuf-java</artifactId>
97+
</exclusion>
98+
<exclusion>
99+
<groupId>io.netty</groupId>
100+
<artifactId>netty-all</artifactId>
101+
</exclusion>
102+
</exclusions>
103+
</dependency>
104+
</dependencies>
105+
106+
107+
<build>
108+
<extensions>
109+
<extension>
110+
<groupId>kr.motd.maven</groupId>
111+
<artifactId>os-maven-plugin</artifactId>
112+
<version>${os-maven-plugin.version}</version>
113+
</extension>
114+
</extensions>
115+
<plugins>
116+
<plugin>
117+
<groupId>org.xolstice.maven.plugins</groupId>
118+
<artifactId>protobuf-maven-plugin</artifactId>
119+
<version>${protobuf-maven-plugin.version}</version>
120+
<extensions>true</extensions>
121+
<configuration>
122+
<protocArtifact>
123+
com.google.protobuf:protoc:${protobuf-compile.version}:exe:${os.detected.classifier}
124+
</protocArtifact>
125+
<protoSourceRoot>${basedir}/src/main/proto/</protoSourceRoot>
126+
<includes>
127+
<include>csi.proto</include>
128+
</includes>
129+
<outputDirectory>target/generated-sources/java</outputDirectory>
130+
<clearOutputDirectory>false</clearOutputDirectory>
131+
</configuration>
132+
<executions>
133+
<execution>
134+
<id>compile-protoc</id>
135+
<goals>
136+
<goal>compile</goal>
137+
<goal>test-compile</goal>
138+
<goal>compile-custom</goal>
139+
<goal>test-compile-custom</goal>
140+
</goals>
141+
<configuration>
142+
<pluginId>grpc-java</pluginId>
143+
<pluginArtifact>
144+
io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}
145+
</pluginArtifact>
146+
</configuration>
147+
</execution>
148+
</executions>
149+
</plugin>
150+
<plugin>
151+
<artifactId>maven-enforcer-plugin</artifactId>
152+
<executions>
153+
<execution>
154+
<id>depcheck</id>
155+
<phase></phase>
156+
</execution>
157+
</executions>
158+
</plugin>
159+
<plugin>
160+
<groupId>org.codehaus.mojo</groupId>
161+
<artifactId>findbugs-maven-plugin</artifactId>
162+
<configuration>
163+
<excludeFilterFile>${basedir}/dev-support/findbugsExcludeFile.xml
164+
</excludeFilterFile>
165+
</configuration>
166+
</plugin>
167+
</plugins>
168+
</build>
169+
</project>
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.ozone.csi;
19+
20+
import java.io.IOException;
21+
22+
import org.apache.hadoop.ozone.client.OzoneClient;
23+
24+
import csi.v1.ControllerGrpc.ControllerImplBase;
25+
import csi.v1.Csi.CapacityRange;
26+
import csi.v1.Csi.ControllerGetCapabilitiesRequest;
27+
import csi.v1.Csi.ControllerGetCapabilitiesResponse;
28+
import csi.v1.Csi.ControllerServiceCapability;
29+
import csi.v1.Csi.ControllerServiceCapability.RPC;
30+
import csi.v1.Csi.ControllerServiceCapability.RPC.Type;
31+
import csi.v1.Csi.CreateVolumeRequest;
32+
import csi.v1.Csi.CreateVolumeResponse;
33+
import csi.v1.Csi.DeleteVolumeRequest;
34+
import csi.v1.Csi.DeleteVolumeResponse;
35+
import csi.v1.Csi.Volume;
36+
import io.grpc.stub.StreamObserver;
37+
38+
/**
39+
* CSI controller service.
40+
* <p>
41+
* This service usually runs only once and responsible for the creation of
42+
* the volume.
43+
*/
44+
public class ControllerService extends ControllerImplBase {
45+
46+
private final String volumeOwner;
47+
48+
private long defaultVolumeSize;
49+
50+
private OzoneClient ozoneClient;
51+
52+
public ControllerService(OzoneClient ozoneClient, long volumeSize,
53+
String volumeOwner) {
54+
this.volumeOwner = volumeOwner;
55+
this.defaultVolumeSize = volumeSize;
56+
this.ozoneClient = ozoneClient;
57+
}
58+
59+
@Override
60+
public void createVolume(CreateVolumeRequest request,
61+
StreamObserver<CreateVolumeResponse> responseObserver) {
62+
try {
63+
ozoneClient.getObjectStore()
64+
.createS3Bucket(volumeOwner, request.getName());
65+
66+
long size = findSize(request.getCapacityRange());
67+
68+
CreateVolumeResponse response = CreateVolumeResponse.newBuilder()
69+
.setVolume(Volume.newBuilder()
70+
.setVolumeId(request.getName())
71+
.setCapacityBytes(size))
72+
.build();
73+
74+
responseObserver.onNext(response);
75+
responseObserver.onCompleted();
76+
} catch (IOException e) {
77+
responseObserver.onError(e);
78+
}
79+
}
80+
81+
private long findSize(CapacityRange capacityRange) {
82+
if (capacityRange.getRequiredBytes() != 0) {
83+
return capacityRange.getRequiredBytes();
84+
} else {
85+
if (capacityRange.getLimitBytes() != 0) {
86+
return Math.min(defaultVolumeSize, capacityRange.getLimitBytes());
87+
} else {
88+
//~1 gig
89+
return defaultVolumeSize;
90+
}
91+
}
92+
}
93+
94+
@Override
95+
public void deleteVolume(DeleteVolumeRequest request,
96+
StreamObserver<DeleteVolumeResponse> responseObserver) {
97+
try {
98+
ozoneClient.getObjectStore().deleteS3Bucket(request.getVolumeId());
99+
100+
DeleteVolumeResponse response = DeleteVolumeResponse.newBuilder()
101+
.build();
102+
103+
responseObserver.onNext(response);
104+
responseObserver.onCompleted();
105+
} catch (IOException e) {
106+
responseObserver.onError(e);
107+
}
108+
}
109+
110+
@Override
111+
public void controllerGetCapabilities(
112+
ControllerGetCapabilitiesRequest request,
113+
StreamObserver<ControllerGetCapabilitiesResponse> responseObserver) {
114+
ControllerGetCapabilitiesResponse response =
115+
ControllerGetCapabilitiesResponse.newBuilder()
116+
.addCapabilities(
117+
ControllerServiceCapability.newBuilder().setRpc(
118+
RPC.newBuilder().setType(Type.CREATE_DELETE_VOLUME)))
119+
.build();
120+
responseObserver.onNext(response);
121+
responseObserver.onCompleted();
122+
}
123+
}

0 commit comments

Comments
 (0)