Home | History | Annotate | Download | only in s3
      1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
      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.
     14 ==============================================================================*/
     15 
     16 #ifndef TENSORFLOW_CONTRIB_S3_S3_FILE_SYSTEM_H_
     17 #define TENSORFLOW_CONTRIB_S3_S3_FILE_SYSTEM_H_
     18 
     19 #include <aws/s3/S3Client.h>
     20 #include "tensorflow/core/platform/env.h"
     21 #include "tensorflow/core/platform/mutex.h"
     22 
     23 namespace tensorflow {
     24 
     25 class S3FileSystem : public FileSystem {
     26  public:
     27   S3FileSystem();
     28   ~S3FileSystem();
     29 
     30   Status NewRandomAccessFile(
     31       const string& fname, std::unique_ptr<RandomAccessFile>* result) override;
     32 
     33   Status NewWritableFile(const string& fname,
     34                          std::unique_ptr<WritableFile>* result) override;
     35 
     36   Status NewAppendableFile(const string& fname,
     37                            std::unique_ptr<WritableFile>* result) override;
     38 
     39   Status NewReadOnlyMemoryRegionFromFile(
     40       const string& fname,
     41       std::unique_ptr<ReadOnlyMemoryRegion>* result) override;
     42 
     43   Status FileExists(const string& fname) override;
     44 
     45   Status GetChildren(const string& dir, std::vector<string>* result) override;
     46 
     47   Status Stat(const string& fname, FileStatistics* stat) override;
     48 
     49   Status DeleteFile(const string& fname) override;
     50 
     51   Status CreateDir(const string& name) override;
     52 
     53   Status DeleteDir(const string& name) override;
     54 
     55   Status GetFileSize(const string& fname, uint64* size) override;
     56 
     57   Status RenameFile(const string& src, const string& target) override;
     58 
     59  private:
     60   // Returns the member S3 client, initializing as-needed.
     61   // When the client tries to access the object in S3, e.g.,
     62   //   s3://bucket-name/path/to/object
     63   // the behavior could be controlled by various environmental
     64   // variables.
     65   // By default S3 access regional endpoint, with region
     66   // controlled by `AWS_REGION`. The endpoint could be overridden
     67   // explicitly with `S3_ENDPOINT`. S3 uses HTTPS by default.
     68   // If S3_USE_HTTPS=0 is specified, HTTP is used. Also,
     69   // S3_VERIFY_SSL=0 could disable SSL verification in case
     70   // HTTPS is used.
     71   // This S3 Client does not support Virtual HostedStyle Method
     72   // for a bucket.
     73   std::shared_ptr<Aws::S3::S3Client> GetS3Client();
     74 
     75   std::shared_ptr<Aws::S3::S3Client> s3_client_;
     76   // Lock held when checking for s3_client_ initialization.
     77   mutex client_lock_;
     78 };
     79 
     80 }  // namespace tensorflow
     81 
     82 #endif  // TENSORFLOW_CONTRIB_S3_S3_FILE_SYSTEM_H_
     83