Dropwizard A RESTful Love Story Ryan Kennedy (@rckenned) - - PowerPoint PPT Presentation

dropwizard
SMART_READER_LITE
LIVE PREVIEW

Dropwizard A RESTful Love Story Ryan Kennedy (@rckenned) - - PowerPoint PPT Presentation

Dropwizard A RESTful Love Story Ryan Kennedy (@rckenned) Core Services @ Yammer Dropwizard A RESTful Love Story Ryan Kennedy (@rckenned) Core


slide-1
SLIDE 1

Dropwizard ¡

A ¡RESTful ¡Love ¡Story ¡ ¡ Ryan ¡Kennedy ¡(@rckenned) ¡ Core ¡Services ¡@ ¡Yammer ¡

slide-2
SLIDE 2

Dropwizard ¡

A ¡RESTful ¡Love ¡Story ¡ ¡ Ryan ¡Kennedy ¡(@rckenned) ¡ Core ¡Services ¡@ ¡Yammer ¡+ ¡MicrosoE ¡

slide-3
SLIDE 3

What ¡on ¡earth ¡is ¡ Dropwizard? ¡

slide-4
SLIDE 4
slide-5
SLIDE 5

Some ¡bearded ¡jerk ¡in ¡ ¡ a ¡pointy ¡hat… ¡

slide-6
SLIDE 6
  • r… ¡
slide-7
SLIDE 7
slide-8
SLIDE 8

Started ¡at ¡Yammer ¡as ¡three ¡services ¡ with ¡largely ¡copy/pasted ¡code ¡

slide-9
SLIDE 9

By ¡service ¡number ¡three ¡we ¡ idenOfied ¡and ¡disOlled ¡the ¡paQern ¡

slide-10
SLIDE 10

What ¡was ¡the ¡paQern? ¡

slide-11
SLIDE 11

“Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

slide-12
SLIDE 12

“Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

slide-13
SLIDE 13

YAML ¡configuraOon ¡file ¡

slide-14
SLIDE 14

hQp: ¡ ¡ ¡port: ¡8080 ¡ ¡ ¡adminPort: ¡8081 ¡ ¡ # ¡a ¡string ¡ foo: ¡foo ¡value ¡ ¡ # ¡a ¡duraOon ¡ bar: ¡60 ¡seconds ¡ ¡ # ¡a ¡number ¡ baz: ¡10101 ¡

slide-15
SLIDE 15

ConfiguraOon ¡validaOon ¡

slide-16
SLIDE 16

public ¡class ¡MyAppConfiguraOon ¡ ¡ ¡ ¡extends ¡ConfiguraOon ¡{ ¡ ¡ ¡@NotBlank ¡ ¡ ¡private ¡String ¡foo; ¡ ¡ ¡ ¡@NotNull ¡ ¡ ¡private ¡DuraOon ¡bar ¡= ¡DuraOon.minutes(10); ¡ ¡ ¡ ¡@Min(1) ¡ ¡ ¡@Max(1024) ¡ ¡ ¡private ¡long ¡baz ¡= ¡1; ¡ } ¡

slide-17
SLIDE 17

“Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

slide-18
SLIDE 18
slide-19
SLIDE 19

Gauges ¡

