<workflow-app name="Create Raw Graph Step 2: Map XML to OAF Entities" xmlns="uri:oozie:workflow:0.5">
    <parameters>
        <property>
            <name>sourcePath</name>
            <description>the source path</description>
        </property>
        <property>
            <name>targetPath</name>
            <description>the source path</description>
        </property>
        <property>
            <name>targetDir</name>
            <description>the name of the  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>entities</name>
            <description>the entities to be extracted</description>
        </property>
    </parameters>

    <start to="DeleteTargetPath"/>

    <kill name="Kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <action name="DeleteTargetPath">
        <fs>
            <mkdir path="${targetPath}"/>  
            <mkdir path="${targetPath}/dataset"/>
            <mkdir path="${targetPath}/publication"/>
            <mkdir path="${targetPath}/unknown"/>
            <mkdir path="${targetPath}/relation"/>            
            <delete path='${targetPath}/dataset/${targetDir}'/>
            <delete path='${targetPath}/publication/${targetDir}'/>
            <delete path='${targetPath}/unknown/${targetDir}'/>
            <delete path='${targetPath}/relation/${targetDir}'/>
        </fs>
        <ok to="ExtractDLIEntities"/>
        <error to="Kill"/>
    </action>

    <action name="ExtractDLIEntities">
        <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>Extract ${entities}</name>
            <class>eu.dnetlib.dhp.sx.graph.SparkExtractEntitiesJob</class>
            <jar>dhp-graph-mapper-${projectVersion}.jar</jar>
            <spark-opts>
                --executor-memory ${sparkExecutorMemory}
                --driver-memory=${sparkDriverMemory}
                ${sparkExtraOPT}
            </spark-opts>
            <arg>-mt</arg> <arg>yarn-cluster</arg>
            <arg>--sourcePath</arg><arg>${sourcePath}</arg>
            <arg>--targetPath</arg><arg>${targetPath}</arg>
            <arg>--targetDir</arg><arg>${targetDir}</arg>
            <arg>--entities</arg><arg>${entities}</arg>
        </spark>
        <ok to="End"/>
        <error to="Kill"/>
    </action>

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