Search in sources :

Example 6 with Field

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

Example 7 with Field

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

Example 8 with Field

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

Example 9 with Field

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

Example 10 with Field

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));
        }
    }
}
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)

Aggregations

Field (io.cdap.cdap.spi.data.table.field.Field)72 StructuredRow (io.cdap.cdap.spi.data.StructuredRow)40 StructuredTable (io.cdap.cdap.spi.data.StructuredTable)33 ArrayList (java.util.ArrayList)33 Range (io.cdap.cdap.spi.data.table.field.Range)24 HashSet (java.util.HashSet)18 Map (java.util.Map)17 List (java.util.List)16 Nullable (javax.annotation.Nullable)16 CloseableIterator (io.cdap.cdap.api.dataset.lib.CloseableIterator)15 Collections (java.util.Collections)15 HashMap (java.util.HashMap)15 LinkedHashSet (java.util.LinkedHashSet)15 Set (java.util.Set)15 Fields (io.cdap.cdap.spi.data.table.field.Fields)14 Collection (java.util.Collection)14 LinkedHashMap (java.util.LinkedHashMap)14 Collectors (java.util.stream.Collectors)14 Optional (java.util.Optional)13 IOException (java.io.IOException)12