Search in sources :

Example 1 with ProfileCreateRequest

use of co.cask.cdap.proto.profile.ProfileCreateRequest 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)

Aggregations

BadRequestException (co.cask.cdap.common.BadRequestException)1 ProfileId (co.cask.cdap.proto.id.ProfileId)1 Profile (co.cask.cdap.proto.profile.Profile)1 ProfileCreateRequest (co.cask.cdap.proto.profile.ProfileCreateRequest)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1