Metrics.newGauge(My.class, ¡“jobs", ¡ ¡ ¡new ¡Gauge<Integer>() ¡{ ¡ ¡ ¡ ¡ ¡ ¡@Override ¡ ¡ ¡ ¡ ¡ ¡public ¡Integer ¡value() ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡queue.size(); ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡} ¡ ); ¡

slide-20
SLIDE 20

Counters ¡

Counter ¡pendingJobs ¡= ¡Metrics.newCounter(My.class, ¡“jobs"); ¡ ¡ public ¡void ¡addJob(Job ¡job) ¡{ ¡ ¡ ¡ ¡ ¡pendingJobs.inc(); ¡ ¡ ¡ ¡ ¡queue.offer(job); ¡ } ¡ ¡ public ¡Job ¡takeJob() ¡{ ¡ ¡ ¡ ¡ ¡pendingJobs.dec(); ¡ ¡ ¡ ¡ ¡return ¡queue.take(); ¡ } ¡

slide-21
SLIDE 21

Meters ¡

Meter ¡requests ¡= ¡Metrics.newMeter( ¡ ¡ ¡My.class, ¡"requests", ¡ ¡ ¡ ¡"requests", ¡TimeUnit.SECONDS); ¡ ¡ public ¡void ¡handleRequest(Request ¡request, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Response ¡response) ¡{ ¡ ¡ ¡ ¡ ¡requests.mark(); ¡ ¡ ¡ ¡ ¡// ¡etc ¡ } ¡

slide-22
SLIDE 22

Histograms ¡

Histogram ¡responseSizes ¡= ¡Metrics.newHistogram( ¡ ¡ ¡My.class, ¡"response-­‑sizes"); ¡ ¡ public ¡void ¡handleRequest(Request ¡request, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Response ¡response) ¡{ ¡ ¡ ¡ ¡ ¡// ¡etc ¡ ¡ ¡ ¡ ¡int ¡length ¡= ¡response.getContent().length; ¡ ¡ ¡ ¡ ¡responseSizes.update(length); ¡ } ¡

slide-23
SLIDE 23

Timers ¡

Timer ¡responses ¡= ¡Metrics.newTimer(My.class, ¡"responses", ¡ ¡ ¡ ¡TimeUnit.MILLISECONDS, ¡TimeUnit.SECONDS); ¡ ¡ public ¡String ¡handleRequest(Request ¡request, ¡Response ¡response) ¡{ ¡ ¡ ¡ ¡ ¡final ¡TimerContext ¡context ¡= ¡responses.Ome(); ¡ ¡ ¡ ¡ ¡try ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡etc; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡"OK"; ¡ ¡ ¡ ¡ ¡} ¡finally ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡context.stop(); ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-24
SLIDE 24

Health ¡Checks ¡

public ¡class ¡DatabaseHealthCheck ¡extends ¡HealthCheck ¡{ ¡ ¡ ¡ ¡ ¡@Override ¡ ¡ ¡ ¡ ¡public ¡Result ¡check() ¡throws ¡ExcepOon ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡(database.isConnected()) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡Result.healthy(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡else ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡Result.unhealthy("Cannot ¡connect ¡to ¡db”); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-25
SLIDE 25

“Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

slide-26
SLIDE 26

JMX ¡ReporOng ¡

slide-27
SLIDE 27

HTTP ¡ReporOng ¡

slide-28
SLIDE 28

Metrics ¡

hQp://host:adminPort/metrics ¡

slide-29
SLIDE 29
slide-30
SLIDE 30
slide-31
SLIDE 31

Metrics ¡reporters ¡can ¡be ¡added ¡to ¡ adapt ¡dropwizard ¡metrics ¡to ¡your ¡ collecOon ¡system ¡of ¡choice ¡

slide-32
SLIDE 32

Health ¡Checks ¡

hQp://host:adminPort/healthcheck ¡

slide-33
SLIDE 33
slide-34
SLIDE 34

Thread ¡Dumps ¡

hQp://hostname:adminPort/threads ¡

slide-35
SLIDE 35
slide-36
SLIDE 36

Ping ¡

hQp://hostname:adminPort/ping ¡

slide-37
SLIDE 37
slide-38
SLIDE 38

“Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

slide-39
SLIDE 39

Dropwizard ¡provides ¡its ¡own ¡ applicaOon ¡logging ¡abstracOon ¡

slide-40
SLIDE 40

HTTP ¡request ¡logging ¡is ¡ supported ¡as ¡well ¡

slide-41
SLIDE 41

Dropwizard ¡provides ¡log ¡file ¡ rotaOon ¡and ¡compression ¡

slide-42
SLIDE 42

“Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

slide-43
SLIDE 43

The ¡unbeatable ¡Jackson ¡

slide-44
SLIDE 44

“Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

slide-45
SLIDE 45

Dropwizard ¡embeds ¡JeQy ¡for ¡all ¡ your ¡HTTP ¡serving ¡needs ¡

slide-46
SLIDE 46

JAX-­‑RS ¡(JSR-­‑311) ¡for ¡all ¡your ¡ RESTful ¡needs ¡

slide-47
SLIDE 47

@Path(“/users/{id}”) ¡ public ¡class ¡UserResource ¡{ ¡ ¡ ¡ ¡ ¡@GET ¡ ¡ ¡ ¡ ¡public ¡User ¡get(@PathParam(“id”) ¡long ¡id) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡db.findUserById(id); ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡ ¡@PUT ¡ ¡ ¡ ¡ ¡public ¡User ¡update(@PathParam(“id”) ¡long ¡id, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡User ¡user) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡db.updateUser(id, ¡user); ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-48
SLIDE 48

How ¡Yammer ¡uses ¡Dropwizard ¡

slide-49
SLIDE 49

Lots ¡of ¡small ¡services…16 ¡and ¡ counOng ¡

slide-50
SLIDE 50

Maven ¡is ¡our ¡friend ¡

slide-51
SLIDE 51

SOck ¡the ¡code ¡in ¡GitHub ¡

slide-52
SLIDE 52

Shade ¡your ¡JARs ¡

slide-53
SLIDE 53

Get ¡yourself ¡some ¡conOnuous ¡ integraOon ¡

slide-54
SLIDE 54

Write ¡yourself ¡a ¡startup ¡script ¡

slide-55
SLIDE 55

Have ¡a ¡good ¡deploy ¡story ¡

slide-56
SLIDE 56

Over ¡Ome, ¡Dropwizard ¡has ¡ grown ¡a ¡few ¡appendages ¡

slide-57
SLIDE 57

Dropwizard ¡Client ¡

HQpClient ¡or ¡JerseyClient ¡flavors ¡

slide-58
SLIDE 58

Dropwizard ¡DB ¡

JDBI ¡as ¡a ¡service ¡

slide-59
SLIDE 59

Dropwizard ¡AuthenOcaOon ¡

Abstracted ¡authenOcaOon…providers ¡ for ¡OAuth ¡2 ¡and ¡Basic ¡Auth ¡

slide-60
SLIDE 60

An ¡example… ¡

@Path("/my") ¡ public ¡class ¡MyResource ¡{ ¡ ¡ ¡ ¡ ¡@GET ¡ ¡ ¡ ¡ ¡public ¡MyResponse ¡get( ¡ ¡ ¡@Auth(required ¡= ¡false) ¡Token ¡token) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡(token ¡!= ¡null) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡new ¡MyResponse(getUser(token)); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡else ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡new ¡MyResponse(getGuestUser()); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡} ¡ } ¡

slide-61
SLIDE 61

Dropwizard ¡Views ¡

Full ¡blown ¡applicaOon ¡UIs ¡or ¡just ¡a ¡ nice ¡admin ¡interface ¡

slide-62
SLIDE 62

Dropwizard ¡Scala ¡

The ¡original ¡Dropwizard…for ¡those ¡ who ¡don’t ¡know ¡any ¡beQer ¡

slide-63
SLIDE 63

Dropwizard ¡TesOng ¡

Test ¡JSON ¡representaOons ¡and ¡ resources ¡

slide-64
SLIDE 64

I ¡blew ¡through ¡that ¡preQy ¡ quickly, ¡fortunately ¡you ¡have… ¡

hQp://dropwizard.codahale.com/ ¡

slide-65
SLIDE 65

And ¡the ¡sample ¡applicaOon ¡

hQps://github.com/codahale/ dropwizard ¡

slide-66
SLIDE 66

And ¡(hopefully) ¡Ome ¡for ¡ quesOons! ¡

Also…WE’RE ¡HIRING! ¡