Tuesday, April 7, 2015

CANONICAL MODEL and its relevance to SOA



Introduction

Does an Enterprise implementing SOA need a Canonical data Model ?There has been a lot of research going on in the implementation of Common Information Model (CIM) commonly called as Canonical data model (CDM) in an Enterprise SOA.

CDM and its definition
CDM is essentially for an enterprise having disparate applications requiring seamless integration. The problem occurs with an enterprise which is growing continuously requiring constant change in the CDM to include all sets of possible granular Business Objects and relationships that the Enterprise wants to integrate to keep it upto the pace of organizational changes. This causes increase in effort and cost in maintaining those changes. CIM should be completely Application independent and must be either domain oriented or Enterprise scoped.

But what is CIM/CDM?

A simple definition is as follows:
A CIM (Common Information Model) is all about semantic business process integration and is superset of Information objects and relationships that define the complete business semantics of an Enterprise in a granular, application independent, neutral approach backed by Industry standards for an Application-Application (A2A), Business-Business(B2B customers & partners) or an Event Driven (EDA) SOA solution applications needed to agree to do the business. CIM is a completely controlled and totally governed centralized data model that defines the dataflow through a Mediator/BPEL. CIM should be an application-independent and enterprise-specific metadata and complete analysis of domain data should be done before implementing CIM. CIM is substituted with terms like 'Canonical', 'Enterprise Canonical' and Information with 'Data', 'Domain'. CIM, CDM and ECDM - All means the same. For example, every major car company probably has a unique data type representation of a car’s tire throughout the company.
Early adoption of CIM is an ideal approach for any SOA initiative. The main ingredient of SOA i.e reusability can be achieved through CIM. We need to make a time-cost analysis and if your enterprise integration vision has new applications to be integrated or a possible acquisition/merger/expansion that involve ESB, its advisable to start CIM implementation as soon as you can and have the data flow for the new services through CIM-ESB. For enterprises starting the SOA initiative, it's probably a right approach to figure out the need for the CIM now than months later. Once CIM is deployed, enterprise can concentrate on service orchestration and assembly rather than data modeling. As the number of applications and data associated increases, CIM should be a growing structure with granular objects perfectly distinguished and maintained by proper name spacing. Maintenance of CIM through a central governance body (Ex: Center of Excellence in your enterprise) and metadata management repository is a must. As applications to be integrated are expected to grow in future, early CIM adoption gives ROI.

However, in order to integrate the applications, either along the way or at the end of the data-generation processes, we need to use a particularly constrained definition of Canonical Schema: the Enterprise Canonical Message Schema which is a subset of the Enterprise Canonical Data Model that represents the data we will pass between systems that many people feel would be useful. By constraining our message schema to the elements in the Enterprise Canonical Data Model, we radically reduce the cost of producing good data "at the end" because we will not generate bad data along the way. When we pass a message from one application to another, over a Service Oriented Architecture or in EDI or in a batch file, we pass a set of data between applications. Both the sender and the receiver have a shared understanding of what these fields (a) data type, (b) range of values, and (c) semantic meaning. This is where most of the cost of point-to-point integration takes from: creating a consistent agreement between two applications for what the data MEANS and how it will be used.

The schema guidelines must be clearly defined including Versioning, namespaces, and naming and usage of file comments and xsd tags.The entities shared across schemas in a common schema must be defined

Schema versioning is one of the greatest concerns when working with a canonical data model. Once developers start using your CDM it becomes harder and harder to make changes without impacting the current services. Determine a standard on how major and minor version numbers will be used to support backward compatibility. We use minor version numbers to represent changes that are fully backward compatibility and major version numbers to represent changes that require users to modify their code to utilize the new schema.

Common Information Model (CIM) is needed in these cases:

1) When the integration involves increasing number of applications and increasing acquisitions, mergers and ever increasing number of business processes involving a time-cost analysis if all your applications are not fully connected and does not require all possible two way point -point interfaces
2) Need for centralized (governed) dataflow of data flowing in the ESB for improved traceability and uniformity across the enterprise
3) When there is need for reusability in data modeling (schemas)

Ideal Common Information Model (CIM) should have following characteristics:

1) CIM should be an application-independent and industry specific or enterprise-specific metadata following industry standards. Also, backward compatibility and interoperability exists for the future applications to be integrated.

