use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey 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;
});
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method recordProgramStart.
/**
* Logs initialization of program run and persists program status to {@link ProgramRunStatus#STARTING}.
* @param programRunId run id of the program
* @param twillRunId Twill run id
* @param systemArgs the system arguments for this program run
* @param sourceId unique id representing the source of program run status, such as the message id of the program
* run status notification in TMS. The source id must increase as the recording time of the program
* run status increases, so that the attempt to persist program run status older than the existing
* program run status will be ignored
* @return {@link ProgramRunStatus#STARTING} if it is successfully persisted, {@code null} otherwise.
*/
public ProgramRunStatus recordProgramStart(ProgramRunId programRunId, String twillRunId, Map<String, String> systemArgs, byte[] sourceId) {
MDSKey.Builder keyBuilder = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTING, programRunId.getParent());
RunRecordMeta existing = getRun(programRunId);
if (existing == null) {
LOG.warn("Ignoring unexpected transition of program run {} to program state {} with no existing run record.", programRunId, ProgramRunStatus.STARTING);
return null;
}
if (!isValid(existing, sourceId, "start")) {
return null;
}
if (existing.getStatus() != null && existing.getStatus() != ProgramRunStatus.STARTING) {
LOG.warn("Ignoring unexpected transition of program run {} from program state {} to program state {}.", programRunId, existing.getStatus(), ProgramRunStatus.STARTING);
return null;
}
if (systemArgs != null && systemArgs.containsKey(ProgramOptionConstants.WORKFLOW_NAME)) {
// Program is started by Workflow. Add row corresponding to its node state.
addWorkflowNodeState(programRunId, systemArgs, ProgramRunStatus.STARTING, null, sourceId);
}
// Delete the old run record
delete(existing);
MDSKey key = keyBuilder.add(programRunId.getRun()).build();
RunRecordMeta meta = RunRecordMeta.builder(existing).setStatus(ProgramRunStatus.STARTING).setTwillRunId(twillRunId).setSourceId(sourceId).build();
write(key, meta);
return ProgramRunStatus.STARTING;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getActiveRuns.
public Map<ProgramRunId, RunRecordMeta> getActiveRuns(NamespaceId namespaceId) {
// TODO CDAP-12361 should consolidate these methods and get rid of duplicate / unnecessary methods.
Predicate<RunRecordMeta> timePredicate = getTimeRangePredicate(0, Long.MAX_VALUE);
MDSKey key = getNamespaceKeyBuilder(TYPE_RUN_RECORD_STARTING, namespaceId).build();
Map<ProgramRunId, RunRecordMeta> activeRuns = getProgramRunIdMap(listKV(key, null, RunRecordMeta.class, Integer.MAX_VALUE, timePredicate));
key = getNamespaceKeyBuilder(TYPE_RUN_RECORD_STARTED, namespaceId).build();
activeRuns.putAll(getProgramRunIdMap(listKV(key, null, RunRecordMeta.class, Integer.MAX_VALUE, timePredicate)));
key = getNamespaceKeyBuilder(TYPE_RUN_RECORD_SUSPENDED, namespaceId).build();
activeRuns.putAll(getProgramRunIdMap(listKV(key, null, RunRecordMeta.class, Integer.MAX_VALUE, timePredicate)));
return activeRuns;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getUnfinishedRun.
/**
* @return run records for runs that do not have start time in mds key for the run record.
*/
private RunRecordMeta getUnfinishedRun(ProgramRunId programRunId, String recordType) {
MDSKey runningKey = getProgramKeyBuilder(recordType, programRunId.getParent()).add(programRunId.getRun()).build();
RunRecordMeta runRecordMeta = get(runningKey, RunRecordMeta.class);
if (!upgradeComplete.get() && runRecordMeta == null && programRunId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
runningKey = getVersionLessProgramKeyBuilder(recordType, programRunId.getParent()).add(programRunId.getRun()).build();
return get(runningKey, RunRecordMeta.class);
}
return runRecordMeta;
}
use of io.cdap.cdap.data2.dataset2.lib.table.MDSKey in project cdap by caskdata.
the class AppMetadataStore method getCompletedRun.
private RunRecordMeta getCompletedRun(MDSKey completedKey, final String runid) {
// Get start time from RunId
long programStartSecs = RunIds.getTime(RunIds.fromString(runid), TimeUnit.SECONDS);
if (programStartSecs > -1) {
// If start time is found, run a get
MDSKey key = new MDSKey.Builder(completedKey).add(getInvertedTsKeyPart(programStartSecs)).add(runid).build();
return get(key, RunRecordMeta.class);
} else {
// If start time is not found, scan the table (backwards compatibility when run ids were random UUIDs)
MDSKey startKey = new MDSKey.Builder(completedKey).add(getInvertedTsScanKeyPart(Long.MAX_VALUE)).build();
MDSKey stopKey = new MDSKey.Builder(completedKey).add(getInvertedTsScanKeyPart(0)).build();
List<RunRecordMeta> runRecords = list(// Should have only one record for this runid
startKey, // Should have only one record for this runid
stopKey, // Should have only one record for this runid
RunRecordMeta.class, // Should have only one record for this runid
1, (input) -> input.getPid().equals(runid));
return Iterables.getFirst(runRecords, null);
}
}
Aggregations