Package com.linkedin.databus2.core.container.monitoring.mbean

Examples of com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector


    }

    @Override
    protected DatabusComponentAdmin createComponentAdmin()
    { 
      return new DatabusComponentAdmin(this, null, "fake")
    }
View Full Code Here


  }

  @Override
  protected DatabusComponentAdmin createComponentAdmin()
  {
    return new DatabusComponentAdmin(this,
                                     getMbeanServer(),
                                     BootstrapHttpServer.class.getSimpleName());
  }
View Full Code Here

      _clientNode = null;
      _groupMember = null;
    }
    _checkpointPersistenceProvider = _clientStaticConfig.getCheckpointPersistence()
            .getOrCreateCheckpointPersistenceProvider(_groupMember);
    HttpStatisticsCollector httpStatsColl = _clientStaticConfig.getHttpStatsCollector()
                                            .getExistingStatsCollector();
    if (null == httpStatsColl)
    {
      httpStatsColl = new HttpStatisticsCollector(getContainerStaticConfig().getId(),
                                                  "httpOutbound",
                                                  _clientStaticConfig.getRuntime().getHttpStatsCollector().isEnabled(),
                                                  true,
                                                  getMbeanServer());
    }
View Full Code Here

            Integer srcId = Integer.valueOf(sourceId);
            sourceIds.add(srcId);
          }
          catch (NumberFormatException nfe)
          {
            HttpStatisticsCollector globalHttpStatsCollector = _relay.getHttpStatisticsCollector();
            if (null != globalHttpStatsCollector) {
              globalHttpStatsCollector.registerInvalidStreamRequest();
            }
            throw new InvalidRequestParamValueException(COMMAND_NAME, SOURCES_PARAM, sourceId);
          }
        }
      }

      //process explicit subscriptions and generate respective logical partition filters
      NavigableSet<PhysicalPartitionKey> ppartKeys = null;
      if (null != subsStr)
      {
        List<DatabusSubscription.Builder> subsBuilder = null;
        subsBuilder = objMapper.readValue(subsStr,
                                          new TypeReference<List<DatabusSubscription.Builder>>(){});
        subs = new ArrayList<DatabusSubscription>(subsBuilder.size());
        for (DatabusSubscription.Builder subBuilder: subsBuilder)
        {
          subs.add(subBuilder.build());
        }

        ppartKeys = new TreeSet<PhysicalPartitionKey>();
        for (DatabusSubscription sub: subs)
        {
          PhysicalPartition ppart = sub.getPhysicalPartition();
          if (ppart.isAnyPartitionWildcard())
          {
            ppartKeys = _eventBuffer.getAllPhysicalPartitionKeys(); break;
          }
          else
          {
            ppartKeys.add(new PhysicalPartitionKey(ppart));
          }
        }
      }
      // TODO
      // The following if statement is a very conservative one just to make sure that there are
      // not some clients out there that send subs, but do not send checkpoint mult. It seems that
      // this was the case during development but never in production, so we should remove this
      // pretty soon (1/28/2013).
      // Need to make sure that we don't have tests that send requests in this form.
      if(subs != null && checkpointStringMult == null && checkpointString != null) {
        throw new RequestProcessingException("Both Subscriptions and CheckpointMult should be present");
      }

      //convert source ids into subscriptions
      if (null == subs) subs = new ArrayList<DatabusSubscription>();
      for (Integer srcId: sourceIds)
      {
        LogicalSource lsource = srcRegistry.getSource(srcId);
        if(lsource == null)
          throw new InvalidRequestParamValueException(COMMAND_NAME, SOURCES_PARAM, srcId.toString());
        if(isDebug)
          LOG.debug("registry returns " + lsource  + " for srcid="+ srcId);
        DatabusSubscription newSub = DatabusSubscription.createSimpleSourceSubscription(lsource);
        subs.add(newSub);
      }

      DbusFilter ppartFilters = null;
      if (subs.size() > 0)
      {
        try
        {
          ppartFilters = _eventBuffer.constructFilters(subs);
        }
        catch (DatabusException de)
        {
          throw new RequestProcessingException("unable to generate physical partitions filters:" +
                                               de.getMessage(),
                                               de);
        }
      }

      ConjunctionDbusFilter filters = new ConjunctionDbusFilter();

      // Source filter comes first
      if (v2Mode) filters.addFilter(new SourceDbusFilter(sourceIds));
      else if (null != ppartFilters) filters.addFilter(ppartFilters);

      /*
      // Key range filter comes next
      if ((keyMin >0) && (keyMax > 0))
      {
        filters.addFilter(new KeyRangeFilter(keyMin, keyMax));
      }
      */
      if ( null != keyCompositeFilter)
      {
        filters.addFilter(keyCompositeFilter);
      }

      // need to update registerStreamRequest to support Mult checkpoint TODO (DDSDBUS-80)
      // temp solution
      // 3 options:
      // 1. checkpointStringMult not null - generate checkpoint from it
      // 2. checkpointStringMult null, checkpointString not null - create empty CheckpointMult
      // and add create Checkpoint(checkpointString) and add it to cpMult;
      // 3 both are null - create empty CheckpointMult and add empty Checkpoint to it for each ppartition
      PhysicalPartition pPartition;

      Checkpoint cp = null;
      CheckpointMult cpMult = null;

      if(checkpointStringMult != null) {
        try {
          cpMult = new CheckpointMult(checkpointStringMult);
        } catch (InvalidParameterSpecException e) {
          LOG.error("Invalid CheckpointMult:" + checkpointStringMult, e);
          throw new InvalidRequestParamValueException("stream", "CheckpointMult", checkpointStringMult);
        }
      } else {
        // there is no checkpoint - create an empty one
        cpMult = new CheckpointMult();
        Iterator<Integer> it = sourceIds.iterator();
        while(it.hasNext()) {
          Integer srcId = it.next();
          pPartition = _eventBuffer.getPhysicalPartition(srcId);
          if(pPartition == null)
            throw new RequestProcessingException("unable to find physical partitions for source:" + srcId);

          if(checkpointString != null) {
            cp = new Checkpoint(checkpointString);
          } else {
            cp = new Checkpoint();
            cp.setFlexible();
          }
          cpMult.addCheckpoint(pPartition, cp);
        }
      }

      if (isDebug) LOG.debug("checkpointStringMult = " + checkpointStringMult +  ";singlecheckpointString="+ checkpointString + ";CPM="+cpMult);

      // If the client has not sent a cursor partition, then use the one we may have retained as a part
      // of the server context.
      if (cpMult.getCursorPartition() == null) {
        cpMult.setCursorPartition(request.getCursorPartition());
      }
      if (isDebug) {
        if (cpMult.getCursorPartition() != null) {
          LOG.debug("Using physical paritition cursor " + cpMult.getCursorPartition());
        }
      }

      // for registerStreamRequest we need a single Checkpoint (TODO - fix it) (DDSDBUS-81)
      if(cp==null) {
        Iterator<Integer> it = sourceIds.iterator();
        if (it.hasNext()) {
          Integer srcId = it.next();
          pPartition = _eventBuffer.getPhysicalPartition(srcId);
          cp = cpMult.getCheckpoint(pPartition);
        } else {
          cp = new Checkpoint();
          cp.setFlexible();
        }
      }

      if (null != checkpointString && isDebug)
        LOG.debug("About to stream from cp: " + checkpointString.toString());

      HttpStatisticsCollector globalHttpStatsCollector = _relay.getHttpStatisticsCollector();
      HttpStatisticsCollector connHttpStatsCollector = null;
      if (null != globalHttpStatsCollector)
      {
        connHttpStatsCollector = (HttpStatisticsCollector)request.getParams().get(globalHttpStatsCollector.getName());
      }

      if (null != globalHttpStatsCollector) globalHttpStatsCollector.registerStreamRequest(cp, sourceIds);

      StatsCollectors<DbusEventsStatisticsCollector> statsCollectors = _relay.getOutBoundStatsCollectors();

      try
      {


        DbusEventBufferBatchReadable bufRead = v2Mode
          ? _eventBuffer.getDbusEventBufferBatchReadable(sourceIds, cpMult, statsCollectors)
          : _eventBuffer.getDbusEventBufferBatchReadable(cpMult, ppartKeys, statsCollectors);

        int eventsRead = 0;
        int minPendingEventSize = 0;
        StreamEventsResult result = null;

        bufRead.setClientMaxEventVersion(clientEventVersion);

        if (v2Mode)
        {
          result = bufRead.streamEvents(streamFromLatestSCN, fetchSize,
                                            request.getResponseContent(), enc, filters);
          eventsRead = result.getNumEventsStreamed();
          minPendingEventSize = result.getSizeOfPendingEvent();
          if(isDebug) {
            LOG.debug("Process: streamed " + eventsRead + " from sources " +
                     Arrays.toString(sourceIds.toArray()));
            LOG.debug("CP=" + cpMult); //can be used for debugging to stream from a cp
          }
          //if (null != statsCollectors) statsCollectors.mergeStatsCollectors();
        }
        else
        {
          result = bufRead.streamEvents(streamFromLatestSCN, fetchSize,
                                            request.getResponseContent(), enc, filters);
          eventsRead = result.getNumEventsStreamed();
          minPendingEventSize = result.getSizeOfPendingEvent();
          if(isDebug)
            LOG.debug("Process: streamed " + eventsRead + " with subscriptions " + subs);
          cpMult = bufRead.getCheckpointMult();
          if (cpMult != null) {
            request.setCursorPartition(cpMult.getCursorPartition());
          }
        }

        if (eventsRead == 0 && minPendingEventSize > 0)
        {
          // Append a header to indicate to the client that we do have at least one event to
          // send, but it is too large to fit into client's offered buffer.
          request.getResponseContent().addMetadata(DatabusHttpHeaders.DATABUS_PENDING_EVENT_SIZE,
                                                   minPendingEventSize);
          LOG.debug("Returning 0 events but have pending event of size " + minPendingEventSize);
        }
      }
      catch (ScnNotFoundException snfe)
      {
        if (null != globalHttpStatsCollector) {
          globalHttpStatsCollector.registerScnNotFoundStreamResponse();
        }
        throw new RequestProcessingException(snfe);
      }
      catch (OffsetNotFoundException snfe)
      {
        LOG.error("OffsetNotFound", snfe);
        if (null != globalHttpStatsCollector) {
          globalHttpStatsCollector.registerScnNotFoundStreamResponse();
        }
        throw new RequestProcessingException(snfe);
      }

      /* FIXME snagaraj
      if (null != connEventsStatsCollector && null != globalEventsStatsCollector)
      {
        globalEventsStatsCollector.merge(connEventsStatsCollector);
        connEventsStatsCollector.reset();
      }
      */

      if (null != connHttpStatsCollector)
      {
        connHttpStatsCollector.registerStreamResponse(System.currentTimeMillis()-start);
        globalHttpStatsCollector.merge(connHttpStatsCollector);
        connHttpStatsCollector.reset();
      }
      else if (null != globalHttpStatsCollector)
      {
        globalHttpStatsCollector.registerStreamResponse(System.currentTimeMillis()-start);
      }
    }
    catch (InvalidRequestParamValueException e)
    {
      HttpStatisticsCollector globalHttpStatsCollector = _relay.getHttpStatisticsCollector();
      if (null != globalHttpStatsCollector) {
        globalHttpStatsCollector.registerInvalidStreamRequest();
      }
      throw e;
    }
    return request;
  }