2) You need to establish is your governance model around the CDM. Governance model must assure that:

  • Any new version is backward compatible (never delete entities or attributes, any new element is always optional)
  • Changes can be propagated in steps and do not require a big bang change
  • Changes are documented and communication of the changes reach everyone that uses the model.


3) Before implementing SOA-ESB methodology, perform a complete enterprise business (domain) data and cost analysis and then start services creation.
4) To execute loosely coupled Service Oriented Architecture, have your data tightly coupled to the services using a CIM and allow loose coupling for the services.
5) Make sure all the data that flows in the ESB is accommodated in the CIM for improved traceability.
6) CIM should have accommodations for future scoping and allow space for asking questions (reply back).
7) Make your CIM objects (schemas) granular, application independent, and reusable separated by proper name spacing.
8) The operability of the model and how people make use of it. Architects should review and approve any implementation of the model, assuring that the usage of it is consistent across domains/implementations.
9) Applications should consume the services on a standard way, and if you use CDM, the services should make use of it on the interface.However you should consider implementing service abstraction, allowing that way, that application to make use of your service using a different interface and do not try to force all applications to conform to the same standard interface

Disadvantages of CIM:
1) Additional translation (adapter) layer.
2) Improper implementation of CIM (lacking standards or an incomplete analysis of the domain) might have a ripple effect in your services if the domain datamodel changes.
3) Initial maintenance issues. If the application data and domain data models(CIM) changes frequently, CIM would be a maintenance burden.
4) Time to market factor
5) Heavy Flux of Business Data and Business System Data
6) CIM alone can't address other key data issues (eg:data security, data synch, data aggregation, data Mapping, data) which forces to take other SOA solution like ESB/Broker products

Advantages of CIM:
1) Speed of Integration with introduction of new applications.
2) By using a CDM you can have a single language the people can know the entities on your company, facilitating the conversations between different teams/sub-organizational units. Reduces mappings between applications
3) Transformations are only necessary to and from canonical form, reducing the number of different transformations required to be created
4) Interoperability with future applications.
5) Reduces Data modeling and Schema design effort for every interface to every other interface.Decouples format of data from services, allowing a service to be replaced by
one providing the same function but a different format of data
6) Maintenance in Long-term is economical.
7) Granularity in Enterprise workflow.
8) Traceability of transactions across your Enterprise.
9) This level of abstraction can go as far as hiding the fact that we are using multiple services concurrently by allowing us to make routing decisions at runtime.

The integration projects required to have a canonical data model for all messages exchanged between systems to map between the format and semantics of the disparate systems taking part in a SOA solution.The canonical data model was a common format for all messages. If a system wanted to send a message, then it first needed to transform itto the canonical form before it could be forwarded to the receiving system, which would then transform it from the canonical form to its own representation. Basically trying to enforce one Canonical Message Schema across services

All these features are there to help us build service-oriented architectures that are resilient to change and can easily absorb new functionality and services.

Classifications of CIM
SOA in Enterprise Architecture leverages Canonical data model which can be classified as follows:

->An enterprise canonical data model (Abstract model) – this is the model that encompasses the entire enterprise and covers all entities, their attributes and the various relationships they share. This data model does not limit the definition of an entity to a given business function or activity. On the contrary, this provides an exhaustive definition of what each entity signifies for the enterprise via its attributes, behaviors and relationships. The main advantage of this enterprise data model is that as it grows over a period of time, it becomes the single point of reference across the organization; service designers refer to it for building and specifying their contract; service consumers look at it to understand the “common meaning” of the entity and it’s attributes; business refers to this model to understand the complete view of the entity; all parties refer to this common vocabulary when communicating with each other. This model becomes the basic fabric on which all communication is based.

->A context-specific canonical data model (service canonical model)- this is the model that is very context-specific which is the business function context in which this data model is being used. This model will be a scaled down version of the entity and its attributes as they appear in the enterprise model in the light of the business function. Additionally, this model will also apply the appropriate constraints on the entities and their attributes as relevant to the context of the business function.The advantage of this model is that all parties to this service will have a clear definition of what this function will need as input and what can be expected from it in return.





Conclusion

