<workflow-app name="import regular entities as Graph (step 2)" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        <property>
            <name>migrationPathStep1</name>
            <description>the base path to store hdfs file</description>
        </property>
        <property>
            <name>migrationPathStep2</name>
            <description>the temporary path to store entities before dispatching</description>
        </property>
        <property>
            <name>isLookupUrl</name>
            <description>the address of the lookUp service</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="ResetEntities"/>

    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    
	<action name="ResetEntities">
        <fs>
            <delete path='${migrationPathStep2}'/>
            <mkdir path='${migrationPathStep2}'/>
        </fs>
        <ok to="GenerateEntities"/>
        <error to="Kill"/>
    </action>

    <action name="GenerateEntities">
        <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>GenerateEntities</name>
            <class>eu.dnetlib.dhp.migration.step2.GenerateEntitiesApplication</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>${migrationPathStep1}/db_records,${migrationPathStep1}/oaf_records,${migrationPathStep1}/odf_records</arg>
            <arg>-t</arg><arg>${migrationPathStep2}/all_entities</arg>
            <arg>--islookup</arg><arg>${isLookupUrl}</arg>
        </spark>
        <ok to="End"/>
        <error to="Kill"/>
    </action>

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