-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#5061] Basic user and group CLI #5133
Changes from all commits
b5e08c0
655d133
4a29c8b
1b12eff
75de71e
5172afa
0dc8856
24dee9e
0ddbb7d
4b95dd3
f76fa16
8cbc605
0ec7ecb
fa2cdaf
1e05853
3df9f11
5e611be
68f7fa2
e2ebb7a
0e82c8f
7b97750
a562ed7
47364fd
d678b99
c201ef5
253a2b4
0ef4695
f90a086
3c87c3d
10af3d2
f955db2
80aef91
6d897c0
76aa1fe
affd6ad
abc2da8
a7c2a88
055678b
9808022
464a74b
05bc9ed
d27c59a
423219c
954b351
808fffc
848a381
2fe9a80
526d305
d2ded4c
cb5a5d7
71107fd
a6aeb42
ce3ddc1
70aaaf9
22ca191
ab52cf2
bd57944
445cd41
7ea7125
0a8844e
c342d7e
d2b28af
038e1f6
ce5fa18
069f425
5ed49fa
4d68055
f8c1f9b
33efd6e
82ba035
a4ac180
1ea9e12
c3fc55c
451a92f
50edda6
cb31019
dd97d26
4b60ea4
20e550f
eeefccc
9f073ac
64f18ef
74452c9
c79c6e3
d8c111f
09a5d55
3a64a1d
ccb5e01
7ab5666
8472692
ddc0711
366de9e
e133aff
6ce9a37
36596ef
8b65598
41fc424
6d5275c
6255901
2b22e09
18af138
601c320
ffea521
cdbad31
033c04d
f244010
9cf358c
76dd0f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,19 +55,21 @@ public Properties(String delimiter, String keyValueSeparator) { | |
* <p>Each pair in the input string is split by the specified delimiter, and then each pair is | ||
* further split by the key-value separator. | ||
* | ||
* @param input The input string containing name-value pairs. | ||
* @param inputs An arrays of input strings containing name-value pairs. | ||
* @return A map of entries, where each entry represents a key-value pair from the input string. | ||
*/ | ||
public Map<String, String> parse(String input) { | ||
public Map<String, String> parse(String[] inputs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change related with the "user and group" CLI? seems it has already been handled in previous PR, please double check whether this is a code merge issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It not a code merge issue - the way properties have been handled have been improved |
||
HashMap<String, String> map = new HashMap<>(); | ||
|
||
// Split the input by the delimiter into key-value pairs | ||
String[] pairs = input.split(delimiter); | ||
for (String pair : pairs) { | ||
// Split each key-value pair by the separator | ||
String[] keyValue = pair.split(keyValueSeparator, 2); | ||
if (keyValue.length == 2) { | ||
map.put(keyValue[0].trim(), keyValue[1].trim()); | ||
for (String input : inputs) { | ||
// Split the input by the delimiter into key-value pairs | ||
String[] pairs = input.split(delimiter); | ||
for (String pair : pairs) { | ||
// Split each key-value pair by the separator | ||
String[] keyValue = pair.split(keyValueSeparator, 2); | ||
if (keyValue.length == 2) { | ||
map.put(keyValue[0].trim(), keyValue[1].trim()); | ||
} | ||
} | ||
} | ||
|
||
|
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() { | ||
justinmclean marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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"); | ||
} | ||
} |
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"); | ||
} | ||
} |
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."); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"comma separated" is a necessary description for the properties I think, why not keep it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The option has been updated, and they no longer have to be comma separated - see the description in cli.md.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see; This change is irrelavant with current PR, now mixed with other changes; Next time please use a seperate PR, that will be helpful for review as well as code management (revert, cherry-pick, etc).