<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6816360065241545754</id><updated>2025-07-12T19:47:57.077-07:00</updated><category term="interview"/><category term="java"/><category term="maven"/><category term="Spring"/><category term="algorithm"/><category term="mysql"/><category term="oracle"/><category term="CORS"/><category term="binary search"/><category term="cobertura"/><category term="eclipse"/><category term="git"/><category term="jQuery"/><category term="jaxb"/><category term="ms sql"/><category term="mvn"/><category term="plugin"/><category term="sorted array"/><category term="unit test"/><category term="CORS Spring"/><category term="CORS Spring Rest"/><category term="DAO test mysql"/><category term="EnableTransactionManagement"/><category term="Erlang"/><category term="Fibonacci"/><category term="HBase"/><category term="Java heap space"/><category term="Mac"/><category term="Merge from Trunk to a branch"/><category term="O(n)"/><category term="OutOfMemoryError"/><category term="POI"/><category term="POJO"/><category term="POJO to json"/><category term="POJO to xml"/><category term="RDS"/><category term="Spark"/><category term="Spring MVC"/><category term="Spring rest"/><category term="Sqoop"/><category term="Thrift"/><category term="Thrift2"/><category term="View merge history"/><category term="add existing project to git repository"/><category term="amazon S3"/><category term="amazon emr"/><category term="awk"/><category term="cheat sheet"/><category term="cluster"/><category term="command"/><category term="command line"/><category term="config"/><category term="configuration"/><category term="connect to HBase"/><category term="counter"/><category term="create tag"/><category term="custom jar"/><category term="dependency injection"/><category term="dynamic tags"/><category term="early initialization"/><category term="elastic map reduce"/><category term="elasticsearch"/><category term="embedded mysql"/><category term="emr"/><category term="enum"/><category term="exclude"/><category term="existing project"/><category term="filter text"/><category term="first occurrence"/><category term="first/top n rows query"/><category term="gem"/><category term="geo distance"/><category term="geo point"/><category term="get"/><category term="github repository"/><category term="ha"/><category term="hadoop"/><category term="hangs"/><category term="hidden characters"/><category term="high availability"/><category term="ignore"/><category term="in place"/><category term="introduction to algorithm"/><category term="jar"/><category term="jdbc"/><category term="json"/><category term="jsonp"/><category term="lazy initialization"/><category term="linear"/><category term="linux/unix"/><category term="log4j"/><category term="m2eclipse"/><category term="maven-jaxb2-plugin"/><category term="maven-surefire-plugin"/><category term="maximum subarray"/><category term="maximum sum"/><category term="memory"/><category term="memory_backend"/><category term="merge into"/><category term="micrometer"/><category term="microservice"/><category term="mutateRow"/><category term="mxj"/><category term="mysql gem"/><category term="number of occurrences of a given key"/><category term="one table"/><category term="overflow"/><category term="phantom reference"/><category term="plugin execution not covered by lifecycle configuration"/><category term="point of interests"/><category term="print column"/><category term="put"/><category term="rabbitmq"/><category term="random"/><category term="random(a b)"/><category term="range"/><category term="recursive"/><category term="remove duplicates"/><category term="rest"/><category term="rest api"/><category term="restful"/><category term="reverse a singly list"/><category term="reverse print"/><category term="reverse string"/><category term="riak"/><category term="ruby"/><category term="security group"/><category term="shade"/><category term="singleton"/><category term="singly linked list"/><category term="skip cobertura"/><category term="skip unit test"/><category term="soft reference"/><category term="spring amqp"/><category term="start"/><category term="strong reference"/><category term="svn"/><category term="swap integers"/><category term="test"/><category term="tomcat"/><category term="transaction"/><category term="vi"/><category term="weak reference"/><category term="without temp variable"/><category term="word by word"/><category term="xml"/><title type='text'>Technology Blog</title><subtitle type='html'>the technology I am interested in and work with</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>47</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-4762454638550003328</id><published>2020-10-12T21:04:00.004-07:00</published><updated>2020-10-28T12:01:33.434-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="counter"/><category scheme="http://www.blogger.com/atom/ns#" term="dynamic tags"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="micrometer"/><title type='text'>Micrometer with Dynamic Tags</title><content type='html'>&lt;p&gt;&amp;nbsp;With Micrometer, it is easy to create a counter with Builder:&lt;/p&gt;&lt;pre style=&quot;background-color: white; color: #080808; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: #871094;&quot;&gt;Counter okCounter &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;Counter&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;builder&lt;/span&gt;(&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;http.status.count&quot;&lt;/span&gt;)&lt;br /&gt;        .tag(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;status&quot;&lt;/span&gt;, &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;200&quot;&lt;/span&gt;)&lt;br /&gt;        .description(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;The number of OK count&quot;&lt;/span&gt;)&lt;br /&gt;        .register(meterRegistry);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; color: #080808; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: #871094;&quot;&gt;Counter notFoundCounter &lt;/span&gt;= &lt;span style=&quot;color: black;&quot;&gt;Counter&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;builder&lt;/span&gt;(&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;http.status.count&quot;&lt;/span&gt;)&lt;br /&gt;        .tag(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;status&quot;&lt;/span&gt;, &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;404&quot;&lt;/span&gt;)&lt;br /&gt;        .description(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;The number of not found count&quot;&lt;/span&gt;)&lt;br /&gt;        .register(meterRegistry);&lt;/pre&gt;&lt;p style=&quot;text-align: left;&quot;&gt;However, it is not feasible to create counter for every HTTP status.&amp;nbsp; We can use Java HashMap to cache the creation dynamically by leveraging the method &lt;span style=&quot;font-family: courier;&quot;&gt;computeIfAbsent&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;background-color: white; color: #080808; font-family: &amp;quot;JetBrains Mono&amp;quot;, monospace; font-size: 11.3pt;&quot;&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;io.micrometer.core.instrument.Counter&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;io.micrometer.core.instrument.MeterRegistry&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;concurrent.&lt;/span&gt;ConcurrentHashMap&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;java.util.Map&lt;/span&gt;;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;import &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;org.springframework.http.HttpStatus&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #0033b3;&quot;&gt;public class &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;HttpStatusCounter &lt;/span&gt;{&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;private static final &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;String &lt;/span&gt;&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;HTTP_STATUS_COUNT &lt;/span&gt;= &lt;span style=&quot;color: #067d17;&quot;&gt;&quot;http.status.count&quot;&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;private final &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;MeterRegistry &lt;/span&gt;&lt;span style=&quot;color: #871094;&quot;&gt;meterRegistry&lt;/span&gt;;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;private &lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;Map&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;Counter&lt;/span&gt;&amp;gt; &lt;span style=&quot;color: #871094;&quot;&gt;httpStatusCounterMap&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;HttpStatusCounter&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;MeterRegistry &lt;/span&gt;meterRegistry) {&lt;br /&gt;        &lt;span style=&quot;color: #871094;&quot;&gt;httpStatusCounterMap &lt;/span&gt;= &lt;span style=&quot;color: #0033b3;&quot;&gt;new ConcurrentHashMap&lt;/span&gt;&amp;lt;&amp;gt;();&lt;br /&gt;        &lt;span style=&quot;color: #0033b3;&quot;&gt;this&lt;/span&gt;.&lt;span style=&quot;color: #871094;&quot;&gt;meterRegistry &lt;/span&gt;= meterRegistry;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style=&quot;color: #0033b3;&quot;&gt;public void &lt;/span&gt;&lt;span style=&quot;color: #00627a;&quot;&gt;increment&lt;/span&gt;(&lt;span style=&quot;color: black;&quot;&gt;HttpStatus &lt;/span&gt;status, &lt;span style=&quot;color: #0033b3;&quot;&gt;int &lt;/span&gt;amount) {&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;Counter statusCounter &lt;/span&gt;= &lt;span style=&quot;color: #871094;&quot;&gt;httpStatusCounterMap&lt;/span&gt;.computeIfAbsent(&lt;br /&gt;                status.value(), k -&amp;gt; &lt;span style=&quot;color: black;&quot;&gt;Counter&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;builder&lt;/span&gt;(&lt;span style=&quot;color: #871094; font-style: italic;&quot;&gt;HTTP_STATUS_COUNT&lt;/span&gt;)&lt;br /&gt;                        .tag(&lt;span style=&quot;color: #067d17;&quot;&gt;&quot;status&quot;&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;String&lt;/span&gt;.&lt;span style=&quot;font-style: italic;&quot;&gt;valueOf&lt;/span&gt;(&lt;span style=&quot;color: #851691;&quot;&gt;status&lt;/span&gt;.value()))&lt;br /&gt;                        .register(&lt;span style=&quot;color: #871094;&quot;&gt;meterRegistry&lt;/span&gt;));&lt;br /&gt;        &lt;span style=&quot;color: black;&quot;&gt;statusCounter&lt;/span&gt;.increment(amount);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/4762454638550003328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2020/10/micrometer-with-dynamic-tags.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4762454638550003328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4762454638550003328'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2020/10/micrometer-with-dynamic-tags.html' title='Micrometer with Dynamic Tags'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-6772204003329661373</id><published>2020-09-04T18:42:00.007-07:00</published><updated>2020-09-05T14:34:27.717-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="elasticsearch"/><category scheme="http://www.blogger.com/atom/ns#" term="geo distance"/><category scheme="http://www.blogger.com/atom/ns#" term="geo point"/><category scheme="http://www.blogger.com/atom/ns#" term="POI"/><category scheme="http://www.blogger.com/atom/ns#" term="point of interests"/><title type='text'>Elasticsearch with Geopoint</title><content type='html'>&lt;h1 style=&quot;text-align: left;&quot;&gt;Install Elasticsearch on Mac&lt;/h1&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Install the tap&lt;br /&gt;&lt;/h3&gt;&lt;pre class=&quot;lang:default decode:true code_snippet2 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;brew tap elastic/tap&lt;/pre&gt;&lt;h2 style=&quot;text-align: left;&quot;&gt;&lt;/h2&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Install Elasticsearch&lt;/h3&gt;&lt;pre class=&quot;lang:default decode:true code_snippet4 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;brew install elastic/tap/elasticsearch-full&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Start Elasticsearch&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;pre class=&quot;lang:default decode:true code_snippet7 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;elasticsearch&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Confirm the installation works&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;curl http://localhost:9200&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Something similar to the following should be shown:&lt;/h3&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;{&lt;br /&gt;&amp;nbsp; &quot;name&quot; : &quot;MACC02Y753HJGH5&quot;,&lt;br /&gt;&amp;nbsp; &quot;cluster_name&quot; : &quot;elasticsearch_zhentao.li&quot;,&lt;br /&gt;&amp;nbsp; &quot;cluster_uuid&quot; : &quot;mkwsHWW8SoCcPzXg_KOyuQ&quot;,&lt;br /&gt;&amp;nbsp; &quot;version&quot; : {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;number&quot; : &quot;7.9.1&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;build_flavor&quot; : &quot;default&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;build_type&quot; : &quot;tar&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;build_hash&quot; : &quot;083627f112ba94dffc1232e8b42b73492789ef91&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;build_date&quot; : &quot;2020-09-01T21:22:21.964974Z&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;build_snapshot&quot; : false,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;lucene_version&quot; : &quot;8.6.2&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;minimum_wire_compatibility_version&quot; : &quot;6.8.0&quot;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;minimum_index_compatibility_version&quot; : &quot;6.0.0-beta1&quot;&lt;br /&gt;&amp;nbsp; },&lt;br /&gt;&amp;nbsp; &quot;tagline&quot; : &quot;You Know, for Search&quot;&lt;br /&gt;}&lt;/pre&gt;&lt;h1 style=&quot;text-align: left;&quot;&gt;Search by Geo Distance&lt;br /&gt;&lt;/h1&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Define the index for Geo Type&lt;br /&gt;&lt;/h3&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;put http://localhost:9200/regions&lt;/pre&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;{&lt;br /&gt;    &quot;mappings&quot;: {&lt;br /&gt;        &quot;properties&quot;: {&lt;br /&gt;            &quot;name&quot;: {&lt;br /&gt;                type: &quot;text&quot;&lt;br /&gt;            },&lt;br /&gt;            &quot;location&quot;: {&lt;br /&gt;                &quot;type&quot;: &quot;geo_point&quot;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;With the following response:&lt;/h3&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;{&lt;br /&gt;    &quot;acknowledged&quot;: true,&lt;br /&gt;    &quot;shards_acknowledged&quot;: true,&lt;br /&gt;    &quot;index&quot;: &quot;regions&quot;&lt;br /&gt;}&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Download Geo data file&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;curl https://restcountries.eu/rest/v1/all | jq -c &#39;.[] | {&quot;index&quot;: {&quot;_index&quot;: &quot;regions&quot;, &quot;_id&quot;: .alpha3Code}}, {name: .name, location: [.latlng[1], .latlng[0]] }&#39; &amp;gt; regions&lt;/pre&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;b&gt;or download it from &lt;a href=&quot;https://github.com/zhentao/geo-regions/blob/master/regions&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Import the file&lt;/h3&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;curl -H &#39;Content-Type: application/json&#39;  -s -XPUT localhost:9200/_bulk --data-binary &quot;@regions&quot;&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;List all regions&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;http://localhost:9200/regions/_search?size=100&lt;/pre&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; color: #292929; display: inline; float: none; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot;&gt;GET /regions/_search&lt;/span&gt;&lt;br style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; box-sizing: inherit; color: #292929; font-family: &amp;quot;menlo&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;courier new&amp;quot;, &amp;quot;courier&amp;quot;, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot; /&gt;&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; color: #292929; display: inline; float: none; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot;&gt;{&lt;/span&gt;&lt;br style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; box-sizing: inherit; color: #292929; font-family: &amp;quot;menlo&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;courier new&amp;quot;, &amp;quot;courier&amp;quot;, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot; /&gt;&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; color: #292929; display: inline; float: none; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot;&gt;   &quot;size&quot; : 100,&lt;/span&gt;&lt;br style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; box-sizing: inherit; color: #292929; font-family: &amp;quot;menlo&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;courier new&amp;quot;, &amp;quot;courier&amp;quot;, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot; /&gt;&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; color: #292929; display: inline; float: none; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot;&gt;   &quot;query&quot;: {&lt;/span&gt;&lt;br style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; box-sizing: inherit; color: #292929; font-family: &amp;quot;menlo&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;courier new&amp;quot;, &amp;quot;courier&amp;quot;, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot; /&gt;&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; color: #292929; display: inline; float: none; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot;&gt;      &quot;match_all&quot;: {}&lt;/span&gt;&lt;br style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; box-sizing: inherit; color: #292929; font-family: &amp;quot;menlo&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;courier new&amp;quot;, &amp;quot;courier&amp;quot;, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot; /&gt;&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; color: #292929; display: inline; float: none; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot;&gt;   }&lt;/span&gt;&lt;br style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; box-sizing: inherit; color: #292929; font-family: &amp;quot;menlo&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;courier new&amp;quot;, &amp;quot;courier&amp;quot;, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot; /&gt;&lt;span style=&quot;-webkit-text-stroke-width: 0px; background-color: #f2f2f2; color: #292929; display: inline; float: none; font-family: Menlo, Monaco, &amp;quot;Courier New&amp;quot;, Courier, monospace; font-size: 16px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; letter-spacing: -0.352px; orphans: 2; text-align: start; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Filter by Geo distance&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;{&lt;br /&gt;   &quot;size&quot;: 50,&lt;br /&gt;   &quot;query&quot;: {&lt;br /&gt;      &quot;bool&quot;: {&lt;br /&gt;         &quot;must&quot;: {&lt;br /&gt;            &quot;match_all&quot;: {}&lt;br /&gt;         },&lt;br /&gt;         &quot;filter&quot;: {&lt;br /&gt;            &quot;geo_distance&quot;: {&lt;br /&gt;               &quot;distance&quot;: &quot;3000km&quot;,&lt;br /&gt;               &quot;location&quot;: {&lt;br /&gt;                  &quot;lat&quot;: 35,&lt;br /&gt;                  &quot;lon&quot;: 105&lt;br /&gt;               }&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   },&lt;br /&gt;   &quot;sort&quot;: [&lt;br /&gt;      {&lt;br /&gt;         &quot;_geo_distance&quot;: {&lt;br /&gt;            &quot;location&quot;: {&lt;br /&gt;               &quot;lat&quot;: 35,&lt;br /&gt;               &quot;lon&quot;: 105&lt;br /&gt;            },&lt;br /&gt;            &quot;order&quot;: &quot;asc&quot;,&lt;br /&gt;            &quot;unit&quot;: &quot;km&quot;,&lt;br /&gt;            &quot;distance_type&quot;: &quot;arc&quot;&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   ]&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;The result is like below&lt;/h3&gt;&lt;p&gt;&lt;/p&gt;&lt;pre class=&quot;lang:default decode:true code_snippet8 lang:bash&quot; style=&quot;-webkit-text-stroke-width: 0px; background: rgb(245, 242, 240) none repeat scroll 0% 0%; box-sizing: inherit; color: black; display: block; font-family: &amp;quot;consolas&amp;quot;, &amp;quot;monaco&amp;quot;, &amp;quot;andale mono&amp;quot;, &amp;quot;ubuntu mono&amp;quot;, monospace; font-size: 14px; font-style: normal; font-variant-caps: normal; font-variant-ligatures: normal; font-weight: 400; hyphens: none; letter-spacing: normal; line-height: 1.5; margin: 0.5em 0px; orphans: 2; overflow-wrap: normal; overflow: auto; padding: 1em; tab-size: 4; text-align: left; text-decoration-color: initial; text-decoration-style: initial; text-indent: 0px; text-shadow: rgb(255, 255, 255) 0px 1px; text-transform: none; white-space: pre; widows: 2; word-break: normal; word-spacing: 0px;&quot;&gt;{&lt;br /&gt;    &quot;took&quot;: 15,&lt;br /&gt;    &quot;timed_out&quot;: false,&lt;br /&gt;    &quot;_shards&quot;: {&lt;br /&gt;        &quot;total&quot;: 1,&lt;br /&gt;        &quot;successful&quot;: 1,&lt;br /&gt;        &quot;skipped&quot;: 0,&lt;br /&gt;        &quot;failed&quot;: 0&lt;br /&gt;    },&lt;br /&gt;    &quot;hits&quot;: {&lt;br /&gt;        &quot;total&quot;: {&lt;br /&gt;            &quot;value&quot;: 19,&lt;br /&gt;            &quot;relation&quot;: &quot;eq&quot;&lt;br /&gt;        },&lt;br /&gt;        &quot;max_score&quot;: null,&lt;br /&gt;        &quot;hits&quot;: [&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;CHN&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;China&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        105,&lt;br /&gt;                        35&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    0.0&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;MNG&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Mongolia&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        105,&lt;br /&gt;                        46&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    1223.1458751104453&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;MMR&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Myanmar&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        98,&lt;br /&gt;                        22&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    1597.9864780876323&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;BTN&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Bhutan&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        90.5,&lt;br /&gt;                        27.5&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    1608.420695556179&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;MAC&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Macau&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        113.55,&lt;br /&gt;                        22.16666666&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    1651.5104987054583&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;HKG&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Hong Kong&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        114.16666666,&lt;br /&gt;                        22.25&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    1674.4580484734988&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;LAO&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Laos&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        105,&lt;br /&gt;                        18&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    1890.3163582803475&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;BGD&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Bangladesh&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        90,&lt;br /&gt;                        24&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    1894.1562153610287&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;TWN&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Taiwan&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        121,&lt;br /&gt;                        23.5&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2006.2988706499348&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;PRK&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;North Korea&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        127,&lt;br /&gt;                        40&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2012.9111514604588&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;KOR&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;South Korea&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        127.5,&lt;br /&gt;                        37&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2031.4778900496392&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;VNM&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Vietnam&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        107.83333333,&lt;br /&gt;                        16.16666666&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2113.0731526216714&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;NPL&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Nepal&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        84,&lt;br /&gt;                        28&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2132.4138804176705&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;THA&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Thailand&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        100,&lt;br /&gt;                        15&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2279.3258680765903&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;KHM&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Cambodia&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        105,&lt;br /&gt;                        13&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2446.291756434398&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;KGZ&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Kyrgyzstan&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        75,&lt;br /&gt;                        41&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2697.507030320444&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;RUS&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Russia&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        100,&lt;br /&gt;                        60&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2803.2803033336695&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;JPN&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Japan&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        138,&lt;br /&gt;                        36&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2975.112941971521&lt;br /&gt;                ]&lt;br /&gt;            },&lt;br /&gt;            {&lt;br /&gt;                &quot;_index&quot;: &quot;regions&quot;,&lt;br /&gt;                &quot;_type&quot;: &quot;_doc&quot;,&lt;br /&gt;                &quot;_id&quot;: &quot;PHL&quot;,&lt;br /&gt;                &quot;_score&quot;: null,&lt;br /&gt;                &quot;_source&quot;: {&lt;br /&gt;                    &quot;name&quot;: &quot;Philippines&quot;,&lt;br /&gt;                    &quot;location&quot;: [&lt;br /&gt;                        122,&lt;br /&gt;                        13&lt;br /&gt;                    ]&lt;br /&gt;                },&lt;br /&gt;                &quot;sort&quot;: [&lt;br /&gt;                    2983.948851295192&lt;br /&gt;                ]&lt;br /&gt;            }&lt;br /&gt;        ]&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;When you search by distance, Elasticsearch won’t return the distance itself as it isn’t a real field. If you need sorting, Elasticsearch advise to use the &lt;i&gt;sort&lt;/i&gt; function to return the value.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/6772204003329661373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2020/09/elasticsearch-with-geopoint.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6772204003329661373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6772204003329661373'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2020/09/elasticsearch-with-geopoint.html' title='Elasticsearch with Geopoint'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-8168607089502907675</id><published>2016-02-21T23:17:00.000-08:00</published><updated>2016-02-21T23:21:06.034-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dependency injection"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="microservice"/><category scheme="http://www.blogger.com/atom/ns#" term="restful"/><category scheme="http://www.blogger.com/atom/ns#" term="Spark"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring"/><category scheme="http://www.blogger.com/atom/ns#" term="tomcat"/><title type='text'>Spring with Spark Framework for Microservices</title><content type='html'>&lt;span id=&quot;goog_655204999&quot;&gt;&lt;/span&gt;&lt;a href=&quot;https://www.blogger.com/&quot;&gt;&lt;/a&gt;&lt;span id=&quot;goog_655205000&quot;&gt;&lt;/span&gt;Recently, my team decided to use &lt;a href=&quot;http://sparkjava.com/&quot; target=&quot;_blank&quot;&gt;Spark&lt;/a&gt; to build our new REST api.&amp;nbsp; Spark seems easy with less coding.&amp;nbsp; We still wanted to use &lt;a href=&quot;http://spring.io/&quot; target=&quot;_blank&quot;&gt;Spring&lt;/a&gt;&lt;span id=&quot;goog_655204997&quot;&gt; for dependency injection.&amp;nbsp; We also wanted to use &lt;a href=&quot;http://tomcat.apache.org/&quot; target=&quot;_blank&quot;&gt;Tomcat&lt;/a&gt;&lt;/span&gt;&lt;span id=&quot;goog_655204997&quot;&gt; as the standalone web container.&amp;nbsp; After some research, we figured out how to build the REST api with Spring, Spark and Tomcat.&lt;/span&gt;&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Create class SpringSparkFilter which extends &lt;a href=&quot;https://github.com/perwendel/spark/blob/master/src/main/java/spark/servlet/SparkFilter.java&quot; target=&quot;_blank&quot;&gt;SparkFilter&lt;/a&gt;. Override method getApplication:
&lt;script src=&quot;https://gist.github.com/zhentao/20a7738ea6d4659d8cdc.js&quot;&gt;&lt;/script&gt;
&lt;/li&gt;
&lt;li&gt;
Create class MySparkApplication, which implements &lt;a href=&quot;https://github.com/perwendel/spark/blob/master/src/main/java/spark/servlet/SparkApplication.java&quot; target=&quot;_blank&quot;&gt;SparkApplication&lt;/a&gt;. Implement init method:
&lt;script src=&quot;https://gist.github.com/zhentao/a572d4591804665ffbf6.js&quot;&gt;&lt;/script&gt;
&lt;/li&gt;
&lt;li&gt;
Configure web.xml to use SpringSparkFilter:
&lt;script src=&quot;https://gist.github.com/zhentao/25f31c234a195d24a6af.js&quot;&gt;&lt;/script&gt;
&lt;/li&gt;
&lt;/ol&gt;
Then either build a war file, and deploy it to tomcat or use &lt;a href=&quot;https://tomcat.apache.org/maven-plugin-2.2/tomcat7-maven-plugin/&quot; target=&quot;_blank&quot;&gt;tomcat7-maven-plugin&lt;/a&gt; for test run.&amp;nbsp; I usually use tomcat7-maven-plugin for fast development.&amp;nbsp; Here is the command:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace;&quot;&gt;mvn tomcat7:run&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Then access http://localhost:8080/current-date.&amp;nbsp; The complete example can be found &lt;a href=&quot;https://github.com/zhentao/spring-sparkjava-example&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/8168607089502907675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2016/02/spring-with-spark-framework-for.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8168607089502907675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8168607089502907675'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2016/02/spring-with-spark-framework-for.html' title='Spring with Spark Framework for Microservices'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-4261704776193224948</id><published>2014-09-18T14:46:00.001-07:00</published><updated>2014-09-24T16:55:18.642-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="connect to HBase"/><category scheme="http://www.blogger.com/atom/ns#" term="Erlang"/><category scheme="http://www.blogger.com/atom/ns#" term="get"/><category scheme="http://www.blogger.com/atom/ns#" term="HBase"/><category scheme="http://www.blogger.com/atom/ns#" term="Mac"/><category scheme="http://www.blogger.com/atom/ns#" term="mutateRow"/><category scheme="http://www.blogger.com/atom/ns#" term="put"/><category scheme="http://www.blogger.com/atom/ns#" term="Thrift"/><category scheme="http://www.blogger.com/atom/ns#" term="Thrift2"/><title type='text'>HBase, Thrift2 and Erlang on Mac</title><content type='html'>There are not to many documents showing how Erlang can connect to HBase using Thrift protocol.&amp;nbsp; The very useful &lt;a href=&quot;http://kungfooguru.wordpress.com/2009/08/31/erlang-thrift-and-hbase/&quot; target=&quot;_blank&quot;&gt;link&lt;/a&gt; which was published more than 5 years ago, and it discussed Thrift1.&amp;nbsp; Based on Lars George&#39;s &lt;a href=&quot;http://search-hadoop.com/m/O9OjiuXFJQ1/hbase+thrift2+lars&amp;amp;subj=Thrift+2+Update&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt;, Thrift2 will replace Thrift1 eventually.&amp;nbsp; The following will show what I have done to get Erlang to work with HBase using Thrift on a Mac machine.&amp;nbsp; It should be similar to get it work on a Linux machine.&amp;nbsp; Note that only Java is supported as first class citizen for HBase.&amp;nbsp; If you have the choice, I suggest using Java directly. &lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Download &lt;a href=&quot;http://archive.apache.org/dist/thrift/0.9.0/thrift-0.9.0.tar.gz&quot; target=&quot;_blank&quot;&gt;thrift-0.9.0 &lt;/a&gt;and follow this &lt;a href=&quot;http://thrift.apache.org/tutorial/&quot; target=&quot;_blank&quot;&gt;tutorial&lt;/a&gt; to install it. &lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;cp -r thrift-0.9.0/lib/erl/*&amp;nbsp; /usr/local/opt/erlang/lib/erlang/lib/thrift-0.9.0&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
(homebrew installed &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;erlang&lt;/span&gt; to &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;/usr/local/opt/erlang&lt;/span&gt;.&amp;nbsp; Find out your own erlang directory.)&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;Download latest stable &lt;a href=&quot;http://www.apache.org/dyn/closer.cgi/hbase/&quot; target=&quot;_blank&quot;&gt;hbase &lt;/a&gt;and decompress it.&amp;nbsp; I installed it to &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;/usr/local/hbase-0.98.6.1-hadoop2&lt;/span&gt;, and will refer it as &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;$HBASE_FOLDER&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;Download &lt;a href=&quot;https://git-wip-us.apache.org/repos/asf?p=hbase.git;a=blob;f=hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift&quot; target=&quot;_blank&quot;&gt;hbase.thrift&lt;/a&gt; and generate erlang bindings. &lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;thrift -gen erl hbase.thrift &lt;/span&gt;&lt;br /&gt;

