Search in sources :

Example 1 with BufferNotFoundException

use of com.linkedin.databus2.core.BufferNotFoundException in project databus by linkedin.

the class TestDbusEventBufferMult method testReset.

@Test
public void testReset() throws Exception {
    createBufMult();
    addEvents();
    Integer pPartitionId = 100;
    PhysicalPartition pPartition = new PhysicalPartition(pPartitionId, "multBufferTest1");
    _eventBufferMult.resetBuffer(pPartition, 108L);
    DbusEventBufferAppendable eventBuffer = _eventBufferMult.getDbusEventBufferAppendable(pPartition);
    Assert.assertTrue(eventBuffer.empty());
    pPartition = new PhysicalPartition(pPartitionId, "unknownBuffer");
    boolean caughtException = false;
    try {
        _eventBufferMult.resetBuffer(pPartition, -1L);
    } catch (BufferNotFoundException e) {
        caughtException = true;
    }
    assertTrue(caughtException);
}
Also used : BufferNotFoundException(com.linkedin.databus2.core.BufferNotFoundException) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with BufferNotFoundException

use of com.linkedin.databus2.core.BufferNotFoundException in project databus by linkedin.

the class RelayCommandRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    String command = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    if (null == command) {
        throw new InvalidRequestParamValueException(COMMAND_NAME, "command", "null");
    }
    String reply = "Command " + command + " completed ";
    LOG.info("got relayCommand = " + command);
    if (command.equals(SAVE_META_STATE_PARAM)) {
        _relay.saveBufferMetaInfo(true);
    } else if (command.equals(SHUTDOWN_RELAY_PARAM)) {
        String msg = "received shutdown curl request from: " + request.getRemoteAddress() + ". Shutting down\n";
        LOG.warn(msg);
        request.getResponseContent().write(ByteBuffer.wrap(msg.getBytes("UTF-8")));
        request.getResponseContent().close();
        _relay.shutdown();
    } else if (command.equals(VALIDATE_RELAY_BUFFER_PARAM)) {
        _relay.validateRelayBuffers();
    } else if (command.equals(DISCONNECT_CLIENTS)) {
        Channel rspChannel = request.getResponseContent().getRawChannel();
        _relay.disconnectDBusClients(rspChannel);
    } else if (command.equals(RUN_GC_PARAM)) {
        Runtime rt = Runtime.getRuntime();
        long mem = rt.freeMemory();
        LOG.info("mem before gc = " + rt.freeMemory() + " out of " + rt.totalMemory());
        long time = System.currentTimeMillis();
        System.gc();
        time = System.currentTimeMillis() - time;
        mem = rt.freeMemory() - mem;
        reply = new String("GC run. Took " + time + " millsecs. Freed " + mem + " bytes out of " + rt.totalMemory());
    } else if (command.startsWith(RESET_RELAY_BUFFER_PARAM)) {
        // We expect the request to be of the format:
        //   resetRelayBuffer/<dbName>/<partitionId>?prevScn=<long>&binlogOffset=<long>
        String[] resetCommands = command.split("/");
        if (resetCommands.length != 3) {
            throw new InvalidRequestParamValueException(COMMAND_NAME, "command", command);
        }
        String dbName = resetCommands[1];
        String dbPart = resetCommands[2];
        long prevScn = request.getRequiredLongParam(PREV_SCN_PARAM);
        long binlogOffset = request.getOptionalLongParam(BINLOG_OFFSET_PARAM, 0L);
        LOG.info("reset command = " + dbName + " part =" + dbPart);
        try {
            _relay.resetBuffer(new PhysicalPartition(Integer.parseInt(dbPart), dbName), prevScn, binlogOffset);
        } catch (BufferNotFoundException e) {
            reply = new String("command " + command + ":" + e.getMessage());
        }
    } else if (command.startsWith(GET_BINLOG_OFFSET_PARAM)) {
        String[] getOfsArgs = command.split("/");
        if (getOfsArgs.length != 2) {
            throw new InvalidRequestParamValueException(GET_BINLOG_OFFSET_PARAM, "Server ID", "");
        }
        int serverId;
        try {
            serverId = Integer.parseInt(getOfsArgs[1]);
            int[] offset = _relay.getBinlogOffset(serverId);
            if (offset.length != 2) {
                reply = "Error getting binlog offset";
            } else {
                reply = new String("RelayLastEvent(" + offset[0] + "," + offset[1] + ")");
            }
        } catch (NumberFormatException e) {
            throw new InvalidRequestParamValueException(GET_BINLOG_OFFSET_PARAM, "Server ID", getOfsArgs[1]);
        } catch (DatabusException e) {
            reply = new String("command " + command + "failed with:" + e.getMessage());
        }
    } else if (command.startsWith(PRINT_RELAY_INFO_PARAM)) {
        try {
            Map<String, String> infoMap = _relay.printInfo();
            reply = makeJsonResponse(infoMap, request);
        } catch (Exception e) {
            reply = new String("command " + command + " failed with:" + e.getMessage());
        }
    } else {
        // invalid command
        reply = new String("command " + command + " is invalid. Valid commands are: " + SAVE_META_STATE_PARAM + "|" + SHUTDOWN_RELAY_PARAM + "|" + VALIDATE_RELAY_BUFFER_PARAM + "|" + RUN_GC_PARAM + "|" + RESET_RELAY_BUFFER_PARAM + "|" + GET_BINLOG_OFFSET_PARAM + "|" + PRINT_RELAY_INFO_PARAM + "|" + DISCONNECT_CLIENTS);
    }
    byte[] responseBytes = new byte[(reply.length() + 2)];
    System.arraycopy(reply.getBytes("UTF-8"), 0, responseBytes, 0, reply.length());
    int idx = reply.length();
    responseBytes[idx] = (byte) '\r';
    responseBytes[idx + 1] = (byte) '\n';
    request.getResponseContent().write(ByteBuffer.wrap(responseBytes));
    return request;
}
Also used : Channel(org.jboss.netty.channel.Channel) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) BufferNotFoundException(com.linkedin.databus2.core.BufferNotFoundException) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) DatabusException(com.linkedin.databus2.core.DatabusException) BufferNotFoundException(com.linkedin.databus2.core.BufferNotFoundException) IOException(java.io.IOException) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) DatabusException(com.linkedin.databus2.core.DatabusException) Map(java.util.Map) PhysicalPartition(com.linkedin.databus.core.data_model.PhysicalPartition)

