Skip to content
Browse files

funjector

  • Loading branch information...
0 parents commit d78a3f8e0a4ebf99737fc986eec25a38efefccc6 @apage43 apage43 committed
Showing with 86 additions and 0 deletions.
  1. +10 −0 .gitignore
  2. +20 −0 README.md
  3. +10 −0 project.clj
  4. +46 −0 src/funjector/core.clj
10 .gitignore
@@ -0,0 +1,10 @@
+/target
+/lib
+/classes
+/checkouts
+pom.xml
+*.jar
+*.class
+.lein-deps-sum
+.lein-failures
+.lein-plugins
20 README.md
@@ -0,0 +1,20 @@
+Stuff modified .beam code into a running couchbase node...
+
+.jar in downloads section
+
+Usage:
+
+ java -jar funjector.jar [options] file1.beam file2.beam ...
+
+
+Options:
+
+ -N[arg] Couchbase node (default: http://127.0.0.1:8091/)
+ --node[=arg]
+
+ -u[arg] Couchbase username (default: Administrator)
+ --username[=arg]
+
+ -p[arg] Couchbase password (default: password)
+ --password[=arg]
+
10 project.clj
@@ -0,0 +1,10 @@
+(defproject funjector "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.4.0"]
+ [clojopts "0.3.2"]
+ [org.clojure/data.codec "0.1.0"]
+ [clj-http "0.5.6"]]
+ :main funjector.core)
46 src/funjector/core.clj
@@ -0,0 +1,46 @@
+(ns funjector.core
+ (:use clojopts.core
+ clojure.pprint)
+ (:import java.io.ByteArrayOutputStream)
+ (:require [clj-http.client :as http]
+ [clojure.string :as st]
+ [clojure.data.codec.base64 :as b64]
+ [clojure.java.io :as io])
+ (:gen-class))
+
+(defn erl-format [xpr]
+ (str "list_to_binary(io_lib:format(\"~w\",[" xpr "]))"))
+
+(defn load-expr [filename]
+ (let [beamfile (io/file filename)
+ basename (st/replace (.getName beamfile) ".beam" "")
+ baos (ByteArrayOutputStream.)]
+ (io/copy beamfile baos)
+ (erl-format (str "code:load_binary(" basename ",\"" (.getName beamfile)
+ "\",base64:decode(<<\""
+ (String. (b64/encode (.toByteArray baos))) "\">>))"))))
+
+(defn load-files [opts]
+ (when-let [files (seq (:clojopts/more opts))]
+ (let [{:keys [username password node]} opts
+ nodeuri (java.net.URI. node)
+ results (:body (http/post (str (.resolve nodeuri "/diag/eval"))
+ {:basic-auth [username password]
+ :as :json
+ :body (str "{json,[" (st/join "," (map load-expr files)) "]}.")}))]
+ (doseq [[file result] (map vector files results)]
+ (println file "-" result)))))
+
+(defn -main
+ [& args]
+ (let [opts (merge
+ {:node "http://127.0.0.1:8091/"
+ :username "Administrator"
+ :password "password"}
+ (clojopts "funjector" args
+ (optional-arg node N "Couchbase node (default: http://127.0.0.1:8091/)")
+ (optional-arg username u "Couchbase username (default: Administrator)")
+ (optional-arg password p "Couchbase password (default: password)")))]
+ (try (load-files opts)
+ (catch clojure.lang.ExceptionInfo e
+ (pprint (select-keys (:object (ex-data e)) [:status :headers :body]))))))

0 comments on commit d78a3f8

Please sign in to comment.
Something went wrong with that request. Please try again.