org.apache.commons.codec.EncoderException Java Examples

The following examples show how to use org.apache.commons.codec.EncoderException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FHex.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts a String or an array of bytes into an array of characters representing the hexadecimal values of each
 * byte in order. The returned array will be double the length of the passed String or array, as it takes two
 * characters to represent any given byte.
 * <p>
 * The conversion from hexadecimal characters to bytes to be encoded to performed with the charset named by
 * {@link #getCharset()}.
 * </p>
 *
 * @param object
 *            a String, ByteBuffer, or byte[] to convert to Hex characters
 * @return A char[] containing lower-case hexadecimal characters
 * @throws EncoderException
 *             Thrown if the given object is not a String or byte[]
 * @see #encodeHex(byte[])
 */
@Override
public Object encode(final Object object) throws EncoderException {
    byte[] byteArray;
    if (object instanceof String) {
        byteArray = ((String) object).getBytes(this.getCharset());
    } else if (object instanceof ByteBuffer) {
        byteArray = ((ByteBuffer) object).array();
    } else {
        try {
            byteArray = (byte[]) object;
        } catch (final ClassCastException e) {
            throw new EncoderException(e.getMessage(), e);
        }
    }
    return encodeHex(byteArray);
}
 
Example #2
Source File: MetadataTrackerTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
@Ignore("Superseded by AlfrescoSolrTrackerTest")
public void doTrackWithNoTransactionsDoesNothing() throws AuthenticationException, IOException, JSONException, EncoderException
{
    TrackerState state = new TrackerState();
    when(srv.getTrackerInitialState()).thenReturn(state);
    when(this.metadataTracker.getTrackerState()).thenReturn(state);

    Transactions txs = mock(Transactions.class);
    List<Transaction> txsList = new ArrayList<>();
    when(txs.getTransactions()).thenReturn(txsList);

    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), isNull(ShardState.class))).thenReturn(txs);
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), any(ShardState.class))).thenReturn(txs);
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt())).thenReturn(txs);

    this.metadataTracker.doTrack("AnIterationId");

    verify(srv, never()).commit();
}
 
