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

[#5057] Added first part of CLI code #5058

Merged
merged 51 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
51 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
fa2cdaf
remove unneeded call
justinmclean Oct 9, 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
d678b99
Trino Connector uses old deprecated CLI
justinmclean Oct 12, 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
9808022
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
0accd4d
no message
justinmclean Oct 24, 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
141 changes: 141 additions & 0 deletions clients/cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<!--
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
justinmclean marked this conversation as resolved.
Show resolved Hide resolved

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.
justinmclean marked this conversation as resolved.
Show resolved Hide resolved

## 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
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
- 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
justinmclean marked this conversation as resolved.
Show resolved Hide resolved

### 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] [options]
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
Options
-c,--catalog <arg> catalog name
-C,--create create an entity
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
-D,--details list details about an entity
-e,--entity <arg> entity type
-f,--name <arg> full entity name (dot separated)
-h,--help command help information
-L,--list list entity children
-m,--metalake <arg> metalake name
-R,--delete delete an entity
-s,--schema <arg> schema name
-t,--table <arg> table name
-u,--url <arg> Gravitino URL (default: http://localhost:8090)
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
-U,--update update an entity
-v,--version Gravitino client version
-r,--server Gravitino server version
-x,--command <arg> one of: list, details, create, delete, or update
```

## 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
```
justinmclean marked this conversation as resolved.
Show resolved Hide resolved

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
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
```

## 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"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use the shadow client jar

Copy link
Member Author

@justinmclean justinmclean Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mchades I tried doing this but was unable to get it to work. You might have to give me some help here. Given it works without why is it needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it is probably best to do this in a separate PR, unless you think otherwise.

implementation(project(":api"))
implementation(project(":common"))
implementation(libs.slf4j.api)
implementation(libs.slf4j.simple)
implementation(libs.commons.cli.new)
justinmclean marked this conversation as resolved.
Show resolved Hide resolved

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

testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.build {
dependsOn("javadoc")
yuqi1129 marked this conversation as resolved.
Show resolved Hide resolved
}

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
}
48 changes: 48 additions & 0 deletions clients/cli/errors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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
gcli metalake unknown

# unknown entity
gcli unknown list

# Name not specified
gcli metalake details

# Unknown metalake name
gcli metalake details --name unknown

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

# Missing catalog name
gcli catalog details --name metalake_demo
111 changes: 111 additions & 0 deletions clients/cli/examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# 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.
#

#!/bin/bash

# These examples assume you have the Apache Gravitino playground running.

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

# display help
gcli --help

# display version
gcli --version

# metalake details
gcli details

# metalake list
gcli list

# metalake details (all these command are equivalent)
gcli metalake details --name metalake_demo
gcli metalake details --metalake metalake_demo
gcli --command details --metalake metalake_demo
gcli metalake --name metalake_demo details
gcli details --name metalake_demo
gcli details --metalake metalake_demo

# list all catalogs in a metalake
gcli metalake list --name metalake_demo

# list catalog schema
gcli catalog list --name metalake_demo.catalog_iceberg
gcli catalog list --name metalake_demo.catalog_mysql
gcli catalog list --name metalake_demo.catalog_postgres
gcli catalog list --name metalake_demo.catalog_hive

# list catalog details
gcli catalog details --name metalake_demo.catalog_iceberg
gcli catalog details --name metalake_demo.catalog_mysql
gcli catalog details --name metalake_demo.catalog_postgres
gcli catalog details --name metalake_demo.catalog_hive

# list schema tables
gcli schema list --name metalake_demo.catalog_postgres.hr
gcli schema list --name metalake_demo.catalog_mysql.db
gcli schema list --name metalake_demo.catalog_hive.sales

# list schema details
gcli schema details --name metalake_demo.catalog_postgres.hr
gcli schema details --name metalake_demo.catalog_mysql.db
gcli schema details --name metalake_demo.catalog_hive.sales

# list table details
gcli table list --name metalake_demo.catalog_postgres.hr.departments
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
gcli table list --name metalake_demo.catalog_mysql.db.iceberg_tables
gcli table list --name metalake_demo.catalog_hive.sales.products

# Exmaples where metalake is set in an evironment variable
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
export GRAVITINO_METALAKE=metalake_demo
justinmclean marked this conversation as resolved.
Show resolved Hide resolved

# metalake details
gcli metalake details

# list all catalogs in a metalake
gcli metalake list
justinmclean marked this conversation as resolved.
Show resolved Hide resolved

# list catalog schema
gcli catalog list --name catalog_iceberg
gcli catalog list --name catalog_mysql
gcli catalog list --name catalog_postgres
gcli catalog list --name catalog_hive

# list catalog details
justinmclean marked this conversation as resolved.
Show resolved Hide resolved
gcli catalog details --name catalog_iceberg
gcli catalog details --name catalog_mysql
gcli catalog details --name catalog_postgres
gcli catalog details --name catalog_hive

# list schema tables
gcli schema list --name catalog_postgres.hr
gcli schema list --name catalog_mysql.db
gcli schema list --name catalog_hive.sales

# list schema details
gcli schema details --name catalog_postgres.hr
gcli schema details --name catalog_mysql.db
gcli schema details --name catalog_hive.sales

# list table details
gcli table list --name catalog_postgres.hr.departments
gcli table list --name catalog_mysql.db.iceberg_tables
gcli table list --name catalog_hive.sales.products
Loading
Loading