org.apache.kafka.clients.admin.DeleteTopicsResult Java Examples
The following examples show how to use
org.apache.kafka.clients.admin.DeleteTopicsResult.
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: KafkaTopicClientImpl.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 6 votes |
@Override public void deleteTopics(final List<String> topicsToDelete) { if (!isDeleteTopicEnabled) { log.info("Cannot delete topics since 'delete.topic.enable' is false. "); return; } final DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(topicsToDelete); final Map<String, KafkaFuture<Void>> results = deleteTopicsResult.values(); List<String> failList = Lists.newArrayList(); for (final Map.Entry<String, KafkaFuture<Void>> entry : results.entrySet()) { try { entry.getValue().get(30, TimeUnit.SECONDS); } catch (Exception e) { failList.add(entry.getKey()); } } if (!failList.isEmpty()) { throw new KsqlException("Failed to clean up topics: " + failList.stream() .collect(Collectors.joining(","))); } }
Example #2
Source File: KafkaOperations.java From kafka-webview with MIT License | 6 votes |
/** * Remove a topic from a kafka cluster. This is destructive! * @param topic name of the topic to remove. * @return true on success. */ public boolean removeTopic(final String topic) { try { final DeleteTopicsResult result = adminClient.deleteTopics(Collections.singletonList(topic)); // Wait for the async request to process. result.all().get(); // return true? return true; } catch (final ExecutionException e) { throw handleExecutionException(e); } catch (final InterruptedException exception) { // TODO Handle this throw new RuntimeException(exception.getMessage(), exception); } }
Example #3
Source File: KafkaAdminClientImpl.java From vertx-kafka-client with Apache License 2.0 | 6 votes |
@Override public Future<Void> deleteTopics(List<String> topicNames) { ContextInternal ctx = (ContextInternal) vertx.getOrCreateContext(); Promise<Void> promise = ctx.promise(); DeleteTopicsResult deleteTopicsResult = this.adminClient.deleteTopics(topicNames); deleteTopicsResult.all().whenComplete((v, ex) -> { if (ex == null) { promise.complete(); } else { promise.fail(ex); } }); return promise.future(); }
Example #4
Source File: KafkaSystemAdmin.java From samza with Apache License 2.0 | 6 votes |
@Override public boolean clearStream(StreamSpec streamSpec) { LOG.info("Creating Kafka topic: {} on system: {}", streamSpec.getPhysicalName(), streamSpec.getSystemName()); String topicName = streamSpec.getPhysicalName(); try { DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(ImmutableSet.of(topicName)); deleteTopicsResult.all().get(KAFKA_ADMIN_OPS_TIMEOUT_MS, TimeUnit.MILLISECONDS); } catch (Exception e) { LOG.error("Failed to delete topic {} with exception {}.", topicName, e); return false; } return true; }
Example #5
Source File: KafkaTopicClientImplTest.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 5 votes |
private DeleteTopicsResult getDeleteInternalTopicsResult() { DeleteTopicsResult deleteTopicsResult = mock(DeleteTopicsResult.class); Map<String, KafkaFuture<Void>> deletedTopics = new HashMap<>(); deletedTopics.put(internalTopic1, KafkaFuture.allOf()); deletedTopics.put(internalTopic2, KafkaFuture.allOf()); expect(deleteTopicsResult.values()).andReturn(deletedTopics); replay(deleteTopicsResult); return deleteTopicsResult; }
Example #6
Source File: KafkaTopicClientImplTest.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 5 votes |
private DeleteTopicsResult getDeleteTopicsResult() { DeleteTopicsResult deleteTopicsResult = mock(DeleteTopicsResult.class); expect(deleteTopicsResult.values()).andReturn(Collections.singletonMap(topicName1, KafkaFuture .allOf())); replay(deleteTopicsResult); return deleteTopicsResult; }
Example #7
Source File: KafkaRule.java From kafka-pubsub-emulator with Apache License 2.0 | 5 votes |
public void deleteTopics(String... topics) throws Exception { try (AdminClient admin = AdminClient.create(getAdminConfig())) { DeleteTopicsResult deleteTopicsResult = admin.deleteTopics(Arrays.asList(topics)); deleteTopicsResult.all().get(5, TimeUnit.SECONDS); } catch (Exception e) { LOGGER.log(Level.SEVERE, "Error on delete topics " + Arrays.toString(topics), e); throw e; } }
Example #8
Source File: TopicAdmin.java From kafka-message-tool with MIT License | 5 votes |
public void deleteTopic(String topicName) throws Exception { Logger.trace(String.format("Deleting topic '%s'", topicName)); final DeleteTopicsResult result = kafkaClientsAdminClient.deleteTopics(Collections.singletonList(topicName)); for (Map.Entry<String, KafkaFuture<Void>> entry : result.values().entrySet()) { entry.getValue().get(ApplicationConstants.DELETE_TOPIC_FUTURE_GET_TIMEOUT_MS, TimeUnit.MILLISECONDS); } }
Example #9
Source File: AdminClientWrapper.java From hdinsight-kafka-java-get-started with MIT License | 5 votes |
public static void deleteTopics(String brokers, String topicName) throws IOException { // Set properties used to configure admin client Properties properties = getProperties(brokers); try (final AdminClient adminClient = KafkaAdminClient.create(properties)) { final DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(Collections.singleton(topicName)); deleteTopicsResult.values().get(topicName).get(); System.out.print("Topic " + topicName + " deleted"); } catch (Exception e) { System.out.print("Delete Topics denied\n"); System.out.print(e.getMessage()); //throw new RuntimeException(e.getMessage(), e); } }
Example #10
Source File: AdminClientWrapper.java From hdinsight-kafka-java-get-started with MIT License | 5 votes |
public static void deleteTopics(String brokers, String topicName) throws IOException { // Set properties used to configure admin client Properties properties = getProperties(brokers); try (final AdminClient adminClient = KafkaAdminClient.create(properties)) { final DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(Collections.singleton(topicName)); deleteTopicsResult.values().get(topicName).get(); System.out.print("Topic " + topicName + " deleted"); } catch (Exception e) { System.out.print("Delete Topics denied\n"); System.out.print(e.getMessage()); //throw new RuntimeException(e.getMessage(), e); } }
Example #11
Source File: KafkaImplTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
private void mockDeleteTopics(Admin admin, Map<String, Either<Void, Exception>> result) { DeleteTopicsResult deleteTopicsResult = mock(DeleteTopicsResult.class); when(deleteTopicsResult.values()).thenReturn(result.entrySet().stream().collect(toMap( entry -> entry.getKey(), entry -> { KafkaFutureImpl<Void> kafkaFuture = new KafkaFutureImpl<>(); if (entry.getValue().isLeft()) { kafkaFuture.complete(null); } else { kafkaFuture.completeExceptionally(entry.getValue().right()); } return kafkaFuture; }))); when(admin.deleteTopics(result.keySet())).thenReturn(deleteTopicsResult); }
Example #12
Source File: TopicOperatorBaseIT.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
protected void deleteTopicInKafka(String topicName, String resourceName) throws InterruptedException, ExecutionException { LOGGER.info("Deleting topic {} (KafkaTopic {})", topicName, resourceName); // Now we can delete the topic DeleteTopicsResult dlt = adminClient.deleteTopics(singletonList(topicName)); dlt.all().get(); LOGGER.info("Deleted topic {}", topicName); }
Example #13
Source File: IntegrationTestHarness.java From samza with Apache License 2.0 | 5 votes |
protected boolean deleteTopics(Collection<String> topics) { boolean deleteStatus = true; try { DeleteTopicsResult resultFutures = adminClient.deleteTopics(topics); resultFutures.all().get(ADMIN_OPERATION_WAIT_DURATION_MS, TimeUnit.MILLISECONDS); } catch (Exception e) { LOG.error("Error deleting topics: {}", StringUtils.join(topics, ","), e); deleteStatus = false; } return deleteStatus; }
Example #14
Source File: MiniKafkaCluster.java From incubator-pinot with Apache License 2.0 | 5 votes |
public boolean deleteTopic(String topicName) { final DeleteTopicsResult deleteTopicsResult = this.adminClient.deleteTopics(Collections.singletonList(topicName)); try { deleteTopicsResult.all().get(); } catch (InterruptedException | ExecutionException e) { LOGGER.error("Failed to delete Kafka topic: {}, Exception: {}", topicName, e); return false; } return true; }