Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Alter describe topics to utilize json output
Browse files Browse the repository at this point in the history
  • Loading branch information
wcarlsen committed Apr 27, 2022
1 parent 2860172 commit 2ed45ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
18 changes: 15 additions & 3 deletions server/src/server/wrapper/connected/CCloudTopics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { executeCli } from "./executeCli";
import { TopicAlreadyExistsException } from "../model/error";
import { GetConfig } from "../../config";
import { Deserializer, ConcatOutput } from "../utils";
import ListTopics from "../model/topics";
import { ListTopics, DescribeTopic } from "../model/topics";


export class CcloudTopics implements Topics {
Expand All @@ -28,9 +28,21 @@ export class CcloudTopics implements Topics {

async describeTopic(name: string): Promise<Topic> {
let config = GetConfig();
let consoleLines = await executeCli(["kafka", "topic", "describe", name, "--cluster", config.clusterId, "--environment", config.environmentId, "--output", "json"]);
let result = await executeCli(["kafka", "topic", "describe", name, "--cluster", config.clusterId, "--environment", config.environmentId, "--output", "json"]);

var topic = parseTopicDescription(consoleLines);
let combinedResult = ConcatOutput(result);
let deserializedResult : DescribeTopic;
try {
deserializedResult = Deserializer<DescribeTopic>(combinedResult);
} catch (error) {
return error;
}

let topic = {
Name: deserializedResult.topic_name,
PartitionCount: deserializedResult.config["num.partitions"], // might be an issue that partitionCount is present twice
Configurations: deserializedResult.config // might be an issue that partitionCount is present twice
};

return topic;
}
Expand Down
9 changes: 5 additions & 4 deletions server/src/server/wrapper/model/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ export class ListTopic {
name: string
}

type ListTopics = Array<ListTopic>;

export default ListTopics;

export type ListTopics = Array<ListTopic>;

export class DescribeTopic {
topic_name: string
config: {[key: string]: any}
}

0 comments on commit 2ed45ed

Please sign in to comment.