Your SlideShare is downloading. ×
0
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
BlueEyes russian
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

BlueEyes russian

745

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
745
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  1. Michael Lagutko  @mlagutko  BlueEyes 
  2. Цели •  Создание RESTful сервисов •  Высокая производительность (асинхронная  обработка запросов) •  Масштабируемость (отсутствие поддержки  состояния) •  Автомотическое тестирование  (Независимость от сервера) 
  3. Service •  BlueEyesServiceBuilder •  Комбинаторы оброботчиков запросов •  Уникальное имя и версия  •  Жизненный цикл •  Контекст 
  4. Жизненный цикл сервиса •  Старт •  Обработка запросов •  Остановка 
  5. Комбинаторы оброботчиков  запросов •  path(*padern*) { ... } •  contentType(*mimeType*) { ... } •  get { ... } •  put { ... } •  post { ... } •  delete { ... } •  … path("/emails"){   get { request =>          val response = H"pResponse(content = Some(emailIds))           Future.sync{response }       }     } 
  6. Комбинаторы путей •  Строковый: "/foo/bar” •  Символьный: "/foo/fooId” •  Но основе регулярных выражений:"/foo/bar/baz.(? <extension>w{3,4})” path("/emails"){       path(emailId) {         path("(?<bar>[a‐z]+)"){           get { request =>             val fooId = request.parameters(fooId)             val extension = request.parameters(extension)             ...           }         }       }     } 
  7. Комбинации оброботчиков запросов produces(applicavon/json) {       path("/users/") {         get { request =>           // get list of all users           ...         } ~         path(userId) {           parameter(userId) { userId =>             get { request =>               // get user               ...             } ~             put { request =>               // update user               ...             }           }         }       }     } 
  8. Контекст •  Конфигурация •  Имя сервиса •  Версия сервиса 
  9. Простой сервис trait EmailServices extends BlueEyesServiceBuilder {  val emailService = service("email", "1.32") { context =>   startup {     loadContactList(context.config("contactFile"))   } ‐>   request { contactList =>     path("/emails/") {       produce(applicavon/json) {         get { request =>           Future.async{               …    H"pResponse(content = Some(JArray(emailIds)))   }         }       }     } ~     path(emailId) {       produce(applicavon/json) {         get { request =>           val emailId = request.parameters(emailId)           ...           Future.sync(H"pResponse(content = Some(emailObj)))         }       }     }   } ‐>     shutdown { contactList =>       contactList.finalize     }   } } 
  10. HdpRequest •  method: HdpMethod •  uri: URI •  parameters: Map[Symbol, String]  •  headers: HdpHeaders  •  content: Op]on[ByteChunk] •  …  
  11. HdpResponse •  status: HdpStatus •  headers: HdpHeaders •  content: Op]on[ByteChunk] •  … 
  12. ByteChunk trait Chunk[T]{   def data: T   def next: Opvon[Future[Chunk[T]]] } type ByteChunk = Chunk[Array[Byte]] 
  13. Получение всего контента запроса  path("/emails/") {       aggregate(None){        get { request: H"pRequest[ByteChunk] =>             Future.async{                       …               HdpResponse(content = Some(JArray(emailIds)))             }         }       }     } 
  14. Бизнесс данные •  Explicitly:    post { request: H"pRequest[ByteChunk] =>         val bijecvon = BijecvonsChunkJson.ChunkToJValue         val emailId = request.content.map(bijec]on(_))         ...         Future.sync(HdpResponse(content = Some(bijec]on.Inverse(emailObj))))    } •  Implicitly: trait EmailServices extends BlueEyesServiceBuilder with Bijec]onsChunkJson …    contentType(MimeTypes.applica]on/MimeTypes.json) {      post { request: H"pRequest[JValue] =>         val emailId = request.content         ...         Future.sync(HdpResponse(content = Some(emailObj)))      }   } 
  15. Расширение сирвисов •  Фабрики сервис дескрипторов •  Logging •  Health monitors •  Request logging 
  16. Logging trait LogDemo extends BlueEyesServiceBuilder {        val logDemoService = service("logdemo", "1.32") {         logging { log =>           context =>             startup {             request { state =>               path("/foo") {                 contentType(applicavon/json) {                   get { request =>                     log.info("request at /foo")                     ...                   }                 }               }             }         }      } 
  17. Request Logging (W3C Extended Log  format) trait RequestLogDemo extends BlueEyesServiceBuilder {        val requestLogDemoService = service("requestlogdemo", "1.32") {         requestLogging{           context =>             startup {             request { state =>               path("/foo") {                 contentType(applicavon/json) {                   get { request =>                     ...                   }                 }               }             }         }      } “requestLog” секция: "enabled           = true | false" ( default = true )    "fields            = see W3C Extended Log format"    "roll              = "never" | "hourly" | "daily" | "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" |  "saturday" " ( default = "never")    "file              = path to log file"    "writeDelaySeconds = delay between flush to file" ( default = 1 ) 
  18. Health Monitor •  /blueeyes/services/[serviceName]/ v[serviceMajorVersion]/health trait HealthMonitorDemo extends BlueEyesServiceBuilder {         val healthMonitorService = service("healthmon", "1.32") {          healthMonitor { monitor =>            context =>              request { state =>                path("/foo") {                  contentType(applicavon/json) {                    get { request =>                      monitor.vme(".requests.foo.vming") {                        ...                      }                    }                  }                }              }          }       } 
  19. HdpClient •  HdpClient •  HdpClientXLightWebEngines val responseFuture = client.get("hdp://myservice.com/foo")     responseFuture map {response => response.content.get} def myService: HdpClient[JValue] = client.path("hdp:// myservice.com/").contentType[JValue](applicavon/json)     val responseFuture = myService.get("api/v1")     responseFuture map {response => response.content.get} 
  20. Тестирваоние •  Полная потдержка Scala Specs •  Не требует старта сервера 
  21. Пример простого теста class EmailServicesSpec extends BlueEyesServiceSpecifica]on with  EmailServices {       "EmailService" should {         "get emails" in {           val f = service.contentType[JValue](applicavon/json).get("/emails")           f.value must eventually(beSomething)           val response = f.value.get           response.status mustEqual(HdpStatus(OK))         }       }     } 
  22. Запуск сервиса object AppServer extends BlueEyesServer with EmailServices  with OrderProcessingServices with LoginServices with  CatalogServices val startFuture = AppServer .start val stopFuture = AppServer .stop java ‐jar appserver.jar ‐‐configFile /etc/default/appserver.conf 
  23. Данные •  Библиотека JSON 
  24. MongoDB •  BlueEyes MongoDB QL •  Потдержка Mock MongoDB   

×