use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.
the class AppMetadataStore method getNonCompleteRuns.
private Map<ProgramRunId, RunRecordMeta> getNonCompleteRuns(@Nullable ProgramId programId, String recordType, final long startTime, final long endTime, int limit, Predicate<RunRecordMeta> filter) {
Predicate<RunRecordMeta> valuePredicate = andPredicate(new Predicate<RunRecordMeta>() {
@Override
public boolean apply(RunRecordMeta input) {
return input.getStartTs() >= startTime && input.getStartTs() < endTime;
}
}, filter);
if (programId == null || !programId.getVersion().equals(ApplicationId.DEFAULT_VERSION)) {
MDSKey key = getProgramKeyBuilder(recordType, programId).build();
return getProgramRunIdMap(listKV(key, null, RunRecordMeta.class, limit, valuePredicate));
}
Predicate<MDSKey> keyPredicate = new AppVersionPredicate(ApplicationId.DEFAULT_VERSION);
MDSKey key = getProgramKeyBuilder(recordType, programId).build();
Map<MDSKey, RunRecordMeta> newRecords = listKV(key, null, RunRecordMeta.class, limit, keyPredicate, valuePredicate);
int remaining = limit - newRecords.size();
if (remaining > 0 && !upgradeComplete.get()) {
// We need to scan twice since the scan key is modified based on whether we include the app version or not.
key = getVersionLessProgramKeyBuilder(recordType, programId).build();
Map<MDSKey, RunRecordMeta> oldRecords = listKV(key, null, RunRecordMeta.class, remaining, keyPredicate, valuePredicate);
newRecords.putAll(oldRecords);
}
return getProgramRunIdMap(newRecords);
}
use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.
the class AppMetadataStore method recordProgramSuspendResume.
private void recordProgramSuspendResume(ProgramId programId, String pid, String action) {
String fromType = TYPE_RUN_RECORD_STARTED;
String toType = TYPE_RUN_RECORD_SUSPENDED;
ProgramRunStatus toStatus = ProgramRunStatus.SUSPENDED;
if (action.equals("resume")) {
fromType = TYPE_RUN_RECORD_SUSPENDED;
toType = TYPE_RUN_RECORD_STARTED;
toStatus = ProgramRunStatus.RUNNING;
}
MDSKey key = getProgramKeyBuilder(fromType, programId).add(pid).build();
RunRecordMeta record = get(key, RunRecordMeta.class);
// Check without the version string only for default version
if (!upgradeComplete.get() && record == null && (programId.getVersion().equals(ApplicationId.DEFAULT_VERSION))) {
key = getVersionLessProgramKeyBuilder(fromType, programId).add(pid).build();
record = get(key, RunRecordMeta.class);
}
if (record == null) {
String msg = String.format("No meta for %s run record for namespace %s app %s program type %s " + "program %s pid %s exists", action.equals("suspend") ? "started" : "suspended", programId.getNamespace(), programId.getApplication(), programId.getType().name(), programId.getProgram(), pid);
LOG.error(msg);
throw new IllegalArgumentException(msg);
}
// Since the key contains the RunId/PID in addition to the programId, it is ok to deleteAll.
deleteAll(key);
key = getProgramKeyBuilder(toType, programId).add(pid).build();
write(key, new RunRecordMeta(record, null, toStatus));
}
use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.
the class AppMetadataStore method recordProgramStop.
private void recordProgramStop(ProgramId programId, String pid, long stopTs, ProgramRunStatus runStatus, @Nullable BasicThrowable failureCause, MDSKey.Builder builder) {
MDSKey key = getProgramKeyBuilder(TYPE_RUN_RECORD_STARTED, programId).add(pid).build();
RunRecordMeta started = getFirst(key, RunRecordMeta.class);
// Check without the version string only for default version
if (!upgradeComplete.get() && started == null && (programId.getVersion().equals(ApplicationId.DEFAULT_VERSION))) {
key = getVersionLessProgramKeyBuilder(TYPE_RUN_RECORD_STARTED, programId).add(pid).build();
started = getFirst(key, RunRecordMeta.class);
}
if (started == null) {
String msg = String.format("No meta for started run record for namespace %s app %s version %s program type %s " + "program %s pid %s exists", programId.getNamespace(), programId.getApplication(), programId.getVersion(), programId.getType().name(), programId.getProgram(), pid);
LOG.error(msg);
throw new IllegalArgumentException(msg);
}
if (started.getSystemArgs() != null && started.getSystemArgs().containsKey(ProgramOptionConstants.WORKFLOW_NAME)) {
addWorkflowNodeState(programId, pid, started.getSystemArgs(), runStatus, failureCause);
}
// Since the key contains the RunId/PID in addition to the programId, it is ok to deleteAll.
deleteAll(key);
key = builder.add(getInvertedTsKeyPart(started.getStartTs())).add(pid).build();
write(key, new RunRecordMeta(started, stopTs, runStatus));
}
use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.
the class MetricsDataMigrator method findMetricsTableVersion.
@Nullable
private Version findMetricsTableVersion(MetricHBaseTableUtil metricHBaseTableUtil) {
// Figure out what is the latest working version of CDAP
// 1) if latest is 2.8.x - nothing to do, if "pre-2.8", proceed to next step.
// 2) find a most recent metrics table: start by looking for 2.7, then 2.6
// 3) if we find 2.7 - we will migrate data from 2.7 table, if not - migrate data from 2.6 metrics table
// todo - use UpgradeTool to figure out if version is 2.8.x, return if it is 2.8.x
String tableName27 = cConf.get(Constants.Metrics.METRICS_TABLE_PREFIX, UpgradeMetricsConstants.DEFAULT_METRICS_TABLE_PREFIX) + ".agg";
// versions older than 2.7, has two metrics table, identified by system and user prefix
String tableName26 = "system." + tableName27;
DefaultDatasetNamespace defaultDatasetNamespace = new DefaultDatasetNamespace(cConf);
String metricsEntityTable26 = defaultDatasetNamespace.namespace(NamespaceId.SYSTEM, tableName26);
String metricsEntityTable27 = defaultDatasetNamespace.namespace(NamespaceId.SYSTEM, tableName27);
Version version = null;
try (HBaseAdmin hAdmin = new HBaseAdmin(hConf)) {
for (HTableDescriptor desc : hAdmin.listTables()) {
if (desc.getNameAsString().equals(metricsEntityTable27)) {
System.out.println("Matched HBase Table Name For Migration " + desc.getNameAsString());
version = metricHBaseTableUtil.getVersion(desc);
version = verifyVersion(Version.VERSION_2_7, version);
if (version == null) {
return null;
}
break;
}
if (desc.getNameAsString().equals(metricsEntityTable26)) {
System.out.println("Matched HBase Table Name For Migration " + desc.getNameAsString());
version = metricHBaseTableUtil.getVersion(desc);
version = verifyVersion(Version.VERSION_2_6_OR_LOWER, version);
if (version == null) {
return null;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return version;
}
use of co.cask.cdap.data2.dataset2.lib.table.hbase.MetricHBaseTableUtil.Version in project cdap by caskdata.
the class MetricsDataMigrator method migrateMetricsTableFromVersion27.
private void migrateMetricsTableFromVersion27(Version version) throws DataMigrationException {
EntityTable entityTable = new EntityTable(getOrCreateMetricsTable(entityTableName, DatasetProperties.EMPTY));
MetricsTable metricsTable = getOrCreateMetricsTable(metricsTableName, DatasetProperties.EMPTY);
System.out.println("Migrating Metrics Data from table : " + metricsTableName);
migrateMetricsData(entityTable, metricsTable, null, version);
}
Aggregations