Search in sources :

Example 1 with PhysicalSource

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++;
    }
    ;
}
Also used : PhysicalSourceStaticConfig(com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig) PhysicalSource(com.linkedin.databus.core.data_model.PhysicalSource) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource) LogicalPartition(com.linkedin.databus.core.data_model.LogicalPartition) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with PhysicalSource

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");
}
Also used : PhysicalSource(com.linkedin.databus.core.data_model.PhysicalSource) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) Test(org.testng.annotations.Test)

Example 3 with PhysicalSource

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ObjectWriter(org.codehaus.jackson.map.ObjectWriter) PhysicalSource(com.linkedin.databus.core.data_model.PhysicalSource) StringWriter(java.io.StringWriter) PhysicalPartitionKey(com.linkedin.databus.core.DbusEventBufferMult.PhysicalPartitionKey) DbusEventBufferMult(com.linkedin.databus.core.DbusEventBufferMult) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 4 with PhysicalSource

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);
}
Also used : PhysicalSource(com.linkedin.databus.core.data_model.PhysicalSource)

Example 5 with PhysicalSource

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;
}
Also used : PhysicalSource(com.linkedin.databus.core.data_model.PhysicalSource) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Aggregations

PhysicalSource (com.linkedin.databus.core.data_model.PhysicalSource)5 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)4 DbusEventBufferMult (com.linkedin.databus.core.DbusEventBufferMult)1 PhysicalPartitionKey (com.linkedin.databus.core.DbusEventBufferMult.PhysicalPartitionKey)1 LogicalPartition (com.linkedin.databus.core.data_model.LogicalPartition)1 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)1 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)1 PhysicalSourceStaticConfig (com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 ObjectWriter (org.codehaus.jackson.map.ObjectWriter)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1