Example #3
Source File: Hex.java    From pivaa with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts a String or an array of bytes into an array of characters representing the hexadecimal values of each
 * byte in order. The returned array will be double the length of the passed String or array, as it takes two
 * characters to represent any given byte.
 * <p>
 * The conversion from hexadecimal characters to bytes to be encoded to performed with the charset named by
 * {@link #getCharset()}.
 * </p>
 *
 * @param object
 *            a String, ByteBuffer, or byte[] to convert to Hex characters
 * @return A char[] containing lower-case hexadecimal characters
 * @throws EncoderException
 *             Thrown if the given object is not a String or byte[]
 * @see #encodeHex(byte[])
 */
@Override
public Object encode(final Object object) throws EncoderException {
    byte[] byteArray;
    if (object instanceof String) {
        byteArray = ((String) object).getBytes(this.getCharset());
    } else if (object instanceof ByteBuffer) {
        byteArray = ((ByteBuffer) object).array();
    } else {
        try {
            byteArray = (byte[]) object;
        } catch (final ClassCastException e) {
            throw new EncoderException(e.getMessage(), e);
        }
    }
    return encodeHex(byteArray);
}
 
Example #4
Source File: RFC1522Codec.java    From pivaa with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Applies an RFC 1522 compliant encoding scheme to the given string of text with the given charset.
 * <p>
 * This method constructs the "encoded-word" header common to all the RFC 1522 codecs and then invokes
 * {@link #doEncoding(byte [])} method of a concrete class to perform the specific encoding.
 *
 * @param text
 *            a string to encode
 * @param charset
 *            a charset to be used
 * @return RFC 1522 compliant "encoded-word"
 * @throws EncoderException
 *             thrown if there is an error condition during the Encoding process.
 * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 */
protected String encodeText(final String text, final Charset charset) throws EncoderException {
    if (text == null) {
        return null;
    }
    final StringBuilder buffer = new StringBuilder();
    buffer.append(PREFIX);
    buffer.append(charset);
    buffer.append(SEP);
    buffer.append(this.getEncoding());
    buffer.append(SEP);
    final byte [] rawData = this.doEncoding(text.getBytes(charset));
    buffer.append(StringUtils.newStringUsAscii(rawData));
    buffer.append(POSTFIX);
    return buffer.toString();
}
 
Example #5
Source File: DefaultHasher.java    From metron with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns a hash which has been encoded using the supplied encoder. If input is null then a string
 * containing all '0' will be returned. The length of the string is determined by the hashing algorithm
 * used.
 * @param toHash The value to hash.
 * @return A hash of {@code toHash} that has been encoded.
 * @throws EncoderException If unable to encode the hash then this exception occurs.
 * @throws NoSuchAlgorithmException If the supplied algorithm is not known.
 */
@Override
public String getHash(final Object toHash) throws EncoderException, NoSuchAlgorithmException {
  final MessageDigest messageDigest = MessageDigest.getInstance(algorithm);

  if (toHash == null) {
    return StringUtils.repeat("00", messageDigest.getDigestLength());
  } else if (toHash instanceof String) {
    return getHash(messageDigest, toHash.toString().getBytes(charset));
  } else if (toHash instanceof Serializable) {
    final byte[] serialized = SerializationUtils.serialize((Serializable) toHash);
    return getHash(messageDigest, serialized);
  }

  return null;
}
 
Example #6
Source File: TLSHHasher.java    From metron with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an encoded string representation of the hash value of the input. It is expected that
 * this implementation does throw exceptions when the input is null.
 *
 * @param o The value to hash.
 * @return A hash of {@code toHash} that has been encoded.
 * @throws EncoderException         If unable to encode the hash then this exception occurs.
 * @throws NoSuchAlgorithmException If the supplied algorithm is not known.
 */
@Override
public Object getHash(Object o) throws EncoderException, NoSuchAlgorithmException {
  TLSH tlsh = TLSHCache.INSTANCE.get().getTLSH(bucketOption, checksumOption);
  byte[] data = null;
  if (o instanceof String) {
    data = ((String)o).getBytes(StandardCharsets.UTF_8);
  } else if (o instanceof byte[]) {
    data = (byte[])o;
  } else {
    data = SerDeUtils.toBytes(o);
  }
  try {
    String hash = tlsh.apply(data, force);
    if (hashes != null && hashes.size() > 0) {
      Map<String, Object> ret = new HashMap<>();
      ret.put(TLSH_KEY, hash);
      ret.putAll(bin(hash));
      return ret;
    } else {
      return hash;
    }
  } catch (Exception e) {
    return null;
  }
}
 
Example #7
Source File: BasicAuthAuthenticatorTest.java    From carbon-device-mgt with Apache License 2.0 6 votes vote down vote up
@Test(description = "This method tests the behaviour of the authenticate method in BasicAuthenticator with valid "
        + "credentials", dependsOnMethods = "testCanHandleWithRequireParameters")
public void testAuthenticateWithValidCredentials() throws EncoderException, IllegalAccessException {
    String encodedString = new String(Base64.getEncoder().encode((ADMIN_USER + ":" + ADMIN_USER).getBytes()));
    request = new Request();
    context = new StandardContext();
    context.addParameter("basicAuth", "true");
    request.setContext(context);
    mimeHeaders = new MimeHeaders();
    bytes = mimeHeaders.addValue(BaseWebAppAuthenticatorFrameworkTest.AUTHORIZATION_HEADER);
    bytes.setString(BASIC_HEADER + encodedString);
    coyoteRequest = new org.apache.coyote.Request();
    headersField.set(coyoteRequest, mimeHeaders);
    request.setCoyoteRequest(coyoteRequest);
    AuthenticationInfo authenticationInfo = basicAuthAuthenticator.authenticate(request, null);
    Assert.assertEquals(authenticationInfo.getStatus(), WebappAuthenticator.Status.CONTINUE,
            "For a valid user authentication failed.");
    Assert.assertEquals(authenticationInfo.getUsername(), ADMIN_USER,
            "Authenticated username for from BasicAuthenticator is not matching with the original user.");
    Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
            "Authenticated user's tenant domain from BasicAuthenticator is not matching with the "
                    + "original user's tenant domain");
    Assert.assertEquals(authenticationInfo.getTenantId(), MultitenantConstants.SUPER_TENANT_ID,
            "Authenticated user's tenant ID from BasicAuthenticator is not matching with the "
                    + "original user's tenant ID");
}
 
Example #8
Source File: ColognePhonetic.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object encode(final Object object) throws EncoderException {
    if (!(object instanceof String)) {
        throw new EncoderException("This method's parameter was expected to be of the type " +
            String.class.getName() +
            ". But actually it was of the type " +
            object.getClass().getName() +
            ".");
    }
    return encode((String) object);
}
 
Example #9
Source File: QCodec.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its quoted-printable form using the default charset. Unsafe characters are escaped.
 *
 * @param obj
 *            object to convert to quoted-printable form
 * @return quoted-printable object
 * @throws EncoderException
 *             thrown if a failure condition is encountered during the encoding process.
 */
@Override
public Object encode(final Object obj) throws EncoderException {
    if (obj == null) {
        return null;
    } else if (obj instanceof String) {
        return encode((String) obj);
    } else {
        throw new EncoderException("Objects of type " +
              obj.getClass().getName() +
              " cannot be encoded using Q codec");
    }
}
 
Example #10
Source File: QuotedPrintableCodec.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its quoted-printable safe form. Unsafe characters are escaped.
 *
 * @param obj
 *            string to convert to a quoted-printable form
 * @return quoted-printable object
 * @throws EncoderException
 *             Thrown if quoted-printable encoding is not applicable to objects of this type or if encoding is
 *             unsuccessful
 */
@Override
public Object encode(final Object obj) throws EncoderException {
    if (obj == null) {
        return null;
    } else if (obj instanceof byte[]) {
        return encode((byte[]) obj);
    } else if (obj instanceof String) {
        return encode((String) obj);
    } else {
        throw new EncoderException("Objects of type " +
              obj.getClass().getName() +
              " cannot be quoted-printable encoded");
    }
}
 
Example #11
Source File: URLCodec.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes a string into its URL safe form using the default string charset. Unsafe characters are escaped.
 *
 * @param str
 *            string to convert to a URL safe form
 * @return URL safe string
 * @throws EncoderException
 *             Thrown if URL encoding is unsuccessful
 *
 * @see #getDefaultCharset()
 */
@Override
public String encode(final String str) throws EncoderException {
    if (str == null) {
        return null;
    }
    try {
        return encode(str, getDefaultCharset());
    } catch (final UnsupportedEncodingException e) {
        throw new EncoderException(e.getMessage(), e);
    }
}
 
Example #12
Source File: URLCodec.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its URL safe form. Unsafe characters are escaped.
 *
 * @param obj
 *            string to convert to a URL safe form
 * @return URL safe object
 * @throws EncoderException
 *             Thrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessful
 */
@Override
public Object encode(final Object obj) throws EncoderException {
    if (obj == null) {
        return null;
    } else if (obj instanceof byte[]) {
        return encode((byte[])obj);
    } else if (obj instanceof String) {
        return encode((String)obj);
    } else {
        throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be URL encoded");

    }
}
 
Example #13
Source File: BCodec.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its Base64 form using the default charset. Unsafe characters are escaped.
 *
 * @param value
 *            object to convert to Base64 form
 * @return Base64 object
 * @throws EncoderException
 *             thrown if a failure condition is encountered during the encoding process.
 */
@Override
public Object encode(final Object value) throws EncoderException {
    if (value == null) {
        return null;
    } else if (value instanceof String) {
        return encode((String) value);
    } else {
        throw new EncoderException("Objects of type " +
              value.getClass().getName() +
              " cannot be encoded using BCodec");
    }
}
 
Example #14
Source File: ColognePhonetic.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object encode(final Object object) throws EncoderException {
    if (!(object instanceof String)) {
        throw new EncoderException("This method's parameter was expected to be of the type " +
            String.class.getName() +
            ". But actually it was of the type " +
            object.getClass().getName() +
            ".");
    }
    return encode((String) object);
}
 
Example #15
Source File: BeiderMorseEncoder.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object encode(final Object source) throws EncoderException {
    if (!(source instanceof String)) {
        throw new EncoderException("BeiderMorseEncoder encode parameter is not of type String");
    }
    return encode((String) source);
}
 
Example #16
Source File: BeiderMorseEncoder.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String encode(final String source) throws EncoderException {
    if (source == null) {
        return null;
    }
    return this.engine.encode(source);
}
 
Example #17
Source File: URLCodec.java    From text_converter with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public String encode(@NonNull String text) {
    setMax(1);
    setConfident(1);
    org.apache.commons.codec.net.URLCodec urlCodec = new org.apache.commons.codec.net.URLCodec();
    try {
        return urlCodec.encode(text);
    } catch (EncoderException e) {
        setConfident(0);
        e.printStackTrace();
        return text;
    }
}
 
Example #18
Source File: SOLRAPIClient.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Transactions getTransactions(Long fromCommitTime, Long minTxnId, Long toCommitTime, Long maxTxnId, int maxResults) throws AuthenticationException, IOException, JSONException
{
    try
    {
        return getTransactions(fromCommitTime, minTxnId, toCommitTime, maxTxnId, maxResults, null);
    }
    catch (EncoderException e)
    {
        // Can not happen ....
        throw new IOException(e);
    }
}
 
Example #19
Source File: NodeStatePublisher.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void doTrack(String iterationId)
{
    try
    {
        ShardState shardstate = getShardState();
        client.getTransactions(0L, null, 0L, null, 0, shardstate);
    }
    catch (EncoderException | IOException | AuthenticationException exception )
    {
        LOGGER.error("Unable to publish this node state. " +
                "A failure condition has been met during the outbound subscription message encoding process. " +
                "See the stacktrace below for further details.", exception);
    }
}
 
Example #20
Source File: MetadataTrackerTest.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
@Ignore("Superseded by AlfrescoSolrTrackerTest")
public void doTrackWithOneTransactionUpdatesOnce() throws AuthenticationException, IOException, JSONException, EncoderException
{
    TrackerState state = new TrackerState();
    state.setTimeToStopIndexing(2L);
    when(srv.getTrackerInitialState()).thenReturn(state);
    // TrackerState is persisted per tracker
    when(this.metadataTracker.getTrackerState()).thenReturn(state);

    List<Transaction> txsList = new ArrayList<>();
    Transaction tx = new Transaction();
    tx.setCommitTimeMs(1L);
    tx.setDeletes(1);
    tx.setUpdates(1);
    txsList.add(tx);
    Transactions txs = mock(Transactions.class);
    when(txs.getTransactions()).thenReturn(txsList);

    // Subsequent calls to getTransactions must return a different set of transactions to avoid an infinite loop
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt())).thenReturn(txs)
                .thenReturn(txs).thenReturn(mock(Transactions.class));
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), isNull(ShardState.class))).thenReturn(txs)
    .thenReturn(txs).thenReturn(mock(Transactions.class));
    when(repositoryClient.getTransactions(anyLong(), anyLong(), anyLong(), anyLong(), anyInt(), any(ShardState.class))).thenReturn(txs)
    .thenReturn(txs).thenReturn(mock(Transactions.class));

    List<Node> nodes = new ArrayList<>();
    Node node = new Node();
    nodes.add(node );
    when(repositoryClient.getNodes(any(GetNodesParameters.class), anyInt())).thenReturn(nodes);
    
    this.metadataTracker.doTrack("AnIterationId");

    InOrder inOrder = inOrder(srv);
    inOrder.verify(srv).indexNodes(nodes, true);
    inOrder.verify(srv).indexTransaction(tx, true);
    inOrder.verify(srv).commit();
}
 
