Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Managing fabric8 with Apache ZooKeeper

Managing fabric8 with Apache ZooKeeper

The times when server-side applications were designed as single monolithic executables are over. The demand for scaling out in clustered environments requires applications to spread across multiple hardware nodes. New architectural styles like microservices promote that applications should be implemented as multiple independent services.

Fabric8 is an open-source platform that takes care of automated configuration and deployment of your Java services in a clustered environment. Among other things, fabric8 enables automatically discovery of services through a runtime registry, implements load balancing, and provides leader election and master/slave coordination.

This talk focuses on the coordination features of fabric8 and shows how Apache ZooKeeper is used to maintain highly reliable distributed services.

---

JBoss OneDayTalk 2014, http://www.onedaytalk.org

Fabian Stäber

September 29, 2014
Tweet

More Decks by Fabian Stäber

Other Decks in Programming

Transcript

  1. Seite JBoss OneDayTalk 2014 How to make a REST service

    scalable and fault tolerant without changing code. 14.10.2014 www.consol.de 2
  2. Seite Microservices are not for everyone 14.10.2014 www.consol.de 6 YOU

    MUST BE THIS TALL TO USE MICROSERVICES Monitoring Provisioning Rapid Application Development (Martin Fowler)
  3. Seite Example: Uptime Assume a Monolithic Service with 99.99% availability.

    What if you have… ~30 Microservices (each with 99.99% SLA)? 14.10.2014 www.consol.de 7 http://www.slideshare.net/stonse/microservices-at-netflix
  4. Seite Fabric8 • Open source integration platform • Originally part

    of JBoss Fuse, now independent open source project • Utilizes a lot of Apache projects • Makes it really easy to provision, automate, configure, and manage from a central location with a consistent UI and UX. • It also gives you non-functional requirements like configuration management, service discovery, failover, load balancing, centralized monitoring, automation, and more! 14.10.2014 www.consol.de 11
  5. Seite Fabric8 • Open source integration platform • Originally part

    of JBoss Fuse, now independent open source project • Utilizes a lot of Apache projects • Makes it really easy to provision, automate, configure, and manage from a central location with a consistent UI and UX. • It also gives you non-functional requirements like configuration management, service discovery, failover, load balancing, centralized monitoring, automation, and more! 14.10.2014 www.consol.de 12 Focus of this talk
  6. Seite Fabric8 and ZooKeeper How to make a REST service

    scalable and fault tolerant without changing code. 14.10.2014 www.consol.de 13
  7. Seite Build Fabric8 1.1.0.CR5 from Source 14.10.2014 www.consol.de 14 fabian@ubuntu:~$

    git clone https://github.com/fabric8io/fabric8.git … fabian@ubuntu:~$ cd fabric8 fabian@ubuntu:~/fabric8$ git checkout -b fabric8-1.1.0.CR5 fabric8- 1.1.0.CR5 … fabian@ubuntu:~/fabric8$ mvn clean install -DskipTests … fabian@ubuntu:~/fabric8$ cd ..
  8. Seite Install and Run Fabric8 14.10.2014 www.consol.de 15 fabian@ubuntu:~$ tar

    xfz ~/.m2/repository/io/fabric8/fabric8- karaf/1.1.0.CR5/fabric8-karaf-1.1.0.CR5.tar.gz fabian@ubuntu:~$ cd fabric8-karaf-1.1.0.CR5/ fabian@ubuntu:~/fabric8-karaf-1.1.0.CR5$ ./bin/fabric8 … Fabric8:karaf@root>
  9. Seite List of Fabric8 Maven Archetypes 14.10.2014 www.consol.de 16 fabian@ubuntu:~$

    mvn archetype:generate -Dfilter=io.fabric8: … 31: remote -> io.fabric8.archetypes:karaf-rest-archetype (Creates a new RESTful WebService Example using JAX-RS with JBoss Fuse) …
  10. Seite Create Project from Archetype 14.10.2014 www.consol.de 17 fabian@ubuntu:~$ mvn

    archetype:generate \ -DarchetypeGroupId=io.fabric8.archetypes \ -DarchetypeArtifactId=karaf-rest-archetype \ -DarchetypeVersion=1.1.0.CR5 \ -DgroupId=de.consol.research.fabric8 \ -DartifactId=demo \ -Dversion=1.0-SNAPSHOT \ -Dpackage=de.consol.research.fabric8.demo
  11. Seite Set fabric8.profile in pom.xml 14.10.2014 www.consol.de 18 <project> ...

    <groupId>de.consol.research.fabric8</groupId> <artifactId>demo</artifactId> <version>1.0-SNAPSHOT</version> <packaging>bundle</packaging> ... <properties> ... <!-- fabric8 deploy profile configuration --> <fabric8.profile>demo</fabric8.profile> <fabric8.parentProfiles>feature-cxf</fabric8.parentProfiles> <fabric8.features>cxf-jaxrs swagger</fabric8.features> </properties> ... </project>
  12. Seite Deploy as new Profile in Fabric8 14.10.2014 www.consol.de 19

    fabian@ubuntu:~/demo$ mvn clean install ... fabian@ubuntu:~/demo$ mvn fabric8:deploy ...
  13. Seite Run Containers from Profile 14.10.2014 www.consol.de 20 Fabric8:karaf@root> profile-list

    | grep demo ... Fabric8:karaf@root> container-create-child --profile demo root container1 ... Fabric8:karaf@root> container-create-child --profile demo root container2 ... Fabric8:karaf@root> container-list ...
  14. Seite View Service Endpoints in ZooKeeper 14.10.2014 www.consol.de 25 Fabric8:karaf@root>

    profile-edit --features fabric-zookeeper-commands \ fabric ... Fabric8:karaf@root> zk:list --recursive ...
  15. Seite Start container from HTTP Gateway Profile 14.10.2014 www.consol.de 26

    Fabric8:karaf@root> profile-list | grep gateway ... Fabric8:karaf@root> container-create-child --profile gateway-http \ root demogateway ... Fabric8:karaf@root> container-list ...
  16. Seite Fabric8 Terminology • Container: Running Instance. – Child Container:

    Same host – SSH Container: Other host – Cloud Container: Other host • Fabric: Collection of containers sharing a ZooKeeper registry 14.10.2014 www.consol.de 32 Container Container Container Container Fabric
  17. Seite Fabric8 Terminology • Container: Running Instance. – Child Container:

    Same host – SSH Container: Other host – Cloud Container: Other host • Fabric: Collection of containers sharing a ZooKeeper registry • Fabric Server: Container serving the ZooKeeper registry 14.10.2014 www.consol.de 33 Container Container Container Fabric Server
  18. Seite Fabric8 Terminology • Container: Running Instance. – Child Container:

    Same host – SSH Container: Other host – Cloud Container: Other host • Fabric: Collection of containers sharing a ZooKeeper registry • Fabric Server: Container serving the ZooKeeper registry • Ensemble: Collection of Fabric Servers maintaining a distributed ZooKeeper registry 14.10.2014 www.consol.de 34 Container Fabric Server Server Server
  19. Seite Create an Ensemble 14.10.2014 www.consol.de 35 Fabric8:karaf@root> container-list ...

    Fabric8:karaf@root> ensemble-add container1 container2 ... Fabric8:karaf@root> container-list ...
  20. Seite ZooKeeper • Maintains distributed registry • No single point

    of failure • Consistent as long as majority of nodes in ensemble is up 14.10.2014 www.consol.de 36 ✓ ✓ ✓
  21. Seite ZooKeeper Hierarchal namespace (like a file system). Each znode

    has data and children. Data is read and written in its entirety. 14.10.2014 www.consol.de 37 fabric | +--registry (runtime registry) | | | +--containers | | | +----root | +--configs (configuration registry) | +--versions | | | +--1.0 | | | +--profiles | | | +--default | +--containers
  22. Seite ZooKeeper Flags for create: • Ephemeral: znode deleted when

    creator fails or explicitly deleted • Sequence: append a monotonically increasing counter to znode name 14.10.2014 www.consol.de 38 String create(path, data, acl, flags); void delete(path, expectedVersion); Stat setData(path, data, expectedVersion); (data, Stat) getData(path, watch); Stat exists(path, watch); String[] getChildren(path, watch); void sync();
  23. Seite ZooKeeper 14.10.2014 www.consol.de 39 public final class FabricCxfRegistrationHandler ...

    { protected void registerApiEndpoint(...) { ... ZooKeeperUtils.setData(..., path, json, CreateMode.EPHEMERAL); ... } } public enum ZkPath { ... API_REST_ENDPOINTS ("/fabric/registry/clusters/apis/rest/{name}/{version}/{container}") ... }
  24. Seite Zab – ZooKeeper Atomic Broadcast 14.10.2014 www.consol.de 41 Server

    Server Server Server Leader read, watch read, watch read, watch read, watch client client client client • Super scalable • High throughput • Guaranteed order of events • Upates may be delayed on some servers
  25. Seite Zab – ZooKeeper Atomic Broadcast 14.10.2014 www.consol.de 42 Server

    Server Server Server Leader write client client client client • Writes are serialized by the leader • Leader implements two phase commit protocol (propose, accept, commit) • Commit phase done when majority of servers commit • ZooKeeper is optimized for read performance, not for write performance write write write
  26. Seite Leader Election 14.10.2014 www.consol.de 43 Server Server Server Server

    Leader • Quorum protocol • Leader with latest state wins. • An elected leader has committed all transactions that will ever be committed from previous epochs before it starts broadcasting new transactions; before the sync phase completes, a new leader does not broadcast new state changes.
  27. Seite Summary How to make a REST service scalable and

    fault tolerant without changing code. 14.10.2014 www.consol.de 44
  28. Seite Backup Slide: Fabric8 and Karaf 14.10.2014 www.consol.de 47 OSGi

    Bundle Contains Java classes and resources Karaf Feature Contains OSGi bundles, references to repositories and other features, configuration Fabric8 Profile Fabric8‘s Unit of deployment, contains OSGi bundles, Karaf features, and configuration
  29. Seite Backup Slide: ZooKeeper Recipies What are ZooKeeper Recipies: •

    Higher-level Constructs with ZooKeeper Examples of Recipies: • Name Service • Configuration • Group Membership • Barriers • Queues • Locks • Two-phased Commit • Leader Election Apache Curator Framework implements some of these recipies. References • https://www.usenix.org/conference/usenix-atc-10/zookeeper-wait-free-coordination-internet-scale-systems • http://zookeeper.apache.org/doc/trunk/recipes.html 14.10.2014 www.consol.de 48