{"id":2185,"date":"2015-07-21T16:34:28","date_gmt":"2015-07-21T23:34:28","guid":{"rendered":"https:\/\/www.microsoft.com\/reallifecode\/index.php\/2015\/07\/21\/leveraging-hdinsight-from-on-premises-hadoop\/"},"modified":"2020-03-19T09:58:52","modified_gmt":"2020-03-19T16:58:52","slug":"leveraging-hdinsight-from-on-premises-hadoop","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/ise\/leveraging-hdinsight-from-on-premises-hadoop\/","title":{"rendered":"Leveraging HDInsight from On-Premises Hadoop"},"content":{"rendered":"<p>In big data solutions, compute is expected to takes place where the data resides, mainly due to the cost of moving very large scale data across clusters. However there exist scenarios where more compute capacity is needed than the on-premises cluster provides. To avoid moving large chunk of data around, the beneficial scenario consists of a comparable small dataset (in big data terms) that requires an indirect proportional amount of compute capacity. This is usually the case when building Monte Carlo models or calculating multiple models based on one dataset.<\/p>\n<p>In this case study you will learn how take advantage of <a href=\"http:\/\/azure.microsoft.com\/en-us\/services\/hdinsight\/\">Microsoft Azure HDInsight<\/a> to run a remote <a href=\"http:\/\/hadoop.apache.org\/docs\/r1.2.1\/index.html#MapReduce\">Hadoop MapReduce<\/a> job using Apache Templeton.<\/p>\n<h2 id=\"overview-of-the-solution\">Overview of the Solution<\/h2>\n<p>The solution realizes a simple data flow that extracts a dataset from an on-premises Hadoop cluster (in our case a Cloudera cluster running on Linux), runs an on-premises task to anonymize the data (if needed), then creates a <a href=\"http:\/\/azure.microsoft.com\/en-us\/services\/hdinsight\/\">Microsoft Azure HDInsight<\/a> cluster, uploads the anonymized dataset, and runs a set of compute intense translation\/modeling jobs in HDInsight. Once the translation\/modeling has been completed, the data will be downloaded from the cloud to the on-premises Hadoop cluster where the previously anonymized data will be de-anonymized. (The case study <a href=\"http:\/\/blogs.msdn.com\/b\/partnercatalystteam\/archive\/2015\/06\/04\/data-anonymizing-in-hadoop-a-ted-case-study.aspx\">Data Anonymizing in Hadoop<\/a> describes our anonymizing approach in detail and comes with a <a href=\"https:\/\/github.com\/irjudson\/jaglion\">code repository on GitHub<\/a>)<\/p>\n<p>For simplicity purposes, we decided to describe and execute the data flow using a bash script. It schedules the on-premises MapReduce jobs for data extraction, runs the PIG statements that anonymize the data, leverages the <a href=\"https:\/\/azure.microsoft.com\/en-us\/documentation\/articles\/xplat-cli-install\/\">Azure Command-Line Interface (CLI)<\/a> for data upload\/download and the interaction with HDInsight.<\/p>\n<p>At the heart of the solution is Apache Templeton: It provides a REST-like web API which can be used to make HTTP requests to MapReduce, Pig and Hive. Using the HDInsight Templeton endpoint allows us to start, monitor and stop our remote MapReduce jobs.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2020\/03\/2015-07-21-Leveraging-HDInsight-from-on-premise-Hadoop_images-image001.png\" alt=\"Architecture\" \/><\/p>\n<p>Figure 1: the data flow script runs on-premises and orchestrates all involved tasks<\/p>\n<h2 id=\"code-artifacts\">Code Artifacts<\/h2>\n<p>The bash script consists of a sequential flow of Azure CLI and Apache Templeton calls. While most of this is straight forward, starting and monitoring an HDInsight job from an on-premises Hadoop cluster required some trickery (the commands dealing with the HDInsight job are highlighted in bold):<\/p>\n<div class=\"highlighter-rouge\">\n<pre class=\"highlight\"><code># We copy the data and programs to blob store using the Azure CLI tools\r\n# These blobs are mapped through the HDInsight cluster via wasb:\/\/ so they are available via\r\n# the local cluster file system.\r\nazure storage blob upload anonymized default \"\/user\/jaglion\/input\/\"\r\nazure storage blob upload bin\/jaglion.jar default \"\/user\/jaglion\/jaglion.jar\"\r\n\r\n# This part of the script is what launches and monitors the job through the \u201cTempleton\u201d interface\r\n# HDInsight Endpoint for remote invocations\r\n# API=https:\/\/jaglion.azurehdinsight.net\/templeton\/v1\r\n\r\n# HDInsight credentials\r\nCRED=\u201duser.name=jaglion \u2013u jaglion:&lt;password&gt;\u201d\r\n\r\n# Run the job in HDInsight\r\n#  This invocation sends a request to Hadoop via Templeton that requests the cluster to run\r\n#  the Jaglion.Job class with the arguments defined with \u2018\u2013d arg=\u2019.\r\n#  The other arguments, specifically (jar, callback, statusdir, hdInsightJobName) are information #  for Hadoop to successfully run the job requested.\r\n#\r\nJOBID=$(curl -d $CRED -d jar=$OUTPUTBASE\/jaglion.jar -d hdInsightJobName=$BASEDIR \r\n-d arg=$BASEDIR\/input -d arg=$BASEDIR\/output \r\n-d arg=$BASEDIR\/configuration.xml -d statusdir=$BASEDIR \r\n-d callback=null -d class=Jaglion.Job  '$API\/mapreduce\/jar' | jsawk 'return this.id')\r\n\r\n# Monitor the job until it completes\r\nSTATUS=$(curl -s $CRED $API\/jobs\/$JOBID?user.name=jaglion | jsawk 'return this.status.state')\r\nwhile [ \"$STATUS\" != \"SUCCEEDED\" ]; do\r\n    STATUS=$(curl -s $CRED $API\/jobs\/$JOBID?user.name=jaglion | jsawk 'return this.status.state')\r\ndone\r\n\r\n# After this, we can copy the resulting data back to the local cluster from blob store because\r\n# the HDInsight job writes the results back to blob store via the same wasb:\/\/ mapped file system\r\n# used to setup the job.\r\nmkdir -p $OUTPUTBASE\/translated\r\nazure storage blob download default \"$OUTPUTBASE\/output\" $OUTPUTBASE\/output\r\n<\/code><\/pre>\n<\/div>\n<h2 id=\"opportunities-for-reuse\">Opportunities for Reuse<\/h2>\n<p>The described way to run and monitor an HDInsight job from a Linux or Windows server can be used even without involving an on-premises Hadoop cluster. However for performance reasons, it is crucial that the amount of off-premises compute is highly indirect proportional to the size of the data which is moved between off- and on-premises. The following two formulas help to evaluate whether running jobs off-premises yield to a capacity and\/or time gain:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2020\/03\/2015-07-21-Leveraging-HDInsight-from-on-premise-Hadoop_images-image002.png\" alt=\"Formula 1\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/cse\/wp-content\/uploads\/sites\/55\/2020\/03\/2015-07-21-Leveraging-HDInsight-from-on-premise-Hadoop_images-image003.png\" alt=\"Formula 2\" \/><\/p>\n<p>In the case of an on-premises Windows to HDInsight scenario, the <a href=\"http:\/\/azure.microsoft.com\/en-us\/documentation\/services\/data-factory\/\">Microsoft Azure Data Factory<\/a> should be considered. It provides a reliable platform for building rich data processing pipelines across multiple data stores.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to take advantage of Microsoft Azure HDInsight to run a remote Hadoop MapReduce job using Apache Templeton.<\/p>\n","protected":false},"author":21354,"featured_media":12677,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[47,67,73,78,193,241],"class_list":["post-2185","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-big-data","tag-apache-templeton","tag-azure-cli","tag-azure-data-factory","tag-azure-hdinsight","tag-hadoop","tag-mapreduce"],"acf":[],"blog_post_summary":"<p>How to take advantage of Microsoft Azure HDInsight to run a remote Hadoop MapReduce job using Apache Templeton.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/2185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/users\/21354"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/comments?post=2185"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/posts\/2185\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media\/12677"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/media?parent=2185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/categories?post=2185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/ise\/wp-json\/wp\/v2\/tags?post=2185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}