use of org.apache.oozie.client.CoordinatorAction in project oozie by apache.
the class TestCoordinatorEngineStreamLog method testCoordLogStreaming.
public void testCoordLogStreaming() throws Exception {
services.setService(DummyXLogStreamingService.class);
new DagXLogInfoService().init(services);
CoordinatorEngine ce = createCoordinatorEngine();
final String jobId = createJobs(6);
CoordinatorJobBean cjb = ce.getCoordJob(jobId);
Date createdDate = cjb.getCreatedTime();
Date endDate = cjb.getEndTime();
assertTrue(endDate.after(createdDate));
List<CoordinatorAction> list = cjb.getActions();
Collections.sort(list, new Comparator<CoordinatorAction>() {
public int compare(CoordinatorAction a, CoordinatorAction b) {
return a.getId().compareTo(b.getId());
}
});
// Test 1.to test if fields are injected
ce.streamLog(jobId, new StringWriter(), new HashMap<String, String[]>());
DummyXLogStreamingService service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
XLogFilter filter = service.filter;
assertEquals(filter.getFilterParams().get(DagXLogInfoService.JOB), jobId);
assertEquals(cjb.getCreatedTime(), service.startTime);
assertEquals(cjb.getLastModifiedTime(), service.endTime);
// Test2
// * Test method org.apache.oozie.CoordinatorEngine.streamLog(String,
// String,
// * String, Writer) with null 2nd and 3rd arguments.
// */
ce.streamLog(jobId, null, null, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
filter = service.filter;
assertEquals(filter.getFilterParams().get(DagXLogInfoService.JOB), jobId);
// Test 3
// * Test method org.apache.oozie.CoordinatorEngine.streamLog(String,
// String,
// * String, Writer) with RestConstants.JOB_LOG_ACTION and non-null 2nd
// * argument.
ce.streamLog(jobId, "1, 3-4, 6", RestConstants.JOB_LOG_ACTION, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
filter = service.filter;
assertEquals(jobId, filter.getFilterParams().get(DagXLogInfoService.JOB));
assertEquals("(" + jobId + "@1|" + jobId + "@3|" + jobId + "@4|" + jobId + "@6)", filter.getFilterParams().get(DagXLogInfoService.ACTION));
// Test 4. testing with date range
long middle = (createdDate.getTime() + endDate.getTime()) / 2;
Date middleDate = new Date(middle);
ce.streamLog(jobId, DateUtils.formatDateOozieTZ(createdDate) + "::" + DateUtils.formatDateOozieTZ(middleDate) + "," + DateUtils.formatDateOozieTZ(middleDate) + "::" + DateUtils.formatDateOozieTZ(endDate), RestConstants.JOB_LOG_DATE, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
filter = service.filter;
assertEquals(jobId, filter.getFilterParams().get(DagXLogInfoService.JOB));
final String action = filter.getFilterParams().get(DagXLogInfoService.ACTION);
assertEquals("(" + jobId + "@1|" + jobId + "@2|" + jobId + "@3|" + jobId + "@4|" + jobId + "@5|" + jobId + "@6)", action);
// Test 5 testing with action list range
ce.streamLog(jobId, "2-4", RestConstants.JOB_LOG_ACTION, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
assertEquals(list.get(1).getCreatedTime(), service.startTime);
assertEquals(list.get(3).getLastModifiedTime(), service.endTime);
// Test 6, testing with 1 action list
ce.streamLog(jobId, "5", RestConstants.JOB_LOG_ACTION, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
assertEquals(list.get(4).getCreatedTime(), service.startTime);
assertEquals(list.get(4).getLastModifiedTime(), service.endTime);
// Test 7, testing with 1 action list + range
ce.streamLog(jobId, "1,2-4,5", RestConstants.JOB_LOG_ACTION, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
assertEquals(list.get(0).getCreatedTime(), service.startTime);
assertEquals(list.get(4).getLastModifiedTime(), service.endTime);
// Test 8, testing with out order range
ce.streamLog(jobId, "5,3-4,1", RestConstants.JOB_LOG_ACTION, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
assertEquals(list.get(0).getCreatedTime(), service.startTime);
assertEquals(list.get(4).getLastModifiedTime(), service.endTime);
// Test 9, testing with date range
ce.streamLog(jobId, DateUtils.formatDateOozieTZ(list.get(1).getCreatedTime()) + "::" + DateUtils.formatDateOozieTZ(list.get(4).getLastModifiedTime()) + ",", RestConstants.JOB_LOG_DATE, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
assertEquals(list.get(1).getCreatedTime().toString(), service.startTime.toString());
assertEquals(list.get(4).getLastModifiedTime().toString(), service.endTime.toString());
// Test 10, testing with multiple date range
ce.streamLog(jobId, DateUtils.formatDateOozieTZ(list.get(1).getCreatedTime()) + "::" + DateUtils.formatDateOozieTZ(list.get(2).getLastModifiedTime()) + "," + DateUtils.formatDateOozieTZ(list.get(3).getCreatedTime()) + "::" + DateUtils.formatDateOozieTZ(list.get(5).getLastModifiedTime()), RestConstants.JOB_LOG_DATE, new StringWriter(), new HashMap<String, String[]>());
service = (DummyXLogStreamingService) services.get(XLogStreamingService.class);
assertEquals(list.get(1).getCreatedTime().toString(), service.startTime.toString());
assertEquals(list.get(5).getLastModifiedTime().toString(), service.endTime.toString());
// Test 11, testing -scope option with Max Count
Services.get().getConf().setInt(CoordinatorEngine.COORD_ACTIONS_LOG_MAX_COUNT, 1);
ce = createCoordinatorEngine();
try {
ce.streamLog(jobId, "1-3", RestConstants.JOB_LOG_ACTION, new StringWriter(), new HashMap<String, String[]>());
} catch (XException e) {
assertEquals(e.getErrorCode(), ErrorCode.E0302);
assertTrue(e.getMessage().indexOf("Retrieving log of too many coordinator actions") != -1);
}
// Test 12, testing -date option with Max Count
try {
ce.streamLog(jobId, DateUtils.formatDateOozieTZ(createdDate) + "::" + DateUtils.formatDateOozieTZ(endDate), RestConstants.JOB_LOG_DATE, new StringWriter(), new HashMap<String, String[]>());
} catch (XException e) {
assertEquals(e.getErrorCode(), ErrorCode.E0302);
assertTrue(e.getMessage().indexOf("Retrieving log of too many coordinator actions") != -1);
}
}
use of org.apache.oozie.client.CoordinatorAction in project oozie by apache.
the class AppInfoCollector method persistCoordinatorJobInfo.
private void persistCoordinatorJobInfo(int maxChildActions, final CoordinatorJob job, final DiagBundleEntryWriter bundleEntryWriter) throws IOException {
bundleEntryWriter.writeString("COORDINATOR\n").writeString("-----------\n").writeStringValue("Coordinator Id : ", job.getId()).writeStringValue("Name : ", job.getAppName()).writeStringValue("App Path : ", job.getAppPath()).writeStringValue("User : ", job.getUser()).writeStringValue("ACL : ", job.getAcl()).writeStringValue("Status : ", job.getStatus().toString()).writeStringValue("Console URL : ", job.getConsoleUrl()).writeStringValue("External Id : ", job.getExternalId()).writeStringValue("Bundle Id : ", job.getBundleId()).writeStringValue("Frequency : ", job.getFrequency()).writeStringValue("Time Unit : ", job.getTimeUnit().toString()).writeDateValue("Start Time : ", job.getStartTime()).writeDateValue("End Time : ", job.getEndTime()).writeDateValue("Last Action Time : ", job.getLastActionTime()).writeDateValue("Next Materialized Time : ", job.getNextMaterializedTime()).writeDateValue("Pause Time : ", job.getPauseTime()).writeStringValue("Timezone : ", job.getTimeZone()).writeIntValue("Concurrency : ", job.getConcurrency()).writeIntValue("Timeout : ", job.getTimeout()).writeStringValue("Execution Order : ", job.getExecutionOrder().toString()).writeIntValue("Action Count : ", job.getActions().size()).writeNewLine().writeString("ACTIONS\n").writeString("------\n").flush();
final List<CoordinatorAction> coordinatorActions = job.getActions();
for (int i = 0; i < maxChildActions && i != coordinatorActions.size(); ++i) {
final CoordinatorAction action = coordinatorActions.get(i);
bundleEntryWriter.writeStringValue("Action Id : ", action.getId()).writeIntValue("Action Number : ", action.getActionNumber()).writeStringValue("Job Id : ", action.getJobId()).writeStringValue("Status : ", action.getStatus().toString()).writeStringValue("External Id : ", action.getExternalId()).writeStringValue("External Status : ", action.getExternalStatus()).writeStringValue("Console URL : ", action.getConsoleUrl()).writeStringValue("Tracker URI : ", action.getTrackerUri()).writeDateValue("Created Time : ", action.getCreatedTime()).writeDateValue("Nominal Time : ", action.getNominalTime()).writeDateValue("Last Modified Time : ", action.getLastModifiedTime()).writeStringValue("Error Code : ", action.getErrorCode()).writeStringValue("Error Message : ", action.getErrorMessage()).writeStringValue("Missing Dependencies : ", action.getMissingDependencies()).writeStringValue("Push Missing Dependencies : ", action.getPushMissingDependencies()).writeNewLine().flush();
}
}
use of org.apache.oozie.client.CoordinatorAction in project oozie by apache.
the class AppInfoCollector method getCoordJob.
private void getCoordJob(final File outputDir, final String jobId, int maxChildActions) {
if (jobId == null || !isCoordinator(jobId)) {
return;
}
try {
System.out.print("Getting Details for " + jobId + "...");
final File coordOutputDir = new File(outputDir, jobId);
if (!createOutputDirectory(coordOutputDir)) {
return;
}
final CoordinatorJob job = client.getCoordJobInfo(jobId);
try (DiagBundleEntryWriter bundleEntryWriter = new DiagBundleEntryWriter(coordOutputDir, "info.txt")) {
persistCoordinatorJobInfo(maxChildActions, job, bundleEntryWriter);
}
storeCommonDetails(coordOutputDir, jobId, "coordinator", job.getConf());
System.out.println("Done");
final List<CoordinatorAction> coordinatorActions = job.getActions();
for (int i = 0; i != coordinatorActions.size() && i < maxChildActions; ++i) {
storeWorkflowJobDetails(outputDir, coordinatorActions.get(i).getExternalId(), maxChildActions);
}
} catch (IOException | OozieClientException e) {
System.err.printf(String.format("Exception occurred during the retrieval of coordinator information:%s%n", e.getMessage()));
}
}
use of org.apache.oozie.client.CoordinatorAction in project oozie by apache.
the class OozieCLI method printBulkJobs.
@VisibleForTesting
void printBulkJobs(List<BulkResponse> jobs, String timeZoneId, boolean verbose) throws IOException {
if (jobs != null && jobs.size() > 0) {
for (BulkResponse response : jobs) {
BundleJob bundle = response.getBundle();
CoordinatorJob coord = response.getCoordinator();
CoordinatorAction action = response.getAction();
if (verbose) {
System.out.println();
System.out.println("Bundle Name : " + maskIfNull(bundle.getAppName()));
System.out.println(RULER);
System.out.println("Bundle ID : " + maskIfNull(bundle.getId()));
System.out.println("Coordinator Name : " + maskIfNull(coord.getAppName()));
System.out.println("Coord Action ID : " + maskIfNull(action.getId()));
System.out.println("Action Status : " + action.getStatus());
System.out.println("External ID : " + maskIfNull(action.getExternalId()));
System.out.println("Created Time : " + maskDate(action.getCreatedTime(), timeZoneId, false));
System.out.println("User : " + maskIfNull(bundle.getUser()));
System.out.println("Error Message : " + maskIfNull(action.getErrorMessage()));
System.out.println(RULER);
} else {
System.out.println(String.format(BULK_RESPONSE_FORMATTER, "Bundle Name", "Bundle ID", "Coord Name", "Coord Action ID", "Status", "External ID", "Created Time", "Error Message"));
System.out.println(RULER);
System.out.println(String.format(BULK_RESPONSE_FORMATTER, maskIfNull(bundle.getAppName()), maskIfNull(bundle.getId()), maskIfNull(coord.getAppName()), maskIfNull(action.getId()), action.getStatus(), maskIfNull(action.getExternalId()), maskDate(action.getCreatedTime(), timeZoneId, false), maskIfNull(action.getErrorMessage())));
System.out.println(RULER);
}
}
} else {
System.out.println("Bulk request criteria did not match any coordinator actions");
}
}
use of org.apache.oozie.client.CoordinatorAction in project oozie by apache.
the class OozieCLI method printCoordJob.
@VisibleForTesting
void printCoordJob(CoordinatorJob coordJob, String timeZoneId, boolean verbose) {
System.out.println("Job ID : " + coordJob.getId());
System.out.println(RULER);
List<CoordinatorAction> actions = coordJob.getActions();
System.out.println("Job Name : " + maskIfNull(coordJob.getAppName()));
System.out.println("App Path : " + maskIfNull(coordJob.getAppPath()));
System.out.println("Status : " + coordJob.getStatus());
System.out.println("Start Time : " + maskDate(coordJob.getStartTime(), timeZoneId, false));
System.out.println("End Time : " + maskDate(coordJob.getEndTime(), timeZoneId, false));
System.out.println("Pause Time : " + maskDate(coordJob.getPauseTime(), timeZoneId, false));
System.out.println("Concurrency : " + coordJob.getConcurrency());
System.out.println(RULER);
if (verbose) {
System.out.println("ID" + VERBOSE_DELIMITER + "Action Number" + VERBOSE_DELIMITER + "Console URL" + VERBOSE_DELIMITER + "Error Code" + VERBOSE_DELIMITER + "Error Message" + VERBOSE_DELIMITER + "External ID" + VERBOSE_DELIMITER + "External Status" + VERBOSE_DELIMITER + "Job ID" + VERBOSE_DELIMITER + "Tracker URI" + VERBOSE_DELIMITER + "Created" + VERBOSE_DELIMITER + "Nominal Time" + VERBOSE_DELIMITER + "Status" + VERBOSE_DELIMITER + "Last Modified" + VERBOSE_DELIMITER + "Missing Dependencies");
System.out.println(RULER);
for (CoordinatorAction action : actions) {
System.out.println(maskIfNull(action.getId()) + VERBOSE_DELIMITER + action.getActionNumber() + VERBOSE_DELIMITER + maskIfNull(action.getConsoleUrl()) + VERBOSE_DELIMITER + maskIfNull(action.getErrorCode()) + VERBOSE_DELIMITER + maskIfNull(action.getErrorMessage()) + VERBOSE_DELIMITER + maskIfNull(action.getExternalId()) + VERBOSE_DELIMITER + maskIfNull(action.getExternalStatus()) + VERBOSE_DELIMITER + maskIfNull(action.getJobId()) + VERBOSE_DELIMITER + maskIfNull(action.getTrackerUri()) + VERBOSE_DELIMITER + maskDate(action.getCreatedTime(), timeZoneId, verbose) + VERBOSE_DELIMITER + maskDate(action.getNominalTime(), timeZoneId, verbose) + action.getStatus() + VERBOSE_DELIMITER + maskDate(action.getLastModifiedTime(), timeZoneId, verbose) + VERBOSE_DELIMITER + maskIfNull(getFirstMissingDependencies(action)));
System.out.println(RULER);
}
} else {
System.out.println(String.format(COORD_ACTION_FORMATTER, "ID", "Status", "Ext ID", "Err Code", "Created", "Nominal Time", "Last Mod"));
for (CoordinatorAction action : actions) {
System.out.println(String.format(COORD_ACTION_FORMATTER, maskIfNull(action.getId()), action.getStatus(), maskIfNull(action.getExternalId()), maskIfNull(action.getErrorCode()), maskDate(action.getCreatedTime(), timeZoneId, verbose), maskDate(action.getNominalTime(), timeZoneId, verbose), maskDate(action.getLastModifiedTime(), timeZoneId, verbose)));
System.out.println(RULER);
}
}
}
Aggregations