Search in sources :

Example 31 with DatabusRequest

use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.

the class ClientStateRequestProcessor method processPartition.

/**
   * Provide a partition information belonging to a V2/V3 client cluster and hosted in
   * this client instance
   * 
   * @param request
   *          DatabusRequest corresponding to the REST call.
   * @throws IOException
   *           when unable to write to output channel.
   * @throws RequestProcessingException
   *           when cluster not found or when partition is not hosted in this instance
   */
private void processPartition(DatabusRequest request) throws IOException, RequestProcessingException {
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String clusterPartitionName = category.substring(CLIENT_CLUSTER_PARTITION_REG_KEY.length());
    /**
     * API: curl
     * http://<HOST>:<PORT>/clientState/clientPartition/<CLUSTER_NAME>/<PARTITION> curl
     * http://<HOST>:<PORT>/clientState/clientPartition/<CLUSTER_NAME>:<PARTITION>
     */
    String[] toks = clusterPartitionName.split("[:/]");
    if (toks.length != 2)
        throw new RequestProcessingException("Cluster and partition info are expected to be in pattern = <cluster>[/:]<partition> but was " + clusterPartitionName);
    RegInfo reg = null;
    boolean found = true;
    // Try as a V2 Partition
    try {
        reg = getV2PartitionRegistration(toks[0], new Long(toks[1]));
    } catch (RequestProcessingException ex) {
        found = false;
    }
    // If not found, try as V3
    if (!found) {
        reg = getV3PartitionRegistration(toks[0], new Long(toks[1]));
    }
    writeJsonObjectToResponse(reg, request);
}
Also used : RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException)

Example 32 with DatabusRequest

use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.

the class ClientStatsRequestProcessor method processEventsPeerStats.

private void processEventsPeerStats(DbusEventsStatisticsCollector statsCollector, String prefix, DatabusRequest request) throws IOException, RequestProcessingException {
    if (null == statsCollector)
        return;
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String client = category.substring(prefix.length());
    DbusEventsTotalStats clientStats = statsCollector.getPeerStats(client);
    if (null == clientStats) {
        throw new InvalidRequestParamValueException(request.getName(), prefix, client);
    }
    writeJsonObjectToResponse(clientStats, request);
    if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
        enableOrResetStatsMBean(clientStats, request);
    }
}
Also used : DbusEventsTotalStats(com.linkedin.databus.core.monitoring.mbean.DbusEventsTotalStats) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)

Example 33 with DatabusRequest

use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.

the class ClientStatsRequestProcessor method findV3Registration.

private DatabusV3Registration findV3Registration(DatabusRequest request, String prefix) throws InvalidRequestParamValueException {
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String registrationIdStr = category.substring(prefix.length());
    DatabusV3Registration reg = _client.getRegistration(new RegistrationId(registrationIdStr));
    if (null == reg) {
        LOG.warn("Invalid registrationId: " + registrationIdStr);
        throw new InvalidRequestParamValueException(request.getName(), prefix, "No data available for this RegistrationId yet");
    }
    return reg;
}
Also used : DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)

Example 34 with DatabusRequest

use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.

the class ClientStatsRequestProcessor method findRegistration.

private DatabusRegistration findRegistration(DatabusRequest request, String prefix) throws RequestProcessingException {
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String registrationIdStr = category.substring(prefix.length());
    RegistrationId regId = new RegistrationId(registrationIdStr);
    Collection<DatabusRegistration> regs = _client.getAllRegistrations();
    for (DatabusRegistration r : regs) {
        if (regId.equals(r.getRegistrationId()))
            return r;
        if (r instanceof DatabusMultiPartitionRegistration) {
            Map<DbusPartitionInfo, DatabusRegistration> childRegs = ((DatabusMultiPartitionRegistration) r).getPartitionRegs();
            for (Entry<DbusPartitionInfo, DatabusRegistration> e : childRegs.entrySet()) if (regId.equals(e.getValue().getRegistrationId()))
                return e.getValue();
        }
    }
    throw new RequestProcessingException("Unable to find registration (" + regId + ") ");
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) DatabusMultiPartitionRegistration(com.linkedin.databus.client.registration.DatabusMultiPartitionRegistration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo)

Example 35 with DatabusRequest

use of com.linkedin.databus2.core.container.request.DatabusRequest in project databus by linkedin.

