Search in sources :

Example 26 with DatabusRequest

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

the class ContainerStatsRequestProcessor method processOutboundTrafficClientStats.

private void processOutboundTrafficClientStats(DatabusRequest request) throws IOException, RequestProcessingException {
    String category = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME);
    String prefix = "outbound/client/";
    String client = category.substring(prefix.length());
    ContainerTrafficTotalStats clientStats = _containerStatsCollector.getOutboundClientStats(client);
    if (null == clientStats) {
        throw new InvalidRequestParamValueException(request.getName(), prefix, client);
    }
    JsonEncoder jsonEncoder = clientStats.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
    clientStats.toJson(jsonEncoder, null);
    if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
        enableOrResetStatsMBean(clientStats, request);
    }
}
Also used : JsonEncoder(org.apache.avro.io.JsonEncoder) ContainerTrafficTotalStats(com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStats)

Example 27 with DatabusRequest

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

the class ContainerStatsRequestProcessor method processOutboundTrafficTotalStats.

private void processOutboundTrafficTotalStats(DatabusRequest request) throws IOException {
    ContainerTrafficTotalStatsMBean outboundTrafficTotalStatsMBean = _containerStatsCollector.getOutboundTrafficTotalStats();
    if (null == outboundTrafficTotalStatsMBean)
        return;
    //String json = outboundTrafficTotalStatsMBean.toJson();
    JsonEncoder jsonEncoder = outboundTrafficTotalStatsMBean.createJsonEncoder(Channels.newOutputStream(request.getResponseContent()));
    outboundTrafficTotalStatsMBean.toJson(jsonEncoder, null);
    if (request.getRequestType() == HttpMethod.PUT || request.getRequestType() == HttpMethod.POST) {
        enableOrResetStatsMBean(outboundTrafficTotalStatsMBean, request);
    }
}
Also used : ContainerTrafficTotalStatsMBean(com.linkedin.databus2.core.container.monitoring.mbean.ContainerTrafficTotalStatsMBean) JsonEncoder(org.apache.avro.io.JsonEncoder)

Example 28 with DatabusRequest

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

the class ClientStateRequestProcessor method processRegistrationInfo.

/**
   * Provides an individual registrations details. The individual registration can be
   * either that of V2/V3 and top-level or child. Top-level registrations are those that
   * were created as a result of one of "registerXXX()" calls on databus-client. In the
   * case of multi-partition registrations (like MPRegistration, V2/V3 CLB), only the
   * parent registration is considered the top-level registration. Per-partition (child)
   * registrations which were created as part of partition migration are NOT top-level
   * registrations. The output format can be different depending on whether it is a V2/V3
   * as we are dumping the entire Registration in the case of V2. In the case of V3, we
   * create an intermediate objects. These are legacy formats which when changed could
   * cause the integ-tests to fail.
   * 
   * @param request
   *          DatabusRequest corresponding to the REST call.
   * @throws IOException
   *           if unable to write to output channel.
   * @throws RequestProcessingException
   *           when registration could not be located.
   */
private void processRegistrationInfo(DatabusRequest request) throws IOException, RequestProcessingException {
    boolean found = true;
    // V2 Registration lookup first
    RegistrationStatsInfo regStatsInfo = null;
    try {
        DatabusRegistration r = findV2Registration(request, REGISTRATION_KEY_PREFIX);
        writeJsonObjectToResponse(r, request);
    } catch (RequestProcessingException ex) {
        found = false;
    }
    // V3 Registration lookup if not found
    if (!found) {
        // if
        DatabusV3Registration reg = findV3Registration(request, REGISTRATION_KEY_PREFIX);
        // reg
        // is
        // null,
        // the
        // callee
        // throws
        // an
        // exception.
        DatabusSourcesConnection sourcesConn = _client.getDatabusSourcesConnection(reg.getRegistrationId().getId());
        regStatsInfo = new RegistrationStatsInfo(reg, sourcesConn);
        writeJsonObjectToResponse(regStatsInfo, request);
    }
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) RegistrationStatsInfo(com.linkedin.databus.client.monitoring.RegistrationStatsInfo) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException) DatabusSourcesConnection(com.linkedin.databus.client.DatabusSourcesConnection)

Example 29 with DatabusRequest

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

