use of io.cdap.cdap.spi.data.StructuredTable 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.StructuredTable in project cdap by caskdata.
the class TetheringStore method deletePeer.
/**
* Deletes a peer
*
* @param peerName name of the peer
* @throws IOException if deleting the table fails
* @throws PeerNotFoundException if the peer is not found
*/
public void deletePeer(String peerName) throws IOException, PeerNotFoundException {
TransactionRunners.run(transactionRunner, context -> {
StructuredTable tetheringTable = context.getTable(StoreDefinition.TetheringStore.TETHERING);
// throw PeerNotFoundException if peer doesn't exist
getPeer(tetheringTable, peerName);
tetheringTable.delete(Collections.singleton(Fields.stringField(StoreDefinition.TetheringStore.PEER_NAME_FIELD, peerName)));
}, IOException.class, PeerNotFoundException.class);
}
use of io.cdap.cdap.spi.data.StructuredTable 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));
}
}
}
use of io.cdap.cdap.spi.data.StructuredTable in project cdap by caskdata.
the class CapabilityStatusStore method deleteCapabilityOperation.
/**
* Deletes capability operations
*
* @param capability
* @throws IOException
*/
public void deleteCapabilityOperation(String capability) throws IOException {
TransactionRunners.run(transactionRunner, context -> {
StructuredTable capabilityTable = context.getTable(StoreDefinition.CapabilitiesStore.CAPABILITY_OPERATIONS);
capabilityTable.delete(Collections.singleton(Fields.stringField(StoreDefinition.CapabilitiesStore.NAME_FIELD, capability)));
}, IOException.class);
}
use of io.cdap.cdap.spi.data.StructuredTable in project cdap by caskdata.
the class CapabilityStatusStore method addOrUpdateCapabilityOperation.
/**
* Adds or update capability operations
*
* @param capability
* @param actionType
* @param config
* @throws IOException
*/
public void addOrUpdateCapabilityOperation(String capability, CapabilityAction actionType, CapabilityConfig config) throws IOException {
TransactionRunners.run(transactionRunner, context -> {
StructuredTable capabilityTable = context.getTable(StoreDefinition.CapabilitiesStore.CAPABILITY_OPERATIONS);
Collection<Field<?>> fields = new ArrayList<>();
fields.add(Fields.stringField(StoreDefinition.CapabilitiesStore.NAME_FIELD, capability));
fields.add(Fields.stringField(StoreDefinition.CapabilitiesStore.ACTION_FIELD, actionType.name().toLowerCase()));
fields.add(Fields.stringField(StoreDefinition.CapabilitiesStore.CONFIG_FIELD, GSON.toJson(config)));
capabilityTable.upsert(fields);
}, IOException.class);
}
Aggregations