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#5962] feat(client): added audit cli command model (apache#6047)
### What changes were proposed in this pull request? The audit command is one of the commands suggested by @justinmclean as part of adding Model entity support for the CLI. Also includes addition of relevant testing code for Model entity CLI commands a whole. ### Why are the changes needed? To add audit functionality for a Model using the CLI Improvement: apache#5962 ### Does this PR introduce _any_ user-facing change? Yes. The audit command for a model was added. ### How was this patch tested? Unit tests were added for Model CLI support and ran successfully for the audit command.
- Loading branch information
1 parent
2221095
commit 82a299e
Showing
9 changed files
with
142 additions
and
5 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
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
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
90 changes: 90 additions & 0 deletions
90
clients/cli/src/main/java/org/apache/gravitino/cli/commands/ModelAudit.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,90 @@ | ||
/* | ||
* 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.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.NoSuchModelException; | ||
import org.apache.gravitino.model.Model; | ||
import org.apache.gravitino.model.ModelCatalog; | ||
|
||
/** Displays the audit information of a model. */ | ||
public class ModelAudit extends AuditCommand { | ||
|
||
protected final String metalake; | ||
protected final String catalog; | ||
protected final String schema; | ||
protected final String model; | ||
|
||
/** | ||
* Displays the audit information of a model. | ||
* | ||
* @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 schema. | ||
* @param model The name of the model. | ||
*/ | ||
public ModelAudit( | ||
String url, | ||
boolean ignoreVersions, | ||
String metalake, | ||
String catalog, | ||
String schema, | ||
String model) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.catalog = catalog; | ||
this.schema = schema; | ||
this.model = model; | ||
} | ||
|
||
/** Displays the audit information of a model. */ | ||
@Override | ||
public void handle() { | ||
NameIdentifier name = NameIdentifier.of(schema, model); | ||
Model result; | ||
|
||
try (GravitinoClient client = buildClient(this.metalake)) { | ||
ModelCatalog modelCatalog = client.loadCatalog(catalog).asModelCatalog(); | ||
result = modelCatalog.getModel(name); | ||
} catch (NoSuchMetalakeException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_METALAKE); | ||
return; | ||
} catch (NoSuchCatalogException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_CATALOG); | ||
return; | ||
} catch (NoSuchModelException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_MODEL); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
gcli model [details] | ||
|
||
Please set the metalake in the Gravitino configuration file or the environment variable before running any of these commands. | ||
|
||
Example commands | ||
|
||
Show model audit information | ||
gcli model details --name catalog_postgres.hr --audit |
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