Search in sources :

Example 1 with ListBrokerConfigsResponse

use of io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse in project kafka-rest by confluentinc.

the class ListAllBrokersConfigsActionIntegrationTest method listBrokersConfigs_existingBrokers_returnsConfigs.

@Test
public void listBrokersConfigs_existingBrokers_returnsConfigs() {
    String baseUrl = restConnect;
    String clusterId = getClusterId();
    ResourceCollection.Metadata expectedMetadata = ResourceCollection.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/brokers/-/configs").build();
    BrokerConfigData expectedBroker1Config1 = createBrokerConfigData(baseUrl, clusterId, 0, "log.cleaner.min.compaction.lag.ms", "0", true, false, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("log.cleaner.min.compaction.lag.ms").setValue("0").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    BrokerConfigData expectedBroker1Config2 = createBrokerConfigData(baseUrl, clusterId, 0, "offsets.topic.num.partitions", "5", false, true, ConfigSource.STATIC_BROKER_CONFIG, ImmutableList.of(ConfigSynonymData.builder().setName("offsets.topic.num.partitions").setValue("5").setSource(ConfigSource.STATIC_BROKER_CONFIG).build(), ConfigSynonymData.builder().setName("offsets.topic.num.partitions").setValue("50").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    BrokerConfigData expectedBroker2Config1 = createBrokerConfigData(baseUrl, clusterId, 1, "num.network.threads", "3", true, false, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("num.network.threads").setValue("3").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    BrokerConfigData expectedBroker2Config2 = createBrokerConfigData(baseUrl, clusterId, 1, "default.replication.factor", "1", false, true, ConfigSource.STATIC_BROKER_CONFIG, ImmutableList.of(ConfigSynonymData.builder().setName("default.replication.factor").setValue("1").setSource(ConfigSource.STATIC_BROKER_CONFIG).build(), ConfigSynonymData.builder().setName("default.replication.factor").setValue("1").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    BrokerConfigData expectedBroker2Config3 = createBrokerConfigData(baseUrl, clusterId, 1, "queued.max.request.bytes", "-1", true, true, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("queued.max.request.bytes").setValue("-1").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    Response response = request("/v3/clusters/" + clusterId + "/brokers/-/configs").accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    ListBrokerConfigsResponse responseBody = response.readEntity(ListBrokerConfigsResponse.class);
    assertEquals(expectedMetadata, responseBody.getValue().getMetadata());
    assertEquals(2, responseBody.getValue().getData().stream().collect(Collectors.toMap(BrokerConfigData::getBrokerId, config -> config, (o, n) -> n)).size(), "Unexpected number of brokers in response");
    assertTrue(responseBody.getValue().getData().contains(expectedBroker1Config1), String.format("Not true that `%s' contains `%s'.", responseBody, expectedBroker1Config1));
    assertTrue(responseBody.getValue().getData().contains(expectedBroker1Config2), String.format("Not true that `%s' contains `%s'.", responseBody, expectedBroker1Config2));
    assertTrue(responseBody.getValue().getData().contains(expectedBroker2Config1), String.format("Not true that `%s' contains `%s'.", responseBody, expectedBroker2Config1));
    assertTrue(responseBody.getValue().getData().contains(expectedBroker2Config2), String.format("Not true that `%s' contains `%s'.", responseBody, expectedBroker2Config2));
    assertTrue(responseBody.getValue().getData().contains(expectedBroker2Config3), String.format("Not true that `%s' contains `%s'.", responseBody, expectedBroker2Config3));
}
Also used : ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Response(javax.ws.rs.core.Response) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Collectors(java.util.stream.Collectors) Collections.singletonList(java.util.Collections.singletonList) BrokerConfigData(io.confluent.kafkarest.entities.v3.BrokerConfigData) Test(org.junit.jupiter.api.Test) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) List(java.util.List) MediaType(javax.ws.rs.core.MediaType) ImmutableList(com.google.common.collect.ImmutableList) Response(javax.ws.rs.core.Response) ConfigSynonymData(io.confluent.kafkarest.entities.v3.ConfigSynonymData) Resource(io.confluent.kafkarest.entities.v3.Resource) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ClusterTestHarness(io.confluent.kafkarest.integration.ClusterTestHarness) Status(javax.ws.rs.core.Response.Status) ConfigSource(io.confluent.kafkarest.entities.ConfigSource) BrokerConfigData(io.confluent.kafkarest.entities.v3.BrokerConfigData) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) Test(org.junit.jupiter.api.Test)

Example 2 with ListBrokerConfigsResponse

use of io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse 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());
}
Also used : BrokerConfig(io.confluent.kafkarest.entities.BrokerConfig) HashMap(java.util.HashMap) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ArrayList(java.util.ArrayList) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Test(org.junit.jupiter.api.Test)

Example 3 with ListBrokerConfigsResponse

use of io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse 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());
}
Also used : BrokerConfig(io.confluent.kafkarest.entities.BrokerConfig) HashMap(java.util.HashMap) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Test(org.junit.jupiter.api.Test)

Example 4 with ListBrokerConfigsResponse

use of io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse 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);
}
Also used : PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) CrnFactory(io.confluent.kafkarest.response.CrnFactory) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Inject(javax.inject.Inject) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) UrlFactory(io.confluent.kafkarest.response.UrlFactory) MediaType(javax.ws.rs.core.MediaType) Objects.requireNonNull(java.util.Objects.requireNonNull) BrokerConfig(io.confluent.kafkarest.entities.BrokerConfig) Broker(io.confluent.kafkarest.entities.Broker) AsyncResponses(io.confluent.kafkarest.resources.AsyncResponses) AsyncResponse(javax.ws.rs.container.AsyncResponse) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Collectors(java.util.stream.Collectors) Suspended(javax.ws.rs.container.Suspended) BrokerConfigManager(io.confluent.kafkarest.controllers.BrokerConfigManager) BrokerManager(io.confluent.kafkarest.controllers.BrokerManager) Comparator(java.util.Comparator) BrokerConfigDataList(io.confluent.kafkarest.entities.v3.BrokerConfigDataList) Broker(io.confluent.kafkarest.entities.Broker) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) BrokerConfigManager(io.confluent.kafkarest.controllers.BrokerConfigManager) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Produces(javax.ws.rs.Produces) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) GET(javax.ws.rs.GET)