Enterprise implementing SOA should incorporate Canonical data model to make services reusable and One of the most important things an architect also need to do, is to educate the enterprise on the use of the CDM, and the long term advantages of it. People often fail to see the long term and select a more pragmatic approach to solve the problems they are facing without considering the impacts of it down the road. Architect need to assure that your stake holders comprehend the benefits that they will get by applying strong governance on the usage of CDM and the technical people know how to make use of it. If you neglect either of this educational steps, you will find resistance whenever you propose to use the CDM and your CDM program will probably fail.

Simplifying Mobile Integration by using JAX-RS RI to build RESTful web services

SOA in large enterprises have evolved and are now using RESTful web services as it is faster, lightweight, easy to implement. REST stands for Representational State Transfer and involves request to be sent from client to server in the form of URI. REST is a simple stateless architecture generally running over HTTP supporting request/reply pattern. Among big REST drivers today are mobile applications, social networking Web sites, mashup tools and automated business processes.
With the increasing amount of smartphone users all over the world, we needed to have a mobile
app strategy to build RESTful services that can bring our product to this growing market.REST
has distinct advantages for loosely coupled services  on massive scale. REST integration patterns are often highly effective for enterprise architects that are working on integrating applications within a SOA framework. However, the need to implement REST based architecture depends completely on business requirements of the company.
REST is preferred and cost-effective architectural style for implementing services due to its scalability, its ability to allow dynamic connectivity without prior planning, ability to enable independent evolution of clients and services and its built-in support for caching and security.
REST can help having centralized data storage for the data coming from both the web and the mobile. This can avoid repetition by just creating a storage layer once, as an API, and reusing it with multiple application versions. We can even easily have REST service distributed between several load-balanced servers, and even save precious CPU cycles by reusing already generated data in some requests.
REST services have uniform interface which only allow HTTP operations: GET, POST, PUT, DELETE. We needed to build Restful services which takes JSON input/output. JSON is recommended for data transfer in a REST API as it is scalable and hence cost-effective and sending or receiving JSON data in each request is preferred as it is light-weight,simple,clean data with minimal tags, human-readable, faster than XML.It is programming language independent and also doesn’t have the concept of namespaces as in XML.
Comparison between the options we had for building Restful services (PROS/CONS)
We had some options to decide an optimal way to build RESTful services for the mobile application utilizing Oracle SOA(11.1.1.6). The following table lists the different options we considered and what made us choose JAX-RS(Jersey) RI.

Custom Wrapper(Spring/hibernate)
Jersey(JAX-RS RI)
HTTP Adapter
Socket Adapter
Single Router
Single router to appropriate Resource class/method
Simple to implement/code
Simple to implement code
Could build all services that were needed
Could build all services that were needed
Easy to build RESTful services with GET or POST method
Custom Java Code needed to be plugged in in socket adapter for a request/reply handshake  and request/response are parsed using XSLT functions
Deploys easily(Single WAR in spring)
Deploys easily(Single WAR)
Deploys easily
Deployment challenges
JSON IN/OUT
JSON IN/OUT
Payload is XML or URL-Encoded type only-NO JSON support
JSON IN/OUT
GSON deserializability
GSON deserializability
Easy for Mobile to consume JSON
Easy for Mobile to consume JSON
Complex configurations even for simple functionality
All custom java/Spring code
PL/SQL,JAVA,SOA code
SOA,JAVA to code
JAVA,SOA to code
Lot of code and customizations needed
Less code because of JAX-WS to JAX-RS translation
Query String inputs
1 socket for each service unless custom router was used
OSS Dependency
OSS Dependency
Time/Learning curve
Reusability challenge


Future support for Mobile applications (REST Based services)

Oracle SOA Suite 11.1.1.7 simplifies integration experience by leveraging mobile integration where Oracle SOA connects mobile applications using JSON and REST via Oracle Service bus and in Oracle SOA 12c simplifies integration by utilizing REST binding exposing traditional SOAP services, Enterprise Java Beans (EJBs), JCA adapters connecting backend applications or any other underlying implementation through JSON/REST.

Methodology



The above figure presents the diagrammatic technical design of approach taken for building RESTful services. This incorporated the use of Façade object oriented pattern wherein Façade Jersey class abstracts other packages used in creation of the web services and wherein one RESTful webservice call  by Mobile application(client) utilizes Façade pattern  to access data from database  which are the result from N number of calls behind service for that one  web service call.
We utilized Oracle SOA to either select or insert data into the database using BPEL/mediator . While some of the PL/SQL procedures contained the hardcoded JSON formatted queries to access the database and other JSON formatting was done in Jersey class using JSONObject and other JSON classes. The SOAP web service was consumed by JAVA proxy for web service. We selected JAX-WS style for proxy wherein client uses JAXB mapping style for serialization to generate asynchronous methods with JAX-WS bindings.
JAX-RS web services/clients were written by configuring Jersey for project and adding all .JAR files to the classpath of project/application.

