private void log(String errorMessage, Topic topic, String messageId, String hostAndPort) { logger.error(new StringBuilder() .append(errorMessage) .append("; publishing on topic: ") .append(topic.getQualifiedName()) .append("; message id: ") .append(messageId) .append("; remote host: ") .append(hostAndPort) .toString()); trackers.get(topic).logError(messageId, topic.getName(), errorMessage, hostAndPort); }
@Override public void onTopicRemoved(Topic topic) { if (topicCache.containsKey(topic.getName().qualifiedName())) { Topic cachedTopic = topicCache.get(topic.getName().qualifiedName()).getTopic(); if (cachedTopic.equals(topic)) { topicCache.remove(topic.getName().qualifiedName()); } else { logger.warn("Received event about removed topic but cache contains different topic under the same name." + "Cached topic {}, removed topic {}", cachedTopic, topic); } } }
private Stream<Subscription> notSuspendedSubscriptionsForTopic(Topic topic) { return subscriptionRepository.listSubscriptions(topic.getName()) .stream() .filter(sub -> Subscription.State.SUSPENDED != sub.getState()); } }
@Override public List<SchemaVersion> versions(Topic topic, boolean online) { try { return rawSchemaClient.getVersions(topic.getName()); } catch (Exception e) { logger.error("Error while loading schema versions for topic {}", topic.getQualifiedName(), e); return emptyList(); } }
@Override public void onTopicChanged(Topic topic) { for (Subscription subscription : subscriptionsCache.subscriptionsOfTopic(topic.getName())) { executorService.submit(() -> supervisor.updateTopic(subscription, topic)); } }
@Override public void onTopicCreated(Topic topic) { topicCache.put(topic.getName().qualifiedName(), cachedTopic(topic)); }
@Override public List<SchemaVersion> load(Topic topic) throws Exception { logger.debug("Loading schema versions for topic {}", topic.getQualifiedName()); return rawSchemaClient.getVersions(topic.getName()); }
@Override public CompiledSchema<T> getSchema(Topic topic, SchemaVersion version, boolean online) { return rawSchemaClient.getSchema(topic.getName(), version) .map(rawSchema -> new CompiledSchema<>(schemaCompiler.compile(rawSchema), version)) .orElseThrow(() -> new SchemaNotFoundException(topic, version)); } }
private void createTopicInBrokers(Topic topic) { try { multiDCAwareService.manageTopic(brokerTopicManagement -> brokerTopicManagement.createTopic(topic) ); } catch (Exception exception) { logger.error( String.format("Could not create topic %s, rollback topic creation.", topic.getQualifiedName()), exception ); topicRepository.removeTopic(topic.getName()); } }
public void markStatusCodeMeter(int status) { httpStatusCodesMeters.computeIfAbsent( status, code -> new MetersPair( hermesMetrics.httpStatusCodeMeter(status), hermesMetrics.httpStatusCodeMeter(status, topic.getName())) ).mark(); }
@Test public void shouldDeserializeTopic() throws Exception { // given String json = "{\"name\":\"foo.bar\", \"description\": \"description\"}"; // when Topic topic = objectMapper.readValue(json, Topic.class); // then assertThat(topic.getName().getName()).isEqualTo("bar"); assertThat(topic.getName().getGroupName()).isEqualTo("foo"); assertThat(topic.getDescription()).isEqualTo("description"); }
public MultiDCOffsetChangeSummary moveOffset(Topic topic, String subscriptionName, Long timestamp, boolean dryRun) { MultiDCOffsetChangeSummary multiDCOffsetChangeSummary = new MultiDCOffsetChangeSummary(); clusters.forEach(cluster -> multiDCOffsetChangeSummary.addPartitionOffsetList( cluster.getClusterName(), cluster.indicateOffsetChange(topic, subscriptionName, timestamp, dryRun))); if (!dryRun) { logger.info("Preparing retransmission for subscription {}", topic.getQualifiedName() + "$" + subscriptionName); adminTool.retransmit(new SubscriptionName(subscriptionName, topic.getName())); clusters.forEach(clusters -> waitUntilOffsetsAreMoved(topic, subscriptionName)); } return multiDCOffsetChangeSummary; }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { AttachmentContent attachment = exchange.getAttachment(AttachmentContent.KEY); try { next.handleRequest(exchange); } finally { messagePreviewLog.add(attachment.getTopic().getName(), attachment.getMessage()); } } }
public void registerSchema(Topic topic, String schema, boolean validate) { if (validate) { SchemaValidator validator = validatorProvider.provide(topic.getContentType()); validator.check(schema); } rawSchemaClient.registerSchema(topic.getName(), RawSchema.valueOf(schema)); }
@Override public boolean areOffsetsMoved(Topic topic, String subscriptionName, String brokersClusterName) { return kafkaNamesMapper.toKafkaTopics(topic).allMatch(kafkaTopic -> { List<Integer> partitionIds = brokerStorage.readPartitionsIds(kafkaTopic.name().asString()); return subscriptionOffsetChange.areOffsetsMoved(topic.getName(), subscriptionName, brokersClusterName, kafkaTopic, partitionIds); }); }
private void migrateTopic(Topic topic, Group group, String sourceName, OwnerExistsStrategy strategy, EntityMigrationCounters topicCounters) { if (topic.getOwner() == null || strategy == OwnerExistsStrategy.OVERRIDE) { migrateEntity(topicCounters, "topic " + topic.getQualifiedName(), () -> topicService.updateTopic(topic.getName(), patchWithOwner(sourceName, group.getSupportTeam()), MIGRATION_USER) ); } else { topicCounters.markSkipped(OWNER_ALREADY_EXISTED_REASON); } }
public void delayedSent(HttpServerExchange exchange, CachedTopic cachedTopic, Message message) { trackers.get(cachedTopic.getTopic()).logPublished(message.getId(), cachedTopic.getTopic().getName(), readHostAndPort(exchange)); brokerListeners.onAcknowledge(message, cachedTopic.getTopic()); cachedTopic.incrementPublished(); }
public void bufferedButDelayed(HttpServerExchange exchange, AttachmentContent attachment) { Topic topic = attachment.getTopic(); brokerListeners.onTimeout(attachment.getMessage(), topic); trackers.get(topic).logInflight(attachment.getMessageId(), topic.getName(), readHostAndPort(exchange)); handleRaceConditionBetweenAckAndTimeout(attachment, topic); sendResponse(exchange, attachment, StatusCodes.ACCEPTED); }