High Performance Cloud Native APIs
Using Apache Geode
Anna Jung Paul Vermeulen
1
@antheajung pvermeulen@pivotal.io
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
What is Cloud Native….
2
● Cloud-native is about how applications are created and deployed, not where
● 12 factor manifesto outlines rules/guidelines for building a cloud native apps
● Must be a micro-service
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Health Care Service Corporation
3
#6on Diversity MBA’s
50 Out Front for Diversity
Leadership Best Places to Work for Women
& Diverse Managers
Operating Blue Cross
and Blue Shield plans in
FIVE states: IL, MT,
NM, OK, TX
OUR PURPOSE
To do everything in our power to stand
with our members in sickness and in
health®
1936
year founded
+$1
billion
in IT
spend
Over
21,000
employees
15 million
members
2,100
IT employees
208.3million
claims processed
annually
LARGESTcustomer-
owned
health insurer in the U.S. and
4th largest overall
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Business Problem
4
● Inquiry Service and Not Information Service
● Heavy weight, Hard to use SOAP services
● Constraints with Performance and Scalability
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Architecture
5
Consumer
Consumer
Pivotal Cloud Foundry
Data Aware Functions
RESTful API
Pivotal Cloud Foundry
Micro-service is a collection of small services
- Implements business capabilities
- Runs in its own process space
- Communicates via HTTP API
- Deployed, upgrade, scaled and restarted independent of other services
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Why Pivotal Cloud Foundry?
6
Cloud Foundry’s architectural structure includes components and
a high-enough level of interoperability to permit
● Fast application development and deployment
● Continuous integration
● DevOps-friendly workflows
● Integration with various cloud providers
● Integration with Spring frameworks for developer productivity
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Why Apache Geode?
7
Apache Geode architecture provides low latency performance
and scalability at all levels
● Scalability of Geode cache
● Continuous availability of Geode
● High performance reads
● Caching patterns
● Supports cloning of micro-services for performance and scalability
● Provided isolation layer for making backing store changes
● Integration with Spring framework for developer productivity
Demo Overview
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Demo Overview
9
Client
● Act as independent client or Spring Boot
● REST API Controller
Server
● Client Function Provider
● Abstract Function Provider
● Function Test Setup
● Function Test
● Server-side Service Function
● Server-side Abstract Service Function
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
REST API Spring Boot Application
10
@SpringBootApplication
public class CustomerOrderClientApplication {
public static void main(String[] args) {
SpringApplication.run(CustomerOrderClientApplication.class, args);
}
}
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
REST API Controller
11
@RestController
public class CustomerOrderController {
@Autowired
private CustomerListProvider customerListProvider;
. . .
@GetMapping(value = "/customers")
public List<CustomerIO> customers() throws IOException {
return customerListProvider.execute();
}
}
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Client Function Provider
12
public class CustomerListProvider
extends AbstractProvider<String, CustomerIO> {
private static final String FUNCTION_NAME = "CustomerListFunction";
private static final String REGION_NAME = "customer";
public CustomerListProvider(GemFireCache cache) { super(cache); }
public Set<?> getFilters(String request) { return emptySet(); }
public String getRegionName() { return REGION_NAME; }
public String getFunctionId() { return FUNCTION_NAME; }
}
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Abstract Function Provider
13
public abstract class AbstractProvider<V, R> implements ServiceProvider<V, R> {
private GemFireCache cache;
private Provider provider;
AbstractProvider(GemFireCache cache, Provider provider) { . . . }
public Collection<R> execute() { . . . }
private Provider getProvider() { return this.provider; }
static class Provider {
Provider() { }
Execution getExecution(Region<?, ?> region) {
return FunctionService.onRegion(region);
}
}
}
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Function Test Setup
14
@RunWith(SpringRunner.class)
public class CustomerListFunctionTest {
@MockBean private GemFireCache cache;
@MockBean(name = "customer")
private Region<CustomerKey, Customer> customerRegion;
@Mock private RegionFunctionContext regionFunctionContext;
@Mock private QueryService queryService;
@Mock private Query query;
@Mock private SelectResults<Entry<CustomerKey, Customer>> results;
@Autowired private CustomerListFunction customerListFunction;
@Before public void setUp() throws Exception {
when(cache.getQueryService()).thenReturn(queryService);
when(queryService.newQuery(any())).thenReturn(query);
when(query.execute(regionFunctionContext)).thenReturn(results);
}
. . .
}
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Function Test
15
@Test
public void customerListFunction_returnsAllCustomers() {
ResultSender resultSender = mock(ResultSender.class);
when(regionFunctionContext.getResultSender()).thenReturn(resultSender);
when(results.asList()).thenReturn(getAllCustomers());
customerListFunction.processRequest(regionFunctionContext);
ArgumentCaptor<CustomerIO> captor =
ArgumentCaptor.forClass(CustomerIO.class);
verify(resultSender).lastResult(captor.capture());
CustomerIO customerIO = captor.getValue();
assertThat(customerIO.getId()).isEqualTo("customer1");
assertThat(customerIO.getName()).isEqualTo("Demo Person");
}
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Server-Side Service Function
16
public class CustomerListFunction extends AbstractServiceFunction {
@Autowired private GemFireCache cache;
@Resource(name = "customer")
private Region<CustomerKey, Customer> customerRegion;
. . .
@Override
protected void processRequest(RegionFunctionContext regionFunctionContext) {
String queryString = "SELECT * FROM /customer.entries entry";
Query query = cache.getQueryService().newQuery(queryString);
SelectResults<Entry<CustomerKey, Customer>> results =
query.execute(regionFunctionContext);
//iterate over query result set
regionFunctionContext.getResultSender().sendResult(customerIO);
. . .
regionFunctionContext.getResultSender().lastResult(customerIO);
}
}
Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-
NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/
Server-Side Abstract Service Function
17
public abstract class AbstractServiceFunction implements Function, Declarable {
protected abstract void validateRequest(RegionFunctionContext var1);
protected abstract void processRequest(RegionFunctionContext var1);
public void execute(FunctionContext ctx) { . . . }
public String getId() { . . . }
public boolean hasResult() { . . . }
public boolean isHA() { . . . }
public boolean optimizeForWrite() { . . . }
}
Demo
Learn More. Stay Connected.
12/05 5:00pm Apache Geode Test Automation and Continuous Integration &
Deployment (CI-CD)
12/07 9:00am Main Stage Keynote by Mark Ardito
12/07 11:50am RDBMS and Apache Geode Data Movement
19
#springone@s1
p
Q & A

