Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5059] Add commands to create, delete and modify metalakes, catalogs and schema in CLI. #5117

Merged
merged 85 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
b5e08c0
Added firest part of CLI code.
justinmclean Oct 2, 2024
655d133
update CLI option with output
justinmclean Oct 2, 2024
4a29c8b
Add missing license header
justinmclean Oct 2, 2024
1b12eff
Add default
justinmclean Oct 2, 2024
75de71e
Spotless on Java 11
justinmclean Oct 2, 2024
5172afa
Ignore warnings in test with Java 11
justinmclean Oct 2, 2024
0dc8856
Disable two tests on JAVA 17
justinmclean Oct 2, 2024
24dee9e
disabling two tests for now
justinmclean Oct 2, 2024
0ddbb7d
fix disabled tests
justinmclean Oct 2, 2024
4b95dd3
Still having issues on Java 17
justinmclean Oct 2, 2024
f76fa16
remove two tests as Java 17 is still giving issues
justinmclean Oct 2, 2024
8cbc605
No need to copy CLI for IT tests
justinmclean Oct 2, 2024
0ec7ecb
create catalogs and other entities
justinmclean Oct 9, 2024
fa2cdaf
remove unneeded call
justinmclean Oct 9, 2024
1e05853
Merge branch 'CLI' into CLI_II
justinmclean Oct 10, 2024
3df9f11
add more tests
justinmclean Oct 11, 2024
5e611be
add more tests
justinmclean Oct 11, 2024
68f7fa2
change version command into client and server version commands
justinmclean Oct 11, 2024
e2ebb7a
list entities and commands
justinmclean Oct 11, 2024
0e82c8f
Cache the metalake environment variable
justinmclean Oct 11, 2024
7b97750
use libs
justinmclean Oct 11, 2024
a562ed7
Merge branch 'main' into CLI
justinmclean Oct 11, 2024
47364fd
Merge branch 'CLI' into CLI_II
justinmclean Oct 12, 2024
d678b99
Trino Connector uses old deprecated CLI
justinmclean Oct 12, 2024
c201ef5
Merge branch 'CLI' into CLI_II
justinmclean Oct 12, 2024
253a2b4
fix test
justinmclean Oct 12, 2024
f90a086
fix spelling error
justinmclean Oct 16, 2024
3c87c3d
add examples not using metalake
justinmclean Oct 16, 2024
10af3d2
remove duplication and clarify
justinmclean Oct 16, 2024
f955db2
use client shadow jar
justinmclean Oct 16, 2024
80aef91
wrong file
justinmclean Oct 16, 2024
6d897c0
new -> 19
justinmclean Oct 17, 2024
76aa1fe
fix example command
justinmclean Oct 17, 2024
affd6ad
revert as the suggested name is not value
justinmclean Oct 17, 2024
abc2da8
simplify command options
justinmclean Oct 17, 2024
a7c2a88
Merge branch 'CLI' into CLI_II
justinmclean Oct 17, 2024
055678b
fix merge issue and tests
justinmclean Oct 17, 2024
9808022
update command options
justinmclean Oct 17, 2024
464a74b
fix imports
justinmclean Oct 17, 2024
05bc9ed
update command options
justinmclean Oct 17, 2024
423219c
Merge branch 'main' into CLI
justinmclean Oct 17, 2024
954b351
Make executable and runnable from bin directory. update command format.
justinmclean Oct 22, 2024
808fffc
revert back to using two args and fix command format
justinmclean Oct 22, 2024
848a381
remove meatlake form name and add back metalake option
justinmclean Oct 22, 2024
2fe9a80
add Gravitino URL as an environment variable
justinmclean Oct 22, 2024
526d305
update README to mention environment variables
justinmclean Oct 22, 2024
d2ded4c
improved description of met lake name and add to options docs
justinmclean Oct 22, 2024
cb5a5d7
remove version number from alias
justinmclean Oct 22, 2024
71107fd
order in alphabetical order
justinmclean Oct 22, 2024
a6aeb42
add final where needed
justinmclean Oct 22, 2024
ce3ddc1
made private
justinmclean Oct 22, 2024
70aaaf9
use Joiner instead of StringBuilder
justinmclean Oct 22, 2024
22ca191
update commands
justinmclean Oct 23, 2024
ab52cf2
improve command line error handling
justinmclean Oct 23, 2024
bd57944
add executable shell script
justinmclean Oct 23, 2024
445cd41
put back README and make it developer focused
justinmclean Oct 23, 2024
7ea7125
support ignore option to ignore client/server version mismatch
justinmclean Oct 23, 2024
0a8844e
move list commands up one entity
justinmclean Oct 23, 2024
c342d7e
add comment
justinmclean Oct 23, 2024
d2b28af
no need for class
justinmclean Oct 23, 2024
038e1f6
fix command error handling and unwanted output
justinmclean Oct 23, 2024
ce5fa18
remove example scripts
justinmclean Oct 23, 2024
069f425
add CLI documentation
justinmclean Oct 23, 2024
5ed49fa
Merge branch 'CLI' into CLI_II
justinmclean Oct 23, 2024
4d68055
update tests
justinmclean Oct 23, 2024
f8c1f9b
update commands to use ignore parameter
justinmclean Oct 23, 2024
33efd6e
made variables final
justinmclean Oct 23, 2024
82ba035
remove user-facing content
justinmclean Oct 23, 2024
a4ac180
add URL to config file
justinmclean Oct 24, 2024
1ea9e12
list commands need to run first or warning in output occurs
justinmclean Oct 24, 2024
c3fc55c
add javadocs
justinmclean Oct 24, 2024
4b60ea4
Merge branch 'main' into CLI_II
justinmclean Oct 24, 2024
20e550f
reset files
justinmclean Oct 24, 2024
eeefccc
restore test files
justinmclean Oct 24, 2024
9f073ac
add ignore to the config file
justinmclean Oct 24, 2024
64f18ef
update documentation
justinmclean Oct 24, 2024
74452c9
minor English updates
justinmclean Oct 25, 2024
d8c111f
add override annotation
justinmclean Oct 31, 2024
09a5d55
add expections
justinmclean Oct 31, 2024
3a64a1d
add @Override
justinmclean Oct 31, 2024
ccb5e01
update tests
justinmclean Oct 31, 2024
7ab5666
update documentation
justinmclean Oct 31, 2024
366de9e
Remove different catalog options and classes and add the ability to s…
justinmclean Nov 4, 2024
e133aff
update documentation
justinmclean Nov 4, 2024
81bf84b
Merge branch 'main' into CLI_II
justinmclean Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ subprojects {
options.locale = "en_US"

val projectName = project.name
if (projectName == "common" || projectName == "api" || projectName == "client-java" || projectName == "filesystem-hadoop3") {
if (projectName == "common" || projectName == "api" || projectName == "client-java" || projectName == "client-cli" || projectName == "filesystem-hadoop3") {
options {
(this as CoreJavadocOptions).addStringOption("Xwerror", "-quiet")
isFailOnError = true
Expand Down Expand Up @@ -757,6 +757,7 @@ tasks {
subprojects.forEach() {
if (!it.name.startsWith("catalog") &&
!it.name.startsWith("client") &&
!it.name.startsWith("cli") &&
!it.name.startsWith("authorization") &&
!it.name.startsWith("filesystem") &&
!it.name.startsWith("spark") &&
Expand Down
198 changes: 198 additions & 0 deletions clients/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
<!--
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.
-->

# Apache Gravitino CLI

Apache Gravitino CLI is a command-line tool that interacts with the Gravitino server to manage and query entities like metalakes, catalogs, schemas, and tables. The tool provides options for listing information about Gravitino entities and in future versions support creating, deleting, and updating these entities.

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Commands](#commands)
- [Running Tests](#running-tests)
- [Contributing](#contributing)
- [License](#license)

## Features

- Retrieve server version
- Provide help on usage
- Manage Gravitino entities such as Metalakes, Catalogs, Schemas, and Tables
- List details about Graviotino entities

## Installation

### Prerequisites

Before you can build and run this project, it is suggested you have the following installed:

- Java 11 or higher

### Build the Project

1. Clone the entire Gravitino repository:

```bash
git clone https://github.com/apache/gravitino
```

2. Build the CLI sub-project using Gradle:

```bash
./gradlew :clients:cli:build
```
3. Create an alias:

```bash
alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar'
```
3. Test the command:
```bash
gcli --help
```

## Usage

To run the Gravitino CLI, use the following command structure:

```bash
usage: gcli [metalake|catalog|schema|table] [list|details|create|delete|update|set|remove|properties] [options]
-b,--bootstrap <arg> Kafka bootstrap servers
-c,--catalog <arg> catalog name
-C,--create create an entity
-D,--details list details about an entity
-d,--database <arg> database name
-e,--entity <arg> entity type
-h,--help command help information
-j,--jdbcurl <arg> JDBC URL
-L,--list list entity children
-m,--metastore <arg> Hive metastore URI
-n,--name <arg> full entity name (dot separated)
-P,--properties show an entities properties
-p,--password <arg> database password
-R,--delete delete an entity
-r,--rename <arg> new entity name
-s,--schema <arg> schema name
-t,--table <arg> table name
-u,--user <arg> database username
-U,--update update an entity
-v,--value <arg> property value
-w,--warehouse <arg> warehouse name
-x,--command <arg> one of: list, details, create, delete, or update
```

The command line can be used in several ways to achieve the same results, depending on your preference.
```bash
gcli catalog details --name metalake_demo.catalog_postgres
gcli catalog --command details -name metalake_demo.catalog_postgres
gcli --entity catalog --command details -name metalake_demo.catalog_postgres
gcli catalog details --metalake metalake_demo --catalog catalog_postgres
gcli details --metalake metalake_demo --catalog catalog_postgres
gcli --metalake metalake_demo --catalog catalog_postgres
gcli --command details --metalake metalake_demo --catalog catalog_postgres
```
The form `gcli <entity> <action> [options]` is used in this document.

## Commands
The following commands are available for entity management:

list: List available entities
details: Show detailed information about an entity
create: Create a new entity
delete: Delete an existing entity
update: Update an existing entity

### Examples
List All Metalakes

```bash
gcli list
```

Get Details of a Specific Metalake

```bash
gcli metalake details -name my_metalake
```

List Tables in a Catalog

```bash
gcli metalake list -name my_metalake.my_catalog
```

Create a Metalake

```bash
gcli metalake create -name my_metalake -comment "This is my metalake"
```

Create a Catalog

```bash
gcli catalog create -name metalake_demo.iceberg --provider iceberg --metastore thrift://hive-host:9083 --warehouse hdfs://hdfs-host:9000/user/iceberg/warehouse
```

Delete a Catalog

```bash
gcli catalog delete -name my_metalake.my_catalog
```

Rename a Metalake

```bash
gcli metalake update -name metalake_demo -rename demo
```

Update a Metalake's comment

```bash
gcli metalake update -name metalake_demo -comment "new comment"
```

### Setting Metalake name

As dealing with one Metalake is a typical scenario, you can set the Metalake name in several ways.

1. Passed in on the command line either as the first part of the entities name or via the `--metalake` parameter.
2. Set via the 'GRAVITINO_METALAKE' environment variable.
3. Placed in the Gravitino configuration file `~/.gravitino` by adding a line like `metalake=metalake_demo`.

The command line option overrides the other options and the environment variable overrides the value in the configuration file.

## Running Tests

This project includes a suite of unit tests to verify its functionality.

To run the tests, execute the following command:

```bash
./gradlew :clients:cli:test
```

## Contributing

We welcome contributions to the Gravitino CLI!

## License

This project is licensed under the Apache License 2.0.
59 changes: 59 additions & 0 deletions clients/cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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.
*/
plugins {
`maven-publish`
id("java")
id("idea")
}

dependencies {
implementation(project(":clients:client-java"))
implementation(project(":api"))
implementation(project(":common"))
implementation(libs.slf4j.api)
implementation(libs.slf4j.simple)
implementation(libs.commons.cli.new)

testImplementation(libs.junit.jupiter.api)
testImplementation(libs.junit.jupiter.params)
testImplementation(libs.mockito.core)

testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.build {
dependsOn("javadoc")
}

tasks.clean {
delete("target")
delete("tmp")
}

tasks.jar {
manifest {
attributes["Main-Class"] = "org.apache.gravitino.cli.Main"
}
val dependencies = configurations
.runtimeClasspath
.get()
.map(::zipTree)
from(dependencies)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
63 changes: 63 additions & 0 deletions clients/cli/errors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

#
# 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.
#

# Some of these examples assume you have the Apache Gravitino playground running.

alias gcli='java -jar clients/cli/build/libs/gravitino-cli-0.7.0-incubating-SNAPSHOT.jar'

# No such command
gcli unknown

# unknown command and entiry
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
gcli unknown unknown

# unknown command and entiry
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
gcli unknown unknown

# unknown command
gcli metalake unknown

# unknown entity
gcli unknown list

# Name not specified
gcli metalake details

# Too many arguments
gcli metalake details more

# Unknown metalake name
gcli metalake details --name unknown

# Unknown catalog name
gcli catalog details --name metalake_demo.unknown

# Unknown catalog name
gcli catalog details --name metalake_demo

# Already exists
gcli metalake create -name metalake_demo

# Doesn't exist
gcli metalake delete -name unknown-metalake

# Malformed name
gcli catalog details -name metalake_demo
Loading
Loading