use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by cdapio.
the class ProfileService method saveProfile.
/**
* 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 or creating a new profile when disallowed.
*/
public void saveProfile(ProfileId profileId, Profile profile) throws MethodNotAllowedException {
TransactionRunners.run(transactionRunner, context -> {
if (!cConf.getBoolean(Constants.Profile.UPDATE_ALLOWED)) {
throw new MethodNotAllowedException("Compute profile creation and update are not allowed");
}
ProfileStore dataset = ProfileStore.get(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);
}
use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by cdapio.
the class CoreSchedulerService method execute.
@SuppressWarnings("UnusedReturnValue")
private <V, T extends Exception> V execute(StoreQueueAndProfileTxRunnable<V, ? extends Exception> runnable, Class<? extends T> tClass) throws T {
return TransactionRunners.run(transactionRunner, context -> {
ProgramScheduleStoreDataset store = Schedulers.getScheduleStore(context);
ProfileStore profileStore = ProfileStore.get(context);
JobQueueTable queue = JobQueueTable.getJobQueue(context, cConf);
return runnable.run(store, queue, profileStore);
}, tClass);
}
use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by cdapio.
the class PreferencesService method setConfig.
/**
* Validate the profile status is enabled and set the preferences in same transaction
*/
private void setConfig(EntityId entityId, Map<String, String> propertyMap) throws NotFoundException, ProfileConflictException, BadRequestException {
TransactionRunners.run(transactionRunner, context -> {
ProfileStore profileStore = ProfileStore.get(context);
PreferencesTable preferencesTable = new PreferencesTable(context);
setConfig(profileStore, preferencesTable, entityId, propertyMap);
}, NotFoundException.class, ProfileConflictException.class, BadRequestException.class);
}
use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by caskdata.
the class PreferencesService method addProperties.
/**
* Set instance level preferences if they are not already set. Only adds the properties that don't already exist.
*
* @param properties the preferences to add
* @return the preference keys that were added
*/
public Set<String> addProperties(Map<String, String> properties) throws NotFoundException, ProfileConflictException, BadRequestException {
InstanceId instanceId = new InstanceId("");
Set<String> added = new HashSet<>();
TransactionRunners.run(transactionRunner, context -> {
ProfileStore profileStore = ProfileStore.get(context);
PreferencesTable preferencesTable = new PreferencesTable(context);
Map<String, String> oldProperties = preferencesTable.getPreferences(instanceId).getProperties();
Map<String, String> newProperties = new HashMap<>(properties);
added.addAll(Sets.difference(newProperties.keySet(), oldProperties.keySet()));
newProperties.putAll(oldProperties);
setConfig(profileStore, preferencesTable, instanceId, newProperties);
}, NotFoundException.class, ProfileConflictException.class, BadRequestException.class);
return added;
}
use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by caskdata.
the class CoreSchedulerService method execute.
@SuppressWarnings({ "UnusedReturnValue", "SameParameterValue" })
private <V, T extends Exception> V execute(StoreAndProfileTxRunnable<V, ? extends Exception> runnable, Class<? extends T> tClass) throws T {
return TransactionRunners.run(transactionRunner, context -> {
ProgramScheduleStoreDataset store = Schedulers.getScheduleStore(context);
ProfileStore profileStore = ProfileStore.get(context);
return runnable.run(store, profileStore);
}, tClass);
}
Aggregations