Search in sources :

Example 1 with BundleJob

use of org.apache.oozie.client.BundleJob in project oozie by apache.

the class TestOozieCLIMethods method testValidationPrintBundleJobsOutput.

/**
 * Create list of {@code BundleJob} mocks,
 * call {@code new OozieCLI().printBundleJobs()}
 * and validate {@code System.out} on match with expected pattern
 * <p>
 * Method do pass only if output matched with predefined pattern
 * </p>
 */
@Test
public void testValidationPrintBundleJobsOutput() throws IOException {
    final DataObject dtObject1 = new DataObject() {

        {
            this.deamonName = "testBundleJob1";
            this.appName = "testBundleJobApp1";
            this.appPath = "testBundleJobAppPath1";
        }
    };
    final DataObject dtObject2 = new DataObject() {

        {
            this.deamonName = "testBundleJob2";
            this.appName = "testBundleJobApp2";
            this.appPath = "testBundleJobAppPath2";
        }
    };
    ImmutableList<BundleJob> bundleJobs = ImmutableList.of(createBundleJob(dtObject1), createBundleJob(dtObject2));
    Pattern pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" + dtObject1.appName + "[\\s]+" + dtObject1.appPath);
    assertPrintBundleJobsOutput(readBundleJobsOutput(bundleJobs, true), pattern);
    pattern = Pattern.compile(dtObject1.deamonName + "[\\s]+" + dtObject1.appName);
    assertPrintBundleJobsOutput(readBundleJobsOutput(bundleJobs, false), pattern);
}
Also used : Pattern(java.util.regex.Pattern) BundleJob(org.apache.oozie.client.BundleJob) Test(org.junit.Test)

Example 2 with BundleJob

use of org.apache.oozie.client.BundleJob in project oozie by apache.

the class TestOozieCLIMethods method createBundleJob.

private static BundleJob createBundleJob(DataObject dtObject) {
    BundleJob bundleJobMock = mock(BundleJob.class);
    when(bundleJobMock.getId()).thenReturn(dtObject.deamonName);
    when(bundleJobMock.getAppName()).thenReturn(dtObject.appName);
    when(bundleJobMock.getAppPath()).thenReturn(dtObject.appPath);
    when(bundleJobMock.getStatus()).thenReturn(org.apache.oozie.client.Job.Status.RUNNING);
    CoordinatorJob coordinatorJobMock = createCoordinatorJob(dtObject);
    when(bundleJobMock.getCoordinators()).thenReturn(ImmutableList.of(coordinatorJobMock));
    return bundleJobMock;
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) BundleJob(org.apache.oozie.client.BundleJob)

Example 3 with BundleJob

use of org.apache.oozie.client.BundleJob in project oozie by apache.

the class TestJsonToBean method testParseBulkResponse.

public void testParseBulkResponse() {
    JSONObject json = createJsonBulkResponse();
    BundleJob bulkBundle = JsonToBean.createBundleJob((JSONObject) json.get(JsonTags.BULK_RESPONSE_BUNDLE));
    CoordinatorJob bulkCoord = JsonToBean.createCoordinatorJob((JSONObject) json.get(JsonTags.BULK_RESPONSE_COORDINATOR));
    CoordinatorAction bulkAction = JsonToBean.createCoordinatorAction((JSONObject) json.get(JsonTags.BULK_RESPONSE_ACTION));
    assertNotNull(bulkBundle);
    assertNotNull(bulkCoord);
    assertNotNull(bulkAction);
    assertEquals("bundle-app", bulkBundle.getAppName());
    assertEquals("bundle-id", bulkBundle.getId());
    assertEquals(BundleJob.Status.RUNNING, bulkBundle.getStatus());
    assertEquals("coord-app", bulkCoord.getAppName());
    assertEquals(CoordinatorJob.Status.SUSPENDED, bulkCoord.getStatus());
    assertEquals("action-id", bulkAction.getId());
    assertEquals("coord-id", bulkAction.getJobId());
    assertEquals(1, bulkAction.getActionNumber());
    assertEquals("action-externalId", bulkAction.getExternalId());
    assertEquals(CoordinatorAction.Status.FAILED, bulkAction.getStatus());
    assertEquals("action-externalStatus", bulkAction.getExternalStatus());
    assertEquals("action-errorCode", bulkAction.getErrorCode());
    assertEquals("action-errorMessage", bulkAction.getErrorMessage());
    assertEquals(JsonUtils.parseDateRfc822(CREATED_TIME), bulkAction.getCreatedTime());
    assertEquals(JsonUtils.parseDateRfc822(NOMINAL_TIME), bulkAction.getNominalTime());
    assertEquals("action-missingDeps", bulkAction.getMissingDependencies());
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) JSONObject(org.json.simple.JSONObject) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) BundleJob(org.apache.oozie.client.BundleJob)

Example 4 with BundleJob

use of org.apache.oozie.client.BundleJob in project oozie by apache.

the class AppInfoCollector method getBundleJob.

private void getBundleJob(final File outputDir, final String jobId, int maxChildActions) {
    if (jobId == null || !isBundle(jobId)) {
        return;
    }
    try {
        System.out.print("Getting Details for " + jobId + "...");
        final File bundleOutputDir = new File(outputDir, jobId);
        if (!createOutputDirectory(bundleOutputDir)) {
            return;
        }
        final BundleJob job = client.getBundleJobInfo(jobId);
        try (DiagBundleEntryWriter bundleEntryWriter = new DiagBundleEntryWriter(bundleOutputDir, "info.txt")) {
            persistBundleJobInfo(job, bundleEntryWriter);
        }
        storeCommonDetails(bundleOutputDir, jobId, "bundle", job.getConf());
        System.out.println("Done");
        for (CoordinatorJob coordJob : job.getCoordinators()) {
            getCoordJob(outputDir, coordJob.getId(), maxChildActions);
        }
    } catch (IOException | OozieClientException e) {
        System.err.printf(String.format("Exception occurred during the retrieval of bundle information: %s%n", e.getMessage()));
    }
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) OozieClientException(org.apache.oozie.client.OozieClientException) BundleJob(org.apache.oozie.client.BundleJob) IOException(java.io.IOException) File(java.io.File)

Example 5 with BundleJob

use of org.apache.oozie.client.BundleJob 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");
    }
}
Also used : CoordinatorJob(org.apache.oozie.client.CoordinatorJob) CoordinatorAction(org.apache.oozie.client.CoordinatorAction) BulkResponse(org.apache.oozie.client.BulkResponse) BundleJob(org.apache.oozie.client.BundleJob) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

BundleJob (org.apache.oozie.client.BundleJob)7 CoordinatorJob (org.apache.oozie.client.CoordinatorJob)5 CoordinatorAction (org.apache.oozie.client.CoordinatorAction)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 BulkResponse (org.apache.oozie.client.BulkResponse)2 File (java.io.File)1 IOException (java.io.IOException)1 Pattern (java.util.regex.Pattern)1 OozieClientException (org.apache.oozie.client.OozieClientException)1 JSONObject (org.json.simple.JSONObject)1 Test (org.junit.Test)1