Example 3 with BufferNotFoundException

use of com.linkedin.databus2.core.BufferNotFoundException in project databus by linkedin.

the class BufferInfoRequestProcessor method processInboundRequest.

private void processInboundRequest(DatabusRequest request, PhysicalPartition pPart) throws IOException, DatabusException {
    DbusEventBuffer evb = _eventBufferMult.getOneBuffer(pPart);
    if (null == evb) {
        LOG.error("BufferInfoRequest : Buffer not available for physical partition :" + pPart);
        throw new BufferNotFoundException("Buffer not available for partition :" + pPart);
    }
    BufferInfoResponse response = new BufferInfoResponse();
    response.setMinScn(evb.getMinScn());
    response.setMaxScn(evb.lastWrittenScn());
    response.setTimestampFirstEvent(evb.getTimestampOfFirstEvent());
    response.setTimestampLatestEvent(evb.getTimestampOfLatestDataEvent());
    writeJsonObjectToResponse(response, request);
}
Also used : BufferNotFoundException(com.linkedin.databus2.core.BufferNotFoundException) DbusEventBuffer(com.linkedin.databus.core.DbusEventBuffer) BufferInfoResponse(com.linkedin.databus.core.BufferInfoResponse)

Aggregations

BufferNotFoundException (com.linkedin.databus2.core.BufferNotFoundException)3 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)2 BufferInfoResponse (com.linkedin.databus.core.BufferInfoResponse)1 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)1 DatabusException (com.linkedin.databus2.core.DatabusException)1 InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)1 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Channel (org.jboss.netty.channel.Channel)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1