View Full Code Here

      if (null == _schemaRegistryService)
      {
        throw new InvalidConfigException("Unable to initialize schema registry");
      }

      HttpStatisticsCollector httpStatsColl = _relayStaticConfig.getHttpStatsCollector()
                                              .getExistingStatsCollector();
      if (null == httpStatsColl)
      {
        httpStatsColl = new HttpStatisticsCollector(getContainerStaticConfig().getId(),
                                                    "httpOutbound",
                                                    _relayStaticConfig.getRuntime().getHttpStatsCollector().isEnabled(),
                                                    true,
                                                    getMbeanServer());
      }
View Full Code Here

                                                      registerRequestProtocolVersionStr);
        }
      }

      Collection<LogicalSource> logicalSources = null;
      HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();

      String sources = request.getParams().getProperty(SOURCES_PARAM);
      if (null == sources)
      {
        // need to return all schemas, so first get all sources
        logicalSources = _relay.getSourcesIdNameRegistry().getAllSources();
      }
      else
      {
        String[] sourceIds = sources.split(",");
        logicalSources = new ArrayList<LogicalSource>(sourceIds.length);

        for (String sourceId: sourceIds)
        {
          int srcId;
          String trimmedSourceId = sourceId.trim();
          try
          {
            srcId = Integer.valueOf(trimmedSourceId);
            LogicalSource lsource = _relay.getSourcesIdNameRegistry().getSource(srcId);
            if (null != lsource) logicalSources.add(lsource);
            else
            {
              LOG.error("No source name for source id: " + srcId);
              throw new InvalidRequestParamValueException(COMMAND_NAME, SOURCES_PARAM, sourceId);
            }
          }
          catch (NumberFormatException nfe)
          {
            if (relayStatsCollector != null)
            {
              relayStatsCollector.registerInvalidRegisterCall();
            }
            throw new InvalidRequestParamValueException(COMMAND_NAME, SOURCES_PARAM, sourceId);
          }
        }
      }

      SchemaRegistryService schemaRegistry = _relay.getSchemaRegistryService();
      ArrayList<RegisterResponseEntry> registeredSources = new ArrayList<RegisterResponseEntry>(20);

      for (LogicalSource lsource: logicalSources)
      {
        getSchemas(schemaRegistry, lsource.getName(), lsource.getId(), sources, registeredSources);
      }

      // Note that, as of April 2013, the Espresso sandbox's schema registry
      // (in JSON format) is 4.5 MB and growing.  But 100 KB is probably OK
      // for regular production cases.
      StringWriter out = new StringWriter(102400);
      ObjectMapper mapper = new ObjectMapper();

      // any circumstances under which we might want to override this?
      int registerResponseProtocolVersion = registerRequestProtocolVersion;

      if (registerRequestProtocolVersion == 4// DDSDBUS-2009
      {
        LOG.debug("Got version 4 /register request; fetching metadata schema.");
        // Get (replication) metadata schema from registry; format it as list
        // of schemas (multiple only if more than one version exists).  Per
        // https://iwww.corp.linkedin.com/wiki/cf/display/ENGS/Espresso+Metadata+Schema,
        // name of replication metadata is simply "metadata".
        ArrayList<RegisterResponseMetadataEntry> registeredMetadata = new ArrayList<RegisterResponseMetadataEntry>(2);
        getMetadataSchemas(schemaRegistry, registeredMetadata);

        // Set up the v4 response as a map:  one entry is the existing list of source
        // schemas, and the others (if present) are the new lists of metadata schema(s)
        // and (TODO) key schemas.
        HashMap<String, List<Object>> responseMap = new HashMap<String, List<Object>>(4);
        responseMap.put(RegisterResponseEntry.SOURCE_SCHEMAS_KEY, (List<Object>)(List<?>)registeredSources);
        if (registeredMetadata.size() > 0)
        {
          LOG.debug("Sending v4 /register response with metadata schema.");
          responseMap.put(RegisterResponseMetadataEntry.METADATA_SCHEMAS_KEY,
                          (List<Object>)(List<?>)registeredMetadata);
        }
        else
        {
          LOG.debug("No metadata schema available; sending v4 /register response without.");
        }
        // TODO:  figure out how to retrieve key schemas and include via RegisterResponseEntry.KEY_SCHEMAS_KEY
        mapper.writeValue(out, responseMap);
      }
      else // fall back to old style (v2/v3 response)
      {
        mapper.writeValue(out, registeredSources);
      }

      ChunkedWritableByteChannel responseContent = request.getResponseContent();
      byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
      responseContent.addMetadata(DatabusHttpHeaders.DBUS_CLIENT_RELAY_PROTOCOL_VERSION_HDR,
                                  registerResponseProtocolVersion);
      responseContent.write(ByteBuffer.wrap(resultBytes));

      if (null != relayStatsCollector)
      {
        HttpStatisticsCollector connStatsCollector = (HttpStatisticsCollector)
        request.getParams().get(relayStatsCollector.getName());
        if (null != connStatsCollector)
        {
          connStatsCollector.registerRegisterCall(registeredSources);
        }
        else
        {
          relayStatsCollector.registerRegisterCall(registeredSources);
        }
      }

      return request;
    }
    catch (InvalidRequestParamValueException e)
    {
      HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
      if (null != relayStatsCollector)
        relayStatsCollector.registerInvalidRegisterCall();
      throw e;
    }
  }
