use of io.cdap.cdap.proto.id.NamespaceId 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.proto.id.NamespaceId 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);
});
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDeployNonExistingNamespace.
/**
* Tests deploying an application in a non-existing non-default namespace.
*/
@Test
public void testDeployNonExistingNamespace() throws Exception {
HttpResponse response = deploy(AllProgramsApp.class, 404, Constants.Gateway.API_VERSION_3_TOKEN, "random");
NotFoundException nfe = new NamespaceNotFoundException(new NamespaceId("random"));
Assert.assertEquals(nfe.getMessage(), response.getResponseBodyAsString());
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AppLifecycleHttpHandlerTest method testDeployAppWithDisabledProfileInSchedule.
@Test
public void testDeployAppWithDisabledProfileInSchedule() throws Exception {
// put my profile and disable it
ProfileId profileId = new NamespaceId(TEST_NAMESPACE1).profile("MyProfile");
Profile profile = new Profile("MyProfile", Profile.NATIVE.getLabel(), Profile.NATIVE.getDescription(), Profile.NATIVE.getScope(), Profile.NATIVE.getProvisioner());
putProfile(profileId, profile, 200);
disableProfile(profileId, 200);
// deploy an app with schedule with some disabled profile in the schedule property
AppWithSchedule.AppConfig config = new AppWithSchedule.AppConfig(true, true, true, ImmutableMap.of(SystemArguments.PROFILE_NAME, "USER:MyProfile"));
Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.fromEntityId(TEST_NAMESPACE_META1.getNamespaceId()), AppWithSchedule.NAME, VERSION1);
addAppArtifact(artifactId, AppWithSchedule.class);
AppRequest<? extends Config> request = new AppRequest<>(new ArtifactSummary(artifactId.getName(), artifactId.getVersion().getVersion()), config, null, null, true);
// deploy should fail with a 409
ApplicationId defaultAppId = TEST_NAMESPACE_META1.getNamespaceId().app(AppWithSchedule.NAME);
Assert.assertEquals(409, deploy(defaultAppId, request).getResponseCode());
// enable
enableProfile(profileId, 200);
Assert.assertEquals(200, deploy(defaultAppId, request).getResponseCode());
// disable again so that we can delete it at namespace deletion
disableProfile(profileId, 200);
// clean up
deleteApp(defaultAppId, 200);
deleteArtifact(artifactId, 200);
}
use of io.cdap.cdap.proto.id.NamespaceId in project cdap by caskdata.
the class AppFabricTestBase method getProgramRuns.
protected List<BatchProgramHistory> getProgramRuns(NamespaceId namespace, List<ProgramId> programs) throws Exception {
List<BatchProgram> request = programs.stream().map(program -> new BatchProgram(program.getApplication(), program.getType(), program.getProgram())).collect(Collectors.toList());
HttpResponse response = doPost(getVersionedAPIPath("runs", namespace.getNamespace()), GSON.toJson(request));
assertResponseCode(200, response);
return GSON.fromJson(response.getResponseBodyAsString(), BATCH_PROGRAM_RUNS_TYPE);
}
Aggregations