Browse files

First commit

  • Loading branch information...
0 parents commit 1ed8d383451c7b5c0ad9cad1d0abb4f4b6278c7d Corey M. Hoffstein committed Aug 24, 2011
21 project.clj
@@ -0,0 +1,21 @@
+(defproject servlet-test "1.0.0-SNAPSHOT"
+ :description "FIXME: write"
+ :dependencies [[org.clojure/clojure "1.2.0"]
+ [org.clojure/clojure-contrib "1.2.0"]
+ [net.cgrand/moustache "1.0.0"]
+ [ring "0.3.7"]
+ [org.cloudhoist/pallet "0.6.2"]
+ [org.cloudhoist/pallet-crates-all "0.5.0"]
+ [org.jclouds/jclouds-all "1.0.0"]
+ [org.jclouds.driver/jclouds-jsch "1.0.0"]]
+
+ :dev-dependencies [[uk.org.alienscience/leiningen-war "0.0.3"]
+ [org.cloudhoist/pallet-lein "0.4.0"]
+ [vmfest "0.2.3"]]
+
+ :repositories {"sonatype"
+ "http://oss.sonatype.org/content/repositories/releases"
+ "sonatype-snapshots"
+ "http://oss.sonatype.org/content/repositories/snapshots"}
+
+ :aot [servlet-test.core])
16 src/pallet/task/my_deploy.clj
@@ -0,0 +1,16 @@
+(ns pallet.task.my-deploy
+ (:use (clojure.contrib strint core))
+ (:require
+ [servlet-test.ops.nodes :as webdeploy-nodes]
+ pallet.core
+ [org.jclouds.compute :as jcompute]
+ [clojure.contrib.logging :as log]))
+
+(defonce cloud-service (pallet.compute/compute-service-from-config-file "aws-ec2"))
+
+(when-not webdeploy-nodes/warfile-path
+ (throw (IllegalStateException. "No .war file defined, cannot deploy")))
+
+(pallet.core/converge {webdeploy-nodes/appserver 1}
+ :compute cloud-service
+ :phase [:deploy]))
15 src/pallet/task/my_shutdown.clj
@@ -0,0 +1,15 @@
+(ns pallet.task.my-shutdown
+ (:use (clojure.contrib strint core))
+ (:require
+ [servlet-test.ops.nodes :as webdeploy-nodes]
+ pallet.core
+ [org.jclouds.compute :as jcompute]
+ [clojure.contrib.logging :as log]))
+
+(defonce cloud-service (pallet.compute/compute-service-from-config-file "aws-ec2"))
+
+(when-not webdeploy-nodes/warfile-path
+ (throw (IllegalStateException. "No .war file defined, cannot deploy")))
+
+(pallet.core/converge {webdeploy-nodes/appserver 0}
+ :compute cloud-service))
10 src/servlet_test/core.clj
@@ -0,0 +1,10 @@
+(ns servlet-test.core
+ (:use [net.cgrand.moustache]
+ [ring.util.servlet :only (defservice)])
+ (:gen-class :extends javax.servlet.http.HttpServlet))
+
+(def routes
+ (app
+ [_] {:get (fn [req] {:status 200 :body "HELLO, WORLD!"})}))
+
+(defservice #'routes)
32 src/servlet_test/ops/crate.clj
@@ -0,0 +1,32 @@
+(ns servlet-test.ops.crate
+ (:use (clojure.contrib strint core))
+ (:require
+ (pallet core resource)
+ pallet.resource.service
+ (pallet.crate
+ [tomcat :as tomcat]
+ [etc-default :as default])))
+
+(defn tomcat-deploy
+ "Deploys the specified .war file to tomcat. An optional :port kwarg
+ defines the port that tomcat will serve on (defaults to 80)."
+ [pallet-request warfile & {:keys [port] :or {port 80}}]
+ (pallet.resource.service/with-restart pallet-request "tomcat*"
+ (default/write "tomcat6"
+ ; configure tomcat's heap to utilize 2/3 of machine's total memory
+ :JAVA_OPTS (->> pallet-request
+ :target-node
+ .getHardware
+ .getRam
+ (* 0.66)
+ int
+ (format "-Xmx%sm"))
+ ; allow tomcat to run on ports < 1024
+ :AUTHBIND "yes")
+ (tomcat/server-configuration
+ (tomcat/server
+ (tomcat/service
+ (tomcat/connector :port (str port) :protocol "HTTP/1.1"
+ :connectionTimeout "20000"
+ :redirectPort "8443"))))
+ (tomcat/deploy "ROOT" :local-file warfile :clear-existing true)))
45 src/servlet_test/ops/nodes.clj
@@ -0,0 +1,45 @@
+(ns servlet-test.ops.nodes
+ (:use clojure.contrib.core)
+ (:require
+ [servlet-test.ops.crate :as webdeploy-crate]
+ (pallet core resource)
+ (pallet.crate java
+ [tomcat :as tomcat]
+ [automated-admin-user :as admin])
+ [clojure.contrib.logging :as log]))
+
+(def warfile-path
+ ; this is just making things easier for demonstration purposes
+ ; for a real project, you'd likely want to parameterize this via
+ ; a system property (or use the maven dependency plugin to copy
+ ; a separately-build .war to a known location), so as to separate
+ ; the production of the war artifact from its deployment
+ (or (-?>> "target"
+ java.io.File.
+ .listFiles
+ (filter #(.endsWith (.getName %) ".war"))
+ first
+ .getAbsolutePath)
+ (when-not *compile-files*
+ (log/fatal "No .war artifact available in target dir, deployment operations will FAIL"))))
+
+(def nodespec (pallet.core/node-spec
+ :hardware {:os-family :ubuntu
+ :os-description-matches "10.10"
+ :min-ram 1024
+ ;; can optionally require cloud-specific images and node sizes if you like
+ ;; (strongly recommended for real usage!)
+ ;; :image-id "us-east-1/ami-508c7839"
+ ;; :hardware-id "m1.small"
+ :inbound-ports [22 80]}))
+
+(def appserver
+ (pallet.core/server-spec
+ :phases {:bootstrap (pallet.phase/phase-fn
+ (admin/automated-admin-user))
+ :configure (pallet.phase/phase-fn
+ (pallet.crate.java/java :openjdk)
+ (tomcat/tomcat))
+ :deploy (pallet.phase/phase-fn
+ (webdeploy-crate/tomcat-deploy warfile-path))}
+ :node-spec nodespec))
27 src/web.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app
+ version="2.5"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <servlet>
+ <servlet-name>servlet_test</servlet-name>
+ <servlet-class>servlet_test.core</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>servlet_test</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>default</servlet-name>
+ <url-pattern>*.css</url-pattern>
+ <url-pattern>*.js</url-pattern>
+ <url-pattern>*.png</url-pattern>
+ <url-pattern>*.jpg</url-pattern>
+ <url-pattern>*.gif</url-pattern>
+ <url-pattern>*.ico</url-pattern>
+ <url-pattern>*.swf</url-pattern>
+ </servlet-mapping>
+</web-app>
6 test/servlet_test/test/core.clj
@@ -0,0 +1,6 @@
+(ns servlet-test.test.core
+ (:use [servlet-test.core] :reload)
+ (:use [clojure.test]))
+
+(deftest replace-me ;; FIXME: write
+ (is false "No tests have been written."))

0 comments on commit 1ed8d38

Please sign in to comment.