8. OpenGenesis
Deployment orchestration tool
● open source - open-genesis.org
● 2 years of development
● > 50 KLOC of scala code
● successfully deployed to production in one
large american financial institution
● Buzzwords: continuous deployment, cloud,
chef, devops, aws, openstack
9. Enterprise characteristics
● Integration with legacy apps and data (lots of
SOAP and xml)
● sophisticated security policies
● IT department separated from development
team
● J2EE Containers everywhere
● Risk averse
11. j2ee stack. Scala edition
Web layer Spring MVC + scala magic
Service layer Spring + scala implicits
Data access layer
JPA Squeryl
DB
12. j2ee stack. Scala edition
WAR
Spring MVC
Web layer
Spring
Service layer
Squeryl
Data access layer
DB
13. j2ee stack. Scala edition + scala
goodness
WAR
Spring MVC
Web layer
Akka
Spring
Workflow distributed
Service layer engine
Squeryl
Data access layer
DB
16. Spring with scala
● DI fits almost nicely with scala
class GenesisRestController {
@Autowired var genesisService: GenesisService = _
}
class GenesisRestController {
@BeanProperty var genesisService: GenesisService = _
}
class GenesisRestController (genesisService: GenesisService) {}
17. Spring with scala
● DI fits almost nicely with scala
○ "Everything is a trait" approach can't be done
18. Spring with scala
● DI fits almost nicely with scala
○ "Everything is a trait" approach can't be done
○ Be aware of type inference in @Configuration bean
trait Service
class ServiceImpl extends Service
@Configuration
class ServiceContext {
@Bean def service = new ServiceImpl
}
19. Spring with scala
● DI fits almost nicely with scala
○ "Everything is a trait" approach can't be done
○ Be aware of type inference in @Configuration bean
trait Service
class ServiceImpl extends Service
@Configuration
class ServiceContext {
@Bean def service: Service = new ServiceImpl
}
20. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
21. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
springLdapTemplate.authenticate("user", "*", "password", new
AuthenticationErrorCallback {
def execute(e: Exception) {log.error(e)}
})
22. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
springLdapTemplate.authenticate("user", "*", "password", new
AuthenticationErrorCallback {
def execute(e: Exception) {log.error(e)}
})
23. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
springLdapTemplate.authenticate("user", "*", "password", new
AuthenticationErrorCallback {
def execute(e: Exception) {log.error(e)}
})
springLdapTemplate.authenticate("user", "*", "password", log.error(_))
24. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
springLdapTemplate.authenticate("user", "*", "password", log.error(_))
implicit def authErrorCallbackWrapper(func:(Exception) => Any) = {
new AuthenticationErrorCallback {
def execute(exception: Exception): Unit = func(exception)
}
}
25. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
26. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
○ Be aware of naming in debug info
def findUsers(projectId: Int) {
dao.findUsers(projectId)
}
def findUsers2(projectId: Int) {
dao.allUsers().filter(_.projectId == projectId)
}
27. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
○ Be aware of naming in debug info
def findUsers(projectId: Int) { // debugIfo: name "projectId"
dao.findUsers(projectId)
}
def findUsers2(projectId: Int) { // debugInfo: name "projectId$"
dao.allUsers().filter(_.projectId == projectId)
}
28. Spring with scala
● DI fits almost nicely with scala
● Rich spring templates libraries.
● AOP for free (almost)
● Spring security just works
31. Squeryl
● Lightweight ORM written in scala
class Workflow(override val id: Int) extends KeyedEntity[Int]
32. Squeryl
● Lightweight ORM written in scala
class Workflow(override val id: Int) extends KeyedEntity[Int]
object GS extends Schema {
val workflows = table[Workflow]
}
33. Squeryl
● Lightweight ORM written in scala
class Workflow(override val id: Int) extends KeyedEntity[Int]
object GS extends Schema {
val workflows = table[Workflow]
}
def find(workflowId: Int) = from(GS.workflows)(w =>
where(w.id === workflowId)
select (w)
orderBy(w.id desc)
)
34. Squeryl
● Lightweight ORM written in scala
○ First class support for scala collections, options, etc
35. Squeryl
● Lightweight ORM written in scala
○ First class support for scala collections, options, etc
○ Integrates with spring transaction management
(not out of the box)
36. Squeryl
● Lightweight ORM written in scala
○ First class support for scala collections, options, etc
○ Integrates with spring transaction management
(not out of the box)
@Transactional(propagation = REQUIRES_NEW)
def find(workflowId: Int) = from(GS.workflows)(w =>
where(w.id === workflowId)
select (w)
orderBy(w.id desc)
)
37. Squeryl
● Lightweight ORM written in scala
○ Likes heap in the same proportion as
Hibernate does
hibernate squeryl
38. Squeryl
● Lightweight ORM written in scala
○ Likes heap in the same proportion as
Hibernate does
○ Lot's of "black magic" in source code
39. Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
○ Type safe queries - compile time syntax check
40. Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
○ Lot's of "black magic" in source code
41. Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
○ Lot's of "black magic" in source code
○ Fallback on native sql is not easy
42. Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
○ Lot's of "black magic" in source code
○ Fallback on native sql is not easy
○ Lots of implicits drives IDE crazy and
increases compilation time
43. Squeryl
● Lightweight ORM written in scala
● Internal scala DSL for writing queries
○ Lot's of "black magic" in source code
○ Fallback on native sql is not easy
○ Lots of implicits drives IDE crazy and
increase compilation time
○ The approach is somewhat flawed (opinion)
55. Challenges
● Hiring is hard
● Settling team standards and code
convention
○ Tools are not there yet
56. Challenges
● Hiring is hard
● Settling team standards and code
convention
○ Tools are not there yet
○ Between "OCaml" and "Java" fires
57. Challenges
● Hiring is hard
● Settling team standards and code
convention
○ Tools are not there yet
○ Between "OCaml" and "Java" fires
○ "Effective scala" by Twitter and "Scala style guide"
might help (a bit)
58. The greatest code-review mystery of
all times
How to deal with scala.Option
if (option.isDefined) { option match {
case Some(x) => ..
.. case None => ..
?
} }
option.foreach { .. }
59. The greatest code-review mystery of
all times
How to deal with scala.Option
if (option.isDefined) { option match {
case Some(x) => ..
.. case None => ..
?
} }
option.foreach { .. }