use of co.cask.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileHttpHandler method deleteProfile.
/**
* Delete a profile from a namespace. A profile must be in the disabled state before it can be deleted.
* Before a profile can be deleted, it cannot be assigned to any program or schedule,
* and it cannot be in use by any running program.
*/
@DELETE
@Path("/profiles/{profile-name}")
public void deleteProfile(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("profile-name") String profileName) throws NotFoundException, ConflictException, IOException {
// TODO: add the check if there is any program or schedule associated with the profile
profileStore.delete(new ProfileId(namespaceId, profileName));
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileHttpHandler method getProfile.
/**
* Get the information about a specific profile.
*/
@GET
@Path("/profiles/{profile-name}")
public void getProfile(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("profile-name") String profileName) throws NotFoundException, IOException {
ProfileId profileId = new ProfileId(namespaceId, profileName);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(profileStore.getProfile(profileId)));
}
use of co.cask.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileHttpHandler method writeProfile.
/**
* Write a profile in a namespace.
*/
@PUT
@Path("/profiles/{profile-name}")
public void writeProfile(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("profile-name") String profileName) throws BadRequestException, IOException, AlreadyExistsException {
ProfileCreateRequest profileCreateRequest;
try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) {
// TODO: validate the profileCreateRequest, the provisoner should exist and the property should be correct
profileCreateRequest = GSON.fromJson(reader, ProfileCreateRequest.class);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Request body is invalid json: " + e.getMessage(), e);
}
ProfileId profileId = new ProfileId(namespaceId, profileName);
Profile profile = new Profile(profileName, profileCreateRequest.getDescription(), profileId.getNamespaceId().equals(NamespaceId.SYSTEM) ? EntityScope.SYSTEM : EntityScope.USER, profileCreateRequest.getProvisioner());
profileStore.add(profileId, profile);
responder.sendStatus(HttpResponseStatus.OK);
}
use of co.cask.cdap.proto.id.ProfileId in project cdap by caskdata.
the class ProfileStoreTest method testProfileStore.
@Test
public void testProfileStore() throws Exception {
// get non-existing profile
try {
profileStore.getProfile(NamespaceId.DEFAULT.profile("nonExisting"));
Assert.fail();
} catch (NotFoundException e) {
// expected
}
// delete non-existing profile
try {
profileStore.delete(NamespaceId.DEFAULT.profile("nonExisting"));
Assert.fail();
} catch (NotFoundException e) {
// expected
}
ProfileId profileId = NamespaceId.DEFAULT.profile("MyProfile");
Profile expected = new Profile("MyProfile", "my profile for testing", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES));
// add a profile
profileStore.add(profileId, expected);
// get the profile
Assert.assertEquals(expected, profileStore.getProfile(profileId));
// add a profile which already exists
try {
profileStore.add(profileId, new Profile("MyProfile", "my another profile", new ProvisionerInfo("defaultProvisioner", PROPERTY_SUMMARIES)));
Assert.fail();
} catch (AlreadyExistsException e) {
// expected
}
// add another profile to default namespace
ProfileId profileId2 = NamespaceId.DEFAULT.profile("MyProfile2");
Profile profile2 = new Profile("MyProfile2", "my 2nd profile for testing", new ProvisionerInfo("anotherProvisioner", PROPERTY_SUMMARIES));
profileStore.add(profileId2, profile2);
// get all profiles
List<Profile> profiles = ImmutableList.of(expected, profile2);
Assert.assertEquals(profiles, profileStore.getProfiles(NamespaceId.DEFAULT));
// delete the second profile
profileStore.delete(profileId2);
Assert.assertEquals(ImmutableList.of(expected), profileStore.getProfiles(NamespaceId.DEFAULT));
// add one and delete all profiles
profileStore.add(profileId2, profile2);
profileStore.deleteAll(NamespaceId.DEFAULT);
Assert.assertEquals(Collections.EMPTY_LIST, profileStore.getProfiles(NamespaceId.DEFAULT));
}
Aggregations