use of io.confluent.kafkarest.entities.BrokerConfig in project kafka-rest by confluentinc.
the class ListAllBrokersConfigsActionTest method listAllBrokerConfigs_noBrokers_returnsEmptyConfigs.
@Test
public void listAllBrokerConfigs_noBrokers_returnsEmptyConfigs() {
expect(brokerManager.listBrokers(CLUSTER_ID)).andReturn(completedFuture(new ArrayList<>()));
expect(brokerConfigManager.listAllBrokerConfigs(CLUSTER_ID, new ArrayList<>())).andReturn(completedFuture(new HashMap<Integer, List<BrokerConfig>>()));
replay(brokerManager, brokerConfigManager);
FakeAsyncResponse response = new FakeAsyncResponse();
allBrokersConfigsAction.listBrokersConfigs(response, CLUSTER_ID);
ListBrokerConfigsResponse expected = ListBrokerConfigsResponse.create(BrokerConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/-/configs").build()).setData(new ArrayList<>()).build());
assertEquals(expected, response.getValue());
}
use of io.confluent.kafkarest.entities.BrokerConfig in project kafka-rest by confluentinc.
the class ListAllBrokersConfigsActionTest method listAllBrokerConfigs_existingBrokers_returnsConfigs.
@Test
public void listAllBrokerConfigs_existingBrokers_returnsConfigs() {
expect(brokerManager.listBrokers(CLUSTER_ID)).andReturn(completedFuture(Arrays.asList(Broker.create(CLUSTER_ID, BROKER_ID, "localhost", 9092, "us-east"))));
expect(brokerConfigManager.listAllBrokerConfigs(CLUSTER_ID, Arrays.asList(BROKER_ID))).andReturn(completedFuture(new HashMap<Integer, List<BrokerConfig>>() {
{
put(BROKER_ID, Arrays.asList(CONFIG_1, CONFIG_2, CONFIG_3));
}
}));
replay(brokerManager, brokerConfigManager);
FakeAsyncResponse response = new FakeAsyncResponse();
allBrokersConfigsAction.listBrokersConfigs(response, CLUSTER_ID);
ListBrokerConfigsResponse expected = ListBrokerConfigsResponse.create(BrokerConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/-/configs").build()).setData(Arrays.asList(BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs/config-1").setResourceName("crn:///kafka=cluster-1/broker=1/config=config-1").build()).setClusterId(CLUSTER_ID).setBrokerId(BROKER_ID).setName(CONFIG_1.getName()).setValue(CONFIG_1.getValue()).setDefault(CONFIG_1.isDefault()).setReadOnly(CONFIG_1.isReadOnly()).setSensitive(CONFIG_1.isSensitive()).setSource(CONFIG_1.getSource()).setSynonyms(CONFIG_1.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build(), BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs/config-2").setResourceName("crn:///kafka=cluster-1/broker=1/config=config-2").build()).setClusterId(CLUSTER_ID).setBrokerId(BROKER_ID).setName(CONFIG_2.getName()).setValue(CONFIG_2.getValue()).setDefault(CONFIG_2.isDefault()).setReadOnly(CONFIG_2.isReadOnly()).setSensitive(CONFIG_2.isSensitive()).setSource(CONFIG_2.getSource()).setSynonyms(CONFIG_2.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build(), BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/brokers/1/configs/config-3").setResourceName("crn:///kafka=cluster-1/broker=1/config=config-3").build()).setClusterId(CLUSTER_ID).setBrokerId(BROKER_ID).setName(CONFIG_3.getName()).setValue(CONFIG_3.getValue()).setDefault(CONFIG_3.isDefault()).setReadOnly(CONFIG_3.isReadOnly()).setSensitive(CONFIG_3.isSensitive()).setSource(CONFIG_3.getSource()).setSynonyms(CONFIG_3.getSynonyms().stream().map(ConfigSynonymData::fromConfigSynonym).collect(Collectors.toList())).build())).build());
assertEquals(expected, response.getValue());
}
use of io.confluent.kafkarest.entities.BrokerConfig in project kafka-rest by confluentinc.
the class ListAllBrokersConfigsAction method listBrokersConfigs.
@GET
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.brokers.configs.list")
@ResourceName("api.v3.brokers-configs.list")
public void listBrokersConfigs(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) {
BrokerConfigManager resolvedBrokerConfigManager = brokerConfigManager.get();
CompletableFuture<ListBrokerConfigsResponse> response = brokerManager.get().listBrokers(clusterId).thenCompose(brokers -> resolvedBrokerConfigManager.listAllBrokerConfigs(clusterId, brokers.stream().map(Broker::getBrokerId).collect(Collectors.toList())).thenApply(configs -> ListBrokerConfigsResponse.create(BrokerConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(urlFactory.create("v3", "clusters", clusterId, "brokers", "-", "configs")).build()).setData(configs.values().stream().flatMap(brokerConfigs -> brokerConfigs.stream().sorted(Comparator.comparing(BrokerConfig::getBrokerId))).map(brokerConfig -> BrokerConfigsResource.toBrokerConfigData(brokerConfig, crnFactory, urlFactory)).collect(Collectors.toList())).build())));
AsyncResponses.asyncResume(asyncResponse, response);
}
use of io.confluent.kafkarest.entities.BrokerConfig in project kafka-rest by confluentinc.
the class BrokerConfigManagerImplTest method listBrokerConfigs_existingBroker_returnsConfigs.
@Test
public void listBrokerConfigs_existingBroker_returnsConfigs() throws Exception {
expect(clusterManager.getCluster(CLUSTER_ID)).andReturn(completedFuture(Optional.of(CLUSTER)));
expect(adminClient.describeConfigs(eq(singletonList(new ConfigResource(ConfigResource.Type.BROKER, String.valueOf(BROKER_ID)))), anyObject(DescribeConfigsOptions.class))).andReturn(describeConfigsResult);
expect(describeConfigsResult.all()).andReturn(KafkaFuture.completedFuture(singletonMap(new ConfigResource(ConfigResource.Type.BROKER, String.valueOf(BROKER_ID)), CONFIG)));
replay(adminClient, clusterManager, describeConfigsResult);
List<BrokerConfig> configs = brokerConfigManager.listBrokerConfigs(CLUSTER_ID, BROKER_ID).get();
assertEquals(new HashSet<>(Arrays.asList(CONFIG_1, CONFIG_2, CONFIG_3)), new HashSet<>(configs));
}
use of io.confluent.kafkarest.entities.BrokerConfig in project kafka-rest by confluentinc.
the class BrokerConfigManagerImplTest method getBrokerConfig_nonExistingConfig_returnsEmpty.
@Test
public void getBrokerConfig_nonExistingConfig_returnsEmpty() throws Exception {
expect(clusterManager.getCluster(CLUSTER_ID)).andReturn(completedFuture(Optional.of(CLUSTER)));
expect(adminClient.describeConfigs(eq(singletonList(new ConfigResource(ConfigResource.Type.BROKER, String.valueOf(BROKER_ID)))), anyObject(DescribeConfigsOptions.class))).andReturn(describeConfigsResult);
expect(describeConfigsResult.all()).andReturn(KafkaFuture.completedFuture(singletonMap(new ConfigResource(ConfigResource.Type.BROKER, String.valueOf(BROKER_ID)), CONFIG)));
replay(adminClient, clusterManager, describeConfigsResult);
Optional<BrokerConfig> config = brokerConfigManager.getBrokerConfig(CLUSTER_ID, BROKER_ID, "foobar").get();
assertFalse(config.isPresent());
}
Aggregations