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#5963] feat(client): added delete cli command model (apache#6099
) ### What changes were proposed in this pull request? The delete command is one of the commands suggested by @justinmclean as part of adding Model entity support for the CLI. ### Why are the changes needed? To add delete functionality for a Model using the CLI Improvement: apache#5963 (NOTE: Create command is redundant with addition of Register command) ### Does this PR introduce any user-facing change? Yes. The delete command for a model was added. ### How was this patch tested? Unit tests were added for Model CLI support and ran successfully for the delete command, along with CI tests in forked repository
- Loading branch information
1 parent
c16f595
commit 86ef6e8
Showing
5 changed files
with
176 additions
and
4 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
96 changes: 96 additions & 0 deletions
96
clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteModel.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,96 @@ | ||
/* | ||
* 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.AreYouSure; | ||
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.exceptions.NoSuchSchemaException; | ||
|
||
/** Deletes an existing model. */ | ||
public class DeleteModel extends Command { | ||
|
||
protected final String metalake; | ||
protected final String catalog; | ||
protected final String schema; | ||
protected final String model; | ||
protected final boolean force; | ||
|
||
/** | ||
* Deletes an existing model. | ||
* | ||
* @param url The URL of the Gravitino server. | ||
* @param ignoreVersions If true don't check the client/server versions match. | ||
* @param force Force operation. | ||
* @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 DeleteModel( | ||
String url, | ||
boolean ignoreVersions, | ||
boolean force, | ||
String metalake, | ||
String catalog, | ||
String schema, | ||
String model) { | ||
super(url, ignoreVersions); | ||
this.force = force; | ||
this.metalake = metalake; | ||
this.catalog = catalog; | ||
this.schema = schema; | ||
this.model = model; | ||
} | ||
|
||
/** Deletes an existing model. */ | ||
public void handle() { | ||
boolean deleted = false; | ||
|
||
if (!AreYouSure.really(force)) { | ||
return; | ||
} | ||
|
||
try (GravitinoClient client = buildClient(metalake)) { | ||
NameIdentifier name = NameIdentifier.of(schema, model); | ||
deleted = client.loadCatalog(catalog).asModelCatalog().deleteModel(name); | ||
} catch (NoSuchMetalakeException noSuchMetalakeException) { | ||
exitWithError(ErrorMessages.UNKNOWN_METALAKE); | ||
} catch (NoSuchCatalogException noSuchCatalogException) { | ||
exitWithError(ErrorMessages.UNKNOWN_CATALOG); | ||
} catch (NoSuchSchemaException noSuchSchemaException) { | ||
exitWithError(ErrorMessages.UNKNOWN_SCHEMA); | ||
} catch (NoSuchModelException noSuchModelException) { | ||
exitWithError(ErrorMessages.UNKNOWN_MODEL); | ||
} catch (Exception err) { | ||
exitWithError(err.getMessage()); | ||
} | ||
|
||
if (deleted) { | ||
System.out.println(model + " deleted."); | ||
} else { | ||
System.out.println(model + " not deleted."); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,41 @@ | ||
gcli model [details] | ||
gcli model [list|details|create|update|delete] | ||
|
||
Please set the metalake in the Gravitino configuration file or the environment variable before running any of these commands. | ||
|
||
Example commands | ||
|
||
Register a model | ||
gcli model create --name hadoop.schema.model | ||
|
||
Register a model with comment | ||
gcli model create --name hadoop.schema.model --comment comment | ||
|
||
Register a model with properties | ||
gcli model create --name hadoop.schema.model --properties key1=val1 key2=val2 | ||
|
||
Register a model with properties" and comment | ||
gcli model create --name hadoop.schema.model --properties key1=val1 key2=val2 --comment comment | ||
|
||
List models | ||
gcli model list --name hadoop.schema | ||
|
||
Show a model's details | ||
gcli model details --name hadoop.schema.model | ||
|
||
Show model audit information | ||
gcli model details --name catalog_postgres.hr --audit | ||
gcli model details --name hadoop.schema.model --audit | ||
|
||
Link a model | ||
gcli model update --name hadoop.schema.model --uri file:///tmp/file | ||
|
||
Link a model with alias | ||
gcli model update --name hadoop.schema.model --uri file:///tmp/file --alias aliasA aliasB | ||
|
||
Link a model with all component | ||
gcli model update --name hadoop.schema.model --uri file:///tmp/file --alias aliasA aliasB --comment comment --properties key1=val1 key2=val2 | ||
|
||
Link a model without uri | ||
gcli model update --name hadoop.schema.model | ||
|
||
Delete a model | ||
gcli model delete --name hadoop.schema.model |
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