<workflow-app name="import regular entities as Graph (step 3)" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        
        <property>
            <name>migrationPathStep2</name>
            <description>the temporary path to store entities before dispatching</description>
        </property>
        <property>
            <name>migrationPathStep3</name>
            <description>the graph Raw 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>
    </parameters>

	<start to="ResetGraph"/>

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

    <action name="ResetGraph">
        <fs>
            <delete path='${migrationPathStep3}'/>
            <mkdir path='${migrationPathStep3}'/>
        </fs>
        <ok to="GenerateGraph"/>
        <error to="Kill"/>
    </action>

    <action name="GenerateGraph">
        <spark xmlns="uri:oozie:spark-action:0.2">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <master>yarn-cluster</master>
            <mode>cluster</mode>
            <name>GenerateGraph</name>
            <class>eu.dnetlib.dhp.migration.step3.DispatchEntitiesApplication</class>
            <jar>dhp-aggregation-${projectVersion}.jar</jar>
            <spark-opts>--executor-memory ${sparkExecutorMemory} --executor-cores ${sparkExecutorCores} --driver-memory=${sparkDriverMemory} --conf spark.extraListeners="com.cloudera.spark.lineage.NavigatorAppListener" --conf spark.sql.queryExecutionListeners="com.cloudera.spark.lineage.NavigatorQueryListener" --conf spark.sql.warehouse.dir="/user/hive/warehouse"</spark-opts>
            <arg>-mt</arg> <arg>yarn-cluster</arg>
            <arg>-s</arg><arg>${migrationPathStep2}/all_entities</arg>
            <arg>-g</arg><arg>${migrationPathStep3}</arg>
        </spark>
        <ok to="End"/>
        <error to="Kill"/>
    </action>  

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