private NamespaceId getValidatedNamespace(String namespaceStr) throws BadRequestException, MethodNotAllowedException { try { NamespaceId namespaceId = new NamespaceId(namespaceStr); if (namespaceId.equals(NamespaceId.SYSTEM)) { throw new MethodNotAllowedException( "Cannot perform profile methods on the system namespace. " + "Please use the top level profile endpoints to manage system profiles."); } return namespaceId; } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } }
private NamespaceId getValidatedNamespace(String namespaceStr) throws BadRequestException, MethodNotAllowedException { try { NamespaceId namespaceId = new NamespaceId(namespaceStr); if (namespaceId.equals(NamespaceId.SYSTEM)) { throw new MethodNotAllowedException( "Cannot perform profile methods on the system namespace. " + "Please use the top level profile endpoints to manage system profiles."); } return namespaceId; } catch (IllegalArgumentException e) { throw new BadRequestException(e.getMessage(), e); } }
/** * Disable the profile. After the profile is disabled, any program/schedule cannot be associated with this profile. * * @param profileId the id of the profile to disable * @throws NotFoundException if the profile is not found * @throws ProfileConflictException if the profile is already disabled * @throws MethodNotAllowedException if trying to disable the native profile */ public void disableProfile(ProfileId profileId) throws NotFoundException, ProfileConflictException, MethodNotAllowedException { if (profileId.equals(ProfileId.NATIVE)) { throw new MethodNotAllowedException(String.format("Cannot change status for Profile Native %s, " + "it should always be ENABLED", profileId.getScopedName())); } Transactionals.execute(transactional, context -> { getProfileDataset(context).disableProfile(profileId); }, NotFoundException.class, ProfileConflictException.class); }
/** * Disable the profile. After the profile is disabled, any program/schedule cannot be associated with this profile. * * @param profileId the id of the profile to disable * @throws NotFoundException if the profile is not found * @throws ProfileConflictException if the profile is already disabled * @throws MethodNotAllowedException if trying to disable the native profile */ public void disableProfile(ProfileId profileId) throws NotFoundException, ProfileConflictException, MethodNotAllowedException { if (profileId.equals(ProfileId.NATIVE)) { throw new MethodNotAllowedException(String.format("Cannot change status for Profile Native %s, " + "it should always be ENABLED", profileId.getScopedName())); } Transactionals.execute(transactional, context -> { getProfileDataset(context).disableProfile(profileId); }, NotFoundException.class, ProfileConflictException.class); }
/** * Save the profile to the profile store. By default the profile status will be enabled. * * @param profileId the id of the profile to save * @param profile the information of the profile * @throws MethodNotAllowedException if trying to update the Native profile */ public void saveProfile(ProfileId profileId, Profile profile) throws MethodNotAllowedException { Transactionals.execute(transactional, context -> { ProfileDataset dataset = getProfileDataset(context); if (profileId.equals(ProfileId.NATIVE)) { try { dataset.getProfile(profileId); throw new MethodNotAllowedException(String.format("Profile Native %s already exists. It cannot be updated", profileId.getScopedName())); } catch (NotFoundException e) { // if native profile is not found, we can add it to the dataset } } dataset.saveProfile(profileId, profile); }, MethodNotAllowedException.class); }
/** * Save the profile to the profile store. By default the profile status will be enabled. * * @param profileId the id of the profile to save * @param profile the information of the profile * @throws MethodNotAllowedException if trying to update the Native profile */ public void saveProfile(ProfileId profileId, Profile profile) throws MethodNotAllowedException { Transactionals.execute(transactional, context -> { ProfileDataset dataset = getProfileDataset(context); if (profileId.equals(ProfileId.NATIVE)) { try { dataset.getProfile(profileId); throw new MethodNotAllowedException(String.format("Profile Native %s already exists. It cannot be updated", profileId.getScopedName())); } catch (NotFoundException e) { // if native profile is not found, we can add it to the dataset } } dataset.saveProfile(profileId, profile); }, MethodNotAllowedException.class); }
/** * Delete all profiles in a given namespace. Deleting all profiles in SYSTEM namespace is not allowed. * * @param namespaceId the id of the namespace */ public void deleteAllProfiles(NamespaceId namespaceId) throws MethodNotAllowedException, NotFoundException, ProfileConflictException { if (namespaceId.equals(NamespaceId.SYSTEM)) { throw new MethodNotAllowedException("Deleting all system profiles is not allowed."); } List<ProfileId> deleted = new ArrayList<>(); Transactionals.execute(transactional, context -> { ProfileDataset profileDataset = getProfileDataset(context); AppMetadataStore appMetadataStore = AppMetadataStore.create(cConf, context, datasetFramework); List<Profile> profiles = profileDataset.getProfiles(namespaceId, false); for (Profile profile : profiles) { ProfileId profileId = namespaceId.profile(profile.getName()); deleteProfile(profileDataset, appMetadataStore, profileId, profile); deleted.add(profileId); } }, ProfileConflictException.class, NotFoundException.class); // delete the metrics for (ProfileId profileId : deleted) { deleteMetrics(profileId); } }
/** * Delete all profiles in a given namespace. Deleting all profiles in SYSTEM namespace is not allowed. * * @param namespaceId the id of the namespace */ public void deleteAllProfiles(NamespaceId namespaceId) throws MethodNotAllowedException, NotFoundException, ProfileConflictException { if (namespaceId.equals(NamespaceId.SYSTEM)) { throw new MethodNotAllowedException("Deleting all system profiles is not allowed."); } List<ProfileId> deleted = new ArrayList<>(); Transactionals.execute(transactional, context -> { ProfileDataset profileDataset = getProfileDataset(context); AppMetadataStore appMetadataStore = AppMetadataStore.create(cConf, context, datasetFramework); List<Profile> profiles = profileDataset.getProfiles(namespaceId, false); for (Profile profile : profiles) { ProfileId profileId = namespaceId.profile(profile.getName()); deleteProfile(profileDataset, appMetadataStore, profileId, profile); deleted.add(profileId); } }, ProfileConflictException.class, NotFoundException.class); // delete the metrics for (ProfileId profileId : deleted) { deleteMetrics(profileId); } }
/** * Deletes the profile from the profile store. Native profile cannot be deleted. * Other profile deletion must satisfy the following: * 1. Profile must exist and must be DISABLED * 2. Profile must not be assigned to any entities. Profiles can be assigned to an entity by setting a preference * or a schedule property. * 3. There must be no active program runs using this profile * * @param profileId the id of the profile to delete * @throws NotFoundException if the profile is not found * @throws ProfileConflictException if the profile is enabled * @throws MethodNotAllowedException if trying to delete the Native profile */ public void deleteProfile(ProfileId profileId) throws MethodNotAllowedException, NotFoundException, ProfileConflictException { if (profileId.equals(ProfileId.NATIVE)) { throw new MethodNotAllowedException(String.format("Profile Native %s cannot be deleted.", profileId.getScopedName())); } Transactionals.execute(transactional, context -> { ProfileDataset profileDataset = getProfileDataset(context); Profile profile = profileDataset.getProfile(profileId); AppMetadataStore appMetadataStore = AppMetadataStore.create(cConf, context, datasetFramework); deleteProfile(profileDataset, appMetadataStore, profileId, profile); }, NotFoundException.class, ProfileConflictException.class); deleteMetrics(profileId); }
/** * Deletes the profile from the profile store. Native profile cannot be deleted. * Other profile deletion must satisfy the following: * 1. Profile must exist and must be DISABLED * 2. Profile must not be assigned to any entities. Profiles can be assigned to an entity by setting a preference * or a schedule property. * 3. There must be no active program runs using this profile * * @param profileId the id of the profile to delete * @throws NotFoundException if the profile is not found * @throws ProfileConflictException if the profile is enabled * @throws MethodNotAllowedException if trying to delete the Native profile */ public void deleteProfile(ProfileId profileId) throws MethodNotAllowedException, NotFoundException, ProfileConflictException { if (profileId.equals(ProfileId.NATIVE)) { throw new MethodNotAllowedException(String.format("Profile Native %s cannot be deleted.", profileId.getScopedName())); } Transactionals.execute(transactional, context -> { ProfileDataset profileDataset = getProfileDataset(context); Profile profile = profileDataset.getProfile(profileId); AppMetadataStore appMetadataStore = AppMetadataStore.create(cConf, context, datasetFramework); deleteProfile(profileDataset, appMetadataStore, profileId, profile); }, NotFoundException.class, ProfileConflictException.class); deleteMetrics(profileId); }