Search in sources :

Example 6 with DraftId

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

the class DraftServiceTest method testDraftAuthorization.

@Test
public void testDraftAuthorization() throws Exception {
    user = ALICE_NAME;
    HttpResponse response;
    // Check Alice can't list requests
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "");
    // Grant her nesessary privilidges
    Authorizable namespaceAuthorizable = Authorizable.fromEntityId(NamespaceId.DEFAULT);
    getAccessController().grant(namespaceAuthorizable, ALICE_PRINCIPAL, EnumSet.of(StandardPermission.GET));
    // Check Alice can list requests now
    expectedCode = HttpURLConnection.HTTP_OK;
    listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "");
    // Check Bob still can't do it
    user = "bob";
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    listDrafts(NamespaceId.DEFAULT.getNamespace(), false, "", "", "");
    // Check Alice can't do it for other namespace
    user = ALICE_NAME;
    listDrafts(TEST_NAMESPACE, false, "", "", "");
    // Check Alice can't create drafts
    NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
    DraftId draftId = new DraftId(namespace, "draft1", ALICE_NAME);
    // She can't delete it as well
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    deleteDraft(draftId);
    createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    // Grant Alice create priviledge. Note that we don't differenciate create and update,
    // so update is used in both cases
    getAccessController().grant(namespaceAuthorizable, ALICE_PRINCIPAL, EnumSet.of(StandardPermission.UPDATE));
    // Now Alice should be able to create draft
    expectedCode = HttpURLConnection.HTTP_OK;
    createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    // Bob still can't get the draft
    expectedCode = HttpURLConnection.HTTP_FORBIDDEN;
    user = "bob";
    getDraft(draftId);
    // Alice should be able to delete draft
    expectedCode = HttpURLConnection.HTTP_OK;
    user = ALICE_NAME;
    deleteDraft(draftId);
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) Authorizable(io.cdap.cdap.proto.security.Authorizable) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Test(org.junit.Test)

Example 7 with DraftId

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

the class DraftServiceTest method testCreateAndDeleteDraft.

private void testCreateAndDeleteDraft(DraftType draftType) throws IOException, TimeoutException, InterruptedException, ExecutionException {
    NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
    DraftId draftId = new DraftId(namespace, "test-1", "admin");
    Draft expectedDraft;
    if (draftType == DraftType.Batch) {
        expectedDraft = createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    } else {
        expectedDraft = createStreamingPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    }
    Draft fetchedDraft = getDraft(draftId);
    Assert.assertTrue(sameDraft(fetchedDraft, expectedDraft));
    validateMetric(1, Constants.Metrics.DRAFT_COUNT);
    deleteDraftAndCheck(draftId);
    validateMetric(0, Constants.Metrics.DRAFT_COUNT);
}
Also used : Draft(io.cdap.cdap.datapipeline.draft.Draft) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId)

Example 8 with DraftId

use of io.cdap.cdap.datapipeline.draft.DraftId 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

DraftId (io.cdap.cdap.datapipeline.draft.DraftId)8 NamespaceSummary (io.cdap.cdap.api.NamespaceSummary)5 HttpResponse (io.cdap.common.http.HttpResponse)3 Path (javax.ws.rs.Path)3 Test (org.junit.Test)3 Draft (io.cdap.cdap.datapipeline.draft.Draft)2 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)2 DraftNotFoundException (io.cdap.cdap.datapipeline.draft.DraftNotFoundException)1 DraftStoreRequest (io.cdap.cdap.datapipeline.draft.DraftStoreRequest)1 ETLConfig (io.cdap.cdap.etl.proto.v2.ETLConfig)1 Authorizable (io.cdap.cdap.proto.security.Authorizable)1 ArrayList (java.util.ArrayList)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1