-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add banner and namespace list * Support namespace creation and deletion * Add error message when fail to create namespace --------- Co-authored-by: datavisorwenjiejiang <[email protected]>
- Loading branch information
1 parent
1cc64d4
commit 5fc828c
Showing
14 changed files
with
741 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
export default function Layout({children}: {children: React.ReactNode}) { | ||
return ( | ||
<> | ||
{children} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Box, Container } from "@mui/material"; | ||
import Sidebar from "../ui/sidebar"; | ||
|
||
export default function Cluster() { | ||
return ( | ||
<div className="flex h-full"> | ||
<Sidebar /> | ||
<Container maxWidth={false} disableGutters sx={{height: '100%', overflowY: 'auto', marginLeft: '16px'}}> | ||
<div> | ||
todo: show all clusters in selected namespace here | ||
</div> | ||
</Container> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
'use server'; | ||
|
||
import { redirect } from "next/navigation"; | ||
import { createNamespace, deleteNamespace } from "./api"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
export async function createNamespaceAction(name: string): Promise<string> { | ||
const errMsg = await createNamespace(name); | ||
if(!errMsg) { | ||
revalidatePath('/cluster'); | ||
} | ||
return errMsg; | ||
} | ||
|
||
export async function deleteNamespaceAction(name: string): Promise<string> { | ||
const result = deleteNamespace(name); | ||
revalidatePath('/cluster'); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import yaml from 'js-yaml'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import axios, { AxiosError } from 'axios'; | ||
|
||
const configFile = './config/config.yaml'; | ||
const apiPrefix = '/api/v1'; | ||
let host; | ||
try { | ||
const wholeFilePath = path.join(process.cwd(), '..', configFile); | ||
const doc = yaml.load(fs.readFileSync(wholeFilePath, 'utf8')); | ||
host = (doc as any)['addr']; | ||
} catch (error) { | ||
host = '127.0.0.1:9379'; | ||
} | ||
const apiHost = `http://${host}${apiPrefix}`; | ||
|
||
export async function fetchNamespaces(): Promise<string[]> { | ||
try { | ||
const { data: responseData } = await axios.get(`${apiHost}/namespaces`); | ||
return responseData.data.namespaces || []; | ||
} catch (error) { | ||
handleError(error); | ||
return []; | ||
} | ||
} | ||
export async function createNamespace(name: string): Promise<string> { | ||
try { | ||
const { data: responseData } = await axios.post(`${apiHost}/namespaces`, {namespace: name}); | ||
if(responseData?.data == 'created') { | ||
return ''; | ||
} else { | ||
return handleError(responseData); | ||
} | ||
} catch (error) { | ||
return handleError(error); | ||
} | ||
} | ||
|
||
export async function deleteNamespace(name: string): Promise<string> { | ||
try { | ||
const { data: responseData } = await axios.delete(`${apiHost}/namespaces/${name}`); | ||
if(responseData?.data == 'ok') { | ||
return ''; | ||
} else { | ||
return handleError(responseData); | ||
} | ||
} catch (error) { | ||
return handleError(error); | ||
} | ||
} | ||
|
||
function handleError(error: any): string { | ||
let message: string = ''; | ||
if(error instanceof AxiosError) { | ||
message = error.response?.data?.error?.message || error.message; | ||
} else if (error instanceof Error) { | ||
message = error.message; | ||
} else if (typeof error === 'object') { | ||
message = error?.error?.message || error?.message; | ||
} | ||
return message || 'Unknown error'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { AppBar, Container, Toolbar } from "@mui/material"; | ||
import Image from "next/image"; | ||
import NavLinks from "./nav-links"; | ||
|
||
const links = [ | ||
{ | ||
url: '/', | ||
title: 'Home' | ||
},{ | ||
url: '/cluster', | ||
title: 'cluster' | ||
},{ | ||
url: 'https://kvrocks.apache.org', | ||
title: 'community', | ||
_blank: true | ||
}, | ||
] | ||
|
||
export default function Banner() { | ||
return (<AppBar> | ||
<Container maxWidth={false}> | ||
<Toolbar className="space-x-4"> | ||
<Image src="/logo.svg" width={40} height={40} alt='logo'></Image> | ||
<NavLinks links={links}/> | ||
</Toolbar> | ||
</Container> | ||
</AppBar>) | ||
} |
Oops, something went wrong.