public TableImpl(TableDescriptor tableDescriptor) { this.tableId = tableDescriptor.getTableId(); }
/** * Generate configuration for provided tables * * @param jobConfig existing job config * @param tableDescriptors table descriptors, for which configuration to be generated * @return table configuration */ public static Map<String, String> generate(Config jobConfig, List<TableDescriptor> tableDescriptors) { Map<String, String> tableConfig = new HashMap<>(); tableDescriptors.forEach(tableDescriptor -> tableConfig.putAll(tableDescriptor.toConfig(jobConfig))); LOG.info("TableConfigGenerator has generated configs {}", tableConfig); return tableConfig; }
void addTable(TableDescriptor tableDescriptor) { tables.put(tableDescriptor.getTableId(), tableDescriptor); }
private Context createMockContext(TableDescriptor tableDescriptor) { Context context = mock(Context.class); ContainerContext containerContext = mock(ContainerContext.class); when(context.getContainerContext()).thenReturn(containerContext); MetricsRegistry metricsRegistry = mock(MetricsRegistry.class); when(metricsRegistry.newTimer(anyString(), anyString())).thenReturn(mock(Timer.class)); when(metricsRegistry.newCounter(anyString(), anyString())).thenReturn(mock(Counter.class)); when(containerContext.getContainerMetricsRegistry()).thenReturn(metricsRegistry); TaskContextImpl taskContext = mock(TaskContextImpl.class); when(context.getTaskContext()).thenReturn(taskContext); TaskName taskName = new TaskName("MyTask"); TaskModel taskModel = mock(TaskModel.class); when(taskModel.getTaskName()).thenReturn(taskName); when(context.getTaskContext().getTaskModel()).thenReturn(taskModel); ContainerModel containerModel = mock(ContainerModel.class); when(containerModel.getTasks()).thenReturn(ImmutableMap.of(taskName, taskModel)); when(containerContext.getContainerModel()).thenReturn(containerModel); String containerId = "container-1"; JobModel jobModel = mock(JobModel.class); when(taskContext.getJobModel()).thenReturn(jobModel); when(jobModel.getContainers()).thenReturn(ImmutableMap.of(containerId, containerModel)); JobContext jobContext = mock(JobContext.class); when(jobContext.getConfig()).thenReturn(new MapConfig(tableDescriptor.toConfig(new MapConfig()))); when(context.getJobContext()).thenReturn(jobContext); return context; }
private TableSpecJson buildTableJson(TableDescriptor tableDescriptor, Map<String, TableSpecJson> tableSpecs) { String tableId = tableDescriptor.getTableId(); return tableSpecs.computeIfAbsent(tableId, k -> buildTableJson(tableDescriptor)); }
final void addTableDescriptor(TableDescriptor tableDescriptor) { String tableId = tableDescriptor.getTableId(); Preconditions.checkState(StringUtils.isNotBlank(tableId) && ID_PATTERN.matcher(tableId).matches(), String.format("tableId: %s must confirm to pattern: %s", tableId, ID_PATTERN.toString())); Preconditions.checkState(!tableDescriptors.containsKey(tableId) || tableDescriptors.get(tableId) == tableDescriptor, String.format("Cannot add multiple table descriptors with the same tableId: %s", tableId)); if (tableDescriptor instanceof HybridTableDescriptor) { List<? extends TableDescriptor> tableDescs = ((HybridTableDescriptor) tableDescriptor).getTableDescriptors(); tableDescs.forEach(td -> addTableDescriptor(td)); } tableDescriptors.put(tableId, tableDescriptor); }
final void addTableDescriptor(TableDescriptor tableDescriptor) { String tableId = tableDescriptor.getTableId(); Preconditions.checkState(StringUtils.isNotBlank(tableId) && ID_PATTERN.matcher(tableId).matches(), String.format("tableId: %s must confirm to pattern: %s", tableId, ID_PATTERN.toString())); Preconditions.checkState(!tableDescriptors.containsKey(tableId) || tableDescriptors.get(tableId) == tableDescriptor, String.format("Cannot add multiple table descriptors with the same tableId: %s", tableId)); if (tableDescriptor instanceof BaseHybridTableDescriptor) { List<? extends TableDescriptor> tableDescs = ((BaseHybridTableDescriptor) tableDescriptor).getTableDescriptors(); tableDescs.forEach(td -> addTableDescriptor(td)); } tableDescriptors.put(tableId, tableDescriptor); }
final void addTableDescriptor(TableDescriptor tableDescriptor) { String tableId = tableDescriptor.getTableId(); Preconditions.checkState(StringUtils.isNotBlank(tableId) && ID_PATTERN.matcher(tableId).matches(), String.format("tableId: %s must confirm to pattern: %s", tableId, ID_PATTERN.toString())); Preconditions.checkState(!tableDescriptors.containsKey(tableId) || tableDescriptors.get(tableId) == tableDescriptor, String.format("Cannot add multiple table descriptors with the same tableId: %s", tableId)); if (tableDescriptor instanceof BaseHybridTableDescriptor) { List<? extends TableDescriptor> tableDescs = ((BaseHybridTableDescriptor) tableDescriptor).getTableDescriptors(); tableDescs.forEach(td -> addTableDescriptor(td)); } tableDescriptors.put(tableId, tableDescriptor); }
final void addTableDescriptor(TableDescriptor tableDescriptor) { String tableId = tableDescriptor.getTableId(); Preconditions.checkState(StringUtils.isNotBlank(tableId) && ID_PATTERN.matcher(tableId).matches(), String.format("tableId: %s must confirm to pattern: %s", tableId, ID_PATTERN.toString())); Preconditions.checkState(!tableDescriptors.containsKey(tableId) || tableDescriptors.get(tableId) == tableDescriptor, String.format("Cannot add multiple table descriptors with the same tableId: %s", tableId)); if (tableDescriptor instanceof BaseHybridTableDescriptor) { List<? extends TableDescriptor> tableDescs = ((BaseHybridTableDescriptor) tableDescriptor).getTableDescriptors(); tableDescs.forEach(td -> addTableDescriptor(td)); } tableDescriptors.put(tableId, tableDescriptor); }
final void addTableDescriptor(TableDescriptor tableDescriptor) { String tableId = tableDescriptor.getTableId(); Preconditions.checkState(StringUtils.isNotBlank(tableId) && ID_PATTERN.matcher(tableId).matches(), String.format("tableId: %s must confirm to pattern: %s", tableId, ID_PATTERN.toString())); Preconditions.checkState(!tableDescriptors.containsKey(tableId) || tableDescriptors.get(tableId) == tableDescriptor, String.format("Cannot add multiple table descriptors with the same tableId: %s", tableId)); if (tableDescriptor instanceof BaseHybridTableDescriptor) { List<? extends TableDescriptor> tableDescs = ((BaseHybridTableDescriptor) tableDescriptor).getTableDescriptors(); tableDescs.forEach(td -> addTableDescriptor(td)); } tableDescriptors.put(tableId, tableDescriptor); }
/** * Get list of table specs given a list of table descriptors. * @param tableDescs the list of tableDescriptors * @return list of tableSpecs */ static public List<TableSpec> getTableSpecs(List<TableDescriptor> tableDescs) { Map<TableSpec, TableImpl> tableSpecs = new LinkedHashMap<>(); tableDescs.forEach(tableDesc -> { TableSpec tableSpec = ((BaseTableDescriptor) tableDesc).getTableSpec(); if (tableSpecs.containsKey(tableSpec)) { throw new IllegalStateException( String.format("getTable() invoked multiple times with the same tableId: %s", tableDesc.getTableId())); } tableSpecs.put(tableSpec, new TableImpl(tableSpec)); }); return new ArrayList<>(tableSpecs.keySet()); } }
/** * Get list of table specs given a list of table descriptors. * @param tableDescs the list of tableDescriptors * @return list of tableSpecs */ static public List<TableSpec> getTableSpecs(List<TableDescriptor> tableDescs) { Map<TableSpec, TableImpl> tableSpecs = new LinkedHashMap<>(); tableDescs.forEach(tableDesc -> { TableSpec tableSpec = ((BaseTableDescriptor) tableDesc).getTableSpec(); if (tableSpecs.containsKey(tableSpec)) { throw new IllegalStateException( String.format("getTable() invoked multiple times with the same tableId: %s", tableDesc.getTableId())); } tableSpecs.put(tableSpec, new TableImpl(tableSpec)); }); return new ArrayList<>(tableSpecs.keySet()); } }
/** * Get list of table specs given a list of table descriptors. * @param tableDescs the list of tableDescriptors * @return list of tableSpecs */ static public List<TableSpec> getTableSpecs(List<TableDescriptor> tableDescs) { Map<TableSpec, TableImpl> tableSpecs = new LinkedHashMap<>(); tableDescs.forEach(tableDesc -> { TableSpec tableSpec = ((BaseTableDescriptor) tableDesc).getTableSpec(); if (tableSpecs.containsKey(tableSpec)) { throw new IllegalStateException( String.format("getTable() invoked multiple times with the same tableId: %s", tableDesc.getTableId())); } tableSpecs.put(tableSpec, new TableImpl(tableSpec)); }); return new ArrayList<>(tableSpecs.keySet()); } }
/** * Get list of table specs given a list of table descriptors. * @param tableDescs the list of tableDescriptors * @return list of tableSpecs */ static public List<TableSpec> getTableSpecs(List<TableDescriptor> tableDescs) { Map<TableSpec, TableImpl> tableSpecs = new LinkedHashMap<>(); tableDescs.forEach(tableDesc -> { TableSpec tableSpec = ((BaseTableDescriptor) tableDesc).getTableSpec(); if (tableSpecs.containsKey(tableSpec)) { throw new IllegalStateException( String.format("getTable() invoked multiple times with the same tableId: %s", tableDesc.getTableId())); } tableSpecs.put(tableSpec, new TableImpl(tableSpec)); }); return new ArrayList<>(tableSpecs.keySet()); } }
private TableSpecJson buildTableJson(TableDescriptor tableDescriptor) { TableSpecJson tableSpecJson = new TableSpecJson(); tableSpecJson.id = tableDescriptor.getTableId(); tableSpecJson.providerFactory = ((BaseTableDescriptor) tableDescriptor).getProviderFactoryClassName(); return tableSpecJson; } }
@Override public Map<String, String> toConfig(Config jobConfig) { Map<String, String> tableConfig = new HashMap<>(super.toConfig(jobConfig)); if (cache != null) { addTableConfig(CACHE_TABLE_ID, cache.getTableId(), tableConfig); } else { if (readTtl != null) { addTableConfig(READ_TTL_MS, String.valueOf(readTtl.toMillis()), tableConfig); } if (writeTtl != null) { addTableConfig(WRITE_TTL_MS, String.valueOf(writeTtl.toMillis()), tableConfig); } if (cacheSize > 0) { addTableConfig(CACHE_SIZE, String.valueOf(cacheSize), tableConfig); } } addTableConfig(REAL_TABLE_ID, table.getTableId(), tableConfig); addTableConfig(WRITE_AROUND, String.valueOf(isWriteAround), tableConfig); return Collections.unmodifiableMap(tableConfig); }
Answer getRegisteredTableAnswer() { return (InvocationOnMock x) -> { TableDescriptor descriptor = x.getArgumentAt(0, TableDescriptor.class); String tableId = "t1"; TableImpl mockTable = mock(TableImpl.class); when(mockTable.getTableId()).thenReturn(tableId); this.registeredTables.putIfAbsent(descriptor.getTableId(), mockTable); return this.registeredTables.get(descriptor.getTableId()); }; }
private void validateTableConfigure(JobConfig jobConfig, Map<String, Serde> deserializedSerdes, TableDescriptor tableDescriptor) { Config tableConfig = jobConfig.subset(String.format("tables.%s.", tableDescriptor.getTableId())); assertEquals(MockTableProviderFactory.class.getName(), tableConfig.get("provider.factory")); assertEquals("mock.config.value", jobConfig.get("mock.table.provider.config")); validateTableSerdeConfigure(tableDescriptor.getTableId(), jobConfig, deserializedSerdes); }
Set<String> intStreamIds = intermediateEdges.stream().map(stream -> stream.getStreamSpec().getId()).collect(Collectors.toSet()); assertThat(jsonObject.intermediateStreams.keySet(), Matchers.containsInAnyOrder(intStreamIds.toArray())); Set<String> tableIds = tables.stream().map(t -> t.getTableId()).collect(Collectors.toSet()); assertThat(jsonObject.tables.keySet(), Matchers.containsInAnyOrder(tableIds.toArray())); JobGraphJsonGenerator.JobNodeJson expectedNodeJson = new JobGraphJsonGenerator.JobNodeJson();
tables.put(table1Descriptor.getTableId(), table1Descriptor); tables.put(table2Descriptor.getTableId(), table2Descriptor); when(mockJobNode.getTables()).thenReturn(tables);