It generates erlang bindings in &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;gen-erl&lt;/span&gt; folder.&lt;/li&gt;
&lt;li&gt;start hbase server:&lt;br /&gt;
before starting hbase server, update conf/hbase-site.xml&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;name&amp;gt;hbase.rootdir&amp;lt;/name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;value&amp;gt;file:///some-folder-hbase&amp;lt;/value&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/property&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;property&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;name&amp;gt;hbase.zookeeper.property.dataDir&amp;lt;/name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;value&amp;gt;/some-folder-zookeeper&amp;lt;/value&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;br /&gt;
Then start hbase server:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;$HBASE_FOLDER/bin/start-hbase.sh &lt;/span&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;start Thrift2:
&lt;br /&gt;

&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;$HBASE_FOLDER/bin/base-daemon.sh start thrift2&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Create table &#39;ups&#39; with column family &#39;ui&#39; using HBase Shell (Thrift2 doesn&#39;t support create table yet):&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;$HBASE_FOLDER/bin/hbase shell&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;hbase(main):001:0&amp;gt;; create &#39;ups&#39;, &#39;ui&#39;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;Download &lt;a href=&quot;https://github.com/zhentao/erlang-hbase-thrift2/blob/master/src/hbase_thrift2_client.erl&quot; target=&quot;_blank&quot;&gt;erlang client file&lt;/a&gt; and save it to &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;gen-erl&lt;/span&gt; folder. &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Go to &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;gen-erl&lt;/span&gt; folder, compile erlang files and start erlang shell:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;cd gen-erl&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;erlc *.erl&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;erl&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;1&amp;gt;hbase_thrift2_client:put(&quot;localhost&quot;, 9090).&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{{tclient,tHBaseService_thrift,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {protocol,thrift_binary_protocol,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {binary_protocol,{transport,thrift_buffered_transport,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {buffered_transport,{transport,thrift_socket_transport,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {data,#Port&amp;lt;0 data-blogger-escaped-.716=&quot;&quot;&amp;gt;,infinity}},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; []}},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; true,true}},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0},&lt;br /&gt;&amp;nbsp;{ok,ok}}&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;2&amp;gt;hbase_thrift2_client:get(&quot;localhost&quot;, 9090).&lt;br /&gt;{{tclient,tHBaseService_thrift,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {protocol,thrift_binary_protocol,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {binary_protocol,{transport,thrift_buffered_transport,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {buffered_transport,{transport,thrift_socket_transport,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {data,#Port&amp;lt;0 data-blogger-escaped-.717=&quot;&quot;&amp;gt;,infinity}},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; []}},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; true,true}},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0},&lt;br /&gt;&amp;nbsp;{ok,{tResult,&amp;lt;&amp;lt;&quot;zhentao-key1&quot;&amp;gt;&amp;gt;,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [{tColumnValue,&amp;lt;&amp;lt;&quot;ui&quot;&amp;gt;&amp;gt;,&amp;lt;&amp;lt;&quot;test&quot;&amp;gt;&amp;gt;,&amp;lt;&amp;lt;&quot;xyz1&quot;&amp;gt;&amp;gt;,1411075681134,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; undefined},&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {tColumnValue,&amp;lt;&amp;lt;&quot;ui&quot;&amp;gt;&amp;gt;,&amp;lt;&amp;lt;&quot;test1&quot;&amp;gt;&amp;gt;,&amp;lt;&amp;lt;&quot;abc1&quot;&amp;gt;&amp;gt;,1411075681134,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; undefined}]}}}&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;!--0--&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
The detailed erlang project can be found &lt;a href=&quot;https://github.com/zhentao/erlang-hbase-thrift2&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;

