Package com.linkedin.databus2.core.container.request

Examples of com.linkedin.databus2.core.container.request.RequestProcessingException


            }
          }
        }
      }
    }
    throw new RequestProcessingException("Unable to find registration (" + regId + ") ");
  }
View Full Code Here


          if ( regId.equals(e.getValue().getRegistrationId()))
            return e.getValue();
      }

    }
    throw new RequestProcessingException("Unable to find registration (" + regId + ") ");
  }
View Full Code Here

        }
        else
        {
          if (startSCN == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN)
          {
            throw new RequestProcessingException("Bootstrap DB is being initialized! startSCN=" + startSCN);
          }

          if (_config.isEnableMinScnCheck())
          {
            //snapshot isn't bypassed. Check if snapshot is possible from sinceScn by checking minScn
            long minScn = processor.getBootstrapMetaDataDAO().getMinScnOfSnapshots(srcStatusPairs);
            LOG.info("Min scn for tab tables is: " + minScn);
            if (minScn == BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN)
            {
              throw new BootstrapDatabaseTooYoungException("BootstrapDB has no minScn for these sources, but minScn check is enabled! minScn=" + minScn);
            }

            //Note: The cleaner deletes rows less than or equal to scn: BootstrapDBCleaner::doClean
            //sinceSCN should be greater than minScn, unless sinceScn=minScn=0
            if ((sinceScn <= minScn) && !(sinceScn==0 && minScn==0))
            {
              LOG.error("Bootstrap Snapshot doesn't have requested data . sinceScn too old! sinceScn is " + sinceScn +  " but minScn available is " + minScn);
              throw new BootstrapDatabaseTooYoungException("Min scn=" + minScn + " Since scn=" + sinceScn);
            }
          }
          else
          {
            LOG.debug("Bypassing minScn check! ");
          }
        }
      }
      catch (BootstrapDatabaseTooOldException tooOldException)
      {
        if (bootstrapStatsCollector != null)
        {
          bootstrapStatsCollector.registerErrStartSCN();
          bootstrapStatsCollector.registerErrDatabaseTooOld();
        }

        LOG.error("The bootstrap database is too old!", tooOldException);
        throw new RequestProcessingException(tooOldException);
      }
      catch (BootstrapDatabaseTooYoungException e)
      {
        if (bootstrapStatsCollector != null)
        {
          bootstrapStatsCollector.registerErrStartSCN();
          bootstrapStatsCollector.registerErrBootstrap();
        }
        LOG.error("The bootstrap database is too young!", e);
        throw new RequestProcessingException(e);
      }
      catch (SQLException e)
      {
          if (bootstrapStatsCollector != null)
          {
            bootstrapStatsCollector.registerErrStartSCN();
              bootstrapStatsCollector.registerErrSqlException();
          }
        LOG.error("Error encountered while fetching startSCN from database.", e);
        throw new RequestProcessingException(e);
      }
      mapper.writeValue(out, String.valueOf(startSCN));
      byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
      request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
      LOG.info("startSCN: " + startSCN + " with server Info :" + _serverHostPort);

    } catch (RequestProcessingException ex) {
      LOG.error("Got exception while calculating startSCN", ex);
      throw ex;
    } catch (Exception ex) {
      LOG.error("Got exception while calculating startSCN", ex);
      throw new RequestProcessingException(ex);
    } finally {
      if ( null != processor)
        processor.shutdown();
    }
View Full Code Here

            bootstrapStatsCollector.registerErrTargetSCN();
            bootstrapStatsCollector.registerErrDatabaseTooOld();
          }

        LOG.error("The bootstrap database is too old!", tooOldException);
        throw new RequestProcessingException(tooOldException);
      }
      catch (SQLException e)
      {
        if (bootstrapStatsCollector != null)
          {
            bootstrapStatsCollector.registerErrTargetSCN();
            bootstrapStatsCollector.registerErrSqlException();
          }

        LOG.error("Error encountered while fetching targetSCN from database.", e);
        throw new RequestProcessingException(e);
      }

      ObjectMapper mapper = new ObjectMapper();
      StringWriter out = new StringWriter(1024);
      mapper.writeValue(out, String.valueOf(targetScn));
      byte[] resultBytes = out.toString().getBytes(Charset.defaultCharset());
      request.getResponseContent().write(ByteBuffer.wrap(resultBytes));
      LOG.info("targetSCN: " + targetScn);
    } catch (Exception ex) {
      LOG.error("Got exception while calculating targetSCN", ex);
      throw new RequestProcessingException(ex);
    } finally {
      if ( null != processor)
        processor.shutdown();
    }