the class ClientStateRequestProcessor method pauseResumeRegistration.

/**
   * Pause or resume a V2 or V3 registration. The registration can be a top-level or
   * child-level registration Top-level registrations are those that were created as a
   * result of one of "registerXXX()" calls on databus-client. In the case of
   * multi-partition registrations (like MPRegistration, V2/V3 CLB), only the parent
   * registration is considered the top-level registration. Per-partition (child)
   * registrations which were created as part of partition migration are NOT top-level
   * registrations.
   * 
   * @param request
   *          Databus request corresponding to the REST call.
   * @param doPause
   *          true if wanted to pause, false if to be resumed
   * @throws IOException
   *           if unable to write output to channel
   * @throws RequestProcessingException
   *           when registration could not be found.
   */
private void pauseResumeRegistration(DatabusRequest request, boolean doPause) throws IOException, RequestProcessingException {
    DatabusRegistration r = null;
    DatabusV3Registration r2 = null;
    boolean found = true;
    boolean isRunning = false;
    boolean isPaused = false;
    boolean isSuspended = false;
    RegistrationId regId = null;
    RequestProcessingException rEx = null;
    RegStatePair regStatePair = null;
    try {
        r = findV2Registration(request, PAUSE_REGISTRATION);
        isRunning = r.getState().isRunning();
        isPaused = (r.getState() == DatabusRegistration.RegistrationState.PAUSED);
        isSuspended = (r.getState() == DatabusRegistration.RegistrationState.SUSPENDED_ON_ERROR);
        regId = r.getRegistrationId();
    } catch (RequestProcessingException ex) {
        found = false;
        rEx = ex;
    }
    if (!found) {
        try {
            r2 = findV3Registration(request, PAUSE_REGISTRATION);
            found = true;
            isRunning = r2.getState().isRunning();
            isPaused = (r2.getState() == RegistrationState.PAUSED);
            isSuspended = (r2.getState() == RegistrationState.SUSPENDED_ON_ERROR);
            regId = r.getRegistrationId();
        } catch (RequestProcessingException ex) {
            found = false;
            rEx = ex;
        }
    }
    if (!found)
        throw rEx;
    LOG.info("REST call to pause registration : " + regId);
    if (isRunning) {
        if (doPause) {
            if (!isPaused) {
                if (null != r) {
                    r.pause();
                    regStatePair = new RegStatePair(r.getState(), r.getRegistrationId());
                } else {
                    r2.pause();
                    regStatePair = new RegStatePair(r2.getState().name(), r2.getRegistrationId());
                }
            }
        } else {
            if (isPaused || isSuspended) {
                if (null != r) {
                    r.resume();
                    regStatePair = new RegStatePair(r.getState(), r.getRegistrationId());
                } else {
                    r2.resume();
                    regStatePair = new RegStatePair(r2.getState().name(), r2.getRegistrationId());
                }
            }
        }
    }
    writeJsonObjectToResponse(regStatePair, request);
}
Also used : DatabusRegistration(com.linkedin.databus.client.pub.DatabusRegistration) DatabusV3Registration(com.linkedin.databus.client.pub.DatabusV3Registration) RegistrationId(com.linkedin.databus.client.pub.RegistrationId) RequestProcessingException(com.linkedin.databus2.core.container.request.RequestProcessingException)

Example 30 with DatabusRequest

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

the class ConsumerPauseRequestProcessor method process.

@Override
public DatabusRequest process(DatabusRequest request) throws IOException, RequestProcessingException {
    String action = request.getParams().getProperty(DatabusRequest.PATH_PARAM_NAME, "");
    if (action.equals("pause")) {
        _pauseConsumer.pause();
        request.getResponseContent().write(ByteBuffer.wrap("{\"pauseConsumer\":\"set-pause\"}".getBytes(Charset.defaultCharset())));
    } else if (action.equals("resume")) {
        _pauseConsumer.resume();
        request.getResponseContent().write(ByteBuffer.wrap("{\"pauseConsumer\":\"set-resume\"}".getBytes(Charset.defaultCharset())));
    } else {
        throw new InvalidRequestParamValueException(COMMAND_NAME, "request path", action);
    }
    return request;
}
Also used : InvalidRequestParamValueException(com.linkedin.databus2.core.container.request.InvalidRequestParamValueException)

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