Example #21
Source File: QCodec.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its quoted-printable form using the default charset. Unsafe characters are escaped.
 *
 * @param obj
 *            object to convert to quoted-printable form
 * @return quoted-printable object
 * @throws EncoderException
 *             thrown if a failure condition is encountered during the encoding process.
 */
@Override
public Object encode(final Object obj) throws EncoderException {
    if (obj == null) {
        return null;
    } else if (obj instanceof String) {
        return encode((String) obj);
    } else {
        throw new EncoderException("Objects of type " +
              obj.getClass().getName() +
              " cannot be encoded using Q codec");
    }
}
 
Example #22
Source File: QuotedPrintableCodec.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its quoted-printable safe form. Unsafe characters are escaped.
 *
 * @param obj
 *            string to convert to a quoted-printable form
 * @return quoted-printable object
 * @throws EncoderException
 *             Thrown if quoted-printable encoding is not applicable to objects of this type or if encoding is
 *             unsuccessful
 */
@Override
public Object encode(final Object obj) throws EncoderException {
    if (obj == null) {
        return null;
    } else if (obj instanceof byte[]) {
        return encode((byte[]) obj);
    } else if (obj instanceof String) {
        return encode((String) obj);
    } else {
        throw new EncoderException("Objects of type " +
              obj.getClass().getName() +
              " cannot be quoted-printable encoded");
    }
}
 