the class GenerateDataEventsRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    String action = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
    if (action.equals("check")) {
        boolean genRunning = _producer.checkRunning();
        StringBuilder resBuilder = new StringBuilder(1024);
        Formatter fmt = new Formatter(resBuilder);
        fmt.format("{\"genDataEventsRunning\":\"%b\"}", genRunning);
        request.getResponseContent().write(ByteBuffer.wrap(resBuilder.toString().getBytes(Charset.defaultCharset())));
    } else if (action.equals("stop")) {
        _producer.stopGeneration();
        request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-stop\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("suspend")) {
        _producer.suspendGeneration();
        request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-suspend\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("resume")) {
        long numEventToGenerate = request.getOptionalLongParam(NUM_EVENTS_TO_GENERATE, Long.MAX_VALUE);
        long keyMin = request.getOptionalLongParam(KEY_MIN_PARAM, 0L);
        long keyMax = request.getOptionalLongParam(KEY_MAX_PARAM, Long.MAX_VALUE);
        int percentOfBufferToGenerate = request.getOptionalIntParam(PERCENT_BUFFER_TO_GENERATE, Integer.MAX_VALUE);
        _producer.resumeGeneration(numEventToGenerate, percentOfBufferToGenerate, keyMin, keyMax);
        request.getResponseContent().write(ByteBuffer.wrap("{\"genDataEventsRunning\":\"send-resume\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("start")) {
        long fromScn = request.getRequiredLongParam(SCN_PARAM);
        long durationMs = request.getRequiredLongParam(DURATION_MS);
        int eventsPerSec = request.getRequiredIntParam(EVENTS_PER_SEC_PARAM);
        long numEventToGenerate = request.getOptionalLongParam(NUM_EVENTS_TO_GENERATE, Long.MAX_VALUE);
        int percentOfBufferToGenerate = request.getOptionalIntParam(PERCENT_BUFFER_TO_GENERATE, Integer.MAX_VALUE);
        long keyMin = request.getOptionalLongParam(KEY_MIN_PARAM, 0L);
        long keyMax = request.getOptionalLongParam(KEY_MAX_PARAM, Long.MAX_VALUE);
        String sourcesListStr = request.getRequiredStringParam(SOURCES_NAME_PARAM);
        String[] sourcesStrArray = sourcesListStr.split(",");
        List<IdNamePair> sourcesIdList = new ArrayList<IdNamePair>(sourcesStrArray.length);
        for (String sourceIdStr : sourcesStrArray) {
            try {
                Integer id = Integer.valueOf(sourceIdStr);
                LogicalSource source = _relay.getSourcesIdNameRegistry().getSource(id);
                if (null != source)
                    sourcesIdList.add(source.asIdNamePair());
                else
                    LOG.error("unable to find source id: " + id);
            } catch (NumberFormatException nfe) {
                throw new InvalidRequestParamValueException(COMMAND_NAME, SOURCES_NAME_PARAM, sourceIdStr);
            }
        }
        //We have to use the global stats collector because the generation can go beyond the lifespan
        //of the connection
        boolean tryStart = _producer.startGeneration(fromScn, eventsPerSec, durationMs, numEventToGenerate, percentOfBufferToGenerate, keyMin, keyMax, sourcesIdList, _relayStatsCollector);
        StringBuilder resBuilder = new StringBuilder(1024);
        Formatter fmt = new Formatter(resBuilder);
        fmt.format("{\"genDataEventsStarted\":\"%b\"}", tryStart);
        request.getResponseContent().write(ByteBuffer.wrap(resBuilder.toString().getBytes(Charset.defaultCharset())));
    } else {
        throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", action);
    }
    return request;
}
Also used : Formatter(java.util.Formatter) ArrayList(java.util.ArrayList) LogicalSource(com.linkedin.databus.core.data_model.LogicalSource) InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException) IdNamePair(com.linkedin.databus.core.util.IdNamePair)

Aggregations

InvalidRequestParamValueException (com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)20 RequestProcessingException (com.linkedin.databus2.core.container.request.RequestProcessingException)17 ArrayList (java.util.ArrayList)9 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)9 LogicalSource (com.linkedin.databus.core.data_model.LogicalSource)8 DatabusRequest (com.linkedin.databus2.core.container.request.DatabusRequest)8 IOException (java.io.IOException)8 Properties (java.util.Properties)8 DbusHttpTotalStats (com.linkedin.databus2.core.container.monitoring.mbean.DbusHttpTotalStats)6 List (java.util.List)6 RegistrationId (com.linkedin.databus.client.pub.RegistrationId)5 RegisterRequestProcessor (com.linkedin.databus.container.request.RegisterRequestProcessor)5 PhysicalPartition (com.linkedin.databus.core.data_model.PhysicalPartition)5 ChunkedWritableByteChannel (com.linkedin.databus2.core.container.ChunkedWritableByteChannel)5 EventProducer (com.linkedin.databus2.producers.EventProducer)5 SchemaRegistryService (com.linkedin.databus2.schemas.SchemaRegistryService)5 SourceIdNameRegistry (com.linkedin.databus2.schemas.SourceIdNameRegistry)5 HashMap (java.util.HashMap)5 DatabusRegistration (com.linkedin.databus.client.pub.DatabusRegistration)4 DatabusV3Registration (com.linkedin.databus.client.pub.DatabusV3Registration)4