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());
}
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);
}
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));
});
}
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);
});
}
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);
});
}
Aggregations