Search in sources :

Example 6 with ProfileStore

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);
}
Also used : MethodNotAllowedException(io.cdap.cdap.common.MethodNotAllowedException) NotFoundException(io.cdap.cdap.common.NotFoundException) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore)

Example 7 with ProfileStore

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);
}
Also used : JobQueueTable(io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable) ProgramScheduleStoreDataset(io.cdap.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore)

Example 8 with ProfileStore

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);
}
Also used : ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore)

Example 9 with ProfileStore

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;
}
Also used : InstanceId(io.cdap.cdap.proto.id.InstanceId) HashMap(java.util.HashMap) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore) HashSet(java.util.HashSet)

Example 10 with ProfileStore

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);
}
Also used : ProgramScheduleStoreDataset(io.cdap.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore)

Aggregations

ProfileStore (io.cdap.cdap.internal.app.store.profile.ProfileStore)14 MethodNotAllowedException (io.cdap.cdap.common.MethodNotAllowedException)6 ProgramScheduleStoreDataset (io.cdap.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset)4 AppMetadataStore (io.cdap.cdap.internal.app.store.AppMetadataStore)4 Profile (io.cdap.cdap.proto.profile.Profile)4 NotFoundException (io.cdap.cdap.common.NotFoundException)2 JobQueueTable (io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable)2 InstanceId (io.cdap.cdap.proto.id.InstanceId)2 ProfileId (io.cdap.cdap.proto.id.ProfileId)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2