Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

SOA for PL/SQL Developer (OPP 2010)

3,938 views

Published on

PL/SQL developers (as well as DBAs and many others involved) typically are uncertain what SOA means to them. They feel overwhelmed by a avalanche of acronyms. Yet they see it coming and instead of being surprised or bypassed, this session allows them to start participating and benefiting themselves. This session introduces SOA and the Oracle SOA Suite 11g to the realm of the PL/SQL developer - from which it sometimes seems so far removed. What are the key SOA concepts and objectives - what's the buzz about? What is at the heart of SOA Suite 11g: Composite Applications, BPEL PM and the Mediator.

The presentation demonstrates how SOA Services can be leveraged from the database – from Triggers and PL/SQL applications and how the database can publish events to the Event Delivery Network. It demonstrates how the SOA infrastructure can access the database, primarily using the Database Adapter – and how database developers can be instrumental in efficiently doing so. It concludes with some hints for applying SOA concepts for 'normal' database development.

SOA for PL/SQL Developer (OPP 2010)

  1. 1. SOA for PL/SQL Developers OPP 2010 28th October, 2010 Lucas Jellema AMIS, The Netherlands WebLogic Server 11g SOA Suite 11g
  2. 2. Blogger Presenter Author
  3. 3. SOA is not… • XML • WebService • SOAP • Middle Tier or Application Server • Java • High level – abstract – architecture • Unrelated to the database and PL/SQL • Complex only/always
  4. 4. SOA = BAD
  5. 5. SOA = Business Agility through Decoupling
  6. 6. Decoupling ≈ Managing Dependencies minimize impact of change while maximizing reusability
  7. 7. Types of decoupling • Functional – Interface - Encapsulation of implementation • Design by Contract, Implement by Design • Design Time – Separate teams working in parallel based on mutually agreed interface definitions • Technical – No proprietary technology, protocol, message format – Standards based (XML, HTTP, RSS, WSDL…) • Temporal – Asynchronous communication (separate response)
  8. 8. Objectives (1/2) • Business Agility – (Faster) responses to (new and changing) market demands and user requirements • IT Flexibility – Optimize locally without impact ‘globally’ – Prepare for future developments • Lower costs – Through reuse, better integration, decoupling, automation of manual tasks & human coordination
  9. 9. Objectives (2/2) • (longer term) Higher Quality and Faster (traceable) Process execution – Automated data exchange cross boundaries – Workflow and task orientation • integrated, cross department, in a controlled way based on sound understanding of the business processes – Business Event driven interaction • Manage risks and fear
  10. 10. Common Characteristics in SOA • Cross Boundaries – Cross Technology - .Net, Uniface, Java, Tibco – Cross Channel – Back Office, Web, PDA, API – Cross User Group – Internal, Agents, Self Service – Cross Domain – Multiple departments & systems – Cross Enterprise – Interact with external partners • Data synchronization or consolidation • Management whim Vision • From Database angle: providing services
  11. 11. What is a service? • Standards based callable, reusable functionality according to an interaction contract • In terms of functionality (WSDL – compare Package Specification) – What are the input parameters – What are the output parameters (if any) – What are the exceptions – How (when, where) is the response delivered – Implementation is hidden!
  12. 12. What is a service (2)? • In terms of operational QoS (Quality of Service) define in a Service Level Agreement (SLA) – Availability – Stability & Release schedule – Response Time – Peak load capacity – Price – Reliability, Confidentiality – Address, protocol
  13. 13. Services in various shapes • Library (dll, jar) • Java Class (public methods) or an EJB (interface) • URL • RSS feed • Portlet (UI Service) • SOAP WebService • Database View or Package Specification • …. If it exposes a clear, standardized interface
  14. 14. Example of a service call? • Browser sends http request to a URL – Text based message with headers and body
  15. 15. What is a service call? • Server returns a response – Another text based message with headers and body
  16. 16. SOA Concepts in the database
  17. 17. Key SOA concepts and lessons • Functional interface, hiding implementation details – for example Package specification
  18. 18. Design by Contract Encapsulation Decoupling Assertion
  19. 19. specification body Encapsulation
  20. 20. specification body specification body Decoupling
  21. 21. Contract Specification Assertions
  22. 22. function func ( p_name in varchar2 ,p_sal in number ,p_hiredate in date ) return number
  23. 23. function func ( p_name in varchar2 ,p_sal in number ,p_hiredate in date ) return number Expectation regarding Valid Input Agreed Contract Indication of possible Exceptions Description of output value
  24. 24. -- Description of this function -- -- %param p_name Name of an Employee -- {*} Requirement Name must be provided -- -- %param p_sal Salary of the Employee -- {*} Requirement Salary must be greater than zero -- -- %param p_hiredate Hiredate -- {*} Requirement Hiredate must be in the Future -- -- %raises DBC.AssertFail -- When a Parameter does not match the requirement -- -- %raises EmployeeNotFound -- When a an employee with p_name can not be found -- -- %return -- The value returned is an integer: 0 < return <= 4
  25. 25. Key SOA concepts and lessons • Functional interface, hiding implementation details – Simple View API (possibly with IOT) – with complex joins, analytical functions, advanced SQL and PL/SQL integration – Package specification
  26. 26. API Services for consumers • Views – for encapsulation of (legacy) model, multi-table join, collection integration, SQL hiding (but still SQL) • PL/SQL – for encapsulation, cursor based data retrieval, DML hiding, table decoupling (no SQL) View
  27. 27. Providing a ‘business object’ API • DML API: can be a View – aided by Instead Of trigger • Insert of one new row in USERS_VW can actually be four new records – USER, PERSON, EMAIL_TYPE EMAIL_ADDRESS USERS PERSONS EMAIL_ ADDRESSES EMAIL_TYPE USERS * * * *
  28. 28. FIY Data Service API: returning cursors • Fetch it Yourself! • Cursor opened to be fetched from – Data is gathered and pre-processed before being returned – SQL is wrapped • And can be constructed at run-time – Access privileges are taken care of – Cursors can be handled elegantly in most client languages and technologies • For example Java: JDBC ResultSet Prompt Prompt Prompt Prompt Prompt Prompt Prompt Prompt Prompt A ct ie A ct ie HRM_API CURSOR
  29. 29. Demo • Create a database “service” – for retrieving a department, its employees and the manager for each employee – that is promotes decoupling and encapsulates implementation – that can be extended to also support data manipulation • Leveraging Types and Collections to support nested structures such as master-details DEPT EMP DEPARTMENTS HRM Service API SQL PL/ SQL •Cursor •Collection •XML
  30. 30. Key SOA concepts and lessons • Functional interface, hiding implementation details – Package specification – View API • Reusable, standardized services as flexible building blocks • Aggregate and Combine into more valuable reusables • Governance: security, management of services, SLAs – Allow for configuration without development or deployment effort • Decoupling in every aspect!
  31. 31. Coupling & Decoupling in Oracle RDBMS Decoupling • Package Specification • Views (+ Instead of Trigger) • Triggers in general • DBMS_JOB • Advanced Queuing • Publish (intranet) XML & WebService • %TYPE instead of hardcoded data type • Centrally managed “parameter (injection) service” – instead of local constants – instead of hard coded values • Use generic (SOA) services Coupling • Database Link • SYSDATE and USER • Application performing SQL against tables – SQL all over the place • Access database from DMZ or even outside firewall – Publish WebService or Web Application on Internet • Too frequent use of dbms_output.put_line • Copy and paste of code • Poorly documented code • Use of exotic features summary
  32. 32. Decoupling Applications & Data Data Application (User Interface) Application (User Interface) Data
  33. 33. Decoupling Applications & Data Application (User Interface) Data Application (User Interface)
  34. 34. Decoupling Applications & Data (User Interface) Application Workflow Engine Email IM Fax CMS
  35. 35. ‘formal’ SOA infrastructure
  36. 36. Enterprise Service Bus Data Service Service Service App 2 Data Service External Partner Service App 1
  37. 37. The Enterprise Service Bus • Should first of all be considered ‘a pattern’ • Virtualizes services – hides the real service from consumers – Deals with the physical location of the services – Interacts with the technology used to implement services • Adapts synchronous to a-synchronous and vv. • Can use multiple real services to offer one virtual (composite) service • Allows callers to use a generic, canonical message structure that it will transform to the service contract – It may even allow callers to use their own “lingo”
  38. 38. Canonical Data Model • Common Business Language – Esperanto for service invokers Data Data ServiceService Clients Customers
  39. 39. The Enterprise Service Bus (2) • Handles various QoS & SLA aspects – sometimes in concert with tools like OWSM – Encryption, signing, authentication – Retry and fallback – “Throttle” (prevent peak loads) • Does monitoring, tracking & auditing, reporting, notification and escalation • Works with Adapters to access technologies – like RDBMS (SQL, PL/SQL), AQ and JMS, File System, FTP, Java, E-Business Suite
  40. 40. Tables & Business Rules Views PL/SQL “Services” Oracle Forms Forms DWH External Partners Web Application Email Server Java based SQL* Loader Modern Architecture and the role of the database
  41. 41. Tables & Business Rules Views PL/SQL “Services” Oracle Forms Forms External Partners Web Application Email Server Java based (extranet) Web Application Internal Users (outside intranet/firewall) “Mobile Enabled” ADF 11g ADF 11g Enterprise Service and Process Bus (SOA Suite 11g: BPEL, Mediator, Human Task, Business Rules, Technology Adapters) files UCM (Document Management) DWH Operational Dashboard APEX
  42. 42. Tables & Business Rules Views PL/SQL “Services” Oracle Forms Forms External Partners Web Application Email Server Java based (extranet) Web Application Internal Users (outside intranet/firewall) “Mobile Enabled” ADF 11g ADF 11g Enterprise Service and Process Bus (SOA Suite 11g: BPEL, Mediator, Human Task, Business Rules, Technology Adapters) files UCM (Document Management) DWH Operational Dashboard APEX
  43. 43. The SOA Suite 11g • The engine that – runs applications that implement the WebServices – implements the Enterprise Service Bus [pattern] – Lives inside the WebLogic Server application server WebLogic Server 11g SOA Suite 11g WebServices
  44. 44. SOA Suite 11g Composite Applications • SOA Composite Applications consist of special components that process XML messages: – Decision Logic (go left or right, discount is X) – Human Workflow (end user must act) – BPEL (service orchestration) – Mediator (filter, transform and route messages)
  45. 45. SOA Suite 11g – calling out to external service and adapters • SOA Composite Applications can call out to external WebServices and Adapters • Adapters connect to various technologies – Database (SQL & PL/SQL) – Advanced Queuing – File & FTP – JMS, MQ Series, EBS TCP/IP Sockets • Adapters can trigger application execution
  46. 46. Publish Services from the Database • Describe Services in WSDL and XSL – Specify operations, input and output parameters – Describe complex data structures of parameters • Publish Database-based Services – Plain URL services through PL/SQL packages • based on MOD_PLSQL, XML DB or DBMS_EPG – Full blown SOAP WebServices • 11g Native WebService (publish PL/SQL package), use UTL_DBWS, JPublisher for Java proxy class in AppServer – Leverage SOA Suite to expose Database functionality • Through the database adapter in SOA Suite/WLS
  47. 47. #1 SOA task: Publish PL/SQL Package through ESB • Use Database Adapter to create Service, combine with ESB Routing Service • Use case: – external access to services – virtualize location and technology of service – • route to service based on content of the request – virtualize part of contract of service • Package-derived XSD not suitable for consumers – handle peak loads – monitor service levels and trace service access WS*
  48. 48. Demo • Create SOA Composite application • Configure Database Adapter to interact with HRM_SERVICE_API package • Create a Mediator to transform XML message from the db adapter to the desired format
  49. 49. XSD for the HRM WebService
  50. 50. Transform XML
  51. 51. Demo • Create SOA Composite application • Configure Database Adapter to interact with HRM_SERVICE_API package • Create a Mediator to transform XML message from the db adapter to the desired format • Deploy SOA Composite in SOA Suite in WLS • Test the Web Service based on the PL/SQL package based on the DEPT and EMP table
  52. 52. SOA Composite Application exposes Hrm Web Service
  53. 53. Enterprise Service Bus in action • One team responsible for exposing services to external consumers – Working with those customers for establishing the contract and testing across the firewall – This team built from internally provided services • Team two worked inside database – providing package based API for granular services • Team three created ESB level database adapter and routing/mapping services WS*
  54. 54. Business Events Dealer Order Event Pool Sales Desk Marketing Customer Relations Shipping
  55. 55. Event Driven Architecture • EDA (is also Extremely Decoupled Architecture) • Any system – including database – reports events that may be interesting to other parties • The Event backbone (could be the ESB) – Defines Event Types (name, structure of payload) – Registers Event Listeners (“please call me when the event occurs and send the details”) – Receives events – instances of the predefined event type with payload and timestamp • Propagate events to all registered listeners • Without blocking the event producer
  56. 56. Event Driven Architecture (EDA) Data Service Service Service App 2 Data Service External Partner Service App 1
  57. 57. Leveraging SOA Suite 11g from the database • The database can call out to the SOA Suite 11g – With UTL_HTTP or Stored Java (2-way, synchronous) – Through Advanced Queuing or Database Adapter polling (one way) WebLogic Server 11g SOA Suite 11g AQ AQ
  58. 58. Call the “getOilPrice Service” • We need to know the oil price for some calculations… • But that price is not constant, we need the current price • • We do not want the exact market price, we have our own contracts • Let’s define a constant in a package • Oh, well, let’s call a WebService – Yahoo? • Ah, the Purchasing department publishes a WebService for such data
  59. 59. Calling a Web Service • Send an XML document to a URL via HTTP – Request message contains headers and body • Service (server) returns another XML document – Response message contains headers and body • Response can be a fault (a WebService exception) • Headers are used for meta-data – Sender (identity, address), Return address – Encryption, digitally signed, – Type of content, type of compression
  60. 60. PurchasingPrices available via SOAP • PurchasingPrices Service is available as a (SOAP based) WebService (implemented using BPEL) – Service and WSDL are available (URLs are known)
  61. 61. PurchasingPrices available via SOAP • SOAP call over HTTP can be made from PL/SQL – Using UTL_HTTP • Assemble SOAP message – Envelope – Payload • Name of product – Make HTTP Post request – Process Response • Retrieve and Return the product price – “re-Publish” service as PL/SQL function WebLogic Server 11g SOA Suite 11g
  62. 62. PurchasingPrices available via SOAP WebLogic Server 11g SOA Suite 11g
  63. 63. Publishing events to the EDN from within the database • Publishing events to the Event Delivery Network from table triggers or PL/SQL APIs – Is best done via Advanced Queuing • The same route in reverse can consume events from EDN into the database
  64. 64. The database can ask the middle tier for other services as well • Get information from (or to) services on the intranet or internet (‘please get us the NBA scores ’) • Publish/Send information to the internet (RSS, email, chat) • Can tell the middle tier – Interesting events and data changes • Trigger cache refresh! – Alert about (im)pending issues, attempted rule violations, … – The outcome of batch calculcations WebLogic Server 11g SOA Suite 11g AQ Web App summary
  65. 65. Complex Event Processing to process on behalf of database events JMS HTTP JMX File DB Complex Event Processor Event Consumer Alert JMS Dashboard SOA Application DB Data Warehouse WebService File
  66. 66. The Data Avalanche • The league of real time events – Continuous stream of a multitude of tiny events with hardly any payload, most of which are not interesting at all – Sent from physical sensors (temperature, pressure, RFID, security gates), process sensors, Twitter, manufacturing equipment, database triggers, web servers, ESBs, stock trade tickers, sport statistics, RSS, network switches, …
  67. 67. Making Sense of Non-sense Complex Event Processing • Useful information could be hidden in those streams of events – and CEP extracts it – By detecting patterns, deviations, aggregations in these event streams – CEP publishes ‘meaningful’ (business) events to report its findings – by executing some Event Processing Langugae events Complex Event Processor
  68. 68. Continuous Query Language (CQL) • Standard extension/complement to SQL – For handling large volumes of continuously arriving events – Executing the queries continuously • Operates on streams of continually arriving events instead of static relational data sets – Events can be enriched with context – Results keep being produced as event stream • Is used for comparing events of same type, to find – Trends and Patterns – Exceptions – Aggregates Complex Event Processor summary
  69. 69. Business Agility through Decoupling
  70. 70. PL/SQL Package PL/SQL Package PL/SQL Package PL/SQL Package PL/SQL Package
  71. 71. PL/SQL Package PL/SQL Package PL/SQL Package PL/SQL Package PL/SQL Package
  72. 72. True Injection Dependency_Injector After Logon trigger setMailServer EMAILER setInterestRate setVatRate TAX_CALC setFileInName setLogLevel LOGGER setUrlProxy RSS_READER Configuration Values mailserver interest_rate vat_rate file_in_name log_level url_proxy emailer tax_calc tax_calc logger logger rss_reader amislin32 4.5 17.6 app_log_x debug amisvm2… property package value
  73. 73. Decoupling from Table to ESB+ http WEBDAVFTP http WS/SOAP WS* WS* WS* WSRP coupled complex
  74. 74. Increasingly decoupled • More hiding of the implementation • More Formal Interface Contract • Less (proprietary) technology & more standards for interacting • Less exposure of (legacy) data model • More support for asynchronous interaction • More reuse potential • Pervasive throughout enterprise • More suitable for external consumption
  75. 75. Comes at a cost… • More run time overhead – Additional tiers – XML serialization and deserialization • More infrastructure – Burden of Administration – License Costs – Hardware • Broader skills palette – more stuff to master • Harder to get started
  76. 76. Summary • SOA is about decoupling, integration & reuse • SOA Suite 11g runs service implementations – That can access database and other technologies through adapters – either inbound or outbound • Database can access services from utl_http – Or AQ, Database polling or File polling • SOA Suite hooks into database via SQL, PL/SQL, AQ or even XML DB file protocols • Many SOA concepts can be applied without the SOA Suite, using standard DB features
  77. 77. Tables & Business Rules Views PL/SQL “Services” Oracle Forms Forms External Partners Web Application Email Server Java based (extranet) Web Application Internal Users (outside intranet/firewall) “Mobile Enabled” ADF 11g ADF 11g Enterprise Service and Process Bus (SOA Suite 11g: BPEL, Mediator, Human Task, Business Rules, Technology Adapters) files UCM (Document Management) DWH Operational Dashboard APEX
  78. 78. Resources • Presentation and demos are on our blog – http://technology.amis.nl/blog • Contact me at: – lucas.jellema@ amis.nl

×