Skip to content

Commit

Permalink
remove invalid code
Browse files Browse the repository at this point in the history
  • Loading branch information
xunliu committed Oct 29, 2024
1 parent bb20a1e commit 88af032
Showing 1 changed file with 25 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -723,8 +723,8 @@ private void doRemoveMetadataObject(RangerMetadataObject rangerMetadataObject) {
}

/**
* Remove the SCHEMA, Need to rename these the relevant policies, `{schema}`, `{schema}.*`,
* `{schema}.*.*` <br>
* Remove the SCHEMA, Need to remove these the relevant policies, `{schema}`, `{schema}.*`,
* `{schema}.*.*` permissions.
*/
private void doRemoveSchemaMetadataObject(RangerMetadataObject rangerMetadataObject) {
Preconditions.checkArgument(
Expand Down Expand Up @@ -769,8 +769,8 @@ private void doRemoveSchemaMetadataObject(RangerMetadataObject rangerMetadataObj
}

/**
* Remove the TABLE, Need to rename these the relevant policies, `*.{table}`, `*.{table}.{column}`
* <br>
* Remove the TABLE, Need to remove these the relevant policies, `*.{table}`, `*.{table}.{column}`
* permissions.
*/
private void doRemoveTableMetadataObject(RangerMetadataObject rangerMetadataObject) {
List<List<String>> loop =
Expand Down Expand Up @@ -821,23 +821,16 @@ private void doRenameSchemaMetadataObject(
RangerMetadataObject rangerMetadataObject, RangerMetadataObject newRangerMetadataObject) {
List<String> oldMetadataNames = new ArrayList<>();
List<String> newMetadataNames = new ArrayList<>();
List<Map<String, MetadataObject.Type>> loop =
List<Map<String, String>> loop =
ImmutableList.of(
ImmutableMap.of(rangerMetadataObject.names().get(0), MetadataObject.Type.SCHEMA),
ImmutableMap.of(RangerHelper.RESOURCE_ALL, MetadataObject.Type.TABLE),
ImmutableMap.of(RangerHelper.RESOURCE_ALL, MetadataObject.Type.COLUMN));
for (Map<String, MetadataObject.Type> nameAndType : loop) {
oldMetadataNames.add(nameAndType.keySet().stream().findFirst().get());
if (nameAndType.containsValue(MetadataObject.Type.SCHEMA)) {
newMetadataNames.add(newRangerMetadataObject.names().get(0));
} else {
newMetadataNames.add(RangerHelper.RESOURCE_ALL);
}
updatePolicyByMetadataObject(
MetadataObject.Type.SCHEMA,
oldMetadataNames,
newMetadataNames,
nameAndType.values().stream().findFirst().get());
ImmutableMap.of(
rangerMetadataObject.names().get(0), newRangerMetadataObject.names().get(0)),
ImmutableMap.of(RangerHelper.RESOURCE_ALL, RangerHelper.RESOURCE_ALL),
ImmutableMap.of(RangerHelper.RESOURCE_ALL, RangerHelper.RESOURCE_ALL));
for (Map<String, String> mapName : loop) {
oldMetadataNames.add(mapName.keySet().stream().findFirst().get());
newMetadataNames.add(mapName.values().stream().findFirst().get());
updatePolicyByMetadataObject(MetadataObject.Type.SCHEMA, oldMetadataNames, newMetadataNames);
}
}

Expand All @@ -856,7 +849,6 @@ private void doRenameTableMetadataObject(
ImmutableMap.of(RangerHelper.RESOURCE_ALL, MetadataObject.Type.COLUMN));
for (Map<String, MetadataObject.Type> nameAndType : loop) {
oldMetadataNames.add(nameAndType.keySet().stream().findFirst().get());

if (nameAndType.containsValue(MetadataObject.Type.SCHEMA)) {
newMetadataNames.add(newRangerMetadataObject.names().get(0));
// Skip update the schema name operation
Expand All @@ -866,11 +858,7 @@ private void doRenameTableMetadataObject(
} else if (nameAndType.containsValue(MetadataObject.Type.COLUMN)) {
newMetadataNames.add(RangerHelper.RESOURCE_ALL);
}
updatePolicyByMetadataObject(
MetadataObject.Type.TABLE,
oldMetadataNames,
newMetadataNames,
nameAndType.values().stream().findFirst().get());
updatePolicyByMetadataObject(MetadataObject.Type.TABLE, oldMetadataNames, newMetadataNames);
}
}

Expand All @@ -881,12 +869,11 @@ private void doRenameColumnMetadataObject(
List<String> newMetadataNames = new ArrayList<>();
List<Map<String, MetadataObject.Type>> loop =
ImmutableList.of(
ImmutableMap.of(RangerHelper.RESOURCE_ALL, MetadataObject.Type.SCHEMA),
ImmutableMap.of(RangerHelper.RESOURCE_ALL, MetadataObject.Type.TABLE),
ImmutableMap.of(rangerMetadataObject.names().get(0), MetadataObject.Type.SCHEMA),
ImmutableMap.of(rangerMetadataObject.names().get(1), MetadataObject.Type.TABLE),
ImmutableMap.of(rangerMetadataObject.names().get(2), MetadataObject.Type.COLUMN));
for (Map<String, MetadataObject.Type> nameAndType : loop) {
oldMetadataNames.add(nameAndType.keySet().stream().findFirst().get());

if (nameAndType.containsValue(MetadataObject.Type.SCHEMA)) {
newMetadataNames.add(newRangerMetadataObject.names().get(0));
// Skip update the schema name operation
Expand All @@ -898,16 +885,12 @@ private void doRenameColumnMetadataObject(
} else if (nameAndType.containsValue(MetadataObject.Type.COLUMN)) {
newMetadataNames.add(newRangerMetadataObject.names().get(2));
}
updatePolicyByMetadataObject(
MetadataObject.Type.COLUMN,
oldMetadataNames,
newMetadataNames,
nameAndType.values().stream().findFirst().get());
updatePolicyByMetadataObject(MetadataObject.Type.COLUMN, oldMetadataNames, newMetadataNames);
}
}

/**
* Remove the policy by the metadata object. <br>
* Remove the policy by the metadata object names. <br>
*
* @param metadataNames The metadata object names.
*/
Expand Down Expand Up @@ -946,32 +929,14 @@ private void removePolicyByMetadataObject(List<String> metadataNames) {
private void updatePolicyByMetadataObject(
MetadataObject.Type operationType,
List<String> oldMetadataNames,
List<String> newMetadataNames,
MetadataObject.Type type) {

RangerMetadataObject oldMetadataObject =
new RangerMetadataObjects.RangerMetadataObjectImpl(
RangerMetadataObjects.getParentFullName(oldMetadataNames),
RangerMetadataObjects.getLastName(oldMetadataNames),
RangerMetadataObject.Type.fromMetadataType(type));
RangerMetadataObject newMetadataObject =
new RangerMetadataObjects.RangerMetadataObjectImpl(
RangerMetadataObjects.getParentFullName(newMetadataNames),
RangerMetadataObjects.getLastName(newMetadataNames),
RangerMetadataObject.Type.fromMetadataType(type));
List<RangerPolicy> oldPolicies = rangerHelper.wildcardSearchPolies(oldMetadataObject.names());
List<RangerPolicy> existNewPolicies =
rangerHelper.wildcardSearchPolies(newMetadataObject.names());

List<String> newMetadataNames) {
List<RangerPolicy> oldPolicies = rangerHelper.wildcardSearchPolies(oldMetadataNames);
List<RangerPolicy> existNewPolicies = rangerHelper.wildcardSearchPolies(newMetadataNames);
if (oldPolicies.isEmpty()) {
LOG.warn(
"Cannot find the Ranger policy for the metadata object({})!",
oldMetadataObject.fullName());
LOG.warn("Cannot find the Ranger policy for the metadata object({})!", oldMetadataNames);
}
if (!existNewPolicies.isEmpty()) {
LOG.warn(
"The Ranger policy for the metadata object({}) already exists!",
newMetadataObject.fullName());
LOG.warn("The Ranger policy for the metadata object({}) already exists!", newMetadataNames);
}
Map<MetadataObject.Type, Integer> operationTypeIndex =
ImmutableMap.of(
Expand Down Expand Up @@ -1011,7 +976,7 @@ private void updatePolicyByMetadataObject(
if (alreadyExist) {
LOG.warn(
"The Ranger policy for the metadata object({}) already exists!",
newMetadataObject.fullName());
newMetadataNames);
return;
}

Expand All @@ -1024,47 +989,10 @@ private void updatePolicyByMetadataObject(
});
}

/** rename the COLUMN, Only need to rename `{schema}.*.*` <br> */
private boolean doRenameColumnMetadataObject2(
RangerMetadataObject rangerMetadataObject, RangerMetadataObject newRangerMetadataObject) {
RangerPolicy policy = rangerHelper.findManagedPolicy(rangerMetadataObject);
RangerPolicy newPolicy = rangerHelper.findManagedPolicy(newRangerMetadataObject);
if (policy != null && newPolicy == null) {
try {
policy.setName(newRangerMetadataObject.fullName());
policy.getResources().clear();
List<String> nsMetadataObject = newRangerMetadataObject.names();
for (int i = 0; i < nsMetadataObject.size(); i++) {
RangerPolicy.RangerPolicyResource policyResource =
new RangerPolicy.RangerPolicyResource(nsMetadataObject.get(i));
policy.getResources().put(rangerHelper.policyResourceDefines.get(i), policyResource);
}
rangerClient.updatePolicy(policy.getId(), policy);
} catch (RangerServiceException e) {
LOG.error("Failed to rename the policy {}!", policy);
throw new RuntimeException(e);
}
} else {
if (policy == null) {
LOG.warn(
"Cannot find the Ranger policy for the metadata object({})!",
rangerMetadataObject.fullName());
}
if (newPolicy != null) {
LOG.warn(
"The Ranger policy for the metadata object({}) already exists!",
newRangerMetadataObject.fullName());
}
// Don't throw exception or return false, because need support immutable operation.
return true;
}
return true;
}

@Override
public void close() throws IOException {}

/** Generate different Ranger securable object */
/** Generate Ranger securable object */
public RangerSecurableObject generateRangerSecurableObject(
List<String> names, RangerMetadataObject.Type type, Set<RangerPrivilege> privileges) {
validateRangerMetadataObject(names, type);
Expand Down

0 comments on commit 88af032

Please sign in to comment.