Friday, May 23, 2014

JEE application and MDS provisioning

This article uncovers how standard JEE EAR file caring MAR archive populates MDS during deployment process. Presented information was used to implement off-line configuration of SOA Suite 11g.
#1 Oracle Fusion Middleware 11g introduced metadata repository - MDS, which is used by all Middleware family to store non business related data. MDS is designed to store multi version XML information. Fusion Middleware applications uses XML standard to encode customizations, runtime configuration, WSDL interface descriptors, and BPEL business logic. MDS is natural storage for them. [Link]

#2 Metadata Repository defines new file type: MAR. "A Metadata Archive (MAR) is a compressed archive of selected metadata, such as the application-level deployment profile, for an application. A MAR is used to deploy metadata content to the metadata service (MDS) repository. The following application types use a MAR as a container for content that is deployed to the MDS Repository: ADF applications, SOA composite applications, and Oracle WebCenter applications." [Link] Moreover SOA Suite 11g uses MDS/MAR to store configuration files. Inside of MAR you will see no more than set of files and directories without any additional descriptors.

Figure 1. Content of soa.mar shipped with soa-infra-wls.ear

#3 MAR file in unknown for JEE application server. It must be embedded in EAR to be picked up during EAR deployment process. MDS deployment is processed by MDS class registered as application life cycle listener and hooking preStart state. It's important information, as MAR deployment is done during deployment of EAR, the application in "prepared" state, already has populated MDS with it's metadata. This is is really nice.
The listener and whole MDS package is shipped with Java Required Files (JRF) template. It's in middleware home, oracle_common/modules/oracle.mds_11.1.1/mdsrt.jar if you want to take a look at this. As you see MDS is not a part of core WebLogic.

<?xml version="1.0"?>
<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <listener>
     <listener-class>oracle.mds.lcm.weblogic.WLLifecycleListener</listener-class>
  </listener>

</weblogic-application>
Source 1. META-INF/weblogic-application.xml

Registered listener (oracle.mds.lcm.weblogic.WLLifecycleListener) forwards actual work to oracle.mds.internal.lcm.MDSLifecycleListenerImpl class which uses oracle.mds.internal.lcm.deploy.DeployManager to perform actual MDS interaction. Both classes are in oracle_common/modules/oracle.mds_11.1.1/mdlcm.jar.

Note that typical ADF application has one more listener provided by ADF components. Other descriptors are not necessary as if the application does not contain any ADF related resources and is used just to deploy MAR [Link].

#4 MAR deployment code relays on a marker file containing no Java classes. There is only META-INF/MANIFEST.MF with classpath information adding ../adf to application classpath. 

Manifest-Version: 1.0
Class-Path: ../adf
Source 2. lib/adf-loc.jar

This simple file is an interesting piece of JEE engineering. To understand what it's doing, it's necessary to look inside JAR specification [Link], EAR specification [Link, page 156], and the source code. Let's start from the code. MDSLifecycleListenerImpl mentions "META-INF/adf-config.xml", which defined and used by MDSLCMManager by getting resource from it's class loader: Thread.currentThread().getContextClassLoader().getResource("META-INF/adf-config.xml"). EAR specification explains why adf-loc.jar was added to class path (EAR/lib), finally JAR specification makes clear how ../adf is added to applications' classpath (Class-path attribute).

#5 Main MDS configuration files is located in ../adf directory. MDS manager code looks up META-INF/adf-config.xml, which is found in a classpath due to adf-loc.jar classpath manipulation. 
Finally MDSLCMManager reads it's critical configuration file delivering information about associated MDS repository. 

<?xml version = '1.0' encoding = 'UTF-8'?>
  <adf-mds-config xmlns="http://xmlns.oracle.com/adf/mds/config">
    <mds-config xmlns="http://xmlns.oracle.com/mds/config">
      <persistence-config>
        <metadata-namespaces>
          <namespace path="/deployed-composites" metadata-store-usage="soa-infra-store"/>
          <namespace path="/soa/configuration" metadata-store-usage="soa-infra-store"/>
        </metadata-namespaces>
        <metadata-store-usages>
          <metadata-store-usage id="soa-infra-store" deploy-target="true" default-cust-store="true">
            <metadata-store class-name="oracle.mds.persistence.stores.db.DBMetadataStore">
             <property name="repository-name" value="mds-soa"/>
             <property value="soa-infra" name="partition-name"/>
             <property value="jdbc/mds/MDS_LocalTxDataSource" name="jndi-datasource"/>
            </metadata-store>
          </metadata-store-usage>
        </metadata-store-usages>

        <auto-purge seconds-to-live="3600"/>
        <retry-connection enabled="true"/>
      </persistence-config>
    </mds-config>
  </adf-mds-config>
</adf-config>
Source 3. Trimmed MDS connectivity descriptor shipped with soa-infra-wls.ear


#6 EAR level META-INF/MANIFEST.MF is created by jar archiver, and contains no information other than file version. 

Manifest-Version: 1.0
Source 4. EAR level manifest.mf

#7 Summary. Presented information was used to implement off-line configuration of SOA Suite 11g. Take a look into MAR deployment lifecycle to understand how and when metadata is copied into MDS.


###

No comments:

Post a Comment