StefanRRichter commented on a change in pull request #7123: [FLINK-10865] Add Aliyun OSS file systems without Hadoop dependencies URL: https://github.com/apache/flink/pull/7123#discussion_r236348045
########## File path: docs/ops/deployment/oss.md ########## @@ -0,0 +1,233 @@ +--- +title: "Aliyun Open Storage Service (OSS)" +nav-title: Aliyun OSS +nav-parent_id: deployment +nav-pos: 9 +--- +<!-- +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 + + http://www.apache.org/licenses/LICENSE-2.0 + +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. +--> + +* ToC +{:toc} + + +## OSS: Open Storage Service + +[Aliyun Open Storage Service](https://www.aliyun.com/product/oss) (Aliyun OSS) is widely used especially among China’s cloud users, and it provides cloud object storage for a variety of use cases. + +[Hadoop file system](http://hadoop.apache.org/docs/current/hadoop-aliyun/tools/hadoop-aliyun/index.html) supports OSS since version 2.9.1. Now, you can also use OSS with Fink for **reading** and **writing data**. + +You can access OSS objects like this: + +{% highlight plain %} +oss://<your-bucket>/<object-name> +{% endhighlight %} + +Below shows how to use OSS with Flink: + +{% highlight java %} +// Read from OSS bucket +env.readTextFile("oss://<your-bucket>/<object-name>"); + +// Write to OSS bucket +dataSet.writeAsText("oss://<your-bucket>/<object-name>") + +{% endhighlight %} + +There are two ways to use OSS with Flink, our shaded `flink-oss-fs-hadoop` will cover most scenarios. However, you may need to set up a specific Hadoop OSS FileSystem implementation if you want use OSS as YARN's resource storage dir([This patch](https://issues.apache.org/jira/browse/HADOOP-15919) enables YARN to use OSS). Both ways are described below. + +### Shaded Hadoop OSS file system (recommended) + +In order to use `flink-oss-fs-hadoop`, copy the respective JAR file from the opt directory to the lib directory of your Flink distribution before starting Flink, e.g. + +{% highlight bash %} +cp ./opt/flink-oss-fs-hadoop-{{ site.version }}.jar ./lib/ +{% endhighlight %} + +`flink-oss-fs-hadoop` registers default FileSystem wrappers for URIs with the oss:// scheme. + +#### Configurations setup +After setting up the OSS FileSystem wrapper, you need to add some configurations to make sure that Flink is allowed to access your OSS buckets. + +In order to use OSS with Flink more easily, you can use the same configuration keys in `flink-conf.yaml` with which in Hadoop's `core-site.xml` + +You can see configuration keys in [Hadoop OSS documentation](http://hadoop.apache.org/docs/current/hadoop-aliyun/tools/hadoop-aliyun/index.html). + +There are some required configurations must be added to `flink-conf.yaml`(**Other configurations defined in Hadoop OSS documentation are advanced configurations which used by performance tuning**): + +{% highlight yaml %} +fs.oss.endpoint: Aliyun OSS endpoint to connect to +fs.oss.accessKeyId: Aliyun access key ID +fs.oss.accessKeySecret: Aliyun access key secret +{% endhighlight %} + +### Hadoop-provided OSS file system - manual setup +This setup is a bit more complex and we recommend using our shaded Hadoop file systems instead (see above) unless required otherwise, e.g. for using OSS as YARN’s resource storage dir via the fs.defaultFS configuration property in Hadoop’s core-site.xml. + +#### Set OSS FileSystem +You need to point Flink to a valid Hadoop configuration, which contains the following properties in core-site.xml: + +{% highlight xml %} +<configuration> + +<property> + <name>fs.oss.impl</name> + <value>org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem</value> + </property> + + <property> + <name>fs.oss.endpoint</name> + <value>Aliyun OSS endpoint to connect to</value> + <description>Aliyun OSS endpoint to connect to. An up-to-date list is provided in the Aliyun OSS Documentation.</description> + </property> + + <property> + <name>fs.oss.accessKeyId</name> + <description>Aliyun access key ID</description> + </property> + + <property> + <name>fs.oss.accessKeySecret</name> + <description>Aliyun access key secret</description> + </property> + + <property> + <name>fs.oss.buffer.dir</name> + <value>/tmp/oss</value> + </property> + +</property> + +</configuration> +{% endhighlight %} + +#### Hadoop Configuration + +You can specify the [Hadoop configuration](../config.html#hdfs) in various ways pointing Flink to +the path of the Hadoop configuration directory, for example +- by setting the environment variable `HADOOP_CONF_DIR`, or +- by setting the `fs.hdfs.hadoopconf` configuration option in `flink-conf.yaml`: +{% highlight yaml %} +fs.hdfs.hadoopconf: /path/to/etc/hadoop +{% endhighlight %} + +This registers `/path/to/etc/hadoop` as Hadoop's configuration directory with Flink. Flink will look for the `core-site.xml` and `hdfs-site.xml` files in the specified directory. + +#### Provide OSS FileSystem Dependency + +You can find Hadoop OSS FileSystem are packaged in the hadoop-aliyun artifact. This JAR and all its dependencies need to be added to Flink’s classpath, i.e. the class path of both Job and TaskManagers. + +There are multiple ways of adding JARs to Flink’s class path, the easiest being simply to drop the JARs in Flink’s lib folder. You need to copy the hadoop-aliyun JAR with all its dependencies(You can find these as part of the Hadoop binaries in hadoop-3/share/hadoop/tools/lib). You can also export the directory containing these JARs as part of the HADOOP_CLASSPATH environment variable on all machines. + +## An Example +Below is an example shows the result of our setup(Data is generated by TPC-DS tool) + +{% highlight java %} +// Read from OSS bucket +scala> val dataSet = benv.readTextFile("oss://<your-bucket>/50/call_center/data-m-00049") +dataSet: org.apache.flink.api.scala.DataSet[String] = org.apache.flink.api.scala.DataSet@31940704 + +scala> dataSet.print() +1|AAAAAAAABAAAAAAA|1998-01-01|||2450952|NY Metro|large|2935|1670015|8AM-4PM|Bob Belcher|6|More than other authori|Shared others could not count fully dollars. New members ca|Julius Tran|3|pri|6|cally|730|Ash Hill|Boulevard|Suite 0|Oak Grove|Williamson County|TN|38370|United States|-5|0.11| +2|AAAAAAAACAAAAAAA|1998-01-01|2000-12-31||2450806|Mid Atlantic|medium|1574|594972|8AM-8AM|Felipe Perkins|2|A bit narrow forms matter animals. Consist|Largely blank years put substantially deaf, new others. Question|Julius Durham|5|anti|1|ought|984|Center Hill|Way|Suite 70|Midway|Williamson County|TN|31904|United States|-5|0.12| +3|AAAAAAAACAAAAAAA|2001-01-01|||2450806|Mid Atlantic|medium|1574|1084486|8AM-4PM|Mark Hightower|2|Wrong troops shall work sometimes in a opti|Largely blank years put substantially deaf, new others. Question|Julius Durham|1|ought|2|able|984|Center Hill|Way|Suite 70|Midway|Williamson County|TN|31904|United States|-5|0.01| +4|AAAAAAAAEAAAAAAA|1998-01-01|2000-01-01||2451063|North Midwest|medium|10137|6578913|8AM-4PM|Larry Mccray|2|Dealers make most historical, direct students|Rich groups catch longer other fears; future,|Matthew Clifton|4|ese|3|pri|463|Pine Ridge|RD|Suite U|Five Points|Ziebach County|SD|56098|United States|-6|0.05| +5|AAAAAAAAEAAAAAAA|2000-01-02|2001-12-31||2451063|North Midwest|small|17398|4610470|8AM-8AM|Larry Mccray|2|Dealers make most historical, direct students|Blue, due beds come. Politicians would not make far thoughts. Specifically new horses partic|Gary Colburn|4|ese|3|pri|463|Pine Ridge|RD|Suite U|Five Points|Ziebach County|SD|56098|United States|-6|0.12| +6|AAAAAAAAEAAAAAAA|2002-01-01|||2451063|North Midwest|medium|13118|6585236|8AM-4PM|Larry Mccray|5|Silly particles could pro|Blue, due beds come. Politicians would not make far thoughts. Specifically new horses partic|Gary Colburn|5|anti|3|pri|463|Pine Ridge|RD|Suite U|Five Points|Ziebach County|SD|56098|United States|-6|0.11| +7|AAAAAAAAHAAAAAAA|1998-01-01|||2451024|Pacific Northwest|small|6280|1739560|8AM-4PM|Alden Snyder|6|Major, formal states can suppor|Reduced, subsequent bases could not lik|Frederick Weaver|5|anti|4|ese|415|Jefferson Tenth|Court|Suite 180|Riverside|Walker County|AL|39231|United States|-6|0.00| +8|AAAAAAAAIAAAAAAA|1998-01-01|2000-12-31||2450808|California|small|4766|2459256|8AM-12AM|Wayne Ray|6|Here possible notions arrive only. Ar|Common, free creditors should exper|Daniel Weller|5|anti|2|able|550|Cedar Elm|Ct.|Suite I|Fairview|Williamson County|TN|35709|United States|-5|0.06| + +scala> dataSet.count() +res0: Long = 8 + +// Write to OSS bucket +scala> dataSet.writeAsText("oss://<your-bucket>/50/call_center/data-m-00049.1") + +scala> benv.execute("My batch program") +res1: org.apache.flink.api.common.JobExecutionResult = org.apache.flink.api.common.JobExecutionResult@77476fcf + +scala> val newDataSet = benv.readTextFile("oss://<your-bucket>/50/call_center/data-m-00049.1") +newDataSet: org.apache.flink.api.scala.DataSet[String] = org.apache.flink.api.scala.DataSet@40b70f31 + +scala> newDataSet.count() +res2: Long = 8 + +{% endhighlight %} + +## Common Issues +### Could not find OSS file system +If your job submission fails with an Exception message like below, please checkout whether our shaded jar(flink-oss-fs-hadoop-{{ site.version }}.jar) is in lib dir. Review comment: in **the** lib dir ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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
