<workflow-app name="import Crossref from index into HDFS" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        <property>
            <name>workingPath</name>
            <description>the working dir base path</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>timestamp</name>
            <description>Timestamp for incremental Harvesting</description>
        </property>

    </parameters>

    <start to="ExtractCrossrefToOAF"/>


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

    <action name="ResetWorkingPath">
        <fs>
            <delete path='${workingPath}/input/crossref/index_dump'/>
<!--            <mkdir path='${workingPath}/input/crossref'/>-->
        </fs>
        <ok to="ImportCrossRef"/>
        <error to="Kill"/>
    </action>



    <action name="ImportCrossRef">
        <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>eu.dnetlib.doiboost.crossref.CrossrefImporter</main-class>
            <arg>-t</arg><arg>${workingPath}/input/crossref/index_dump_1</arg>
            <arg>-n</arg><arg>${nameNode}</arg>
            <arg>-ts</arg><arg>${timestamp}</arg>
        </java>
        <ok to="End"/>
        <error to="Kill"/>
    </action>


    <action name="ExtractCrossrefToOAF">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn-cluster</master>
            <mode>cluster</mode>
            <name>ExtractCrossrefToOAF</name>
            <class>eu.dnetlib.doiboost.crossref.SparkMapDumpIntoOAF</class>
            <jar>dhp-doiboost-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory=${sparkExecutorMemory}
                --executor-cores=${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                ${sparkExtraOPT}
            </spark-opts>
            <arg>--sourcePath</arg><arg>${workingPath}/input/crossref/index_dump,${workingPath}/input/crossref/index_dump_1,${workingPath}/crossref/index_dump</arg>
            <arg>--targetPath</arg><arg>${workingPath}/input/crossref</arg>
            <arg>--master</arg><arg>yarn-cluster</arg>
        </spark>
        <ok to="End"/>
        <error to="Kill"/>
    </action>



    <action name="GenerateDataset">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn-cluster</master>
            <mode>cluster</mode>
            <name>ExtractCrossrefToOAF</name>
            <class>eu.dnetlib.doiboost.crossref.CrossrefDataset</class>
            <jar>dhp-doiboost-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory=${sparkExecutorMemory}
                --executor-cores=${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                ${sparkExtraOPT}
            </spark-opts>
            <arg>--sourcePath</arg><arg>/data/doiboost/crossref/cr_dataset</arg>
            <arg>--targetPath</arg><arg>/data/doiboost/crossref/crossrefDataset</arg>
            <arg>--master</arg><arg>yarn-cluster</arg>
        </spark>
        <ok to="End"/>
        <error to="Kill"/>
    </action>

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