<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>akquinet-blog</title>
	<atom:link href="http://blog.akquinet.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.akquinet.de</link>
	<description>akquinet blog</description>
	<lastBuildDate>Wed, 01 Feb 2012 17:36:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.akquinet.de' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>akquinet-blog</title>
		<link>http://blog.akquinet.de</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.akquinet.de/osd.xml" title="akquinet-blog" />
	<atom:link rel='hub' href='http://blog.akquinet.de/?pushpress=hub'/>
		<item>
		<title>Deploying applications continuously with SCP</title>
		<link>http://blog.akquinet.de/2012/01/31/deploying-applications-continuously-with-scp/</link>
		<comments>http://blog.akquinet.de/2012/01/31/deploying-applications-continuously-with-scp/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 15:05:51 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[continous]]></category>
		<category><![CDATA[continuous delivery]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[hudson]]></category>
		<category><![CDATA[JBOSS]]></category>
		<category><![CDATA[jenkins]]></category>
		<category><![CDATA[SCP]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1712</guid>
		<description><![CDATA[The last blog post (Jumping into continuous delivery with Jenkins and SSH) demonstrated how to build and deploy an application continuously using Jenkins, SSH and Nexus. In that scenario, the application was packaged and deployed on Nexus by Jenkins, and then retrieved from Nexus by the host. However, what about doing it without Nexus? You might [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1712&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The last blog post (<a href="http://blog.akquinet.de/2012/01/10/jumping-into-continuous-delivery-with-jenkins-and-ssh/" title="Jumping into continuous delivery with Jenkins and SSH" target="_blank">Jumping into continuous delivery with Jenkins and SSH</a>) demonstrated how to build and deploy an application continuously using <a href="http://jenkins-ci.org/" title="Jenkins CI" target="_blank">Jenkins</a>, SSH and <a href="http://nexus.sonatype.org/" title="Sonatype Nexus" target="_blank">Nexus</a>. In that scenario, the application was packaged and deployed on Nexus by Jenkins, and then retrieved from Nexus by the host. However, what about doing it without Nexus? You might have no other need for Nexus or even Maven. Or perhaps you prefer to deploy your application only after you have tested it in several environments. So, how to deploy your application without Nexus? </p>
<p>This post explains how to use the Jenkins SCP plugin to copy the freshly built application to another machine using SCP. This is useful when you need to copy an application to a specific machine or another environment without exposing it publicly. </p>
<p>Although this post is focused on Jenkins, other continuous integration servers have equivalent capabilities.<br />
<span id="more-1712"></span></p>
<h3>Why copying instead of deploying to a repository?</h3>
<p>In addition to the fact that you may not use Nexus or Maven, there are a couple more advantages to copying an application instead of publishing it. </p>
<p>First, using copies, your application is kept private. Your artifact must cross the whole test pipeline before being published to a repository. So, you know that your team won&#8217;t rely on an untested (or at least, not completely tested) artifact. </p>
<p>Secondly, <em>all</em> the versions built by Jenkins will be copied. The previous approach used only the latest, which runs the risk of skipping some versions, making it hard to know when a regression was introduced.</p>
<p>Let’s move on and modify the pipeline. Our previous pipeline was the following:<br />
<div id="attachment_1692" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2012/01/big_picture1.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/big_picture1.png?w=440&#038;h=223" alt="The journey of the source code from the developer machine to the test environment" title="The journey of the source code from the developer machine to the test environment" width="440" height="223" class="size-full wp-image-1692" /></a><p class="wp-caption-text">The journey of the source code from the developer machine to the test environment</p></div></p>
<p>We update it slightly, to the following:<br />
<div id="attachment_1713" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2012/01/new-pipeline.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/new-pipeline.png?w=440&#038;h=223" alt="A slightly updated pipeline using SCP instead of Nexus" title="Another Journey from the developer computer to live" width="440" height="223" class="size-full wp-image-1713" /></a><p class="wp-caption-text">A slightly updated pipeline using SCP instead of Nexus</p></div></p>
<p>To implement this pipeline, install the Jenkins SCP Publisher Plugin (actually named Hudson SCP Publisher Plugin):</p>
<p><a href="http://akquinetblog.files.wordpress.com/2012/01/hudson-scp-plugin.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/hudson-scp-plugin.png?w=440" alt="" title="Hudson SCP Plugin"   class="aligncenter size-full wp-image-1715" /></a></p>
<p>Then, you need to configure the host on which you want to upload the application. In the global configuration of Jenkins, scroll down to the SCP repository hosts section, and configure your new SCP Site:</p>
<p><a href="http://akquinetblog.files.wordpress.com/2012/01/adding-a-scp-site.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/adding-a-scp-site.png?w=440&#038;h=130" alt="" title="Adding a SCP Site" width="440" height="130" class="aligncenter size-full wp-image-1714" /></a></p>
<p>Note: The SSH and SCP plugins must be configured separately.</p>
<p>Then, in the Jenkins job building the application, we add a post-build action to upload the artifact to the host. Check the ‘Publish artifacts to SCP Repository’ check box, and select the site you added. You also have to select the files you want to upload. In the following picture, we select the war file we’re building:</p>
<div id="attachment_1716" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2012/01/upload-configuration.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/upload-configuration.png?w=440&#038;h=109" alt="Configuration of the uploaded files" title="Configuration of the uploaded files" width="440" height="109" class="size-full wp-image-1716" /></a><p class="wp-caption-text">Configuration of the uploaded files</p></div>
<p>The &#8216;destination&#8217; allows you to define the final location of the file you deploy. This location is relative to the root set in the site configuration. In our case, it’s already the Tomcat deploy folder. You can upload several sets of files, but to only one site. If you have to deploy to several sites/hosts, you will need one job per site/host (making sure that each job deploys the same files).</p>
<p>Once done, we’re good to go. Execute your build, and the files will be uploaded. The rest of the pipeline can be more or less the same as in the <a href="http://blog.akquinet.de/2012/01/10/jumping-into-continuous-delivery-with-jenkins-and-ssh/" title="Jumping into continuous delivery with Jenkins and SSH" target="_blank">previous post</a>, except that now you already have the application in place. If you’re targeting an already running environment supporting hot-deploy, then you don’t even have to do anything else after this deployment. </p>
<h3>Conclusion</h3>
<p>This blog post shows how the Jenkins SCP plugin can be used to support continuous delivery, and actually provision your application to your host. It’s another way to achieve continuous delivery simply. This approach is particularly well suited when your host already contains your application server, and when this application server supports hot-redeployment.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/innovation/'>Innovation</a> Tagged: <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/continous/'>continous</a>, <a href='http://blog.akquinet.de/tag/continuous-delivery/'>continuous delivery</a>, <a href='http://blog.akquinet.de/tag/continuous-integration/'>continuous integration</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/hudson/'>hudson</a>, <a href='http://blog.akquinet.de/tag/jboss/'>JBOSS</a>, <a href='http://blog.akquinet.de/tag/jenkins/'>jenkins</a>, <a href='http://blog.akquinet.de/tag/scp/'>SCP</a>, <a href='http://blog.akquinet.de/tag/tomcat/'>Tomcat</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1712/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1712/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1712/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1712&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2012/01/31/deploying-applications-continuously-with-scp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/big_picture1.png" medium="image">
			<media:title type="html">The journey of the source code from the developer machine to the test environment</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/new-pipeline.png" medium="image">
			<media:title type="html">Another Journey from the developer computer to live</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/hudson-scp-plugin.png" medium="image">
			<media:title type="html">Hudson SCP Plugin</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/adding-a-scp-site.png" medium="image">
			<media:title type="html">Adding a SCP Site</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/upload-configuration.png" medium="image">
			<media:title type="html">Configuration of the uploaded files</media:title>
		</media:content>
	</item>
		<item>
		<title>Jumping into continuous delivery with Jenkins and SSH</title>
		<link>http://blog.akquinet.de/2012/01/10/jumping-into-continuous-delivery-with-jenkins-and-ssh/</link>
		<comments>http://blog.akquinet.de/2012/01/10/jumping-into-continuous-delivery-with-jenkins-and-ssh/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 15:49:19 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[Continuous]]></category>
		<category><![CDATA[Delivery]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[hudson]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[javaEE]]></category>
		<category><![CDATA[jenkins]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[nexus]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1683</guid>
		<description><![CDATA[Let’s imagine the following situation. You’re working on an application for a customer. Despite a firm deadline and a roadmap given to your customer, he’d like to check the progress regularly, let’s say weekly or even daily, and actually give you feedback. So to make everybody happy, you start releasing the application weekly. However, releasing is generally [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1683&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let’s imagine the following situation. You’re working on an application for a customer. Despite a <em>firm</em> deadline and a roadmap given to your customer, he’d like to check the progress regularly, let’s say weekly or even daily, and actually give you feedback.</p>
<p>So to make everybody happy, you start releasing the application weekly. However, releasing is generally a hard-core process, even for the most automated processes, and requires human actions. As the release date approaches, stress increases. The tension reaches its climax one hour before the deadline when the release process fails, or worse, when the deployment fails. We&#8217;ve all been in situations like that, right?</p>
<p>This all-too-common nightmare can be largely avoided. This blog post presents a way to deal with the above situation using Jenkins, Nexus and SSH. The application is deployed continuously and without human intervention on a test environment, which can be checked and tested by the customer. Jenkins, a continuous integration server, is used as the orchestrator of the whole continuous delivery process.</p>
<p><span id="more-1683"></span></p>
<h3>The principles of Continuous Delivery</h3>
<p>Continuous Delivery is basically a set of principles to automate the process of software delivery. The overall goal is to continuously deliver new versions of a software system.</p>
<p>It relies on automated testing, continuous integration and automated deployments. The application is packaged and deployed to test and production environments, resulting in the ability to rapidly, reliably and repeatedly push out enhancements and bug fixes to customers at low risk and with minimal manual overhead.</p>
<p>Continuous Delivery is based on the <em>pipeline</em> concept. A delivery pipeline is the process taken by the code from the developer&#8217;s machine to <em>production</em> environments, particularly pipelines defined for the testing stages and the deployment process.</p>
<h3 id="asimplepipeline">A Simple Pipeline</h3>
<p>Continuous delivery can be quite hard to set up for complex systems. We recommend starting with a simple configuration. Let’s take a simple web application deployed on an application server such as Tomcat or JBoss.</p>
<div id="attachment_1692" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2012/01/big_picture1.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/big_picture1.png?w=440&#038;h=223" alt="The journey of the source code from the developer machine to the test environment" title="The journey of the source code from the developer machine to the test environment" width="440" height="223" class="size-full wp-image-1692" /></a><p class="wp-caption-text">The journey of the source code from the developer machine to the test environment</p></div>
<p>The code of our application is hosted on a source code management (SCM) server. It can be Git, Subversion or anything else. It’s the entry point of our pipeline.</p>
<p>Our continuous integration server (Jenkins) pulls the code from the SCM. It builds and tests the application. If all tests are <em>green</em>, the application is packaged and deployed to an artifact repository (Nexus in our context). Then, Jenkins triggers the deployment process.</p>
<p>To achieve this, Jenkins connects to our host machine using SSH, and launches the deployment script. In this example, the deployment script is a simple shell script redeploying and restarting the application.</p>
<p>Finally, when the deployment is done, we check the availability of our web application.</p>
<h3 id="implementingthepipeline">Implementing the pipeline</h3>
<p>The presented pipeline is quite simple, but works pretty well for most web / JavaEE applications. To implement it, we need a Jenkins with two specific plugins (the SSH plugin and the Groovy Plugin) and a host machine available through SSH.</p>
<h4 id="preparingjenkins">Preparing Jenkins</h4>
<p>The first thing you need is to install the plugins in Jenkins: &#8211; The <a href="http://wiki.jenkins-ci.org/display/JENKINS/SSH+plugin">Jenkins SSH plugin</a> allows you to connect to the host machine by SSH and execute commands; the <a href="http://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin">Hudson Groovy Builder</a> to execute Groovy code. We use Groovy to check the deployment result. However, you can use other options (unit tests, nagios…)</p>
<p>Once those two plugins are installed, you need to configure the connection to the host machine. In the Global Configuration page of Jenkins, scroll down to the <em>SSH Remote Host</em> section and add a host. Enter the machine name or the IP address, and the credentials. You can also use a key file.</p>
<div id="attachment_1687" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2012/01/add-ssh-connection-jenkins.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/add-ssh-connection-jenkins.png?w=440&#038;h=186" alt="Add an SSH connection to Jenkins" title="Add an SSH Connection" width="440" height="186" class="size-full wp-image-1687" /></a><p class="wp-caption-text">Add an SSH connection to Jenkins</p></div>
<p>Once done and saved, it’s time to create our Jenkins <em>Jobs</em> supporting our continuous delivery process. To keep this example simple, we divide our process in two jobs:</p>
<ul>
<li>The first job compiles, tests, builds and deploys the application. If successful, the new application archive is deployed on our Nexus repository.</li>
<li>The second job is triggered upon the success of the first job. It connects to the host machine, and executes a shell script. Once done, it executes a simple Groovy script to check the deployment success. We use Groovy for its simplicity in making HTTP connections and retrieving the result. However, you can use plenty of other ways.</li>
</ul>
<p>The first job configuration is not specific to the continuous delivery pipeline. It’s generally a regular job deploying the artifacts to a Maven repository. So, a simple <em>Maven Job</em> executing <em>mvn clean deploy</em> upon a source code update is enough. If you want to divide this job into several steps, have a look at <a href="http://blog.akquinet.de/2011/11/09/building-pipelines-by-linking-jenkins-jobs/">this post</a>. In our example, we deploy the application to a Nexus repository.</p>
<p>The second job is more interesting. Create a new <em>freestyle</em> project job. This job is triggered upon successful execution of the first job. So select <em>None</em> as <em>Source Code Management</em> and indicate the previous job name in the <em>Build after other projects are built</em> option.</p>
<div id="attachment_1689" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2012/01/build-trigger.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/build-trigger.png?w=440&#038;h=188" alt="The build is started when the previous build succeeds" title="The build is started when the previous build succeeds" width="440" height="188" class="size-full wp-image-1689" /></a><p class="wp-caption-text">The build is started when the previous build succeeds</p></div>
<p>In the <em>Build</em> section, add a first build step, and select <em>Execute shell script on remote host using ssh</em>. Select your host, and add the script. You can also use a command directly, and execute a script already present on the host.</p>
<div id="attachment_1690" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2012/01/ssh-script-execution.png"><img src="http://akquinetblog.files.wordpress.com/2012/01/ssh-script-execution.png?w=440&#038;h=135" alt="Launch the deployment script" title="Launch the deployment script" width="440" height="135" class="size-full wp-image-1690" /></a><p class="wp-caption-text">Launch the deployment script</p></div>
<h4 id="preparingtheapplicationhost">Preparing the application host</h4>
<p>At this point, we have a Jenkins job connecting to the host and executing some commands. To simplify, we focus only on the application deployment and not on the environment setup. So we consider that the host is ready to be used. The deployment script follows this basic pattern:<br />
<code><br />
    1) Stop the application<br />
    2) Retrieve the new application<br />
    3) Deploy the new application<br />
    4) Restart the application<br />
</code></p>
<p>First, if the application runs, it should be stopped (except if your application server supports hot-redeployment). Then, we retrieve the application package. This step consists of downloading the latest version of our application from a repository. Once downloaded, the application is deployed, so either copied to a <em>deploy</em> folder, or unpackaged to a specific location. Finally, we restart the application.</p>
<p>Step 1) and 4) are dependent on your application server, but if you’re using Linux upstart scripts, it should be something like:<br />
<pre class="brush: plain;">
stop my_application
...
start my_application
</pre></p>
<p>Or if you&#8217;re using a service:<br />
<pre class="brush: plain;">
/etc/init.d/my_application stop
...
/etc/init.d/my_application start
</pre></p>
<p>To retrieve the latest version of our application, we’re relying on the Nexus REST API and a script to download the latest version. This script is available <a href="https://github.com/cescoffier/puppet-nexus/blob/master/files/download-artifact-from-nexus.sh">here</a>, and so should be available and made executable on your host (Note: this script requires Curl). With this script, getting the latest version of our application is quite simple:</p>
<p><pre class="brush: plain;">
...
download-artifact-from-nexus.sh \
 -a mycompany:myapplication:LATEST \
 -e war \
 -o /tmp/my_application.war \
 -r public-snapshots \
 -n http://mynexus \
 -u username -p password
...
</pre></p>
<p>We first specify the Maven artifact to download, and so use the <em>GroupId:ArtifactId:Version</em> coordinates. We use <em>LATEST</em> as version to download the latest version (a snapshot in our case). The <em>-e</em> parameter indicates the packaging type. Then, we indicate the output directory. The <em>-r</em> option specifies the Maven repository on which the artifact is hosted (check your Nexus configuration to find this value). The other options set the Nexus url and the credentials.</p>
<p>Deploying the application (step 3) depends on your execution environment. It generally consists of copying the downloaded archive to a specific directory.</p>
<p>So, to sum up, the following script can be a valid deployment script for a web application packaged as a war file executed on a Tomcat server:</p>
<p><pre class="brush: plain;">
export WEBAPP=Tomcat webapp folder
stop my_application
download-artifact-from-nexus.sh \
 -a mycompany:myapplication:LATEST \
 -e war \
 -o /tmp/my_application.war \
 -r public-snapshots \
 -n http://mynexus \
 -u username -p password
cp /tmp/my_application.war $WEBAPP
start my_application
</pre></p>
<p>So, if everything is configured correctly, once you commit a change to your application, this change should be deployed <em>immediately</em> to your test environment.</p>
<p>First, your application is tested, built and deployed on a Nexus repository. Then, a second Jenkins job connects to the host machine and runs a deployment script. This script retrieves and deploys the latest version of the application.</p>
<h4 id="checkingthedeployment">Checking the deployment</h4>
<p>An improvement you could make is to check whether the deployment was performed correctly. For that, you can use Groovy. In the second Jenkins job, add a new build step: <em>Execute Groovy Script</em>. In the text area, just do a simple check like:<br />
<pre class="brush: plain;">
Thread.sleep(Startup_time)
def address = &quot;Your_URL&quot;
def url = address.toURL()
println &quot;URL : ${url}&quot;
def connection = url.openConnection()
println &quot;Response Code/Message: ${connection.responseCode} / ${connection.responseMessage}&quot;
assert connection.responseCode == 200
</pre></p>
<p>This simple Groovy script waits a couple of seconds (until your application is actually started), and connects to your application. If the application response is correct, then everything is fine. If not, the build is marked as <em>failed</em>, and you should have a look. Obviously, this simple script can be improved and adapted to your situation.</p>
<h3 id="thisisit">That&#8217;s it!</h3>
<p>This blog post has presented a way to implement continuous delivery for applications using Jenkins, Nexus and a machine accessible using SSH. Obviously other combinations are possible.</p>
<p>Continuous delivery may be hard to achieve in one step, but as illustrated in this post, it can be set up pretty easily to continuously deploy an application to a testing environment.</p>
<p>Thanks to these principles, you make the development more reactive; we can immediately see the changes. Moreover, errors and bugs are detected earlier.</p>
<p>It’s up to you to tune your pipeline to fit your needs. For instance, pushing the application on the test environment nightly, instead of after every change.</p>
<p>akquinet tech@spree is now using continuous delivery principles in several projects. The results are really beneficial. The test campaigns were improved, and thanks to the pipeline, developers can focus on the devleopment of new features and bug fixes, while still seeing their changes <em>immediately</em>.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/innovation/'>Innovation</a> Tagged: <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/continuous/'>Continuous</a>, <a href='http://blog.akquinet.de/tag/delivery/'>Delivery</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/hudson/'>hudson</a>, <a href='http://blog.akquinet.de/tag/integration/'>integration</a>, <a href='http://blog.akquinet.de/tag/javaee/'>javaEE</a>, <a href='http://blog.akquinet.de/tag/jenkins/'>jenkins</a>, <a href='http://blog.akquinet.de/tag/maven/'>Maven</a>, <a href='http://blog.akquinet.de/tag/nexus/'>nexus</a>, <a href='http://blog.akquinet.de/tag/ssh/'>SSH</a>, <a href='http://blog.akquinet.de/tag/tomcat/'>Tomcat</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1683/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1683/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1683/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1683/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1683/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1683/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1683/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1683/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1683&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2012/01/10/jumping-into-continuous-delivery-with-jenkins-and-ssh/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/big_picture1.png" medium="image">
			<media:title type="html">The journey of the source code from the developer machine to the test environment</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/add-ssh-connection-jenkins.png" medium="image">
			<media:title type="html">Add an SSH Connection</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/build-trigger.png" medium="image">
			<media:title type="html">The build is started when the previous build succeeds</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2012/01/ssh-script-execution.png" medium="image">
			<media:title type="html">Launch the deployment script</media:title>
		</media:content>
	</item>
		<item>
		<title>The akquinet tech@spree Technology Radar is now available</title>
		<link>http://blog.akquinet.de/2012/01/06/the-akquinet-techspree-technology-radar-is-now-available/</link>
		<comments>http://blog.akquinet.de/2012/01/06/the-akquinet-techspree-technology-radar-is-now-available/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 13:48:45 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Enterprise Applications]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[User eXperience]]></category>
		<category><![CDATA[2011]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[CDI]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[frameowrk]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[javaEE]]></category>
		<category><![CDATA[JBOSS]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[play!]]></category>
		<category><![CDATA[prediction]]></category>
		<category><![CDATA[radar]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[trends]]></category>
		<category><![CDATA[ui]]></category>

		<guid isPermaLink="false">http://akquinetblog.wordpress.com/?p=1674</guid>
		<description><![CDATA[akquinet tech@spree has published a technology radar analyzing the trends of 2011&#8211;2012. It provides an overview of the evolution of practice in the Information Technology sector in 2011 as well as a forecast for 2012. It is the result of one year of analysis and synthesis performed by the Innovation department of akquinet tech@spree. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1674&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>akquinet tech@spree has published a technology radar analyzing the trends of 2011&#8211;2012. It provides an overview of the evolution of practice in the Information Technology sector in 2011 as well as a forecast for 2012. It is the result of one year of analysis and synthesis performed by the Innovation department of akquinet tech@spree.</p>
<p>The technology radar captures the output from discussions, experiments, projects, and feedback from customers and developers. It synthesizes the results to inform global technology strategy decisions. It focuses on new technologies and methodologies with a high level of attraction. This document does not aim to provide an in-depth presentation of each technology, focusing instead on conciseness and highlighting the trends and state of the practice.</p>
<p>More information on <a href="http://radar.spree.de" title="akquinet tech@spree Technology Radar">http://radar.spree.de</a></p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/enterprise-applications/'>Enterprise Applications</a>, <a href='http://blog.akquinet.de/category/all/innovation/'>Innovation</a>, <a href='http://blog.akquinet.de/category/all/mobile-all/'>Mobile</a>, <a href='http://blog.akquinet.de/category/all/user-experience/'>User eXperience</a> Tagged: <a href='http://blog.akquinet.de/tag/2011/'>2011</a>, <a href='http://blog.akquinet.de/tag/2012/'>2012</a>, <a href='http://blog.akquinet.de/tag/android/'>android</a>, <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/cdi/'>CDI</a>, <a href='http://blog.akquinet.de/tag/css/'>css</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/frameowrk/'>frameowrk</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/html5/'>html5</a>, <a href='http://blog.akquinet.de/tag/ios/'>ios</a>, <a href='http://blog.akquinet.de/tag/javaee/'>javaEE</a>, <a href='http://blog.akquinet.de/tag/jboss/'>JBOSS</a>, <a href='http://blog.akquinet.de/tag/osgi/'>osgi</a>, <a href='http://blog.akquinet.de/tag/play/'>play!</a>, <a href='http://blog.akquinet.de/tag/prediction/'>prediction</a>, <a href='http://blog.akquinet.de/tag/radar/'>radar</a>, <a href='http://blog.akquinet.de/tag/technology/'>technology</a>, <a href='http://blog.akquinet.de/tag/trends/'>trends</a>, <a href='http://blog.akquinet.de/tag/ui/'>ui</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1674/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1674/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1674/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1674&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2012/01/06/the-akquinet-techspree-technology-radar-is-now-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>
	</item>
		<item>
		<title>Patching PicketLink to support multiple LDAP stores</title>
		<link>http://blog.akquinet.de/2011/12/26/patching-picketlink-to-support-multiple-ldap-stores/</link>
		<comments>http://blog.akquinet.de/2011/12/26/patching-picketlink-to-support-multiple-ldap-stores/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 21:32:03 +0000</pubDate>
		<dc:creator>Michael Schuetz</dc:creator>
				<category><![CDATA[JBOSS AID]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[GateIn]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[IDM]]></category>
		<category><![CDATA[JBOSS]]></category>
		<category><![CDATA[LDAP]]></category>
		<category><![CDATA[PicketLink]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1626</guid>
		<description><![CDATA[The PicketLink framework[1] provides identity management (IDM)[2] to applications based on different identity providers. PicketLink offers support for a number of different identity store back-ends like LDAP or RDBMSes. We are successfully using PicketLink in several internal and external applications and it is also a foundation for many other frameworks like seam-security[3] or the GateIn[4] [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1626&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The PicketLink framework[1] provides identity management (IDM)[2] to applications based on different identity providers. PicketLink offers support for a number of different identity store back-ends like LDAP or RDBMSes.</p>
<p>We are successfully using PicketLink in several internal and external applications and it is also a foundation for many other frameworks like seam-security[3] or the GateIn[4] portal server.</p>
<p><span id="more-1626"></span></p>
<h3>The Problem</h3>
<p>One of our customer applications is based on a customized version of GateIn 3.1.0 and uses PicketLink internally to load users from an LDAP. That application is facing an international rollout which requires it to talk to an additional LDAP store. However, this is a feature which is not yet fully supported in the version of PicketLink (1.1.5CR01) used in GateIn 3.1.0. The application is depending on a few quirks of GateIn 3.1.0 and our customizations to that. Therefore an update to a newer version of PicketLink or even GateIn is out of the question. The risk of braking changes or worse, subtle incompatibilities is too high.</p>
<p>To solve that problem, we explored the option to enhance PicketLink 1.1.5 CR01 to support multiple LDAP stores and use that patched version in GateIn. We successfully managed to create a fork of 1.1.5 that sequentially queries multiple LDAP servers. We made the modification available at GitHub. This blogpost describes the changes we made to PicketLink and their motivations.</p>
<h3>PicketLink</h3>
<p>The fact that PicketLink does not support multiple LDAP stores was not clear from the beginning. The configuration file (usually picketlin-idm-config.xml) happily accepts an arbitrary number of LDAP stores. The following listing shows a snippet from a valid configuration file with multiple stores defined:</p>
<p>picketlink-idm-config.xml:</p>
<p><pre class="brush: xml;">
&lt;repositories&gt;
  &lt;repository&gt;
    &lt;id&gt;PortalRepository&lt;/id&gt;
    &lt;class&gt;org.picketlink.idm.impl.repository.FallbackIdentityStoreRepository&lt;/class&gt;
    &lt;external-config/&gt;
    &lt;default-identity-store-id&gt;HibernateStore
    &lt;/default-identity-store-id&gt;
    ...
    &lt;identity-store-mappings&gt;
      &lt;identity-store-mapping&gt;
        &lt;identity-store-id&gt;LDAP1&lt;/identity-store-id&gt;
      &lt;/identity-store-mapping&gt;
      &lt;identity-store-mapping&gt;
        &lt;identity-store-id&gt;LDAP2&lt;/identity-store-id&gt;
      &lt;/identity-store-mapping&gt;
    &lt;/identity-store-mappings&gt;
    ...
  &lt;/repository&gt;
&lt;/repositories&gt;
</pre></p>
<p>Yet, there is a caveat. Only the last configured identity-store is used by PicketLink. So our first task was to understand where and why the other configured stores get lost.</p>
<p>PicketLink has an ObjectTypeIdentifier that tells it, what kind of object it is dealing with. This ObjectTypeIdentifier is not much more than a simple String. For users, it is usually configured to be &#8216;USER&#8217; but this can be changed in the configuration file. During the bootstrap of PicketLink, it creates a HashMap from these ObjetTypeIdentifiers to map to the store that is configured for that specific type. And of course, if two stores define the same &#8216;identity-object-type&#8217;, they fall into the same bucket of the map. Every subsequent store overwriting the previous one.</p>
<p>The naive approach of just defining two different identity-object-types, one per store does not work. When PicketLink queries a user, it looks for the type of users and only looks in the identity store, that matches the &#8216;UserType&#8217;. The second store with a different &#8216;identity-object-type&#8217; is never queried.</p>
<p>But this is exactly the entry point we decided to expand upon. The class <b>PersistenceManagerImpl</b> has a number of methods that eventually query an identity store. Three of those methods are actually used by our application. The query for a single user, the query for a list of users and the query for the count of users (instead of returning the list, the last call only returns the resultset size).</p>
<p>We modified each of those methods. Instead of just querying the store that matches the configured &#8216;ObjectType&#8217; for user, the methods now query all configured identity-stores sequentially, merging the results. The map containing the identity-stores is easily available at runtime. The modfications are simple and straight forward.</p>
<p>One optimization, we made was to shortcut subsequent queries for users if we already have found a user. This implies the assumption, that a user is unique throughout all LDAP stores &#8211; in our usecase, this assumption is sound.</p>
<p>The following listing shows as an example the changes we made to the &#8216;findUser&#8217; method. The &#8216;identityStoreMappings&#8217; contain the configured ObjectTypeIdentifier as keys. We iterate over those keys and create new SimpleIdentityObjectTypes from each key. PicketLink will then choose the store to query based on the ObjectType and therefore query a different store each time. Finally, we collect and accumulate the results.</p>
<p>Modified PersistenceManagerImpl to find users in multiple LDAP store:<br />
<pre class="brush: java;">
public Collection&lt;User&gt; findUser(IdentitySearchCriteria criteria)
  {
  // search cache
  ...
  // search all stores
  final Map&lt;String, IdentityStore&gt; identityStoreMappings = 
  getRepository().getIdentityStoreMappings();
  List&lt;IdentityObject&gt; identityObjects = 
  new LinkedList&lt;IdentityObject&gt;();
    for (String storeId : identityStoreMappings.keySet())
    {
    final Collection&lt;IdentityObject&gt; ios =
    getRepository().findIdentityObject(getInvocationContext(), new
    SimpleIdentityObjectType(storeId), 
    convertSearchControls(criteria));
      identityObjects.addAll(ios);
    }
    final List&lt;User&gt; identities = new LinkedList&lt;User&gt;();
    for (IdentityObject identityObject : identityObjects)
    {
      identities.add(createUser(identityObject));
    }
  // add to cache
  ...
  return identities;
}
</pre></p>
<p>This works fine for querying users. A first victory! But not yet the final result. Although PicketLink can now query for users, it is still unable to fetch the attributes, like names or mail-adresses from those users. The querying for attributes happens in another class: <b>FallbackIdentityStoreRepository</b>. The method &#8216;getAttributes(IdentityStoreInvocationContext invocationContext, IdentityObject identity)&#8217; is responsible for that. We extended it in a similar fashion. First, we let PicketLink decide, which store to search for attributes first. If the resultset is not empty, we obvioulsy have found the user and can proceed as normal. This query can also be executed against a &#8216;Hibernate Store&#8217; or any other store. If we were unable to find attributes that way, we iterate over all configured &#8216;identity-store-mappings&#8217; again. This time also making sure, that we do not query the store that was used in the previous query again. If the user is present in any of the stores, we query that store for the attributes, hopefully finding them and proceeding as normal.</p>
<p>Modified FallbackIdentityStoreRepository to get attributes from multiple LDAP store:<br />
<pre class="brush: java;">
public Map&lt;String, IdentityObjectAttribute&gt; getAttributes(...)
  {
  Map&lt;String, IdentityObjectAttribute&gt; results = new 
  HashMap&lt;String, IdentityObjectAttribute&gt;();
  IdentityStore toStore = resolveIdentityStore(identity);
  IdentityStoreInvocationContext targetCtx = 
  resolveInvocationContext(toStore, invocationContext);

  // expect user in first LDAP store
  if (hasIdentityObject(targetCtx, toStore, identity))
  {
    results = toStore.getAttributes(targetCtx, identity);
  }
  else
  {
    // check that the identity we are looking is configured in the
    // attributeStoreMappings
    if (toStore != defaultAttributeStore &amp;&amp; 
    attributeStoreMappings.keySet().contains(identity.
    getIdentityType().getName()))
    {
      // check attributes for all LDAP stores
      for (String storeName : attributeStoreMappings.keySet())
      {
        IdentityStore userIdentityStore = resolveIdentityStore(new
        SimpleIdentityObjectType(storeName));
        // check that it is not the LDAP, we already checked a few 
        // lines ago
        if (userIdentityStore != toStore)
        {
          IdentityStoreInvocationContext otherLdapCtx = 
          resolveInvocationContext(userIdentityStore, 
          invocationContext);
          SimpleIdentityObject userFrIdentity = new
          SimpleIdentityObject(identity.getName(), 
          identity.getId(),
          new SimpleIdentityObjectType(storeName));
          if (hasIdentityObject(otherLdapCtx, userIdentityStore,
          userFrIdentity))
          {
            results = userIdentityStore.getAttributes
            (otherLdapCtx, userFrIdentity);
          }
        }
      }
    }
  }
  if (toStore != defaultAttributeStore)
  {
  ...
  }
  return results;
  }
}
</pre></p>
<p>With those changes in place, we are now able to query our users from an arbitrary number of identity stores and successfully fetch the attributes to those users. Our testcases are green and the application is behaving as expected with those modifications in place.</p>
<h3>Bootstrap</h3>
<p>There is only one minor annoyance left. During the bootstrap of GateIn, we import a number of users into a primary hibernate identity-store. The bootstrap first checks whether those users already exist and insert them if thy can’t be found. During that bootstrap, PicketLink appears to be in an imcompletely configured state. At that time, getIdentityStoreMappings() returns an empty map. Since we iterate over the keys of that map, our modifications aren’t querying anything and users, that already exist won’t be found. This results in an exception when the bootstrap tries to create them.</p>
<p>Those exceptions do not interfere with the application but they litter the server log. To avoid this strange edge-case of an incompletely configured PicketLink, we perform a check to see if the configured store-mappings are empty. When they are empty, we add the user-object-type to the keyset before iterating over it. Therefore we always query at least the store that is configured as the default store for users.</p>
<h3>findUser result caching</h3>
<p>One minor remark: During our debugging, we discovered a caching problem in PicketLink. GateIn first queries PicketLink for all users matching a certain criteria. And later in the rendering of the GUI, it performs individual queries for each user again. Therefore it makes a lot of sense to cache those users. However, The caching strategy of PicketLink caches complete searches, only. A second query for a list of users with the same criterias should result in a cache hit. However, individual queries for those users are always cache-misses. We decided to change that behaviour. The findUsers Method puts not only the &#8216;Result-Collection&#8217; in the cache. It now also caches each individual user. Therefore all subsequent requests to findUser for each individual user can be answered directly from the cache. This dramatically reduces the number of LDAP queries performed by PicketLink. And since each findUser query now has to potentially go to every configured LDAP store, this can be quite significant.</p>
<h3>Tuning performance &#8211; maximum LDAP results</h3>
<p>According to the LDAP spec, each LDAP request returns maximum pages size of 1000 entries. After extending PicketLink to support multiple LDAPs, we were forced to potentially handle 1000 * n entries (where n is the number of configured LDAP Stores). As PicketLink doesn’t provide the capability to limit the result set out of the box, we also added this behaviour. (BTW, this is implemented in PicketLink since version 1.3.0.Final)</p>
<p>The PicketLink configuration file accepts an arbitrary number of name-value options. We decided to use the same option that is also used in later versions of PicketLink. The following listing shows the required configuration to set the result set size for an LDAP Store to 10 (You might want to set that number higher in real scenarios)</p>
<p>configure for each LDAP strore, picketlink-idm-config.xml:</p>
<p><pre class="brush: xml;">
&lt;option&gt;
  &lt;name&gt;maxSearchResults&lt;/name&gt;
  &lt;value&gt;10&lt;/value&gt;
&lt;/option&gt;
</pre></p>
<p>The next step is to make PicketLink aware of the new option. We tried to keep our changes as local and as minimal as possible to keep the risk of unforeseen side-efects as small as possible. Instead of adding a new pair of getter/setter to the the &#8216;LDAPIdentityStoreConfiguration&#8217;, we directly access the options. The options from the configuration file are parsed into a hash map that is kept around and accessible at runtime through the LDAPIdentityStoreConfiguration and its MetaData. We decided to create a default value and lazily initialize a new instance variable in LDAPIdentityObjectImpl to control the result set size. Based on that number, we create a &#8216;javax.naming.ldap.PagedResultsControl&#8217; object and add it to the existing LDAP request controls effectively limiting the result size. The following listing shows those changes:</p>
<p><pre class="brush: java;">
public List&lt;SearchResult&gt; searchIdentityObjects(...)
  {
  // Set max results for query. Try to get from configuration 
  // file, first. Use {@link MAX_SEARCH_RESULTS_DEFAULT}, 
  // alternatively.
  try
  {
    List&lt;Control&gt; controlList = new ArrayList&lt;Control&gt;();
    if (requestControls != null)
    {
      controlList.addAll(Arrays.asList(requestControls));
    }
    // lazily load maxResults from configuration
    if (maxResults &lt;= 0)
    {
      maxResults = MAX_SEARCH_RESULTS_DEFAULT; // default value
      try
      {
        maxResults = Integer.valueOf(getConfiguration(ctx).
        getConfigurationMetaData().getOptions().get(MAX_SEARCH_RESULTS).get(0));
      }
      catch (Exception e)
      {
      ...
      }
    }
    controlList.add(new PagedResultsControl(maxResults, 
    Control.CRITICAL));
    requestControls = new Control[controlList.size()];
    requestControls = controlList.toArray(requestControls);
  }
  ...
  }
</pre></p>
<h3>Deployment</h3>
<p>With all those issues sorted out, we had a working PicketLink implementation with only a few minor changes to the base version we started from. All our requirements are fulfilled and the required patches are clear and minimal.</p>
<p>To maintain our changes and to contribute our modifications back to the community, we decided to use GitHub. We started with a new GitHub project and checked in the unmodified PicketLink sources in version 1.1.5.CR01. We then formulated our own requirements in the form of issues against that github repository. We tracked and documented our progress by commiting our progress to github and updating the relevant issues.</p>
<p>We decided against a true fork of PicketLink in the form of a new, separate maven artefact. Since we do not build GateIn and PicketLink is integrated within GateIn, the benefit of such a fork would be minimal. Instead, we manually build our version of PicketLink and replace the jars inside GateIn. We already had scripts in place to create and configure GateIn for our different environments. Those scripts now also replace PicketLink in GateIn.</p>
<h3>Conclusion</h3>
<p>In this post we described required steps to extend PicketLink to support multiple LDAP stores at the same time. We described how and why we changed PicketLink.</p>
<p><strong>An overview of our changes:</strong></p>
<ul>
<li>Support multiple usertype mappings that each map to different LDAP identity stores.</li>
<li>Iterate over the userTypeMappings, that have identity-stores instead of using the single one user-type mapping</li>
<li>Define amount of LDAP search results for each LPAD store as option &#8220;maxSearchResults&#8221; via xml config file.</li>
<li>Fixed performance issues caused by new implementation.</li>
</ul>
<p>As sources are LGPL licensed, we do provide code on GitHub for public usage: <a href="https://github.com/akquinet/picketlink-idm" title="https://github.com/akquinet/picketlink-idm" target="_blank">https://github.com/akquinet/picketlink-idm</a></p>
<p>We also informed the PicketLink forum about our changes and they are looking into merging some of them back upstream.</p>
<p><strong>You are welcome to try our modifications. To get started:</strong></p>
<ul>
<li>download tagged sources</li>
<li>build project locally</li>
<li>replace picketlink-idm-core-1.1.5.CR01.jar and picketlink-idm-ldap-1.1.5.CR01.jar in GateIn</li>
</ul>
<p>We would appreciate any feedback either via mail or direct through GitHub.</p>
<p><strong>references:</strong><br />
[1] http://www.jboss.org/picketlink<br />
[2] http://www.jcp.org/en/jsr/detail?id=351<br />
[3] http://seamframework.org/Seam3/SecurityModule<br />
[4] http://www.jboss.org/gatein</p>
<p>Happy New Year!<br />
Moritz Grauel, Michael Schuetz</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/jboss-aid/'>JBOSS AID</a> Tagged: <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/gatein/'>GateIn</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/idm/'>IDM</a>, <a href='http://blog.akquinet.de/tag/jboss/'>JBOSS</a>, <a href='http://blog.akquinet.de/tag/ldap/'>LDAP</a>, <a href='http://blog.akquinet.de/tag/picketlink/'>PicketLink</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1626/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1626/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1626/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1626/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1626/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1626/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1626/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1626/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1626&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2011/12/26/patching-picketlink-to-support-multiple-ldap-stores/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/288c63aab0b07b1841816bdb88c221e3?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">michaelschuetz</media:title>
		</media:content>
	</item>
		<item>
		<title>Managing an Apache server with Puppet</title>
		<link>http://blog.akquinet.de/2011/11/23/managing-an-apache-server-with-puppet/</link>
		<comments>http://blog.akquinet.de/2011/11/23/managing-an-apache-server-with-puppet/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 14:43:06 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[OSGi and Mobile Solutions]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[host]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[virtual]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1603</guid>
		<description><![CDATA[Puppet is a configuration manager embracing the infrastructure-as-code movement. It allows you to describe the desired configuration of your system. One of the most common tasks for Puppet is to configure an Apache frontend. This blog post explains how you can use Puppet to configure an Apache server as frontend using the mod_proxy, without having [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1603&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.puppetlabs.com/">Puppet</a> is a configuration manager embracing the infrastructure-as-code movement. It allows you to describe the desired configuration of your system. One of the most common tasks for Puppet is to configure an Apache frontend.</p>
<p>This blog post explains how you can use Puppet to configure an Apache server as frontend using the <em>mod_proxy</em>, without having to write a single Apache directive.</p>
<p><span id="more-1603"></span></p>
<h3>1 machine -&gt; n servers</h3>
<p>We often have the following topology: we use the same machine to host several systems. Let&#8217;s take,  for example, a server used as a development forge and so hosting a maven repository manager, a continuous integration server, a code browser, a quality tracker, a source repository manager and so on. Another example is to host several web sites on the same machine. This is quite a common configuration for web sites that do not consume a lot of resources.</p>
<p>To route the request to the right web site, we set up an Apache frontend (aka proxy) redirecting the requests to the correct web site. The redirection is based on the target url, so for example <em>http://my-site.com</em> redirects to <em>http://localhost:9015</em>, or <em>http://mydomain/nexus</em> to <em>http://localhost:9000</em>. </p>
<div id="attachment_1608" class="wp-caption aligncenter" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2011/11/apache_as_frontend1.png"><img src="http://akquinetblog.files.wordpress.com/2011/11/apache_as_frontend1.png?w=440&#038;h=190" alt="An Apache server used as frontend" title="apache_as_frontend" width="440" height="190" class="size-full wp-image-1608" /></a><p class="wp-caption-text">An Apache server used as frontend</p></div>
<p>Configuring the Apache server to delegate the requests is not hard, once you have the required modules (<i>mods</i>) enabled, and are able to write Apache virtual host configurations (a mix between XML and plain text). But it starts to become rather cumbersome when the number of proxied sites or servers starts to grow, or when you need to replicate this configuration on another server.</p>
<p>By using Puppet for this purpose, we simplify the deployment of the system. Adding a web site will require 5 lines of code only. So in addition to all the other advantages of using Puppet and infrastructure-as-code, it also makes your Apache configuration cleaner. </p>
<h3>Using Puppet to configure virtual hosts</h3>
<p>There are a lot of Puppet modules to configure Apache. We chose one provided by puppetlabs, available on <a href="https://github.com/puppetlabs/puppetlabs-apache/">github</a>. This module supports <em>mod_proxy</em> and <em>mod_redirect</em> out of the box. </p>
<p>So the first thing to do is to install the module. This module is hosted on the Puppet Module Forge, so can be installed using the <em>puppet-module </em>command:</p>
<p><pre class="brush: plain;">
puppet-module install puppetlabs-apache
</pre></p>
<p>Now that we have the module, we need to describe our system. With Puppet, you describe the resulting state and not how you reach it. So in our case we need to:</p>
<ul>
<li>ensure that Apache is available,</li>
<li>ensure that the mod_proxy is enabled,</li>
<li>define our virtual hosts</li>
</ul>
<p>We can achieve these tasks with the following Puppet manifest:<br />
<pre class="brush: plain;">
Exec {
    path =&gt; [&quot;/bin&quot;, &quot;/sbin&quot;, &quot;/usr/bin&quot;, &quot;/usr/sbin&quot;],
}

include apache

a2mod { &quot;Enable proxy mod&quot;:
	name =&gt; &quot;proxy&quot;,
	ensure =&gt; &quot;present&quot;
}

a2mod { &quot;Enable proxy_http mod&quot;:
	name =&gt; &quot;proxy_http&quot;,
	ensure =&gt; &quot;present&quot;
}

apache::vhost::proxy { &quot;my-site&quot;:
	servername =&gt; &quot;my-site.com&quot;,
	port =&gt; 80,
	dest =&gt; &quot;http://localhost:9015&quot;,
	vhost_name =&gt; &quot;my-site&quot;
}
</pre></p>
<p>So, this manifest checks whether Apache 2 is installed and running correctly. Then, it ensures that the Proxy module and the Proxy module for HTTP are enabled. Finally, we declare our proxied site. The server name and the port indicates the address received by the Apache server that need to be redirected to the <em>dest</em> parameter. So in the previous example, we redirect <em>http://my-site.com</em> to <em>http://location:9015</em>.</p>
<p>Of course, we can declare several such proxied sites:<br />
<pre class="brush: plain;">
...
apache::vhost::proxy { &quot;my-site&quot;:
	servername =&gt; &quot;my-site.com&quot;,
	port =&gt; 80,
	dest =&gt; &quot;http://localhost:9015&quot;,
	vhost_name =&gt; &quot;my-site&quot;
}

apache::vhost::proxy { &quot;my-site-2&quot;:
	servername =&gt; &quot;my-site-2.com&quot;,
	port =&gt; 80,
	dest =&gt; &quot;http://localhost:9016&quot;,
	vhost_name =&gt; &quot;my-site-2&quot;
}
</pre></p>
<p>When we apply this manifest, all virtual hosts are created, and the Apache server restarted. So, we&#8217;re up and running.</p>
<p>One of the big advantages of Puppet is that you can add a virtual host, re-apply the configuration and it will set up everything for you. However, if the host is already defined, Puppet will do nothing: only new hosts are created.</p>
<h3>Conclusion</h3>
<p>This blog post has shown how Puppet can be used to create Apache virtual hosts to manage an Apache frontend delegating on proxied servers. If you&#8217;re running topologies such as the one described in this blog post, Puppet can help you to manage such configuration in a very elegant way.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/osgi-and-mobile-solutions/'>OSGi and Mobile Solutions</a> Tagged: <a href='http://blog.akquinet.de/tag/apache/'>apache</a>, <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/host/'>host</a>, <a href='http://blog.akquinet.de/tag/puppet/'>puppet</a>, <a href='http://blog.akquinet.de/tag/virtual/'>virtual</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1603/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1603/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1603/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1603/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1603/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1603/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1603/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1603/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1603/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1603/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1603/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1603/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1603/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1603/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1603&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2011/11/23/managing-an-apache-server-with-puppet/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2011/11/apache_as_frontend1.png" medium="image">
			<media:title type="html">apache_as_frontend</media:title>
		</media:content>
	</item>
		<item>
		<title>Connecting to Amazon VPC</title>
		<link>http://blog.akquinet.de/2011/11/11/connecting-to-amazon-vpc/</link>
		<comments>http://blog.akquinet.de/2011/11/11/connecting-to-amazon-vpc/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 16:02:07 +0000</pubDate>
		<dc:creator>Immanuel Sims</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Enterprise Applications]]></category>
		<category><![CDATA[Amazon]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[cisco]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[ipsec]]></category>
		<category><![CDATA[openswan]]></category>
		<category><![CDATA[openvpn]]></category>
		<category><![CDATA[racoon]]></category>
		<category><![CDATA[strongswan]]></category>
		<category><![CDATA[vpc]]></category>
		<category><![CDATA[vpn]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1588</guid>
		<description><![CDATA[Overview Amazons virtual privacy cloud service (VPC) offers great outsourcing possibilities for your less private (but still private) services. Consider a Jenkins build server. You have got one on your local machine but sometimes it’s just too much load for your hardware. It would be nice in such a case to just push some load [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1588&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Overview</h3>
<p>Amazons virtual privacy cloud service (VPC) offers great outsourcing possibilities for your less private (but still private) services.</p>
<p>Consider a Jenkins build server. You have got one on your local machine but sometimes it’s just too much load for your hardware. It would be nice in such a case to just push some load into the cloud. Clearly you can not just put a Jenkins server into the cloud because it will need access to various services like at least some repository (Git, SVN). To protect that cloud-internal traffic (you do not want other Amazon customers to see your source code) one should use VPC. And for a seamless integration into your existing infrastructure you will need a VPN tunnel from the Amazon VPC to your local network.</p>
<p>Amazon offers the possibility to create such a VPN connection to your VPC. You may set up your own VPN server in your VPC but in our opinion it is easier and cheaper to use Amazons solution. Because it seemed less pricy we first tried to just use open-source software for that VPN server.</p>
<p><span id="more-1588"></span></p>
<h3>How Amazon builds up a VPN</h3>
<div id="attachment_1589" class="wp-caption alignnone" style="width: 450px"><a href="http://akquinetblog.files.wordpress.com/2011/11/vpc.png"><img class="size-full wp-image-1589" title="vpc" src="http://akquinetblog.files.wordpress.com/2011/11/vpc.png?w=440&#038;h=127" alt="Figure 1: Amazon’s VPN architecture " width="440" height="127" /></a><p class="wp-caption-text">Figure 1: Amazon’s VPN architecture</p></div>
<p>In figure 1 you see an overview of the VPN connection, how Amazon requires it. Let us say our VPN server has a public ip 1.2.3.4. For redundancy reasons amazon builds up two VPN tunnels with endpoint ip 87.238.85.40 for tunnel #1 and 87.238.85.44 for tunnel #2. You will need an ISAKMP daemon listening on your public ip 1.2.3.4 which will manage the two IPSec connections.</p>
<p>For each tunnel you need to set up an internal network device in the net 169.254.254.0/30 for tunnel #1 and 169.254.254.4/30 for tunnel #2. On Amazon’s side of each VPN tunnel there is a BGP router 169.254.254.1 for tunnel #1 and 169.254.254.5 for tunnel #2. From your internal ip for tunnel #1 169.254.254.2 you need to establish a BGP peering with that BGP router 169.254.254.1 and for tunnel #2 you need to do the same with the other two ips.</p>
<p>This is a route based VPN that means in our case any package that gets routed over the net 169.254.254.0/30 will use tunnel #1 and any packet that gets routed over 169.254.254.4/30 will be sent over tunnel #2.</p>
<p>So a packet from our internal net (let us say 192.168.1.0/24) which is addressed to our subnet in Amazon’s VPC (let us say 10.0.1.0/24) will get routed to one of the two BGP servers on Amazon’s side. To get there it will use the appropriate VPN tunnel and from the BGP server it will be sent to some Amazon-internal router. From there it will finally be delivered to our VPC. Sending a packet from the VPC to our home net is just the reverse way.</p>
<p>Amazon leaves no room for individual configuration. According to Amazons VPC-FAQ your device must be able to: (requirement list copied from there)</p>
<ul>
<li>Establish IKE Security Association using Pre-Shared Keys</li>
<li>Establish IPsec Security Associations in Tunnel mode</li>
<li>Utilize the AES 128-bit encryption function</li>
<li>Utilize the SHA-1 hashing function</li>
<li>Utilize Diffie-Hellman Perfect Forward Secrecy in &#8220;Group 2&#8243; mode</li>
<li>Establish Border Gateway Protocol (BGP) peerings</li>
<li>Bind tunnels to logical interfaces (route-based VPN)</li>
<li>Utilize IPsec Dead Peer Detection</li>
<li>Perform packet fragmentation prior to encryption</li>
</ul>
<p>Most points are supported by nearly all VPN servers that use IPSec for their tunnels. The most important points to look out for are:</p>
<ul>
<li>Establish Border Gateway Protocol (BGP) peerings</li>
<li>Bind tunnels to logical interfaces (route-based VPN)</li>
<li>Utilize IPsec Dead Peer Detection</li>
</ul>
<p>Even if you look at the officially supported Cisco hardware like the Cisco ISR 880 series, you have to watch out for BGP support. Sometimes you need a software upgrade like (in case of the Cisco 880 series) the “Advanced IP Services”- upgrade. Whether a device or software supports route-based VPNs or not is oftenly not stated directly. You will have to look deeper into the manuals and descriptions to find out about that. If it just supports policy-based VPNs, it will not support route-based VPNs out of the box. Dead Peer Detection sometimes is not available on older devices (or software).</p>
<h3>The Choice of VPN Servers</h3>
<p>There is a list of officially supported VPN servers:</p>
<ul>
<li>Cisco ISR running Cisco IOS 12.4 (or later) software</li>
<li>Juniper J-Series Service Router running JunOS 9.5 (or later) software</li>
<li>Juniper SSG running ScreenOS 6.1, or 6.2 (or later) software</li>
<li>Juniper ISG running ScreenOS 6.1, or 6.2 (or later) software</li>
<li>Yamaha RTX1200 router</li>
</ul>
<p>If you start using VPC you maybe just want to test it and do not want to spend much money for it (like for the above hardware). So it seems a good idea to use some linux box as VPN server. IPSec is implemented in the kernel and for ISAKMP you may want to use some daemon like racoon, Openswan, FreeS/WAN, or strongSwan.</p>
<h3>Using Linux as VPN Server</h3>
<p>Let us say you have decided to use some linux for your VPN server. For an IPSec newbie there is no obvious reason that this is a bad idea. And because one soon finds a tutorial like <a title="http://openfoo.org/blog/amazon_vpc_with_linux.html" href="http://openfoo.org/blog/amazon_vpc_with_linux.html">http://openfoo.org/blog/amazon_vpc_with_linux.html</a> it seems possible to perform that task. Following this tutorial you should be able to ping the two BGP servers from your VPN server. And that means your IPSec tunnels are both up and working. But after that point you will start to get in trouble. Maybe you are able to connect to a server in your VPC. But there is one thing you won’t get working stable: Connecting from the VPC to some server in your home net 192.168.1.1/24. That is because linux has a policy-based IPSec implementation.</p>
<p>To connect your home net to the VPC net you need a policy like</p>
<blockquote>
<pre>spdadd 10.0.0.0/24 192.168.1.0/24 any -P in ipsec
    esp/tunnel/87.238.85.40-1.2.3.4/require;</pre>
</blockquote>
<p>If a packet from your VPC net gets routed over the tunnel #1 (over 87.238.85.40) everything<br />
works fine. But if a packet from your VPC get’s routed over the other tunnel (over 87.238.85.44)<br />
you’ve got a problem. Because you would need an additional policy like</p>
<blockquote>
<pre>spdadd 10.0.0.0/24 192.168.1.0/24 any -P in ipsec
    esp/tunnel/87.238.85.44-1.2.3.4/require;</pre>
</blockquote>
<p>to make your linux box unpack and forward that IPSec packet. That is a problem because you can not have two policies with the same source (here 10.0.0.0/24), destination (192.168.1.0/24), protocol (any), direction (in), and method (ipsec). This is why amazon requires a route-based VPN.</p>
<p>One workaround would be to connect just one tunnel. But this is not a good idea because you sacrifice the reliability of the VPN connection. As another workaround there are some dirty tricks to simulate a route-based VPN with Openswan (like <a title="http://lists.openswan.org/pipermail/users/2011-February/020123.html" href="http://lists.openswan.org/pipermail/users/2011-February/020123.html">http://lists.openswan.org/pipermail/users/2011-February/020123.html</a> ). This, in our opinion, is not a good idea as well. This is because: First you need to use KLIPS (an older IPSec implementation) which has a rather bad reputation in the community. Second you need to apply a patch from some newsgroup. And the last and most important reason is that Openswan is not intended to be used that way. Abusing software in a security relevant place doesn’t seem to be a good idea.</p>
<h3>Conclusion</h3>
<p>There are two important things you won’t achieve going the linux-as-VPN-server way:</p>
<ol>
<li>an easy to administer and supported solution</li>
<li>having a cost effective solution</li>
</ol>
<p>The first point is because the linux IPSec implementation is not meant to be used for route-based VPNs. If it is possible, you’ll need some really dirty tricks. The second point is because for the officially supported devices Amazon offers generated configuration files. And these hardware routers are not as pricy as you think. For example a Cisco ISR 880 series CISCO881-SEC-K9 is available between 350-400€ (incl. VAT).</p>
<p>Our next step is to try an Amazon-supported solution. We will also post our experiences with that solution.</p>
<p>If you just want to try out VPC for a short time (like a few days) you may set up an OpenVPN server on a cloud instance in your VPC (and another OpenVPN server in youre home net). This solution will only cost less than the hardware solution if you are familiar with OpenVPN. This OpenVPN solution is only suitable for very small VPCs because you will need to adjust the routes on every instance inside the VPC manually.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/enterprise-applications/'>Enterprise Applications</a> Tagged: <a href='http://blog.akquinet.de/tag/amazon/'>Amazon</a>, <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/cisco/'>cisco</a>, <a href='http://blog.akquinet.de/tag/cloud/'>cloud</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/ec2/'>ec2</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/ipsec/'>ipsec</a>, <a href='http://blog.akquinet.de/tag/openswan/'>openswan</a>, <a href='http://blog.akquinet.de/tag/openvpn/'>openvpn</a>, <a href='http://blog.akquinet.de/tag/racoon/'>racoon</a>, <a href='http://blog.akquinet.de/tag/strongswan/'>strongswan</a>, <a href='http://blog.akquinet.de/tag/vpc/'>vpc</a>, <a href='http://blog.akquinet.de/tag/vpn/'>vpn</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1588/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1588/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1588/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1588&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2011/11/11/connecting-to-amazon-vpc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4f12679b601665fa3488bfaa85a71e00?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">immsims</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2011/11/vpc.png" medium="image">
			<media:title type="html">vpc</media:title>
		</media:content>
	</item>
		<item>
		<title>Building pipelines by linking Jenkins jobs</title>
		<link>http://blog.akquinet.de/2011/11/09/building-pipelines-by-linking-jenkins-jobs/</link>
		<comments>http://blog.akquinet.de/2011/11/09/building-pipelines-by-linking-jenkins-jobs/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 14:27:00 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[OSGi and Mobile Solutions]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[continuous delivery]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[hudson]]></category>
		<category><![CDATA[jenkins]]></category>
		<category><![CDATA[jobs]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[pipeline]]></category>
		<category><![CDATA[trigger]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1566</guid>
		<description><![CDATA[Continuous integration servers have become a corner stone of any professional development environment. By letting a machine integrate and build software, developers can focus on their tasks: fixing bugs and developing new features. With the emergence of trends such as continuous deployment and delivery, the continuous integration server is not limited to integrating your products, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1566&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Continuous integration servers have become a corner stone of any professional development environment. By letting a machine integrate and build software, developers can focus on their tasks: fixing bugs and developing new features.  With the emergence of trends such as continuous deployment and delivery, the continuous integration server is not limited to integrating your products, but has become a central piece of infrastructure.</p>
<p>However, organizing jobs on the CI server is not always easy. </p>
<p>This blog post describes a couple of strategies for creating dependent tasks with Jenkins (or Hudson).</p>
<p><span id="more-1566"></span></p>
<h3>On keeping things small</h3>
<p>To make your continuous server really efficient for your team, you need to give feedback to your development team as fast as possible. After a commit (or a push), we all wait for a notification to make sure we didn&#8217;t introduce any obvious bugs (at some point, we&#8217;ve all forgotten to add a file to the SCM, or introduced a wrong import statement). However, builds tend to be long for enterprise applications; tests (both unit and smoke) can take hours to execute. So it&#8217;s imperative to reduce feedback time and therefore, to divide massive jobs into small and fast units. </p>
<p>For example, a regular build process would generally take the following actions (for each module/component):</p>
<ul>
<li>compile the code</li>
<li>run unit tests</li>
<li>package the code</li>
<li>run integration tests</li>
<li>extract quality metric</li>
<li>generate reports and documentation</li>
<li>deploy the package on a server</li>
</ul>
<p>It&#8217;s clear that carrying out all those tasks on a multi-module project can take a considerable length of time, leaving the development team waiting before they can switch to the next task. It&#8217;s not rare to see a Maven build taking (just for the compilation / test / packaging) up to 30 minutes.</p>
<p>Moreover, smaller jobs offer much more flexibility. For example, one can restart from a failing step without restarting the full build from scratch.</p>
<h3>A true story : Restarting a test server</h3>
<p>Recently, in one of our projects, we had to clean up and re-populate a test server. In the first version, a script was executing the following actions in one massive job:</p>
<ul>
<li>Stop the server</li>
<li>Clean up the file system</li>
<li>Drop tables</li>
<li>Create tables and populate with test data</li>
<li>Start the server</li>
</ul>
<p>The process was taking more or less 10 minutes, and in case of failure didn&#8217;t allow  restarts from the failing step.</p>
<p>In a second version, each action was executed in its own job. However, jobs were not dependent on each other, which required job/wait cycles of 10 minutes. </p>
<div id="attachment_1569" class="wp-caption aligncenter" style="width: 450px"><img src="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-job-list.png?w=440&#038;h=198" alt="" title="Jobs to achieve our second scenario" width="440" height="198" class="size-full wp-image-1569" /><p class="wp-caption-text">Jobs to achieve our second scenario</p></div>
<p>Finally, we linked jobs together to trigger the whole process by simply starting the first job. To create those dependencies, we tried three approaches of which two were successful (I&#8217;ll let you guess about the third one).</p>
<h3>One-to-One Relationship</h3>
<p>The first approach was pretty simple: one job triggers another one after successful completion. So in our case:</p>
<pre>
Stop server
    |-&gt; Clean up filesystem
           |-&gt; Drop database
                  |-&gt; Create table and insert data
                        |-&gt; Start server
</pre>
<p><pre class="brush: plain;">
INFO: Pipeline Blog Post - Stop Server #3 main build action completed: SUCCESS
07.11.2011 15:12:20 hudson.model.Run run
INFO: Pipeline Blog Post - Cleanup #3 main build action completed: SUCCESS
07.11.2011 15:15:27 hudson.model.Run run
INFO: Pipeline Blog Post - Dropping tables #3 main build action 
completed: SUCCESS
07.11.2011 15:17:29 hudson.model.Run run
INFO: Pipeline Blog Post - Creating tables and Inserting data #3 main build action completed: SUCCESS
07.11.2011 15:22:31 hudson.model.Run run
INFO: Pipeline Blog Post - Start server #3 main build action completed: SUCCESS
</pre></p>
<p>To achieve these sorts of relationships with Jenkins, you can either configure a post-build action starting the next job (downstream) or configure the trigger of the current build (upstream). Both ways are totally equivalent.</p>
<h4>Triggering a job after successful completion of the current job</h4>
<p>This first way is probably the most intuitive. It consists of configuring the job triggered after the current job. In our scenario, the &#8216;stop server&#8217; job triggers, on successful completion, the &#8216;cleanup&#8217; job. To configure this dependency, we configure a post-build action in the Configure page of the &#8216;stop server&#8217; job:</p>
<div id="attachment_1570" class="wp-caption aligncenter" style="width: 450px"><img src="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-stop-server-config-jenkins.png?w=440&#038;h=95" alt="" title="Post-build action" width="440" height="95" class="size-full wp-image-1570" /><p class="wp-caption-text">Trigger a build once the current job finishes</p></div>
<h4>Starting the current job after completion of another build</h4>
<p>With this second way, you configure which job triggers the current job. In our scenario, the &#8216;cleanup&#8217; job is triggered after the &#8216;stop server&#8217; job. So in the Configure page of &#8216;cleanup&#8217;, in the <tt>Build trigger</tt> section, we select the <tt>Build after other projects are built</tt> and specify the &#8216;stop server&#8217; job:</p>
<p><a href="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-cleanup-config-build-trigger.png"><img src="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-cleanup-config-build-trigger.png?w=440&#038;h=66" alt="" title="Build triggered by another build" width="440" height="66" class="aligncenter size-full wp-image-1567" /></a></p>
<p>Using this one-to-one dependency approach is probably the simplest way to orchestrate jobs on Jenkins. With such easy configuration, decomposing complex activities / build processes is very simple. You can restart the stream from any point, and get feedback after every success or failure.</p>
<h3>Über Job: the wrong good idea</h3>
<p>One attempt to optimize the previous method was to create a kind of über job, triggering all other jobs. Unfortunately, even if it was a brilliant idea on paper, it doesn&#8217;t work. Indeed, there are two issues:</p>
<ul>
<li>Even if a job fails, others are triggered</li>
<li>The job execution order is not deterministic</li>
</ul>
<p>The first point is simple to explain: the jobs are not interconnected, so even if one fails, others are still executed. This can be really annoying if the initial requirement of a job is not set up correctly.</p>
<p><pre class="brush: plain;">
07.11.2011 15:32:51 hudson.model.Run run
INFO: Pipeline Blog Post - Uber Job #6 main build action completed: SUCCESS
07.11.2011 15:32:59 hudson.model.Run run
INFO: Pipeline Blog Post - Stop Server #5 main build action completed: SUCCESS
07.11.2011 15:33:01 hudson.model.Run run
INFO: Pipeline Blog Post - Cleanup #3 main build action completed: SUCCESS
07.11.2011 15:33:03 hudson.model.Run run
INFO: Pipeline Blog Post - Dropping tables #3 main build action completed: FAILURE
07.11.2011 15:33:05 hudson.model.Run run
INFO: Pipeline Blog Post - Creating tables and Inserting data #3 main build action completed: SUCCESS
07.11.2011 15:33:07 hudson.model.Run run
INFO: Pipeline Blog Post - Start server #3 main build action completed: SUCCESS
</pre></p>
<p>In this log, the &#8216;drop tables&#8217; job failed. We would expect the whole scenario to come to a halt at this point, but unfortunately that&#8217;s not the case. When this happens, we can&#8217;t be sure of the resulting state on our restarted server.</p>
<p>The second point is more tricky. Jenkins is built on an asynchronous model: jobs are scheduled and will be executed later. The order of execution can depend on a lot of different parameters, so the order is hard to plan. In our case, we have seen:</p>
<p><pre class="brush: plain;">
07.11.2011 15:32:51 hudson.model.Run run
INFO: Pipeline Blog Post - Pipeline #18 main build action completed: SUCCESS
07.11.2011 15:32:59 hudson.model.Run run
INFO: Pipeline Blog Post - Stop Server #15 main build action completed: SUCCESS
07.11.2011 15:33:01 hudson.model.Run run
INFO: Pipeline Blog Post - Cleanup #13 main build action completed: SUCCESS
07.11.2011 15:33:03 hudson.model.Run run
INFO: Pipeline Blog Post - Creating tables and Inserting data #13 main build action completed: SUCCESS
07.11.2011 15:33:05 hudson.model.Run run
INFO: Pipeline Blog Post - Dropping tables #13 main build action completed: SUCCESS
07.11.2011 15:33:07 hudson.model.Run run
INFO: Pipeline Blog Post - Start server #13 main build action completed: SUCCESS
</pre></p>
<p>You can see that the tables were dropped after the data was inserted. Well&#8230; I&#8217;ll let you guess the state of the server after this execution. </p>
<p>So, even if this method seemed to be a good idea, it&#8217;s actually a pretty bad idea if you want your process executed reliably. </p>
<h3>A bit of optimization: Fork and Join</h3>
<p>This last method uses a Jenkins plugin named &#8216;Join plugin&#8217; (see the <a href="https://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin">Join plugin page</a>). In brief, this plugin allows you to configure fork/join patterns: once downstream projects are completed, other projects are triggered.</p>
<p>If you have jobs that can be run in any order, this plugin will reduce the amount of configuration you need. In our scenario, in the &#8216;stop server&#8217; job, it can be used as follows:</p>
<p><a href="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-fork-_-join.png"><img src="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-fork-_-join.png?w=440&#038;h=120" alt="" title="Join plugin configuration" width="440" height="120" class="aligncenter size-full wp-image-1568" /></a></p>
<p>So, the &#8216;stop server&#8217; job triggers the &#8216;clean up&#8217; and &#8216;drop table&#8217; jobs. Once those (independent) jobs are completed, we trigger the data insertion and restart the server. In our experience, these two &#8216;join&#8217; jobs were always executed in right order (and on the same executor). But we recommend triggering only one join job with a one-to-one dependency:</p>
<pre>
            /-&gt; Cleanup    -\
    Stop server              * -&gt;  Insert data -&gt; Start server
            \-&gt; Drop table -/
</pre>
<p>This approach reduces the number of builds to configure, but should be used only if your jobs are independent.</p>
<h3>A last tip</h3>
<p>Especially in the one-to-one approach, the pipeline can become pretty long. Jenkins has a nice plugin to visualize the downstream builds: <a href="https://wiki.jenkins-ci.org/display/JENKINS/Downstream+buildview+plugin">Downstream buildview plugin</a>.</p>
<p>We recommend using this plugin to track the progress and visualize the result of complex/long pipelines.</p>
<h3>Conclusion</h3>
<p>Even if the advantages of splitting a long build process into small jobs are obvious, doing so may be more difficult than expected. This post has presented several ways to create dependencies between your jobs for Jenkins/Hudson.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/innovation/'>Innovation</a>, <a href='http://blog.akquinet.de/category/all/osgi-and-mobile-solutions/'>OSGi and Mobile Solutions</a> Tagged: <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/build/'>build</a>, <a href='http://blog.akquinet.de/tag/continuous-delivery/'>continuous delivery</a>, <a href='http://blog.akquinet.de/tag/continuous-integration/'>continuous integration</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/hudson/'>hudson</a>, <a href='http://blog.akquinet.de/tag/jenkins/'>jenkins</a>, <a href='http://blog.akquinet.de/tag/jobs/'>jobs</a>, <a href='http://blog.akquinet.de/tag/join/'>join</a>, <a href='http://blog.akquinet.de/tag/pipeline/'>pipeline</a>, <a href='http://blog.akquinet.de/tag/trigger/'>trigger</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1566/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1566&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2011/11/09/building-pipelines-by-linking-jenkins-jobs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-job-list.png" medium="image">
			<media:title type="html">Jobs to achieve our second scenario</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-stop-server-config-jenkins.png" medium="image">
			<media:title type="html">Post-build action</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-cleanup-config-build-trigger.png" medium="image">
			<media:title type="html">Build triggered by another build</media:title>
		</media:content>

		<media:content url="http://akquinetblog.files.wordpress.com/2011/11/pipeline-blog-post-fork-_-join.png" medium="image">
			<media:title type="html">Join plugin configuration</media:title>
		</media:content>
	</item>
		<item>
		<title>Provisioning Maven artifacts with Puppet</title>
		<link>http://blog.akquinet.de/2011/11/01/provisioning-maven-artifacts-with-puppet/</link>
		<comments>http://blog.akquinet.de/2011/11/01/provisioning-maven-artifacts-with-puppet/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 13:12:38 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[JBOSS AID]]></category>
		<category><![CDATA[OSGi and Mobile Solutions]]></category>
		<category><![CDATA[artifacts]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[continuous delivery]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[infrastructure as code]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[nexus]]></category>
		<category><![CDATA[puppet]]></category>
		<category><![CDATA[repository]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1553</guid>
		<description><![CDATA[Our last blog post introduced how Puppet can be used to achieve Infrastructure-As-Code, and how to deploy Play applications following this practice. However, we didn’t address how the applications are actually copied to the host. Apache Maven is a widely used build tool adopted by more and more companies to support their build process from compilation [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1553&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Our last <a title="Deploying Play Framework Application with Puppet" href="http://blog.akquinet.de/2011/10/25/deploying-play-framework-applications-with-puppet/">blog post</a> introduced how Puppet can be used to achieve <em>Infrastructure-As-Code</em>, and how to deploy Play applications following this practice. However, we didn’t address how the applications are actually copied to the host.</p>
<p><a title="Apache Maven" href="http://maven.apache.org" target="_blank">Apache Maven</a> is a widely used build tool adopted by more and more companies to support their build process from compilation to deployment. Deploying, in the  Maven world,  means uploading the <em>artifact</em> to a Maven repository. Such Maven repositories are managed using <a title="Sonatype Nexus" href="http://nexus.sonatype.org/" target="_blank">Sonatype Nexus</a> or <a title="JFrog Artifactory" href="http://www.jfrog.com/" target="_blank">JFrog Artifactory</a>. However, this sort of deployment does not address the real provisioning of the application, i.e the deployment on the production servers.</p>
<p>This blog post presents a Puppet module to download Maven artifacts from a Nexus repository. This module closes the gap between the development team deploying their artifacts to a Maven repository, and the administration team responsible for installing and configuring the application.</p>
<p><span id="more-1553"></span></p>
<h3>Why use Puppet to download Maven artifacts ?</h3>
<p>The first question you&#8217;re probably wondering is &#8220;why?&#8221;. At akquinet, Apache Maven and Nexus are cornerstones of our build processes. However, dealing with the live deployment still requires manual configuration, copies and so on. This process is error-prone and puts a lot of pressure on the development team. So, we started adopting Continuous Delivery and Infrastructure as Code to improve this last deployment step. But, all our applications and artifacts were stored in Nexus repositories, and the deployment to the production servers requires copying them onto a different type of server (generally via SSH/SCP) to be then deployed to the production servers. Even if these copies were automated using a continuous integration server (such as Jenkins), we&#8217;re duplicating the artifacts, making harder to trace the origin of each file. So, it makes a lot of sense to avoid this second server and to retrieve the artifacts directly from Nexus.</p>
<p>The puppet-nexus module is a Puppet extension downloading Maven artifacts from Nexus. Why Nexus? Because it relies on the REST API of Nexus. This Puppet extension supports authentication and repository selection. Actually, we have developed a <a title="Script to download Maven artifacts" href="https://github.com/cescoffier/puppet-nexus/blob/master/files/download-artifact-from-nexus.sh" target="_blank">Bash script to do the job</a>. This script can be used outside of the Puppet module and is just wrapped inside Puppet. But we needed a solution integrated with Puppet and our deployment tool, and which simplified usage of the script.</p>
<h3>The Puppet Nexus Module</h3>
<p>The Puppet Nexus module defines two entities: The Nexus class and the artifact resource.</p>
<p>The Nexus class is configured with the base url of your Nexus installation and the credentials of the user:</p>
<p><pre class="brush: plain;">
class {'nexus':
    url      =&gt; &quot;http://edge.spree.de/nexus&quot;,
    username =&gt; &quot;nexus&quot;,
    password =&gt; &quot;********&quot;
}
</pre></p>
<p>Once done, you can declare <em>nexus::artifacts</em> as follows:</p>
<p><pre class="brush: plain;">
nexus::artifact {'commons-io':
   gav        =&gt; &quot;commons-io:commons-io:2.1&quot;,
   repository =&gt; &quot;public&quot;,
   output     =&gt; &quot;/tmp/commons-io-2.1.jar&quot;
}
</pre></p>
<p>The artifact is identified using the <em>GAV</em> coordinates (<em>groupId:artifactId:version</em>). The module supports <em>SNAPSHOT</em> versions (downloading the latest snapshot). The <em>classifier</em> and <em>packaging</em> attributes allow you to select the right file:</p>
<p><pre class="brush: plain;">
nexus::artifact {'chameleon web distribution':
   gav        =&gt; &quot;org.ow2.chameleon:distribution-web:0.3.0-SNAPSHOT&quot;,
   classifier =&gt; 'distribution',
   packaging  =&gt; 'zip',
   repository =&gt; &quot;public-snapshots&quot;,
   output     =&gt; &quot;/tmp/distribution-web-0.3.0-SNAPSHOT.zip&quot;
</pre></p>
<p>The <em>repository</em> attribute indicates the repository to use, generally a group (i.e. a group of proxies and hosted repositories) such as the <em>public, public-snapshots, central</em>. Check your nexus installation to know which repository you should use.</p>
<p>The <em>output</em> attribute indicates the location of the downloaded artifact. It must be an absolute path (following the Puppet convention).</p>
<p>The <em>ensure</em> parameter can be set to:</p>
<ul>
<li><em>present</em> : does not update the file if already there</li>
<li><em>absent</em> : deletes the file if there</li>
<li><em>update</em> : updates the file (default)</li>
</ul>
<p><pre class="brush: plain;">
# Checks that the file is present, downloads it if needed
nexus::artifact {'ipojo-2':
    gav        =&gt; &quot;org.apache.felix:org.apache.felix.ipojo:1.8.0&quot;,
    repository =&gt; &quot;public&quot;,
    output     =&gt; &quot;/tmp/ipojo-1.8.jar&quot;,
    ensure     =&gt; present
}
# Delete the file
nexus::artifact {'ipojo-1':
    gav        =&gt; &quot;org.apache.felix:org.apache.felix.ipojo:1.8.0&quot;,
    repository =&gt; &quot;public&quot;,
    output     =&gt; &quot;/tmp/ipojo-1.8.jar&quot;,
    ensure     =&gt; absent
}
# Update the file
nexus::artifact {'ipojo-3':
    gav        =&gt; &quot;org.apache.felix:org.apache.felix.ipojo:1.8.0&quot;,
    repository =&gt; &quot;public&quot;,
    output     =&gt; &quot;/tmp/ipojo-1.8.jar&quot;,
    ensure     =&gt; update
}
</pre></p>
<h3>Getting and using the module</h3>
<p>To use the presented module, clone the <a title="Puppet Nexus on Github" href="https://github.com/cescoffier/puppet-nexus" target="_blank">git repository</a>. Once done, configure the <em><a title="Configuring the Puppet Module Path" href="http://docs.puppetlabs.com/references/stable/configuration.html#modulepath" target="_blank">modulepath</a></em> of Puppet in the Puppet configuration file (<em>/etc/puppet/puppet.conf</em>). Once the module is installed correctly, you can download any Maven artifacts from the repositories hosted on your Nexus instance as presented above.</p>
<p>The common pattern is to download an archive containing your application (EAR, ZIP, WAR) and to unzip it (if needed) to the right location such as in the deploy folder of your application server. </p>
<h3>Conclusion</h3>
<p>This blog post has presented a Puppet Module closing the gap between Maven deployment and the production installation. The Nexus Puppet Module allows you to download Maven artifacts on your production servers. Artifacts are still organized and managed by Nexus. They are downloaded when the application is installed using Puppet.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/innovation/'>Innovation</a>, <a href='http://blog.akquinet.de/category/all/jboss-aid/'>JBOSS AID</a>, <a href='http://blog.akquinet.de/category/all/osgi-and-mobile-solutions/'>OSGi and Mobile Solutions</a> Tagged: <a href='http://blog.akquinet.de/tag/artifacts/'>artifacts</a>, <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/continuous-delivery/'>continuous delivery</a>, <a href='http://blog.akquinet.de/tag/deployment/'>deployment</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/infrastructure-as-code/'>infrastructure as code</a>, <a href='http://blog.akquinet.de/tag/maven/'>Maven</a>, <a href='http://blog.akquinet.de/tag/nexus/'>nexus</a>, <a href='http://blog.akquinet.de/tag/puppet/'>puppet</a>, <a href='http://blog.akquinet.de/tag/repository/'>repository</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1553/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1553/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1553/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1553/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1553/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1553/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1553/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1553&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2011/11/01/provisioning-maven-artifacts-with-puppet/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>
	</item>
		<item>
		<title>Deploying Play Framework applications with Puppet</title>
		<link>http://blog.akquinet.de/2011/10/25/deploying-play-framework-applications-with-puppet/</link>
		<comments>http://blog.akquinet.de/2011/10/25/deploying-play-framework-applications-with-puppet/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 13:34:23 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[OSGi and Mobile Solutions]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[infrastructure]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[play!]]></category>
		<category><![CDATA[playframework]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1545</guid>
		<description><![CDATA[Puppet is a configuration management tool made to ease the management of your infrastructure by making it more traceable and easier to understand. It allows infrastructure-as-code, a major trend today to deal with the complexity of infrastructure management. On the other side, Play framework is a promoting a new way to build web applications, making [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1545&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Puppet is a configuration management tool made to ease the management of your infrastructure by making it more traceable and easier to understand. It allows <em>infrastructure-as-code</em>, a major trend today to deal with the complexity of infrastructure management.</p>
<p>On the other side, <a title="Play!" href="http://www.playframework.org/" target="_blank">Play framework</a> is a promoting a new way to build web applications, making this sort of development more efficient and productive. By avoiding the turn over (compilation-packaging-deployment-navigation) after every change, it makes web development fun again.</p>
<p>This blog post explains how you can deploy your Play applications using Puppet. This allows you to develop web apps in a very productive way and deploy them reliably.<br />
<span id="more-1545"></span></p>
<h3>Treat your infrastructure as code</h3>
<p>Infrastructure-as-code is a major trend in IT management. It aims to make infrastructure configuration more traceable and understandable. You can summarize this movement as <em>“Treat your infrastructure as code. Programmable. Testable. Deployable”</em>.</p>
<p>There are a couple of tools to help you make your infrastructure as code such as <a title="Chef" href="http://wiki.opscode.com/display/chef/Home" target="_blank">Chef</a>, <a title="Vagrant" href="http://vagrantup.com/" target="_blank">Vagrant</a> and <a title="Puppet" href="http://puppetlabs.com/" target="_blank">Puppet</a>. There are already plenty of resources to compare them. In this blog post, we use Puppet.</p>
<p>Puppet is an open source configuration manager tool. Puppet follows one important philosophy: you describe <strong>what</strong> not <strong>how</strong>. In other words, you describe the resulting state and not how to reach it. This description is stored in a <em>manifest</em> specifying resources and desired states. Puppet discovers the system information and compiles the manifests into a system-specific catalog containing resources and resource dependency which is applied against the target systems. Any actions taken to remediate the system to the desired state will be reported.</p>
<p>In Puppet, everything is a resource. So, to support Play applications, we just have to define new resources.</p>
<h3>Playing with resources</h3>
<p>To support the provisioning of the Play framework and of Play applications, we wrote a Puppet module (available <a title="Puppet Play Module" href="https://github.com/cescoffier/puppet-play" target="_blank">here</a>) for Ubuntu, defining three resources: <em>module</em>, <em>application</em> and <em>service</em>.</p>
<p>But, before looking into those resources, let’s have a look at the Play <em>class</em> initializing the Play framework support. This class simply checks the availability of the Play framework on the target system and if not available, downloads and installs it.</p>
<p>So now that we’re sure that Play will be installed, let’s look at our resources.</p>
<ul>
<li><em>play::module</em> handles a Play <a title="Play Modules" href="http://www.playframework.org/modules" target="_blank">module</a>. So this resource ensures the availability of a specified module. If not present, it installs the module.</li>
<li><em>play::application</em> handles a Play application. It ensures that the specified Play application is running (or stopped). If needed it starts (or stops) it. In case of starting, it resolves the dependencies. This resource supports the <a title="Framework Id" href="http://www.playframework.org/documentation/1.2.3/ids" target="_blank">framework id</a>, as well as JVM options.</li>
<li><em>play::service</em> handles a Play application started as a service. It ensures that a daemon script is present in <em>/etc/init.d</em> and is started. Similarly to <em>play::application</em>, it supports framework id and JVM options.</li>
</ul>
<h3>Less conversation, more action Please</h3>
<p>Ok, enough talk; let’s see how you can deploy Play applications in practice. First, you need an Ubuntu server with Puppet, git and Java installed. Everything except Puppet can be installed with Puppet.<br />
You can choose to install the Puppet module in <em>/etc/puppet/modules</em> or in any other directory. For that, just clone the Play Puppet Module:</p>
<p><pre class="brush: plain;">
git clone git://github.com/cescoffier/puppet-play.git play
</pre></p>
<p>Check that your Puppet Module path included the chosen module directory (in<em> /etc/puppet/puppet.conf</em>), or declare the <em>modulepath</em> parameter when launching Puppet.</p>
<p>The Puppet module does not define how your application is copied/delivered on your host. You can achieve it using scp, wget or even git. Just choose your preferred way. We just assume that we have our application copied in <em>/var/data-www/bilderverwaltung</em>.</p>
<p>Now, let’s have a look at our manifest, generally named <em>site.pp</em>:</p>
<p><pre class="brush: plain;">
Exec {
    path =&gt; [&quot;/bin&quot;, &quot;/sbin&quot;, &quot;/usr/bin&quot;, &quot;/usr/sbin&quot;],
}
# Install mongoDB
include mongodb
#Install Play and define our Play service
include play
play::module {&quot;mongodb module&quot; :
 	module =&gt; &quot;mongo-1.3&quot;,
	require =&gt; [Class[&quot;play&quot;], Class[&quot;mongodb&quot;]]
}
play::module { &quot;less module&quot; :
 	module =&gt; &quot;less-0.3&quot;,
	require =&gt; Class[&quot;play&quot;]
}
play::application { &quot;bilderverwaltung&quot; :
	path =&gt; &quot;/var/data-www/bilderverwaltung &quot;,
	require =&gt; [Play::Module[&quot;mongodb module&quot;], Play::Module[&quot;less module&quot;]
}
</pre></p>
<p>This manifest installs <em>mongodb</em>, defines two Play modules (less and mongodb), and starts the Play application. The require relationships are used to orchestrate the resolution of resources, i.e. first the Play framework, then the modules and finally the application.</p>
<p>So, if you apply this manifest, it installs the Play framework, installs the two modules, and starts your application:</p>
<p><pre class="brush: plain;">
sudo puppet apply --modulepath=/my/puppet/modules site.pp
</pre></p>
<p>That’s it. Thanks to Puppet, all the tricky configuration parts are managed for you. So just store your manifest in a source code management repository, and you can trace changes, rollback and re-apply the same manifest on different servers. You can also use the Play module in a Puppet master-client configuration to configure and manage sophisticated infrastructure. You can also enhance the manifest to configure an Apache 2 virtual host, or whatever you need.</p>
<h3>Conclusion</h3>
<p>This blog post has briefly introduced the advantage of using infrastructure as code and how you can manage Play applications with Puppet. The Play module <a title="Play Puppet Module" href="https://github.com/cescoffier/puppet-play" target="_blank">web site</a> contains more details about the module and the different resources.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/innovation/'>Innovation</a>, <a href='http://blog.akquinet.de/category/all/osgi-and-mobile-solutions/'>OSGi and Mobile Solutions</a> Tagged: <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/deployment/'>deployment</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/infrastructure/'>infrastructure</a>, <a href='http://blog.akquinet.de/tag/module/'>module</a>, <a href='http://blog.akquinet.de/tag/play/'>play!</a>, <a href='http://blog.akquinet.de/tag/playframework/'>playframework</a>, <a href='http://blog.akquinet.de/tag/puppet/'>puppet</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1545/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1545/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1545/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1545&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2011/10/25/deploying-play-framework-applications-with-puppet/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>
	</item>
		<item>
		<title>Simplify OSGi application tests with the OSGi Helper library</title>
		<link>http://blog.akquinet.de/2011/10/09/simplify-osgi-application-tests-with-the-osgi-helper-library/</link>
		<comments>http://blog.akquinet.de/2011/10/09/simplify-osgi-application-tests-with-the-osgi-helper-library/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 11:15:43 +0000</pubDate>
		<dc:creator>Clement Escoffier</dc:creator>
				<category><![CDATA[All]]></category>
		<category><![CDATA[OSGi and Mobile Solutions]]></category>
		<category><![CDATA[Berlin]]></category>
		<category><![CDATA[chameleon]]></category>
		<category><![CDATA[Deutschland]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[Germany]]></category>
		<category><![CDATA[iPOJO]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[ow2]]></category>
		<category><![CDATA[pax]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[unit]]></category>

		<guid isPermaLink="false">http://blog.akquinet.de/?p=1532</guid>
		<description><![CDATA[Testing OSGi applications and services has always been a difficult challenge. Despite the development of several frameworks such as OPS4J Pax Exam, or junit4osgi, writing tests requires a non-negligible amount of code to manage the OSGi aspect of the test. Indeed, waiting and getting the service under test or releasing the service requires dealing directly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1532&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Testing OSGi applications and services has always been a difficult challenge. Despite the development of several frameworks such as OPS4J Pax Exam, or junit4osgi, writing tests requires a non-negligible amount of code to manage the OSGi aspect of the test. Indeed, waiting and getting the service under test or releasing the service requires dealing directly with the OSGi framework and so the OSGi API. The OSGi Helper library is a small collection of classes to let tests focus on the behavior to verify instead of drowning the code in the depths of the OSGi development model. </p>
<p>The OSGi Helper library was developed by the Innovation department of akquinet, and was contributed to the <a href="http://chameleon.ow2.org">OW2 Chameleon project</a>.</p>
<p>This post explains the benefits brought by the library in comparison to plain OSGi tests.<br />
<span id="more-1532"></span></p>
<h3>Plain OSGi testing</h3>
<p>Let’s imagine the well-known <tt>Hello Service</tt>:<br />
<pre class="brush: java;">
public interface HelloService {
    public String sayHello();
    public String sayHello(String name);
}
</pre></p>
<p>Let&#8217;s also imagine a really great implementation:<br />
<pre class="brush: java;">
@Component
@Provides
@Instantiate
public class HelloServiceImpl implements HelloService {

    public String sayHello() {
        return &quot;hello&quot;;
    }

    public String sayHello(String name) {
        return &quot;hello &quot; + name;
    }
}
</pre></p>
<p>This implementation is using the Apache Felix iPOJO component model, but you can imagine any other development model such as plain OSGi, SCR or Blueprint.</p>
<p>Now that we have our application, let’s look at a simple OSGi test for our Hello Service:</p>
<p><pre class="brush: java;">
@Test
public void testWithoutHelpers() throws Exception {
    HelloService service = null;
    ServiceReference ref = null;
    for (int i = 0; service == null  &amp;&amp; i &lt; 10; i++) {
        ref = context
            .getServiceReference(
               HelloService.class.getName());
        if (ref == null) {
            // Wait until the service is there...
            Thread.sleep(10);
        } else {
            service = (HelloService) 
                context.getService(ref);
        }
    }

    Assert.assertNotNull(service);

    // We have the service object, run the test
    Assert.assertEquals(&quot;hello&quot;, service.sayHello());
    Assert.assertEquals(&quot;hello John&quot;, 
               service.sayHello(&quot;John&quot;));

    context.ungetService(ref);
}
</pre></p>
<p>The above code uses Pax Exam, but the code would be pretty much the same if you use another testing framework.<br />
Notice that this test contains more OSGi code than functional test. </p>
<h3>Using the OSGi Helper Library</h3>
<p>Let’s now see how our test looks like when using the library:<br />
<pre class="brush: java;">
@Test
public void testWithHelpers() throws Exception {
    HelloService service = helper.waitForService(HelloService.class, null, 1000);
    Assert.assertEquals(&quot;hello&quot;, service.sayHello());
    Assert.assertEquals(&quot;hello John&quot;, service.sayHello(&quot;John&quot;));
}
</pre><br />
The complete code is available from <a href="https://github.com/cescoffier/osgi-test-helpers-example/blob/master/hello-service-it/src/test/java/de/akquinet/innovation/osgi/it/HelloTest.java" title="HelloTest.java">here</a>.</p>
<p>Thanks to the OSGi Helper, the test method focuses only on the functional behavior. The <tt>waitForService</tt> method is looking for the service. If the service is not available before the given timeout (in milliseconds), the test fails. Thanks to this simple method, getting the service to test is definitely simpler. Moreover, you don’t need to release the service. The OSGi helper does it for you.</p>
<h3>OSGi Assertions</h3>
<p>The OSGi Helper library also provides a couple of assertions to check the OSGi aspect of the application (deployed bundles, available services…). The following method gives you a short overview of such assertions:</p>
<p><pre class="brush: java;">
@Test
public void testWithAssertions() throws Exception {
    OSGiAssert assertions = new OSGiAssert(context);

    assertions.assertServiceAvailable(HelloService.class, 1000);

    assertions.assertBundlePresent(&quot;hello-service-impl&quot;);
    Bundle bundle = helper.getBundle(&quot;hello-service-impl&quot;);
    bundle.stop();
    assertions
        .assertBundleState(&quot;hello-service-impl&quot;, Bundle.RESOLVED);

    assertions.assertServiceUnavailable(HelloService.class);

    bundle.start();
    assertions
        .assertBundleState(&quot;hello-service-impl&quot;, Bundle.ACTIVE);
    assertions.assertServiceAvailable(HelloService.class, 1000);
}
</pre></p>
<h3>Conclusion</h3>
<p>This blog post has presented a brief overview of the <a href="http://wiki.chameleon.ow2.org/xwiki/bin/view/Main.Testing/OSGi_Helpers" title="OSGi Helper Library">OSGi Helper library</a>. This library contains more good stuff to test OSGi and iPOJO applications.<br />
The code of this blog post is available from <a href="https://github.com/cescoffier/osgi-test-helpers-example" title="osgi-test-helpers-example">Github</a>. </p>
<p>The OSGi Helper library was developed by the Innovation team of akquinet in order to improve the testability and the quality of OSGi applications. The library is now part of the OW2 Chameleon project and delivered under the Apache License 2.0.</p>
<br />Filed under: <a href='http://blog.akquinet.de/category/all/'>All</a>, <a href='http://blog.akquinet.de/category/all/osgi-and-mobile-solutions/'>OSGi and Mobile Solutions</a> Tagged: <a href='http://blog.akquinet.de/tag/berlin/'>Berlin</a>, <a href='http://blog.akquinet.de/tag/chameleon/'>chameleon</a>, <a href='http://blog.akquinet.de/tag/deutschland/'>Deutschland</a>, <a href='http://blog.akquinet.de/tag/exam/'>exam</a>, <a href='http://blog.akquinet.de/tag/germany/'>Germany</a>, <a href='http://blog.akquinet.de/tag/ipojo/'>iPOJO</a>, <a href='http://blog.akquinet.de/tag/junit/'>junit</a>, <a href='http://blog.akquinet.de/tag/osgi/'>osgi</a>, <a href='http://blog.akquinet.de/tag/ow2/'>ow2</a>, <a href='http://blog.akquinet.de/tag/pax/'>pax</a>, <a href='http://blog.akquinet.de/tag/test/'>test</a>, <a href='http://blog.akquinet.de/tag/unit/'>unit</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/akquinetblog.wordpress.com/1532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/akquinetblog.wordpress.com/1532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/akquinetblog.wordpress.com/1532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/akquinetblog.wordpress.com/1532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/akquinetblog.wordpress.com/1532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/akquinetblog.wordpress.com/1532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/akquinetblog.wordpress.com/1532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/akquinetblog.wordpress.com/1532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/akquinetblog.wordpress.com/1532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/akquinetblog.wordpress.com/1532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/akquinetblog.wordpress.com/1532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/akquinetblog.wordpress.com/1532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/akquinetblog.wordpress.com/1532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/akquinetblog.wordpress.com/1532/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.akquinet.de&amp;blog=7947367&amp;post=1532&amp;subd=akquinetblog&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.akquinet.de/2011/10/09/simplify-osgi-application-tests-with-the-osgi-helper-library/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ab937f7df990a673446f1e30fd9ccfba?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">cescoffier</media:title>
		</media:content>
	</item>
	</channel>
</rss>
