Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clojure in the Cloud Everett Toews Developer JavaOne Sept. 29, 12:30 pm.

Similar presentations


Presentation on theme: "Clojure in the Cloud Everett Toews Developer JavaOne Sept. 29, 12:30 pm."— Presentation transcript:

1 Clojure in the Cloud Everett Toews Developer Advocate @everett_toews JavaOne Sept. 29, 2014 @ 12:30 pm

2 Intro Developer

3 PMC and Committer on Apache jclouds

4 Intro Advocate

5

6 Operations

7 Co-author of The OpenStack Ops Guide docs.openstack.org/ops

8 Clojure

9

10 List

11 (2 3)

12 Clojure Vector

13 [2 3]

14 Clojure Map

15 {:key1 "value1" :key2 "value2"} :key2 "value2"}

16 Clojure Parens

17 (fn arg1 arg2) (sf arg1 arg2)

18 Clojure Prefix

19 (+ 2 3) ; 5

20 Clojure Functional

21 (defn add-7 [x] [x] (+ x 7)) (+ x 7))

22 (add-7 3) ; 10

23 (map add-7 [2 3]) ; (9 10)

24 Clojure Types

25 (add-7 "3") ; ClassCastException java.lang.String cannot be cast to java.lang.Number

26 Clojure Destructuring

27 1 (defn print-args 2 [f & rest] 3 (println f) 4 (println 5 (apply sorted-map rest)))

28 (print-args "first" :k3 "v3" :k1 "v1" :k3 "v3" :k1 "v1" :k2 "v2") :k2 "v2") ; first ; {:k1 v1, :k2 v2, :k3 v3}

29 Clojure Lambda

30 (map (fn [x] (+ x 7)) (fn [x] (+ x 7)) [2 3]) [2 3]) ; (9 10)

31 Clojure Macro

32 (defmacro when [test & body] [test & body] (list 'if test (list 'if test (cons 'do body))) (cons 'do body)))

33 (when true (+ 2 3)) ; 5

34 Clojure lein

35 lein new app github-comment-clj lein clean lein install lein test lein run lein repl

36 Clojure REPL

37 PrintEvalRead Loop

38 Cloud

39

40 SaaS

41 IaaS

42 Resources Accessible Via HTTP API

43 HTTP APIs

44

45 Documentation

46 Logging

47 Auth

48 Endpoint

49 Environment

50 Connect!

51 Request

52 Response

53 Headers

54 Body

55 JSON

56 Clojure in the Cloud

57

58 Conjecture in the Cloud ClojectureConjecture

59 Clojure in the Cloud Clojure > Java

60 Clojure in the Cloud Domain Modeling vsMaps

61 Example ExampleSurprise!

62 """" {"key": "value"} Map Map

63 "" {"key": {BLAH}}ParseException

64 Example Example Changing Objects

65 """" {"obj": "BLAH"} "" {"obj": {BLAH}} "" {"obj": [BLAH]}

66 Clojure in the Cloud Example Huge Objects

67

68 Clojure in the Cloud Maps

69 WARNING Demos Ahead

70

71 Clojure in the Cloud Compile/Run/printlnvsREPL

72 Demo lein repl

73 Clojure in the Cloud pom.xml/mvn/Classvs lein try

74 Clojure in the Cloud Demo lein try

75 Clojure in the Cloud Works For Me vs I Feel Your Pain

76 Clojure in the Cloud Demo lein repl :connect

77 Use Case

78 GitHubTwitter Rackspace Jenkins Developer 1.PR 2. Webhook 4. Comment 3. Status 5. Save

79 Talkin’ HTTP

80

81 HTTP Library

82 clj-http

83 Talkin’ HTTP Java SDK

84 Hosebird Client (hbc)

85 Talkin’ HTTP Clojure Bindings for Java SDK

86 Clojure Bindings for Java SDK Apache jclouds

87 Talkin’ HTTP Clojure SDK

88 twitter-apitentacles

89 twitter-api

90 :dependencies