High Performance Cloud Native APIs Using Apache Geode

  • 1.
    High Performance CloudNative APIs Using Apache Geode Anna Jung Paul Vermeulen 1 @antheajung pvermeulen@pivotal.io
  • 2.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What is Cloud Native…. 2 ● Cloud-native is about how applications are created and deployed, not where ● 12 factor manifesto outlines rules/guidelines for building a cloud native apps ● Must be a micro-service
  • 3.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Health Care Service Corporation 3 #6on Diversity MBA’s 50 Out Front for Diversity Leadership Best Places to Work for Women & Diverse Managers Operating Blue Cross and Blue Shield plans in FIVE states: IL, MT, NM, OK, TX OUR PURPOSE To do everything in our power to stand with our members in sickness and in health® 1936 year founded +$1 billion in IT spend Over 21,000 employees 15 million members 2,100 IT employees 208.3million claims processed annually LARGESTcustomer- owned health insurer in the U.S. and 4th largest overall
  • 4.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Business Problem 4 ● Inquiry Service and Not Information Service ● Heavy weight, Hard to use SOAP services ● Constraints with Performance and Scalability
  • 5.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Architecture 5 Consumer Consumer Pivotal Cloud Foundry Data Aware Functions RESTful API Pivotal Cloud Foundry Micro-service is a collection of small services - Implements business capabilities - Runs in its own process space - Communicates via HTTP API - Deployed, upgrade, scaled and restarted independent of other services
  • 6.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why Pivotal Cloud Foundry? 6 Cloud Foundry’s architectural structure includes components and a high-enough level of interoperability to permit ● Fast application development and deployment ● Continuous integration ● DevOps-friendly workflows ● Integration with various cloud providers ● Integration with Spring frameworks for developer productivity
  • 7.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why Apache Geode? 7 Apache Geode architecture provides low latency performance and scalability at all levels ● Scalability of Geode cache ● Continuous availability of Geode ● High performance reads ● Caching patterns ● Supports cloning of micro-services for performance and scalability ● Provided isolation layer for making backing store changes ● Integration with Spring framework for developer productivity
  • 8.
  • 9.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Demo Overview 9 Client ● Act as independent client or Spring Boot ● REST API Controller Server ● Client Function Provider ● Abstract Function Provider ● Function Test Setup ● Function Test ● Server-side Service Function ● Server-side Abstract Service Function
  • 10.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ REST API Spring Boot Application 10 @SpringBootApplication public class CustomerOrderClientApplication { public static void main(String[] args) { SpringApplication.run(CustomerOrderClientApplication.class, args); } }
  • 11.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ REST API Controller 11 @RestController public class CustomerOrderController { @Autowired private CustomerListProvider customerListProvider; . . . @GetMapping(value = "/customers") public List<CustomerIO> customers() throws IOException { return customerListProvider.execute(); } }
  • 12.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Client Function Provider 12 public class CustomerListProvider extends AbstractProvider<String, CustomerIO> { private static final String FUNCTION_NAME = "CustomerListFunction"; private static final String REGION_NAME = "customer"; public CustomerListProvider(GemFireCache cache) { super(cache); } public Set<?> getFilters(String request) { return emptySet(); } public String getRegionName() { return REGION_NAME; } public String getFunctionId() { return FUNCTION_NAME; } }
  • 13.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Abstract Function Provider 13 public abstract class AbstractProvider<V, R> implements ServiceProvider<V, R> { private GemFireCache cache; private Provider provider; AbstractProvider(GemFireCache cache, Provider provider) { . . . } public Collection<R> execute() { . . . } private Provider getProvider() { return this.provider; } static class Provider { Provider() { } Execution getExecution(Region<?, ?> region) { return FunctionService.onRegion(region); } } }
  • 14.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Function Test Setup 14 @RunWith(SpringRunner.class) public class CustomerListFunctionTest { @MockBean private GemFireCache cache; @MockBean(name = "customer") private Region<CustomerKey, Customer> customerRegion; @Mock private RegionFunctionContext regionFunctionContext; @Mock private QueryService queryService; @Mock private Query query; @Mock private SelectResults<Entry<CustomerKey, Customer>> results; @Autowired private CustomerListFunction customerListFunction; @Before public void setUp() throws Exception { when(cache.getQueryService()).thenReturn(queryService); when(queryService.newQuery(any())).thenReturn(query); when(query.execute(regionFunctionContext)).thenReturn(results); } . . . }
  • 15.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Function Test 15 @Test public void customerListFunction_returnsAllCustomers() { ResultSender resultSender = mock(ResultSender.class); when(regionFunctionContext.getResultSender()).thenReturn(resultSender); when(results.asList()).thenReturn(getAllCustomers()); customerListFunction.processRequest(regionFunctionContext); ArgumentCaptor<CustomerIO> captor = ArgumentCaptor.forClass(CustomerIO.class); verify(resultSender).lastResult(captor.capture()); CustomerIO customerIO = captor.getValue(); assertThat(customerIO.getId()).isEqualTo("customer1"); assertThat(customerIO.getName()).isEqualTo("Demo Person"); }
  • 16.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Server-Side Service Function 16 public class CustomerListFunction extends AbstractServiceFunction { @Autowired private GemFireCache cache; @Resource(name = "customer") private Region<CustomerKey, Customer> customerRegion; . . . @Override protected void processRequest(RegionFunctionContext regionFunctionContext) { String queryString = "SELECT * FROM /customer.entries entry"; Query query = cache.getQueryService().newQuery(queryString); SelectResults<Entry<CustomerKey, Customer>> results = query.execute(regionFunctionContext); //iterate over query result set regionFunctionContext.getResultSender().sendResult(customerIO); . . . regionFunctionContext.getResultSender().lastResult(customerIO); } }
  • 17.
    Unless otherwise indicated,these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution- NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Server-Side Abstract Service Function 17 public abstract class AbstractServiceFunction implements Function, Declarable { protected abstract void validateRequest(RegionFunctionContext var1); protected abstract void processRequest(RegionFunctionContext var1); public void execute(FunctionContext ctx) { . . . } public String getId() { . . . } public boolean hasResult() { . . . } public boolean isHA() { . . . } public boolean optimizeForWrite() { . . . } }
  • 18.
  • 19.
    Learn More. StayConnected. 12/05 5:00pm Apache Geode Test Automation and Continuous Integration & Deployment (CI-CD) 12/07 9:00am Main Stage Keynote by Mark Ardito 12/07 11:50am RDBMS and Apache Geode Data Movement 19 #springone@s1 p
  • 20.