I am trying to configure an Apache Oozie workflow to execute different actions depending on the day of the week. After reading https://stackoverflow.com/questions/71422257/oozie-coordinator-get-day-of-the-week, I am trying to develop a solution on my own.
I started by compiling this simple java source code:
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;
public class DatetimeProcessor {
public static void main(String[] args) {
String inputDate = args.length > 0 ? args[0] : "";
String day = "";
try {
day = getDayOfWeek(inputDate);
} catch (Exception e) {
System.out.println("Invalid date format. Please enter a valid date in the format 'yyyy-MM-dd'T'HH:mm'Z'.");
}
System.out.println("dayOfWeek=" + day);
}
public static String getDayOfWeek(String date) {
LocalDateTime dateTime = LocalDateTime.parse(date, DateTimeFormatter.ISO_DATE_TIME);
DayOfWeek dayOfWeek = dateTime.atOffset(ZoneOffset.UTC).getDayOfWeek();
return dayOfWeek.toString().substring(0, 3);
}
}
After building the jar file, I wrote this Oozie coordinator:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<coordinator-app xmlns="uri:oozie:coordinator:0.5" name="mail-test" frequency="* * * * *" start="2024-11-11T00:00Z" end="2024-11-11T00:02Z" timezone="UTC">
<action>
<workflow>
<app-path>/user/my.user.name</app-path>
<configuration>
<property>
<name>nominalTime</name>
<value>${coord:nominalTime()}</value>
</property>
</configuration>
</workflow>
</action>
</coordinator-app>
However, when I launch the following workflow:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<workflow-app xmlns="uri:oozie:workflow:0.5" name="workflow-test">
<parameters>
<property>
<name>nominalTime</name>
</property>
</parameters>
<start to="process-date-action"/>
<action name="process-date-action">
<java>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<main-class>DatetimeProcessor</main-class>
<arg>${nominalTime}</arg>
<file>${wf:appPath()}/DatetimeProcessor.jar</file>
<capture-output/>
</java>
<ok to="mail-action"/>
<error to="fail"/>
</action>
<action name="mail-action">
<email xmlns="uri:oozie:email-action:0.2">
<to>[email protected]</to>
<subject>Mail Test</subject>
<body>
Workflow id: ${wf:id()}
Workflow usr: ${wf:user()}
Timestamp: ${timestamp()}
Coordinator nominalTime: ${nominalTime}
Coordinator Day of the Week: ${wf:actionData("process-date-action")["dayOfWeek"]}
</body>
</email>
<ok to="end"/>
<error to="fail"/>
</action>
<kill name="fail">
<message>Workflow failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>
I do not see any output on the final e-mail after "Coordinator Day of the Week:". Did I badly use the capture output tag? Thank you in advance.