%
%  $Id$
%
%  Copyright (c) 2004, RIACA, Technische Universiteit Eindhoven (TU/e).
%  All Rights Reserved.
%
%
\documentclass{article}

\RequirePackage[T1]{fontenc}
\usepackage[screen]{tuepdfscreen}
\usepackage{graphicx}
\usepackage[english]{babel}

\hypersetup{
  pdfauthor={Manfred N. Riem},
  pdftitle={Monet Execution Manager},
  pdfsubject={Monet},
  pdfkeywords={Monet,Architecture,Jelly,Exection},
  pdfpagemode={FullScreen}
}

\bottombuttons
\pagenumbering
\overlay{tuebgkuk}

\title{\Huge Monet Execution Manager}
\author{\Large Manfred N. Riem}
\date{March 17, 2004}

\begin{document}
 \begin{slide}
  \maketitle
 \end{slide}

 \begin{slidetop}
  \bigskip
  \section*{What does the Execution Manager (EM) do?}
  \bigskip
  \begin{itemize}
   \item Execute written or generated plans.
   \item Call (mathematical) web services as specified in a plan.
   \item Gives an explanation of an execution.
   \item Delivers workflow management for plans.
   \item Delivers a simple calculation environment.
  \end{itemize}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Where does it plug into the Monet architecture?}
  \bigskip
  In the Monet architecture the Execution manager is at the end of
  the pipeline. 
  \par
  \bigskip
  A possible scenario is:
  \begin{itemize}
   \item The user poses a query and gets a result of 
   possible plans that can solve the given problem. 
   \item The user picks one plan and submits it for 
   execution to the Execution Manager.
   \item The Execution Manager will execute the given 
   plan and return the result (with or without explanation) 
   to the user.
  \end{itemize}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Looking at EM as a black box}
  As every component in the Monet architecture is implemented as 
  a webservice you can look at it as a blackbox delivering a 
  specific service.
  \par
  \bigskip
  In the case of the EM this is transforming a plan written
  in MPL to an explanation written in MEL. Where the explanation
  can simply be the result of the execution, or a trace of the 
  execution plus the result, or a more elaborate result document
  in MEL.
  \par
  \bigskip
  \begin{center}
   \includegraphics[angle=270]{em}
  \end{center}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Mathematical Planning Language (MPL)}
  The EM is written to support MPL. The syntax and semantics of MPL
  are similar to the Business Process Execution Language (BPEL). There
  were three good reasons for MPL to have a syntax similar to BPEL:
  \begin{enumerate}
   \item It is a standard used in industry for non-mathematical
         processes and as such borrowing from its syntax makes 
         it easier for users to understand MPL.
   \item Writing an EM based on an existing BPEL engine is a possibility.
   \item Integrating the EM into an existing BPEL process / environment
         is easier when the language that is understood is the same language.
  \end{enumerate}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{An example of MPL}
  \begin{small}
  \begin{verbatim}
<plan>
  ... parameters ... 
  ... variables  ...
  <sequence>
    ... assignments ...
    <sequence>
      <assign>
        <varref name="g"/>
        <invoke url="http://localhost:8080/gcdws/gcdws?MSDL">
          <mapping>
            <map inputname="a"><paramref name="firstValue"/></map>
            <map inputname="b"><paramref name="secondValue"/></map>
           </mapping>
        </invoke>
      </assign>
      <return><varref name="g"/></return>
    </sequence>
  </sequence>
</plan> 
  \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Mathematical Explanation Language (MEL)}
  When executing a plan the result returned is an explanation
  written in MEL. The result could be the following things:
  \begin{itemize}
    \item An answer only
    \item An answer plus traces of the calls to webservices
    \item An answer plus several explanations given by the
         invoked webservices and/or the plan itself.
  \end{itemize}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{An example of MEL}
  \begin{small}
   \begin{verbatim}
<monet:query-response ....>
 <monet:executionResponse>
  <monet:problem>
   ...
  </monet:problem>
  <monet:explanation>
   <monet:executionResponse>
    <monet:errorcode>0</monet:errorcode>
    <monet:explanationFormat isProvided="false"/>
    <monet:result>
     <monet:resultFormat type="xsd:int">123</monet:resultFormat>
    </monet:result>
   </monet:executionResponse>
  </monet:explanation>
  <monet:result>
   <monet:resultFormat type="xsd:int">234</monet:resultFormat>
  </monet:result>
 </monet:executionResponse>
</monet:query-response>    
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{How does it work internally?}
  Our implementation of the Execution Manager uses the 
  following set of technologies:
  \begin{itemize}
   \item XSL-T processing.
   \item Jelly scripting.
   \item Jelly extensions.
  \end{itemize}
  \par
  \bigskip
  \begin{center}
   \includegraphics[angle=270]{internal}
  \end{center}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{What is Jelly?}
  Jelly is a tool for turning XML into executable code. So Jelly is a Java and 
  XML based scripting and processing engine.
  \par
  \bigskip
  A Jelly script is an XML document which gets parsed into a Script. The script can then be ran to 
    produce dynamic XML events which can then be turned into text, XML, HTML etc. 
  \par
  \bigskip
  \begin{center}
   \includegraphics[angle=270]{jelly}
  \end{center}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Example: Hello World}
  \par
   The input document could be:
  \bigskip
  \begin{verbatim}
