Search in sources :

Example 1 with MetadataStoreDataset

use of co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset in project cdap by caskdata.

the class ProgramNotificationSubscriberServiceTest method testAppSpecNotRequiredToWriteState.

@Test
public void testAppSpecNotRequiredToWriteState() throws Exception {
    Injector injector = AppFabricTestHelper.getInjector();
    CConfiguration cConf = injector.getInstance(CConfiguration.class);
    ProgramNotificationSubscriberService programNotificationSubscriberService = injector.getInstance(ProgramNotificationSubscriberService.class);
    programNotificationSubscriberService.startAndWait();
    DatasetFramework datasetFramework = injector.getInstance(DatasetFramework.class);
    TransactionExecutorFactory txExecutorFactory = injector.getInstance(TransactionExecutorFactory.class);
    DatasetId storeTable = NamespaceId.SYSTEM.dataset(Constants.AppMetaStore.TABLE);
    Table table = DatasetsUtil.getOrCreateDataset(datasetFramework, storeTable, Table.class.getName(), DatasetProperties.EMPTY, Collections.<String, String>emptyMap());
    final AppMetadataStore metadataStoreDataset = new AppMetadataStore(table, cConf, new AtomicBoolean(false));
    final TransactionExecutor txnl = txExecutorFactory.createExecutor(Collections.singleton((TransactionAware) metadataStoreDataset));
    ProgramStateWriter programStateWriter = injector.getInstance(ProgramStateWriter.class);
    ProgramId programId = NamespaceId.DEFAULT.app("someapp").program(ProgramType.SERVICE, "s");
    ProgramOptions programOptions = new SimpleProgramOptions(programId);
    final ProgramRunId runId = programId.run(RunIds.generate());
    programStateWriter.start(runId, programOptions, null);
    Tasks.waitFor(ProgramRunStatus.STARTING, () -> txnl.execute(() -> {
        RunRecordMeta meta = metadataStoreDataset.getRun(runId);
        return meta == null ? null : meta.getStatus();
    }), 10, TimeUnit.SECONDS);
    programStateWriter.running(runId, UUID.randomUUID().toString());
    Tasks.waitFor(ProgramRunStatus.RUNNING, () -> txnl.execute(() -> {
        RunRecordMeta meta = metadataStoreDataset.getRun(runId);
        return meta == null ? null : meta.getStatus();
    }), 10, TimeUnit.SECONDS);
    programStateWriter.killed(runId);
    Tasks.waitFor(ProgramRunStatus.KILLED, () -> txnl.execute(() -> {
        RunRecordMeta meta = metadataStoreDataset.getRun(runId);
        return meta == null ? null : meta.getStatus();
    }), 10, TimeUnit.SECONDS);
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) AppMetadataStore(co.cask.cdap.internal.app.store.AppMetadataStore) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) TransactionExecutor(org.apache.tephra.TransactionExecutor) ProgramId(co.cask.cdap.proto.id.ProgramId) CConfiguration(co.cask.cdap.common.conf.CConfiguration) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(co.cask.cdap.app.runtime.ProgramOptions) TransactionExecutorFactory(co.cask.cdap.data2.transaction.TransactionExecutorFactory) DatasetId(co.cask.cdap.proto.id.DatasetId) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgramStateWriter(co.cask.cdap.app.runtime.ProgramStateWriter) Injector(com.google.inject.Injector) TransactionAware(org.apache.tephra.TransactionAware) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Example 2 with MetadataStoreDataset

use of co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset in project cdap by caskdata.

the class ProfileStore method add.

/**
 * Add the profile to the profile store.
 *
 * @param profileId the id of the profile to add
 * @param profile the information of the profile
 * @throws IOException if there was an IO error adding the profile
 * @throws AlreadyExistsException if the profile already exists
 */
public void add(ProfileId profileId, Profile profile) throws IOException, AlreadyExistsException {
    Transactionals.execute(transactional, context -> {
        MetadataStoreDataset mds = getMDS(context);
        // make sure that a profile doesn't exist
        MDSKey rowKey = getRowKey(profileId);
        Profile value = mds.get(rowKey, Profile.class);
        if (value != null) {
            throw new AlreadyExistsException(profileId, String.format("Profile '%s' already exists.", profile.getName()));
        }
        mds.write(rowKey, profile);
    }, IOException.class, AlreadyExistsException.class);
}
Also used : AlreadyExistsException(co.cask.cdap.common.AlreadyExistsException) MetadataStoreDataset(co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) Profile(co.cask.cdap.proto.profile.Profile)

