Search in sources :

Example 1 with DraftStoreRequest

use of io.cdap.cdap.datapipeline.draft.DraftStoreRequest in project cdap by caskdata.

the class DraftServiceTest method createBatchPipelineDraft.

private Draft createBatchPipelineDraft(DraftId draftId, String name, String description) throws IOException {
    ArtifactSummary artifact = new ArtifactSummary("cdap-data-pipeline", "1.0.0");
    ETLBatchConfig config = ETLBatchConfig.builder().addStage(new ETLStage("src", MockSource.getPlugin("dummy1"))).addStage(new ETLStage("sink", MockSink.getPlugin("dummy2"))).addConnection("src", "sink").setEngine(Engine.SPARK).build();
    DraftStoreRequest<ETLBatchConfig> batchDraftStoreRequest = new DraftStoreRequest<>(config, "", name, description, 0, artifact);
    long now = System.currentTimeMillis();
    Draft expectedDraft = new Draft(config, name, description, artifact, draftId.getId(), now, now);
    createPipelineDraft(draftId, batchDraftStoreRequest);
    return expectedDraft;
}
Also used : ETLBatchConfig(io.cdap.cdap.etl.proto.v2.ETLBatchConfig) DraftStoreRequest(io.cdap.cdap.datapipeline.draft.DraftStoreRequest) Draft(io.cdap.cdap.datapipeline.draft.Draft) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage)

Example 2 with DraftStoreRequest

use of io.cdap.cdap.datapipeline.draft.DraftStoreRequest in project cdap by caskdata.

the class DraftServiceTest method createStreamingPipelineDraft.

private Draft createStreamingPipelineDraft(DraftId draftId, String name, String description) throws IOException {
    ArtifactSummary artifact = new ArtifactSummary("cdap-data-streams", "1.0.0");
    DataStreamsConfig config = DataStreamsConfig.builder().addStage(new ETLStage("src", MockSource.getPlugin("dummy1"))).addStage(new ETLStage("sink", MockSink.getPlugin("dummy2"))).addConnection("src", "sink").setCheckpointDir("temp/dir").build();
    DraftStoreRequest<DataStreamsConfig> batchDraftStoreRequest = new DraftStoreRequest<>(config, "", name, description, 0, artifact);
    long now = System.currentTimeMillis();
    Draft expectedDraft = new Draft(config, name, description, artifact, draftId.getId(), now, now);
    createPipelineDraft(draftId, batchDraftStoreRequest);
    return expectedDraft;
}
Also used : DraftStoreRequest(io.cdap.cdap.datapipeline.draft.DraftStoreRequest) Draft(io.cdap.cdap.datapipeline.draft.Draft) ArtifactSummary(io.cdap.cdap.api.artifact.ArtifactSummary) ETLStage(io.cdap.cdap.etl.proto.v2.ETLStage) DataStreamsConfig(io.cdap.cdap.etl.proto.v2.DataStreamsConfig)

Example 3 with DraftStoreRequest

use of io.cdap.cdap.datapipeline.draft.DraftStoreRequest in project cdap by caskdata.

the class DraftServiceTest method testListDraftFilter.

private void testListDraftFilter(DraftType draftType) throws IOException, TimeoutException, InterruptedException, ExecutionException {
    // Create 2 drafts per namespace, each belonging to a different user
    NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
    List<DraftId> draftsToCleanUp = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        String id = String.format("draft-%d", i);
        String name = String.format("draft-name-%d", i);
        String owner = String.format("draft-user-%d", i);
        DraftId draftId = new DraftId(namespace, id, owner);
        draftsToCleanUp.add(draftId);
        if (draftType == DraftType.Batch) {
            createBatchPipelineDraft(draftId, name, "This is a test pipeline.");
        } else {
            createStreamingPipelineDraft(draftId, name, "This is a test pipeline.");
        }
    }
    // Test getting drafts for the default namespace
    List<Draft> drafts = listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "");
    Assert.assertEquals(4, drafts.size());
    drafts.forEach(draft -> Assert.assertNull(draft.getConfig()));
    validateMetric(4, Constants.Metrics.DRAFT_COUNT);
    // Check that the default sorting is correct
    String[] expectedOrder = new String[] { "draft-name-0", "draft-name-1", "draft-name-2", "draft-name-3" };
    Assert.assertArrayEquals(drafts.stream().map(DraftStoreRequest::getName).toArray(), expectedOrder);
    // Test getting drafts for the default namespace and sorting on id column with descending order
    drafts = listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "id", "DESC", "");
    Assert.assertEquals(4, drafts.size());
    String[] expectedReverseOrder = new String[] { "draft-3", "draft-2", "draft-1", "draft-0" };
    Assert.assertArrayEquals(drafts.stream().map(Draft::getId).toArray(), expectedReverseOrder);
    // Test filtering on draft name using a filter with 0 matches
    drafts = listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "nomatches");
    Assert.assertEquals(drafts.size(), 0);
    // Test filtering on draft name using a filter with 1 match and include the config
    Draft specialDraft;
    DraftId specialDraftId = new DraftId(namespace, "newDraft", "");
    draftsToCleanUp.add(specialDraftId);
    if (draftType == DraftType.Batch) {
        specialDraft = createBatchPipelineDraft(specialDraftId, "SpecialDraft", "This is a special pipeline.");
    } else {
        specialDraft = createStreamingPipelineDraft(specialDraftId, "SpecialDraft", "This is a special pipeline.");
    }
    drafts = listDrafts(NamespaceId.DEFAULT.getNamespace(), true, "", "", "spe");
    Assert.assertEquals(drafts.size(), 1);
    Assert.assertTrue(// This confirms that the config was included
    sameDraft(drafts.get(0), specialDraft));
    // List with all options enabled
    drafts = listDrafts(NamespaceId.DEFAULT.getNamespace(), true, "id", "DESC", "draft");
    // Confirm special draft is not present
    Assert.assertEquals(drafts.size(), 4);
    drafts.forEach(// Confirm that config was included
    draft -> Assert.assertNotNull(draft.getConfig()));
    Assert.assertArrayEquals(drafts.stream().map(Draft::getId).toArray(), // Confirm sorting
    expectedReverseOrder);
    // Cleanup
    for (DraftId draftId : draftsToCleanUp) {
        deleteDraftAndCheck(draftId);
    }
}
Also used : Draft(io.cdap.cdap.datapipeline.draft.Draft) DraftStoreRequest(io.cdap.cdap.datapipeline.draft.DraftStoreRequest) ArrayList(java.util.ArrayList) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId)

Aggregations

Draft (io.cdap.cdap.datapipeline.draft.Draft)3 DraftStoreRequest (io.cdap.cdap.datapipeline.draft.DraftStoreRequest)3 ArtifactSummary (io.cdap.cdap.api.artifact.ArtifactSummary)2 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)2 NamespaceSummary (io.cdap.cdap.api.NamespaceSummary)1 DraftId (io.cdap.cdap.datapipeline.draft.DraftId)1 DataStreamsConfig (io.cdap.cdap.etl.proto.v2.DataStreamsConfig)1 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)1 ArrayList (java.util.ArrayList)1