</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/4261704776193224948/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2014/09/hbase-thrift2-and-erlang-on-mac.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4261704776193224948'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4261704776193224948'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2014/09/hbase-thrift2-and-erlang-on-mac.html' title='HBase, Thrift2 and Erlang on Mac'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-6347896013721908052</id><published>2013-08-30T16:51:00.000-07:00</published><updated>2013-08-30T16:52:13.502-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cluster"/><category scheme="http://www.blogger.com/atom/ns#" term="ha"/><category scheme="http://www.blogger.com/atom/ns#" term="high availability"/><category scheme="http://www.blogger.com/atom/ns#" term="rabbitmq"/><category scheme="http://www.blogger.com/atom/ns#" term="spring amqp"/><title type='text'>Spring AMQP and RabbitMQ High Availability (HA)</title><content type='html'>Recently, I finished a project to use RabbitMQ as the message broker.&amp;nbsp; It is pretty easy to set up a RabbitMQ cluster with High Availability (HA).&amp;nbsp; The RabbitMQ has the pretty good documentation on how to set up the cluster.&amp;nbsp; I also document it &lt;a href=&quot;https://github.com/zhentao/rabbit-ha-example&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt; on how to set up a 2-node cluster on a single Mac machine.&amp;nbsp; In this post, I would like to show how we can leverage spring-amqp to connect to RabbitMQ cluster.&amp;nbsp; I have a rabbit cluster running with 2 nodes: &lt;i&gt;localhost:5673 and localhost:5672&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
It is pretty easy to use spring-amqp.&amp;nbsp; I used maven to manage the dependencies:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/6395202.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
jackson-jaxrs-json-provider is used to serialize java object to json, and deserialize json back to java object.&lt;br /&gt;
&lt;br /&gt;
When creating ConnectionFactory, the addresses should be used instead of the host and port:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/6395219.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
The addresses are the comma separated host:port pairs which consist of the cluster.&lt;br /&gt;
&lt;br /&gt;
For producer, we use rabbitTemplate to send messages:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/6395323.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
For consumer, a MessageListenerContainer is created to consume message asynchronously:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/6395245.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
The MessageHandler code is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/6395259.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
This class can be called anything you like, but the method must be called &lt;i&gt;handleMessaege&lt;/i&gt; and with the correct signature (here it is Employee to match producer).&amp;nbsp; If you want to change the method name, you have to call:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;MessageListenerAdapter.setDefaultListenerMethod&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The source code can be download from &lt;a href=&quot;https://github.com/zhentao/rabbit-ha-example&quot; target=&quot;_blank&quot;&gt;github&lt;/a&gt;&lt;i&gt;.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/6347896013721908052/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2013/08/spring-amqp-and-rabbit-high.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6347896013721908052'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6347896013721908052'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2013/08/spring-amqp-and-rabbit-high.html' title='Spring AMQP and RabbitMQ High Availability (HA)'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-7848210761264779668</id><published>2013-06-11T10:52:00.000-07:00</published><updated>2013-06-11T10:52:13.375-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cobertura"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="skip cobertura"/><category scheme="http://www.blogger.com/atom/ns#" term="skip unit test"/><title type='text'>Skip cobertura coverage check when skip unit test</title><content type='html'>After I introduced &lt;a href=&quot;http://zhentao-li.blogspot.com/2013/06/using-embedded-mysql-database-for-unit.html&quot; target=&quot;_blank&quot;&gt;embedded mysql&lt;/a&gt;&lt;a href=&quot;http://zhentao-li.blogspot.com/2013/06/using-embedded-mysql-database-for-unit.html&quot; target=&quot;_blank&quot;&gt; for unit testing &lt;/a&gt;to my project, the build is taking longer now.&amp;nbsp; For my local development, sometimes I want to disable the unit test:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt; mvn clean package -DskipTests&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Note that you can even skip the compiling of test class by using&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt; mvn clean package -Dmaven.test.skip&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
However, if you use cobertura for code coverage check, you would get the following error:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;i&gt;[ERROR] Project failed check. Total branch coverage rate of 0.0% is below 85.0%&lt;br /&gt;Project failed check. Total line coverage rate of 0.0% is below 85.0%&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
So you need to skip cobertura as well.&amp;nbsp; if you google &quot;skip cobertura&quot;, most answers suggested using &lt;i&gt;haltOnFailure&lt;/i&gt;. However, cobertura already provides the skip functionality:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt; &lt;/i&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;mvn clean package -DskipTests -Dcobertura.skip&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
With &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;-Dcobertura.skip&lt;/span&gt;&lt;i&gt;, &lt;/i&gt;cobertura check will be skipped:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;[INFO] --- cobertura-maven-plugin:2.5.2:instrument (default) @ tag-service ---&lt;br /&gt;[INFO] Skipping cobertura execution&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/7848210761264779668/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2013/06/skip-cobertura-coverage-check-when-skip.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/7848210761264779668'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/7848210761264779668'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2013/06/skip-cobertura-coverage-check-when-skip.html' title='Skip cobertura coverage check when skip unit test'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-5168640337620599972</id><published>2013-06-10T10:04:00.000-07:00</published><updated>2013-06-10T10:09:33.503-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DAO test mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="embedded mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="mxj"/><category scheme="http://www.blogger.com/atom/ns#" term="mysql"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring"/><category scheme="http://www.blogger.com/atom/ns#" term="unit test"/><title type='text'>Using embedded mysql database for unit test with maven and spring</title><content type='html'>I used H2 in memory database to unit test my DAO.&amp;nbsp; However, my production database is MySQL.&lt;br /&gt;
Generally, H2 is compatible with MySQL.&amp;nbsp; However, H2 doesn&#39;t support ENUM type yet, and my schema uses ENUM for a column definition.&amp;nbsp; Inspired by this &lt;a href=&quot;http://rajandesai.com/blog/2011/10/13/how-do-you-unit-test-your-data-access-layer/&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; and &lt;a href=&quot;http://blog.palominolabs.com/2011/10/03/embedded-mysql-on-java-with-connectormxj-and-64-bit-linux/&quot; target=&quot;_blank&quot;&gt;another&lt;/a&gt;, I successfully used embedded MySQL for unit test.&amp;nbsp; Here is what I did:&lt;br /&gt;
&lt;br /&gt;
1.&amp;nbsp; Add mysql-connector-mxj dependency:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/5746725.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
2. Create EmbeddedMysqlDatabase.java and EmbeddedMysqlDatabaseBuilder.java&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/5750106.js&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://gist.github.com/zhentao/5750111.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
3. Create spring bean datasource:

