Search in sources :

Example 1 with ProfileStore

use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by caskdata.

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 2 with ProfileStore

use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by caskdata.

the class ProfileService method deleteAllProfiles.

/**
 * 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<>();
    TransactionRunners.run(transactionRunner, context -> {
        ProfileStore profileStore = ProfileStore.get(context);
        AppMetadataStore appMetadataStore = AppMetadataStore.create(context);
        List<Profile> profiles = profileStore.getProfiles(namespaceId, false);
        for (Profile profile : profiles) {
            ProfileId profileId = namespaceId.profile(profile.getName());
            deleteProfile(profileStore, appMetadataStore, profileId, profile);
            deleted.add(profileId);
        }
    }, ProfileConflictException.class, NotFoundException.class);
    // delete the metrics
    for (ProfileId profileId : deleted) {
        deleteMetrics(profileId);
    }
}
Also used : ProfileId(io.cdap.cdap.proto.id.ProfileId) MethodNotAllowedException(io.cdap.cdap.common.MethodNotAllowedException) AppMetadataStore(io.cdap.cdap.internal.app.store.AppMetadataStore) ArrayList(java.util.ArrayList) ProfileStore(io.cdap.cdap.internal.app.store.profile.ProfileStore) Profile(io.cdap.cdap.proto.profile.Profile)

Example 3 with ProfileStore

use of io.cdap.cdap.internal.app.store.profile.ProfileStore in project cdap by caskdata.

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 4 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 5 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)7 MethodNotAllowedException (io.cdap.cdap.common.MethodNotAllowedException)3 ProgramScheduleStoreDataset (io.cdap.cdap.internal.app.runtime.schedule.store.ProgramScheduleStoreDataset)2 AppMetadataStore (io.cdap.cdap.internal.app.store.AppMetadataStore)2 Profile (io.cdap.cdap.proto.profile.Profile)2 NotFoundException (io.cdap.cdap.common.NotFoundException)1 JobQueueTable (io.cdap.cdap.internal.app.runtime.schedule.queue.JobQueueTable)1 InstanceId (io.cdap.cdap.proto.id.InstanceId)1 ProfileId (io.cdap.cdap.proto.id.ProfileId)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1