<workflow-app name="Enrich_graph_with_ORCID_Workflow" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        <property>
            <name>orcidPath</name>
            <description>the path of the orcid Table generated by the dump</description>
        </property>
        <property>
            <name>graphPath</name>
            <description>the path of the graph we want to apply enrichment</description>
        </property>
        <property>
            <name>targetPath</name>
            <description>the output path of the graph enriched</description>
        </property>
    </parameters>

    <start to="EnrichGraph"/>

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

    <action name="EnrichGraph">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <master>yarn</master>
            <mode>cluster</mode>
            <name>Enrich Graph with ORCID</name>
            <class>eu.dnetlib.dhp.enrich.orcid.SparkEnrichGraphWithOrcidAuthors</class>
            <jar>dhp-graph-mapper-${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>--orcidPath</arg><arg>${orcidPath}</arg>
            <arg>--targetPath</arg><arg>${targetPath}</arg>
            <arg>--graphPath</arg><arg>${graphPath}</arg>
            <arg>--master</arg><arg>yarn</arg>
        </spark>
        <ok to="copy_datasource"/>
        <error to="Kill"/>
    </action>

    <action name="copy_datasource">
        <distcp xmlns="uri:oozie:distcp-action:0.2">
            <arg>${nameNode}/${graphPath}/datasource</arg>
            <arg>${nameNode}/${targetPath}/datasource</arg>
        </distcp>
        <ok to="copy_organization"/>
        <error to="Kill"/>
    </action>
    <action name="copy_organization">
        <distcp xmlns="uri:oozie:distcp-action:0.2">
            <arg>${nameNode}/${graphPath}/organization</arg>
            <arg>${nameNode}/${targetPath}/organization</arg>
        </distcp>
        <ok to="copy_project"/>
        <error to="Kill"/>
    </action>
    <action name="copy_project">
        <distcp xmlns="uri:oozie:distcp-action:0.2">
            <arg>${nameNode}/${graphPath}/project</arg>
            <arg>${nameNode}/${targetPath}/project</arg>
        </distcp>
        <ok to="copy_relation"/>
        <error to="Kill"/>
    </action>
    <action name="copy_relation">
        <distcp xmlns="uri:oozie:distcp-action:0.2">
            <arg>${nameNode}/${graphPath}/relation</arg>
            <arg>${nameNode}/${targetPath}/relation</arg>
        </distcp>
        <ok to="End"/>
        <error to="Kill"/>
    </action>
    <end name="End"/>

</workflow-app>