<?xml version='1.0' encoding='utf-8' ?>
<schema
    targetNamespace="http://lead.extreme.indiana.edu/namespaces/2005/06/workflow_tracking"
    xmlns:lead="http://lead.extreme.indiana.edu/namespaces/2005/06/workflow_tracking"
    xmlns="http://www.w3.org/2001/XMLSchema"
    attributeFormDefault="qualified"
    elementFormDefault="qualified">

    <!-- Workflow instance ID. for now, the  notification topic serves this purpose. -->
    <element name="workflowID" type="string" />
    <!-- distinct ID of a node within a WF graph. unique within the workflowID -->
    <element name="nodeID" type="string" /> 
    <!-- the timestep within workflow execution at which this invocation is made. -->
    <!-- timesteps is a monotonically increasing sequence within wf execution. -->
    <!-- Unique within the workflowID -->
    <element name="wfTimeStep" type="string" /> 
    <!-- ID to uniquely identify the service instance that is invoked. The Concrete WSDL QName -->
    <element name="serviceID" type="string" /> 

    <!-- the UUID for a file that appears in the notification. -->
    <!-- this UUID should be registered with the naming service and resolvable to a physical file. -->
    <element name="fileUUID" type="Name" /> 

    <!-- the timestamp of the activity. -->
    <element name="timestamp" type="dateTime" />

    <!-- general complex data types -->
    <complexType name="LEADMessageType">
	<attribute name="topic" type="string" use="required" />
    </complexType>

    <!-- general complex data types -->
    <complexType name="IDGroupType">
	<complexContent>
	    <extension base="lead:LEADMessageType">
		<sequence>
		    <element ref="lead:workflowID" />
		    <element ref="lead:nodeID" />
		    <element ref="lead:wfTimeStep" />
		    <element ref="lead:serviceID" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="IDGroupTimestampType">
	<complexContent>
	    <extension base="lead:IDGroupType">
		<sequence>
		    <element ref="lead:timestamp" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="IDGroupTimestampFileType">
      <complexContent>
        <extension base="lead:IDGroupTimestampType">
	    <group ref="lead:fileAttributeGroup" />
	</extension>
      </complexContent>
    </complexType>

    <complexType name="IDGroupTimestampFileSetType">
      <complexContent>
        <extension base="lead:IDGroupTimestampType">
	  <sequence>
	    <element name="file" type="lead:fileAttributeType" minOccurs="1" maxOccurs="unbounded" />
	  </sequence>
	</extension>
      </complexContent>
    </complexType>

    <complexType name="WFGroupTimestampType">
      <complexContent>
        <extension base="lead:LEADMessageType">
	  <sequence>
	    <element ref="lead:workflowID" />
     	    <element ref="lead:timestamp" />
	  </sequence>
	</extension>
      </complexContent>
    </complexType>

    <!-- general complex data types -->
    <group name="fileAttributeGroup">
	<sequence>
	    <element ref="lead:fileUUID" />
	    <element name="localFilePath" type="string" minOccurs="0" />
	    <element name="fileSizeBytes" type="long" minOccurs="0"/>
	</sequence>
    </group>

    <complexType name="fileAttributeType">
	<sequence>
	    <group ref="lead:fileAttributeGroup" />
     	    <element ref="lead:timestamp" />
	</sequence>
    </complexType>
	    
    <complexType name="nameValueSet">
        <sequence>
	    <element name="name" type="string" minOccurs="0" maxOccurs="unbounded" />
	    <element name="value" type="anyType" minOccurs="0" maxOccurs="unbounded" />
        </sequence>
    </complexType>


    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Notifications produced by the Jython Application Script -->
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- sent at the beginning of the jython app -->
    <element name="applicationStart">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="name" type="string" />
	      <element name="host" type="NCName" nillable="true"/>
	      <element name="applicationInput" type="lead:nameValueSet" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent at the end of the jython app if it is successful. -->
    <!-- for the jython wf, the results of the jython app to be passed to the next service -->
    <!-- are also returned as name-value pairs. this will not be required in the bpel version. -->
    <element name="applicationFinishSuccess">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="applicationResult" type="lead:nameValueSet" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>


    <!-- sent at the end of the jython app if it fails. -->
    <element name="applicationFinishFailed">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="errorMessage" type="string" />
	      <element name="stackTrace" type="string" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent at the end of a computational block in the jython app -->
    <!-- with the time in milliseconds taken for that computational block -->
    <element name="computationDuration">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="name" type="string" />
	      <element name="durationMillis" type="long" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent at the end of sending a file to remote location (thro' gridftp?) by the jython app -->
    <!-- with the time in milliseconds taken to send that file -->
    <!-- TODO: later add support for time for multiple files in asingle notification? -->
    <element name="fileSendDuration">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampFileType">
	    <sequence>
	      <element name="remoteFilePath" type="anyURI" />
	      <element name="durationMillis" type="long" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent at the end of receiving a file from remote location (thro' gridftp?) by the jython app -->
    <!-- with the time in milliseconds taken to send that file -->
    <!-- TODO: later add support for time for multiple files in asingle notification? -->
    <element name="fileReceiveDuration">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampFileType">
	    <sequence>
	      <element name="remoteFilePath" type="anyURI" />
	      <element name="durationMillis" type="long" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent when a file is used by the jython app. -->
    <element name="fileConsumed" type="lead:IDGroupTimestampFileSetType" />

    <!-- sent when a file is generated by the jython app. -->
    <element name="fileProduced" type="lead:IDGroupTimestampFileSetType" />

    <!-- sent when an interesting file is created by the jython app that can be viewed thro' a URL -->
    <!-- used to display as a link on the portal -->
    <element name="publishURL">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="title" type="string" minOccurs="0" />
	      <element name="location" type="anyURI" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- generic log message at different levels of importance that can be produced by the jython app -->
    <element name="log">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="message" type="string" />
	    </sequence>
            <attribute name="level" use="required" type="lead:logLevelType" />
	  </extension>
        </complexContent>
      </complexType>
    </element>
    <simpleType name="logLevelType">
      <restriction base="NCName">
        <enumeration value="INFO" /> <!-- highest -->
        <enumeration value="EXCEPTION" />
        <enumeration value="WARNING" />
        <enumeration value="DEBUG" /> <!-- lowest -->
      </restriction>
    </simpleType>

    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Notifications produced by the Jython Workflow Script -->
    <!-- ++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

    <!-- sent when the jython workflow starts  -->
    <element name="workflowStart">
      <complexType>
        <complexContent>
	  <extension base="lead:WFGroupTimestampType">
	    <sequence>
	      <element name="workflowInput" type="lead:nameValueSet" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent when the jython workflow finishes successfully -->
    <element name="workflowFinishSuccess">
      <complexType>
        <complexContent>
	  <extension base="lead:WFGroupTimestampType">
	    <sequence>
	      <element name="workflowResult" type="lead:nameValueSet" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent when the jython workflow finishes with a failure -->
    <element name="workflowFinishFailed">
      <complexType>
	<complexContent>
	  <extension base="lead:WFGroupTimestampType">
  	    <sequence>
	      <element name="errorMessage" type="string" />
	      <element name="stackTrace" type="string" minOccurs="0" />
	    </sequence>
	  </extension>
	</complexContent>
      </complexType>
    </element>

    <!-- sent when the jython workflow invokes a service  -->
    <element name="invokeServiceStart">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="invocationInput" type="lead:nameValueSet" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent when the jython workflow finishes successfully -->
    <element name="invokeServiceSuccess">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="invocationResult" type="lead:nameValueSet" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

    <!-- sent when the jython workflow fails when trying to or when invoking a service -->
    <element name="invokeServiceFailed">
      <complexType>
        <complexContent>
	  <extension base="lead:IDGroupTimestampType">
	    <sequence>
	      <element name="errorMessage" type="string" />
	      <element name="stackTrace" type="string" minOccurs="0" />
	    </sequence>
	  </extension>
        </complexContent>
      </complexType>
    </element>

</schema>