<j:jelly xmlns:j="jelly:core">
  Hello World!
</j:jelly>
  \end{verbatim}
  \par
   The output document would be:
  \bigskip
  \begin{verbatim}
Hello World!
  \end{verbatim}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Example: XML processing}
  \begin{small}
   \begin{verbatim}
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml">
  <x:parse var="doc">
    <web-app>
      <servlet>
        <servlet-name>snoop</servlet-name>
        <servlet-class>SnoopServlet</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>file</servlet-name>
        <servlet-class>ViewFile</servlet-class>
        <init-param>
          <param-name>initial</param-name>
          <param-value>1000</param-value>
          <description>
            The initial value for the counter
          </description>
        </init-param>
      </servlet>
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Example: XML processing (2)} 
  \begin{small}
   \begin{verbatim}
      <servlet-mapping>
        <servlet-name>snoop</servlet-name>
        <url-pattern>/foo/snoop</url-pattern>
      </servlet-mapping>
    </web-app>
  </x:parse>
  <x:set var="count" select="count($doc//servlet)"/>
  <x:forEach var="s" select="$doc//servlet">
    name: <x:expr select="$s/servlet-name"/>
    class: <x:expr select="$s/servlet-class"/>
  </x:forEach>
  There are <x:expr select="$count"/> servlet(s)
</j:jelly>
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Example: GCD using a GCD webservice}
  \begin{small}
   \begin{verbatim}
<j:jelly xmlns:j="jelly:core" 
 xmlns:i="jelly:nl.tue.win.riaca.jelly.invoke.InvokeTagLibrary">
  <j:set var="a" value="${34}"/>
  <j:set var="b" value="${12}"/>
  
  <j:expr value="a=${a},"/>
  <j:expr value="b=${b},"/>
  <i:invoke var="r" 
      service="Gcdws" 
      port="GcdWebServiceIFPort" 
      namespace="http://echoservice.org/wsdl"
      endpoint="http://localhost:8080/gcdws/gcdws"
      operation="gcd"
      returnType="xsd:int">
    <int_1 type="xsd:int"><j:expr value="${a}"/></int_1>
    <int_2 type="xsd:int"><j:expr value="${b}"/></int_2>
  </i:invoke>
  <j:expr value="r=${r}"/>
</j:jelly>
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Example: GCD using an REM webservice}
  Instead of using a GCD webservice directly one can of course also
  use a REM webservice (which does remainder for you) to perform a
  GCD.
  \bigskip
  \begin{small}
   \begin{verbatim}
<j:jelly xmlns:j="jelly:core" 
 xmlns:i="jelly:nl.tue.win.riaca.jelly.invoke.InvokeTagLibrary">
  <j:set var="a" value="${34}"/>
  <j:set var="b" value="${12}"/>
  
  <j:if test="a lt b">
    <j:set var="r"><j:expr value="${a}"/></j:set>
    <j:set var="a"><j:expr value="${b}"/></j:set>
    <j:set var="b"><j:expr value="${r}"/></j:set>
  </j:if>

  <j:expr value="a=${a},"/>
  <j:expr value="b=${b},"/>
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Example: GCD using an REM webservice (2)}
  \begin{small}
   \begin{verbatim}
  <j:while test="${b ne 0}">
    <i:invoke var="r" 
        service="Remws" 
        port="RemWebServiceIFPort" 
        namespace="http://echoservice.org/wsdl"
        endpoint="http://localhost:8080/remws/remws"
        operation="rem"
        returnType="xsd:int">
      <int_1 type="xsd:int"><j:expr value="${a}"/></int_1>
      <int_2 type="xsd:int"><j:expr value="${b}"/></int_2>
    </i:invoke>
    <j:expr value="r=${r},"/>
    <j:set var="a"><j:expr value="${b}"/></j:set>
    <j:set var="b"><j:expr value="${r}"/></j:set>
    <j:expr value="a=${a},"/>
    <j:expr value="b=${b},"/>
  </j:while>
  <j:expr value="a=${a}"/>