91 1 [org.clojure/clojure "1.4.0"] ;; Clojure 2 [org.clojure/data.json "0.2.1"] ;; JSON 3 [http.async.client "0.5.2"] ;; HTTP 4 [clj-oauth "1.4.0"]] ;; OAuth

92 twitter-api Macros

93 1 (defmacro def-twitter-restful-method 2 [verb resource-path & rest] 3 (let [json-path (str resource-path ".json") 4 dashed-name (...) 5 clean-name (...) 6 fn-name (symbol clean-name)] 7 `(def-twitter-method ~fn-name ~verb ~json-path :api ~*rest-api* :callbacks (get- default-callbacks :sync :single) ~@rest)))

94 1 (defmacro def-twitter-method 2 [fn-name default-verb resource-path & rest] 3 (let [rest-map (apply sorted-map rest)] 4 `(defn ~fn-name 5 [& {:as args#}] 6 (let [...] 7 (http-request verb# uri# arg-map#))))

95 1 (def-twitter-restful-method :get "statuses/home_timeline") 2 (statuses-home-timeline :oauth-creds twitter ‑ creds :params {:count 3}) ; {:headers {:content-length "7558",...} ; :status {:code 200,...} ; :body ; [{:text "Untappd but for Pho",...}...]}

96 1 (def-twitter-restful-method :post "statuses/update") 2 (statuses-update :oauth-creds twitter ‑ creds :params {:status ”Hi!"}) ; {:headers {:content-length ”1904",...} ; :status {:code 200,...} ; :body ; [{:text "Hi!",...}...]}

97 twitter-api Documentation

98 Logging

99 tentacles

100 :dependencies

101 1 [org.clojure/clojure "1.5.1"] ;; Clojure 2 [org.clojure/data.codec "0.1.0"] ;; Base64 3 [clj-http "0.4.0"] ;; HTTP 4 [cheshire "4.0.0"] ;; JSON 5 [com.cemerick/url "0.0.6"] ;; URLs 6 [environ "0.4.0"] ;; Env

102 tentacles Functions

103 1 (defn api-call 2 [method end-point positional query] 3 (let [query (query-map query) 4 all-pages? (query "all_pages") 5 req (make-request...) 6 exec-request-one (fn...(request req)) 7 exec-request (fn...)] 8 (exec-request req)))

104 1 (issues/create-comment "everett-toews” "github-comment-clj" 6 "Hi!" github-creds) ; {:url "https://...", ; :id 378246, ; :user {:id 9775324,...} ; :body "Hi!"}

105 tentacles Documentation

106 Logging

107 jclouds

108 :dependencies

109 1 [org.clojure/clojure "1.3.0"] ;; Clojure 2 [org.clojure/tools.logging "0.2.3"] ;; Log 3 [org.clojure/core.incubator "0.1.0"];; Inc 4 [org.apache.jclouds.labs/ rackspace-cloudfiles-us 1.8.0"] ;; BlobStore rackspace-cloudfiles-us 1.8.0"] ;; BlobStore

110 jclouds JavaClasses/Methods

111 1 (defn create-container 2 [^BlobStore blobstore container-name & 3 {:keys [location public-read?]}] 4 (let [cco (CreateContainerOptions.) 5 cco (if public-read?...)] 6 (.createContainerInLocation blobstore location container-name cco)))

112 1 (defn put-blob 2 [^BlobStore blobstore container-name blob & 3 {:keys [multipart?]}] 4 (let [options (if multipart?...)] 5 (.putBlob blobstore container-name blob options)))

113 1 (def my-blob (blob "my-file.log" :payload "my-file-contents")) ; #'blobstore.core/blob 2 (create-container blobstore "my-container") ; true 3 (put-blob blobstore "my-container" my-blob) ; "60e46aeaed758964902dd7ae99858f03"

114 jclouds Documentation

115 Logging

116 Clojure in the Cloud

117

118 Thank You Clojure Made Simple Intro to Apache jclouds Everett Toews Developer Advocate @everett_toews


Download ppt "Clojure in the Cloud Everett Toews Developer JavaOne Sept. 29, 12:30 pm."

Similar presentations


Ads by Google