private void inplaceRemove(Map<StreamPartition, List<StreamRouterSpec>> routeSpecMap, Map<StreamPartition, List<StreamRoutePartitioner>> routePartitionerMap, StreamRouterSpec toBeRemoved) { routeSpecMap.remove(toBeRemoved.getPartition()); routePartitionerMap.remove(toBeRemoved.getPartition()); }
public Map<StreamPartition, List<StreamRouterSpec>> makeSRS() { Map<StreamPartition, List<StreamRouterSpec>> newSRS = new HashMap<>(); this.getRouterSpecs().forEach(t -> { if (!newSRS.containsKey(t.getPartition())) { newSRS.put(t.getPartition(), new ArrayList<>()); } newSRS.get(t.getPartition()).add(t); }); return newSRS; }
private void inplaceAdd(Map<StreamPartition, List<StreamRouterSpec>> routeSpecMap, Map<StreamPartition, List<StreamRoutePartitioner>> routePartitionerMap, StreamRouterSpec toBeAdded, Map<String, StreamDefinition> sds) { if (!routeSpecMap.containsKey(toBeAdded.getPartition())) { routeSpecMap.put(toBeAdded.getPartition(), new ArrayList<StreamRouterSpec>()); } routeSpecMap.get(toBeAdded.getPartition()).add(toBeAdded); try { List<StreamRoutePartitioner> routePartitioners = calculatePartitioner(toBeAdded, sds, routePartitionerMap); routePartitionerMap.put(toBeAdded.getPartition(), routePartitioners); } catch (Exception e) { LOG.error("ignore this failure StreamRouterSpec " + toBeAdded + ", with error" + e.getMessage(), e); routeSpecMap.remove(toBeAdded.getPartition()); routePartitionerMap.remove(toBeAdded.getPartition()); } }
public Map<StreamPartition, StreamSortSpec> makeSSS() { Map<StreamPartition, StreamSortSpec> newSSS = new HashMap<>(); this.getRouterSpecs().forEach(t -> { if (t.getPartition().getSortSpec() != null) { newSSS.put(t.getPartition(), t.getPartition().getSortSpec()); } }); return newSSS; }
private List<StreamRoutePartitioner> calculatePartitioner(StreamRouterSpec streamRouterSpec, Map<String, StreamDefinition> sds, Map<StreamPartition, List<StreamRoutePartitioner>> routePartitionerMap) throws Exception { List<StreamRoutePartitioner> routePartitioners = routePartitionerMap.get(streamRouterSpec.getPartition()); if (routePartitioners == null) { routePartitioners = new ArrayList<>(); } for (PolicyWorkerQueue pwq : streamRouterSpec.getTargetQueue()) { routePartitioners.add(StreamRoutePartitionFactory.createRoutePartitioner( Lists.transform(pwq.getWorkers(), WorkSlot::getBoltId), sds.get(streamRouterSpec.getPartition().getStreamId()), streamRouterSpec.getPartition())); } return routePartitioners; }
@Override public String toString() { return String.format("StreamRouterSpec[streamId=%s,partition=%s, queue=[%s]]", this.getStreamId(), this.getPartition(), this.getTargetQueue()); }
if (copyRouteSpecMap.containsKey(spec.getPartition()) && copyRouteSpecMap.get(spec.getPartition()).contains(spec)) { LOG.error("Metadata calculation error: add existing StreamRouterSpec " + spec); } else { if (!copyRouteSpecMap.containsKey(spec.getPartition()) || !copyRouteSpecMap.get(spec.getPartition()).contains(spec)) { LOG.error("Metadata calculation error: remove non-existing StreamRouterSpec " + spec); } else { if (!copyRouteSpecMap.containsKey(spec.getPartition()) || copyRouteSpecMap.get(spec.getPartition()).contains(spec)) { LOG.error("Metadata calculation error: modify nonexisting StreamRouterSpec " + spec); } else {
StreamRouterSpec routeSpec = spec.getRouterSpecs().get(0); Assert.assertEquals(STREAM2, routeSpec.getStreamId()); Assert.assertEquals(Arrays.asList("col1"), routeSpec.getPartition().getColumns());
Assert.assertEquals(1, routeSpecs.size()); for (StreamRouterSpec spec : routeSpecs) { StreamPartition par = spec.getPartition(); Assert.assertEquals(STREAM1, par.getStreamId()); Assert.assertEquals(Arrays.asList("col1"), par.getColumns());
Assert.assertEquals(1, routeSpecs.size()); for (StreamRouterSpec spec : routeSpecs) { StreamPartition par = spec.getPartition(); Assert.assertEquals(STREAM1, par.getStreamId()); Assert.assertEquals(Arrays.asList("col1"), par.getColumns());
@Test public void testStreamRouterSpec() { StreamRouterSpec streamRouterSpec = new StreamRouterSpec(); Assert.assertEquals(null, streamRouterSpec.getPartition()); Assert.assertEquals(null, streamRouterSpec.getStreamId()); Assert.assertTrue(streamRouterSpec.getTargetQueue().isEmpty());