Example #23
Source File: URLCodec.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes a string into its URL safe form using the default string charset. Unsafe characters are escaped.
 *
 * @param str
 *            string to convert to a URL safe form
 * @return URL safe string
 * @throws EncoderException
 *             Thrown if URL encoding is unsuccessful
 *
 * @see #getDefaultCharset()
 */
@Override
public String encode(final String str) throws EncoderException {
    if (str == null) {
        return null;
    }
    try {
        return encode(str, getDefaultCharset());
    } catch (final UnsupportedEncodingException e) {
        throw new EncoderException(e.getMessage(), e);
    }
}
 
Example #24
Source File: BeiderMorseEncoder.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String encode(final String source) throws EncoderException {
    if (source == null) {
        return null;
    }
    return this.engine.encode(source);
}
 
Example #25
Source File: URLCodec.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its URL safe form. Unsafe characters are escaped.
 *
 * @param obj
 *            string to convert to a URL safe form
 * @return URL safe object
 * @throws EncoderException
 *             Thrown if URL encoding is not applicable to objects of this type or if encoding is unsuccessful
 */
@Override
public Object encode(final Object obj) throws EncoderException {
    if (obj == null) {
        return null;
    } else if (obj instanceof byte[]) {
        return encode((byte[])obj);
    } else if (obj instanceof String) {
        return encode((String)obj);
    } else {
        throw new EncoderException("Objects of type " + obj.getClass().getName() + " cannot be URL encoded");

    }
}
 
