Apache Oozie ile MapReduce Görevi Çalıştırma

Apache Oozie’ye daha önce basit bir giriş yapmış ve küçük bir java uygulamasını çalıştırmıştık. Bu yazımızda examples dosyası içindeki MapReduce görevini başlatacağız.  examples klasörünü bulmayı ve lokal dizinde bir yere kopyalamayı şu yazıya bırakarak atlıyorum. Aşağıdaki kodlarda önce pwd bulunduğum dizine bakacağım ve sonra map-reduce örneğinin bulunduğu dizinin içini listeleyeceğim.

[cloudera@quickstart ~]\$ pwd
/home/cloudera
[cloudera@quickstart ~]\$ ls -ltr oozie_ornekler/examples/apps/map-reduce/
total 20
-rw-r--r-- 1 1106 4001 2559 Mar 23  2016 workflow.xml
-rw-r--r-- 1 1106 4001 2274 Mar 23  2016 workflow-with-config-class.xml
-rw-r--r-- 1 1106 4001 1028 Mar 23  2016 job-with-config-class.properties
-rw-r--r-- 1 1106 4001 1012 Mar 23  2016 job.properties
drwxr-xr-x 2 root root 4096 Aug 26 02:06 lib

En altta lib klasörü içinde map-reduce uygulamasının .jar dosyası olacak. Onun da içine girip bir göz atalım.

[cloudera@quickstart ~]\$ jar tf oozie_ornekler/examples/apps/map-reduce/lib/oozie-examples-4.1.0-cdh5.7.0.jar
META-INF/
META-INF/MANIFEST.MF
org/
org/apache/
org/apache/oozie/
org/apache/oozie/example/
META-INF/DEPENDENCIES
META-INF/LICENSE
META-INF/NOTICE
org/apache/oozie/example/TimeUnit.class
org/apache/oozie/example/DemoMapReduceMain.class
org/apache/oozie/example/LocalOozieExample.class
org/apache/oozie/example/DemoReducer.class
org/apache/oozie/example/DemoPigMain.class
org/apache/oozie/example/DemoJavaMain.class
org/apache/oozie/example/DemoMapper.class
org/apache/oozie/example/SampleMapper.class
org/apache/oozie/example/SampleOozieActionConfigurator.class
org/apache/oozie/example/DateList.class
org/apache/oozie/example/SparkFileCopy.class
org/apache/oozie/example/SampleReducer.class
org/apache/oozie/example/Repeatable.class
META-INF/maven/
META-INF/maven/org.apache.oozie/
META-INF/maven/org.apache.oozie/oozie-examples/
META-INF/maven/org.apache.oozie/oozie-examples/pom.xml
META-INF/maven/org.apache.oozie/oozie-examples/pom.properties

Buradan çıkalım ve bir üst dizindeki job.properties dosyasına bakalım.

[cloudera@quickstart ~]\$ cat oozie_ornekler/examples/apps/map-reduce/job.properties
#
# 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.
#

nameNode=hdfs://localhost:8020
jobTracker=localhost:8021
queueName=default
examplesRoot=examples

oozie.wf.application.path=\${nameNode}/user/\${user.name}/\${examplesRoot}/apps/map-reduce/workflow.xml
outputDir=map-reduce

En üstteki açıklama satırı haricinde altı özellik ve aldığı değeri görüyoruz. Bu dosya örnek olduğu için nameNode ve jobtracker adreslerimiz bizim faklı. Bu adresleri nasıl öğreneceğiz? Aşağıdaki komut ile açılan xml dosyası içinden fs.defaultFS özelliğinde yazan değer nameNode adresidir. Benimki hdfs://quickstart.cloudera:8020

[cloudera@quickstart ~]\$ cat /etc/hadoop/conf/core-site.xml

Jobtracker adresi konusunda bu yazıda bazı bilgiler verdim. Burada sadece buraya yazacağımız adresi nasıl öğreneceğimizi koyacağım:

