Exemplo n.º 1
0
 private void monitorAllTables(String database, DatabaseSchema dbSchema) {
   Set<String> tables = dbSchema.getTables();
   if (tables != null) {
     List<MonitorRequest<GenericTableSchema>> monitorRequests = Lists.newArrayList();
     for (String tableName : tables) {
       GenericTableSchema tableSchema = dbSchema.table(tableName, GenericTableSchema.class);
       Set<String> columns = tableSchema.getColumns();
       MonitorRequestBuilder<GenericTableSchema> monitorBuilder =
           MonitorRequestBuilder.builder(tableSchema);
       for (String column : columns) {
         monitorBuilder.addColumn(column);
       }
       monitorRequests.add(monitorBuilder.with(new MonitorSelect(true, true, true, true)).build());
     }
     this.callback.update(monitor(dbSchema, monitorRequests, callback), dbSchema);
   } else {
     LOG.warn(
         "No tables for schema {} for database {} for key {}", dbSchema, database, connectionInfo);
   }
 }
Exemplo n.º 2
0
 @SuppressWarnings(value = "unchecked")
 public TableUpdates tableUpdates(List<OperationResult> results) {
   Map<String, TableUpdate> map = new HashMap<>();
   for (OperationResult r : results) {
     for (Row<GenericTableSchema> row : r.getRows()) {
       String table = row.getTableSchema().getName();
       TableUpdate<GenericTableSchema> update;
       if (map.containsKey(table)) {
         update = map.get(table);
       } else {
         update = new TableUpdate<>();
         map.put(table, update);
       }
       GenericTableSchema ts = vtepSchema.table(table, GenericTableSchema.class);
       UUID rowId = row.getColumn(ts.column("_uuid", UUID.class)).getData();
       update.addRow(rowId, null, row);
     }
   }
   return new TableUpdates(map);
 }
Exemplo n.º 3
0
  // Monitor support
  @Override
  public <E extends TableSchema<E>> TableUpdates monitor(
      DatabaseSchema dbSchema, List<MonitorRequest<E>> requests, MonitorCallBack cb) {
    List<Operation> ops = new ArrayList<>();
    for (MonitorRequest<E> e : requests) {
      monitorRegistrar.register(e.getTableName(), e.getColumns(), cb);
      Select<GenericTableSchema> query =
          new Select<>(vtepSchema.table(e.getTableName(), GenericTableSchema.class));
      if (e.getColumns() != null) query.setColumns(Lists.newArrayList(e.getColumns()));
      ops.add(query);
    }
    ListenableFuture<List<OperationResult>> results = transact(vtepSchema, ops);

    try {
      return tableUpdates(results.get());
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      return null;
    } catch (ExecutionException e) {
      log.error("exception on monitored table data", e);
      return null;
    }
  }
Exemplo n.º 4
0
 // Schema operations
 @Override
 public ListenableFuture<List<String>> getDatabases() {
   return new MockListenableFuture<>(Collections.singletonList(vtepSchema.getName()));
 }
Exemplo n.º 5
0
 private DatabaseSchema getDbSchema(String dbName) {
   return (vtepSchema.getName().equals(dbName)) ? vtepSchema : null;
 }