<?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/"
	>

<channel>
	<title>Cake Solutions Team Blog &#187; Ani&#8217;s Blog</title>
	<atom:link href="http://www.cakesolutions.net/teamblogs/category/anis-blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cakesolutions.net/teamblogs</link>
	<description>void magic() { }</description>
	<lastBuildDate>Tue, 07 Feb 2012 12:02:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Configuring Jenkins plugin for SBT</title>
		<link>http://www.cakesolutions.net/teamblogs/2012/01/05/configuring-jenkins-plugin-for-sbt/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=configuring-jenkins-plugin-for-sbt</link>
		<comments>http://www.cakesolutions.net/teamblogs/2012/01/05/configuring-jenkins-plugin-for-sbt/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 14:01:43 +0000</pubDate>
		<dc:creator>Anirvan Chakraborty</dc:creator>
				<category><![CDATA[Ani's Blog]]></category>
		<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[sbt]]></category>
		<category><![CDATA[sbt-launcher]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Specs2 Spring]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=1764</guid>
		<description><![CDATA[As a logical next step of moving Specs2 Spring from Maven to SBT, I have now got Specs2 Spring building comfortably in our local Jenkins using the SBT goodness. The process was pretty straight forward! First, I installed the sbt-plugin &#8230; <a href="http://www.cakesolutions.net/teamblogs/2012/01/05/configuring-jenkins-plugin-for-sbt/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As a logical next step of moving <a href="http://www.cakesolutions.org/specs2-spring.html" title="Specs2-Spring" target="_blank">Specs2 Spring</a> from <a href="http://www.cakesolutions.net/teamblogs/2012/01/04/maven-to-sbt/" title="Maven to SBT" target="_blank">Maven to SBT</a>, I have now got Specs2 Spring building comfortably in our local <a href="http://jenkins-ci.org/" title="Jenkins" target="_blank">Jenkins</a> using the SBT goodness. The process was pretty straight forward!</p>
<p>First, I installed the <b>sbt-plugin</b> for Jenkins from the list of available plugins under <b>Manage Plugin</b>.</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/manage.jpeg"><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/manage-300x191.jpg" alt="Manage plugin" title="Manage plugin"/></a></p>
<p>Once the plugin installation completes and <code>Jenkins</code> is restarted, I verified that sbt-plugin is now available as one of the installed <code>Jenkins</code> plugins.</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/installed.jpeg"><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/installed-300x121.jpg" alt="sbt-plging installed" title="sbt-plging installed" width="300" height="121" /></a></p>
<p>Now that sbt-plugin is available on <code>Jenkins</code>, I had to configure a sbt launcher jar. I downloaded the very latest sbt launcher jar [0.11.2] from <a href="http://typesafe.artifactoryonline.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/0.11.2/sbt-launch.jar" title="sbt-launcher.jar" target="_blank">here</a>, and saved it on our <code>Jenkins</code> build server. In order to complete the configuration, I had to specify the name and location of the sbt launcher jar under Jenkins configuration.</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/configure.jpeg"><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/configure-300x68.jpg" alt="configure sbt plugin" title="configure sbt plugin" width="300" height="68" /></a></p>
<p>Jenkins sbt plugin allows you to install multiple versions of sbt launcher jar files giving you the option of choosing the most appropriate one for your project.</p>
<p>All that remained now was to create a <code>Jenkins</code> build job which used sbt-launcher to build <code>Spec2Spring</code>. To do that I simply selected <b>Build using sbt</b> from Add build step.</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/addjob.jpeg"><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/addjob.jpeg" alt="add job step 1" title="add job step 1" width="242" height="130" /></a></p>
<p>Finally, I selected my preferred sbt launcher and specified the actions I wanted to run. And that was <em>all</em> I had to do!</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/addjob2.jpeg"><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2012/01/addjob2-300x64.jpg" alt="add job step 2" title="add job step 2" width="300" height="64" /></a></p>
<p><code>-Dsbt.log.noformat=true</code> sbt flag keeps the console output clean and tidy!</p>
<p>Note: To avoid frequent <code>OutOfMemory</code> errors, add something like the following JVM flags to your Jenkins build configuration (notice in particular the stack and perm gen size parameters):</p>
<p><code>-XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss16M</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2012/01/05/configuring-jenkins-plugin-for-sbt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dependency injection vs. Cake pattern</title>
		<link>http://www.cakesolutions.net/teamblogs/2011/12/15/dependency-injection-vs-cake-pattern/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dependency-injection-vs-cake-pattern</link>
		<comments>http://www.cakesolutions.net/teamblogs/2011/12/15/dependency-injection-vs-cake-pattern/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 16:09:07 +0000</pubDate>
		<dc:creator>Jan Machacek</dc:creator>
				<category><![CDATA[Ani's Blog]]></category>
		<category><![CDATA[Jan's Blog]]></category>
		<category><![CDATA[Cake pattern]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Play]]></category>
		<category><![CDATA[Scala]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=1545</guid>
		<description><![CDATA[Typically, the argument comes down to is Spring Framework better than Play Framework?, is Lift better than Spring Framework?, is Grails better than everything else?. In this post, we will explore the world of contemporary JEE applications, paying extra attention &#8230; <a href="http://www.cakesolutions.net/teamblogs/2011/12/15/dependency-injection-vs-cake-pattern/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Typically, the argument comes down to <em>is <a title="Spring Framework" href="http://www.springframework.org" target="_blank">Spring Framework</a> better than <a title="Play Framework" href="http://www.playframework.org/" target="_blank">Play Framework</a>?</em>, <em>is <a title="Lift" href="http://liftweb.net/" target="_blank">Lift</a> better than <a title="Spring Framework" href="http://www.springframework.org" target="_blank">Spring Framework</a>?</em>, <em>is <a title="Grails" href="http://grails.org/" target="_blank">Grails</a> better than everything else?</em>. In this post, we will explore the world of contemporary JEE applications, paying extra attention to the usual DI frameworks and frameworks that implement the Cake pattern.</p>
<p>For more detailed discussion of the Cake pattern, see Mark&#8217;s <a href="http://www.cakesolutions.net/teamblogs/2011/12/19/cake-pattern-in-depth/" title="Cake pattern in depth">Cake pattern in depth</a></p>
<p>Before we rush into condemning one or the other, we feel that what you need to think about what kind of application you&#8217;re writing. We&#8217;ll go as far as to say that if you need JMS, JMX, scheduling, WebFlow, &#8230;, then you should stick with the Spring Framework. By all means implement the components that make up your Spring application in Scala! If these JEE dinosaurs do not come anywhere near your application, then Play 2 in Scala, using the Cake pattern might just be the perfect thing for you!</p>
<h2>Dependency injection</h2>
<p>Spring Framework, we have multiple modules; each module contains the code that is appropriate for the tier that the module implements. The code means the Java interfaces &amp; their implementations as well as the Spring configuration (typically in the <code>META-INF/spring/module-context.xml</code> file). The types of the dependencies are checked at compile-time: if we haven&#8217;t defined the <code>UserService</code> interface, for example, and tried to use it in the <code>UserController</code>, the compilation would fail. However, the compiler cannot check that the appropriate implementation of the <code>UserService</code> will be available to be injected to the <code>UserController</code> at runtime. The application is loosely coupled, which is good, but we must supply appropriate metadata (the annotations &amp; the Spring XML) so that Spring can construct the application.</p>
<blockquote><p>Dependency-injection applications must provide valid metadata so that the DI framework can construct their components &amp; satisfy the dependencies between them at runtime.</p></blockquote>
<p>Let&#8217;s write a trivial application that contains a repository and a service. We will follow the recommended code to interfaces approach. This gives us the following code in the repository:</p>
<pre class="brush:[java]">public interface UserRepository {
  List&lt;User&gt; findAll();
}

@Repository
public class ORMUserRepository implements UserRepository {
  private SessionFactory sessionFactory = // construct the SF
  public List&lt;User&gt; findAll() {
    // not real Hibernate code, but close enough
    return sessionFactory.getCurrentSession().query(...);
  }
}</pre>
<p>We now combine this code with the Spring context file, which instructs the DI core to create the <code>ORMUserRepository</code> component.</p>
<pre class="brush:[xml]">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="..."&gt;

  &lt;context:annotation-config/&gt;
  &lt;context:component-scan base-package="...repository"/&gt;

&lt;beans/&gt;</pre>
<p>We implement the code in the services in using a similar pattern: we have the <code>UserService</code> interface and we implement it in some class. Crucially, we will rely on Spring to inject a valid implementation of the <code>UserRepository</code> to the instance of the <code>DefaultUserService</code> at runtime, using the configuration we provide.</p>
<pre class="brush:[java]">public interface UserService {
  List&lt;User&gt; findAll();
}

@Service
public class DefaultUserService implements UserService {
  private final UserRepository userRepository;

  @Autowired
  public DefaultUserService(final UserRepository userRepository) {
    if (userRepository == null)
      throw new IllegalArgumentException("Off Santa's list!");
    this.userRepository = userRepository;
  }

  public List&lt;User&gt; findAll() {
    return this.userRepository.findAll();
  }
}</pre>
<p>The services module needs its configuration, too. And so, we give the familiar <code>/META-INF/spring/module-context.xml</code>:</p>
<pre class="brush:[xml]">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="..."&gt;

  &lt;context:annotation-config/&gt;
  &lt;context:component-scan base-package="...services"/&gt;

&lt;beans/&gt;</pre>
<p>We have the components and the metadata. All we need now is to let Spring Framework create all the components. In other words, the <code>ApplicationContext</code> implementation that the Spring Framework provides will become our application:</p>
<pre class="brush:[java]">public class App {

  public static void main(String[] args) {
    ApplicationContext application =
      new ClassPathXmlApplicationContext(
        "classpath*:/META-INF/spring/module-context.xml"));

    UserService service = application.getBean(UserService.class);

    // use it!
    service.findAll();
  }
}</pre>
<p><em>The Spring Framework became our application! All we have is a shell that boots-up Spring</em>, as shown on Figure 1.</p>
<p>Figure 1. Spring DI application</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/12/springapp1.png"><img title="springapp" src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/12/springapp1.png" alt="" width="568" height="795" /></a></p>
<h2>The Cake Pattern</h2>
<p>If you are writing new Scala application, you might not want to take in all the baggage that Spring Framework brings with it. (Slf4j, anyone?)</p>
<p>You would typically use the Cake Pattern to achieve something akin to dependency injection. Jonas Boner explained the Cake Pattern in one of his infamous <a title="Real-World Scala: Dependency Injection (DI)" href="http://jboner.github.com/2008/10/06/real-world-scala-dependency-injection-di.html" target="_blank">Real-World Scala Series blog post</a>. What we would try here is to use the Cake pattern to implement the same DI scenario in Scala and then compare that with its corresponding Spring implementation. In doing that we would hope to clear out some of the misty clouds over Scala and DI.</p>
<p>We also want to have a repository and a service, but without the XML configuration file. So, we need not only the repository and service interfaces themselves, but we also need components in which they &#8220;live&#8221;. Starting with the repository, we have:</p>
<pre class="brush:[scala]">trait UserRepositoryComponent {
  def userRepository : UserRepository

  trait UserRepository {
    def findAll: List[User]
  }
}

trait ORMUserRepositoryComponent extends UserRepositoryComponent {
  def userRepository = new ORMUserRepository(sf) //we need to actually instantiate the session factory here

  class ORMUserRepositry(val sf: SessionFactory) extends UserRepository {
    def findAll: List[User] = sf.query(...)
  }
}</pre>
<p>Good. We have the repository tier interface the <code>UserRepositoryComponent</code> provides a way to get to the <code>UserRepository</code> instance. We have also shown an implementation of the repository interfaces: the <code>ORMUserRepositoryComponent</code>&#8216;s <code>userRepository</code> function gives an ORM-based implementation of the <code>UserRepository</code>.</p>
<p>Now, we would like to define the interface to the services tier:</p>
<pre class="brush:[scala]">trait UserServiceComponent {
  def userService: UserService

  trait UserService {
    def findAll: List[User]
  }
}</pre>
<p>OK, we have the repository interface &amp; implementation and the service interface. The implementation of the service will need to have access to some implementation of the repository interface. Naturally, we don&#8217;t want to specify which concrete repository interface implementation we want to use. In fact, we would like to let the users of our code specify arbitrary implementation of the repository interfaces. Good thing we have the composition inheritance!</p>
<pre class="brush:[scala]">trait DefaultUserServiceComponent extends UserServiceComponent {
  this: UserRepositoryComponent =&gt; 

  def userService = new DefaultUserService

  class DefaultUserService extends UserService {
    def findAll = userRepository.findAll
  }
}</pre>
<p>Notice in particular <code>this: UserRepositoryComponent =&gt;</code>. This means that the instance of <code>DefaultUserServiceComponent</code> depends on the <code>UserRepositoryComponent</code>. (It&#8217;s a little more subtle than that, but for the purposes of this post it will do.) This is in function equivalent to Spring&#8217;s <code>@Autowired public DefaultUserService(final UserRepository userRepository)</code>. Just like the Spring application we have created, the Scala code does nothing yet. We need to wire it together in some kind of application!</p>
<pre class="brush:[scala]">object Application {
  val userServiceComponent = new DefaultUserServiceComponent with ORMUserRepositoryComponent
  val userService = userServiceComponent.userService
}

val userService = Application.userService
userService.findAll</pre>
<p>In Scala, there is no <code>ApplicationContext</code>, so we have to implement our own application. But where&#8217;s the dependency injection? Here: <code>new DefaultUserServiceComponent with ORMUserRepositoryComponent</code>, notice the <code>with ORMUserRepositoryComponent</code>. Figure 2 shows the Scala application.</p>
<p>Figure 2. Scala DI</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/12/cake-application1.png"><img title="cake application" src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/12/cake-application1.png" alt="" width="600" /></a></p>
<h2>The comparison</h2>
<p>As you can see, the two approaches are completely different in their implementation. DI in Spring Framework is a runtime business and the component separation is left to the way in which we structure the configuration files. DI in Scala/Cake is a compile-time business with sharper component separation. Figure 3 gives the overall comparison.</p>
<p>Figure 3. The big picture</p>
<p><a href="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/12/compare.png"><img title="compare" src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/12/compare.png" alt="" width="600" /></a></p>
<h2>Summary</h2>
<p>As we have shown here, both pattern represent in function a kind of dependency injection &amp; management. However, the crucial difference is that the dependency injection (in Spring Framework) is useful to manage components, leaving us to carefully design the components. The Cake Pattern allows us to inject &amp; manage functionality. We use traits to assemble components with the functionality we require. It is a different approach to design. Let me repeat:</p>
<p>In plain dependency injection, we create components and we assemble these components together to form an application.<br />
Using the Cake Pattern, we create pieces of functionality and we assemble the functionality to form the application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2011/12/15/dependency-injection-vs-cake-pattern/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Haskell &amp; Happstack on CloudFoundry</title>
		<link>http://www.cakesolutions.net/teamblogs/2011/11/25/haskell-happstack-on-cloudfoundry/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=haskell-happstack-on-cloudfoundry</link>
		<comments>http://www.cakesolutions.net/teamblogs/2011/11/25/haskell-happstack-on-cloudfoundry/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 18:21:47 +0000</pubDate>
		<dc:creator>Anirvan Chakraborty</dc:creator>
				<category><![CDATA[Ani's Blog]]></category>
		<category><![CDATA[cloudfoundry]]></category>
		<category><![CDATA[Happstack]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[vcap]]></category>
		<category><![CDATA[vcap plugin]]></category>
		<category><![CDATA[vmc]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=1411</guid>
		<description><![CDATA[For the past few weeks I have been running some experiments on Cloud Foundry. I was hoping to combine my understanding of the internal workings of VMWare&#8217;s Cloud Application Platform (vcap) with my Haskell code. So, to make sure that &#8230; <a href="http://www.cakesolutions.net/teamblogs/2011/11/25/haskell-happstack-on-cloudfoundry/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For the past few weeks I have been running some experiments on <a href="http://www.cloudfoundry.com" title="Cloud Foundry" target="_blank">Cloud Foundry</a>. I was hoping to combine my understanding of  the internal workings of VMWare&#8217;s Cloud Application Platform (<a href="http://github.com/cloudfoundry/vcap" title="vcap" target="_blank">vcap</a>) with my Haskell code. </p>
<p>So, to make sure that we can run Haskell &#8220;in the cloud&#8221; (especially considering Julian Porter&#8217;s <a href="http://blog.jpembeddedsolutions.com/09/05/2011/steps-towards-haskell-in-the-cloud/" title="CloudHaskell">CloudHaskell</a> work), I decided to include the Haskell runtime and <a href="http://happstack.com/" title="Happstack">Happstack</a> framework in Cloud Foundry. </p>
<h2>Success!</h2>
<p>And guess, what? It worked!</p>
<p>Before I tell you all the details and point you to my <a href="https://github.com/anirvanc/vcap" title="vcap" target="_blank">Github fork of vcap</a>, I&#8217;ll show you, starting with Figure 1, which shows that <code>vmc runtimes</code> now includes [The Glorious Glasgow--ridiculous, I know!] Haskell compiler.</p>
<p>Figure 1. GHC runtime</p>
<p><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/11/runtimes.png" alt="" title="runtimes" /></p>
<p>Next, I have the Happstack framework; Figure 2 shows the output of running <code>vmc frameworks</code>.</p>
<p>Figure 2. Happstack framework</p>
<p><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/11/frameworks.png" alt="" title="frameworks" /></p>
<p>Moving on, I&#8217;m going to deploy trivial Haskell/Happstack application. (Naturally, I <em>could</em> write some amazing Haskell code, but Hello World is the most didactical!). The source is</p>
<pre class="brush:[c]">
module Main where

import Happstack.Server (nullConf, simpleHTTP, toResponse, ok)

main :: IO ()
main = simpleHTTP nullConf $ ok "Hello, World! Haskell is COOL!"
</pre>
<p>Now that I have the application, let&#8217;s deploy it in CloudFoundry, using the usual <code>vmc push</code> command. The updated <code>vmc</code> recognises that the app is indeed a Haskell/Happstack one and selects the appropriate runtime/framework combination. (Viz Figure 3).</p>
<p>Figure 3. vmc push</p>
<p><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/11/push.png" alt="" title="push"  /></p>
<p>Finally, we need to show you that the application is indeed running. So, on to the browser and go to <code>http://haskellapp.vcap.me</code> and see Figure 4.</p>
<p>Figure 4. The result</p>
<p><img src="http://www.cakesolutions.net/teamblogs/wp-content/uploads/2011/11/proof.png" alt="" title="proof" /></p>
<h2>The code</h2>
<p>Let&#8217;s take a look at what we had to do to get it running.</p>
<h3>Hacking vcap</h3>
<p>To make sure that the Cloud Controller understands the new runtime and framework, I modified the &#8216;app&#8217; model by adding the following code:</p>
<pre class="brush:[ruby]">
Runtimes = %w[ruby18 ruby19 java node php erlangR14B02 python26 haskell]
Frameworks = %w[sinatra rails3 java_web spring grails node php otp_rebar lift wsgi django happstack unknown]
...
...
when "happstack/1.0"
    self.framework = 'happstack'
    self.runtime   = 'haskell'
end
</pre>
<p>Next up is the cloud_controller.yml file</p>
<pre class="brush:[ruby]">
  haskell:
    version: "[6-7].*"
</pre>
<p>Now we need make sure that the &#8216;dea&#8217; is configured, so the dea.yml file</p>
<pre class="brush:[ruby]">
  haskell:
    executable: /usr/bin/runhaskell
    version: 6.12.1
    version_flag: '--version'
    environment:
</pre>
<p>So far the cloud controller knows about the runtime and framework and the dea is configured to deal with them as well. Now we need make sure that a Haskell/Happstack app can be staged in cloud foundry. We added the <code>HappstackPlugin</code> and the <code>manifest</code> for Happstack.</p>
<pre class="brush:[ruby]">
class HappstackPlugin < StagingPlugin
  def framework
    'happstack'
  end

  def stage_application
    Dir.chdir(destination_directory) do
      create_app_directories
      copy_source_files
      create_startup_script
    end
  end

  def start_command
    "runhaskell Main.hs"  #Equivalent of
  end

  ...
end
</pre>
</pre>
<pre class="brush:[ruby]">
---
name: "happstack"
runtimes:
  - haskell:
      version: '6.12.1'
      description: 'The Glorious Glasgow Haskell Compilation System'
      executable: /var/vcap/runtimes/haskell-6.12.1/bin/runhaskell
      default: true
app_servers:
detection:
  - "*.hs": true
staged_services:
</pre>
<p>In this post, I&#8217;m ignoring the pains of installing Haskell/Happstack on Ubuntu 10.04&#8211;there&#8217;s a long blog post coming up about that soon! For the brave, take a look at <code>setup/vcap_setup</code> in the vcap repository.</p>
<h3>Hacking vmc</h3>
<p>Not a lot but still you would need the following to get <code>vmc</code> to understand the new runtime and framework: <code>frameworks.rb</code></p>
<pre class="brush:[ruby]">
module VMC::Cli

  class Framework

    DEFAULT_FRAMEWORK = "http://b20nine.com/unknown"
    DEFAULT_MEM = '256M'

    FRAMEWORKS = {
      ...,
      'Happstack'         =&gt; ['happstack',
         { :mem =&gt; '128M', :description =&gt; 'Happstack Web Application'}]
    }

    class &lt;&lt; self

      def known_frameworks
        FRAMEWORKS.keys
      end

      def lookup(name)
        return Framework.new(*FRAMEWORKS[name])
      end

      def detect(path)
        Dir.chdir(path) do
          ...
          ...
          # Happstack
          elsif !Dir.glob('*.hs').empty?
            return Framework.lookup('Happstack')

          end
        end
        nil
      end

    end

...
end
</pre>
<h2>References &amp; Downloads</h2>
<p>We&#8217;ll send a pull request to the VMWare guys soon (after a bit of gold platting&#8230;), but in the meantime, you can fork <a href="https://github.com/anirvanc/vcap" title="vcap" target="_blank">https://github.com/anirvanc/vcap</a> and <a href="https://github.com/anirvanc/vmc" title="vmc" target="_blank">https://github.com/anirvanc/vmc</a> and get hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2011/11/25/haskell-happstack-on-cloudfoundry/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Continuous Integration and Performance Management</title>
		<link>http://www.cakesolutions.net/teamblogs/2009/03/18/continuous-integration-and-performance-management/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=continuous-integration-and-performance-management</link>
		<comments>http://www.cakesolutions.net/teamblogs/2009/03/18/continuous-integration-and-performance-management/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 14:09:31 +0000</pubDate>
		<dc:creator>Anirvan Chakraborty</dc:creator>
				<category><![CDATA[Ani's Blog]]></category>
		<category><![CDATA[Continuous Integration]]></category>
		<category><![CDATA[Performance Management]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/?p=103</guid>
		<description><![CDATA[This is my first post in many ways; 1. It is certainly the first one of the year 2009 (shame!). By the way &#8220;Happy New Year&#8221;! 2. I don&#8217;t remember when was my last blog post (shame again!!). I have &#8230; <a href="http://www.cakesolutions.net/teamblogs/2009/03/18/continuous-integration-and-performance-management/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is my first post in many ways;<br />
	1.  It is certainly the first one of the year 2009 (shame!). By the way &#8220;Happy New Year&#8221;!<br />
	2.  I don&#8217;t remember when was my last blog post (shame again!!).</p>
<p>I have got a perfectly valid set of arguments to justify &#8220;me not blogging&#8221;, but I would not want to bore you lot with that <img src='http://www.cakesolutions.net/teamblogs/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Instead, let&#8217;s talk about something interesting, like &#8220;Continuous Integration&#8221;! I am sure you all do it and so do I. We @Cake use <a href="http://www.atlassian.com/software/bamboo">Atlassian Bamboo</a> as our CI tool, backed up by Ant + Ivy or Maven2 build infrastructure using JUnit. On top of that we have an excellent process of &#8216;Code Review&#8217;, which ensures that we deliver software of a very high standard. In other words, we are perfectly happy with our unit tests running overnight, showing a &#8216;green bar&#8217; and developers addressing their code reviews first thing in the morning. I just love the &#8216;green bar&#8217; though, but that&#8217;s besides the point. Now the question is &#8220;Is that enough of Continuous Integration?&#8221; or &#8220;Does that describe a fairly complete CI process?&#8221; I would have said &#8220;Yeah, thats totally enough&#8221;, till 28th January and I am sure many of you would still say that! But, things did change a bit for me since 28th January 2009, as I attended a webcast from DeCare Systems, titled ‚&#8221;Introducing CPM Toolkit ‚ Bringing Continuous Performance Management to JProbe&#8221;.</p>
<p>I have to agree, that I was a bit skeptical about the webcast. I was thinking in true <a href="http://www.dilbert.com/">Dilbert</a> style, that &#8220;I am an engineer, I can&#8217;t listen to an hour of marketing talk&#8221;! But, boy oh boy, I was wrong! Not only did I like the webcast, I have also been taken by the &#8220;Continuous Performance Management&#8221; idea (honestly, it&#8217;s new to me). Jason Berry, the lead architect of CPM Toolkit did a wonderful demo. The tool is basically a combination of Continuous Integration and Performance Management. Which brings Continuous Performance Management Toolkit, a.k.a CPM Toolkit into play.</p>
<p><a href="http://www.decaresystems.ie/CPM_Toolkit_overview.html">Here</a> you can find a brief introduction of CPM Toolkit. Among others, the two points that got me hooked into it are, &#8220;Discovering performance problems when they are cheapest to solve&#8221; and &#8220;More time resolving and less time searching for the performance problem&#8221;. The CPM Toolkit allows you to pin point the performance problem at a unit test level, so you have a lot less code to find the problem in. This gives you the opportunity to quickly fix the problem and verify that your solution is not causing performance problems for any other parts of your system. I am pretty impressed with the GUI work the guys at DeCare has done. The <a href="http://blog.decaresystems.ie/wp-content/uploads/2008/10/cpm-toolkit-graph-copy.png">graphical representation</a> is simply impressive. To get a better idea of how CPM Toolkit works, I suggest reading Jason&#8217;s <a href="http://blog.decaresystems.ie/index.php/2008/10/08/continuous-performance-management-in-practise">blog</a> about CPM in practice.</p>
<p>One point I must mention here that I am still not 100% convinced that the use of yet another tool in the CI process will actually cut down development cost. Mainly because, I still need to see a real enough example of CPM Toolkit at play. So, I have decided that I am going to try out CPM Toolkit on my next project to get a better feel of it. I will definitely blog about the experience. In the mean time I would advice you guys to get a <a href="http://www.decaresystems.ie/cpm_trial_register.html">Free trial evaluation</a> and give it a go!</p>
<p>I almost forgot that I still don&#8217;t have an answer to my initial question of &#8220;A perfect Continuous Integration process&#8221;. I guess, it&#8217;s very difficult to give a general answer which will fit all organizations. It&#8217;s more to do with the people involved in the process and the tools that are used. There will always be the next new cool tool, but it needs to be judged whether that tool fits into the process or not. I think it is fair enough to say that, introducing CPM ToolKit to your existing CI process can only make it better!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2009/03/18/continuous-integration-and-performance-management/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PostgreSQL database backup and restore</title>
		<link>http://www.cakesolutions.net/teamblogs/2008/02/24/postgresql-database-backup-and-restore/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=postgresql-database-backup-and-restore</link>
		<comments>http://www.cakesolutions.net/teamblogs/2008/02/24/postgresql-database-backup-and-restore/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 18:30:10 +0000</pubDate>
		<dc:creator>Anirvan Chakraborty</dc:creator>
				<category><![CDATA[Ani's Blog]]></category>

		<guid isPermaLink="false">http://www.cakesolutions.net/teamblogs/2008/02/24/postgresql-database-backup-and-restore/</guid>
		<description><![CDATA[In the last couple of weeks I have been using PostgreSQL quite a lot. I have used PostgreSQL before but this time it was different as the development as well as the deployment environment were Linux based, as a result &#8230; <a href="http://www.cakesolutions.net/teamblogs/2008/02/24/postgresql-database-backup-and-restore/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the last couple of weeks I have been using <a href="http://www.postgresql.org">PostgreSQL</a> quite a lot. I have used PostgreSQL before but this time it was different as the development as well as the deployment environment were Linux based, as a result I was denied of the use of <code>pgAdminIII</code>, the GUI based administration tool for PostgreSQL database. My only option was to use the command prompt.</p>
<p>The need of the hour was to backup the live database and restore it on the test environment, which incidentally was also a Linux box. With pgAdminIII, it would have been really simple, take a backup of the database in a binary format and restore the test database from the binary file. So, off I went, digging into the PostgreSQL documentation looking for the commands which will do the same for me and wolla, I found <code><a href="http://www.postgresql.org/docs/current/static/app-pgdump.html">pg_dump</a></code> and <code><a href="http://www.postgresql.org/docs/current/static/app-pgrestore.html">pg_restore</a></code>.</p>
<p><code>pg_dump</code> is the utility for backing up a PostgreSQL database. Following is the command with it&#8217;s options that will create a binary backup of an entire database;<br />
<code>pg_dump -i -h host-name -p port-number -U username -F c -b -v -f "backup-filename.backup" dbname</code></p>
<p><code>pg_restore</code> is the utility for restoring a PostgreSQL database from an archive created by <code>pg_dump</code> in one of the non-plain-text formats. Following is the command with it&#8217;s options that will restore the database from the binary backup file;<br />
<code>pg_restore -i -h host-name -p port-number -U username -d dbname -a -v "backup-filename.backup"</code><br />
I noticed an interesting point while using pg_restore. pg_restore doesn&#8217;t work properly if there are referential integrity among the tables on the target database as tables are restored sequentially. So, the best restoring approach is to first create the tables in the database without enforcing their referential integrity, then run pg_restore to perform the magic. Once restoring is complete you can easily run another script to enforce all the referential integrities at one go. </p>
<p>On a completely different note, it is always considered as a best practice to test your application with a real data-set. This will give you the opportunity to write off those final few bugs which are only exposed when the application is used with a real set of data. What else could be better than the replica of the live database! More over, now you can backup and restore entire PostgreSQL database, even without the help of pgAdminIII. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.cakesolutions.net/teamblogs/2008/02/24/postgresql-database-backup-and-restore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