[cloudera@quickstart ~]\$ cat /etc/hadoop/conf/yarn-site.xml

Komutu ile resourcemanager adresini öğreneceğimiz yarn-site.xml dosyasının içeriğini görebiliriz. Aşağıda ben düzgün görünsün diye Notepad++ içine kopyaladım ve ekran görüntüsü olarak buraya koydum. jobtracker karşısına yazacağımız değer quickstart.cloudera:8032 olacak.

Job.properties dosyasını düzenlemek

Şimdi nano editörü ile job.properties dosyasının içine girip değişikliklerimizi yapalım. (Siz vi, vim vb. başka editör kullanabilirsiniz)

[cloudera@quickstart java-main]\$ sudo nano job.properties
nameNode=hdfs://quickstart.cloudera:8020
jobTracker=quickstart.cloudera:8032
queueName=default
examplesRoot=examples

oozie.wf.application.path=\${nameNode}/user/\${user.name}/\${examplesRoot}/apps/map-reduce/workflow.xml
outputDir=map-reduce

Değişiklik yaptığımız yerlerin fontunu kırmızı yaptım. Beşinci özelliğimiz olan en alt satırdaki oozie.wf.application.path dan bahsetmek istiyorum. Bu beşinci özellik aslında diğer dört özelliği kullanarak dosya yolu oluşturuyor.

\${nameNode}user\${user.name}\${examplesRoot}/apps/map-reduce/workflow.xml

Bu özellik mevcut konfigürasyona göre şu şekilde bir değer alacaktır:

hdfs://quickstart.cloudera:8020userclouderaexamples/apps/map-reduce/workflow.xml

Şimdi dosyalarımızı burada belirtilen hdfs dizinine kopyalayalım. Ben daha önce kopyalamıştım. Tekrar kopyalarsam hata alırım. Bu sebeple önce map-reduce klasörünü hdfs’den kaldıracağım sonra tekrar bu klasörü lokalimden kopyalayacağım.

[cloudera@quickstart ~]\$ hdfs dfs -rm -R /user/cloudera/examples/apps/map-reduce

Lokalden hdfs’e tekrar kopyala:

[cloudera@quickstart ~]\$ hdfs dfs -put /home/cloudera/oozie_ornekler/examples/apps/map-reduce/  /user/cloudera/examples/apps

Evet kopyalandı. Artk görevi çalıştırma aşamasına geçebiliriz.

Oozie ile map-reduce görevini başlatmak
[cloudera@quickstart ~]\$ oozie job -oozie http://quickstart.cloudera:11000/oozie -config /home/cloudera/oozie_ornekler/examples/apps/map-reduce/job.properties -run
job: 0000001-170825203534617-oozie-oozi-W

Yukarıdaki komutla görev başladı ve görev numarası çıktısı komut satırından göründü. Yukarıdaki komut formatının daha anlaşır olması için parametrelerin neye işaret ettiğini açıklayalım:

oozie job -oozie [oozie sunucusu] -config [lokal dizinde job.properties dosya yolu] -run

Görev hakkında bilgi almak için:

[cloudera@quickstart ~]\$ oozie job -oozie http://quickstart.cloudera:11000/oozie -info 0000001-170825203534617-oozie-oozi-W
Job ID : 0000001-170825203534617-oozie-oozi-W
------------------------------------------------------------------------------------------------------------------------------------
Workflow Name : map-reduce-wf
App Path      : hdfs://quickstart.cloudera:8020/user/cloudera/examples/apps/map-reduce/workflow.xml
Status        : SUCCEEDED
Run           : 0
User          : cloudera
Group         : -
Created       : 2017-08-27 15:52 GMT
Started       : 2017-08-27 15:52 GMT
Last Modified : 2017-08-27 15:53 GMT
Ended         : 2017-08-27 15:53 GMT
CoordAction ID: -

