Skip to content

Instantly share code, notes, and snippets.

(defproject todo-rest "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[ring "1.5.0"]
[compojure "1.5.1"]
[ring/ring-json "0.4.0"]
[org.clojure/java.jdbc "0.6.1"]
(ns todo-rest.core
(:require [ring.adapter.jetty :as jetty]
[ring.middleware.reload :refer [wrap-reload]]
[ring.middleware.json :refer [wrap-json-response wrap-json-params]]
[compojure.core :refer [defroutes context GET POST PUT DELETE]]
[compojure.route :refer [not-found]]
[clojure.java.jdbc :as jdbc])
(:import com.mchange.v2.c3p0.ComboPooledDataSource)
(:gen-class))
@jacoelho
jacoelho / clojure.yml
Created July 17, 2016 11:12
install clojure with ansible
- hosts: localhost
become: yes
connection: local
tasks:
- apt:
package: openjdk-8-jdk-headless
update_cache: yes
cache_valid_time: 3600
@jacoelho
jacoelho / alter.rb
Created July 12, 2016 19:08
custom resource alter
require "chef/log"
def alter!(directory, zookeeper, topic, partitions)
cmd = %W(
#{directory}/bin/kafka-topics.sh
--zookeeper #{zookeeper}
--alter
--topic #{topic}
--partitions #{partitions}
).join(" ")
@jacoelho
jacoelho / update.rb
Created July 12, 2016 19:07
custom resource update
action :update do
alter! new_resource.directory,
new_resource.zookeeper,
new_resource.topic,
new_resource.partitions
end
@jacoelho
jacoelho / create.rb
Created July 12, 2016 19:05
custom resource create improved
action :create do
# calls the block if current_resource does not exist
# or values are different from current_resource
converge_if_changed do
if current_resource
action_update
else
converge_by "Create topic #{new_resource.topic}" do
create! new_resource.directory,
new_resource.zookeeper,
@jacoelho
jacoelho / load_current_value.rb
Last active July 12, 2016 18:59
custom resource load_current_value
load_current_value do
current_partitions, current_replicas = list(directory, zookeeper, topic)
.values_at *%w(partitions replicas)
current_value_does_not_exist! unless current_partitions && current_replicas
partitions current_partitions
replicas current_replicas
end
@jacoelho
jacoelho / list.rb
Created July 12, 2016 18:44
custom resource list
def list(directory, zookeeper, topic)
cmd = %W(
#{directory}/bin/kafka-topics.sh
--zookeeper #{zookeeper}
--describe
--topic #{topic}
).join(" ")
result = shell_out(cmd).stdout
extract = ->(a) { a && a.to_i }
@jacoelho
jacoelho / create_spec.rb
Last active July 12, 2016 18:43
simple chefspec example
require "spec_helper"
context "test_example" do
let(:chef_conf) do
ChefSpec::SoloRunner.new cookbook_path: %w(./test/cookbooks ../), # import test and example cookbook
step_into: %w(example_topic) # dive inside example_topic
end
let(:shellout) { double("shellout") } # setup shellout double
name "test_example"
maintainer "The Authors"
maintainer_email "[email protected]"
license "all_rights"
description "Installs/Configures test"
long_description "Installs/Configures test"
version "0.1.0"
depends "example" # example cookbook dependency