Search in sources :

Example 1 with ListTopicConfigsResponse

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

the class TopicConfigsResourceTest method listTopicConfigs_existingTopic_returnsConfigs.

@Test
public void listTopicConfigs_existingTopic_returnsConfigs() {
    expect(topicConfigManager.listTopicConfigs(CLUSTER_ID, TOPIC_NAME)).andReturn(completedFuture(Arrays.asList(CONFIG_1, CONFIG_2, CONFIG_3)));
    replay(topicConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    topicConfigsResource.listTopicConfigs(response, CLUSTER_ID, TOPIC_NAME);
    ListTopicConfigsResponse expected = ListTopicConfigsResponse.create(TopicConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs").build()).setData(Arrays.asList(TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).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(), TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-2").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-2").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).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(), TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-3").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-3").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).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 : ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Test(org.junit.jupiter.api.Test)

Example 2 with ListTopicConfigsResponse

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

the class TopicConfigsResourceIntegrationTest method listTopicConfigs_existingTopic_returnsConfigs.

@Test
public void listTopicConfigs_existingTopic_returnsConfigs() {
    String baseUrl = restConnect;
    String clusterId = getClusterId();
    ResourceCollection.Metadata expectedMetadata = ResourceCollection.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/configs").build();
    TopicConfigData expectedConfig1 = TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/configs/cleanup.policy").setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_1 + "/config=cleanup.policy").build()).setClusterId(clusterId).setTopicName(TOPIC_1).setName("cleanup.policy").setValue("delete").setDefault(true).setReadOnly(false).setSensitive(false).setSource(ConfigSource.DEFAULT_CONFIG).setSynonyms(singletonList(ConfigSynonymData.builder().setName("log.cleanup.policy").setValue("delete").setSource(ConfigSource.DEFAULT_CONFIG).build())).build();
    TopicConfigData expectedConfig2 = TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/configs/compression.type").setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_1 + "/config=compression.type").build()).setClusterId(clusterId).setTopicName(TOPIC_1).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();
    TopicConfigData expectedConfig3 = TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/configs/delete.retention.ms").setResourceName("crn:///kafka=" + clusterId + "/topic=" + TOPIC_1 + "/config=delete.retention.ms").build()).setClusterId(clusterId).setTopicName(TOPIC_1).setName("delete.retention.ms").setValue("86400000").setDefault(true).setReadOnly(false).setSensitive(false).setSource(ConfigSource.DEFAULT_CONFIG).setSynonyms(singletonList(ConfigSynonymData.builder().setName("log.cleaner.delete.retention.ms").setValue("86400000").setSource(ConfigSource.DEFAULT_CONFIG).build())).build();
    Response response = request("/v3/clusters/" + clusterId + "/topics/" + TOPIC_1 + "/configs").accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    ListTopicConfigsResponse responseBody = response.readEntity(ListTopicConfigsResponse.class);
    assertEquals(expectedMetadata, responseBody.getValue().getMetadata());
    assertTrue(responseBody.getValue().getData().contains(expectedConfig1), String.format("Not true that `%s' contains `%s'.", responseBody, expectedConfig1));
    assertTrue(responseBody.getValue().getData().contains(expectedConfig2), String.format("Not true that `%s' contains `%s'.", responseBody, expectedConfig2));
    assertTrue(responseBody.getValue().getData().contains(expectedConfig3), String.format("Not true that `%s' contains `%s'.", responseBody, expectedConfig3));
}
Also used : ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) GetTopicConfigResponse(io.confluent.kafkarest.entities.v3.GetTopicConfigResponse) Response(javax.ws.rs.core.Response) ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) TopicConfigData(io.confluent.kafkarest.entities.v3.TopicConfigData) Test(org.junit.jupiter.api.Test)

Example 3 with ListTopicConfigsResponse

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

the class ListAllTopicsConfigsActionTest method listTopicConfigs_existingTopic_returnsConfigs.

