<workflow-app name="promote_actionsets_for_graph" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        <property>
            <name>activePromoteDatasetActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Dataset payload</description>
        </property>
        <property>
            <name>activePromoteDatasourceActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Datasource payload</description>
        </property>
        <property>
            <name>activePromoteOrganizationActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Organization payload</description>
        </property>
        <property>
            <name>activePromoteOtherResearchProductActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.OtherResearchProduct payload</description>
        </property>
        <property>
            <name>activePromoteProjectActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Project payload</description>
        </property>
        <property>
            <name>activePromotePublicationActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Publication payload</description>
        </property>
        <property>
            <name>activePromoteRelationActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Relation payload</description>
        </property>
        <property>
            <name>activePromoteResultActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Result payload</description>
        </property>
        <property>
            <name>activePromoteSoftwareActionPayload</name>
            <description>when true will promote actions with eu.dnetlib.dhp.schema.oaf.Software payload</description>
        </property>
        <property>
            <name>inputGraphRootPath</name>
            <description>root location of input materialized graph</description>
        </property>
        <property>
            <name>isLookupUrl</name>
            <description>URL of the ISLookupService</description>
        </property>
        <property>
            <name>inputActionSetIds</name>
            <description>comma separated list of action set ids to promote</description>
        </property>
        <property>
            <name>outputGraphRootPath</name>
            <description>root location for output materialized graph</description>
        </property>
        <property>
            <name>mergeAndGetStrategy</name>
            <description>strategy for merging graph table objects with action payload instances, MERGE_FROM_AND_GET or SELECT_NEWER_AND_GET</description>
        </property>
        <property>
            <name>shouldGroupById</name>
            <value>false</value>
            <description>indicates whether the promotion operation should group objects in the graph by id or not</description>
        </property>
        <property>
            <name>sparkDriverMemory</name>
            <description>memory for driver process</description>
        </property>
        <property>
            <name>sparkExecutorMemory</name>
            <description>memory for individual executor</description>
        </property>
        <property>
            <name>sparkExecutorCores</name>
            <description>number of cores used by single executor</description>
        </property>
        <property>
            <name>oozieActionShareLibForSpark2</name>
            <description>oozie action sharelib for spark 2.*</description>
        </property>
        <property>
            <name>spark2ExtraListeners</name>
            <value>com.cloudera.spark.lineage.NavigatorAppListener</value>
            <description>spark 2.* extra listeners classname</description>
        </property>
        <property>
            <name>spark2SqlQueryExecutionListeners</name>
            <value>com.cloudera.spark.lineage.NavigatorQueryListener</value>
            <description>spark 2.* sql query execution listeners classname</description>
        </property>
        <property>
            <name>spark2YarnHistoryServerAddress</name>
            <description>spark 2.* yarn history server address</description>
        </property>
        <property>
            <name>spark2EventLogDir</name>
            <description>spark 2.* event log dir location</description>
        </property>
    </parameters>

    <global>
        <job-tracker>${jobTracker}</job-tracker>
        <name-node>${nameNode}</name-node>
        <configuration>
            <property>
                <name>oozie.action.sharelib.for.spark</name>
                <value>${oozieActionShareLibForSpark2}</value>
            </property>
        </configuration>
    </global>

    <start to="PartitionActionSetsByPayloadType"/>

    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>

    <action name="PartitionActionSetsByPayloadType">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn-cluster</master>
            <mode>cluster</mode>
            <name>PartitionActionSetsByPayloadType</name>
            <class>eu.dnetlib.dhp.actionmanager.partition.PartitionActionSetsByPayloadTypeJob</class>
            <jar>dhp-actionmanager-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory=${sparkExecutorMemory}
                --executor-cores=${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--inputActionSetIds</arg><arg>${inputActionSetIds}</arg>
            <arg>--outputPath</arg><arg>${workingDir}/action_payload_by_type</arg>
            <arg>--isLookupUrl</arg><arg>${isLookupUrl}</arg>
        </spark>
        <ok to="ForkPromote"/>
        <error to="Kill"/>
    </action>

    <fork name="ForkPromote">
        <path start="PromoteActionPayloadForDatasetTable"/>
        <path start="PromoteActionPayloadForDatasourceTable"/>
        <path start="PromoteActionPayloadForOrganizationTable"/>
        <path start="PromoteActionPayloadForOtherResearchProductTable"/>
        <path start="PromoteActionPayloadForProjectTable"/>
        <path start="PromoteActionPayloadForPublicationTable"/>
        <path start="PromoteActionPayloadForRelationTable"/>
        <path start="PromoteActionPayloadForSoftwareTable"/>
    </fork>

    <action name="PromoteActionPayloadForDatasetTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_dataset_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <action name="PromoteActionPayloadForDatasourceTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_datasource_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <action name="PromoteActionPayloadForOrganizationTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_organization_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <action name="PromoteActionPayloadForOtherResearchProductTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_otherresearchproduct_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <action name="PromoteActionPayloadForProjectTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_project_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <action name="PromoteActionPayloadForPublicationTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_publication_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <action name="PromoteActionPayloadForRelationTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_relation_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <action name="PromoteActionPayloadForSoftwareTable">
        <sub-workflow>
            <app-path>${wf:appPath()}/promote_action_payload_for_software_table</app-path>
            <propagate-configuration/>
            <configuration>
                <property>
                    <name>inputActionPayloadRootPath</name>
                    <value>${workingDir}/action_payload_by_type</value>
                </property>
            </configuration>
        </sub-workflow>
        <ok to="JoinPromote"/>
        <error to="Kill"/>
    </action>

    <join name="JoinPromote" to="End"/>

    <end name="End"/>
</workflow-app>