use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
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);
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
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 caskdata.
the class ProfileHttpHandler method verifyCpuLabelsProfiles.
private List<Profile> verifyCpuLabelsProfiles(List<Profile> profileList, NamespaceId namespaceId) throws BadRequestException, MethodNotAllowedException {
List<Profile> verifiedProfiles = new ArrayList<>();
for (Profile profile : profileList) {
ProfileId profileId = getValidatedProfile(namespaceId, profile.getName());
verifiedProfiles.add(verifyCpuLabelsProfile(profile, profileId));
}
return verifiedProfiles;
}
use of io.cdap.cdap.proto.profile.Profile in project cdap by caskdata.
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 caskdata.
the class AppFabricTestBase method getProfile.
protected Optional<Profile> getProfile(ProfileId profileId, int expectedCode) throws Exception {
HttpResponse response = doGet(String.format("/v3/namespaces/%s/profiles/%s", profileId.getNamespace(), profileId.getProfile()));
assertResponseCode(expectedCode, response);
if (expectedCode == HttpResponseStatus.OK.code()) {
return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), Profile.class));
}
return Optional.empty();
}
Aggregations