@Test
public void listTopicConfigs_existingTopic_returnsConfigs() {
    expect(topicManager.listTopics(CLUSTER_ID)).andReturn(completedFuture(Arrays.asList(Topic.create(CLUSTER_ID, TOPIC_NAME, new ArrayList<>(), (short) 1, false, emptySet()))));
    expect(topicConfigManager.listTopicConfigs(CLUSTER_ID, Arrays.asList(TOPIC_NAME))).andReturn(completedFuture(new HashMap<String, List<TopicConfig>>() {

        {
            put(TOPIC_NAME, Arrays.asList(CONFIG_1, CONFIG_2, CONFIG_3));
        }
    }));
    replay(topicManager, topicConfigManager);
    FakeAsyncResponse response = new FakeAsyncResponse();
    allTopicConfigsResource.listTopicConfigs(response, CLUSTER_ID);
    ListTopicConfigsResponse expected = ListTopicConfigsResponse.create(TopicConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/-/configs").build()).setData(Arrays.asList(TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-1").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-1").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).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(), TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-2").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-2").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).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(), TopicConfigData.builder().setMetadata(Resource.Metadata.builder().setSelf("/v3/clusters/cluster-1/topics/topic-1/configs/config-3").setResourceName("crn:///kafka=cluster-1/topic=topic-1/config=config-3").build()).setClusterId(CLUSTER_ID).setTopicName(TOPIC_NAME).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 : HashMap(java.util.HashMap) ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) ArrayList(java.util.ArrayList) TopicConfig(io.confluent.kafkarest.entities.TopicConfig) Test(org.junit.jupiter.api.Test)

Example 4 with ListTopicConfigsResponse

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

the class ListAllTopicsConfigsAction method listTopicConfigs.

@GET
@Produces(MediaType.APPLICATION_JSON)
@PerformanceMetric("v3.topics.configs.list")
@ResourceName("api.v3.topic-configs.list")
public void listTopicConfigs(@Suspended AsyncResponse asyncResponse, @PathParam("clusterId") String clusterId) {
    // have to resolve dependencies here in request scope
    TopicConfigManager resolvedTopicConfigManager = topicConfigManager.get();
    CompletableFuture<ListTopicConfigsResponse> response = topicManager.get().listTopics(clusterId).thenCompose(topics -> resolvedTopicConfigManager.listTopicConfigs(clusterId, topics.stream().map(topic -> topic.getName()).collect(Collectors.toList())).thenApply(configs -> ListTopicConfigsResponse.create(TopicConfigDataList.builder().setMetadata(ResourceCollection.Metadata.builder().setSelf(urlFactory.create("v3", "clusters", clusterId, "topics", "-", "configs")).build()).setData(configs.values().stream().flatMap(topicConfigs -> topicConfigs.stream().sorted(Comparator.comparing(TopicConfig::getName))).map(topicConfig -> TopicConfigsResource.toTopicConfigData(topicConfig, crnFactory, urlFactory)).collect(Collectors.toList())).build())));
    AsyncResponses.asyncResume(asyncResponse, response);
}
Also used : ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) PathParam(javax.ws.rs.PathParam) AsyncResponses(io.confluent.kafkarest.resources.AsyncResponses) Provider(javax.inject.Provider) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) AsyncResponse(javax.ws.rs.container.AsyncResponse) Path(javax.ws.rs.Path) CrnFactory(io.confluent.kafkarest.response.CrnFactory) ResourceName(io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName) CompletableFuture(java.util.concurrent.CompletableFuture) PerformanceMetric(io.confluent.rest.annotations.PerformanceMetric) Collectors(java.util.stream.Collectors) Suspended(javax.ws.rs.container.Suspended) TopicConfigManager(io.confluent.kafkarest.controllers.TopicConfigManager) Inject(javax.inject.Inject) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) UrlFactory(io.confluent.kafkarest.response.UrlFactory) MediaType(javax.ws.rs.core.MediaType) TopicManager(io.confluent.kafkarest.controllers.TopicManager) TopicConfig(io.confluent.kafkarest.entities.TopicConfig) Objects.requireNonNull(java.util.Objects.requireNonNull) Comparator(java.util.Comparator) TopicConfigDataList(io.confluent.kafkarest.entities.v3.TopicConfigDataList) TopicConfigManager(io.confluent.kafkarest.controllers.TopicConfigManager) ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) 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 ListTopicConfigsResponse

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

the class ListAllTopicsConfigsActionIntegrationTest method listTopicConfigs_existingTopics_returnsConfigs.

