org.apache.kafka.common.errors.PolicyViolationException Java Examples

The following examples show how to use org.apache.kafka.common.errors.PolicyViolationException. 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: PolicyDemo.java    From kafka_book_demo with Apache License 2.0 6 votes vote down vote up
public void validate(RequestMetadata requestMetadata)
        throws PolicyViolationException {
    if (requestMetadata.numPartitions() != null ||
            requestMetadata.replicationFactor() != null) {
        if (requestMetadata.numPartitions() < 5) {
            throw new PolicyViolationException("Topic should have at " +
                    "least 5 partitions, received: "+
                    requestMetadata.numPartitions());
        }
        if (requestMetadata.replicationFactor() <= 1) {
            throw new PolicyViolationException("Topic should have at " +
                    "least 2 replication factor, recevied: "+
                    requestMetadata.replicationFactor());
        }
    }
}
 
Example #2
Source File: PolicyDemo.java    From BigData-In-Practice with Apache License 2.0 6 votes vote down vote up
public void validate(RequestMetadata requestMetadata)
        throws PolicyViolationException {
    if (requestMetadata.numPartitions() != null ||
            requestMetadata.replicationFactor() != null) {
        if (requestMetadata.numPartitions() < 5) {
            throw new PolicyViolationException("Topic should have at " +
                    "least 5 partitions, received: " +
                    requestMetadata.numPartitions());
        }
        if (requestMetadata.replicationFactor() <= 1) {
            throw new PolicyViolationException("Topic should have at " +
                    "least 2 replication factor, recevied: " +
                    requestMetadata.replicationFactor());
        }
    }
}
 
Example #3
Source File: KafkaExceptionMapperTest.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
@Test
public void testKafkaExceptions() {
  //exceptions mapped in KafkaExceptionMapper
  verifyMapperResponse(new BrokerNotAvailableException("some message"), Status.SERVICE_UNAVAILABLE,
      BROKER_NOT_AVAILABLE_ERROR_CODE);

  verifyMapperResponse(new InvalidReplicationFactorException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new SecurityDisabledException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new UnsupportedVersionException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new InvalidPartitionsException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new InvalidRequestException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new UnknownServerException("some message"),Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new UnknownTopicOrPartitionException("some message"), Status.NOT_FOUND,
      KAFKA_UNKNOWN_TOPIC_PARTITION_CODE);
  verifyMapperResponse(new PolicyViolationException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new TopicExistsException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);
  verifyMapperResponse(new InvalidConfigurationException("some message"), Status.BAD_REQUEST,
      KAFKA_BAD_REQUEST_ERROR_CODE);

  //test couple of retriable exceptions
  verifyMapperResponse(new NotCoordinatorException("some message"), Status.INTERNAL_SERVER_ERROR,
      KAFKA_RETRIABLE_ERROR_ERROR_CODE);
  verifyMapperResponse(new NotEnoughReplicasException("some message"), Status.INTERNAL_SERVER_ERROR,
      KAFKA_RETRIABLE_ERROR_ERROR_CODE);

  //test couple of kafka exception
  verifyMapperResponse(new CommitFailedException(), Status.INTERNAL_SERVER_ERROR,
      KAFKA_ERROR_ERROR_CODE);
  verifyMapperResponse(new ConcurrentTransactionsException("some message"), Status.INTERNAL_SERVER_ERROR,
      KAFKA_ERROR_ERROR_CODE);

  //test few general exceptions
  verifyMapperResponse(new NullPointerException("some message"), Status.INTERNAL_SERVER_ERROR,
      Status.INTERNAL_SERVER_ERROR.getStatusCode());
  verifyMapperResponse(new IllegalArgumentException("some message"), Status.INTERNAL_SERVER_ERROR,
      Status.INTERNAL_SERVER_ERROR.getStatusCode());
}