forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#5477] improvement(cli): display audit information on Catalog,…
… Schema, Table (apache#5509) ### What changes were proposed in this pull request? Add the `--audit` option to display audit information on Catalog, Schema, Table ### Why are the changes needed? This change allows users to retrieve additional audit information on Catalog/Schema/Table, providing more insights. Close: apache#5477 ### Does this PR introduce _any_ user-facing change? Yes, it adds the `--audit` option to `CommandEntities.CATALOG/SCHEMA/TABLE`. ### How was this patch tested? 1. Follow the instructions in the [cli README](https://github.com/apache/gravitino/tree/main/clients/cli) to build the CLI sub-project. 2. Start the Gravitino Playground. To test, use a command like the following: ``` gcli metalake details --metalake metalake_demo --audit gcli catalog details --metalake metalake_demo --name catalog_postgres --audit gcli schema details --metalake metalake_demo --name catalog_postgres.hr --audit gcli table details --metalake metalake_demo --name catalog_postgres.hr.departments --audit ``` Check that the output matches the expected audit information. ![2024-11-08 002032](https://github.com/user-attachments/assets/636e9abf-fdf3-46f0-9e03-d3b485a06de9)
- Loading branch information
Showing
8 changed files
with
320 additions
and
20 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
56 changes: 56 additions & 0 deletions
56
clients/cli/src/main/java/org/apache/gravitino/cli/commands/AuditCommand.java
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,56 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.gravitino.cli.commands; | ||
|
||
import org.apache.gravitino.Audit; | ||
|
||
public abstract class AuditCommand extends Command { | ||
/** | ||
* @param url The URL of the Gravitino server. | ||
* @param ignoreVersions If true don't check the client/server versions match. | ||
*/ | ||
public AuditCommand(String url, boolean ignoreVersions) { | ||
super(url, ignoreVersions); | ||
} | ||
|
||
/* Overridden in parent - do nothing */ | ||
@Override | ||
public void handle() {} | ||
|
||
/** | ||
* Displays audit information for the given audit object. | ||
* | ||
* @param audit from a class that implements the Auditable interface. | ||
*/ | ||
public void displayAuditInfo(Audit audit) { | ||
String auditInfo = | ||
"creator,create_time,modified,modified_time" | ||
+ System.lineSeparator() | ||
+ audit.creator() | ||
+ "," | ||
+ audit.createTime() | ||
+ "," | ||
+ audit.lastModifier() | ||
+ "," | ||
+ audit.lastModifiedTime(); | ||
|
||
System.out.println(auditInfo); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
clients/cli/src/main/java/org/apache/gravitino/cli/commands/CatalogAudit.java
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,69 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.gravitino.cli.commands; | ||
|
||
import org.apache.gravitino.Catalog; | ||
import org.apache.gravitino.cli.ErrorMessages; | ||
import org.apache.gravitino.client.GravitinoClient; | ||
import org.apache.gravitino.exceptions.NoSuchCatalogException; | ||
import org.apache.gravitino.exceptions.NoSuchMetalakeException; | ||
|
||
public class CatalogAudit extends AuditCommand { | ||
|
||
protected final String metalake; | ||
protected final String catalog; | ||
|
||
/** | ||
* Displays the audit information of a catalog. | ||
* | ||
* @param url The URL of the Gravitino server. | ||
* @param ignoreVersions If true don't check the client/server versions match. | ||
* @param metalake The name of the metalake. | ||
* @param catalog The name of the catalog. | ||
*/ | ||
public CatalogAudit(String url, boolean ignoreVersions, String metalake, String catalog) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.catalog = catalog; | ||
} | ||
|
||
/** Displays the audit information of a specified catalog. */ | ||
@Override | ||
public void handle() { | ||
Catalog result; | ||
|
||
try (GravitinoClient client = buildClient(metalake)) { | ||
result = client.loadCatalog(this.catalog); | ||
} catch (NoSuchMetalakeException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_METALAKE); | ||
return; | ||
} catch (NoSuchCatalogException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_CATALOG); | ||
return; | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
if (result != null) { | ||
displayAuditInfo(result.auditInfo()); | ||
} | ||
} | ||
} |
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
78 changes: 78 additions & 0 deletions
78
clients/cli/src/main/java/org/apache/gravitino/cli/commands/SchemaAudit.java
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,78 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.gravitino.cli.commands; | ||
|
||
import org.apache.gravitino.Schema; | ||
import org.apache.gravitino.cli.ErrorMessages; | ||
import org.apache.gravitino.client.GravitinoClient; | ||
import org.apache.gravitino.exceptions.NoSuchCatalogException; | ||
import org.apache.gravitino.exceptions.NoSuchMetalakeException; | ||
import org.apache.gravitino.exceptions.NoSuchSchemaException; | ||
|
||
/** Displays the audit information of schema. */ | ||
public class SchemaAudit extends AuditCommand { | ||
|
||
protected final String metalake; | ||
protected final String catalog; | ||
protected final String schema; | ||
|
||
/** | ||
* Displays the audit information of a schema. | ||
* | ||
* @param url The URL of the Gravitino server. | ||
* @param ignoreVersions If true don't check the client/server versions match. | ||
* @param metalake The name of the metalake. | ||
* @param catalog The name of the catalog. | ||
* @param schema The name of the schenma. | ||
*/ | ||
public SchemaAudit( | ||
String url, boolean ignoreVersions, String metalake, String catalog, String schema) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.catalog = catalog; | ||
this.schema = schema; | ||
} | ||
|
||
/** Displays the audit information of schema. */ | ||
@Override | ||
public void handle() { | ||
Schema result; | ||
|
||
try (GravitinoClient client = buildClient(metalake)) { | ||
result = client.loadCatalog(catalog).asSchemas().loadSchema(this.schema); | ||
} catch (NoSuchMetalakeException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_METALAKE); | ||
return; | ||
} catch (NoSuchCatalogException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_CATALOG); | ||
return; | ||
} catch (NoSuchSchemaException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_SCHEMA); | ||
return; | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
if (result != null) { | ||
displayAuditInfo(result.auditInfo()); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
clients/cli/src/main/java/org/apache/gravitino/cli/commands/TableAudit.java
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,68 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.gravitino.cli.commands; | ||
|
||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.rel.Table; | ||
|
||
/** Displays the audit information of a table. */ | ||
public class TableAudit extends TableCommand { | ||
|
||
protected final String schema; | ||
protected final String table; | ||
|
||
/** | ||
* Displays the audit information of a table. | ||
* | ||
* @param url The URL of the Gravitino server. | ||
* @param ignoreVersions If true don't check the client/server versions match. | ||
* @param metalake The name of the metalake. | ||
* @param catalog The name of the catalog. | ||
* @param schema The name of the schenma. | ||
* @param table The name of the table. | ||
*/ | ||
public TableAudit( | ||
String url, | ||
boolean ignoreVersions, | ||
String metalake, | ||
String catalog, | ||
String schema, | ||
String table) { | ||
super(url, ignoreVersions, metalake, catalog); | ||
this.schema = schema; | ||
this.table = table; | ||
} | ||
|
||
/** Displays the audit information of a table. */ | ||
@Override | ||
public void handle() { | ||
Table gTable; | ||
|
||
try { | ||
NameIdentifier name = NameIdentifier.of(schema, table); | ||
gTable = tableCatalog().loadTable(name); | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
displayAuditInfo(gTable.auditInfo()); | ||
} | ||
} |
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
Oops, something went wrong.