&lt;script src=&quot;https://gist.github.com/zhentao/5750132.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
4. Run unit test with Spring:

&lt;script src=&quot;https://gist.github.com/zhentao/5750179.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
A couple things are worth mentioning:&lt;br /&gt;
&lt;br /&gt;
1. The test uses Spring annotation &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) &lt;/span&gt;which reload the context after every test method.&amp;nbsp; It means every test method starts a new mysql instance.&amp;nbsp; You may group test methods to 2 different categories, one changes data, and another not.&amp;nbsp; For those methods don&#39;t change data, only need to create one instance of mysql to speed up testing.&lt;br /&gt;
&lt;br /&gt;
2. If you see the following error message on Linux server:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;/lib64/libc.so.6: version `GLIBC_2.7&#39; not found (required by /tmp/test_db_2420035739165052/bin/mysqld)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
You need to either downgrade mysql-connector-mxj to 5.0.11 or upgrade your linux OS.&amp;nbsp; I got the above error message on CentOS 5.4 with 5.0.12, but no problem with 5.0.11. However, 5.0.11 isn&#39;t in any public maven repo, but you can download it from &lt;a href=&quot;http://downloads.mysql.com/archives/mysql-connector-mxj-5.0/mysql-connector-mxj-gpl-5-0-11.tar.gz&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt; and install it to your local repo, or upload to your company&#39;s repo. Using the following command to check CentOS version:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;cat /etc/redhat-release&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
3. The code is tested on Mac and CentOS only, and can be downloaded from &lt;a href=&quot;https://github.com/zhentao/maven-embedded-mysql&quot; target=&quot;_blank&quot;&gt;github&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/5168640337620599972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2013/06/using-embedded-mysql-database-for-unit.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5168640337620599972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5168640337620599972'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2013/06/using-embedded-mysql-database-for-unit.html' title='Using embedded mysql database for unit test with maven and spring'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-2987644232723226563</id><published>2013-06-03T00:22:00.000-07:00</published><updated>2013-06-04T09:28:28.225-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CORS"/><category scheme="http://www.blogger.com/atom/ns#" term="CORS Spring"/><category scheme="http://www.blogger.com/atom/ns#" term="CORS Spring Rest"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="rest api"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring rest"/><title type='text'>Example for enabling CORS support in Spring Rest Api 3.2</title><content type='html'>My last year&#39;s post &quot;&lt;a href=&quot;http://zhentao-li.blogspot.com/2012/06/enable-cors-support-in-rest-services.html&quot;&gt;Enable CORS support in REST services with Spring 3.1&lt;/a&gt;&quot; seems causing some confusion.&amp;nbsp; I decided to create an example to show how to enable CORS with Spring rest api.&amp;nbsp; The CorsFilter is same as before:&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/5699508.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
Below are 2 endpoints from EmployeeController.java:&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/5699544.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
The update method adds the header &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;Access-Control-Allow-Origin&lt;/span&gt; with &quot;*&quot;, but delete method doesn&#39;t.&amp;nbsp; Therefore, the update method is enabled with CORS, but delete isn&#39;t.&amp;nbsp; If delete endpoint is called, the following error will be shown in Chrome:&lt;br /&gt;
&lt;br /&gt;
&quot;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;cannot load http://localhost:8080/rest/employee/1. Origin http://127.0.0.1:8080 is not allowed by Access-Control-Allow-Origin.&lt;/span&gt;&quot;&lt;br /&gt;
&lt;br /&gt;
However, the delete method is still invoked on the server side since the pre-flight request (OPTIONS) &lt;br /&gt;
allows DELETE method to be called.&lt;br /&gt;
&lt;br /&gt;
The entire project can be downloaded from &lt;a href=&quot;https://github.com/zhentao/cors-spring-rest&quot;&gt;github&lt;/a&gt;.&amp;nbsp; Following README to test it.&lt;br /&gt;
&lt;br /&gt;
My intention was to disable/enable CORS support in each individual method by setting &quot;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;Access-Control-Allow-Origin&quot;, &lt;/span&gt;but it seems not working as expected:&amp;nbsp; Although the browser returns correct info, the method call is still invoked on the server side even &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;Access-Control-Allow-Origin &lt;/span&gt;is not set.&amp;nbsp; If you are allowed to enable all endpoints with CORS support, the code can be simplified as below:&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/5707286.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
The only difference is that addHeader(&quot;Access-Control-Allow-Origin&quot;) is moved out the if check. And then the update method can be simplified as:&lt;br /&gt;
&lt;script src=&quot;https://gist.github.com/zhentao/5707319.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
The code can be downloaded from &lt;a href=&quot;https://github.com/zhentao/cors-spring-rest-simple&quot; target=&quot;_blank&quot;&gt;github&lt;/a&gt; too.</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/2987644232723226563/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2013/06/example-for-enabling-cors-support-in.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/2987644232723226563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/2987644232723226563'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2013/06/example-for-enabling-cors-support-in.html' title='Example for enabling CORS support in Spring Rest Api 3.2'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-8923416972277290616</id><published>2013-05-15T16:27:00.000-07:00</published><updated>2013-05-24T14:54:09.975-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="add existing project to git repository"/><category scheme="http://www.blogger.com/atom/ns#" term="existing project"/><category scheme="http://www.blogger.com/atom/ns#" term="git"/><category scheme="http://www.blogger.com/atom/ns#" term="github repository"/><title type='text'>Add an existing project to a newly created git repository</title><content type='html'>I recently created a project on my local machine using maven archetype.&amp;nbsp; See &lt;a href=&quot;http://zhentao-li.blogspot.com/2011/12/create-maven-archetype-from-existing.html&quot; target=&quot;_blank&quot;&gt;my previous post&lt;/a&gt; on how to generate a new project from installed maven catalog.&amp;nbsp; I then got github.com created a repository for this project, for example: git@github.com:zhentao/test1.git&lt;br /&gt;
&lt;br /&gt;
How can I associate my existing project with the newly created git repo?&amp;nbsp; There are 2 ways to do it:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;First option:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
1. clone the git repo:&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git clone git@github.com:zhentao/test1.git&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
It will clone the repo to &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;test1&lt;/span&gt; folder.&lt;br /&gt;
&lt;br /&gt;
2. copy your existing project to &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;test1&lt;/span&gt; folder&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;cp -r /path/to/project /path/to/test1&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
3.&amp;nbsp; commit and push all files&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git add .&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git commit -m &quot;first commit&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git push -u origin master&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Second option&lt;/b&gt; (more git style)&lt;br /&gt;
&lt;br /&gt;
1. go to your project folder&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;cd /path/to/project&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
2. run the following commands:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git init&lt;br /&gt;git add .&lt;br /&gt;git commit -m &quot;first commit&quot;&lt;br /&gt;git remote add origin git@github.com:zhentao/test1.git&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;The above commands associate your project to git remote repo.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;3. run the following commands to to merge the conflict:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git fetch&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git merge origin/master&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;nbsp;--run it if conflicts exist&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git mergetool&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git commit&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;git pus&lt;/span&gt;h -u origin master&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/8923416972277290616/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2013/05/add-existing-project-to-newly-created.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8923416972277290616'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8923416972277290616'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2013/05/add-existing-project-to-newly-created.html' title='Add an existing project to a newly created git repository'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-3086135690807602179</id><published>2013-04-09T16:21:00.000-07:00</published><updated>2013-04-09T16:21:21.529-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="configuration"/><category scheme="http://www.blogger.com/atom/ns#" term="memory"/><category scheme="http://www.blogger.com/atom/ns#" term="memory_backend"/><category scheme="http://www.blogger.com/atom/ns#" term="riak"/><title type='text'>Riak: configure memory_backend</title><content type='html'>Riak supports several backends:&lt;br /&gt;
1. bitcask&lt;br /&gt;
2. memory&lt;br /&gt;
3. leveldb&lt;br /&gt;
4. multi&lt;br /&gt;
&lt;br /&gt;
My recent project required me to use memory backend.&amp;nbsp; I have a test server with 24GB memory.&amp;nbsp; I tried to use 4GB as the max_memory.&amp;nbsp; It seems quite easy at beginning, and I just followed the &lt;a href=&quot;http://docs.basho.com/riak/latest/tutorials/choosing-a-backend/Memory/#Enabling-and-Configuring-the-Memory-Backend&quot; target=&quot;_blank&quot;&gt;doc&lt;/a&gt; from basho.com.&amp;nbsp; I just replace &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;riak_kv_bitcask_backend&lt;/span&gt; with &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;riak_kv_memory_backend&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;{riak_kv, [&lt;/pre&gt;
&lt;pre&gt;  {storage_backend, riak_kv_memory_backend},&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;Then I want to see how much data I can load with default configuration.&amp;nbsp; I loaded a little over 11 million records, then riak crashed.&amp;nbsp; Then I set &lt;/span&gt;max_memory to 4GB to &lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;add the following right under&lt;/span&gt; {eleveldb ... configuration:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;{memory_backend, [
        ...,
            {max_memory, &lt;span style=&quot;color: #0000dd;&quot;&gt;4096&lt;/span&gt;}, %% &lt;span style=&quot;color: #0000dd;&quot;&gt;4&lt;/span&gt;GB &lt;span style=&quot;color: #008800; font-weight: bold;&quot;&gt;in&lt;/span&gt; megabytes
        ...
]}&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;Note that the following is copied from riak&#39;s doc.&amp;nbsp; Then interesting, riak crashed with same number of records (11M+).&amp;nbsp; I then changed it to 8192, but riak still crashed with the same number of records.&amp;nbsp; I spent a couple days, and couldn&#39;t figure out the reason.&amp;nbsp; I went to #riak IRC and asked the following question, and those folks were very responsive and solved my problem right away:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:30] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; hi folks, how to configure the max_memory for memory_backend?&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:30] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;/span&gt;&lt;span class=&quot;Xc4&quot;&gt;&lt;span class=&quot;hyperlink-whois&quot;&gt;alexmoore&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;gt; Hi zhentao&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:30] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; Hi&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:30] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; I added the following to config file:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:30] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; {memory_backend, [&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;{max_memory, 8192} %% 8GB in megabytes&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt; ]},&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:31] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; but it didn&#39;t work&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:31] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;alexmoore&lt;/span&gt;&amp;gt;
 In regards to your earlier question, if you don&#39;t specify a max_memory,
 or a TTL, the memory backend will continue to grow until it runs out of
 memory.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:31] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;alexmoore&lt;/span&gt;&amp;gt; Let me look at your config here&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:31] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; it seems like that&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:32] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; the node crashed after I loaded some data&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:32] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; then I specify the max_memory to 8gb, and it still crashed with same amount of data&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:32] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;alexmoore&lt;/span&gt;&amp;gt; How much RAM does the machine have?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:33] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;sully_&lt;/span&gt;&amp;gt; Cluster health seems like it&#39;s degrading again.&lt;span&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;We&#39;re starting to see the same errors as before.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:34] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; 24 GB&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:34] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;sully_&lt;/span&gt;&amp;gt; We are planning to add 3 more nodes.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:34] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;/span&gt;&lt;span class=&quot;Xc4&quot;&gt;&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;gt; zhentao: that&#39;s 8GB per vnode&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:34] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;rzezeski&lt;/span&gt;&amp;gt;
 sully_ ok, can you tar.gz the latest log files again, that might allow 
me to find the cause before it gets rotated out by the logger&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:34] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;/span&gt;&lt;span class=&quot;Xc4&quot;&gt;&lt;span class=&quot;hyperlink-whois&quot;&gt;jcaprice&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;gt; zhentao: did you restart the node after adding the memory constraint?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:35] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;sully_&lt;/span&gt;&amp;gt; Getting you the latest logs.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:35] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; yes, I restarted it&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:35] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;/span&gt;&lt;span class=&quot;Xc4&quot;&gt;&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;gt; zhentao: how many nodes, and what is your ring size?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:36] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;/span&gt;&lt;span class=&quot;Xc4&quot;&gt;&lt;span class=&quot;hyperlink-whois&quot;&gt;alexmoore&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;gt; zhentao, how many physical machines do you have in your cluster, and what is your ring size?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:36] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; it is a test server and just one machine&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:36] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;jcaprice&lt;/span&gt;&amp;gt; ring size?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:37] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; i am new to riak, and where to find th ring size?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:37] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; if you didn&#39;t set it, it&#39;s 64&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:37] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;alexmoore&lt;/span&gt;&amp;gt; In your vm.args file&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:37] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; so you&#39;re limiting memory to 8GB * 64&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:38] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; let me check &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:38] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; alexmoore: it&#39;s in app.config under riak_core&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:38] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; ring_creation_size&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:38] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;alexmoore&lt;/span&gt;&amp;gt; Whoops, make that the app.config&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:39] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; it is 64&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:39] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; {ring_creation_size, 64},&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:39] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; so you want to change max memory to 128&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:39] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; if you want to limit it at 8GB&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:40] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;/span&gt;&lt;span class=&quot;Xc4&quot;&gt;&lt;span class=&quot;hyperlink-whois&quot;&gt;jcaprice&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&amp;gt; zhentao: max_memory limits the amount of memory used per vnode, not for the node itself&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:40] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; @jcaprice, so what number I should use for max_memory for my test server?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:41] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; 128, like I said above&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:41] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; 128 mb?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:41] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;evanmcc&lt;/span&gt;&amp;gt; yes&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle1 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:41] &lt;/span&gt;&lt;span&gt;&amp;lt;@&lt;span class=&quot;hyperlink-whois&quot;&gt;jcaprice&lt;/span&gt;&amp;gt; as evanmcc said, you&#39;ll want 8192 / 64&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span class=&quot;timestamp&quot;&gt;[10:41] &lt;/span&gt;&lt;span&gt;&amp;lt;&lt;span class=&quot;hyperlink-whois&quot;&gt;zhentao&lt;/span&gt;&amp;gt; thx, let me try it&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span&gt;So in&amp;nbsp; summary, &lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{max_memory, &lt;span style=&quot;color: #0000dd;&quot;&gt;4096&lt;/span&gt;} &lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;is for each &lt;span style=&quot;color: red;&quot;&gt;vnode&lt;/span&gt;, not for each machine.&amp;nbsp; Since I wanted to limit the memory usage for one machine to 4GB, I should use the following:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;{max_memory, &lt;span style=&quot;color: #0000dd;&quot;&gt;64&lt;/span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;The reason is that the ring_creattion_size is 64 which means there are 64 vnodes on my single test server.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;64MB * 64 = 4096MB&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;After I changed max_memory to 64, riak is happy, and it didn&#39;t crash when I tried to load 20MM records.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;Some interesting things I noticed:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;1. since Riak use LRU for memory_backend, the old records are evicted if max_memory can&#39;t hold all records.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;2. With the key as &quot;70f21766-1cde-38d4-5920-a380003723b3&quot;, and value as &quot;&lt;/span&gt;&lt;/span&gt;1365720608095#TQB:1.4:2:1&quot;,&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
4GB memory with 64 vnodes can&amp;nbsp; hold about 2.5MM records&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;4GB memory with 4 vnodes can hold about 7MM records&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;linestyle2 colourline&quot;&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: Times,&amp;quot;Times New Roman&amp;quot;,serif;&quot;&gt;Seems the number of vnodes/machine has big overhead &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/3086135690807602179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2013/04/riak-configure-memorybackend.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/3086135690807602179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/3086135690807602179'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2013/04/riak-configure-memorybackend.html' title='Riak: configure memory_backend'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-5305825612987312161</id><published>2013-02-14T15:30:00.000-08:00</published><updated>2013-02-14T15:30:13.613-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="hangs"/><category scheme="http://www.blogger.com/atom/ns#" term="start"/><title type='text'>eclipse JUNO hangs on start up</title><content type='html'>I use Eclipse JUNO every day.&amp;nbsp; However, I couldn&#39;t start it today after I restart my Mac.&amp;nbsp; Mac updated with Microsoft 2011 so I have to reboot Mac machine.&amp;nbsp; The strange thing happened: Eclipse got stuck.&amp;nbsp; I manually killed the start up process several times, but it didn&#39;t work.&amp;nbsp; Then I googled it, and found the solution from this &lt;a href=&quot;http://stackoverflow.com/questions/207843/how-do-i-prevent-eclipse-from-hanging-on-startup&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt;, and here is what I did:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;lang-java prettyprint prettyprinted&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;rm $WORKSPACE_DIR&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;plugins&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;org&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;eclipse&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;e4&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;workbench&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;workbench&lt;/span&gt;&lt;span class=&quot;pun&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot;&gt;xmi&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;lang-java prettyprint prettyprinted&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;lang-java prettyprint prettyprinted&quot;&gt;&lt;code&gt;&lt;span class=&quot;pln&quot;&gt;Then I can start eclipse, and happy coding.  &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/5305825612987312161/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2013/02/eclipse-juno-hangs-on-start-up.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5305825612987312161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5305825612987312161'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2013/02/eclipse-juno-hangs-on-start-up.html' title='eclipse JUNO hangs on start up'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-8878052684150426571</id><published>2012-12-07T15:41:00.001-08:00</published><updated>2013-11-01T11:50:29.860-07:00</updated><title type='text'>my shell script cheat sheet</title><content type='html'>&lt;b&gt;1. find the total line number of a fold for some files:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
find test -iname *.java | xargs wc -l | tail -1&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2. count # of files in each folder recursively&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;for t in `find . -type d -ls | awk &#39;{print $11}&#39;`; do echo &quot;$t `find $t -type f&amp;nbsp; | wc -l`&quot; ; done &amp;gt; ~/count.txt</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/8878052684150426571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/12/my-shell-script-cheat-sheet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8878052684150426571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8878052684150426571'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/12/my-shell-script-cheat-sheet.html' title='my shell script cheat sheet'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-8870628264709400295</id><published>2012-12-07T15:38:00.001-08:00</published><updated>2012-12-07T15:38:36.621-08:00</updated><title type='text'>insert control character with vi</title><content type='html'>insert a 
visible &lt;code&gt;^A&lt;/code&gt;, we must use: &lt;code&gt;&amp;lt;ctrl&amp;gt; + v + a&lt;/code&gt;&lt;code&gt;&lt;/code&gt;.</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/8870628264709400295/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/12/insert-control-character-with-vi.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8870628264709400295'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8870628264709400295'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/12/insert-control-character-with-vi.html' title='insert control character with vi'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-5946976538672240284</id><published>2012-11-01T11:06:00.001-07:00</published><updated>2012-11-01T11:06:41.667-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="create tag"/><category scheme="http://www.blogger.com/atom/ns#" term="Merge from Trunk to a branch"/><category scheme="http://www.blogger.com/atom/ns#" term="svn"/><category scheme="http://www.blogger.com/atom/ns#" term="View merge history"/><title type='text'>Some svn commands</title><content type='html'>&lt;pre class=&quot;screen&quot;&gt;&lt;b&gt;Create tag from trunk or branch&lt;/b&gt;:&lt;/pre&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;screen&quot;&gt;svn copy http://svn.mydomain.com/repository/myproject/trunk \
           http://svn.mydomain.com/repository/myproject/tags/release-1.0 \
      -m &quot;Tagging the 1.0 release.&quot; &lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;The tag created is the snapshot of the trunk at the time the &quot;svn copy&quot; is executed.  &lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;To be more precisely, the revision # can be passed to &quot;svn copy&quot;:&lt;/span&gt;&lt;/pre&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;screen&quot;&gt;svn copy -r 12345 http://svn.mydomain.com/repository/myproject/trunk \
           http://svn.mydomain.com/repository/myproject/tags/release-1.0 \
      -m &quot;Tagging the 1.0 release.&quot;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;b&gt;Merge from Trunk to a branch&lt;/b&gt;:&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;