@Test
public void listTopicConfigs_existingTopics_returnsConfigs() {
    String baseUrl = restConnect;
    String clusterId = getClusterId();
    ResourceCollection.Metadata expectedMetadata = ResourceCollection.Metadata.builder().setSelf(baseUrl + "/v3/clusters/" + clusterId + "/topics/-/configs").build();
    TopicConfigData expectedTopic1Config1 = createTopicConfigData(baseUrl, clusterId, TOPIC_1, "cleanup.policy", "delete", true, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("log.cleanup.policy").setValue("delete").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    TopicConfigData expectedTopic1Config2 = createTopicConfigData(baseUrl, clusterId, TOPIC_1, "compression.type", "producer", true, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("compression.type").setValue("producer").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    TopicConfigData expectedTopic1Config3 = createTopicConfigData(baseUrl, clusterId, TOPIC_1, "delete.retention.ms", "86400000", true, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("log.cleaner.delete.retention.ms").setValue("86400000").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    TopicConfigData expectedTopic2Config1 = createTopicConfigData(baseUrl, clusterId, TOPIC_2, "cleanup.policy", "delete", true, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("log.cleanup.policy").setValue("delete").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    TopicConfigData expectedTopic2Config2 = createTopicConfigData(baseUrl, clusterId, TOPIC_2, "compression.type", "producer", true, ConfigSource.DEFAULT_CONFIG, singletonList(ConfigSynonymData.builder().setName("compression.type").setValue("producer").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    TopicConfigData expectedTopic2Config3 = createTopicConfigData(baseUrl, clusterId, TOPIC_2, "delete.retention.ms", "100000", false, ConfigSource.DYNAMIC_TOPIC_CONFIG, Arrays.asList(ConfigSynonymData.builder().setName("delete.retention.ms").setValue("100000").setSource(ConfigSource.DYNAMIC_TOPIC_CONFIG).build(), ConfigSynonymData.builder().setName("log.cleaner.delete.retention.ms").setValue("86400000").setSource(ConfigSource.DEFAULT_CONFIG).build()));
    Response response = request("/v3/clusters/" + clusterId + "/topics/-/configs").accept(MediaType.APPLICATION_JSON).get();
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    ListTopicConfigsResponse responseBody = response.readEntity(ListTopicConfigsResponse.class);
    assertEquals(expectedMetadata, responseBody.getValue().getMetadata());
    assertTrue(responseBody.getValue().getData().contains(expectedTopic1Config1), String.format("Not true that `%s' contains `%s'.", responseBody, expectedTopic1Config1));
    assertTrue(responseBody.getValue().getData().contains(expectedTopic1Config2), String.format("Not true that `%s' contains `%s'.", responseBody, expectedTopic1Config2));
    assertTrue(responseBody.getValue().getData().contains(expectedTopic1Config3), String.format("Not true that `%s' contains `%s'.", responseBody, expectedTopic1Config3));
    assertTrue(responseBody.getValue().getData().contains(expectedTopic2Config1), String.format("Not true that `%s' contains `%s'.", responseBody, expectedTopic2Config1));
    assertTrue(responseBody.getValue().getData().contains(expectedTopic2Config2), String.format("Not true that `%s' contains `%s'.", responseBody, expectedTopic2Config2));
    assertTrue(responseBody.getValue().getData().contains(expectedTopic2Config3), String.format("Not true that `%s' contains `%s'.", responseBody, expectedTopic2Config3));
}
Also used : ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) Response(javax.ws.rs.core.Response) ListTopicConfigsResponse(io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse) ResourceCollection(io.confluent.kafkarest.entities.v3.ResourceCollection) TopicConfigData(io.confluent.kafkarest.entities.v3.TopicConfigData) Test(org.junit.jupiter.api.Test)

Aggregations

ListTopicConfigsResponse (io.confluent.kafkarest.entities.v3.ListTopicConfigsResponse)6 Test (org.junit.jupiter.api.Test)5 TopicConfig (io.confluent.kafkarest.entities.TopicConfig)3 ResourceCollection (io.confluent.kafkarest.entities.v3.ResourceCollection)3 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)3 TopicConfigData (io.confluent.kafkarest.entities.v3.TopicConfigData)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Response (javax.ws.rs.core.Response)2 TopicConfigManager (io.confluent.kafkarest.controllers.TopicConfigManager)1 TopicManager (io.confluent.kafkarest.controllers.TopicManager)1 GetTopicConfigResponse (io.confluent.kafkarest.entities.v3.GetTopicConfigResponse)1 TopicConfigDataList (io.confluent.kafkarest.entities.v3.TopicConfigDataList)1 ResourceName (io.confluent.kafkarest.extension.ResourceAccesslistFeature.ResourceName)1 AsyncResponses (io.confluent.kafkarest.resources.AsyncResponses)1 CrnFactory (io.confluent.kafkarest.response.CrnFactory)1 UrlFactory (io.confluent.kafkarest.response.UrlFactory)1 PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)1 Comparator (java.util.Comparator)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1