Skip to content

Commit

Permalink
Google java format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
szczygiel-m committed Jan 22, 2025
1 parent 27af5ed commit cab46da
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public String consumersWorkloadConstraintsPath(String constraintsPath) {
return Joiner.on(URL_SEPARATOR).join(consumersWorkloadConstraintsPath(), constraintsPath);
}

public String oAuthProvidersPath() {
return Joiner.on(URL_SEPARATOR).join(basePath, OAUTH_PROVIDERS_PATH);
}
public String oAuthProvidersPath() {
return Joiner.on(URL_SEPARATOR).join(basePath, OAUTH_PROVIDERS_PATH);
}

public String oAuthProviderPath(String oAuthProviderName) {
return Joiner.on(URL_SEPARATOR).join(oAuthProvidersPath(), oAuthProviderName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import pl.allegro.tech.hermes.frontend.metric.CachedTopic;
import pl.allegro.tech.hermes.frontend.metric.ThroughputRegistry;

public class NotificationBasedTopicsCache
implements TopicCallback, TopicsCache {
public class NotificationBasedTopicsCache implements TopicCallback, TopicsCache {

private static final Logger logger = LoggerFactory.getLogger(NotificationBasedTopicsCache.class);

Expand All @@ -30,19 +29,20 @@ public class NotificationBasedTopicsCache
private final KafkaNamesMapper kafkaNamesMapper;
private final ThroughputRegistry throughputRegistry;

public NotificationBasedTopicsCache(InternalNotificationsBus notificationsBus,
GroupRepository groupRepository,
TopicRepository topicRepository,
MetricsFacade metricsFacade,
ThroughputRegistry throughputRegistry,
KafkaNamesMapper kafkaNamesMapper) {
this.groupRepository = groupRepository;
this.topicRepository = topicRepository;
this.metricsFacade = metricsFacade;
this.kafkaNamesMapper = kafkaNamesMapper;
this.throughputRegistry = throughputRegistry;
notificationsBus.registerTopicCallback(this);
}
public NotificationBasedTopicsCache(
InternalNotificationsBus notificationsBus,
GroupRepository groupRepository,
TopicRepository topicRepository,
MetricsFacade metricsFacade,
ThroughputRegistry throughputRegistry,
KafkaNamesMapper kafkaNamesMapper) {
this.groupRepository = groupRepository;
this.topicRepository = topicRepository;
this.metricsFacade = metricsFacade;
this.kafkaNamesMapper = kafkaNamesMapper;
this.throughputRegistry = throughputRegistry;
notificationsBus.registerTopicCallback(this);
}

@Override
public void onTopicCreated(Topic topic) {
Expand Down Expand Up @@ -70,10 +70,10 @@ public void onTopicChanged(Topic topic) {
topicCache.put(topic.getName().qualifiedName(), cachedTopic(topic));
}

@Override
public Optional<CachedTopic> getTopic(String qualifiedTopicName) {
return Optional.ofNullable(topicCache.get(qualifiedTopicName));
}
@Override
public Optional<CachedTopic> getTopic(String qualifiedTopicName) {
return Optional.ofNullable(topicCache.get(qualifiedTopicName));
}

@Override
public List<CachedTopic> getTopics() {
Expand All @@ -89,7 +89,8 @@ public void start() {
}
}

private CachedTopic cachedTopic(Topic topic) {
return new CachedTopic(topic, metricsFacade, throughputRegistry, kafkaNamesMapper.toKafkaTopics(topic));
}
private CachedTopic cachedTopic(Topic topic) {
return new CachedTopic(
topic, metricsFacade, throughputRegistry, kafkaNamesMapper.toKafkaTopics(topic));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import jakarta.inject.Named;
import java.time.Clock;
import java.util.List;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -21,7 +20,6 @@
import pl.allegro.tech.hermes.frontend.producer.BrokerMessageProducer;
import pl.allegro.tech.hermes.frontend.validator.MessageValidators;
import pl.allegro.tech.hermes.frontend.validator.TopicMessageValidator;
import pl.allegro.tech.hermes.infrastructure.zookeeper.ZookeeperPaths;
import pl.allegro.tech.hermes.schema.SchemaExistenceEnsurer;
import pl.allegro.tech.hermes.schema.SchemaRepository;
import pl.allegro.tech.hermes.tracker.frontend.Trackers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

public class CachedTopic {

private final Topic topic;
private final KafkaTopics kafkaTopics;
private final MetricsFacade metricsFacade;
private final Topic topic;
private final KafkaTopics kafkaTopics;
private final MetricsFacade metricsFacade;

private final HermesTimer topicProducerLatencyTimer;
private final HermesTimer globalProducerLatencyTimer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ private void onRequestValid(
String topicName = exchange.getQueryParameters().get("qualifiedTopicName").getFirst();
Optional<CachedTopic> maybeTopic = topicsCache.getTopic(topicName);

if (!maybeTopic.isPresent()) {
if (maybeTopic.isEmpty()) {
unknownTopic(exchange, topicName, messageId);
return;
}

CachedTopic cachedTopic = maybeTopic.get();
CachedTopic cachedTopic = maybeTopic.get();

Topic topic = cachedTopic.getTopic();
if (topic.isAuthEnabled() && !hasPermission(exchange, topic)) {
Expand Down Expand Up @@ -108,13 +108,11 @@ private void unknownTopic(
UNKNOWN_TOPIC_NAME);
}

private void requestForbidden(HttpServerExchange exchange, String messageId, String qualifiedTopicName) {
messageErrorProcessor.sendQuietly(
exchange,
error("Permission denied.", AUTH_ERROR),
messageId,
qualifiedTopicName);
}
private void requestForbidden(
HttpServerExchange exchange, String messageId, String qualifiedTopicName) {
messageErrorProcessor.sendQuietly(
exchange, error("Permission denied.", AUTH_ERROR), messageId, qualifiedTopicName);
}

// Default Undertow's response code (200) was changed in order to avoid situations in which
// something wrong happens and Hermes-Frontend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package pl.allegro.tech.hermes.management.config.storage;

import static org.slf4j.LoggerFactory.getLogger;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down Expand Up @@ -46,8 +43,6 @@
@EnableConfigurationProperties(StorageClustersProperties.class)
public class StorageConfiguration {

private static final Logger logger = getLogger(StorageConfiguration.class);

@Autowired StorageClustersProperties storageClustersProperties;

@Autowired ObjectMapper objectMapper;
Expand Down Expand Up @@ -148,11 +143,12 @@ MessagePreviewRepository messagePreviewRepository() {
localClient.getCuratorFramework(), objectMapper, zookeeperPaths());
}

@Bean
WorkloadConstraintsRepository workloadConstraintsRepository() {
ZookeeperClient localClient = clientManager().getLocalClient();
return new ZookeeperWorkloadConstraintsRepository(localClient.getCuratorFramework(), objectMapper, zookeeperPaths());
}
@Bean
WorkloadConstraintsRepository workloadConstraintsRepository() {
ZookeeperClient localClient = clientManager().getLocalClient();
return new ZookeeperWorkloadConstraintsRepository(
localClient.getCuratorFramework(), objectMapper, zookeeperPaths());
}

@Bean
@Primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,16 @@ public void createTopicWithSchema(
createTopic(topic, createdBy, isAllowedToManage);
}

public void removeTopicWithSchema(Topic topic, RequestUser removedBy) {
auditor.beforeObjectRemoval(removedBy.getUsername(), Topic.class.getSimpleName(), topic.getQualifiedName());
subscriptionRemover.removeSubscriptionRelatedToTopic(topic, removedBy);
removeSchema(topic);
if (!topicProperties.isAllowRemoval()) {
throw new TopicRemovalDisabledException(topic);
}
removeTopic(topic, removedBy);
public void removeTopicWithSchema(Topic topic, RequestUser removedBy) {
auditor.beforeObjectRemoval(
removedBy.getUsername(), Topic.class.getSimpleName(), topic.getQualifiedName());
subscriptionRemover.removeSubscriptionRelatedToTopic(topic, removedBy);
removeSchema(topic);
if (!topicProperties.isAllowRemoval()) {
throw new TopicRemovalDisabledException(topic);
}
removeTopic(topic, removedBy);
}

public void updateTopicWithSchema(TopicName topicName, PatchData patch, RequestUser modifiedBy) {
Topic topic = getTopicDetails(topicName);
Expand Down Expand Up @@ -286,9 +287,7 @@ public List<Topic> getAllTopics() {

public Optional<byte[]> preview(TopicName topicName, int idx) {
List<byte[]> result =
loadMessagePreviewsFromAllDc(topicName).stream()
.map(MessagePreview::getContent)
.collect(toList());
loadMessagePreviewsFromAllDc(topicName).stream().map(MessagePreview::getContent).toList();

if (idx >= 0 && idx < result.size()) {
return Optional.of(result.get(idx));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.allegro.tech.hermes.management.infrastructure.zookeeper;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -120,9 +119,9 @@ public void start() {
new ZookeeperMessagePreviewRepository(zookeeper, mapper, paths);
messagePreviewRepositoriesByDc.put(dcName, messagePreviewRepository);

WorkloadConstraintsRepository workloadConstraintsRepository =
new ZookeeperWorkloadConstraintsRepository(zookeeper, mapper, paths);
workloadConstraintsRepositoriesByDc.put(dcName, workloadConstraintsRepository);
WorkloadConstraintsRepository workloadConstraintsRepository =
new ZookeeperWorkloadConstraintsRepository(zookeeper, mapper, paths);
workloadConstraintsRepositoriesByDc.put(dcName, workloadConstraintsRepository);

LastUndeliveredMessageReader lastUndeliveredMessageReader =
new ZookeeperLastUndeliveredMessageReader(zookeeper, paths, mapper);
Expand Down Expand Up @@ -167,7 +166,7 @@ public <T> DatacenterBoundRepositoryHolder<T> getLocalRepository(Class<T> reposi

public <T> List<DatacenterBoundRepositoryHolder<T>> getRepositories(Class<T> repositoryType) {
return getRepositoriesByType(repositoryType).entrySet().stream()
.sorted(Comparator.comparing(Map.Entry::getKey))
.sorted(Map.Entry.comparingByKey())
.map(entry -> new DatacenterBoundRepositoryHolder<>(entry.getValue(), entry.getKey()))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public void shouldRemoveTopic() {
() -> assertThat(getGroupTopicsList(topic.getName().getGroupName())).isEmpty());
}

@Test
public void shouldNotAllowOnDeletingTopicWithSubscriptions() {
// given
Topic topic = hermes.initHelper().createTopic(topicWithRandomName().build());
hermes.initHelper().createSubscription(subscriptionWithRandomName(topic.getName()).build());
@Test
public void shouldNotAllowOnDeletingTopicWithSubscriptions() {
// given
Topic topic = hermes.initHelper().createTopic(topicWithRandomName().build());
hermes.initHelper().createSubscription(subscriptionWithRandomName(topic.getName()).build());

// when
WebTestClient.ResponseSpec response = hermes.api().deleteTopic(topic.getQualifiedName());
Expand Down

0 comments on commit cab46da

Please sign in to comment.