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#5061] Basic user and group CLI (apache#5133)
### What changes were proposed in this pull request? Added basic user and group commands. ### Why are the changes needed? For the CLI to support users and groups. Fix: apache#5061 ### Does this PR introduce _any_ user-facing change? No, but extends CLI support. ### How was this patch tested? Tested locally.
- Loading branch information
1 parent
72b92d6
commit 3a21ce4
Showing
17 changed files
with
758 additions
and
28 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
64 changes: 64 additions & 0 deletions
64
clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateGroup.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,64 @@ | ||
/* | ||
* 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.cli.ErrorMessages; | ||
import org.apache.gravitino.client.GravitinoClient; | ||
import org.apache.gravitino.exceptions.GroupAlreadyExistsException; | ||
import org.apache.gravitino.exceptions.NoSuchMetalakeException; | ||
|
||
public class CreateGroup extends Command { | ||
protected final String metalake; | ||
protected final String group; | ||
|
||
/** | ||
* Create a new group. | ||
* | ||
* @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 group The name of the group. | ||
*/ | ||
public CreateGroup(String url, boolean ignoreVersions, String metalake, String group) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.group = group; | ||
} | ||
|
||
/** Create a new group. */ | ||
@Override | ||
public void handle() { | ||
try { | ||
GravitinoClient client = buildClient(metalake); | ||
client.addGroup(group); | ||
} catch (NoSuchMetalakeException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_METALAKE); | ||
return; | ||
} catch (GroupAlreadyExistsException err) { | ||
System.err.println(ErrorMessages.GROUP_EXISTS); | ||
return; | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
System.out.println(group + " created"); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateUser.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,64 @@ | ||
/* | ||
* 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.cli.ErrorMessages; | ||
import org.apache.gravitino.client.GravitinoClient; | ||
import org.apache.gravitino.exceptions.NoSuchMetalakeException; | ||
import org.apache.gravitino.exceptions.UserAlreadyExistsException; | ||
|
||
public class CreateUser extends Command { | ||
protected final String metalake; | ||
protected final String user; | ||
|
||
/** | ||
* Create a new User. | ||
* | ||
* @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 user The name of the user. | ||
*/ | ||
public CreateUser(String url, boolean ignoreVersions, String metalake, String user) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.user = user; | ||
} | ||
|
||
/** Create a new user. */ | ||
@Override | ||
public void handle() { | ||
try { | ||
GravitinoClient client = buildClient(metalake); | ||
client.addUser(user); | ||
} catch (NoSuchMetalakeException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_METALAKE); | ||
return; | ||
} catch (UserAlreadyExistsException err) { | ||
System.err.println(ErrorMessages.USER_EXISTS); | ||
return; | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
System.out.println(user + " created"); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.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,71 @@ | ||
/* | ||
* 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.cli.ErrorMessages; | ||
import org.apache.gravitino.client.GravitinoClient; | ||
import org.apache.gravitino.exceptions.NoSuchGroupException; | ||
import org.apache.gravitino.exceptions.NoSuchMetalakeException; | ||
|
||
public class DeleteGroup extends Command { | ||
|
||
protected final String metalake; | ||
protected final String group; | ||
|
||
/** | ||
* Delete a group. | ||
* | ||
* @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 group The name of the group. | ||
*/ | ||
public DeleteGroup(String url, boolean ignoreVersions, String metalake, String group) { | ||
super(url, ignoreVersions); | ||
this.metalake = metalake; | ||
this.group = group; | ||
} | ||
|
||
/** Delete a group. */ | ||
@Override | ||
public void handle() { | ||
boolean deleted = false; | ||
|
||
try { | ||
GravitinoClient client = buildClient(metalake); | ||
deleted = client.removeGroup(group); | ||
} catch (NoSuchMetalakeException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_METALAKE); | ||
return; | ||
} catch (NoSuchGroupException err) { | ||
System.err.println(ErrorMessages.UNKNOWN_GROUP); | ||
return; | ||
} catch (Exception exp) { | ||
System.err.println(exp.getMessage()); | ||
return; | ||
} | ||
|
||
if (deleted) { | ||
System.out.println(group + " deleted."); | ||
} else { | ||
System.out.println(group + " not deleted."); | ||
} | ||
} | ||
} |
Oops, something went wrong.