Skip to content

Commit

Permalink
Allow to delete consumer group
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Sep 28, 2018
1 parent 2b0f284 commit ef77f05
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
6 changes: 6 additions & 0 deletions public/includes/group.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<td class="row-action main-row-action">
<a href="/${clusterId}/group/${group.getId()}" ><i class="fa fa-search"></i></a>
</td>
<td class="row-action">
<a
href="/${clusterId}/group/${group.getId()}/delete"
data-confirm="Do you want to delete consumer group <br /><strong>${group.getId()}</strong><br /><br /> ?"
><i class="fa fa-trash"></i></a>
</td>
</tr>
</#list>
</tbody>
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/kafkahq/controllers/GroupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

import com.google.inject.Inject;
import org.jooby.Request;
import org.jooby.Result;
import org.jooby.Results;
import org.jooby.View;
import org.jooby.mvc.GET;
import org.jooby.mvc.Path;
import org.kafkahq.models.ConsumerGroup;
import org.kafkahq.repositories.ConsumerGroupRepository;
import org.kafkahq.response.ResultStatusResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;

@Path("/{cluster}/group")
public class GroupController extends AbstractController {
private static final Logger logger = LoggerFactory.getLogger(TopicController.class);

@Inject
private ConsumerGroupRepository consumerGroupRepository;

Expand Down Expand Up @@ -50,4 +56,27 @@ public View group(Request request, String tab) throws ExecutionException, Interr
);
}


@GET
@Path("{id}/delete")
public Result delete(Request request) {
String name = request.param("id").value();
ResultStatusResponse result = new ResultStatusResponse();

try {
this.consumerGroupRepository.delete(request.param("cluster").value(), name);

result.result = true;
result.message = "Topic '" + name + "' is deleted";

return Results.with(result, 200);
} catch (Exception exception) {
logger.error("Failed to delete topic " + name, exception);

result.result = false;
result.message = exception.getCause().getMessage();

return Results.with(result, 500);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kafkahq.repositories;

import com.google.inject.Binder;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.typesafe.config.Config;
import org.apache.kafka.clients.admin.ConsumerGroupDescription;
Expand All @@ -11,13 +12,17 @@
import org.jooby.Jooby;
import org.kafkahq.models.ConsumerGroup;
import org.kafkahq.models.Partition;
import org.kafkahq.modules.KafkaModule;

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

@Singleton
public class ConsumerGroupRepository extends AbstractRepository implements Jooby.Module {
@Inject
private KafkaModule kafkaModule;

public List<ConsumerGroup> list() throws ExecutionException, InterruptedException {
ArrayList<String> list = new ArrayList<>();

Expand Down Expand Up @@ -76,6 +81,12 @@ public List<ConsumerGroup> findByTopic(String topic) throws ExecutionException,
.collect(Collectors.toList());
}

public void delete(String clusterId, String name) throws ExecutionException, InterruptedException {
kafkaModule.getAdminClient(clusterId).deleteConsumerGroups(new ArrayList<String>() {{
add(name);
}}).all().get();
}

@SuppressWarnings("NullableProblems")
@Override
public void configure(Env env, Config conf, Binder binder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public void delete(String clusterId, String name) throws ExecutionException, Int
}}).all().get();
}


@SuppressWarnings("NullableProblems")
@Override
public void configure(Env env, Config conf, Binder binder) {
Expand Down

0 comments on commit ef77f05

Please sign in to comment.