use of com.linkedin.databus.core.data_model.PhysicalSource in project databus by linkedin.
the class TestDbusEventBufferMult method setUpTest.
@BeforeTest
public void setUpTest() throws IOException, InvalidConfigException {
LOG.info("Setting up Test");
PhysicalSourceStaticConfig pStatConf1 = convertToPhysicalSourceConfig(_configSource1).build();
PhysicalSourceStaticConfig pStatConf2 = convertToPhysicalSourceConfig(_configSource2).build();
PhysicalSourceStaticConfig pStatConf3 = convertToPhysicalSourceConfig(_configSource3).build();
_pConfigs = new PhysicalSourceStaticConfig[] { pStatConf1, pStatConf2, pStatConf3 };
// generate testData
int scn = 100;
String srcName = "srcName";
int srcId = 1;
PhysicalSource pS = pStatConf1.getPhysicalSource();
PhysicalPartition pP = pStatConf1.getPhysicalPartition();
_events = new TestDbusEvent[20];
LogicalPartition lP = new LogicalPartition((short) 0);
for (int i = 0; i < _events.length; i++) {
_events[i] = new TestDbusEvent(i, scn, new LogicalSource(srcId, srcName + srcId), pS, pP, lP);
switch(i) {
case 4:
srcId = 2;
break;
case 9:
srcId = 11;
pS = pStatConf2.getPhysicalSource();
pP = pStatConf2.getPhysicalPartition();
break;
case 14:
srcId = 12;
break;
}
if ((i & 1) == 1)
scn++;
}
;
}
use of com.linkedin.databus.core.data_model.PhysicalSource in project databus by linkedin.
the class TestPhysicalSourceConfig method testPhysicalSourceConfigConstructor.
// test partial constructor
@Test
public void testPhysicalSourceConfigConstructor() {
Integer pPartitionId = 10;
String name = "dbName";
PhysicalPartition pPartition = new PhysicalPartition(pPartitionId, name);
PhysicalSource pSource = new PhysicalSource("uri");
PhysicalSourceConfig pConfig = new PhysicalSourceConfig(pPartition.getName(), pSource.getUri(), pPartition.getId());
int lSourceId = 10;
String lSourceName = "lName";
for (int i = 0; i < 10; i++) {
LogicalSourceConfig lSC = new LogicalSourceConfig();
lSourceId = lSourceId + i;
lSC.setId((short) lSourceId);
lSC.setName(lSourceName + lSourceId);
lSC.setPartition((short) 0);
lSC.setUri("lUri");
pConfig.addSource(lSC);
}
assertEquals(10, pConfig.getSources().size(), "number of logical source doesn't match");
}
use of com.linkedin.databus.core.data_model.PhysicalSource in project databus by linkedin.
the class PhysicalBuffersRequestProcessor method process.
@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
ObjectMapper mapper = new ObjectMapper();
boolean pretty = request.getParams().getProperty("pretty") != null;
// create pretty or regular writer
ObjectWriter writer = pretty ? mapper.defaultPrettyPrintingWriter() : mapper.writer();
StringWriter out = new StringWriter(10240);
DbusEventBufferMult multBuf = _relay.getEventBuffer();
Set<PhysicalPartitionKey> keys = multBuf.getAllPhysicalPartitionKeys();
// creat map to output partId=>PhysicalSources...
Map<PhysicalPartition, Set<PhysicalSource>> map = new HashMap<PhysicalPartition, Set<PhysicalSource>>(keys.size());
for (PhysicalPartitionKey key : keys) {
Set<PhysicalSource> set = multBuf.getPhysicalSourcesForPartition(key.getPhysicalPartition());
map.put(key.getPhysicalPartition(), set);
}
if (keys.isEmpty()) {
writer.writeValue(out, new HashSet<PhysicalPartition>());
} else {
writer.writeValue(out, map);
}
byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
return request;
}
use of com.linkedin.databus.core.data_model.PhysicalSource in project databus by linkedin.
the class DbusEventBufferMult method removeBuffer.
public synchronized void removeBuffer(PhysicalSourceStaticConfig pConfig) {
PhysicalPartitionKey pKey = new PhysicalPartitionKey(pConfig.getPhysicalPartition());
PhysicalSource pSource = pConfig.getPhysicalSource();
removeBuffer(pKey, pSource);
}
use of com.linkedin.databus.core.data_model.PhysicalSource in project databus by linkedin.
the class DbusEventBufferMult method addNewBuffer.
//CM API
/** add new buffer
* also checks if any buffers should be removed
* @throws InvalidConfigException */
public synchronized DbusEventBuffer addNewBuffer(PhysicalSourceStaticConfig pConfig, DbusEventBuffer.StaticConfig config) throws InvalidConfigException {
long startTimeTs = System.nanoTime();
if (config == null)
throw new InvalidConfigException("config cannot be null for addNewBuffer");
// see if a buffer for this mapping exists
PhysicalPartition pPartition = pConfig.getPhysicalPartition();
PhysicalPartitionKey pKey = new PhysicalPartitionKey(pPartition);
//record pSource association to the buffer
PhysicalSource pSource = pConfig.getPhysicalSource();
Set<PhysicalSource> set = _partKey2PhysiscalSources.get(pKey);
if (set == null) {
set = new HashSet<PhysicalSource>();
_partKey2PhysiscalSources.put(pKey, set);
}
set.add(pSource);
DbusEventBuffer buf = _bufsMap.get(pKey);
if (buf != null) {
LOG.info("Adding new buffer. Buffer " + buf.hashCode() + " already exists for: " + pConfig);
} else {
if (pConfig.isDbusEventBufferSet()) {
buf = new DbusEventBuffer(pConfig.getDbusEventBuffer(), pPartition, _eventFactory);
LOG.info("Using- source specific event buffer config, the event buffer size allocated is: " + buf.getAllocatedSize());
} else {
buf = new DbusEventBuffer(config, pPartition, _eventFactory);
LOG.info("Using- global event buffer config, the buffer size allocated is: " + buf.getAllocatedSize());
}
addBuffer(pConfig, buf);
}
buf.increaseRefCounter();
// check if some buffers need to be removed
deallocateRemovedBuffers(false);
long endTimeTs = System.nanoTime();
if (PERF_LOG.isDebugEnabled()) {
PERF_LOG.debug("addNewBuffer took:" + (endTimeTs - startTimeTs) / _nanoSecsInMSec + "ms");
}
return buf;
}
Aggregations