World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#1208] feat(web): add catalog management via api (#1718)
CHEYNEd73d73268e7f
diff --git a/web/app/ui/metalakes/CreateCatalogDialog.js b/web/app/ui/metalakes/CreateCatalogDialog.jsindex f13ca596c6..68e63b81c3 100644--- a/web/app/ui/metalakes/CreateCatalogDialog.js+++ b/web/app/ui/metalakes/CreateCatalogDialog.js@@ -28,13 +28,14 @@ import {import Icon from '@/components/Icon'import { useAppDispatch } from '@/lib/hooks/useStore'-import { createCatalog } from '@/lib/store/metalakes'+import { createCatalog, updateCatalog } from '@/lib/store/metalakes'import * as yup from 'yup'import { useForm, Controller } from 'react-hook-form'import { yupResolver } from '@hookform/resolvers/yup'import { providers } from '@/lib/utils/initial'+import { genUpdates } from '@/lib/utils'const defaultValues = {name: '',@@ -100,9 +101,25 @@ const CreateCatalogDialog = props => {data[index][event.target.name] = event.target.valuesetInnerProps(data)setValue('propItems', data)++ const nonEmptyKeys = data.filter(item => item.key.trim() !== '')++ const duplicateKeys = nonEmptyKeys.some((item, i) => i !== index && item.key === event.target.value)+ data[index].hasDuplicateKey = duplicateKeys}const addFields = () => {+ const duplicateKeys = innerProps+ .filter(item => item.key.trim() !== '')+ .some(+ (item, index, filteredItems) =>+ filteredItems.findIndex(otherItem => otherItem !== item && otherItem.key.trim() === item.key.trim()) !== -1+ )++ if (duplicateKeys) {+ return+ }+let newField = { key: '', value: '', required: false }setInnerProps([...innerProps, newField])@@ -155,6 +172,17 @@ const CreateCatalogDialog = props => {}const onSubmit = data => {+ const duplicateKeys = innerProps+ .filter(item => item.key.trim() !== '')+ .some(+ (item, index, filteredItems) =>+ filteredItems.findIndex(otherItem => otherItem !== item && otherItem.key.trim() === item.key.trim()) !== -1+ )++ if (duplicateKeys) {+ return+ }+const { propItems, ...mainData } = datalet nextProps = []@@ -206,6 +234,12 @@ const CreateCatalogDialog = props => {if (type === 'create') {dispatch(createCatalog({ data: catalogData, metalake }))+ } else {+ const reqData = { updates: genUpdates(cacheData, catalogData) }++ if (reqData.updates.length !== 0) {+ dispatch(updateCatalog({ metalake, catalog: cacheData.name, data: reqData }))+ }}handleClose()@@ -228,27 +262,58 @@ const CreateCatalogDialog = props => {defaultProps = providers[providerItemIndex].defaultPropsresetPropsFields(providers, providerItemIndex)- setInnerProps(defaultProps)- setValue('propItems', providers[providerItemIndex].defaultProps)++ if (type === 'create') {+ setInnerProps(defaultProps)+ setValue('propItems', providers[providerItemIndex].defaultProps)+ }}- }, [providerSelect, setInnerProps, setValue])++ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [providerSelect])useEffect(() => {if (open && JSON.stringify(data) !== '{}') {- setCacheData(data)const { properties = {} } = data- const propsArr = Object.keys(properties).map(item => {- return {- key: item,- value: properties[item]+ setCacheData(data)+ setValue('name', data.name)+ setValue('comment', data.comment)+ setValue('type', data.type)+ setValue('provider', data.provider)++ const providerItem = providers.find(i => i.value === data.provider)+ let propsItems = [...providerItem.defaultProps]++ propsItems = propsItems.map((it, idx) => {+ let propItem = {+ ...it,+ disabled: true+ }++ const findProp = Object.keys(properties).find(i => i === it.key)++ if (findProp) {+ propItem.value = properties[findProp]}++ return propItem})- setInnerProps(propsArr)+ for (let item of Object.keys(properties)) {+ const findPropIndex = propsItems.findIndex(i => i.key === item)- setValue('name', data.name)- setValue('comment', data.comment)+ if (findPropIndex === -1) {+ let propItem = {+ key: item,+ value: properties[item]+ }+ propsItems.push(propItem)+ }+ }++ setInnerProps(propsItems)+ setValue('propItems', propsItems)}}, [open, data, setValue])@@ -314,6 +379,7 @@ const CreateCatalogDialog = props => {onChange={onChange}error={Boolean(errors.type)}labelId='select-catalog-type'+ disabled={type === 'update'}><MenuItem value={'relational'}>relational</MenuItem></Select>@@ -340,6 +406,7 @@ const CreateCatalogDialog = props => {onChange={e => handleChangeProvider(onChange, e)}error={Boolean(errors.provider)}labelId='select-catalog-provider'+ disabled={type === 'update'}><MenuItem value={'hive'}>hive</MenuItem><MenuItem value={'lakehouse-iceberg'}>iceberg</MenuItem>@@ -395,6 +462,7 @@ const CreateCatalogDialog = props => {value={item.key}disabled={item.required}onChange={event => handleFormChange({ index, event })}+ error={item.hasDuplicateKey}/></Box><Box>@@ -419,6 +487,7 @@ const CreateCatalogDialog = props => {label='Value'error={item.required && item.value === ''}value={item.value}+ disabled={item.disabled}onChange={event => handleFormChange({ index, event })}/>)}@@ -443,6 +512,9 @@ const CreateCatalogDialog = props => {>{item.description}</FormHelperText>+ {item.hasDuplicateKey && (+ <FormHelperText className={'twc-text-error-main'}>Key already exists</FormHelperText>+ )}</FormControl></Grid></Fragment>diff --git a/web/app/ui/metalakes/DetailsDrawer.js b/web/app/ui/metalakes/DetailsDrawer.jsnew file mode 100644index 0000000000..e6f006f2f3--- /dev/null+++ b/web/app/ui/metalakes/DetailsDrawer.js@@ -0,0 +1,176 @@+/*+ * Copyright 2024 Datastrato Pvt Ltd.+ * This software is licensed under the Apache License version 2.+ */++import { useEffect, useState } from 'react'++import {+ Box,+ Grid,+ Drawer,+ IconButton,+ Typography,+ Table,+ TableHead,+ TableBody,+ TableRow,+ TableCell,+ TableContainer+} from '@mui/material'++import Icon from '@/components/Icon'++import EmptyText from '@/components/EmptyText'++import { formatToDateTime, isValidDate } from '@/lib/utils/date'++const DetailsDrawer = props => {+ const { openDrawer, setOpenDrawer, drawerData = {} } = props++ const { audit = {} } = drawerData++ const [properties, setProperties] = useState([])++ const handleClose = () => {+ setOpenDrawer(false)+ }++ const renderFieldText = (value, linkBreak = false) => {+ if (!value) {+ return <EmptyText />+ }++ return (+ <Typography sx={{ fontWeight: 500, whiteSpace: linkBreak ? 'pre-wrap' : 'normal' }}>+ {isValidDate(value) ? formatToDateTime(value) : value}+ </Typography>+ )+ }++ useEffect(() => {+ if (drawerData.properties) {+ const propsData = Object.keys(drawerData.properties).map(item => {+ return {+ key: item,+ value: drawerData.properties[item]+ }+ })++ setProperties(propsData)+ }+ }, [drawerData])++ return (+ <Drawer+ open={openDrawer}+ anchor='right'+ variant='temporary'+ onClose={handleClose}+ ModalProps={{ keepMounted: true }}+ PaperProps={{+ sx: {+ width: {+ xs: 300,+ sm: 400+ }+ }+ }}+ >+ <Box+ className={'drawer-header twc-flex twc-items-center twc-justify-between'}+ sx={{+ p: theme => theme.spacing(3, 4),+ borderBottom: theme => `1px solid ${theme.palette.divider}`,+ backgroundColor: theme => theme.palette.background.default+ }}+ >+ <Typography variant='h6'>Details</Typography>+ <IconButton size='small' onClick={handleClose} sx={{ color: 'text.primary' }}>+ <Icon icon='bx:x' fontSize={20} />+ </IconButton>+ </Box>+ <Box sx={{ p: 4 }}>+ <Grid item xs={12} sx={{ mb: [0, 5] }}>+ <Typography+ variant='subtitle1'+ className={'twc-py-2 twc-font-semibold twc-text-[1.2rem]'}+ sx={{+ borderBottom: theme => `1px solid ${theme.palette.divider}`+ }}+ >+ {drawerData.name}+ </Typography>+ </Grid>++ <Grid item xs={12} sx={{ mb: [0, 5] }}>+ <Typography variant='body2' sx={{ mb: 2 }}>+ Comment+ </Typography>+ {renderFieldText(drawerData.comment, true)}+ </Grid>++ <Grid item xs={12} sx={{ mb: [0, 5] }}>+ <Typography variant='body2' sx={{ mb: 2 }}>+ Created by+ </Typography>+ {renderFieldText(audit.creator)}+ </Grid>++ <Grid item xs={12} sx={{ mb: [0, 5] }}>+ <Typography variant='body2' sx={{ mb: 2 }}>+ Created at+ </Typography>+ {renderFieldText(audit.createTime)}+ </Grid>++ <Grid item xs={12} sx={{ mb: [0, 5] }}>+ <Typography variant='body2' sx={{ mb: 2 }}>+ Last modified by+ </Typography>+ {renderFieldText(audit.lastModifier)}+ </Grid>++ <Grid item xs={12} sx={{ mb: [0, 5] }}>+ <Typography variant='body2' sx={{ mb: 2 }}>+ Last modified at+ </Typography>+ {renderFieldText(audit.lastModifiedTime)}+ </Grid>++ <Grid item xs={12} sx={{ mb: [0, 5] }}>+ <Typography variant='body2' sx={{ mb: 2 }}>+ Properties+ </Typography>++ <TableContainer>+ <Table>+ <TableHead+ sx={{+ backgroundColor: theme => theme.palette.action.hover+ }}+ >+ <TableRow>+ <TableCell sx={{ py: 2 }}>Key</TableCell>+ <TableCell sx={{ py: 2 }}>Value</TableCell>+ </TableRow>+ </TableHead>+ <TableBody>+ {properties.map((item, index) => {+ return (+ <TableRow key={index}>+ <TableCell className={'twc-py-[0.7rem]'}>{item.key}</TableCell>+ <TableCell className={'twc-py-[0.7rem]'}>{item.value}</TableCell>+ </TableRow>+ )+ })}+ </TableBody>+ </Table>+ </TableContainer>+ </Grid>+ </Box>+ </Drawer>+ )+}++export default DetailsDrawerdiff --git a/web/app/ui/metalakes/RightContent.js b/web/app/ui/metalakes/RightContent.jsindex 9619e77b0f..6705cacf0c 100644--- a/web/app/ui/metalakes/RightContent.js+++ b/web/app/ui/metalakes/RightContent.js@@ -60,7 +60,7 @@ const RightContent = props => {</Box><Box sx={{ height: 'calc(100% - 4rem)' }}>- <TabsContent tableTitle={tableTitle} store={store} page={page} />+ <TabsContent tableTitle={tableTitle} store={store} page={page} routeParams={routeParams} /></Box></Box>)diff --git a/web/app/ui/metalakes/TableView.js b/web/app/ui/metalakes/TableView.jsindex 9765201c8f..f87aa59ef8 100644--- a/web/app/ui/metalakes/TableView.js+++ b/web/app/ui/metalakes/TableView.js@@ -7,11 +7,20 @@ import { useState, useEffect } from 'react'import Link from 'next/link'-import { Box, Typography } from '@mui/material'-import ColumnTypeChip from '@/components/ColumnTypeChip'+import { Box, Typography, IconButton } from '@mui/material'import { DataGrid } from '@mui/x-data-grid'+import Icon from '@/components/Icon'++import ColumnTypeChip from '@/components/ColumnTypeChip'+import DetailsDrawer from '../DetailsDrawer'+import ConfirmDeleteDialog from '@/components/ConfirmDeleteDialog'+import CreateCatalogDialog from './CreateCatalogDialog'+import { useAppSelector, useAppDispatch } from '@/lib/hooks/useStore'-import { setIntoTreeAction } from '@/lib/store/metalakes'+import { setIntoTreeAction, updateCatalog, deleteCatalog } from '@/lib/store/metalakes'++import { to } from '@/lib/utils'+import { getCatalogDetailsApi } from '@/lib/api/catalogs'function removeLastSegment(inputString, separator = '____') {const lastIndex = inputString.lastIndexOf(separator)@@ -23,7 +32,9 @@ function removeLastSegment(inputString, separator = '____') {}const TableView = props => {- const { page } = props+ const { page, routeParams } = props+ const { metalake, catalog } = routeParams+const defaultPaginationConfig = { pageSize: 10, page: 0 }const pageSizeOptions = [10, 25, 50]@@ -32,6 +43,14 @@ const TableView = props => {const [paginationModel, setPaginationModel] = useState(defaultPaginationConfig)const store = useAppSelector(state => state.metalakes)+ const [openDrawer, setOpenDrawer] = useState(false)+ const [drawerData, setDrawerData] = useState()+ const [confirmCacheData, setConfirmCacheData] = useState(null)+ const [openConfirmDelete, setOpenConfirmDelete] = useState(false)+ const [openDialog, setOpenDialog] = useState(false)+ const [dialogData, setDialogData] = useState({})+ const [dialogType, setDialogType] = useState('create')+const handleClickUrl = path => {if (!path) {return@@ -91,6 +110,78 @@ const TableView = props => {}]+ const catalogsColumns = [+ {+ flex: 0.1,+ minWidth: 60,+ field: 'id',+ headerName: 'Name',+ renderCell: ({ row }) => {+ const { name, path } = row++ return (+ <Box sx={{ display: 'flex', alignItems: 'center' }}>+ <Typography+ noWrap+ {...(path+ ? {+ component: Link,+ href: path+ }+ : {})}+ onClick={() => handleClickUrl(path)}+ sx={{+ fontWeight: 400,+ color: 'primary.main',+ textDecoration: 'none',+ '&:hover': { color: 'primary.main', textDecoration: 'underline' }+ }}+ >+ {name}+ </Typography>+ </Box>+ )+ }+ },+ {+ flex: 0.1,+ minWidth: 90,+ sortable: false,+ field: 'actions',+ headerName: 'Actions',+ renderCell: ({ row }) => (+ <>+ <IconButton+ title='Details'+ size='small'+ sx={{ color: theme => theme.palette.text.secondary }}+ onClick={() => handleShowDetails({ row, type: 'catalog' })}+ >+ <Icon icon='bx:show-alt' />+ </IconButton>++ <IconButton+ title='Edit'+ size='small'+ sx={{ color: theme => theme.palette.text.secondary }}+ onClick={() => handleShowEditDialog({ row, type: 'catalog' })}+ >+ <Icon icon='mdi:square-edit-outline' />+ </IconButton>++ <IconButton+ title='Delete'+ size='small'+ sx={{ color: theme => theme.palette.error.light }}+ onClick={() => handleDelete({ name: row.name, type: 'catalog' })}+ >+ <Icon icon='mdi:delete-outline' />+ </IconButton>+ </>+ )+ }+ ]+const tableColumns = [{flex: 0.1,@@ -158,30 +249,111 @@ const TableView = props => {}]+ const handleShowDetails = async ({ row, type }) => {+ if (type === 'catalog') {+ const [err, res] = await to(getCatalogDetailsApi({ metalake, catalog: row.name }))++ if (err || !res) {+ throw new Error(err)+ }++ setDrawerData(res.catalog)+ setOpenDrawer(true)+ }+ }++ const handleShowEditDialog = async data => {+ const metalake = data.row.namespace[0] || null+ const catalog = data.row.name || null++ if (metalake && catalog) {+ const [err, res] = await to(getCatalogDetailsApi({ metalake, catalog }))++ if (err || !res) {+ throw new Error(err)+ }++ const { catalog: resCatalog } = res++ setDialogType('update')+ setDialogData(resCatalog)+ setOpenDialog(true)+ }+ }++ const handleDelete = ({ name, type }) => {+ setOpenConfirmDelete(true)+ setConfirmCacheData({ name, type })+ }++ const handleCloseConfirm = () => {+ setOpenConfirmDelete(false)+ setConfirmCacheData(null)+ }++ const handleConfirmDeleteSubmit = () => {+ if (confirmCacheData) {+ if (confirmCacheData.type === 'catalog') {+ dispatch(deleteCatalog({ metalake, catalog: confirmCacheData.name }))+ }++ setOpenConfirmDelete(false)+ }+ }++ const checkColumns = () => {+ if (page === 'metalakes') {+ return catalogsColumns+ } else if (page === 'tables') {+ return tableColumns+ } else {+ return columns+ }+ }+useEffect(() => {setPaginationModel({ ...paginationModel, page: 0 })// eslint-disable-next-line react-hooks/exhaustive-deps}, [store.tableLoading])return (- <DataGrid- sx={{- '& .MuiDataGrid-columnHeaders': {- borderTopLeftRadius: 0,- borderTopRightRadius: 0,- borderTop: 0- }- }}- autoHeight- loading={store.tableLoading}- rows={store.tableData}- getRowId={row => row?.name}- columns={page === 'tables' ? tableColumns : columns}- disableRowSelectionOnClick- pageSizeOptions={pageSizeOptions}- paginationModel={paginationModel}- onPaginationModelChange={setPaginationModel}- />+ <>+ <DataGrid+ sx={{+ '& .MuiDataGrid-columnHeaders': {+ borderTopLeftRadius: 0,+ borderTopRightRadius: 0,+ borderTop: 0+ }+ }}+ autoHeight+ loading={store.tableLoading}+ rows={store.tableData}+ getRowId={row => row?.name}+ columns={checkColumns()}+ disableRowSelectionOnClick+ pageSizeOptions={pageSizeOptions}+ paginationModel={paginationModel}+ onPaginationModelChange={setPaginationModel}+ />+ <DetailsDrawer openDrawer={openDrawer} setOpenDrawer={setOpenDrawer} drawerData={drawerData} />+ <ConfirmDeleteDialog+ open={openConfirmDelete}+ setOpen={setOpenConfirmDelete}+ confirmCacheData={confirmCacheData}+ handleClose={handleCloseConfirm}+ handleConfirmDeleteSubmit={handleConfirmDeleteSubmit}+ />++ <CreateCatalogDialog+ open={openDialog}+ setOpen={setOpenDialog}+ updateCatalog={updateCatalog}+ data={dialogData}+ type={dialogType}+ routeParams={routeParams}+ />+ </>)}diff --git a/web/app/ui/metalakes/TabsContent.js b/web/app/ui/metalakes/TabsContent.jsindex 82730db007..5c4be8ed39 100644--- a/web/app/ui/metalakes/TabsContent.js+++ b/web/app/ui/metalakes/TabsContent.js@@ -51,7 +51,7 @@ const CustomTabPanel = props => {}const TabsContent = props => {- const { tableTitle, store, page } = props+ const { tableTitle, store, page, routeParams } = propsconst [tab, setTab] = useState('table')const handleChangeTab = (event, newValue) => {@@ -67,7 +67,7 @@ const TabsContent = props => {</TabList></Box><CustomTabPanel value='table'>- <TableView page={page} />+ <TableView page={page} routeParams={routeParams} /></CustomTabPanel><CustomTabPanel value='details'><DetailsView store={store} page={page} />diff --git a/web/lib/api/catalogs/index.js b/web/lib/api/catalogs/index.jsindex f3d3f0af3c..45c1c6eb3f 100644--- a/web/lib/api/catalogs/index.js+++ b/web/lib/api/catalogs/index.js@@ -8,7 +8,9 @@ import { defHttp } from '@/lib/utils/axios'const Apis = {GET: ({ metalake }) => `/api/metalakes/${metalake}/catalogs`,GET_DETAIL: ({ metalake, catalog }) => `/api/metalakes/${metalake}/catalogs/${catalog}`,- CREATE: ({ metalake }) => `/api/metalakes/${metalake}/catalogs`+ CREATE: ({ metalake }) => `/api/metalakes/${metalake}/catalogs`,+ UPDATE: ({ metalake, catalog }) => `/api/metalakes/${metalake}/catalogs/${catalog}`,+ DELETE: ({ metalake, catalog }) => `/api/metalakes/${metalake}/catalogs/${catalog}`}export const getCatalogsApi = params => {@@ -29,3 +31,16 @@ export const createCatalogApi = ({ data, metalake }) => {data})}++export const updateCatalogApi = ({ metalake, catalog, data }) => {+ return defHttp.put({+ url: `${Apis.UPDATE({ metalake, catalog })}`,+ data+ })+}++export const deleteCatalogApi = ({ metalake, catalog }) => {+ return defHttp.delete({+ url: `${Apis.DELETE({ metalake, catalog })}`+ })+}diff --git a/web/lib/store/metalakes/index.js b/web/lib/store/metalakes/index.jsindex afa5192514..bb701f91a0 100644--- a/web/lib/store/metalakes/index.js+++ b/web/lib/store/metalakes/index.js@@ -15,7 +15,13 @@ import {getMetalakeDetailsApi} from '@/lib/api/metalakes'-import { getCatalogsApi, getCatalogDetailsApi, createCatalogApi } from '@/lib/api/catalogs'+import {+ getCatalogsApi,+ getCatalogDetailsApi,+ createCatalogApi,+ updateCatalogApi,+ deleteCatalogApi+} from '@/lib/api/catalogs'import { getSchemasApi, getSchemaDetailsApi } from '@/lib/api/schemas'import { getTablesApi, getTableDetailsApi } from '@/lib/api/tables'@@ -274,7 +280,9 @@ export const getCatalogDetails = createAsyncThunk('appMetalakes/getCatalogDetailexport const createCatalog = createAsyncThunk('appMetalakes/createCatalog',async ({ data, metalake }, { dispatch }) => {+ dispatch(setTableLoading(true))const [err, res] = await to(createCatalogApi({ data, metalake }))+ dispatch(setTableLoading(false))if (err || !res) {throw new Error(err)@@ -288,6 +296,35 @@ export const createCatalog = createAsyncThunk(})+export const updateCatalog = createAsyncThunk(+ 'appMetalakes/updateCatalog',+ async ({ metalake, catalog, data }, { dispatch }) => {+ const [err, res] = await to(updateCatalogApi({ metalake, catalog, data }))+ if (err || !res) {+ throw new Error(err)+ }+ dispatch(fetchCatalogs({ metalake, catalog, page: 'metalakes', init: true }))+ dispatch(initMetalakeTree({ metalake, catalog }))++ return res+ }+)++export const deleteCatalog = createAsyncThunk('appMetalakes/deleteCatalog', async (data, { dispatch }) => {+ dispatch(setTableLoading(true))+ const [err, res] = await to(deleteCatalogApi(data))+ dispatch(setTableLoading(false))++ if (err || !res) {+ throw new Error(err)+ }++ dispatch(fetchCatalogs({ ...data, page: 'metalakes', init: true }))+ dispatch(initMetalakeTree({ ...data }))++ return res+})+export const fetchSchemas = createAsyncThunk('appMetalakes/fetchSchemas',async ({ init, page, metalake, catalog }, { dispatch }) => {