Example 5 with ListBrokerConfigsResponse

use of io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse in project kafka-rest by confluentinc.

the class BrokerConfigsResourceIntegrationTest method listBrokerConfigs_existingBroker_returnsConfigs.

@Test
public void listBrokerConfigs_existingBroker_returnsConfigs() {
    String baseUrl = restConnect;
    String clusterId = getClusterId();
    int brokerId = getBrokers().get(0).id();
    ResourceCollection.Metadata expectedMetadata = ResourceCollection.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/brokers/" + brokerId + "/configs").build();
    BrokerConfigData expectedConfig1 = BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/brokers/" + brokerId + "/configs/max.connections").setResourceName("crn:///kafka=" + clusterId + "/broker=" + brokerId + "/config=max.connections").build()).setClusterId(clusterId).setBrokerId(brokerId).setName("max.connections").setValue("2147483647").setDefault(true).setReadOnly(false).setSensitive(false).setSource(ConfigSource.DEFAULT_CONFIG).setSynonyms(singletonList(ConfigSynonymData.builder().setName("max.connections").setValue("2147483647").setSource(ConfigSource.DEFAULT_CONFIG).build())).build();
    BrokerConfigData expectedConfig2 = BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/brokers/" + brokerId + "/configs/compression.type").setResourceName("crn:///kafka=" + clusterId + "/broker=" + brokerId + "/config=compression.type").build()).setClusterId(clusterId).setBrokerId(brokerId).setName("compression.type").setValue("producer").setDefault(true).setReadOnly(false).setSensitive(false).setSource(ConfigSource.DEFAULT_CONFIG).setSynonyms(singletonList(ConfigSynonymData.builder().setName("compression.type").setValue("producer").setSource(ConfigSource.DEFAULT_CONFIG).build())).build();
    BrokerConfigData expectedConfig3 = BrokerConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/brokers/" + brokerId + "/configs/log.cleaner.threads").setResourceName("crn:///kafka=" + clusterId + "/broker=" + brokerId + "/config=log.cleaner.threads").build()).setClusterId(clusterId).setBrokerId(brokerId).setName("log.cleaner.threads").setValue("1").setDefault(true).setReadOnly(false).setSensitive(false).setSource(ConfigSource.DEFAULT_CONFIG).setSynonyms(singletonList(ConfigSynonymData.builder().setName("log.cleaner.threads").setValue("1").setSource(ConfigSource.DEFAULT_CONFIG).build())).build();
    Response response = request("/v3/clusters/" + clusterId + "/brokers/" + brokerId + "/configs").accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    ListBrokerConfigsResponse actual = response.readEntity(ListBrokerConfigsResponse.class);
    assertEquals(expectedMetadata, actual.getValue().getMetadata());
    assertTrue(actual.getValue().getData().contains(expectedConfig1), String.format("Not true that `%s' contains `%s'.", actual.getValue().getData(), expectedConfig1));
    assertTrue(actual.getValue().getData().contains(expectedConfig2), String.format("Not true that `%s' contains `%s'.", actual.getValue().getData(), expectedConfig2));
    assertTrue(actual.getValue().getData().contains(expectedConfig3), String.format("Not true that `%s' contains `%s'.", actual.getValue().getData(), expectedConfig3));
}
Also used : GetBrokerConfigResponse(io.confluent.kafkarest.entities.v3.GetBrokerConfigResponse) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) Response(javax.ws.rs.core.Response) BrokerConfigData(io.confluent.kafkarest.entities.v3.BrokerConfigData) ListBrokerConfigsResponse(io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) Test(org.junit.jupiter.api.Test)

Aggregations

ListBrokerConfigsResponse (io.confluent.kafkarest.entities.v3.ListBrokerConfigsResponse)6 Test (org.junit.jupiter.api.Test)5 BrokerConfig (io.confluent.kafkarest.entities.BrokerConfig)3 ResourceCollection (io.confluent.kafkarest.entities.v3.ResourceCollection)3 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)3 BrokerConfigData (io.confluent.kafkarest.entities.v3.BrokerConfigData)2 HashMap (java.util.HashMap)2 Collectors (java.util.stream.Collectors)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2 ImmutableList (com.google.common.collect.ImmutableList)1 BrokerConfigManager (io.confluent.kafkarest.controllers.BrokerConfigManager)1 BrokerManager (io.confluent.kafkarest.controllers.BrokerManager)1 Broker (io.confluent.kafkarest.entities.Broker)1 ConfigSource (io.confluent.kafkarest.entities.ConfigSource)1 BrokerConfigDataList (io.confluent.kafkarest.entities.v3.BrokerConfigDataList)1 ConfigSynonymData (io.confluent.kafkarest.entities.v3.ConfigSynonymData)1 GetBrokerConfigResponse (io.confluent.kafkarest.entities.v3.GetBrokerConfigResponse)1 Resource (io.confluent.kafkarest.entities.v3.Resource)1 ResourceName (io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)1