-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes were proposed in this pull request? Added basic Fileset commands to Gravitno CLI ### Why are the changes needed? To expand Gravitino CLI support. Fix: #5379 ### Does this PR introduce _any_ user-facing change? No, but it adds extra commands to the Gravitino CLI. ### How was this patch tested? Compiled and tested locally.
- Loading branch information
1 parent
e25a67a
commit 7a42199
Showing
14 changed files
with
691 additions
and
15 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
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
103 changes: 103 additions & 0 deletions
103
clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateFileset.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,103 @@ | ||
/* | ||
* 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 java.util.Map; | ||
import org.apache.gravitino.NameIdentifier; | ||
import org.apache.gravitino.cli.ErrorMessages; | ||
import org.apache.gravitino.client.GravitinoClient; | ||
import org.apache.gravitino.exceptions.FilesetAlreadyExistsException; | ||
import org.apache.gravitino.exceptions.NoSuchCatalogException; | ||
import org.apache.gravitino.exceptions.NoSuchMetalakeException; | ||
import org.apache.gravitino.exceptions.NoSuchSchemaException; | ||
import org.apache.gravitino.file.Fileset; | ||
|
||
public class CreateFileset extends Command { | ||
protected final String metalake; | ||
protected final String catalog; | ||
protected final String schema; | ||
protected final String fileset; | ||
protected final String comment; | ||
protected final Map<String, String> properties; | ||
|
||
/** | ||
* Create a new fileset. | ||
* | ||
* @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 fileset The name of the fileset. | ||
* @param comment The fileset's comment. | ||
* @param properties The catalog's properties. | ||
*/ | ||
public CreateFileset( | ||
String url, | ||
boolean ignoreVersions, | ||
String metalake, | ||
String catalog, | ||
String schema, | ||
String fileset, | ||
String comment, | ||
Map<String, String> properties) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.catalog = catalog; | ||
this.schema = schema; | ||
this.fileset = fileset; | ||
this.comment = comment; | ||
this.properties = properties; | ||
} | ||
|
||
/** Create a new fileset. */ | ||
@Override | ||
public void handle() { | ||
NameIdentifier name = NameIdentifier.of(schema, fileset); | ||
boolean managed = properties.get("managed").equals("true"); | ||
String location = properties.get("location"); | ||
Fileset.Type filesetType = managed ? Fileset.Type.MANAGED : Fileset.Type.EXTERNAL; | ||
|
||
try { | ||
GravitinoClient client = buildClient(metalake); | ||
client | ||
.loadCatalog(catalog) | ||
.asFilesetCatalog() | ||
.createFileset(name, comment, filesetType, location, null); | ||
} 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 (FilesetAlreadyExistsException err) { | ||
System.err.println(ErrorMessages.FILESET_EXISTS); | ||
return; | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
System.out.println(fileset + " created"); | ||
} | ||
} |
Oops, something went wrong.