&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;1. check out the branch (assume the path is &lt;i&gt;/path/to/mybranch&lt;/i&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;2. go to above folder&lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;3. run the following commmand&lt;/span&gt;:&lt;/pre&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;screen&quot;&gt;svn merge http://svn.mydomain.com/repository/myproject/trunk .&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;It will merge all changes from trunk to mybranch since last merge. &lt;/span&gt;&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;The above command is same as:&lt;/span&gt;&lt;/pre&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;screen&quot;&gt;svn merge -rLastMergedRevision:HEAD http://svn.mydomain.com/repository/myproject/trunk .&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;b&gt;View merge history:&lt;/b&gt;&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;&quot;svn log&quot; doesn&#39;t display the merge history.  It only shows the merge commit:&lt;/span&gt;&lt;/pre&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;screen&quot;&gt;svn log&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;------------------------------------------------------------------------
r196402 | liz | 2012-11-01 10:39:13 -0700 (Thu, 01 Nov 2012) | 1 line

Merging r196340 through r196401
------------------------------------------------------------------------
r196340 | liz | 2012-10-31 14:52:06 -0700 (Wed, 31 Oct 2012) | 1 line

development branch for new feature&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;span style=&quot;font-family: Arial,Helvetica,sans-serif;&quot;&gt;If need to see the merge history, the option &lt;code&gt;--use-merge-history (-g) can be used with svn log:&lt;/code&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;code&gt;svn log -g&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&lt;code&gt;------------------------------------------------------------------------
r196402 | liz | 2012-11-01 10:39:13 -0700 (Thu, 01 Nov 2012) | 1 line

Merging r196340 through r196401
------------------------------------------------------------------------
r196388 | xyz | 2012-11-01 09:50:28 -0700 (Thu, 01 Nov 2012) | 2 lines
Merged via: r196402

Added new unit tests

------------------------------------------------------------------------
r196340 | liz | 2012-10-31 14:52:06 -0700 (Wed, 31 Oct 2012) | 1 line

development branch for new feature&lt;/code&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;screen&quot;&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class=&quot;screen&quot;&gt;&amp;nbsp;&lt;b&gt; &lt;/b&gt;&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/5946976538672240284/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/11/some-svn-commands.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5946976538672240284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5946976538672240284'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/11/some-svn-commands.html' title='Some svn commands'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-804030584923369653</id><published>2012-07-17T15:08:00.000-07:00</published><updated>2012-10-15T00:28:58.142-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="amazon emr"/><category scheme="http://www.blogger.com/atom/ns#" term="amazon S3"/><category scheme="http://www.blogger.com/atom/ns#" term="RDS"/><category scheme="http://www.blogger.com/atom/ns#" term="security group"/><category scheme="http://www.blogger.com/atom/ns#" term="Sqoop"/><title type='text'>Run Sqoop on Amazon Elastic MapReduce (EMR) with Amazon RDS</title><content type='html'>Amazon EMR doesn&#39;t have Sqoop installed.&amp;nbsp; It is possible to run Sqoop with Amazon EMR.&amp;nbsp; The following blog shows how to install and run Sqoop:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://blog.kylemulka.com/2012/04/how-to-install-sqoop-on-amazon-elastic-map-reduce-emr/&quot;&gt;http://blog.kylemulka.com/2012/04/how-to-install-sqoop-on-amazon-elastic-map-reduce-emr/&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
However, the solution isn&#39;t perfect since the input files are usually in S3 and Sqoop doesn&#39;t support S3 directly.&amp;nbsp; Here is my script to install sqoop and export data from S3 to Amazon RDS (mysql):&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;#!/bin/bash&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;BUCKET_NAME=zli-emr-test&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;SQOOP_FOLDER=sqoop-1.4.1-incubating__hadoop-0.20&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;SQOOP_TAR=$SQOOP_FOLDER.tar.gz&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;##change to home directory&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;cd ~&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;##Install sqoop on emr&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;hadoop fs -copyToLocal s3n://$BUCKET_NAME/$SQOOP_TAR $SQOOP_TAR&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;tar -xzf $SQOOP_TAR&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;##Install jdbc driver (ex mysql-connection-java.jar) to sqoop lib folder&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;hadoop fs -copyToLocal s3n://$BUCKET_NAME/mysql-connector-java-5.1.19.jar ~/$SQOOP_FOLDER/lib/&lt;/span&gt;&lt;/i&gt; &lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;##Copy input file from S3 to hdf&lt;/span&gt;&lt;/i&gt; &lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;HADOOP_INPUT=hdfs:///user/hadoop/myinput&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;hadoop distcp s3://$BUCKET_NAME/myinput $HADOOP_INPUT&lt;/span&gt;&lt;/i&gt; &lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/i&gt;
&lt;i&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;~/$SQOOP_FOLDER/bin/sqoop export --connect jdbc:mysql://RDS-Host-name:3306/DB_NAME --username USERNAME --password PASSWORD --table TABLE_NAME --export-dir $HADOOP_INPUT --input-fields-terminated-by=&#39;\t&#39;&lt;/span&gt;&lt;/i&gt;&lt;/blockquote&gt;
The script assumes that sqoop tar ball and mysql-connector-java.jar are in S3 bucket, as well as the input file are in S3 too. &lt;br /&gt;
&lt;br /&gt;
Note that, RDS needs to be configured to allow access to the database with the following 2 EC2 security groups:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
ElasticMapReduce-master&lt;br /&gt;
ElasticMapReduce-slave&lt;/blockquote&gt;
</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/804030584923369653/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/07/run-sqoop-on-amazon-elastic-mapreduce.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/804030584923369653'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/804030584923369653'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/07/run-sqoop-on-amazon-elastic-mapreduce.html' title='Run Sqoop on Amazon Elastic MapReduce (EMR) with Amazon RDS'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-5059296775835194504</id><published>2012-07-10T14:37:00.001-07:00</published><updated>2012-07-10T15:26:13.774-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="command line"/><category scheme="http://www.blogger.com/atom/ns#" term="custom jar"/><category scheme="http://www.blogger.com/atom/ns#" term="elastic map reduce"/><category scheme="http://www.blogger.com/atom/ns#" term="emr"/><category scheme="http://www.blogger.com/atom/ns#" term="hadoop"/><title type='text'>Run custom jar with elastic map reduce (EMR) on command line</title><content type='html'>I followed the instruction to run a custom jar on EMR:&lt;br /&gt;
&lt;br /&gt;
http://aws.amazon.com/articles/3938&lt;br /&gt;
&lt;br /&gt;
I got stuck with step 5:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
5. Run the job flow. &lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt; $ ./elasticmapreduce-client.rb RunJobFlow streaming_jobflow.json &lt;/pre&gt;
&lt;/blockquote&gt;
I couldn&#39;t find file &quot;elasticmapreduce-client.rb&quot; at all.&amp;nbsp; After some online searches, I got it work.&amp;nbsp; The correct command is:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
./elastic-mapreduce --create --json &lt;i&gt;path/to/your/flow&lt;/i&gt;&lt;/blockquote&gt;
Here is my flow file looks like:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;&amp;nbsp; [ &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;Name&quot;: &quot;Custom Jar Grep Example 1&quot;, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;ActionOnFailure&quot;: &quot;CONTINUE&quot;, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;HadoopJarStep&quot;: &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;Jar&quot;: &quot;s3n://YOUR_BUCKET/hadoop-examples-0.20.2-cdh3u4.jar&quot;,&lt;/blockquote&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; ##&quot;MainClass&quot;: &quot;fully-qualified-class-name&quot;,&amp;nbsp; &lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;Args&quot;: &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;grep&quot;, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;s3n://YOUR_BUCKET/input/example&quot;, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;s3n://YOUR_BUCKET/output/example&quot;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &quot;dfs[a-z.]+&quot; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ] &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;
&amp;nbsp;&amp;nbsp; ]&lt;/blockquote&gt;
The flow is corresponding to the following hadoop command:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;hadoop jar hadoop-examples-0.20.2-cdh3u4.jar grep input output &#39;dfs[a-z.]+&#39;&lt;/i&gt;&lt;/blockquote&gt;
&lt;br /&gt;
Some useful tips:&lt;br /&gt;
&lt;br /&gt;
1. show the log:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;./elastic-mapreduce --jobflow JOB_ID --logs &lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/5059296775835194504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/07/run-custom-jar-with-elastic-map-reduce.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5059296775835194504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/5059296775835194504'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/07/run-custom-jar-with-elastic-map-reduce.html' title='Run custom jar with elastic map reduce (EMR) on command line'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-8169622585331701750</id><published>2012-06-29T13:25:00.000-07:00</published><updated>2012-06-29T13:25:20.667-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Java heap space"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="maven-surefire-plugin"/><category scheme="http://www.blogger.com/atom/ns#" term="mvn"/><category scheme="http://www.blogger.com/atom/ns#" term="OutOfMemoryError"/><category scheme="http://www.blogger.com/atom/ns#" term="plugin"/><category scheme="http://www.blogger.com/atom/ns#" term="test"/><category scheme="http://www.blogger.com/atom/ns#" term="unit test"/><title type='text'>mvn test: LocalJobRunner.java with java.lang.OutOfMemoryError</title><content type='html'>When I run mvn test to unit test some hadoop related program, I got the following:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;java.lang.OutOfMemoryError: Java heap space&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.&amp;lt;init&amp;gt;(MapTask.java:949)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:428)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at org.apache.hadoop.mapred.MapTask.run(MapTask.java:372)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:212)&lt;/i&gt;&lt;/blockquote&gt;
I tried to set MAVEN_OPTS=-Xmx2048m, but it didn&#39;t work. &amp;nbsp; After the online research, I fixed this problem by adding the following to pom:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-surefire-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;argLine&amp;gt;-Xms256m -Xmx512m&amp;lt;/argLine&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/8169622585331701750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/mvn-test-localjobrunnerjava-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8169622585331701750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8169622585331701750'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/mvn-test-localjobrunnerjava-with.html' title='mvn test: LocalJobRunner.java with java.lang.OutOfMemoryError'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-4568175418679648516</id><published>2012-06-28T14:04:00.002-07:00</published><updated>2012-11-21T11:33:20.240-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="jar"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="shade"/><title type='text'>maven shade plugin: Invalid signature file digest for Manifest main attributes</title><content type='html'>If you get the following error message with maven shade plugin:&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Exception in thread &quot;main&quot; java.lang.SecurityException: Invalid signature file digest for Manifest main attributes&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
You need to add the following to pom.xml:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;filters&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;filter&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifact&amp;gt;*:*&amp;lt;/artifact&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;excludes&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exclude&amp;gt;META-INF/*.SF&amp;lt;/exclude&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exclude&amp;gt;META-INF/*.DSA&amp;lt;/exclude&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exclude&amp;gt;META-INF/*.RSA&amp;lt;/exclude&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/excludes&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/filter&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/filters&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Explanation:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The above configuration filters all files in META-INF ending with .SF, .DSA, and .RSA for all artifacts (*:*) when creating uber-jar file.&lt;br /&gt;
&lt;br /&gt;
The reason &lt;i&gt;java.lang.SecurityException&lt;/i&gt; is raised is because some dependency jar files are signed jar files.&amp;nbsp; A jar file is signed by using &lt;i&gt;&lt;a href=&quot;http://download.java.net/jdk8/docs/technotes/tools/solaris/jarsigner.html&quot; target=&quot;_blank&quot;&gt;jarsigner&lt;/a&gt;&lt;/i&gt;, which creates 2 additional files and places them in META-INF:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;a signature file, with a .SF extension, and&lt;/li&gt;
&lt;li&gt;a signature block file, with a .DSA, .RSA, or .EC
extension.&lt;/li&gt;
&lt;/ul&gt;
Since the uber-jar file is created, the signatures and integrity of signed JAR
files are no longer valid.&amp;nbsp; When the uber-jar file is executed, &lt;i&gt;java.lang.SecurityException&lt;/i&gt; is thrown&lt;i&gt;.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;
See &lt;a href=&quot;http://download.java.net/jdk8/docs/technotes/tools/solaris/jarsigner.html&quot; target=&quot;_blank&quot;&gt;&lt;i&gt;jarsigner&lt;/i&gt;&lt;/a&gt; for detailed explanation of &lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;JAR Signing and Verification Tool.&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/4568175418679648516/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/maven-shade-plugin-invalid-signature.html#comment-form' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4568175418679648516'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4568175418679648516'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/maven-shade-plugin-invalid-signature.html' title='maven shade plugin: Invalid signature file digest for Manifest main attributes'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-1609737284357265490</id><published>2012-06-24T17:59:00.000-07:00</published><updated>2012-06-24T20:06:31.818-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="jaxb"/><category scheme="http://www.blogger.com/atom/ns#" term="m2eclipse"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="maven-jaxb2-plugin"/><category scheme="http://www.blogger.com/atom/ns#" term="mvn"/><category scheme="http://www.blogger.com/atom/ns#" term="plugin execution not covered by lifecycle configuration"/><title type='text'>Eclipse: fix plugin execution not covered by lifecycle configuration</title><content type='html'>I recently used maven-jaxb2-plugin to generate java classes based on xml schemas (xsd).&amp;nbsp; I can run &quot;mvn compile&quot; on command line to generate java classes with the following configuration:&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;i&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;groupId&amp;gt;org.jvnet.jaxb2.maven2&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;artifactId&amp;gt;maven-jaxb2-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;goal&amp;gt;generate&amp;lt;/goal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;/plugin&amp;gt;&lt;/i&gt;&lt;br /&gt;
However, my Eclipse shows the following error:&lt;br /&gt;
&lt;i&gt; &lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Plugin execution not covered by lifecycle configuration: org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.8.1:generate (execution: default, phase: generate-sources)&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;
This error prevents Eclipse generating java source codes and adding the generated sources to the class path.&amp;nbsp; In order to fix this problem, I need to install m2e connector for maven-jaxb2-plugin.&amp;nbsp; I can manually install it to Eclipse with the following update site:&lt;br /&gt;
&lt;br /&gt;
http://bitstrings.github.com/m2e-connectors-p2/milestones/&lt;br /&gt;
&lt;br /&gt;
However, Eclipse provides a better to install it.&amp;nbsp; Eclipse shows the problem with the following:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg77sNjM5aHu1tyPmiNPglrnOnFednET0IHPiKDStiugWPck0HqxxFYennohysgISEOqkz1r4Gan15FhvjHPzyjx7zArYXFsPm4BximmQjp-drpiU_lg7HDW-daCc9NeNqqzORgJ34mPWBq/s1600/Screen+Shot+2012-06-24+at+5.46.39+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;114&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg77sNjM5aHu1tyPmiNPglrnOnFednET0IHPiKDStiugWPck0HqxxFYennohysgISEOqkz1r4Gan15FhvjHPzyjx7zArYXFsPm4BximmQjp-drpiU_lg7HDW-daCc9NeNqqzORgJ34mPWBq/s320/Screen+Shot+2012-06-24+at+5.46.39+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Roll the mouse over &amp;lt;execution&amp;gt;, it displays the following:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu2nCAx_Qv7UASo2z4aevQKtSlrEezfgvKjSsvb6jXmZvZgAPxLgMNqSHxtVJvI9Y9c-iSfKqtE2tUseqgCTl75PdNHNhrWqeYuD3oHYdKlXjh-KqSmID2ncK1zMDGpt_IBVNJzD_DNSig/s1600/Screen+Shot+2012-06-24+at+5.49.48+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;66&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu2nCAx_Qv7UASo2z4aevQKtSlrEezfgvKjSsvb6jXmZvZgAPxLgMNqSHxtVJvI9Y9c-iSfKqtE2tUseqgCTl75PdNHNhrWqeYuD3oHYdKlXjh-KqSmID2ncK1zMDGpt_IBVNJzD_DNSig/s320/Screen+Shot+2012-06-24+at+5.49.48+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Click the link &quot;Discover new m2e connector&quot;, and eclipse will try to find the correct&amp;nbsp; connector automatically:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6nslR5RuRsnmBUP2OR0Z4HInvzmSjC1pf5LTHI3wQ0VphAGWfn222HMEy73SUbsyTKuvJZQrCy9OLyWqkNweUN-QxRSigq-TmOtHndfwaA7VqFh3wj-WM3kCHHlOe-VBy2PCA7a2H5Nmo/s1600/Screen+Shot+2012-06-24+at+5.52.53+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;182&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6nslR5RuRsnmBUP2OR0Z4HInvzmSjC1pf5LTHI3wQ0VphAGWfn222HMEy73SUbsyTKuvJZQrCy9OLyWqkNweUN-QxRSigq-TmOtHndfwaA7VqFh3wj-WM3kCHHlOe-VBy2PCA7a2H5Nmo/s320/Screen+Shot+2012-06-24+at+5.52.53+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Eclipse found the same m2e connector.&amp;nbsp; Click finish to install it.&amp;nbsp; After I installed it successfully, Eclipse is happy with &lt;i&gt;maven-jaxb2-plugin.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
This approach can be applied to other plugins too.&lt;i&gt; &lt;/i&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/1609737284357265490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/eclipse-fix-plugin-execution-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/1609737284357265490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/1609737284357265490'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/eclipse-fix-plugin-execution-not.html' title='Eclipse: fix plugin execution not covered by lifecycle configuration'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg77sNjM5aHu1tyPmiNPglrnOnFednET0IHPiKDStiugWPck0HqxxFYennohysgISEOqkz1r4Gan15FhvjHPzyjx7zArYXFsPm4BximmQjp-drpiU_lg7HDW-daCc9NeNqqzORgJ34mPWBq/s72-c/Screen+Shot+2012-06-24+at+5.46.39+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-6556829496939380242</id><published>2012-06-08T14:30:00.001-07:00</published><updated>2013-06-04T09:52:25.665-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="CORS"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="jsonp"/><category scheme="http://www.blogger.com/atom/ns#" term="rest"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring MVC"/><title type='text'>Enable CORS support in REST services with Spring 3.1</title><content type='html'>We are working on a web project, which has 2 components, UI and web services.&amp;nbsp; These 2 components are deployed to 2 different servers.&amp;nbsp; UI uses jQuery to make ajax call&amp;nbsp; to back end restful web services. Back end web services use Spring 3.1 MVC framework.&amp;nbsp; We are facing the XSS (cross site scripting) issue since modern browsers don&#39;t allow XSS.&lt;br /&gt;
&lt;br /&gt;
The back end rest web services support HTTP methods GET, POST, PUT and DELETE.&amp;nbsp; The first problem we solved was how to call HTTP method GET from UI using jQuery.&amp;nbsp; Since I used JSONP before, it is a natural solution to me to use JSONP again.&amp;nbsp; My coworker already blog the solution here: http://www.iceycake.com/2012/06/xml-json-jsonp-web-service-endpoints-spring-3-1.&lt;br /&gt;
&lt;br /&gt;
However,&amp;nbsp; JSONP only supports GET, and you can&#39;t set http headers with JSONP request.&amp;nbsp; I also realized that JSONP is kind of out-of-dated too.&amp;nbsp; So how to support other methods like PUT, POST?&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
CORS, &lt;a href=&quot;http://www.w3.org/TR/cors/&quot;&gt;Cross-Origin Resource Sharing&lt;/a&gt;, defines a mechanism to enable client-side cross-origin requests.&amp;nbsp; CORS are widely supported by modern browsers like FireFox, Chrome, Safari, and IE.&lt;br /&gt;
&lt;br /&gt;
The UI code is fairly simple:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;jquery.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&quot;application/javascript&quot;&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
(function($) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var url = &#39;http://localhost:8080/employee/id&#39;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; $.ajax({&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type: &#39;put&#39;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; url: url,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; async: true,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; contentType: &#39;application/json&#39;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data: &#39;{&quot;id&quot;: 1, &quot;name&quot;: &quot;John Doe&quot;}&#39;,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; success: function(response) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(&quot;success&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; },&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; error: function(xhr) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(&#39;Error!&amp;nbsp; Status = &#39; + xhr.status + &quot; Message = &quot; + xhr.statusText);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; });&lt;br /&gt;
})(jQuery);&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- we will add our HTML content here --&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;/blockquote&gt;
If you just run the above javascript and call the backend, you may notice that the PUT request is changed to OPTIONS.&amp;nbsp; The browser sends an OPTIONS request to the server, and the server needs to send response with correct headers.&amp;nbsp; So in order to return the correct response, a filter is created (thanks to the link https://gist.github.com/2232095):&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
package com.zhentao; &lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
import java.io.IOException;&lt;br /&gt;
import javax.servlet.FilterChain;&lt;br /&gt;
import javax.servlet.ServletException;&lt;br /&gt;
import javax.servlet.http.HttpServletRequest;&lt;br /&gt;
import javax.servlet.http.HttpServletResponse;&lt;br /&gt;
import org.springframework.web.filter.OncePerRequestFilter;&lt;br /&gt;
public class CorsFilter extends OncePerRequestFilter {&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throws ServletException, IOException {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (request.getHeader(&quot;Access-Control-Request-Method&quot;) != null &amp;amp;&amp;amp; &quot;OPTIONS&quot;.equals(request.getMethod())) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // CORS &quot;pre-flight&quot; request&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.addHeader(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.addHeader(&quot;Access-Control-Allow-Methods&quot;, &quot;GET, POST, PUT, DELETE&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.addHeader(&quot;Access-Control-Allow-Headers&quot;, &quot;Content-Type&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; response.addHeader(&quot;Access-Control-Max-Age&quot;, &quot;1800&quot;);//30 min&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filterChain.doFilter(request, response);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
}&lt;/blockquote&gt;
&amp;nbsp;The web.xml needs adding the following too:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &lt;i&gt;&amp;lt;filter&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;filter-name&amp;gt;cors&amp;lt;/filter-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;filter-class&amp;gt;com.zhentao.CorsFilter&amp;lt;/filter-class&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/filter&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;filter-mapping&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;filter-name&amp;gt;cors&amp;lt;/filter-name&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;url-pattern&amp;gt;/*&amp;lt;/url-pattern&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/filter-mapping&amp;gt;&lt;/i&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/blockquote&gt;
However, this isn&#39;t enough yet.&amp;nbsp; The original post didn&#39;t address it.&amp;nbsp; You still need to change your rest web services to return Accept-Controll-Allow-Origin header since HTTP is stateless.&amp;nbsp; Here is what I did with Spring Rest api:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; @RequestMapping(value = &quot;/employee/{id}&quot;, method = RequestMethod.PUT, consumes = {&quot;application/json&quot;})&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; public ResponseEntity&amp;lt;Employee&amp;gt; create(@Valid @RequestBody Employee employee, @PathVariable String id)&amp;nbsp; &lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; employee.setId(id);//some logic here&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpHeaders headers = new HttpHeaders();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; headers.add(&quot;Access-Control-Allow-Origin&quot;, &quot;*&quot;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ResponseEntity&amp;lt;Employee&amp;gt; entity = new ResponseEntity&amp;lt;Employee&amp;gt;(headers, HttpStatus.CREATED);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return entity; &lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/blockquote&gt;
Update: it seems my post caused some confusion, and I created another post and fully working examples for CORS. See &lt;a href=&quot;http://zhentao-li.blogspot.com/2013/06/example-for-enabling-cors-support-in.html&quot;&gt;here&lt;/a&gt;. </content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/6556829496939380242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/enable-cors-support-in-rest-services.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6556829496939380242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6556829496939380242'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/06/enable-cors-support-in-rest-services.html' title='Enable CORS support in REST services with Spring 3.1'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-4899478473735568060</id><published>2012-05-30T15:40:00.000-07:00</published><updated>2012-05-30T15:40:03.350-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="filter text"/><category scheme="http://www.blogger.com/atom/ns#" term="log4j"/><title type='text'>log4j filter some text and don&#39;t log it</title><content type='html'>Use org.apache.log4j.varia.StringMatchFilter to filter the text not to display.&amp;nbsp; Here is the example for log4j.xml:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE log4j:configuration SYSTEM &quot;log4j.dtd&quot;&amp;gt;&lt;br /&gt;&amp;lt;log4j:configuration xmlns:log4j=&quot;http://jakarta.apache.org/log4j/&quot;&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;appender name=&quot;console&quot; class=&quot;org.apache.log4j.ConsoleAppender&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;layout class=&quot;org.apache.log4j.PatternLayout&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name=&quot;ConversionPattern&quot; value=&quot;%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/layout&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;filter class=&quot;org.apache.log4j.varia.StringMatchFilter&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name=&quot;StringToMatch&quot; value=&quot;the-text-not-to-log&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;param name=&quot;AcceptOnMatch&quot; value=&quot;false&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/filter&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- &amp;lt;filter class=&quot;org.apache.log4j.varia.DenyAllFilter&quot; /&amp;gt; --&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/appender&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;lt;root&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;priority value=&quot;info&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;appender-ref ref=&quot;console&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/root&amp;gt;&lt;br /&gt;&amp;lt;/log4j:configuration&amp;gt;&lt;/blockquote&gt;
Then run the following to test:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOG.info(&quot;This is an info and shouldn&#39;t be logged with the-text-not-to-log and blah blah&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOG.info(&quot;This is logged&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOG.debug(&quot;This is a debug and not logged&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOG.error(&quot;This is an error and logged&quot;); &lt;br /&gt;
&lt;br /&gt;
If you only want to log some text, then change the value for AcceptOnMatch to &lt;i&gt;&lt;b&gt;true&lt;/b&gt;&lt;/i&gt; and add &lt;i&gt;&lt;b&gt;DenyAllFilter&lt;/b&gt;&lt;/i&gt;.</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/4899478473735568060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/log4j-filter-some-text-and-dont-log-it.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4899478473735568060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/4899478473735568060'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/log4j-filter-some-text-and-dont-log-it.html' title='log4j filter some text and don&#39;t log it'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-6158834316666599037</id><published>2012-05-23T16:01:00.001-07:00</published><updated>2012-05-23T16:01:09.057-07:00</updated><title type='text'>mac: no acceptable C compiler found in $PATH</title><content type='html'>If you get the following error on mac:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;i&gt;configure: error: no acceptable C compiler found in $PATH&lt;/i&gt;&lt;/blockquote&gt;
Here is the step to fix it:&lt;br /&gt;&lt;br /&gt;1. download Xcode from https://developer.apple.com/downloads/index.action&lt;br /&gt;2. install Xcode&lt;br /&gt;3. Open Xcode, go to Preferences --&amp;gt; Downloads --&amp;gt; install &quot;Command Line Tools&quot;&lt;br /&gt;4. relaunch terminal</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/6158834316666599037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/mac-no-acceptable-c-compiler-found-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6158834316666599037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/6158834316666599037'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/mac-no-acceptable-c-compiler-found-in.html' title='mac: no acceptable C compiler found in $PATH'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-1648455399851297910</id><published>2012-05-19T13:27:00.000-07:00</published><updated>2012-05-19T13:27:13.248-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="config"/><category scheme="http://www.blogger.com/atom/ns#" term="EnableTransactionManagement"/><category scheme="http://www.blogger.com/atom/ns#" term="jdbc"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring"/><category scheme="http://www.blogger.com/atom/ns#" term="transaction"/><title type='text'>Enable Spring Jdbc Transaction with Annotation</title><content type='html'>Spring 3.1 introduced a new annotation &lt;i&gt;@EnableTransactionManagement&lt;/i&gt;.&amp;nbsp; With it, all xml configuration can be got rid of now.&amp;nbsp; Here is the example on how to use it:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;br /&gt;@Configuration&lt;br /&gt;@EnableTransactionManagement&lt;br /&gt;public class JdbcConfig {&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Bean&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public DataSource dataSource() {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;//config datasource&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Bean&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public PlatformTransactionManager txManager() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new DataSourceTransactionManager(dataSource());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Bean&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public MyDao myDao() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyDaoJdbc dao = new MyDaoJdbc();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dao.setDataSource(dataSource());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return dao;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/blockquote&gt;
Next you need to annote your dao with @Transactional.&amp;nbsp; The source code can be found at github:&lt;br /&gt;
&lt;br /&gt;
https://github.com/zhentao/spring-jdbc-transaction-example &lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/1648455399851297910/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/enable-spring-jdbc-transaction-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/1648455399851297910'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/1648455399851297910'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/enable-spring-jdbc-transaction-with.html' title='Enable Spring Jdbc Transaction with Annotation'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-8173342123361136972</id><published>2012-05-19T13:03:00.000-07:00</published><updated>2012-05-19T13:03:23.959-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cobertura"/><category scheme="http://www.blogger.com/atom/ns#" term="exclude"/><category scheme="http://www.blogger.com/atom/ns#" term="ignore"/><category scheme="http://www.blogger.com/atom/ns#" term="maven"/><category scheme="http://www.blogger.com/atom/ns#" term="plugin"/><title type='text'>cobertura-maven-plugin</title><content type='html'>Recently I created a parent pom for my team to use.&amp;nbsp; All my team&#39;s projects need to inherit this parent pom.&amp;nbsp; This parent pom is rather simple:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;lt;properties&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;default.encoding&amp;gt;UTF-8&amp;lt;/default.encoding&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;default.jdk&amp;gt;1.6&amp;lt;/default.jdk&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;line.coverage.target&amp;gt;90&amp;lt;/line.coverage.target&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;branch.coverage.target&amp;gt;90&amp;lt;/branch.coverage.target&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/properties&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;lt;build&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;defaultGoal&amp;gt;install&amp;lt;/defaultGoal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;pluginManagement&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugins&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.3.2&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;source&amp;gt;${default.jdk}&amp;lt;/source&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;target&amp;gt;${default.jdk}&amp;lt;/target&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;encoding&amp;gt;${default.encoding}&amp;lt;/encoding&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-source-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.1.2&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-resources-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;encoding&amp;gt;${default.encoding}&amp;lt;/encoding&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-javadoc-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.8&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;encoding&amp;gt;${default.encoding}&amp;lt;/encoding&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-release-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.2.2&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Sonar uses these versions, below --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-pmd-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.7.1&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;targetJdk&amp;gt;${default.jdk}&amp;lt;/targetJdk&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;encoding&amp;gt;${default.encoding}&amp;lt;/encoding&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-checkstyle-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.9.1&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;encoding&amp;gt;${default.encoding}&amp;lt;/encoding&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;cobertura-maven-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.5.1&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-surefire-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;version&amp;gt;2.12&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugins&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/pluginManagement&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugins&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;cobertura-maven-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;check&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Per-class thresholds --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;branchRate&amp;gt;${branch.coverage.target}&amp;lt;/branchRate&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;lineRate&amp;gt;${line.coverage.target}&amp;lt;/lineRate&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Project-wide thresholds --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;totalLineRate&amp;gt;${line.coverage.target}&amp;lt;/totalLineRate&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;totalBranchRate&amp;gt;${branch.coverage.target}&amp;lt;/totalBranchRate&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/check&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;formats&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;format&amp;gt;html&amp;lt;/format&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/formats&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;phase&amp;gt;package&amp;lt;/phase&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;goal&amp;gt;clean&amp;lt;/goal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;goal&amp;gt;cobertura&amp;lt;/goal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;goal&amp;gt;check&amp;lt;/goal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-surefire-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;!-- Ensure that source code is packaged and deployed for inclusion into IDEs --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;maven-source-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;phase&amp;gt;package&amp;lt;/phase&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;goal&amp;gt;jar&amp;lt;/goal&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/goals&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/execution&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/executions&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugins&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/build&amp;gt;&lt;/blockquote&gt;
We are targeting a pretty high unit test coverage, 90% for both line and branch coverage.&amp;nbsp; However, some classes don&#39;t need unit test or don&#39;t need high coverage.&amp;nbsp; Then each individual project can include the following to its project pom:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;build&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugins&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;groupId&amp;gt;org.codehaus.mojo&amp;lt;/groupId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;artifactId&amp;gt;cobertura-maven-plugin&amp;lt;/artifactId&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;instrumentation&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ignores&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ignore&amp;gt;org.slf4j.*&amp;lt;/ignore&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/ignores&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;excludes&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exclude&amp;gt;com/zhentao/Some.class&amp;lt;/exclude&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;exclude&amp;gt;com/zhentao/other.class&amp;lt;/exclude&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/excludes&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/instrumentation&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugin&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/plugins&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;/build&amp;gt;&lt;/blockquote&gt;
&amp;nbsp;&amp;lt;ignore&amp;gt;org.slf4j.*&amp;lt;/ignore&amp;gt; ignores all log statement in the code since we don&#39;t need to test logs.&lt;br /&gt;
&amp;lt;exclude&amp;gt;com/zhentao/Some.class&amp;lt;/exclude&amp;gt; excludes Some.class from the cobertura report.&lt;br /&gt;
&lt;br /&gt;
However, this flexibility can be abused by some developers.&amp;nbsp; I got an build failed notification today:&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;pre&gt;&lt;i&gt;&lt;b&gt;11:52:52&lt;/b&gt;  &lt;/i&gt;&lt;i&gt;Archiving artifacts
&lt;b&gt;11:52:52&lt;/b&gt;  [htmlpublisher] Archiving HTML reports...
&lt;b&gt;11:52:52&lt;/b&gt;  [htmlpublisher] Archiving at PROJECT level /target/site/cobertura to /htmlreports/Cobertura_Report
&lt;b&gt;11:52:52&lt;/b&gt;  ERROR: Specified HTML directory &#39;/target/site/cobertura&#39; does not exist.
&lt;b&gt;11:52:52&lt;/b&gt;  Build step &#39;Publish HTML reports&#39; changed build result to FAILURE&lt;/i&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&amp;nbsp;One developer excluded all classes from testing.&amp;nbsp; What a developer!</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/8173342123361136972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/cobertura-maven-plugin.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8173342123361136972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/8173342123361136972'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/cobertura-maven-plugin.html' title='cobertura-maven-plugin'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6816360065241545754.post-7955900249186196572</id><published>2012-05-04T10:29:00.000-07:00</published><updated>2012-05-04T10:29:25.175-07:00</updated><title type='text'>Yahoo hadoop tutorials</title><content type='html'>This is the link from yahoo for hadoop tutorials:&lt;br /&gt;
&lt;br /&gt;
http://developer.yahoo.com/hadoop/tutorial/index.html</content><link rel='replies' type='application/atom+xml' href='http://zhentao-li.blogspot.com/feeds/7955900249186196572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/yahoo-hadoop-tutorials.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/7955900249186196572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6816360065241545754/posts/default/7955900249186196572'/><link rel='alternate' type='text/html' href='http://zhentao-li.blogspot.com/2012/05/yahoo-hadoop-tutorials.html' title='Yahoo hadoop tutorials'/><author><name>zhentao</name><uri>http://www.blogger.com/profile/05719795252682912081</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>