You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by GitBox <gi...@apache.org> on 2020/01/16 02:34:43 UTC

[GitHub] [hadoop-ozone] smengcl commented on a change in pull request #415: HDDS-2840. Implement ofs://: mkdir

smengcl commented on a change in pull request #415: HDDS-2840. Implement ofs://: mkdir
URL: https://github.com/apache/hadoop-ozone/pull/415#discussion_r367205152
 
 

 ##########
 File path: hadoop-ozone/ozonefs/src/main/java/org/apache/hadoop/fs/ozone/BasicRootedOzoneClientAdapterImpl.java
 ##########
 @@ -0,0 +1,602 @@
+/**
+ * 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.fs.ozone;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.hadoop.classification.InterfaceAudience;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.crypto.key.KeyProvider;
+import org.apache.hadoop.fs.BlockLocation;
+import org.apache.hadoop.fs.FileAlreadyExistsException;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdds.client.ReplicationFactor;
+import org.apache.hadoop.hdds.client.ReplicationType;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.DatanodeDetails;
+import org.apache.hadoop.hdds.security.x509.SecurityConfig;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.OzoneConfigKeys;
+import org.apache.hadoop.ozone.client.ObjectStore;
+import org.apache.hadoop.ozone.client.OzoneBucket;
+import org.apache.hadoop.ozone.client.OzoneClient;
+import org.apache.hadoop.ozone.client.OzoneClientFactory;
+import org.apache.hadoop.ozone.client.OzoneKey;
+import org.apache.hadoop.ozone.client.OzoneVolume;
+import org.apache.hadoop.ozone.client.io.OzoneOutputStream;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
+import org.apache.hadoop.ozone.om.helpers.OmKeyInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo;
+import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup;
+import org.apache.hadoop.ozone.om.helpers.OzoneFileStatus;
+import org.apache.hadoop.ozone.security.OzoneTokenIdentifier;
+import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.security.token.TokenRenewer;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Basic Implementation of the OzoneFileSystem calls.
+ * <p>
+ * This is the minimal version which doesn't include any statistics.
+ * <p>
+ * For full featured version use OzoneClientAdapterImpl.
+ */
+public class BasicRootedOzoneClientAdapterImpl
+    implements RootedOzoneClientAdapter {
+
+  static final Logger LOG =
+      LoggerFactory.getLogger(BasicRootedOzoneClientAdapterImpl.class);
+
+  private OzoneClient ozoneClient;
+  private ObjectStore objectStore;
+  private OzoneVolume volume;
+  private OzoneBucket bucket;
+  private ReplicationType replicationType;
+  private ReplicationFactor replicationFactor;
+  private boolean securityEnabled;
+  private int configuredDnPort;
+
+  /**
+   * Create new OzoneClientAdapter implementation.
+   *
+   * @throws IOException In case of a problem.
+   */
+  public BasicRootedOzoneClientAdapterImpl() throws IOException {
+    this(createConf());
+  }
+
+  private static OzoneConfiguration createConf() {
+    ClassLoader contextClassLoader =
+        Thread.currentThread().getContextClassLoader();
+    Thread.currentThread().setContextClassLoader(null);
+    try {
+      return new OzoneConfiguration();
+    } finally {
+      Thread.currentThread().setContextClassLoader(contextClassLoader);
+    }
+  }
+
+  public BasicRootedOzoneClientAdapterImpl(OzoneConfiguration conf)
+      throws IOException {
+    this(null, -1, conf);
+  }
+
+  public BasicRootedOzoneClientAdapterImpl(String omHost, int omPort,
+      Configuration hadoopConf) throws IOException {
+
+    ClassLoader contextClassLoader =
+        Thread.currentThread().getContextClassLoader();
+    Thread.currentThread().setContextClassLoader(null);
+
+    try {
+      OzoneConfiguration conf = OzoneConfiguration.of(hadoopConf);
+
+      if (omHost == null && OmUtils.isServiceIdsDefined(conf)) {
+        // When the host name or service id isn't given
+        // but ozone.om.service.ids is defined, declare failure.
+
+        // This is a safety precaution that prevents the client from
+        // accidentally failing over to an unintended OM.
+        throw new IllegalArgumentException("Service ID or host name must not"
+            + " be omitted when ozone.om.service.ids is defined.");
+      }
+
+      if (omPort != -1) {
+        // When the port number is specified, perform the following check
+        if (OmUtils.isOmHAServiceId(conf, omHost)) {
+          // If omHost is a service id, it shouldn't use a port
+          throw new IllegalArgumentException("Port " + omPort +
+              " specified in URI but host '" + omHost + "' is a "
+              + "logical (HA) OzoneManager and does not use port information.");
+        }
+      } else {
+        // When port number is not specified, read it from config
+        omPort = OmUtils.getOmRpcPort(conf);
+      }
+
+      SecurityConfig secConfig = new SecurityConfig(conf);
+
+      if (secConfig.isSecurityEnabled()) {
+        this.securityEnabled = true;
+      }
+
+      String replicationTypeConf =
+          conf.get(OzoneConfigKeys.OZONE_REPLICATION_TYPE,
+              OzoneConfigKeys.OZONE_REPLICATION_TYPE_DEFAULT);
+
+      int replicationCountConf = conf.getInt(OzoneConfigKeys.OZONE_REPLICATION,
+          OzoneConfigKeys.OZONE_REPLICATION_DEFAULT);
+
+      if (OmUtils.isOmHAServiceId(conf, omHost)) {
+        // omHost is listed as one of the service ids in the config,
+        // thus we should treat omHost as omServiceId
+        this.ozoneClient =
+            OzoneClientFactory.getRpcClient(omHost, conf);
+      } else if (StringUtils.isNotEmpty(omHost) && omPort != -1) {
+        this.ozoneClient =
+            OzoneClientFactory.getRpcClient(omHost, omPort, conf);
+      } else {
+        this.ozoneClient =
+            OzoneClientFactory.getRpcClient(conf);
+      }
+      objectStore = ozoneClient.getObjectStore();
+      this.replicationType = ReplicationType.valueOf(replicationTypeConf);
+      this.replicationFactor = ReplicationFactor.valueOf(replicationCountConf);
+      this.configuredDnPort = conf.getInt(
+          OzoneConfigKeys.DFS_CONTAINER_IPC_PORT,
+          OzoneConfigKeys.DFS_CONTAINER_IPC_PORT_DEFAULT);
+    } finally {
+      Thread.currentThread().setContextClassLoader(contextClassLoader);
+    }
+  }
+
+  public void setVolume(String volumeString) throws IOException {
+    this.volume = objectStore.getVolume(volumeString);
+  }
+
+  public void setBucket(String bucketString) throws IOException {
+    this.bucket = volume.getBucket(bucketString);
+  }
+
+  private void getVolumeAndBucket(OFSPath ofsPath,
+      boolean createIfNotExist) throws IOException {
+    getVolumeAndBucket(ofsPath.getVolumeName(), ofsPath.getBucketName(),
+        createIfNotExist);
+  }
+
+  /**
+   * Apply volumeStr and bucketStr stored in the object instance before
+   * executing a FileSystem operation.
+   *
+   * @param createIfNotExist Set this to true if the caller is a write operation
+   *                         in order to create the volume and bucket.
+   * @throws IOException
+   */
+  private void getVolumeAndBucket(String volumeStr, String bucketStr,
 
 Review comment:
   done

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-issues-help@hadoop.apache.org