</j:jelly>
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{How is Jelly integrated?}
  Coming back to the picture of the internals of 
  the Execution Manager. The input to the EM is MPL and
  its output is MEL.
  \par
  \bigskip
  How can we go from MPL to MEL? The answer is in the 
  diagram below. The MPL will need to be transformed to a
  Jelly script. For a simple plan the transformation is
  an easy path, for a plan that contains an invocation to
  an external webservice it is a bit more difficult.
  \par
  \bigskip
  \begin{center}
   \includegraphics[angle=270]{internal}
  \end{center}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{MPL invocation}
  MPL defines the invoke element so that a plan
  can call external webservices. To make it work
  inside a Jelly context the invocation below needs
  to be translated into a Jelly invocation.
  \par
  \bigskip
  The translation needs the following things to work:
  \begin{itemize}
   \item The MPL itself.
   \item The MSDL of any mathematical webservice that needs
         to be called.
   \item The WSDL of any mathematical webservice that needs
         to be called.
  \end{itemize}
  \par
  \bigskip
  \textit{Note}: the current version of the Execution Manager 
  enables you to call Mathematical web services described by 
  an MSDL file. If you want to call a non-mathematical web 
  service you will have to write a Jelly script manually.
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Jelly invocation}
  Because Jelly does not contain support to call web services in the 
  basic distribution a Jelly extension was written. In the examples 
  of Jelly given previously we've used the extension written for it.
  How does it work?
  \par
  \bigskip
  To create a extension one needs to do the following:
  \begin{enumerate}
   \item Write a Java class implementing the extension.
   \item Declare an XML namespace for the extension used.
   \item Associate the XML namespace with the Java class.
   \item Use the extension.
  \end{enumerate}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Programming a Jelly extension class}
  \begin{enumerate}
   \item A library class.
   \item Several tag classes.
  \end{enumerate}
  \par
  \bigskip
  The library class is used for registering the tag classes
  under a specific namespace. The tag classes are mapped on
  XML element.
  \par
  \bigskip
  \textbf{A Java skeleton for a tag class}
  \begin{small}
   \begin{verbatim}
public class InvokeTag extends TagSupport
{   
  public void doTag( XMLOutput output )
        throws MissingAttributeException, JellyTagException {
  }    
}
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Using the extension class}
  \begin{small}
   In the example below 3 separate Jelly extensions are used. 
   \begin{enumerate}
    \item j namespace, the core set of Jelly tags
    \item x namespace, XML processing tags
    \item i namespace, a separate invoke tag library
   \end{enumerate}
  \end{small}
  \begin{small}
   \begin{verbatim}
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml"
 xmlns:i="jelly:nl.tue.win.riaca.jelly.invoke.InvokeTagLibrary">
 <x:parse var="input">
  <OMOBJ><OMI>123</OMI></OMOBJ>
  </x:parse>
 </x:parse>
 <i:invoke ....>
  <int_1 type="xsd:int">
   <x:expr select="$input/OMOBJ/OMI"/>
  </int_1> 
 </i:invoke>
</j:jelly>
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{GCD invocation using MEL}
  The previous examples of GCD didn't return MEL. The example
  below does. As you will notice the main difference is the 
  presence of MEL elements in the Jelly script.
  \par
  \bigskip
  \begin{small}
   \begin{verbatim}
<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml"
 xmlns:i="jelly:nl.tue.win.riaca.jelly.invoke.InvokeTagLibrary">
 <x:element name="monet:query-response" ....>
  <x:element name="monet:executionResponse">
   <x:element name="monet:explanation"> 
    <j:set var="a" value="${34}"/>
    <j:set var="b" value="${12}"/>
    <i:invoke var="r" 
       service="Gcdws" 
       port="GcdWebServiceIFPort" 
       namespace="http://echoservice.org/wsdl"
       endpoint="http://localhost:8080/gcdws/gcdws"
       operation="gcd"
       returnType="xsd:int">
   \end{verbatim}
  \end{small} 
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{GCD invocation using MEL (2)}
  \begin{small}
   \begin{verbatim}
     <int_1 type="xsd:int"><j:expr value="${a}"/></int_1>
     <int_2 type="xsd:int"><j:expr value="${b}"/></int_2>
    </i:invoke>
    <x:element name="monet:errorcode">0</x:element>
     <x:element name="monet:explanationFormat">
      <x:attribute name="isProvided">false</x:attribute>
     </x:element>
    </x:element>    
    <x:element name="monet:result">
     <x:element name="monet:resultFormat"> 
      <x:attribute name="xsi:type">integer</x:attribute>
      <j:expr value="${r}"/>
     </x:element>
    </x:element>
   </x:element>
  </x:element>
 </x:element>
</j:jelly>
   \end{verbatim}
  \end{small}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{Future plans}
  \begin{itemize}
   \item Support for additional (scripting) languages
   \item Proper transaction support
   \item Custom Jelly extensions for more process control
   \item Distributed execution
   \item Authentication support
  \end{itemize}
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \bigskip
  \bigskip
  \bigskip
  \center{
   \Large{ Questions? }
  }
 \end{slidetop}

 \begin{slidetop}
  \bigskip
  \section*{References}
  \begin{itemize}
   \item JWSDP, http://java.sun.com/webservices/
   \item Jelly, http://jakarta.apache.org/common/jelly/
   \item BPEL,  http://www.ibm.com/developerworks/library/ws-bpel/
  \end{itemize}
 \end{slidetop}

\end{document}
