Skip to content

Commit

Permalink
Add bootstarp url
Browse files Browse the repository at this point in the history
Signed-off-by: hemahg <[email protected]>
  • Loading branch information
hemahg committed Sep 11, 2024
1 parent 0c99bd9 commit 2ca741f
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import { Divider, Panel, PanelHeader, PanelMain, PanelMainBody, TextContent, Text, TextVariants, Radio, Form, FormGroup, FormSection, Select, SelectList, SelectOption, MenuToggle, MenuToggleElement, TextInput, ActionGroup, Button, SelectProps, PageSection, Page, Bullseye, Spinner, Flex, FlexItem, Grid, GridItem, Alert } from "@/libs/patternfly/react-core";
import { useTranslations } from "next-intl";
import { useState } from "react";
import { useEffect, useState } from "react";
import { DateTimeFormatSelection, OffsetValue, TopicSelection, partitionSelection } from "../types";
import { TypeaheadSelect } from "./TypeaheadSelect";
import { OffsetSelect } from "./OffsetSelect";
import { useRouter } from "@/navigation";
import { getDryrunResult, updateConsumerGroup } from "@/api/consumerGroups/actions";
import { UpdateConsumerGroupErrorSchema } from "@/api/consumerGroups/schema";
import { Dryrun } from "./Dryrun";
import { getKafkaCluster } from "@/api/kafka/actions";

export type Offset = {
topicId: string
Expand Down Expand Up @@ -60,6 +61,8 @@ export function ResetConsumerOffset({

const [showDryRun, setShowDryRun] = useState(false);

const [bootstrapServer, setBootstrapServer] = useState<string | undefined>();

const onTopicSelect = (value: TopicSelection) => {
setSelectedConsumerTopic(value);
};
Expand All @@ -72,6 +75,24 @@ export function ResetConsumerOffset({
setSelectDateTimeFormat(value)
}

useEffect(() => {
const fetchBootstrapServer = async () => {
try {
const data = await getKafkaCluster(kafkaId);
const listeners = data.attributes.listeners || [];
if (listeners.length > 0) {
setBootstrapServer(listeners[0].bootstrapServer);
} else {
throw new Error("No listeners found");
}
} catch (error) {
setError("Failed to fetch bootstrap server");
}
};

fetchBootstrapServer();
}, [kafkaId]);

const handleTopicChange = (topicName: string | number) => {
if (typeof topicName === 'string') {
const selectedTopic = topics.find(topic => topic.topicName === topicName);
Expand Down Expand Up @@ -104,7 +125,10 @@ export function ResetConsumerOffset({
};

const generateCliCommand = (): string => {
let baseCommand = `$ kafka-consumer-groups --bootstrap-server localhost:9092 --group ${consumerGroupName} --reset-offsets`;
if (!bootstrapServer) {
throw new Error("Bootstrap server is not available");
}
let baseCommand = `$ kafka-consumer-groups --bootstrap-server ${bootstrapServer} --group ${consumerGroupName} --reset-offsets`;
const topic = selectedConsumerTopic === "allTopics" ? "--all-topics" : `--topic ${offset.topicName}`;
baseCommand += ` ${topic}`;
if (selectedConsumerTopic === "selectedTopic") {
Expand Down

0 comments on commit 2ca741f

Please sign in to comment.