xiaoyuyao commented on a change in pull request #693: HDDS-1382. Create 
customized CSI server for Ozone.
URL: https://github.com/apache/hadoop/pull/693#discussion_r276461856
 
 

 ##########
 File path: 
hadoop-ozone/csi/src/main/java/org/apache/hadoop/ozone/csi/ControllerService.java
 ##########
 @@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.ozone.csi;
+
+import java.io.IOException;
+
+import org.apache.hadoop.ozone.client.OzoneClient;
+
+import csi.v1.ControllerGrpc.ControllerImplBase;
+import csi.v1.Csi.CapacityRange;
+import csi.v1.Csi.ControllerGetCapabilitiesRequest;
+import csi.v1.Csi.ControllerGetCapabilitiesResponse;
+import csi.v1.Csi.ControllerServiceCapability;
+import csi.v1.Csi.ControllerServiceCapability.RPC;
+import csi.v1.Csi.ControllerServiceCapability.RPC.Type;
+import csi.v1.Csi.CreateVolumeRequest;
+import csi.v1.Csi.CreateVolumeResponse;
+import csi.v1.Csi.DeleteVolumeRequest;
+import csi.v1.Csi.DeleteVolumeResponse;
+import csi.v1.Csi.Volume;
+import io.grpc.stub.StreamObserver;
+
+/**
+ * CSI controller service.
+ * <p>
+ * This service usually runs only once and responsible for the creation of
+ * the volume.
+ */
+public class ControllerService extends ControllerImplBase {
+
+  private OzoneClient ozoneClient;
+
+  public ControllerService(OzoneClient ozoneClient) {
+    this.ozoneClient = ozoneClient;
+  }
+
+  @Override
+  public void createVolume(CreateVolumeRequest request,
+      StreamObserver<CreateVolumeResponse> responseObserver) {
+    try {
+      ozoneClient.getObjectStore().createS3Bucket("hadoop", request.getName());
+
+      long size = findSize(request.getCapacityRange());
+
+      CreateVolumeResponse response = CreateVolumeResponse.newBuilder()
+          .setVolume(Volume.newBuilder()
+              .setVolumeId(request.getName())
+              .setCapacityBytes(size))
+          .build();
+
+      responseObserver.onNext(response);
+      responseObserver.onCompleted();
+    } catch (IOException e) {
+      responseObserver.onError(e);
+    }
+  }
+
+  private long findSize(CapacityRange capacityRange) {
+    if (capacityRange.getRequiredBytes() != 0) {
+      return capacityRange.getRequiredBytes();
+    } else {
+      if (capacityRange.getLimitBytes() != 0) {
+        return Math.min(1000_000_000, capacityRange.getLimitBytes());
 
 Review comment:
   Can we make 1000_000_000 configurable? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to