View Full Code Here

    {
      versionedSchemas = schemaRegistry.fetchAllSchemaVersionsBySourceName(name);
    }
    catch (DatabusException ie)
    {
      HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
      if (relayStatsCollector != null) relayStatsCollector.registerInvalidRegisterCall();
      throw new RequestProcessingException(ie);
    }

    if ((null == versionedSchemas) || (versionedSchemas.isEmpty()))
    {
      HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
      if (relayStatsCollector != null) relayStatsCollector.registerInvalidRegisterCall();
      LOG.error("Problem fetching schema for sourceId " + sourceId + "; sources string = " + sources);
    }
    else
    {
      for (Entry<Short, String> e : versionedSchemas.entrySet())
View Full Code Here

        versionedSchemas = schemaSet.getAllVersionsWithSchemaId(SchemaRegistryService.DEFAULT_METADATA_SCHEMA_SOURCE);
      }
    }
    catch (DatabusException ie)
    {
      HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
      if (relayStatsCollector != null) relayStatsCollector.registerInvalidRegisterCall();
      throw new RequestProcessingException(ie);
    }

    if (versionedSchemas != null && !versionedSchemas.isEmpty())
    {
View Full Code Here

    byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());

    request.getResponseContent().write(ByteBuffer.wrap(resultBytes));

    HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
    if (null != relayStatsCollector)
    {
      HttpStatisticsCollector connStatsCollector = (HttpStatisticsCollector)
          request.getParams().get(relayStatsCollector.getName());
      if (null != connStatsCollector)
      {
        connStatsCollector.registerSourcesCall();
      }
      else
      {
        relayStatsCollector.registerSourcesCall();
      }
View Full Code Here

      mapper.writeValue(out,sources);
   
    byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
    request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
   
    HttpStatisticsCollector relayStatsCollector = _relay.getHttpStatisticsCollector();
    if (null != relayStatsCollector)
    {
      HttpStatisticsCollector connStatsCollector = (HttpStatisticsCollector)
          request.getParams().get(relayStatsCollector.getName());
      if (null != connStatsCollector)
      {
        connStatsCollector.registerSourcesCall();
      }
      else
      {
        relayStatsCollector.registerSourcesCall();
      }
View Full Code Here

TOP

Related Classes of com.linkedin.databus2.core.container.monitoring.mbean.HttpStatisticsCollector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.