Search in sources :

Example 1 with ProfileId

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);
}
Also used : ProfileId(co.cask.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 2 with ProfileId

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)));
}
Also used : ProfileId(co.cask.cdap.proto.id.ProfileId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with 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);
}
Also used : ProfileId(co.cask.cdap.proto.id.ProfileId) JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) ProfileCreateRequest(co.cask.cdap.proto.profile.ProfileCreateRequest) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BadRequestException(co.cask.cdap.common.BadRequestException) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) Profile(co.cask.cdap.proto.profile.Profile) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 4 with ProfileId

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));
}
Also used : ProfileId(co.cask.cdap.proto.id.ProfileId) AlreadyExistsException(co.cask.cdap.common.AlreadyExistsException) ProvisionerInfo(co.cask.cdap.proto.profile.ProvisionerInfo) NotFoundException(co.cask.cdap.common.NotFoundException) Profile(co.cask.cdap.proto.profile.Profile) Test(org.junit.Test)

Aggregations

ProfileId (co.cask.cdap.proto.id.ProfileId)4 Path (javax.ws.rs.Path)3 Profile (co.cask.cdap.proto.profile.Profile)2 AlreadyExistsException (co.cask.cdap.common.AlreadyExistsException)1 BadRequestException (co.cask.cdap.common.BadRequestException)1 NotFoundException (co.cask.cdap.common.NotFoundException)1 ProfileCreateRequest (co.cask.cdap.proto.profile.ProfileCreateRequest)1 ProvisionerInfo (co.cask.cdap.proto.profile.ProvisionerInfo)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Test (org.junit.Test)1