Example 3 with MetadataStoreDataset

use of co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset in project cdap by caskdata.

the class ProfileStore method delete.

/**
 * Deletes the profile from the profile store
 *
 * @param profileId the id of the profile to delete
 * @throws IOException if there was an IO error deleting the profile
 * @throws NotFoundException if the profile is not found
 */
public void delete(ProfileId profileId) throws IOException, NotFoundException {
    Transactionals.execute(transactional, context -> {
        MetadataStoreDataset mds = getMDS(context);
        MDSKey rowKey = getRowKey(profileId);
        Profile value = getMDS(context).get(rowKey, Profile.class);
        if (value == null) {
            throw new NotFoundException(profileId);
        }
        mds.delete(getRowKey(profileId));
    }, IOException.class, NotFoundException.class);
}
Also used : MetadataStoreDataset(co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) NotFoundException(co.cask.cdap.common.NotFoundException) Profile(co.cask.cdap.proto.profile.Profile)

Example 4 with MetadataStoreDataset

use of co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset in project cdap by caskdata.

the class MDSNotificationFeedStore method deleteNotificationFeed.

@Override
public NotificationFeedInfo deleteNotificationFeed(final NotificationFeedId feed) {
    return Transactionals.execute(transactional, context -> {
        MDSKey feedKey = getKey(TYPE_NOTIFICATION_FEED, feed.getNamespace(), feed.getCategory(), feed.getFeed());
        MetadataStoreDataset metaStore = getMetadataStore(context);
        NotificationFeedInfo existing = metaStore.getFirst(feedKey, NotificationFeedInfo.class);
        if (existing != null) {
            metaStore.deleteAll(feedKey);
        }
        return existing;
    });
}
Also used : MetadataStoreDataset(co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo)

Example 5 with MetadataStoreDataset

use of co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset in project cdap by caskdata.

the class MDSNotificationFeedStore method createNotificationFeed.

@Override
public NotificationFeedInfo createNotificationFeed(final NotificationFeedInfo feed) {
    return Transactionals.execute(transactional, context -> {
        MetadataStoreDataset metaStore = getMetadataStore(context);
        MDSKey feedKey = getKey(TYPE_NOTIFICATION_FEED, feed.getNamespace(), feed.getCategory(), feed.getFeed());
        NotificationFeedInfo existing = metaStore.getFirst(feedKey, NotificationFeedInfo.class);
        if (existing != null) {
            return existing;
        }
        metaStore.write(feedKey, feed);
        return null;
    });
}
Also used : MetadataStoreDataset(co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset) MDSKey(co.cask.cdap.data2.dataset2.lib.table.MDSKey) NotificationFeedInfo(co.cask.cdap.proto.notification.NotificationFeedInfo)

Aggregations

MDSKey (co.cask.cdap.data2.dataset2.lib.table.MDSKey)4 MetadataStoreDataset (co.cask.cdap.data2.dataset2.lib.table.MetadataStoreDataset)4 NotificationFeedInfo (co.cask.cdap.proto.notification.NotificationFeedInfo)2 Profile (co.cask.cdap.proto.profile.Profile)2 Table (co.cask.cdap.api.dataset.table.Table)1 ProgramOptions (co.cask.cdap.app.runtime.ProgramOptions)1 ProgramStateWriter (co.cask.cdap.app.runtime.ProgramStateWriter)1 AlreadyExistsException (co.cask.cdap.common.AlreadyExistsException)1 NotFoundException (co.cask.cdap.common.NotFoundException)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)1 TransactionExecutorFactory (co.cask.cdap.data2.transaction.TransactionExecutorFactory)1 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)1 AppMetadataStore (co.cask.cdap.internal.app.store.AppMetadataStore)1 RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)1 DatasetId (co.cask.cdap.proto.id.DatasetId)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)1 Injector (com.google.inject.Injector)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1