use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class TetheringStore method updatePeerTimestamp.
/**
* Updates the last connection timestamp for the peer.
*
* @param peerName name of the peer
* @throws IOException if updating the table fails
*/
public void updatePeerTimestamp(String peerName) throws IOException {
TransactionRunners.run(transactionRunner, context -> {
Collection<Field<?>> fields = new ArrayList<>();
fields.add(Fields.stringField(StoreDefinition.TetheringStore.PEER_NAME_FIELD, peerName));
fields.add(Fields.longField(StoreDefinition.TetheringStore.LAST_CONNECTION_TIME_FIELD, System.currentTimeMillis()));
StructuredTable tetheringTable = context.getTable(StoreDefinition.TetheringStore.TETHERING);
tetheringTable.update(fields);
}, IOException.class);
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class TetheringStore method updatePeerStatusAndTimestamp.
/**
* Updates tethering status and last connection time for a peer.
*
* @param peerName name of the peer
* @param tetheringStatus status of tetherinf with the peer
* @throws IOException if updating the table fails
*/
public void updatePeerStatusAndTimestamp(String peerName, TetheringStatus tetheringStatus) throws IOException {
TransactionRunners.run(transactionRunner, context -> {
Collection<Field<?>> fields = new ArrayList<>();
fields.add(Fields.stringField(StoreDefinition.TetheringStore.PEER_NAME_FIELD, peerName));
fields.add(Fields.stringField(StoreDefinition.TetheringStore.TETHERING_STATE_FIELD, tetheringStatus.toString()));
fields.add(Fields.longField(StoreDefinition.TetheringStore.LAST_CONNECTION_TIME_FIELD, System.currentTimeMillis()));
StructuredTable tetheringTable = context.getTable(StoreDefinition.TetheringStore.TETHERING);
tetheringTable.update(fields);
}, IOException.class);
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class TetheringStore method updatePeerStatus.
/**
* Updates tethering status for a peer.
*
* @param peerName name of the peer
* @param tetheringStatus status of tethering with the peer
* @throws IOException if updating the table fails
*/
public void updatePeerStatus(String peerName, TetheringStatus tetheringStatus) throws IOException {
TransactionRunners.run(transactionRunner, context -> {
Collection<Field<?>> fields = new ArrayList<>();
fields.add(Fields.stringField(StoreDefinition.TetheringStore.PEER_NAME_FIELD, peerName));
fields.add(Fields.stringField(StoreDefinition.TetheringStore.TETHERING_STATE_FIELD, tetheringStatus.toString()));
StructuredTable tetheringTable = context.getTable(StoreDefinition.TetheringStore.TETHERING);
tetheringTable.update(fields);
}, IOException.class);
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class AppMetadataStore method recordProgramSuspendResume.
private RunRecordDetail recordProgramSuspendResume(ProgramRunId programRunId, byte[] sourceId, RunRecordDetail existing, String action, long timestamp) throws IOException {
ProgramRunStatus toStatus = ProgramRunStatus.SUSPENDED;
if (action.equals("resume")) {
toStatus = ProgramRunStatus.RUNNING;
}
// Delete the old run record
delete(existing);
List<Field<?>> key = getProgramRunInvertedTimeKey(TYPE_RUN_RECORD_ACTIVE, programRunId, existing.getStartTs());
RunRecordDetail.Builder builder = RunRecordDetail.builder(existing).setStatus(toStatus).setSourceId(sourceId);
if (timestamp != -1) {
if (action.equals("resume")) {
builder.setResumeTime(timestamp);
} else {
builder.setSuspendTime(timestamp);
}
}
RunRecordDetail meta = builder.build();
writeToRunRecordTableWithPrimaryKeys(key, meta);
LOG.trace("Recorded {} for program {}", toStatus, programRunId);
return meta;
}
use of io.cdap.cdap.spi.data.table.field.Field in project cdap by caskdata.
the class AppMetadataStore method scanActiveRuns.
/**
* Scans active runs, starting from the given cursor.
*
* @param cursor the cursor to start the scan. A cursor can be obtained
* from the call to the given {@link BiConsumer} for some previous scan, or use
* {@link Cursor#EMPTY} to start a scan at the beginning.
* @param limit maximum number of records to scan
* @param consumer a {@link BiConsumer} to consume the scan result
* @throws IOException if failed to query the storage
*/
public void scanActiveRuns(Cursor cursor, int limit, BiConsumer<Cursor, RunRecordDetail> consumer) throws IOException {
Collection<Field<?>> begin = cursor.fields;
if (begin.isEmpty()) {
begin = getRunRecordStatusPrefix(TYPE_RUN_RECORD_ACTIVE);
}
Range range = Range.create(begin, cursor.bound, getRunRecordStatusPrefix(TYPE_RUN_RECORD_ACTIVE), Range.Bound.INCLUSIVE);
StructuredTable table = getRunRecordsTable();
try (CloseableIterator<StructuredRow> iterator = table.scan(range, limit)) {
while (iterator.hasNext()) {
StructuredRow row = iterator.next();
consumer.accept(new Cursor(row.getPrimaryKeys(), Range.Bound.EXCLUSIVE), deserializeRunRecordMeta(row));
}
}
}
Aggregations