Search in sources :

Example 11 with StructuredTable

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);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) ArrayList(java.util.ArrayList)

Example 12 with StructuredTable

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);
}
Also used : StructuredTable(io.cdap.cdap.spi.data.StructuredTable)

Example 13 with StructuredTable

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));
        }
    }
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) StructuredRow(io.cdap.cdap.spi.data.StructuredRow) Range(io.cdap.cdap.spi.data.table.field.Range)

Example 14 with StructuredTable

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);
}
Also used : StructuredTable(io.cdap.cdap.spi.data.StructuredTable)

Example 15 with StructuredTable

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);
}
Also used : Field(io.cdap.cdap.spi.data.table.field.Field) StructuredTable(io.cdap.cdap.spi.data.StructuredTable) ArrayList(java.util.ArrayList)

Aggregations

StructuredTable (io.cdap.cdap.spi.data.StructuredTable)59 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)30 Field (io.cdap.cdap.spi.data.table.field.Field)22 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)11 Range (io.cdap.cdap.spi.data.table.field.Range)9 ArtifactNotFoundException (io.cdap.cdap.common.ArtifactNotFoundException)7 TableNotFoundException (io.cdap.cdap.spi.data.TableNotFoundException)6 HashMap (java.util.HashMap)6 ArtifactRange (io.cdap.cdap.api.artifact.ArtifactRange)5 Map (java.util.Map)5 ApplicationClass (io.cdap.cdap.api.artifact.ApplicationClass)4 PluginNotExistsException (io.cdap.cdap.internal.app.runtime.plugin.PluginNotExistsException)4 List (java.util.List)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Gson (com.google.gson.Gson)3 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)3 PluginClass (io.cdap.cdap.api.plugin.PluginClass)3 ArtifactAlreadyExistsException (io.cdap.cdap.common.ArtifactAlreadyExistsException)3 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)3