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);
}
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);
}
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);
}
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;
});
}
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;
});
}
Aggregations