Search in sources :

Example 1 with DraftId

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

the class DraftServiceTest method testDeleteDraftError.

@Test
public void testDeleteDraftError() throws IOException {
    // Attempt to delete a draft that does not exist
    NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
    HttpResponse response = deleteDraft(new DraftId(namespace, "non-existent", ""));
    Assert.assertEquals(404, response.getResponseCode());
}
Also used : HttpResponse(io.cdap.common.http.HttpResponse) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Test(org.junit.Test)

Example 2 with DraftId

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

the class DraftServiceTest method testGetDraftError.

@Test
public void testGetDraftError() throws IOException {
    // Attempt to fetch an invalid draft from a valid namespace
    NamespaceSummary namespace = new NamespaceSummary(NamespaceId.DEFAULT.getNamespace(), "", 0);
    DraftId invalidId = new DraftId(namespace, "non-existent", "");
    HttpResponse response = fetchDraft(invalidId);
    DraftNotFoundException draftError = new DraftNotFoundException(invalidId);
    Assert.assertEquals(404, response.getResponseCode());
    Assert.assertEquals(draftError.getMessage(), response.getResponseBodyAsString());
    // Attempt to fetch a valid draft but invalid namespace
    DraftId draftId = new DraftId(namespace, "test-draft", "");
    createBatchPipelineDraft(draftId, "TestPipeline1", "This is a test pipeline.");
    NamespaceSummary invalidNamespace = new NamespaceSummary("non-existent", "", 0);
    response = fetchDraft(new DraftId(invalidNamespace, "test-draft", ""));
    Assert.assertEquals(500, response.getResponseCode());
    // Sanity check, get the draft we just created
    getDraft(draftId);
    // Clean up
    deleteDraftAndCheck(draftId);
}
Also used : DraftNotFoundException(io.cdap.cdap.datapipeline.draft.DraftNotFoundException) HttpResponse(io.cdap.common.http.HttpResponse) NamespaceSummary(io.cdap.cdap.api.NamespaceSummary) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Test(org.junit.Test)

Example 3 with DraftId

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

the class DraftHandler method getDraft.

/**
 * Gets the details of a draft
 */
@GET
@Path(API_VERSION + "/contexts/{context}/drafts/{draft}/")
public void getDraft(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespaceName, @PathParam("draft") String draftId) {
    respond(namespaceName, responder, (namespace) -> {
        String userId = request.getUserId();
        userId = userId == null ? "" : userId;
        DraftId id = new DraftId(namespace, draftId, userId);
        responder.sendJson(draftService.getDraft(id));
    });
}
Also used : DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with DraftId

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

the class DraftHandler method putDraft.

/**
 * Creates or updates a draft
 */
@PUT
@Path(API_VERSION + "/contexts/{context}/drafts/{draft}/")
public void putDraft(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespaceName, @PathParam("draft") String draftId) {
    contextAccessEnforcer.enforce(new NamespaceId(namespaceName), StandardPermission.UPDATE);
    respond(namespaceName, responder, (namespace) -> {
        String requestStr = StandardCharsets.UTF_8.decode(request.getContent()).toString();
        DraftStoreRequest<ETLConfig> draftStoreRequest = deserializeDraftStoreRequest(requestStr);
        String userId = request.getUserId();
        userId = userId == null ? "" : userId;
        DraftId id = new DraftId(namespace, draftId, userId);
        draftService.writeDraft(id, draftStoreRequest);
        responder.sendStatus(HttpURLConnection.HTTP_OK);
    });
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) ETLConfig(io.cdap.cdap.etl.proto.v2.ETLConfig) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 5 with DraftId

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

the class DraftHandler method deleteDraft.

/**
 * Deletes a draft
 */
@DELETE
@Path(API_VERSION + "/contexts/{context}/drafts/{draft}/")
public void deleteDraft(HttpServiceRequest request, HttpServiceResponder responder, @PathParam("context") String namespaceName, @PathParam("draft") String draftId) {
    contextAccessEnforcer.enforce(new NamespaceId(namespaceName), StandardPermission.UPDATE);
    respond(namespaceName, responder, (namespace) -> {
        String userId = request.getUserId();
        userId = userId == null ? "" : userId;
        DraftId id = new DraftId(namespace, draftId, userId);
        draftService.deleteDraft(id);
        responder.sendStatus(HttpURLConnection.HTTP_OK);
    });
}
Also used : NamespaceId(io.cdap.cdap.proto.id.NamespaceId) DraftId(io.cdap.cdap.datapipeline.draft.DraftId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

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