<workflow-app name="download_ORCID_DUMP" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        <property>
            <name>targetPath</name>
            <description>the  path  to store the original ORCID dump</description>
        </property>
        <property>
            <name>apiURL</name>
            <description>The figshare  API URL to retrieve the list file to download</description>
        </property>
    </parameters>

    <start to="generateTables"/>

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

    <action name="DownloadDUMP">
        <java>
            <configuration>
                <property>
                    <name>oozie.launcher.mapreduce.user.classpath.first</name>
                    <value>true</value>
                </property>
            </configuration>
            <main-class>eu.dnetlib.dhp.collection.orcid.DownloadORCIDDumpApplication</main-class>
            <arg>--namenode</arg><arg>${nameNode}</arg>
            <arg>--targetPath</arg><arg>${targetPath}</arg>
            <arg>--apiURL</arg><arg>${apiURL}</arg>
        </java>
        <ok to="extractDump"/>
        <error to="Kill"/>
    </action>

    <action name="extractDump">
        <java>
            <configuration>
                <property>
                    <name>oozie.launcher.mapreduce.user.classpath.first</name>
                    <value>true</value>
                </property>
            </configuration>

            <main-class>eu.dnetlib.dhp.collection.orcid.ExtractORCIDDump</main-class>
            <java-opts> -Xmx6g </java-opts>
            <arg>--namenode</arg><arg>${nameNode}</arg>
            <arg>--sourcePath</arg><arg>${targetPath}</arg>
            <arg>--targetPath</arg><arg>${targetPath}/extracted</arg>
        </java>
        <ok to="generateTables"/>
        <error to="Kill"/>
    </action>

    <action name="generateTables">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>Generate ORCID Tables</name>
            <class>eu.dnetlib.dhp.collection.orcid.SparkGenerateORCIDTable</class>
            <jar>dhp-aggregation-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory=${sparkExecutorMemory}
                --executor-cores=${sparkExecutorCores}
                --driver-memory=${sparkDriverMemory}
                --conf spark.executor.memoryOverhead=2g
                --conf spark.sql.shuffle.partitions=3000
                --conf spark.extraListeners=${spark2ExtraListeners}
                --conf spark.sql.queryExecutionListeners=${spark2SqlQueryExecutionListeners}
                --conf spark.yarn.historyServer.address=${spark2YarnHistoryServerAddress}
                --conf spark.eventLog.dir=${nameNode}${spark2EventLogDir}
            </spark-opts>
            <arg>--sourcePath</arg><arg>${targetPath}/extracted</arg>
            <arg>--targetPath</arg><arg>${targetPath}/tables</arg>
            <arg>--master</arg><arg>yarn</arg>
        </spark>
        <ok to="End"/>
        <error to="Kill"/>
    </action>
    <end name="End"/>
</workflow-app>