[ 
https://issues.apache.org/jira/browse/HDDS-1382?focusedWorklogId=229479&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-229479
 ]

ASF GitHub Bot logged work on HDDS-1382:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Apr/19 22:48
            Start Date: 17/Apr/19 22:48
    Worklog Time Spent: 10m 
      Work Description: xiaoyuyao commented on pull request #693: HDDS-1382. 
Create customized CSI server for Ozone.
URL: https://github.com/apache/hadoop/pull/693#discussion_r276462482
 
 

 ##########
 File path: 
hadoop-ozone/csi/src/main/java/org/apache/hadoop/ozone/csi/NodeService.java
 ##########
 @@ -0,0 +1,142 @@
+/**
+ * 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 java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+
+import csi.v1.Csi.NodeGetCapabilitiesRequest;
+import csi.v1.Csi.NodeGetCapabilitiesResponse;
+import csi.v1.Csi.NodeGetInfoRequest;
+import csi.v1.Csi.NodeGetInfoResponse;
+import csi.v1.Csi.NodePublishVolumeRequest;
+import csi.v1.Csi.NodePublishVolumeResponse;
+import csi.v1.Csi.NodeUnpublishVolumeRequest;
+import csi.v1.Csi.NodeUnpublishVolumeResponse;
+import csi.v1.NodeGrpc.NodeImplBase;
+import io.grpc.stub.StreamObserver;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Implementation of the CSI node service.
+ */
+public class NodeService extends NodeImplBase {
+
+  private static final Logger LOG = LoggerFactory.getLogger(NodeService.class);
+
+  private String s3Endpoint;
+
+  public NodeService(OzoneConfiguration configuration) {
+    this.s3Endpoint =
+        configuration.get(CsiConfigurationValues.OZONE_S3_ADDRESS);
+  }
+
+  @Override
+  public void nodePublishVolume(NodePublishVolumeRequest request,
+      StreamObserver<NodePublishVolumeResponse> responseObserver) {
+
+    try {
+      Files.createDirectories(Paths.get(request.getTargetPath()));
+      String mountCommand =
+          String.format("goofys --endpoint %s %s %s",
+              s3Endpoint,
+              request.getVolumeId(),
+              request.getTargetPath());
+      LOG.info("Executing " + mountCommand);
+
+      executeCommand(mountCommand);
+
+      responseObserver.onNext(NodePublishVolumeResponse.newBuilder()
+          .build());
+      responseObserver.onCompleted();
+
+    } catch (Exception e) {
+      responseObserver.onError(e);
+    }
+
+  }
+
+  private void executeCommand(String mountCommand)
+      throws IOException, InterruptedException {
+    Process exec = Runtime.getRuntime().exec(mountCommand);
+    exec.waitFor(10, TimeUnit.SECONDS);
+
+    LOG.info("Command is executed with  stdout: {}, stderr: {}",
+        IOUtils.toString(exec.getInputStream(), "UTF-8"),
+        IOUtils.toString(exec.getErrorStream(), "UTF-8"));
+    if (exec.exitValue() != 0) {
+      throw new RuntimeException(String
+          .format("Return code of the command {} was {} ()", mountCommand,
+              exec.exitValue()));
+    }
+  }
+
+  @Override
+  public void nodeUnpublishVolume(NodeUnpublishVolumeRequest request,
+      StreamObserver<NodeUnpublishVolumeResponse> responseObserver) {
+    String umountCommand =
+        String.format("fusermount -u %s", request.getTargetPath());
+    LOG.info("Executing " + umountCommand);
 
 Review comment:
   NIT: LOG.info("Executing {}", umountCommand);
 
----------------------------------------------------------------
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 229479)
    Time Spent: 50m  (was: 40m)

> Create customized CSI server for Ozone
> --------------------------------------
>
>                 Key: HDDS-1382
>                 URL: https://issues.apache.org/jira/browse/HDDS-1382
>             Project: Hadoop Distributed Data Store
>          Issue Type: Sub-task
>            Reporter: Elek, Marton
>            Assignee: Elek, Marton
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> CSI (Container Storage Interface) is a vendor neutral storage interface 
> specification for container orchestrators. CSI support is implemented in 
> YARN, Kubernetes and Mesos. Implementing a CSI server makes it easy to mount 
> disk volumes for containers.
> See https://github.com/container-storage-interface/spec for more details 
> about the spec.
> Until now we used https://github.com/CTrox/csi-s3 server to support CSI 
> specification. Using an ozone specific CSI server would have the following 
> advantages:
>  * We can provide additional functionalities (as we have access to the 
> internal Ozone API not just the very generic s3 api).
>  * Security setup can be synchronized.
>  * Increased stability
>  * Simplified deployment (only the minimal set of the components are required 
> to be installed)
> The CSI specification itself is very simple 
> (https://github.com/container-storage-interface/spec/blob/master/csi.proto) 
> at least the part which is required for Ozone.
> We can use various fuse s3 driver to mount the ozone buckets via s3.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to