Skip to content

Commit

Permalink
list of rebalance
Browse files Browse the repository at this point in the history
Signed-off-by: hemahg <[email protected]>
  • Loading branch information
hemahg committed Sep 27, 2024
1 parent 3f6312a commit ad54dac
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
10 changes: 6 additions & 4 deletions ui/api/Rebalance/actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { logger } from "@/utils/logger";
import {
RebalanceOptimizationProposalResponse,
RebalanceOptimizationProposalSchema,
RebalanceResponse,
RebalanceResponseSchema,
RebalanceSchema,
Expand All @@ -25,7 +27,8 @@ export async function getRebalancesList(
): Promise<RebalancesResponse> {
const sp = new URLSearchParams(
filterUndefinedFromObj({
"fields[kafkaRebalances]": "name,namespace,creationTimestamp,status",
"fields[kafkaRebalances]":
"name,namespace,creationTimestamp,status,mode,brokers",
"filter[name]": params.name ? `like,*${params.name}*` : undefined,
"filter[status]":
params.status && params.status.length > 0
Expand Down Expand Up @@ -57,7 +60,7 @@ export async function getRebalancesList(
export async function getRebalanceDetails(
kafkaId: string,
rebalanceId: string,
): Promise<RebalanceResponse> {
): Promise<RebalanceOptimizationProposalResponse> {
const url = `${process.env.BACKEND_URL}/api/kafkas/${kafkaId}/rebalances/${rebalanceId}`;
const body = {
data: {
Expand All @@ -73,7 +76,6 @@ export async function getRebalanceDetails(
body: JSON.stringify(body),
});
const rawData = await res.json();
console.log(rawData);
log.debug({ url, rawData }, "get Optimal proposal response");
return RebalanceSchema.parse(rawData);
return RebalanceOptimizationProposalSchema.parse(rawData).data;
}
20 changes: 14 additions & 6 deletions ui/api/Rebalance/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ const OptimizationResultSchema = z.object({
});

export const RebalanceSchema = z.object({
type: z.literal("kafkaRebalances"),
id: z.string(),
type: z.literal("kafkaRebalances"),
meta: z
.object({
autoApproval: z.boolean().optional(),
allowedActions: z.array(z.string()),
})
.optional(),
attributes: z.object({
name: z.string().optional(),
namespace: z.string().optional(),
creationTimestamp: z.string().optional(),
name: z.string(),
namespace: z.string(),
creationTimestamp: z.string(),
status: RebalanceStatusSchema,
mode: z.string().optional(),
brokers: z.array(z.number()).optional(),
brokers: z.array(z.number()).nullable(),
sessionId: z.string().optional(),
optimizationResult: OptimizationResultSchema,
}),
Expand All @@ -57,6 +57,7 @@ const RebalancesListSchema = z.object({
page: z.object({
cursor: z.string(),
}),
autoApproval: z.boolean(),
managed: z.boolean().optional(),
}),
attributes: RebalanceSchema.shape.attributes.pick({
Expand All @@ -66,7 +67,6 @@ const RebalancesListSchema = z.object({
mode: true,
brokers: true,
}),
autoApproval: RebalanceSchema.shape.meta.unwrap().shape.autoApproval,
});

export const RebalanceResponseSchema = z.object({
Expand All @@ -90,3 +90,11 @@ export type RebalancesResponse = z.infer<typeof RebalanceResponseSchema>;
export type RebalanceResponse = z.infer<typeof RebalanceSchema>;

export type RebalanceStatus = z.infer<typeof RebalanceStatusSchema>;

export const RebalanceOptimizationProposalSchema = z.object({
data: RebalanceSchema,
});

export type RebalanceOptimizationProposalResponse = z.infer<
typeof RebalanceSchema
>;
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function NodesPage({ params }: { params: KafkaParams }) {
async function ConnectedNodes({ params }: { params: KafkaParams }) {
const t = await getTranslations();
const res = await getKafkaClusterKpis(params.kafkaId);

let { cluster, kpis } = res || {};

const nodes: Node[] = (cluster?.attributes.nodes || []).map((node) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import { useRouter } from "@/navigation";
import { useFilterParams } from "@/utils/useFilterParams";
import { useRouter } from "@/i18n/routing";
import { useOptimistic, useState, useTransition } from "react";
import {
RebalanceTable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
ResourcesFullIcon,
} from "@/libs/patternfly/react-icons";
import { ReactNode } from "react";
import { Link } from "@/navigation";
import Link from "next/link";

export const RebalanceTableColumns = ["name", "status", "createdAt"] as const;

Expand Down Expand Up @@ -128,7 +128,6 @@ export function RebalanceTable({
onPageChange,
}: RebalanceTabelProps) {
const t = useTranslations("Rebalancing");

return (
<TableView
itemCount={rebalancesCount}
Expand Down Expand Up @@ -224,7 +223,7 @@ export function RebalanceTable({
{t("auto_approval_enabled")}
</DescriptionListTerm>
<DescriptionListDescription>
{row.autoApproval}
{row.meta.autoApproval === true ? "true" : "false"}
</DescriptionListDescription>
</DescriptionListGroup>
</FlexItem>
Expand Down

0 comments on commit ad54dac

Please sign in to comment.