View Full Code Here

      // 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)
      {
View Full Code Here

    }
    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();
View Full Code Here

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

    if (versionedSchemas != null && !versionedSchemas.isEmpty())
    {
      for (SchemaId id:  versionedSchemas.keySet())
      {
        VersionedSchema entry = versionedSchemas.get(id);
        if (entry.getOrigSchemaStr() == null)
        {
          throw new RequestProcessingException("Null schema string for metadata version " + entry.getVersion());
        }
        registeredMetadata.add(new RegisterResponseMetadataEntry((short)entry.getVersion(),
                                                                 entry.getOrigSchemaStr(),
                                                                 id.getByteArray()));
      }
View Full Code Here

    {
      //PhysicalPartition pPartition = new PhysicalPartition(physicalPartitionId);
      // TODO this should actually use DbusEventBufferAppendable (DDSDBUS-78)
      DbusEventBuffer buf = (DbusEventBuffer)_eventBuffer.getDbusEventBufferAppendable(pPartition);
      if(buf == null)
        throw new RequestProcessingException("cannot find buffer for ph. partion " + pPartition);

      if ((buf.getMinScn() < 0) && (buf.getPrevScn() < 0)) buf.start(0);

      try
      {
        DbusEventsStatisticsCollector statsCollector = _relay.getInBoundStatsCollectors().getStatsCollector(pPartition.toSimpleString());

        int eventsAppended = 0;
        if (!((eventsAppended = DbusEventSerializable.appendToEventBuffer(in, buf, statsCollector, startWin))>0))
        {
          throw new RequestProcessingException("event loading failed");
        }

        StringBuilder res = new StringBuilder(20);
        res.append("{\"eventsAppended\":");
        res.append(eventsAppended);
        res.append("}");

        request.getResponseContent().write(ByteBuffer.wrap(res.toString().getBytes(Charset.defaultCharset())));
      }
      catch (InvalidEventException iee)
      {
        throw new RequestProcessingException(iee);
      }
      catch (RuntimeException re)
      {
        LOG.error("runttime excception: " + re.getMessage(), re);
        throw re;
View Full Code Here

  protected void initializeBootstrapServerCommandProcessors() throws DatabusException
  {
    LOG.info("Initializing Bootstrap HTTP Server");
    LOG.info("Config=" + _bootstrapServerConfig);
    try{
      RequestProcessorRegistry processorRegistry = getProcessorRegistry();
      processorRegistry.register(ConfigRequestProcessor.COMMAND_NAME,
                                 new ConfigRequestProcessor(null, this));
      processorRegistry.register(BootstrapRequestProcessor.COMMAND_NAME,
                                 new BootstrapRequestProcessor(null, _bootstrapServerConfig, this));
      processorRegistry.register(StartSCNRequestProcessor.COMMAND_NAME,
                                 new StartSCNRequestProcessor(null, _bootstrapServerConfig, this));
      processorRegistry.register(TargetSCNRequestProcessor.COMMAND_NAME,
                                 new TargetSCNRequestProcessor(null, _bootstrapServerConfig, this));
      processorRegistry.register(ContainerOperationProcessor.COMMAND_NAME,
                                 new ContainerOperationProcessor(null, this));
    }
    catch (SQLException sqle)
    {
      throw new DatabusException("command registration failed", sqle);
View Full Code Here

      _csEventRequestProcessor = new ControlSourceEventsRequestProcessor(
          null, this, plist);
    else
      _csEventRequestProcessor.addEventProducers(plist);

    RequestProcessorRegistry processorRegistry = getProcessorRegistry();
    processorRegistry.reregister(
        ControlSourceEventsRequestProcessor.COMMAND_NAME,
        _csEventRequestProcessor);
  }
View Full Code Here

TOP

Related Classes of com.linkedin.databus2.core.container.request.RequestProcessingException

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.