<?xml version='1.0' encoding='utf-8' ?>
<schema
    targetNamespace="http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking"
    xmlns:wft="http://lead.extreme.indiana.edu/namespaces/2006/06/workflow_tracking"
    xmlns="http://www.w3.org/2001/XMLSchema"
    attributeFormDefault="qualified"
    elementFormDefault="qualified">

    <!-- ========================================================================================== -->
    <!-- Authors:                                                                                   -->
    <!--   Yogesh L. Simmhan*                                                                       -->
    <!--   Alek Slominski                                                                           -->
    <!--   Marcus Christie                                                                          -->
    <!--   Scott Jensen                                                                             -->
    <!--                                                                                            -->
    <!--   Version: 2.1                                                                             -->
    <!--   Date: 2006-08-15                                                                         -->
    <!--                                                                                            -->
    <!--   Copyright (c) 2006 Extreme! Lab, Indiana University. All rights reserved.                -->
    <!--   This software is open source. See http://extreme.indiana.edu/license.txt for license.    -->
    <!-- ========================================================================================== -->


    <!-- ========================================================================================== -->

    <annotation>
	<documentation>
	    *) Workflows and services can be abstract (template) or concrete (instance).
	       Unless otherwise noted, we always refer to the concrete instance of the workflow/service below
	    *) All workflows are also services.
	    *) Services may be part of zero or more workflows
	    *) When Services execute in the context of a workflow,
	       an invocation of the service is associated with the workflowID of the workflow whose context
	       in which it is being invoked (also called parent workflow), 
	       the timestep of this invocation in the parent workflow,
	       and the node ID that uniquely identifies this service within the parent workflow instance.
	    *) Workflows can also be invoked in the context of another parent workflow.
	    *) Workflow ID always refers to the "parent workflow ID". When refering to the invocation of a workflow,
	       its instance ID is called the Service ID.
	    *) Workflows that are not invoked from another workflow do not have a context of execution 
	       (parent workflow is not present => Workflow ID is NULL)
	    *) Schema design notes
	       - This schema uses the "Venetian Blind" schema design pattern
	       - It uses Upper Camel Case for schema types and lower camel case for
	         element and attribute names
	</documentation>
    </annotation>

    <simpleType name="ServiceIDType">
	<annotation>
	    <documentation>
		ID to uniquely identify the service instance.
		This is usually formed from the targetnamespace and porttype name of the service's WSDL.
		This ID may refer to the instance ID for a service or for a workflow.
	    </documentation>
	</annotation>
	<restriction base="anyURI"/>
    </simpleType>
    
    <simpleType name="WorkflowNodeIDType">
	<annotation>
	    <documentation>
		String that identifies uniquely a node in workflow graph. 
		The node ID is unique in the scope of a workflow ID.
	    </documentation>
	</annotation>
	<restriction base="string"/>
    </simpleType>
    
    <simpleType name="WorkflowTimestepType">
	<annotation>
	    <documentation>
		The timestep within workflow execution at which this invocation is made. 
		This is a logical time that monotonically increments for each invocation in a workflow.
	    </documentation>
	</annotation>
	<restriction base="int"/>
    </simpleType>
    
    <simpleType name="DataProductIDType">
	<annotation>
	    <documentation>
		Unique logical ID for a data product in the form of a UUID.
		Physical URL for the data products can be resolved using this ID.
	    </documentation>
	</annotation>
	<restriction base="anyURI"/>
    </simpleType>
    
    <!-- ========================================================================================== -->

    <complexType name="BaseIDType">
	<attribute name="workflowID" type="wft:ServiceIDType" use="optional">
	    <annotation>
		<documentation>
		    The workflow context within which this service is executing.
		    If this service is itself a workflow and not executing as part of another workflow
		    (i.e. this is the root of the invocation trace) then the workflow ID is absent.
		    Otherwise, this is the service ID of the workflow instance.
		</documentation>
	    </annotation>
	</attribute>
	
	<attribute name="serviceID" type="wft:ServiceIDType" use="required">
	    <annotation>
		<documentation>
		    ID to uniquely identify a service instance. The service instance can
		    be part of zero or more workflow.
		    This is formed from the targetnamespace of the service's CWSDL.
		</documentation>
	    </annotation>
	</attribute>
	
	<attribute name="workflowNodeID" type="wft:WorkflowNodeIDType" use="optional">
	    <annotation>
		<documentation>
		    Distinct ID of a node within a Workflow graph. unique within the workflowID,
		    not necessarily the order of execution.
		</documentation>
	    </annotation>
	</attribute>
	
	<attribute name="workflowTimestep" type="wft:WorkflowTimestepType" use="optional">
	    <annotation>
		<documentation>
		    The timestep within workflow execution at which this invocation is made.
		    32bit integer. Timestep is a numerically ordered monotonically increasing sequence
		    within wf execution that allows relative ordering of invocations.
		    It is unique within the workflowID for each invocation in the workflow.
		</documentation>
	    </annotation>
	</attribute>
    </complexType>
    
    <!-- base type for all notifications -->
    <complexType name="BaseNotificationType">
	<annotation>
	    <documentation>This is the base type for all notification activities that are produced</documentation>
	</annotation>
	<sequence>
	    
	    <element name="notificationSource" type="wft:BaseIDType">
		<annotation>
		    <documentation>
			This identifies the entity/invocation context from which this notifcation is being sent.
		    </documentation>
		</annotation>
	    </element>

	    <element name="timestamp" type="dateTime" />

	    <element name="description" type="string" minOccurs="0">
		<annotation>
		    <documentation>Optional human friendly description of this notification.</documentation>
		</annotation>
	    </element>

	    <element name="annotation" type="anyType" minOccurs="0">
		<annotation>
		    <documentation>Optional additional metadata for this notification. See common.AnnotationConsts file.</documentation>
		</annotation>
	    </element>

	</sequence>

	<attribute name="infoModelVersion" 
		   form="unqualified" 
		   type="NMTOKEN" 
		   use="required"> 
	    <!-- we set form as unqualified to allow WS-Messenger YFilter to match it -->
	    <!-- NMToken := (Letter | Digit  | '.' | '-' | '_' | ':')+ -->
	    <annotation>
		<documentation>
		    String identifying notification schema version (used for verifying compatible schema and filtering).
		</documentation>
	    </annotation>
	</attribute>

    </complexType>


    <complexType name="MessageType">
	<sequence>
	    <element name="header" type="anyType" minOccurs="0" /> <!-- e.g. soap:header -->
	    <element name="body" type="anyType" minOccurs="0" /> <!-- e.g. soap:body --> <!-- fixme: change to message -->
	</sequence>
    </complexType>

    <complexType name="FaultMessageType">
	<complexContent>
	    <extension base="wft:MessageType" />
	</complexContent>
    </complexType>

    <complexType name="InvocationMessageType">
	<complexContent>
	    <extension base="wft:MessageType" />
	</complexContent>
    </complexType>


    <complexType name="FailureMessageType">
	<sequence>
	    <element name="trace" type="anyType" minOccurs="0" maxOccurs="unbounded" />
	</sequence>
    </complexType>


    <!-- ========================================================================================== -->
    <!--                           workflow provenance types                                        -->
    <!-- ========================================================================================== -->

    <!-- sent when the service is first created and is ready to accept invocations -->
    <element name="serviceInitialized" type="wft:BaseNotificationType" />

    <!-- sent when the service is terminated and will not accept any further invocations -->
    <element name="serviceTerminated" type="wft:BaseNotificationType" />

    <!-- sent when the workflow is first created and is ready to accept invocations -->
    <!--element name="workflowInitialized" type="wft:BaseNotificationType"-->
    <element name="workflowInitialized">
	<complexType>
	    <complexContent>
		<extension base="wft:BaseNotificationType">
		    <sequence>
			<element name="initialPriority" type="string" minOccurs="0" />
			<element name="workflowTemplateId" type="wft:ServiceIDType" minOccurs="0" />
			<element name="workflowCreatorDn" type="string" minOccurs="0" />
		    </sequence>
		</extension>
	    </complexContent>
	</complexType>
    </element>

    <!-- sent when the workflow is terminated and will not accept any further invocations -->
    <element name="workflowTerminated" type="wft:BaseNotificationType" />

    <!-- sent when the workflow execution is paused: invocations will be accepted but no new messages will be sent by the workflow -->
    <element name="workflowPaused" type="wft:BaseNotificationType" />

    <!-- sent when the workflow execution is resumed -->
    <element name="workflowResumed" type="wft:BaseNotificationType" />

    <!-- workflow priority tracking -->
    <element name="workflowPriorityChanged">
	<complexType>
	    <complexContent>
		<extension base="wft:BaseNotificationType">
		    <sequence>
			<element name="newPriority" type="string" />
			<element name="oldPriority" type="string" />
		    </sequence>
		</extension>
	    </complexContent>
	</complexType>
    </element>

    <!-- ========================================================================================== -->

    <complexType name="InvocationRequestType" abstract="true">
        <complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="request" type="wft:InvocationMessageType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="RequestInitiatorType">
        <complexContent>
	    <extension base="wft:InvocationRequestType">
		<sequence>
		    <!-- used by wf (client) to set service info, when invoking service -->
		    <element name="receiver" type="wft:BaseIDType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="RequestReceiverType">
        <complexContent>
	    <extension base="wft:InvocationRequestType">
		<sequence>
		    <!-- used by service to set workflow(client) info, when invoked by workflow (client) -->
		    <element name="initiator" type="wft:BaseIDType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>


    <!-- ========================================================================================== -->

    <complexType name="AcknowledgementType" abstract="true">
	<complexContent>
	    <extension base="wft:BaseNotificationType" >
		<sequence>
		    <element name="receiver" type="wft:BaseIDType" minOccurs="0" /> <!-- target of the action that succeeded -->
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="AcknowledgeSuccessType">
	<complexContent>
	    <extension base="wft:AcknowledgementType" />
	</complexContent>
    </complexType>

    <complexType name="AcknowledgeFailureType">
        <complexContent>
	    <extension base="wft:AcknowledgementType">
		<sequence>
		    <element name="failure" type="wft:FailureMessageType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <!-- ========================================================================================== -->

    <!-- sent by workflow when a service is invoked by it. -->
    <element name="invokingService" type="wft:RequestInitiatorType" />


    <!-- sent by workflow when it is invoked. -->
    <element name="workflowInvoked" type="wft:RequestReceiverType" />

    <!-- sent by service when it is invoked. -->
    <element name="serviceInvoked" type="wft:RequestReceiverType" />


    <!-- sent by workflow when it invoked a service successfully. -->
    <element name="invokingServiceSucceeded" type="wft:AcknowledgeSuccessType" />

    <!-- sent by workflow when it failed to invoke a service successfully. -->
    <element name="invokingServiceFailed" type="wft:AcknowledgeFailureType" />


    <!-- ========================================================================================== -->

    <complexType name="InvocationResultType" abstract="true">
        <complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="result" type="wft:InvocationMessageType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="InvocationFaultType" abstract="true">
        <complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="fault" type="wft:FaultMessageType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="ResultReceiverType">
        <complexContent>
	    <extension base="wft:InvocationResultType">
		<sequence>
		    <!-- used by wf (client) to set service info, when receiving result from service -->
		    <element name="responder" type="wft:BaseIDType" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="FaultReceiverType">
        <complexContent>
	    <extension base="wft:InvocationFaultType">
		<sequence>
		    <!-- used by wf (client) to set service info, when receiving result from service -->
		    <element name="responder" type="wft:BaseIDType" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="ResultResponderType">
        <complexContent>
	    <extension base="wft:InvocationResultType">
		<sequence>
		    <!-- used by service to set workflow(client) info, when returning result to workflow (client) -->
		    <element name="receiver" type="wft:BaseIDType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="FaultResponderType">
        <complexContent>
	    <extension base="wft:InvocationFaultType">
		<sequence>
		    <!-- used by service to set workflow(client) info, when returning result to workflow (client) -->
		    <element name="receiver" type="wft:BaseIDType" minOccurs="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <!-- ========================================================================================== -->

    <!-- sent by service when it returns the result for an invocation. -->
    <element name="sendingResult" type="wft:ResultResponderType" /> <!-- add workflowSendingResult -->

    <!-- sent by service when it returns a fault for an invocation. -->
    <element name="sendingFault" type="wft:FaultResponderType" /> <!-- add workflowSendingFault -->


    <!-- sent by workflow when it receives the result for an invocation. -->
    <element name="receivedResult" type="wft:ResultReceiverType" /> <!-- add workflowReceivedResult -->

    <!-- sent by workflow when it receives a fault for an invocation. -->
    <element name="receivedFault" type="wft:FaultReceiverType" /> <!-- add workflowFaultResult -->


    <!-- sent by service when it has successfully sent the result for an invocation. -->
    <element name="sendingResponseSucceeded" type="wft:AcknowledgeSuccessType" />

    <!-- sent by service when it has successfully sent a fault for an invocation. -->
    <element name="sendingResponseFailed" type="wft:AcknowledgeFailureType" />

    <!-- ========================================================================================== -->


    <!-- ========================================================================================== -->
    <!--                            data provenance types                                           -->
    <!-- ========================================================================================== -->

    <!-- general complex data types -->
    <complexType name="DataProductType">
	<sequence>
	    <element name="id" type="wft:DataProductIDType" />
	    <element name="location" type="anyURI" minOccurs="0" maxOccurs="unbounded" />
	    <element name="sizeInBytes" type="long" minOccurs="0" />
	    <element name="timestamp" type="dateTime" minOccurs="0" /> <!-- context sensitive. time at which data product was produced or consumed. -->
	    <element name="description" type="string" minOccurs="0">
		<annotation>
		    <documentation>Optional human friendly description of this data product.</documentation>
		</annotation>
	    </element>
	    <element name="annotation" type="anyType" minOccurs="0">
		<annotation>
		    <documentation>Optional additional metadata for this data product.</documentation>
		</annotation>
	    </element>
	</sequence>
    </complexType>

    <complexType name="DataProductNotificationType">
	<complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="dataProduct" type="wft:DataProductType" minOccurs="0" maxOccurs="unbounded" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <!-- sent when a file is used by the jython app. -->
    <element name="dataConsumed" type="wft:DataProductNotificationType" />

    <!-- sent when a file is generated by the jython app. -->
    <element name="dataProduced" type="wft:DataProductNotificationType" />


    <!-- ========================================================================================== -->
    <!--                                   performance audit types                                  -->
    <!-- ========================================================================================== -->


    <!--  sent when the application launches a GRAM job, to facilitate -->
    <!--  auditing and accounting of TeraGrid jobs -->
    <!-- SJ The type name needed Type added at the end -->
    <complexType name="ApplicationAuditType">
	<complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="name" type="string" />
		    <element name="jobHandle" type="anyURI"/>
		    <element name="host" type="string" />
		    <element name="queueName" type="string" minOccurs="0"/>
		    <element name="jobId" type="string" minOccurs="0"/>
		    <element name="distinguishedName" type="string" />
		    <element name="projectId" type="string" minOccurs="0"/>
		    <element name="rsl" type="string"/>
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <element name="applicationAudit" type="wft:ApplicationAuditType" />


    <!-- 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="wft:BaseNotificationType">
		    <sequence>
			<element name="durationInMillis" 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 a single notification? -->
    <complexType name="DataTransferDurationType">
	<complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="id" type="wft:DataProductIDType" />
		    <element name="source" type="anyURI" />
		    <element name="target" type="anyURI" />
		    <element name="sizeInBytes" type="long" minOccurs="0" default="-1" />
		    <element name="durationInMillis" type="long" default="-1" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <element name="dataSendDuration" type="wft:DataTransferDurationType" />
    <element name="dataReceiveDuration" type="wft:DataTransferDurationType" />

    <!-- ========================================================================================== -->
    <!--                               generic log message types                                    -->
    <!-- ========================================================================================== -->


    <!-- 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="wft:BaseNotificationType">
		    <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="logInfo" type="wft:BaseNotificationType" />
    <element name="logException" type="wft:BaseNotificationType" />
    <element name="logWarning" type="wft:BaseNotificationType" />
    <element name="logDebug" type="wft:BaseNotificationType" />


    <!-- ========================================================================================== -->
    <!--                              resource broker message types                                 -->
    <!-- ========================================================================================== -->

    <complexType name="ResourceMappingType">
	<complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="mappedResource" type="string" />
		    <element name="retryStatusCount" type="int" default="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <complexType name="JobStatusType">
	<complexContent>
	    <extension base="wft:BaseNotificationType">
		<sequence>
		    <element name="jobStatus" type="string" />
		    <element name="retryCount" type="int" default="0" />
		</sequence>
	    </extension>
	</complexContent>
    </complexType>

    <element name="resourceMapping" type="wft:ResourceMappingType" />
    <element name="jobStatus" type="wft:JobStatusType" />

</schema>