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