Configuring    Jersey    JAX-RS RI
1) Register JAX-RS libraries with one or more weblogic server instances or pass .jar files in classpath of   Jersey Project/application
Shared Java EE libraries are registered with one or more WebLogic Server(11g) instances by deploying them to the target servers and indicating that the deployments are to be shared. Shared Java EE libraries must be targeted to the same WebLogic Server instances we want to deploy applications that reference the libraries. When a referencing application is deployed, WebLogic Server merges the shared library files with the application.

We can also just include jersey-core.jar, jersey-server.jar,jsr311-api.jar,asm.jar and jersey-client.jar in the web project/application classpath(if not registering with weblogic server)

2)Configure Web application/project that contains RESTFul webservice to use Jersey JAX-RS RI shared libraries.
We need to configure the Web application that contains the RESTful Web services to use the Jersey shared libraries. We need to update the following two deployment descriptor files that are associated with our application:
web.xml—Update to delegate Web requests to the Jersey servlet.
weblogic.xml—Update to reference the shared libraries that are required by application/project only when registering shared libraries with weblogic server
Updating web.xml to Delegate Web Requests to the Jersey Servlet
The following provides an example of how to update the web.xml file:
    <web-app>
        <servlet>
        <display-name>My Jersey Application</display-name>
        <servlet-name>MyJerseyApp</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>myPackage.myJerseyApplication</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyJerseyApp</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>
Updating weblogic.xml to Reference the Shared Libraries
Update the weblogic.xml file to reference the shared libraries that are required by  application/project. The weblogic.xml file is located in the WEB-INF directory in the root directory of your application archive.
Weblogic.xml is updated only if have deployed JAR files to weblogic server.

Once Jersey class is coded, then deploy it to WAR file and deploy it to application server and run the URL on REST console or browser to test.

Securing your REST web service

Securing your REST web service
  • Authentication for Identity Verification
  • Authorization
  • Encryption

  • Userid/Pwd can be used for services consumed by your mobile app for authentication or Oauth can be used for third-party web apps/mobile apps
  • SSL or Secure flag can be used in web.xml in encrypted form for further security measures
  • @context SecurityContext

Authentication:Configure web.xml
<login-config>
 <auth-method>BASIC</auth-method>
  <realm-name>admin</realm-name>
</login-config>
<security-constraint>
<web-resource-collection>http-method>POST</http-method>
</web-resource-collection>
</security-constraint>
….
<auth-constraint>
<description>only let admin login</description>
<role-name>admin</role-name>
</auth-constraint>

Login-config:
Defines how HTTP requests should be authenticated
Auth-method:
BASIC,DIGEST or CLIENT_CERT correspond to basic, digest and client certificate authentication respectively
Realm-name:
Name for database for user id groups that identify valid users of a web application
Security constraint:
Defines access priveleges to collection of resources
url-pattern:
URL pattern you want to secure
http-method:
Methods to be protected
Auth-constraint:
Names the roles authorized to access URL patterns and HTTP methods declared by this security constraint. Authentication by providing security-role which lists all of security roles used in application

Encryption : Configure web.xml
<security-constraint>
    <user-data-constraint>
   <description>SSL</description>
    <transport-guarantee>CONFIDENTIAL</transport-guarentee>
     </user-data-constraint>
</security-constraint>

user-data-constraint: NONE,INTEGRAL or CONFIDENTIAL to imply how the data will be transported between client and server

Authorization Annotations
  • @RolesAllowed({“Admin”,”Customer”}) //roles permitted to execute operation
  • @PermitAll//permitting any authenticated user
  • @DenyAll// to deny all users

JAX-RS Security Context 
public interface SecurityContext { 
public Principal getUserPrincipal();  //Determine the identity of user
public boolean isUserInRole(String role); //check whether user belongs to certain role
public boolean isSecure(); //whether this request was made using a secure channel
public String getAuthenticationScheme(); 
}