Actions
------------------------------------------------------------------------------
ID                         Status    Ext ID                 Ext Status Err Code
------------------------------------------------------------------------------
0000001-170825203534617
-oozie-oozi-W@:start:      OK        -                      OK         -
-------------------------------------------------------------------------------
0000001-170825203534617
-oozie-oozi-W@mr-node      OK        job_1502609949360_0002 SUCCEEDED  -
-------------------------------------------------------------------------------
0000001-170825203534617
-oozie-oozi-W@end          OK        -                      OK         -
-------------------------------------------------------------------------------

Bu görev ne yaptı ona bakalım. job.properties dosyasında outputDir=map-reduce özelliğini değiştirmemiştik. Yani üretilen sonuçlar hdfs’de examples/output-data klasörü altında map-reduce klasörü içine yazılacak. Girip bakalım bu dizine sonuç var mı?

[cloudera@quickstart ~]\$ hdfs dfs -ls /user/cloudera/examples/output-data/map-reduce
Found 2 items
-rw-r--r--   1 cloudera cloudera          0 2017-08-27 08:53 /user/cloudera/examples/output-data/map-reduce/_SUCCESS
-rw-r--r--   1 cloudera cloudera       1547 2017-08-27 08:53 /user/cloudera/examples/output-data/map-reduce/part-00000

Evet buraya map-reduce klasörü açılmış ve içine bir sonuç yazdırılmış. cat ile sonucu okuyalım:

[cloudera@quickstart ~]\$ hdfs dfs -cat /user/cloudera/examples/output-data/map-reduce/part*
0       To be or not to be, that is the question;
42      Whether 'tis nobler in the mind to suffer
84      The slings and arrows of outrageous fortune,
129     Or to take arms against a sea of troubles,
172     And by opposing, end them. To die, to sleep;
217     No more; and by a sleep to say we end
255     The heart-ache and the thousand natural shocks
302     That flesh is heir to ? 'tis a consummation
346     Devoutly to be wish'd. To die, to sleep;
387     To sleep, perchance to dream. Ay, there's the rub,
438     For in that sleep of death what dreams may come,
487     When we have shuffled off this mortal coil,
531     Must give us pause. There's the respect
571     That makes calamity of so long life,
608     For who would bear the whips and scorns of time,
657     Th'oppressor's wrong, the proud man's contumely,
706     The pangs of despised love, the law's delay,
751     The insolence of office, and the spurns
791     That patient merit of th'unworthy takes,
832     When he himself might his quietus make
871     With a bare bodkin? who would fardels bear,
915     To grunt and sweat under a weary life,
954     But that the dread of something after death,
999     The undiscovered country from whose bourn
1041    No traveller returns, puzzles the will,
1081    And makes us rather bear those ills we have
1125    Than fly to others that we know not of?
1165    Thus conscience does make cowards of us all,
1210    And thus the native hue of resolution
1248    Is sicklied o'er with the pale cast of thought,
1296    And enterprises of great pitch and moment
1338    With this regard their currents turn awry,
1381    And lose the name of action.

Yapılan iş şu; her satıdaki karater sayısı sayılıp satır başına eklenmiş. İlk satır 42 karakter, ikinci satır 42. karakterden başlamış ve o şekilde eklemeli olarak devam ediyor. Bir Oozie görevinin daha örneğini yapmış olduk. Veriyle kalın…

Yazar Hakkında
Toplam 177 yazı
Erkan ŞİRİN
Erkan ŞİRİN
10 yılı aşkın süredir yurtiçi ve yurtdışında sektörde büyük veri mühendisliği, platform yönetimi ve makine öğrenmesi ile ilgili çalışmalar yürütmekte ve aynı zamanda birçok kurum ve şirkete danışmanlık ve eğitimler vermektedir. Çalışma alanları: Data ve MLOps platformları, gerçek zamanlı veri işleme, değişen veriyi yakalama (CDC) ve Lakehouse.
Yorumlar (Yorum yapılmamış)

Bir yanıt yazın

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

×

Bir Şeyler Ara