Example #26
Source File: BCodec.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Encodes an object into its Base64 form using the default charset. Unsafe characters are escaped.
 *
 * @param value
 *            object to convert to Base64 form
 * @return Base64 object
 * @throws EncoderException
 *             thrown if a failure condition is encountered during the encoding process.
 */
@Override
public Object encode(final Object value) throws EncoderException {
    if (value == null) {
        return null;
    } else if (value instanceof String) {
        return encode((String) value);
    } else {
        throw new EncoderException("Objects of type " +
              value.getClass().getName() +
              " cannot be encoded using BCodec");
    }
}
 
Example #27
Source File: BeiderMorseEncoder.java    From pivaa with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object encode(final Object source) throws EncoderException {
    if (!(source instanceof String)) {
        throw new EncoderException("BeiderMorseEncoder encode parameter is not of type String");
    }
    return encode((String) source);
}
 
Example #28
Source File: MetadataTracker.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected Transactions getSomeTransactions(BoundedDeque<Transaction> txnsFound, Long fromCommitTime, long timeStep,
            int maxResults, long endTime)
        throws AuthenticationException, IOException, JSONException, EncoderException, NoSuchMethodException
{
    
    Transactions transactions;
    // step forward in time until we find something or hit the time bound
    // max id unbounded
    long startTime = fromCommitTime == null  ? 0L : fromCommitTime;
    if(startTime == 0)
    {
        return client.getTransactions(startTime,
                                      null,
                                      startTime + timeStep,
                                      null, 
                                      maxResults);
    }

    do
    {
        transactions = client.getTransactions(startTime, null, startTime + timeStep,
                null, maxResults);
        startTime += timeStep;
        
        // If no transactions are found, advance the time window to the next available transaction commit time
        if (nextTxCommitTimeServiceAvailable && transactions.getTransactions().size() == 0)
        {
            Long nextTxCommitTime = client.getNextTxCommitTime(coreName, startTime);
            if (nextTxCommitTime != -1)
            {
                LOGGER.info("{}-[CORE {}] Advancing transactions from {} to {}",
                        Thread.currentThread().getId(), coreName, startTime, nextTxCommitTime);
                transactions = client.getTransactions(nextTxCommitTime, null,
                        nextTxCommitTime + timeStep, null, maxResults);
            }
        }

    } while (((transactions.getTransactions().size() == 0) && (startTime < endTime))
                || ((transactions.getTransactions().size() > 0) && alreadyFoundTransactions(txnsFound, transactions)));


    return transactions;
}
 
Example #29
Source File: MetadataTracker.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * When using DB_ID_RANGE, fromCommitTime cannot be before the commit time of the first transaction
 * for the DB_ID_RANGE to be indexed and commit time of the last transaction cannot be lower than fromCommitTime.
 * When there isn't nodes in that range, -1 is returned as commit times
 *
 * @param fromCommitTime Starting commit time to get transactions from Repository
 * @param txnsFound List of transactions previously found
 * @return List of transactions to be indexed
 */
