use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileHttpHandler method writeProfile.
private void writeProfile(ProfileId profileId, FullHttpRequest request) throws BadRequestException, IOException, MethodNotAllowedException {
ProfileCreateRequest profileCreateRequest;
try (Reader reader = new InputStreamReader(new ByteBufInputStream(request.content()), StandardCharsets.UTF_8)) {
profileCreateRequest = GSON.fromJson(reader, ProfileCreateRequest.class);
validateProvisionerProperties(profileCreateRequest);
} catch (JsonSyntaxException e) {
throw new BadRequestException("Unable to parse request body. Please make sure it is valid JSON", e);
}
String totalProcessingCpusLabel = getTotalProcessingCpusLabel(profileCreateRequest.getProvisioner());
profileCreateRequest.getProvisioner().setTotalProcessingCpusLabel(totalProcessingCpusLabel);
Profile profile = new Profile(profileId.getProfile(), profileCreateRequest.getLabel(), profileCreateRequest.getDescription(), profileId.getScope(), profileCreateRequest.getProvisioner());
profileService.saveProfile(profileId, profile);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileHttpHandler method getProfiles.
/**
* List the profiles in the given namespace. By default the results will not contain profiles in system scope.
*/
@GET
@Path("/namespaces/{namespace-id}/profiles")
public void getProfiles(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("includeSystem") @DefaultValue("false") String includeSystem) throws Exception {
NamespaceId namespace = getValidatedNamespace(namespaceId);
accessEnforcer.enforceOnParent(EntityType.PROFILE, namespace, authenticationContext.getPrincipal(), StandardPermission.LIST);
boolean include = Boolean.valueOf(includeSystem);
if (include) {
accessEnforcer.enforceOnParent(EntityType.PROFILE, NamespaceId.SYSTEM, authenticationContext.getPrincipal(), StandardPermission.LIST);
}
List<Profile> profiles = verifyCpuLabelsProfiles(profileService.getProfiles(namespace, include), namespace);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(profiles));
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileStore method changeProfileStatus.
private void changeProfileStatus(ProfileId profileId, ProfileStatus expectedStatus) throws NotFoundException, ProfileConflictException, IOException {
Collection<Field<?>> fields = getProfileKeys(profileId);
Profile oldProfile = getProfileInternal(fields);
if (oldProfile == null) {
throw new NotFoundException(profileId);
}
if (oldProfile.getStatus() == expectedStatus) {
throw new ProfileConflictException(String.format("Profile %s already %s", profileId.getProfile(), expectedStatus.toString()), profileId);
}
Profile newProfile = new Profile(oldProfile.getName(), oldProfile.getLabel(), oldProfile.getDescription(), oldProfile.getScope(), expectedStatus, oldProfile.getProvisioner(), oldProfile.getCreatedTsSeconds());
fields.add(Fields.stringField(StoreDefinition.ProfileStore.PROFILE_DATA_FIELD, GSON.toJson(newProfile)));
profileTable.upsert(fields);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileStore method createIfNotExists.
/**
* Add a profile if it does not exist in the store
*
* @param profileId the id of the profile to add
* @param profile the information of the profile
*/
public void createIfNotExists(ProfileId profileId, Profile profile) throws IOException {
Collection<Field<?>> keys = getProfileKeys(profileId);
Profile newProfile = new Profile(profile.getName(), profile.getLabel(), profile.getDescription(), profile.getScope(), ProfileStatus.ENABLED, profile.getProvisioner());
profileTable.compareAndSwap(keys, Fields.stringField(StoreDefinition.ProfileStore.PROFILE_DATA_FIELD, null), Fields.stringField(StoreDefinition.ProfileStore.PROFILE_DATA_FIELD, GSON.toJson(newProfile)));
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by cdapio.
the class ProfileStore method addProfileAssignment.
/**
* Add an assignment to the profile. Assignment can only be added if the profile is ENABLED
*
* @param profileId the profile id
* @param entityId the entity to add to the assgiment
*/
public void addProfileAssignment(ProfileId profileId, EntityId entityId) throws ProfileConflictException, NotFoundException, IOException {
Collection<Field<?>> fields = getProfileKeys(profileId);
Profile profile = getProfileInternal(fields);
if (profile == null) {
throw new NotFoundException(profileId);
}
if (profile.getStatus() == ProfileStatus.DISABLED) {
throw new ProfileConflictException(String.format("Profile %s is DISABLED. No entity can be assigned to it.", profileId.getProfile()), profileId);
}
addEntityIdKey(fields, entityId);
fields.add(Fields.stringField(StoreDefinition.ProfileStore.ENTITY_DATA_FIELD, GSON.toJson(entityId)));
profileEntityTable.upsert(fields);
}
Aggregations