Skip to content

Commit

Permalink
Merge branch 'CLI_VIIIa' into CLI_VIXb
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmclean committed Nov 17, 2024
2 parents b373a2d + c188d30 commit def8779
Show file tree
Hide file tree
Showing 43 changed files with 2,039 additions and 77 deletions.
53 changes: 27 additions & 26 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@
This product bundles various third-party components also under the
Apache Software License 2.0.

Gradle (https://github.com/gradle/gradle)
./gradlew
./gradle/wrapper/gradle-wrapper.properties

Apache Spark
./api/src/main/java/org/apache/gravitino/SchemaChange.java
./api/src/main/java/org/apache/gravitino/SupportsSchemas.java
Expand All @@ -219,23 +223,23 @@
./api/src/main/java/org/apache/gravitino/rel/expressions/transforms/Transform.java
./api/src/main/java/org/apache/gravitino/rel/expressions/Expression.java
./api/src/main/java/org/apache/gravitino/rel/expressions/NamedReference.java
./spark-connector/spark-connector/src/test/java/org/apache/gravitino/spark/connector/integration/test/util/SparkUtilIT.java
./spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/util/SparkUtilIT.java
./dev/release/do-release.sh
./dev/release/release-build.sh
./dev/release/release-tag.sh
./dev/release/release-util.sh

Apache Iceberg
./api/src/main/java/org/apache/gravitino/exceptions/RESTException.java
./catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/CachedClientPool.java
./catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveClientPool.java
./catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/dyn/DynConstructors.java
./catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/dyn/DynFields.java
./catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/dyn/DynMethods.java
./catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/miniHMS/MiniHiveMetastore.java
./catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/miniHMS/MiniHiveMetastoreService.java
./catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/miniHMS/ScriptRunner.java
./catalogs/catalog-hive/src/test/java/org/apache/gravitino/catalog/hive/TestCachedClientPool.java
./catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/CachedClientPool.java
./catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/HiveClientPool.java
./catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/dyn/DynConstructors.java
./catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/dyn/DynFields.java
./catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/dyn/DynMethods.java
./catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/hms/MiniHiveMetastore.java
./catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/hms/MiniHiveMetastoreService.java
./catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/hms/ScriptRunner.java
./catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/TestCachedClientPool.java
./catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/converter/DescribeIcebergSortOrderVisitor.java
./catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/utils/IcebergTablePropertiesUtil.java
./clients/client-java/src/main/java/org/apache/gravitino/client/HTTPClient.java
Expand All @@ -249,13 +253,12 @@
./clients/client-java/src/main/java/org/apache/gravitino/client/OAuth2ClientUtil.java
./iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergExceptionMapper.java
./iceberg/iceberg-common/src/main/java/org/apache/gravitino/iceberg/common/utils/IcebergHiveCachedClientPool.java
./gradlew

Apache Paimon
./catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TypeUtils.java

Apache Hive
./catalogs/catalog-hive/src/test/resources/hive-schema-3.1.0.derby.sql
./catalogs/hive-metastore-common/src/test/resources/hive-schema-3.1.0.derby.sql

Apache Zeppelin
./integration-test-common/src/test/java/org/apache/gravitino/integration/test/util/CommandExecutor.java
Expand All @@ -273,8 +276,7 @@
./server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java

Apache Kafka
./integration-test/src/test/resources/run
./catalogs/catalog-kafka/src/test/resources/run
./integration-test-common/docker-script/init/kafka/run
./core/src/main/java/org/apache/gravitino/utils/Bytes.java

Apache Submarine
Expand All @@ -287,24 +289,23 @@

Trino
./integration-test-common/src/test/java/org/apache/gravitino/integration/test/util/CloseableGroup.java
./trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/hive/SortingColumn.java
./trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/hive/SortingColumn.java

Apache Arrow
./dev/ci/util_free_space.sh

Apache Ranger
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/JsonDateSerializer.java
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/RangerCommonEnums.java
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/VList.java
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/VXDataObject.java
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/VXGroup.java
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/VXGroupList.java
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/VXUser.java
./authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/reference/VXUserList.java

This product bundles a third-party component under the
MIT License.

Kyligence/kylinpy
./clients/client-python/gravitino/utils/exceptions.py
./clients/client-python/gravitino/utils/http_client.py

Apache Ranger
./security-admin/src/main/java/org/apache/ranger/defines/JsonDateSerializer.java
./security-admin/src/main/java/org/apache/ranger/defines/RangerCommonEnums.java
./security-admin/src/main/java/org/apache/ranger/view/VList.java
./security-admin/src/main/java/org/apache/ranger/view/VXDataObject.java
./security-admin/src/main/java/org/apache/ranger/view/VXGroup.java
./security-admin/src/main/java/org/apache/ranger/view/VXGroupList.java
./security-admin/src/main/java/org/apache/ranger/view/VXUser.java
./security-admin/src/main/java/org/apache/ranger/view/VXUserList.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class CommandActions {
public static final String SET = "set";
public static final String REMOVE = "remove";
public static final String PROPERTIES = "properties";
public static final String REVOKE = "revoke";
public static final String GRANT = "grant";

private static final HashSet<String> VALID_COMMANDS = new HashSet<>();

Expand All @@ -46,6 +48,8 @@ public class CommandActions {
VALID_COMMANDS.add(SET);
VALID_COMMANDS.add(REMOVE);
VALID_COMMANDS.add(PROPERTIES);
VALID_COMMANDS.add(REVOKE);
VALID_COMMANDS.add(GRANT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CommandEntities {
public static final String GROUP = "group";
public static final String TAG = "tag";
public static final String FILESET = "fileset";
public static final String OWNER = "owner";
public static final String ROLE = "role";

private static final HashSet<String> VALID_ENTITIES = new HashSet<>();

Expand All @@ -49,7 +49,7 @@ public class CommandEntities {
VALID_ENTITIES.add(GROUP);
VALID_ENTITIES.add(TAG);
VALID_ENTITIES.add(FILESET);
VALID_ENTITIES.add(OWNER);
VALID_ENTITIES.add(ROLE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class ErrorMessages {
public static final String UNKNOWN_FILESET = "Unknown fileset.";
public static final String FILESET_EXISTS = "Fileset already exists.";
public static final String UNKNOWN_ROLE = "Unknown role.";
public static final String ROLE_EXISTS = "Role already exists.";
public static final String INVALID_SET_COMMAND =
"Unsupported combination of options either use --name or --property and --value.";
public static final String INVALID_REMOVE_COMMAND =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,24 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.gravitino.cli.commands.AddRoleToGroup;
import org.apache.gravitino.cli.commands.AddRoleToUser;
import org.apache.gravitino.cli.commands.CatalogAudit;
import org.apache.gravitino.cli.commands.CatalogDetails;
import org.apache.gravitino.cli.commands.ClientVersion;
import org.apache.gravitino.cli.commands.CreateCatalog;
import org.apache.gravitino.cli.commands.CreateFileset;
import org.apache.gravitino.cli.commands.CreateGroup;
import org.apache.gravitino.cli.commands.CreateMetalake;
import org.apache.gravitino.cli.commands.CreateRole;
import org.apache.gravitino.cli.commands.CreateSchema;
import org.apache.gravitino.cli.commands.CreateTag;
import org.apache.gravitino.cli.commands.CreateUser;
import org.apache.gravitino.cli.commands.DeleteCatalog;
import org.apache.gravitino.cli.commands.DeleteFileset;
import org.apache.gravitino.cli.commands.DeleteGroup;
import org.apache.gravitino.cli.commands.DeleteMetalake;
import org.apache.gravitino.cli.commands.DeleteRole;
import org.apache.gravitino.cli.commands.DeleteSchema;
import org.apache.gravitino.cli.commands.DeleteTable;
import org.apache.gravitino.cli.commands.DeleteTag;
Expand All @@ -52,6 +56,7 @@
import org.apache.gravitino.cli.commands.ListGroups;
import org.apache.gravitino.cli.commands.ListMetalakeProperties;
import org.apache.gravitino.cli.commands.ListMetalakes;
import org.apache.gravitino.cli.commands.ListRoles;
import org.apache.gravitino.cli.commands.ListSchema;
import org.apache.gravitino.cli.commands.ListSchemaProperties;
import org.apache.gravitino.cli.commands.ListTableProperties;
Expand All @@ -63,9 +68,12 @@
import org.apache.gravitino.cli.commands.OwnerDetails;
import org.apache.gravitino.cli.commands.RemoveCatalogProperty;
import org.apache.gravitino.cli.commands.RemoveMetalakeProperty;
import org.apache.gravitino.cli.commands.RemoveRoleFromGroup;
import org.apache.gravitino.cli.commands.RemoveRoleFromUser;
import org.apache.gravitino.cli.commands.RemoveSchemaProperty;
import org.apache.gravitino.cli.commands.RemoveTableProperty;
import org.apache.gravitino.cli.commands.RemoveTagProperty;
import org.apache.gravitino.cli.commands.RoleDetails;
import org.apache.gravitino.cli.commands.SchemaAudit;
import org.apache.gravitino.cli.commands.SchemaDetails;
import org.apache.gravitino.cli.commands.ServerVersion;
Expand Down Expand Up @@ -196,6 +204,8 @@ private void executeCommand() {
handleGroupCommand();
} else if (entity.equals(CommandEntities.TAG)) {
handleTagCommand();
} else if (entity.equals(CommandEntities.ROLE)) {
handleRoleCommand();
}
}

Expand Down Expand Up @@ -399,6 +409,16 @@ protected void handleUserCommand() {
} else if (CommandActions.DELETE.equals(command)) {
boolean force = line.hasOption(GravitinoOptions.FORCE);
new DeleteUser(url, ignore, force, metalake, user).handle();
} else if (CommandActions.REVOKE.equals(command)) {
String role = line.getOptionValue(GravitinoOptions.ROLE);
if (role != null) {
new RemoveRoleFromUser(url, ignore, metalake, user, role).handle();
}
} else if (CommandActions.GRANT.equals(command)) {
String role = line.getOptionValue(GravitinoOptions.ROLE);
if (role != null) {
new AddRoleToUser(url, ignore, metalake, user, role).handle();
}
}
}

Expand All @@ -418,6 +438,16 @@ protected void handleGroupCommand() {
} else if (CommandActions.DELETE.equals(command)) {
boolean force = line.hasOption(GravitinoOptions.FORCE);
new DeleteGroup(url, ignore, force, metalake, group).handle();
} else if (CommandActions.REVOKE.equals(command)) {
String role = line.getOptionValue(GravitinoOptions.ROLE);
if (role != null) {
new RemoveRoleFromGroup(url, ignore, metalake, group, role).handle();
}
} else if (CommandActions.GRANT.equals(command)) {
String role = line.getOptionValue(GravitinoOptions.ROLE);
if (role != null) {
new AddRoleToGroup(url, ignore, metalake, group, role).handle();
}
}
}

Expand Down Expand Up @@ -476,6 +506,25 @@ protected void handleTagCommand() {
}
}

/** Handles the command execution for Roles based on command type and the command line options. */
protected void handleRoleCommand() {
String url = getUrl();
FullName name = new FullName(line);
String metalake = name.getMetalakeName();
String role = line.getOptionValue(GravitinoOptions.ROLE);

if (CommandActions.DETAILS.equals(command)) {
new RoleDetails(url, ignore, metalake, role).handle();
} else if (CommandActions.LIST.equals(command)) {
new ListRoles(url, ignore, metalake).handle();
} else if (CommandActions.CREATE.equals(command)) {
new CreateRole(url, ignore, metalake, role).handle();
} else if (CommandActions.DELETE.equals(command)) {
boolean force = line.hasOption(GravitinoOptions.FORCE);
new DeleteRole(url, ignore, force, metalake, role).handle();
}
}

/**
* Handles the command execution for Columns based on command type and the command line options.
*/
Expand Down Expand Up @@ -509,13 +558,13 @@ private void handleFilesetCommand() {
new ListFilesets(url, ignore, metalake, catalog, schema).handle();
} else if (CommandActions.CREATE.equals(command)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
boolean managed = line.hasOption(GravitinoOptions.MANAGED);
String location = line.getOptionValue(GravitinoOptions.LOCATION);

new CreateFileset(url, ignore, metalake, catalog, schema, fileset, comment, managed, location)
String[] properties = line.getOptionValues(GravitinoOptions.PROPERTIES);
Map<String, String> propertyMap = new Properties().parse(properties);
new CreateFileset(url, ignore, metalake, catalog, schema, fileset, comment, propertyMap)
.handle();
} else if (CommandActions.DELETE.equals(command)) {
new DeleteFileset(url, ignore, metalake, catalog, schema, fileset).handle();
boolean force = line.hasOption(GravitinoOptions.FORCE);
new DeleteFileset(url, ignore, force, metalake, catalog, schema, fileset).handle();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ public class GravitinoOptions {
public static final String GROUP = "group";
public static final String TAG = "tag";
public static final String FILESET = "fileset";
public static final String MANAGED = "managed";
public static final String LOCATION = "location";
public static final String OWNER = "owner";
public static final String ROLE = "role";
public static final String AUDIT = "audit";
public static final String FORCE = "force";

Expand All @@ -66,7 +65,7 @@ public Options options() {
options.addOption(createSimpleOption("a", AUDIT, "display audit information"));

// Create/update options
options.addOption(createArgOption("r", RENAME, "new entity name"));
options.addOption(createArgOption(null, RENAME, "new entity name"));
options.addOption(createArgOption("c", COMMENT, "entity comment"));
options.addOption(createArgOption("P", PROPERTY, "property name"));
options.addOption(createArgOption("V", VALUE, "property value"));
Expand All @@ -76,11 +75,10 @@ public Options options() {
options.addOption(createArgOption("l", USER, "user name"));
options.addOption(createArgOption("g", GROUP, "group name"));
options.addOption(createArgOption("a", TAG, "tag name"));
options.addOption(createArgOption("f", FILESET, "fileset name"));
options.addOption(createSimpleOption("m", MANAGED, "a managed fileset"));
options.addOption(createArgOption("l", LOCATION, "fieset location"));
options.addOption(createArgOption(null, FILESET, "fileset name"));
options.addOption(createArgOption("t", TAG, "tag name"));
options.addOption(createSimpleOption("o", OWNER, "display entity owner"));
options.addOption(createSimpleOption("o", OWNER, "entity owner"));
options.addOption(createArgOption("r", ROLE, "role name"));

// Properties option can have multiple values
Option properties =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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.ArrayList;
import org.apache.gravitino.cli.ErrorMessages;
import org.apache.gravitino.client.GravitinoClient;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
import org.apache.gravitino.exceptions.NoSuchRoleException;
import org.apache.gravitino.exceptions.NoSuchUserException;

/** Adds a role to a group. */
public class AddRoleToGroup extends Command {

protected String metalake;
protected String group;
protected String role;

/**
* Adds a role to 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.
* @param role The name of the role.
*/
public AddRoleToGroup(
String url, boolean ignoreVersions, String metalake, String group, String role) {
super(url, ignoreVersions);
this.metalake = metalake;
this.group = group;
this.role = role;
}

/** Adds a role to a group. */
@Override
public void handle() {
try {
GravitinoClient client = buildClient(metalake);
ArrayList<String> roles = new ArrayList<>();
roles.add(role);
client.grantRolesToGroup(roles, group);
} catch (NoSuchMetalakeException err) {
System.err.println(ErrorMessages.UNKNOWN_METALAKE);
return;
} catch (NoSuchRoleException err) {
System.err.println(ErrorMessages.UNKNOWN_ROLE);
return;
} catch (NoSuchUserException err) {
System.err.println(ErrorMessages.UNKNOWN_USER);
return;
} catch (Exception exp) {
System.err.println(exp.getMessage());
return;
}

System.out.println(role + " added to " + group);
}
}
Loading

0 comments on commit def8779

Please sign in to comment.