private Transactions getDBIDRangeTransactions(Long fromCommitTime, BoundedDeque<Transaction> txnsFound)
        throws NoSuchMethodException, AuthenticationException, IOException, JSONException, EncoderException
{
    boolean shardOutOfRange = false;

    DBIDRangeRouter dbIdRangeRouter = (DBIDRangeRouter) docRouter;
    Pair<Long, Long> commitTimes = client.getTxIntervalCommitTime(coreName,
            dbIdRangeRouter.getStartRange(), dbIdRangeRouter.getEndRange());
    Long shardMinCommitTime = commitTimes.getFirst();
    Long shardMaxCommitTime = commitTimes.getSecond();

    // Node Range it's not still available in repository
    if (shardMinCommitTime == -1)
    {
        LOGGER.debug(
                "{}-[CORE {}] [DB_ID_RANGE] No nodes in range [{}-{}] "
                        + "exist in the repository. Indexing only latest transaction.",
                Thread.currentThread().getId(), coreName, dbIdRangeRouter.getStartRange(),
                dbIdRangeRouter.getEndRange());
        shardOutOfRange = true;
    }
    if (fromCommitTime > shardMaxCommitTime)
    {
        LOGGER.debug(
                "{}-[CORE {}] [DB_ID_RANGE] Last commit time is greater that max commit time in in range [{}-{}]. "
                        + "Indexing only latest transaction.",
                Thread.currentThread().getId(), coreName, dbIdRangeRouter.getStartRange(),
                dbIdRangeRouter.getEndRange());
        shardOutOfRange = true;
    }
    // Initial commit time for Node Range is greater than calculated from commit time
    if (fromCommitTime < shardMinCommitTime)
    {
        LOGGER.debug("{}-[CORE {}] [DB_ID_RANGE] Skipping transactions from {} to {}",
                Thread.currentThread().getId(), coreName, fromCommitTime, shardMinCommitTime);
        fromCommitTime = shardMinCommitTime;
    }

    Transactions transactions = getSomeTransactions(txnsFound, fromCommitTime, timeStep, maxNumberOfTransactions,
                                       state.getTimeToStopIndexing());


    // When transactions are out of Shard range, only the latest transaction needs to be indexed
    // in order to preserve the state up-to-date of the MetadataTracker
    if (shardOutOfRange)
    {
        Transaction latestTransaction = new Transaction();
        latestTransaction.setCommitTimeMs(transactions.getMaxTxnCommitTime());
        latestTransaction.setId(transactions.getMaxTxnId());
        transactions = new Transactions(
                Collections.singletonList(latestTransaction),
                transactions.getMaxTxnCommitTime(),
                transactions.getMaxTxnId());
    }

    return transactions;
}
 
Example #30
Source File: MetadataTracker.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
public IndexHealthReport checkIndex(Long toTx, Long fromTime, Long toTime)
            throws IOException, AuthenticationException, JSONException, EncoderException, NoSuchMethodException
{
    // DB TX Count
    long firstTransactionCommitTime = 0;
    Transactions firstTransactions = client.getTransactions(null, 0L,
            null, INITIAL_MAX_TXN_ID, 1);
    if(firstTransactions.getTransactions().size() > 0)
    {
        Transaction firstTransaction = firstTransactions.getTransactions().get(0);
        firstTransactionCommitTime = firstTransaction.getCommitTimeMs();
    }

    IOpenBitSet txIdsInDb = infoSrv.getOpenBitSetInstance();
    long lastTxCommitTime = firstTransactionCommitTime;
    if (fromTime != null)
    {
        lastTxCommitTime = fromTime;
    }
    long maxTxId = 0;
    Long minTxId = null;

    Transactions transactions;
    BoundedDeque<Transaction> txnsFound = new BoundedDeque<>(METADATA_TRANSACTIONS_FOUND_QUEUE_SIZE);
    long endTime = System.currentTimeMillis() + infoSrv.getHoleRetention();
    DO: do
    {
        transactions = getSomeTransactions(txnsFound, lastTxCommitTime, timeStep, maxNumberOfTransactions, endTime);
        for (Transaction info : transactions.getTransactions())
        {
            // include
            if (toTime != null)
            {
                if (info.getCommitTimeMs() > toTime)
                {
                    break DO;
                }
            }
            if (toTx != null)
            {
                if (info.getId() > toTx)
                {
                    break DO;
                }
            }

            // bounds for later loops
            if (minTxId == null)
            {
                minTxId = info.getId();
            }
            if (maxTxId < info.getId())
            {
                maxTxId = info.getId();
            }

            lastTxCommitTime = info.getCommitTimeMs();
            txIdsInDb.set(info.getId());
            txnsFound.add(info);
        }
    }
    while (transactions.getTransactions().size() > 0);

    return this.infoSrv.reportIndexTransactions(minTxId, txIdsInDb, maxTxId);
}