private MDSKey getEntityIndexRowKeyPrefix(ProfileId profileId) { return getRowKey(INDEX_PREFIX, profileId.getNamespaceId(), profileId.getProfile(), null); }
private MDSKey getProfileRowKey(ProfileId profileId) { return getRowKey(PROFILE_PREFIX, profileId.getNamespaceId(), profileId.getProfile(), null); }
private MDSKey getProfileRowKey(ProfileId profileId) { return getRowKey(PROFILE_PREFIX, profileId.getNamespaceId(), profileId.getProfile(), null); }
private MDSKey getEntityIndexRowKey(ProfileId profileId, EntityId entityId) { return getRowKey(INDEX_PREFIX, profileId.getNamespaceId(), profileId.getProfile(), entityId); }
private MDSKey getEntityIndexRowKeyPrefix(ProfileId profileId) { return getRowKey(INDEX_PREFIX, profileId.getNamespaceId(), profileId.getProfile(), null); }
private MDSKey getEntityIndexRowKey(ProfileId profileId, EntityId entityId) { return getRowKey(INDEX_PREFIX, profileId.getNamespaceId(), profileId.getProfile(), entityId); }
/** * Get the metrics context for the program, the tags are constructed with the program run id and * the profile id */ private MetricsContext getMetricsContextForProfile(MetricsCollectionService metricsCollectionService, ProgramRunId programRunId, ProfileId profileId) { Map<String, String> tags = ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()) .build(); return metricsCollectionService.getContext(tags); } }
@Test public void testNativeProfileImmutable() throws Exception { // verify native profile exists Assert.assertEquals(Profile.NATIVE, getSystemProfile(ProfileId.NATIVE.getProfile(), 200).get()); // disable, update, or delete should throw a 405 disableSystemProfile(ProfileId.NATIVE.getProfile(), 405); putSystemProfile(ProfileId.NATIVE.getProfile(), Profile.NATIVE, 405); deleteSystemProfile(ProfileId.NATIVE.getProfile(), 405); } }
protected Optional<ProfileStatus> getProfileStatus(ProfileId profileId, int expectedCode) throws Exception { HttpResponse response = doGet(String.format("/v3/namespaces/%s/profiles/%s/status", profileId.getNamespace(), profileId.getProfile())); Assert.assertEquals(expectedCode, response.getResponseCode()); if (expectedCode == HttpResponseStatus.OK.code()) { return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), ProfileStatus.class)); } return Optional.empty(); }
protected Optional<Profile> getProfile(ProfileId profileId, int expectedCode) throws Exception { HttpResponse response = doGet(String.format("/v3/namespaces/%s/profiles/%s", profileId.getNamespace(), profileId.getProfile())); Assert.assertEquals(expectedCode, response.getResponseCode()); if (expectedCode == HttpResponseStatus.OK.code()) { return Optional.of(GSON.fromJson(response.getResponseBodyAsString(), Profile.class)); } return Optional.empty(); }
private Map<String, String> getMetricsTags(ProgramRunId programRunId, ProfileId profileId) { return ImmutableMap.<String, String>builder() .put(Constants.Metrics.Tag.PROFILE_SCOPE, profileId.getScope().name()) .put(Constants.Metrics.Tag.PROFILE, profileId.getProfile()) .put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()) .put(Constants.Metrics.Tag.PROGRAM_TYPE, programRunId.getType().getPrettyName()) .put(Constants.Metrics.Tag.APP, programRunId.getApplication()) .put(Constants.Metrics.Tag.PROGRAM, programRunId.getProgram()) .put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()) .build(); }
/** * 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 { Profile profile = table.get(getProfileRowKey(profileId), Profile.class); 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); } table.write(getEntityIndexRowKey(profileId, entityId), entityId); }
protected void putProfile(ProfileId profileId, Object profile, int expectedCode) throws Exception { HttpResponse response = doPut(String.format("/v3/namespaces/%s/profiles/%s", profileId.getNamespace(), profileId.getProfile()), GSON.toJson(profile)); Assert.assertEquals(expectedCode, response.getResponseCode()); }
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); } Profile profile = new Profile(profileId.getProfile(), profileCreateRequest.getLabel(), profileCreateRequest.getDescription(), profileId.getScope(), profileCreateRequest.getProvisioner()); profileService.saveProfile(profileId, profile); }
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); } Profile profile = new Profile(profileId.getProfile(), profileCreateRequest.getLabel(), profileCreateRequest.getDescription(), profileId.getScope(), profileCreateRequest.getProvisioner()); profileService.saveProfile(profileId, profile); }
protected void enableProfile(ProfileId profileId, int expectedCode) throws Exception { HttpResponse response = doPost(String.format("/v3/namespaces/%s/profiles/%s/enable", profileId.getNamespace(), profileId.getProfile())); Assert.assertEquals(expectedCode, response.getResponseCode()); }
protected void disableProfile(ProfileId profileId, int expectedCode) throws Exception { HttpResponse response = doPost(String.format("/v3/namespaces/%s/profiles/%s/disable", profileId.getNamespace(), profileId.getProfile())); Assert.assertEquals(expectedCode, response.getResponseCode()); }
protected void deleteProfile(ProfileId profileId, int expectedCode) throws Exception { HttpResponse response = doDelete(String.format("/v3/namespaces/%s/profiles/%s", profileId.getNamespace(), profileId.getProfile())); Assert.assertEquals(expectedCode, response.getResponseCode()); }
private void changeProfileStatus(ProfileId profileId, ProfileStatus expectedStatus) throws NotFoundException, ProfileConflictException { MDSKey rowKey = getProfileRowKey(profileId); Profile oldProfile = table.get(rowKey, Profile.class); 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); } table.write(rowKey, new Profile(oldProfile.getName(), oldProfile.getLabel(), oldProfile.getDescription(), oldProfile.getScope(), expectedStatus, oldProfile.getProvisioner(), oldProfile.getCreatedTsSeconds())); }
private void changeProfileStatus(ProfileId profileId, ProfileStatus expectedStatus) throws NotFoundException, ProfileConflictException { MDSKey rowKey = getProfileRowKey(profileId); Profile oldProfile = table.get(rowKey, Profile.class); 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); } table.write(rowKey, new Profile(oldProfile.getName(), oldProfile.getLabel(), oldProfile.getDescription(), oldProfile.getScope(), expectedStatus, oldProfile.getProvisioner(), oldProfile.getCreatedTsSeconds())); }